Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Potassium Problems
Sep 28, 2001

SLOSifl posted:

Attribute stuff
If it's possible, can you post the code for all of that? I've been playing around with custom attributes for generating help files and I'd love to see examples of how other people use them.

Fiend posted:

Having an issue with this code on one of two XP machines, both with the same config:
code:
// Throws the error "Object Reference not set to an instance of an object"
string sUrl = Request.Url.ToString();
This is in the BeginRequest handler in Global.asax

Either the Request object is null, or the Url object on the Request object is null.

Adbot
ADBOT LOVES YOU

Fiend
Dec 2, 2001

Lone_Strider posted:

Either the Request object is null, or the Url object on the Request object is null.

I understand that it's the Uri object from the error, it's the "why" I need advice on.

Potassium Problems
Sep 28, 2001

Fiend posted:

I understand that it's the Uri object from the error, it's the "why" I need advice on.
Oh, sorry about that :doh:

SLOSifl
Aug 10, 2002


lightbulbsun posted:

Comments on NetTiers, anyone?

http://www.nettiers.com
Here's the one rule about code generation programs:

It'd better be perfect or else you'll spend more time fixing it than you will save. I can't tell how well NetTiers works from their website, but maybe I'll try passing it the ARTS data model and see what it does. (a 600+ table standardized data model used in retail systems. Here's a simplified list of the data structures NetTiers would be expected to generate in some form - http://www.nrf-arts.org/xml_dictionary_5/XMLDictionary-NonMembers.html)

SLOSifl
Aug 10, 2002


Lone_Strider posted:

If it's possible, can you post the code for all of that? I've been playing around with custom attributes for generating help files and I'd love to see examples of how other people use them.
I doubt my company would be okay with that, but ask me any questions you want in this thread or over PM and I'll be happy to help. Reflection in .NET is very powerful.

I'll throw together a detailed post and possibly an actual sample project if I get a chance this afternoon.

Here's what the program looks like (I'm working on some layout stuff now):


Everything in the main area (i.e. not the buttons or entry box) is built from in-code objects that either self describe, are described in the database, or a combination. That area is called the Journal, but all it really is is a container for Object Views. An Object View is the control that knows what to do with all those visual attributes. It loads them once per type and stores them in various collections (there are 3 layout modes possible) and looks up all the property values dynamically when needed. All drawing is cached to a backing bitmap and displayed when needed, to avoid having to look poo poo up constantly.

Loading all the information for about 12 different types (that means looping through all their properties), including hitting the database once per type, takes about half of a second.

SLOSifl fucked around with this message at 00:14 on Jan 12, 2007

pig-fukr
Nov 3, 2002

Fiend posted:

Having an issue with this code on one of two XP machines, both with the same config:
code:
// Throws the error "Object Reference not set to an instance of an object"
string sUrl = Request.Url.ToString();
This is in the BeginRequest handler in Global.asax

Are the XP machines you're talking about both hitting the same website? Where is the site hosted? Anything different network-wise between the two clients?

poopiehead
Oct 6, 2004

Heffer posted:

Here's example #1 of how things could go wrong. Say you have a table that contains a field for an ID number (2 bytes) a date (8 bytes) and the file itself (32,000 bytes). The rows for the table ordinarily get stored consecutively on the disk, and the database only keeps track of where the first row is, apart from indexes and such.

You want to do a simple thing, like get the file that was uploaded at a specific date. The database reads the first chunk of the table at 64KB per read. The first read gets it two rows to check. Neither match. It goes back to the disk and reads the next 64K. Neither of the new ones match. It does this for 1000 times. It's read 64 megabytes of your disk, looking for a single 32K file out of two thousand.

If you had done this by storing the 240 character filename instead of the actual file, you read 2000 * 250 = 500KB, which only takes 8 read operations instead of 1000.


Wouldn't this be solved by having an an index on the date field? Then it just has to read through the index which is something like 10 bytes per entry. If you're already inserting large files into the database, you're probably not worried about the overhead of an index.

I can see where example 2 makes sense though.

Fiend
Dec 2, 2001

pig-fukr posted:

