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
Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
So I'm trying to come up with a way to display my data in a TreeView. The important part is that each entity has an ID (obviously) and a parent ID which has a foreign key on ID in the same table. More precisely:
code:
CREATE TABLE [dbo].[entities](
	[id] [bigint] IDENTITY(1,1) NOT NULL,
	[parentID] [bigint] NOT NULL,
	[slug] [varchar](50) NOT NULL,
	[title] [varchar](100) NOT NULL,
	[author] [bigint] NOT NULL,
	[group] [bigint] NOT NULL,
	[posted] [datetime2](7) NOT NULL,
	[modified] [datetime2](7) NOT NULL,
 CONSTRAINT [PK_entities] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

ALTER TABLE [dbo].[entities]  WITH CHECK ADD  CONSTRAINT [FK_entities_entities] FOREIGN KEY([parentID])
REFERENCES [dbo].[entities] ([id])
GO

ALTER TABLE [dbo].[entities] CHECK CONSTRAINT [FK_entities_entities]
GO
The test data I have is:


Click here for the full 804x148 image.


So there is indeed some sort of hierarchy going on.

To read the data, what I currently have is:

code:
db.wwwDataContext wdc = db.connections.www();

var ents = from ent in wdc.entities where ent.parentID == 0 && ent.id != 0 orderby ent.id select ent;

foreach (db.entity ent in ents)
{
	var thisNode = dbTreeView.Nodes.Add(ent.id.ToString());
	thisNode.Nodes.Add(build_r(ent.id, wdc));
}

private TreeNode build_r(long start, db.wwwDataContext wdc)
{
	TreeNode ret = new TreeNode();

	var ents = from ent in wdc.entities where ent.parentID == start select ent;

	foreach (db.entity e in ents)
	{
		var thisNode = ret.Nodes.Add(e.id.ToString()/*, e.title*/);

		foreach (db.entity ch in e.children)
		{
			thisNode.Nodes.Add(build_r(ch.id, wdc));
		}
	}

	return ret;
}
Unfortunately, that gives me some weird null objects which definitely don't exist:


Click here for the full 1099x615 image.


Is there anything obvious I'm missing here? Perhaps an artifact of TreeView? Is there a better way to be fetching everything?

Adbot
ADBOT LOVES YOU

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

Triple Tech posted:

What's a good name for a function that validates a string against a set of known values and returns null otherwise?

code:
// only fruits allowed!

apple  => "apple"
orange => "orange"
car    => NULL

I'm rather fond of the interrogative form - IsValidFruit might be a good choice.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

Crazak P posted:

I'm not quite sure if this is the place to ask, but I'm trying to learn asp .net with mvc.

I'm making a timesheet web app. I have a model for timesheets. Each timesheet entry is the hours worked on a specific task for a certain day.

On the user homepage, I want a summary table of all the hours worked for each day of the week for each task. I have a sql statement that can get all that information. I just don't know how to show it in a view.

I'm learning using that Nerd Dinner tutorial. So I have a Timesheet controller and a Timesheet repository. How do I get the information from my sql function to the Timesheet repository so that I can create an instance in the controller to get that info?

Am I going about this in the wrong way by making a sql function? Should I just return all the timesheet objects for that week and then aggregate the date in the controller code?

If you're using LINQ-to-SQL, you can use functions directly (drag them from the server explorer to the design surface). Not sure about EF but I presume you can there as well. I personally do all the data filtering and processing in the controller but there's no rule or pattern dictating that.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

Crepthal posted:

I'm trying to figure out how to connect to an active directory and simply check if one specific user's password is set to expire in Visual Basic .NET

If you're using .NET 3.5, look at the System.DirectoryServices.AccountManagement namespace.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

Sweeper posted:

I have a quick asp.net publish question. I have a class that tracks visits to pages, but I don't want it to do that on my local host, so I have a define that will make it so code is not used is I define the "define" (okay...).

I have something like #define isNotLocalHost, then I use #if isNotLocalHost <code> #endif

Basically I am tired of having to set up this define when I make changes for the dev server and I would like it to just have a define on publish. Is this possible?

You can check if HttpContext.Current.Request.Url.AbsoluteUri.StartsWith("http://localhost:") is true.

Quebec Bagnet fucked around with this message at 06:23 on Jul 29, 2010

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

Kekekela posted:

I've been sending a json request then returning a JsonResult and using jQuery to parse the result out into wherever it needs to go.

I return a PartialViewResult from the server and use jquery's .html() function to replace the div that contains the original partial view. Same effect, works very cleanly.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

fletcher posted:

Is there any issue with having two versions of System.Data.SQLite on the same machine? I want to have one project that uses an older version (1.0.48.0) and one that uses the latest version (1.0.66.0). Anything I need to know about doing something like that?

Assemblies are uniquely named by version (and a couple of other things). As long as both exist and can be reached when the referencing assembly is loaded there won't be a problem.

quote:

What do you generally use for persistence? I've read about NHibernate and the Entity Framework, both of which sound heavy, and have played around with SubSonic, which seems nice but it's too early to tell.

I'm using .NET 4, C#, WPF, MSSQL, putting together an app that requires nothing crazier than a many-to-many relationship.

What ORM would you use if you were starting from scratch?

I'm rewriting my MVC apps to use NHibernate with the Fluent interface (coming from LINQ2SQL) and it seems pretty nice. A little heavy, yes, but easy enough to abstract away.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
So is it better to keep a service running (which both runs periodic tasks and needs to respond to user actions) or to run asynchronous WCF calls? I haven't seen much on how WCF deals with long-running processes.

The longest periodic task I need to deal with in my app is a weekly video encoding (accomplished by spawning an ffmpeg process) which usually takes 20-25 minutes. The other scheduled tasks are around a minute or less (log rotation, database verification, etc).

Right now I have a service running that uses NCrontab, but I wonder if WCF might be a cleaner solution. I'm also interested in building an API and the DataContract stuff looks pretty nice, and integrating them sounds good on paper, but I'm not sure if it will end up more trouble than it's worth (like blocking API clients while waiting on ffmpeg to finish), even with asynchronous calls to WCF and spawning threads on the server side. I'm using IIS6 as well.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
Make the variable in question private static?

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

GrumpyDoctor posted:

I have an F# assembly that has as one of its dependencies the F# core assembly (naturally). Another of its assemblies is a different library that also depends on the F# core assembly. However, when I try to create an installation project, the project detects two different F# core assemblies (one with a path in the GAC somewhere and one in the Visual F# program files directory) and tries to install them both. Since they have the same name, only one of them ends up on the target machine, and then the application doesn't work because it can't find the F# core assembly.

I know I don't understand enough about the way assemblies and the GAC and all that stuff works, and now it's coming around to bite me in the rear end. How do I fix this problem?

I'll bet you're referencing two different versions of the assembly. Make sure both are targeting the same version of the .NET runtime, for starters.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
Is there really no way to do a DNS SRV record lookup with System.Net.Dns.GetHostEntry()? There's DnDns, which I don't mind using, but it would be nice if there's something already in the framework.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

epswing posted:

If you had a .NET project in need of an installer, which would you use and why?

WiX is nice.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
Sounds right, I've always just selected, changed the properties, and called Save().

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
So I'm wondering how to redesign my database layer. Right now the majority of this project does direct LINQ-to-SQL queries, which I now realize is bad. I'm planning on first redoing the ORM (most likely with SubSonic), and I also want to build an API using WCF.

Where should I separate updating/querying logic from database updating? Right now the application is a few ASP.NET projects and some supporting tools. Should I put all of the logic in the API and then call it directly from my app since they're standard .NET methods? I say call it directly because it would seem, for performance reasons, that it's inconvenient to set up a complete WCF connection to handle each page load. Or should I put the logic in the DB layer, call that directly from my own code, and make the API expose that?

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

Nurbs posted:

If you're on .net 4 scrap whatever you've written and embrace System.DirectoryServices.AccountManagement

3.5 :eng101:

Active Directory stores group members by DN (the full CN=... form). Once you get the DN you can query for that user specifically (I believe there's a method on DirectorySearcher to look up something by DN) and the fields you want to read are the sAMAccountName or userPrincipalName.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

Smugdog Millionaire posted:

But I don't know how best to handle add/remove. What's the fastest way to go about building that?

I solved this problem by using an AJAX delete button on each row that did a GET on "/ajax/deleteItem/{id}" and a global add item button that called "/ajax/createItem/{parentID}". The deleteItem and createItem methods returned a PartialView that was the entire new state of the table (this worked because there were only a few items in the table).

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

Tapatio posted:

Well I'm already using Mono and figured out that mcs.exe is the compiler. I've compiled executable files so far but I'm wondering if there is some way to compile to "object" files (.o) as you would with C/C++ (or their C# counter part). I'm still having trouble figuring out these assembly things.

You compile the files for each assembly all in the same compiler invocation.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
Is GhostDoc Pro really worth it? I've been using the free edition and it's been working fine, is it worth shelling out?

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

wwb posted:

Totally speaking out of conjecture here, but will it be like the .NET 2.0 / .NET 3.5 thing we lived through for most of the past decade? Situation was .NET 3.5 compiled down to 2.0 MSIL and was really compiler stunts and syntactic sugar. All your app pools were set to 2.0.5070whatever even if your apps were all built in .NET 3.5 with linq and such.

There was mscorlib 2.0, mscorlib 3.0, mscorlib 3.5 all targeting the 2.0 CLR...but there will be mscorlib 4.0 from the 4.0 framework and mscorlib 4.0 from the 4.5 framework both targeting the 4.0 CLR. I don't get the sudden reversal of practice which worked just fine last time around.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

No Safe Word posted:

Generally speaking, MVC is The Way Forward and should be what you default to unless you have a good reason to use WebForms instead.

My excuse for developing WebForms in 2012 is that I'm using Ext.Net and it fits into the WebForms model pretty well. :shobon:

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
Mono implements most of the .NET framework. Some of the newer stuff is missing or incomplete, and there's a nontrivial amount of classes in .NET that are specific to Windows, for which they sometimes provide equivalent operations in the Mono namespace.

They have a tool that will scan your binaries and report on what is unlikely to work when run on Mono.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

boo_radley posted:

These were good suggestions! The cacheing overhead has its own impact at around 7,000 users that seems to outweigh the time to do a raw query. However it seems like we're just doing too much in one monolithic process: 35,000+ users and 2 to 10 AD groups per user averaging 12s/1,000 group-users will take a bit over 8 hours to run. We're just doing too much with too many people all at once. :sigh:

Could you divide the workload (by, say, first character of last name) across multiple machines and domain controllers to cut down on run time?

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

Orzo posted:

Oh, that reminds me of a question I had. Can someone explain why ASP.NET MVC is such a big deal these days? Why should I use it? Note that I don't need an explanation of why MVC is a generally a good design construct, as I've been using the MVC pattern in fairly complex ASP.NET applications for years now. What does the MVC framework actually provide?

Off the top of my head:

  • You can write your website like an actual website, with HTML, CSS, and JavaScript, without wondering how the controls will screw up your design
  • All of the XHR requests you make are your own
  • No ViewState
  • Controller testability

e:

wither posted:

ASP.NET MVC is absolutely what you want. Unless you're interacting with an existing Active Directory setup or something you just want to use forms authentication anyways.
Any recommended resources on integrating AD with forms auth? All of the users of my app need to be authenticated via AD, but for various reasons it would be helpful to use forms instead of HTTP authentication.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

wwb posted:

AD with forms auth is pretty easy. What you want to do is use the AD membership provider, an AD connection string and forms auth:

code:
		<membership defaultProvider="AdProvider">
			<providers>
				<add 
					name="AdProvider"
					type="System.Web.Security.ActiveDirectoryMembershipProvider, 
						System.Web, Version=2.0.0.0, 
						Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
					connectionStringName="YourAdCstring"
					applicationName="WhateverYouWant"
					enablePasswordReset="false"
					 />
			</providers>
		</membership>
code:
	<connectionStrings>
		<add name="YourAdCstring"
			 connectionString="LDAP://YourADDomain/OU=[whatever],DC=something,DC=else"
			 />
	</connectionStrings>
App needs to have priviliges to access AD -- basically needs to be running as a domain account. Kinda just works, you should be able to slap this into a default MVC site and make it go.

I wouldn't bother with a custom profile provider here -- I'd just get the ProviderUserKey off the AD stuff (user sid) and use that to key whatever user- data you've got in a standard CRUD fashion.

Looks handy, thanks.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
So, WCF and MSMQ integration. I needed to have a service be asynchronous and fire-and-forget preferably with reliable delivery. (It's a video encoding service for our CMS, an encode job takes 5-10 minutes so we'd prefer to have people upload their video and then be returned to the web page ASAP.) MSMQ seemed to hit all of those points, so I chose to use that on the server and client and so far it's working fine.

But now I'm reading that WCF backed by MSMQ is apparently the new hotness. I already talk to my background processes over WCF anyway, but only for synchronous operations. Is that what I should be doing?

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
They're going to at least be on the same LAN, if not same machine. The biggest change that would happen is that I might have to multicast messages which is easy enough to get running.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

CapnAndy posted:

I'm wading into fairly obscure territories here, so I understand if nobody has an answer for this one, but:

I'm trying to use Fluent NHibernate to connect to an iSeries database. Here's the code that keeps throwing errors:
code:
private static ISessionFactory CreateSessionFactory()
{
	return Fluently.Configure()
		.Database(DB2Configuration.Standard.ConnectionString(get_db2_connectionString("P")))
		.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Program>())
		.ExposeConfiguration(BuildSchema)
		.BuildSessionFactory();
}
get_db2_connectionString just builds out the connection string (we have production and testing servers). The error I'm getting every time is "Could not create the driver from NHibernate.Driver.DB2Driver, NHibernate, Version=3.3.1.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4."

I've googled the hell out of it and the consensus seems to be "that means you don't have the right .dll installed", but I do! I've got IBM.Data.DB2.iSeries referenced, it's set to copy local, and I even threw in a using reference to it too to see if that'd help, but it doesn't. I've got the FluentNHibernate and NHibernate .dlls referenced, I'm using them (I also threw in a using for NHibernate.Driver just in case, but that wasn't it either), I do not understand what on Earth I could be missing.

Try turning on NHibernate logging.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

epalm posted:

No seriously, is anyone using MSMQ? If so, do you love it? If so, do you have a favourite MSMQ book?

I found it fairly straightforward to send and receive messages. What are you trying to do with it?

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
See if your server or client machine is configured to disallow unencrypted or low-encryption connections or otherwise have trust (e.g. they are in the same domain or trusted forest). This states that MSMQ tries to use an encrypted RPC channel, which will fail if the allowed encryption methods don't line up or there is not sufficient trust.

You can also look at the problem a different way and see if you can configure message routing on the remote machine to send messages that you're interested in to your local machine.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
Unless I'm reading wrong I'm not seeing how you need IIS on the client, you should only need it on the server.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

Prefect Six posted:

I'm dumb and obviously didn't pay close attention to the beginning variables chapter but why does
code:
double IceLoad = .25;
Console.WriteLine(IceLoad);
Produce the result .25, but
code:
double IceLoad = 1 / 4;
Console.WriteLine(IceLoad);
produce 0?

The result of dividing an integer by an integer is an integer.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

Prefect Six posted:

So how do I make C# perform mathematical equations? Put everything in a variable?

e: yes this would be easier and already done in a spreadsheet, but I want to do it just to learn to code.

e2: Answer: add f to the end of integers. Thanks so much thread!

Correct. You can specify 1f or 1.0f or 1.0 to create a double, or 1M or 1.0M to create a decimal. With no decimal point and no suffix the compiler will assume you mean an integer. In certain cases it will trigger a compiler error.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
Is there a significant performance difference loading a workflow activity from XAML versus defining it entirely in code?

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

PDP-1 posted:

Is it possible to alias the name of a class sitting in one namespace so that it looks like it is a member of another namespace?

My problem is that I'm trying to create a class library that internally references some third party libraries, and I'd like to present a single clean interface that hides the internal operations. For example, if MyClassLibrary uses ThirdParty.Foo and FourthParty.Bar internally, I'd like to let the user just have one using MyClassLibrary statement that would expose things as MyClassLibrary.Foo and MyClassLibrary.Bar as if they were a natural part of MyClassLibrary.

Maybe I'm misunderstanding what you're asking, but couldn't you just subclass FourthParty.Bar in your namespace without any implementation?

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

Uziel posted:

Are there any examples of practical implementations for this? I've looked around at some examples but I don't fully understand the benefit of this vs using a database (it would likely be cross server and used across many applications as this would address a point of failure for all of our web apps).

There's nothing really stopping you from writing messages to a database and having a process watch for new rows. One of the big benefits of using a message queue is asynchronous access, with multiple independent simultaneous readers and writers. The other is durability - you could just send an HTTP request and wait for a response, but if either you or the server crash in the middle, you've lost the message. But with durability guarantees, senders can basically just send a message and assume that it will be picked up.

Some other benefits are correlation (allowing you to specify that a message is in response to another one), triggers, multicasting, Internet routing, WCF integration, and Active Directory integration to route messages to the recipient machine or queue.

I had a really long MSMQ example written up but it was kinda spergy so I'll just say that in your case it would be really simple, just have a single process running on a server somewhere that receives messages from a queue and then grabs the email data out of them and sends. Clients could probably just fire-and-forget. There are a variety of ways to handle exceptions, and here's some ideas.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
Can you make an assembly you share between both projects which defines the common classes, and subclass in either as necessary?

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
I had a slightly easier time implementing WCF when I decided to create my own client channel factory rather than letting VS autogenerate the client.

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
What kind of trouble are you having? What do you need to do with the KML files?

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

fadderman posted:

Entity Framework don't work nativly on windows phone so if i should use EF i would need to program a server app, then a api and last i would have to program a way for the phone to use the api i created. That a lot of work, and i am not that familier with C# either so keeping everything locally is a lot easier

Okay, so you need to manipulate an XML document with a known and documented format. What trouble are you running into?

Adbot
ADBOT LOVES YOU

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

PhonyMcRingRing posted:

It's almost as bad as video coding examples.

A friend of mine defended these by saying he was a "visual learner." I recognize that some people genuinely learn better by watching an example, but typing code into an editor? :what:

  • Locked thread