Are the XP machines you're talking about both hitting the same website? Where is the site hosted? Anything different network-wise between the two clients?

Both machines are hosting the same code for the web site and have the same iis configuration. One machines returns that error.

poopiehead
Oct 6, 2004

In C# ASP .NET 2.0, is there a way to get a mime type from a file extension. I've seen one way by searching through the registry, but I was hoping there was a less hackish way....

Any ideas?

pig-fukr
Nov 3, 2002

Fiend posted:

Both machines are hosting the same code for the web site and have the same iis configuration. One machines returns that error.

What happens if you force the issue and remove the Request object, substituting a hard coded ip?

Also, what happens if you try to write out a straight "Request.ToString()"?

Seems bizarre that the Request object itself would be null, there has to be something else...

Potassium Problems
Sep 28, 2001

SLOSifl posted:

:aaa:
That UI looks awesome. I'll PM you, thanks

SLOSifl
Aug 10, 2002


Lone_Strider posted:

That UI looks awesome. I'll PM you, thanks
I'll post this sample in the thread in case it will help anyone.

This sample contains the following:

1) A project that has a form, and defines a few attribute classes.
2) A project that defines a few classes and defines some methods and properties with attributes attached.

The second project generates an assembly in its bin\Debug (or Release) folder as usual. The other program has a "Load Assembly" button. You can load any .NET assembly into the program and it will generate a simple tree with classes, methods and properties. Any property or method with a ProperyAttribute or MethodAttribute defined will get a child node on the tree with the text supplied.

I got lazy and didn't hook up the ClassAttribute to display anything, and I didn't make an attribute that can be attached to any type of object (the equivalent of your "Note" attribute from your PM). I figure those are no big deal.


(I just realized that I copied and pasted a typo over and over. Ignore the "alwasy" that was supposed to be "always" :saddowns: )

Open the solution, run it, and then navigate to the TestAssembly's bin\Debug folder and select the dll.

Oh, and I didn't comment any of the code. :haw:

http://pandaflash.googlepages.com/AttributeDemo.zip

---------------------------------------------------------------------

Okay, now I'll explain it once you have it loaded up. It's not that complicated in reality, so I'll try to be brief. I will focus only on the MethodAttribute class defined in Attribute.cs, since they're all the same thing anyway.
code:
[AttributeUsage ( AttributeTargets.Property, AllowMultiple = false, Inherited = true )]
public class PropertyAttribute : System.Attribute {

	string description = null;

	public string Description {
		get { return description; }
		set { description = value; }
	}

	public PropertyAttribute ( string description ) {
		this.Description = description;
	}
}
All attributes must inherit from System.Attribute. That is literally all it takes to be used in the [ Attrubute ] syntax. Here I have added an AttributeUsageAttribute to my custom one. Note that the word Attribute, if included in the name of the attribute, can be ommitted whenever you use it. It's not required to be part of the class name, but you probably should include it anyway.

The AttributeUsage is there to say "only allow this to be attached to Methods, don't allow multiple ones per method, and let this attribute come with the method if inherited". Pretty self explanatory. Poke around it with VS's Intellisense a bit.

Other than that attribute and the non-essential naming convention, it's really just a class. You may want to provide multiple constructors if you have a lot of properties, *but* you can take advantage of a neat bonus attributes get: Named parameters. Intellisense will even list them for you when it comes time.
code:
[Method ( Description = "Hay guys what's going on in this attribute", Something = "Lol") ]
So don't feel forced to create 47 constructors with different combinations of parameters. Plus, it makes the code easier to read when you go with Named Parameters. Remember, in standard usage, you never actually have an attribute object you can manipulate, so it has to be done in one line.

So that's an attribute. There are some little caveats, like not being able to use certain datatypes as properties when using a constructor or named params (this is a limitation of the way you declare the attribute inline), but I found them to be easily worked around. For example, I specify my colors for the UI using a syntax like this: "#A,R,G,B" instead of passing in a Color.

In Classes.cs, we'll go ahead and apply a few attributes. Again, they're all basically the same so I'll focus on just a single Method.
code:
[AttributeDemo.Method ( "This is an awesome method." )]
public void AwesomeMethod ( string something ) { }
This method has an attribute attached. The MethodAttribute class is being constructed here. The only difference is you don't need "new" or a semicolon, and you can optionally use named parameters. I added the other project as a reference, since it contained the definition for my attributes.

The only thing to see here is the syntax, which you are already aware of.

Here is a slightly more complicated one from my real application:
code:
[RA.Tools.View ( RA.Tools.ViewAttribute.ViewState.Compact | RA.Tools.ViewAttribute.ViewState.Page |
	  RA.Tools.ViewAttribute.ViewState.Summary, HorizontalPosition = "4px", VerticalPosition = "4px",
	  FontName = "Tahoma", FontSize = 11f, Forecolor = "#245,205,20", Width = "-6px", Height = "90%",
	  HorizontalAlignment = "Near", VerticalAlignment = "Near", Style = "Bold" )]
Now let's get that info back out. This is where you would build your help file based on attributes you loaded in. If you need help loading assemblies dynamically, that happens in LoadAssembly in Form1.cs.

In the ProcessType method in Form1.cs, here is the part that deals with the MethodAttributes:
code:
TreeNode node = this.treeView1.Nodes.Add ( t.FullName, t.Name, 0, 1 );

MethodInfo[] methods = t.GetMethods ();

foreach (MethodInfo method in methods) {
	TreeNode methodNode = node.Nodes.Add ( t.FullName + "." + method.Name, method.Name, 4, 4 );

	methodNode.ToolTipText = string.Format ( methodTip, method.Name, 
                                                 method.ReturnType.FullName, 
                                                 method.GetParameters ().Length );

	object[] attributes = method.GetCustomAttributes ( typeof ( MethodAttribute ), true );

	foreach (MethodAttribute attribute in attributes) {
		TreeNode attNode = methodNode.Nodes.Add ( t.FullName + "." + method.Name + ":" + 
                                                          methodNode.Nodes.Count,
			attribute.Description, 6, 6 );

		methodNode.ToolTipText += "\n\n\"" + attribute.Description + "\"";
	}
}
Almost all of the code is related to building the tree.

First I grab an array of all the Methods defined by the class. For each method, I create a new node on the tree and set its display text. Then I grab all the custom attributes of type MethodAttribute (note that I need to use the full name here). If there are any, I add a child node to the method's node and set that text to attribute.Description. As I mentioned before, it's just a normal class.

That's about it. It's easy to build them and apply them, and it's really just what you do with that metadata that's important.

SLOSifl fucked around with this message at 07:54 on Jan 12, 2007

biznatchio
Mar 31, 2001


Buglord
I'm just posting to say that attributes, as described above, are one of my favorite features of .NET. You can do a lot of really cool meta-programming with them and save yourself a boatload of work in so many situations.

And also, once you discover the compiler-magic ConditionalAttribute, you'll never use "#if DEBUG" ever again.

mr brown
Feb 26, 2003
Mr. Brown? That sounds too much like Mr. Shit.

Fiend posted:

Having an issue with this code on one of two XP machines, both with the same config:
code:
// Throws the error "Object Reference not set to an instance of an object"
string sUrl = Request.Url.ToString();
This is in the BeginRequest handler in Global.asax

Are you sure that both machines have the same version of ASP.NET configured with IIS?

This code works for me:

code:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
	log.Debug("Entering Application_BeginRequest()");

	log.Debug("Request object is " + (Request == null ? "null" : "not null"));

	if (Request != null) 
	{
		log.Debug("Request.Url object is " + (Request.Url == null ? "null" : "not null"));

		if (Request.Url != null) 
		{
			log.Debug("Request.Url.AbsoluteUri is " + (Request.Url.AbsoluteUri));
			log.Debug("Request.Url.ToString() is " + (Request.Url.ToString()));
		}
	}

	log.Debug("Exiting Application_BeginRequest()");
}

protected void Application_EndRequest(Object sender, EventArgs e)
{
	log.Debug("Entering Application_EndRequest()");
	log.Debug("Ending Application_EndRequest()");
}

protected void Application_Error(Object sender, EventArgs e)
{
	log.Error("Caught exception in Application_Error", Server.GetLastError());
}
code:
2007-01-11 22:10:18,399 [6128] DEBUG WebApplication1.Global - Entering Application_BeginRequest()
2007-01-11 22:10:18,430 [6128] DEBUG WebApplication1.Global - Request object is not null
2007-01-11 22:10:18,430 [6128] DEBUG WebApplication1.Global - Request.Url object is not null
2007-01-11 22:10:18,430 [6128] DEBUG WebApplication1.Global - Request.Url.AbsoluteUri is [url]http://localhost/WebApplication1/WebForm1.aspx[/url]
2007-01-11 22:10:18,430 [6128] DEBUG WebApplication1.Global - Request.Url.ToString() is [url]http://localhost/WebApplication1/WebForm1.aspx[/url]
2007-01-11 22:10:18,430 [6128] DEBUG WebApplication1.Global - Exiting Application_BeginRequest()
ASP.NET configuration:
code:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322>aspnet_regiis.exe /lv
1.1.4322.0      Valid (Root)    C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll
2.0.50727.0     Valid           C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll

Victor
Jun 18, 2004
Heffer, do you know that SQL Server doesn't store fields any larger than 8000 bytes in-row? Instead, it uses 16-byte pointers. The scheme you described could never happen with SQL Server, unless all the files are less than 8000 bytes and the store-text/image-in-row option is turned on. I don't know what other RDBMSes do.

DLCinferno
Feb 22, 2003

Happy

poopiehead posted:

In C# ASP .NET 2.0, is there a way to get a mime type from a file extension. I've seen one way by searching through the registry, but I was hoping there was a less hackish way....

Any ideas?
I'd like to know this as well. Currently I'm pulling from the registry and I cache the type (and icon index) in a hashtable so it helps minimize the hit, but if there is some way of using Win32 or something I'm all ears.

SLOSifl
Aug 10, 2002


biznatchio posted:

And also, once you discover the compiler-magic ConditionalAttribute, you'll never use "#if DEBUG" ever again.
:monocle: Oh wow, I've never seen that one. That looks much easier and cleaner (when you want to knock out an entire method, not just a single call somewhere). Nice.

SLOSifl fucked around with this message at 08:07 on Jan 12, 2007

csammis
Aug 26, 2003

Mental Institution

SLOSifl posted:

That's about it. It's easy to build them and apply them, and it's really just what you do with that metadata that's important.


Any ideas on using attributes to define an array of objects? I'm not sure if it's possible if the objects are reference types (require instantiation) but I haven't found anything definitive. I'm trying to use attributes to define a list of options that a plugin assembly can support, but it's not working exactly as I had it planned in my head :)

SLOSifl
Aug 10, 2002


csammis posted:

Any ideas on using attributes to define an array of objects? I'm not sure if it's possible if the objects are reference types (require instantiation) but I haven't found anything definitive. I'm trying to use attributes to define a list of options that a plugin assembly can support, but it's not working exactly as I had it planned in my head :)
Well, for a list of supported options, you could always use an enum marked with the Flags attribute. That should work in theory, provided you have a limited list of options.

More realisitically, you could define an attribute with a lot of bools, one for each option. Then use named parameters to set them to true when supported.
code:
[ PluginOptions ( Option1 = true, Option2 = true, AnotherOption = true ) ]
Are all of your options simply true or false? Maybe taking full advantage of the attribute class will allow you to actually simplify things. I'm guessing these plugins you speak of are for shaim, so perhaps on of the option is for connection settings. An Flags enum with options like "EncryptedLogin" and "EncryptedConversation" and "PeerToPeer", etc, will all fit in one property, while other options can go into other properties.

Or maybe I'm missing what you mean by deinfing an array of objects? Internally, attributes can contain arrays and anything else you want. Defining an array in the constructor *might* be off limits - I can check. I wouldn't be surprised if an array of an alreay allowed type is okay though.

edit: this:
code:
[AttributeDemo.Property ( "This property returns a string.", Options = new object[] { "One", "Two", "Three" } )]
Caused no problems. Changing one of the strings to "new TestClass()" gave me the following error:
"An attribute argument must be a constant expression, typeof expression or array creation expression"

That's the limitation - they must be constant, like a string (or int, bool, etc), a typeof (which should be a constant anyway, right?) or an array of one of the supported types.

It looks like your best option is to create the array internally from allowed values, if possible. It's also possible that, in your case, the list of supported options is actually best as a property of the class, although I do see the attribute angle making a lot of sense.

SLOSifl fucked around with this message at 17:48 on Jan 12, 2007

csammis
Aug 26, 2003

Mental Institution

SLOSifl posted:

:words:
That's the limitation - they must be constant, like a string (or int, bool, etc), a typeof (which should be a constant anyway, right?) or an array of one of the supported types.

Yeah, I was playing with this last night, and that was what I was running into...the documentation was not great on what exactly the error meant, so I wasn't sure if I was missing something. Looks like I was right :sigh:

quote:

It looks like your best option is to create the array internally from allowed values, if possible. It's also possible that, in your case, the list of supported options is actually best as a property of the class, although I do see the attribute angle making a lot of sense.

That's what we're doing right now, the configuration options are exposed as a List<ShaimPluginOption> in a property defined by the plugin interface. The problem we're running into is that the plugin loader has to scan the assembly, find the plugin object, instantiate it (this is the bitch part of it, I'm trying to avoid instantiating the relatively large plugins that may not even be used just for configuration), then get the property. I've been refactoring simple plugin properties like names, authors, descriptions, whether or not to show it in the configuration list, etc. as assembly-level properties.

Being able to specify typeof gives me an idea though...

code:
[assembly: ShaimPluginOptionObject(typeof(some.plugin.namespace.Prefs))]

namespace some.plugin.namespace
{
  public class Prefs
  {
    // expose configuration options for the plugin in this assembly
  }
}
That'll (a) let me avoid having to scan the assembly for a type that implements a certain interface, and (b) let me avoid having to instantiate a heavy object just to set some configuration options. Hooray attributes :woop:

SLOSifl
Aug 10, 2002


csammis posted:

code:
[assembly: ShaimPluginOptionObject(typeof(some.plugin.namespace.Prefs))]
That'll (a) let me avoid having to scan the assembly for a type that implements a certain interface, and (b) let me avoid having to instantiate a heavy object just to set some configuration options. Hooray attributes :woop:
Very nice!

I guess a static method could work too, but that looks like a much more elegant option.

csammis
Aug 26, 2003

Mental Institution

SLOSifl posted:

Very nice!

I guess a static method could work too, but that looks like a much more elegant option.

I like the attribute approach because if a plugin doesn't have any configurable options, it just doesn't use the attribute :)

Fiend
Dec 2, 2001

mr brown posted:

Are you sure that both machines have the same version of ASP.NET configured with IIS?

This code works for me:

I'm pretty sure!

Even the expression to eval if the .Url property is null throws the error.
code:
Line 51: 		if (Request != null)
Line 52: 		{
>>>Line 53: 			sRet += "Request.Url object is " + (Request.Url == null ? "null" : "not null");
Line 54: 
Line 55: 			if (Request.Url != null)


Source File: c:\Inetpub\AppName\App_Code\Global.asax.cs    Line: 53 

[NullReferenceException: Object reference not set to an instance of an object.]
   System.Web.Hosting.ISAPIWorkerRequestInProc.GetServerVariable(String name) +1132
   System.Web.Hosting.ISAPIWorkerRequest.GetServerName() +15
   System.Web.HttpRequest.get_Url() +282
   Global.Application_BeginRequest(Object sender, EventArgs e) in c:\Inetpub\AppName\App_Code\Global.asax.cs:53
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +92
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64
I'm going to go eat a rock :(

Victor
Jun 18, 2004
Fiend, you aren't causing the NullReferenceException: ASP.NET is, inside the GetServerVariable method as indicated by that call stack. Apparently it's an ASP.NET bug. You might want to peek at all the server variables in the Request object to see if the relevant information is there for ASP.NET to build you a Url object. You could also use a tool (like Lutz Roeder's Reflector) to see exactly what is causing the exception, although that might be a bit tricky.

fankey
Aug 31, 2001

XAML question ( probably for csammis )

Has anyone had any luck with using the XAML design view in the real application? It works fine for me on simple projects but appears to get hosed when I start added xmlns definitions in some of the files.

The app compiles and runs without any problems, I'd just like to use the visual XAML editor. Both Window1.xaml and color_control.xaml fail in the Design view. I'm pretty sure I'm up to date on the all the .NET 3.0 SDKs and VisualStudio extensions.

Window1.xaml fails with
Error 3 Value 'Resources\window_close_button.xaml' cannot be assigned to property 'Source'. C:\code\software\IntevacDesigner\App.xaml 10
Error 4 Value 'Window1.xaml' cannot be assigned to property 'StartupUri'. C:\code\software\IntevacDesigner\App.xaml 4

and color_control.xaml fails with
Error 1 Value 'Window1.xaml' cannot be assigned to property 'StartupUri'. C:\code\software\IntevacDesigner\App.xaml 4

Here's what my xaml files look like

App.xaml
code:
<Application x:Class="IntevacDesigner.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="Window1.xaml"
    >
    <Application.Resources>
      <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
          <ResourceDictionary Source="Resources\Shared.xaml" />
          <ResourceDictionary Source="Resources\window_close_button.xaml" />
        </ResourceDictionary.MergedDictionaries>
      </ResourceDictionary>
    </Application.Resources>
</Application>
Window1.xaml
code:
<Window x:Class="IntevacDesigner.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:app="clr-namespace:IntevacDesigner" 
    xmlns:gr="clr-namespace:IntevacDesigner.graphic" 
    xmlns:win="clr-namespace:IntevacDesigner.windows" 
    Title="IntevacDesigner" Icon="Favorites.ico"
    >
  <DockPanel LastChildFill="True">
    <Menu DockPanel.Dock="Top">
      <MenuItem Header="File">
        <MenuItem Command="Open"/>
        <MenuItem Command="Save"/>
        <MenuItem Name="foo_menu" Command="app:Window1.foo"/>
      </MenuItem>
    </Menu>
    <Grid Name="grid">
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="0.232876712328767*" />
        <ColumnDefinition Width="0.767123287671233*" />
      </Grid.ColumnDefinitions>
      <TabControl Grid.Column="0" TabStripPlacement="Bottom">
        <TabItem Header="Devices">
          <app:device_treeview_t/>
        </TabItem>
        <TabItem Header="test">
          <win:color_control/>
        </TabItem>
      </TabControl>
      <GridSplitter DragIncrement="1" Width="5" Grid.Column="0"/>
    </Grid>
  </DockPanel>
</Window>
color_control.xml
code:
<UserControl x:Class="IntevacDesigner.windows.color_control"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
      </Grid.RowDefinitions>
      <TextBlock Grid.Row="1" Grid.Column="1">R</TextBlock>
      <TextBlock Grid.Row="2" Grid.Column="1">G</TextBlock>
      <TextBlock Grid.Row="3" Grid.Column="1">B</TextBlock>
      <TextBlock Grid.Row="4" Grid.Column="1">A</TextBlock>
    </Grid>
</UserControl>

csammis
Aug 26, 2003

Mental Institution

fankey posted:

XAML question

I don't see anything immediately wrong, but it looks like the specific errors you're seeing are most likely the fault of the designer. I don't use a visual designer for XAML, not the one in Visual Studio nor Expression/Sparkle/Blend/Whatever it's called now. Neither of them are anything to write home about, if you ask me, and I stopped using them specifically because they broke down when I started importing namespaces. It may be better for you to ask on the Avalon forums.

mr brown
Feb 26, 2003
Mr. Brown? That sounds too much like Mr. Shit.

Fiend posted:

I'm pretty sure!

Even the expression to eval if the .Url property is null throws the error.

....

I'm going to go eat a rock :(


Victor posted:

Fiend, you aren't causing the NullReferenceException: ASP.NET is, inside the GetServerVariable method as indicated by that call stack. Apparently it's an ASP.NET bug. You might want to peek at all the server variables in the Request object to see if the relevant information is there for ASP.NET to build you a Url object. You could also use a tool (like Lutz Roeder's Reflector) to see exactly what is causing the exception, although that might be a bit tricky.

Victor makes an excellent point here, I neglected to read the stacktrace.

Googling some for "GetServerVariable NullReferenceException" yields these two threads in which someone runs "aspnet_regiis -i" which fixes the problem for them.

I'm really, really surprised your code was able to get that far without ASPNET being properly registered with IIS, but I suppose stranger things have happened. Reflector shows that ISAPIWorkerRequestInProc.GetServerVariable does a lot with looking up what appear to be internal IIS/ASPNET environment variables.

The Noble Nobbler
Jul 14, 2003

SLOSifl posted:

Here's the one rule about code generation programs:

It'd better be perfect or else you'll spend more time fixing it than you will save. I can't tell how well NetTiers works from their website, but maybe I'll try passing it the ARTS data model and see what it does. (a 600+ table standardized data model used in retail systems. Here's a simplified list of the data structures NetTiers would be expected to generate in some form - http://www.nrf-arts.org/xml_dictionary_5/XMLDictionary-NonMembers.html)

The question is, if the code generation scripts even do a mediocre job of creating a business, data layer, and even O/R mapping system for you, doesn't it seem likely they'd save you time any way you'd slice it (unless they *really* screwed things up).

Grid Commander
Jan 7, 2007

thank you mr. morrison

DLCinferno posted:

....Is there a way to get the mime type from the file extension without using the registry? ....

I'd like to know this as well. Currently I'm pulling from the registry and I cache the type (and icon index) in a hashtable so it helps minimize the hit, but if there is some way of using Win32 or something I'm all ears.

Yes, figure out what each file formats' header is. Most binary files have special header at the top of the file. It will be different for different file types. It will be stored at a different location for each file type. It will likely be stored in the first 12 bytes of the file.

The registry is easier, but can sometimes "lie" since you are just checkng for file associations instead of actually using the semantics of the file itself to check its type.

For a good example look up most unix file types, or look at the bitmap or jpeg file formats.

Have fun.

Heffer
May 1, 2003

wwb posted:

I have yet to manage to melt down a SQL server because it was serving files out of the database, but that is me.

I work at a newspaper, and we use some monstrous databases for layout files, photograph storage, and other assorted information and files. Right now we're at umm... 2 Terabytes? Maybe 4 TB. One of the big problems is that AP Photographers and the such are getting higher resolution digital cameras. You qaudruple the resolution of most incoming photos, and things start to get out of hand.

We've adopted some pretty serious policies on pushing outdated content and materials to an archive or external store, but we can't stop everything. Theres a simple trend analysis we do to look at what the average increase in size of the database is versus what the max disk size we can squeeze into the server. We got about 10 months before we hit a brick wall, and the database curls up and dies.

poopiehead
Oct 6, 2004

Grid Commander posted:

Yes, figure out what each file formats' header is. Most binary files have special header at the top of the file. It will be different for different file types. It will be stored at a different location for each file type. It will likely be stored in the first 12 bytes of the file.

The registry is easier, but can sometimes "lie" since you are just checkng for file associations instead of actually using the semantics of the file itself to check its type.

For a good example look up most unix file types, or look at the bitmap or jpeg file formats.

Have fun.

Thanks for the info.

What I, and I'm assuming Grid Commander, are looking for is to return the same Content-Type header as the web server would for a given file. Servers just look up extensions in a table they have and return the associated content type. I probably didn't make that clear in the original question.

In my case, what I'm trying to do is dynamically serve up files through a server side script. I'll know the extension that the file originally had, so I'd like to get the content type from that. I can store the content type when the files are uploaded, but would rather avoid it.

poopiehead fucked around with this message at 07:55 on Jan 13, 2007

ljw1004
Jan 18, 2005

rum

Grid Commander posted:

[Is there a way to find the mime type without using the registry?]
Yes, figure out what each file formats' header is. Most binary files have special header at the top of the file. It will be different for different file types. It will be stored at a different location for each file type. It will likely be stored in the first 12 bytes of the file.

There's already a windows function which does this -- looks at the data to determine its type:

FindMimeFromData

wwb
Aug 17, 2004

Heffer posted:

I work at a newspaper, and we use some monstrous databases for layout files, photograph storage, and other assorted information and files. Right now we're at umm... 2 Terabytes? Maybe 4 TB. One of the big problems is that AP Photographers and the such are getting higher resolution digital cameras. You qaudruple the resolution of most incoming photos, and things start to get out of hand.

We've adopted some pretty serious policies on pushing outdated content and materials to an archive or external store, but we can't stop everything. Theres a simple trend analysis we do to look at what the average increase in size of the database is versus what the max disk size we can squeeze into the server. We got about 10 months before we hit a brick wall, and the database curls up and dies.

Valid point, but that is fundamentally a disk space issue, not a "all these images are making SQL server die" issue.

On NetTiers: first, SLOSifl's comment is very, very poingnant. Always keep that in mind. Anyhow, NetTiers is pretty slick, and does do a reasonable job of creating a table adapter style ORM layer with some nice extensibility points. But it is still a generated, table-adapter style ORM that encourages data-, not behavior-centric programming.

Grid Commander
Jan 7, 2007

thank you mr. morrison

ljw1004 posted:

There's already a windows function which does this -- looks at the data to determine its type:
FindMimeFromData

Nice!! And elegantly named, guess it shows what an extra 10 seconds of research might have turned up if i had just typed that stuff into Google.
Thanks for pointing that out.

DLCinferno
Feb 22, 2003

Happy

ljw1004 posted:

There's already a windows function which does this -- looks at the data to determine its type:

FindMimeFromData
Very cool. Thanks!

Here's the PInvoke link for anyone else:

http://www.pinvoke.net/default.aspx/urlmon/FindMimeFromData.html

csammis
Aug 26, 2003

Mental Institution

DLCinferno posted:

Very cool. Thanks!

Here's the PInvoke link for anyone else:

http://www.pinvoke.net/default.aspx/urlmon/FindMimeFromData.html

Is it just me, or is the declaration on that site horribly mangled?


edit: Your ninja-edit makes me look :downs:

Combat Pretzel
Jun 23, 2004

No, seriously... what kurds?!
Any of you WPF wizards knows whether or how I can force the DWM in Vista to enable shadow on windows without frame? As soon I set WindowStyle to None and set AllowsTransparency, it poofs. I managed to get blur back via PInvoking some DWM functions, but there doesn't seem to be a way to force the shadow.

Meanwhile, I'm doing the shadow in the client area using a nine grid, but I'd like the system to the shadow. Evidence (9grid vs DWM):

fankey
Aug 31, 2001

Toiletbrush posted:

Any of you WPF wizards knows whether or how I can force the DWM in Vista to enable shadow on windows without frame? As soon I set WindowStyle to None and set AllowsTransparency, it poofs. I managed to get blur back via PInvoking some DWM functions, but there doesn't seem to be a way to force the shadow.

Meanwhile, I'm doing the shadow in the client area using a nine grid, but I'd like the system to the shadow. Evidence (9grid vs DWM):

Try setting ClipToBounds = false. I'm not sure if that works with the root window but it did fix a similar problem I was having getting drop shadows to show up on some controls placed inside a Canvas.

Frank Butcher
Oct 11, 2003

'Ave a word with yerself, darlin'
I'm thinking of starting to programme in C# instead of VB. I have a large VB project and was wondering if it's possible to begin writing new classes (or even forms) in C# within this project? I heard that all code compiles the same so I was wondering if it's possible.

Adbot
ADBOT LOVES YOU

Combat Pretzel
Jun 23, 2004

No, seriously... what kurds?!

fankey posted:

Try setting ClipToBounds = false. I'm not sure if that works with the root window but it did fix a similar problem I was having getting drop shadows to show up on some controls placed inside a Canvas.
Throws an exception. I guess I have to write focus aware shadowing code to simulate the Aero stuff. I need to abstract the Window class anyway to share tons of helper code.

Combat Pretzel fucked around with this message at 15:30 on Jan 15, 2007

  • Locked thread