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
some kinda jackal
Feb 25, 2003

 
 
This may be something simple but I haven't dealt with it before.

I've got to integrate a site's look and feel into our company's client pages. Basically this means using a WebRequest to get the HTML content of a header and footer, we then insert our HTML content in between.

This is relatively simple. I've created a class library which I reference in all our client projects. This class library contains several public methods, two of which are GenerateHeader and GenerateFooter. I feed the string output of these methods to two <asp:literal> tags on our client pages. Voila, a header and footer.

Right now I have the Header and Footer generating URL hardcoded in the class library, but I'd like to move it outside to some sort of config file so I can change it if need-be, or point to a staging server, or whatever may come up. Ideally this would be stored in one place on the server so I don't have to change a config file for every app.

Our client pages are deployed to a server as subwebs of a main website. Each have their own web.config which I could use, but again I want to stay away from having to change the URL in 100 different locations if we have a URL change.

So aside from actually putting this in each app's web.config and calling the Generate methods with the URL as a parameter, is there a better way I can go about this?

Adbot
ADBOT LOVES YOU

wwb
Aug 17, 2004

^^^^^^What you are looking for here is a Configuration Service. Basically, your app references a web service which serves back the proper version of your configuration data.

Frank Butcher posted:

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.

Yes, you can compile multiple languages in the same solution. You will want to have the C# stuff in a separate project, AFAIK. Once compiled, none of the code will be the wiser--it is all CLR as far as .NET is concerned.

Also, with 2.0, you can use multiple languages within the same website.

some kinda jackal
Feb 25, 2003

 
 

wwb posted:

^^^^^^What you are looking for here is a Configuration Service. Basically, your app references a web service which serves back the proper version of your configuration data.

Beautiful, thank you kind sir I will investigate this as soon as I get back to work!

BryanGT
Oct 15, 2002

Goodnight, sweet prince.

dcsmrgun posted:

Our client pages are deployed to a server as subwebs of a main website. Each have their own web.config which I could use, but again I want to stay away from having to change the URL in 100 different locations if we have a URL change.

If these apps are all on one (or a few) server, it'd be easier to just add the config key to the machine's web.config.

%windir%\Microsoft.NET\Framework\v2.0.50727\CONFIG\Web.Config

Remove the key from all the web.configs on the server, and add it to this file. After that: all the web applications on the server will inherit that key, and you can maintain it in one place.

fankey
Aug 31, 2001

Does anyone know about how to get nice looking drag icons when using DragDrop.DoDragDrop()? I've implemented DnD in my own WPF app but all I get are the generic DragDropEffects cursors. I'd really like to get something that looks like dragging stuff from the Explorer in Vista, but it doesn't necessarily need to span apps - if it just worked within my app that'd be great. Here's a simple DnD implementation which allows dragging from one of the color rectangles on the left to the canvas on the right but only gets the crappy cursors.

code:
  class MyCanvas : System.Windows.Controls.Canvas
  {
    public MyCanvas()
    {
      this.AllowDrop = true;
      this.Background = Brushes.AliceBlue;
    }
    protected override void OnDragOver(DragEventArgs e)
    {
      base.OnDragOver(e);
    }
    protected override void OnDrop(DragEventArgs e)
    {
      System.Windows.Shapes.Rectangle rc = e.Data.GetData("System.Windows.Shapes.Rectangle") as System.Windows.Shapes.Rectangle;
      if (rc != null)
      {
        Background = rc.Fill;
      }
      base.OnDrop(e);
    }
  }

  class MyListView : StackPanel {
    public void add_rect( Brush brush ) 
    {
      System.Windows.Shapes.Rectangle rc = new System.Windows.Shapes.Rectangle();
      rc.Height = 32;
      rc.Fill = brush;
      rc.MouseDown += new System.Windows.Input.MouseButtonEventHandler(rc_MouseDown);
      rc.Margin = new Thickness(10);
      Children.Add(rc);
    }

    void rc_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
      DragDrop.DoDragDrop(this, new DataObject(sender), DragDropEffects.All);
    }
    public MyListView()
    {
      add_rect(Brushes.BlanchedAlmond);
      add_rect(Brushes.DarkKhaki);
      add_rect(Brushes.DarkOrange);
      add_rect(Brushes.HotPink);
    }
  }

  class Program
  {
    [STAThread]
    static void Main(string[] args)
    {
      Window win = new Window();
      win.Title = "woohoo";
      Grid grid = new Grid();
      grid.ColumnDefinitions.Add(new ColumnDefinition());
      grid.ColumnDefinitions.Add(new ColumnDefinition());
      grid.RowDefinitions.Add(new RowDefinition());
      MyListView tv = new MyListView();
      Grid.SetColumn(tv, 0);
      grid.Children.Add(tv);
      MyCanvas c = new MyCanvas();
      Grid.SetColumn( c, 1 );
      grid.Children.Add(c);
      win.Content = grid;
      win.Show();
      Application app = new Application();
      app.Run();
    }
  }

Grid Commander
Jan 7, 2007

thank you mr. morrison
I have a little chunk of code that launches a cmd process.
I want all of the input and output redirected from a network stream.
I remember being able to do this redirection one time before, but it was a few years ago and I've forgotten how I did it.

Any ideas?

static void Main(string[] args)
{
TcpListener client = new TcpListener(23);
client.Start();
Socket sock = client.AcceptSocket();
NetworkStream myNetworkStream = new NetworkStream(sock);
StreamReader myStreamReader = new StreamReader(myNetworkStream);

Process p = new Process();
ProcessStartInfo si = new ProcessStartInfo();
si.FileName = @"C:\WINDOWS\system32\cmd.exe";
si.Arguments = "/k";
si.RedirectStandardError = true;
si.RedirectStandardOutput = true;
si.RedirectStandardInput = true;
si.UseShellExecute = false;
p.StartInfo = si;

//begin -- this doesn't work because these are read only
p.StandardInput = myNetworkStream;
p.StandardOutput = myNetworkStream;
p.StandardError = myNetworkStream;
//end -- this doesn't work because these are read only

p.Start();
p.WaitForExit();
}

csammis
Aug 26, 2003

Mental Institution
Grid Commander, you have to create your redirection streams from the process streams, not the other way around, like so:

code:
StreamWriter myStreamWriter = myProcess.StandardInput;
For a NetworkStream, you may have to wrap a System.IO stream around the process streams and pipe the output manually, I'm not sure.

poopiehead
Oct 6, 2004

Frank Butcher posted:

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.

Besides what was already mentioned, there are a bunch of guidelines that you should follow to make sure that they will work across all languages. This has nothing to do with internal code, only externally accessible things. The most important thing would be to not have identifiers in C# differ only by case, because VB wouldn't be able to make sense of it.

I couldn't find a good link but found this from an old class web page.
guidelines

Mind Riot
Aug 6, 2006

by Fragmaster
Reposting from another thread:

I've got a program I've been working on that I'm developing a very basic Login control for, and I'm trying to keep the control as reusable as possible.

Now I want the program to be able to set the login control to use one of the program's own functions to validate the username and password, instead of building that logic into the control itself.

I'm doing this in C#, so I believe I need to use a delegate, but I'm really not to sure how it'd work in this situation. Any ideas?

poopiehead
Oct 6, 2004

Mind Riot posted:

Reposting from another thread:

I've got a program I've been working on that I'm developing a very basic Login control for, and I'm trying to keep the control as reusable as possible.

Now I want the program to be able to set the login control to use one of the program's own functions to validate the username and password, instead of building that logic into the control itself.

I'm doing this in C#, so I believe I need to use a delegate, but I'm really not to sure how it'd work in this situation. Any ideas?

I can see two ways that are pretty much the same.

1) Add a TryLogin event to the login control. The implementing page can add a delegate to the event. When a login is attempted, fire the event and pass a reference to the login control as a parameter. Then the delegate can set a public IsLoggedIn or LoggedInUerId property when it gets called.

2) Create a delegate. Something with a signature like "bool TryLogin(string username,string pass)". Then have a public property of the type of that delegate. The implementing page can set the property. When a user attempts to log in, use the provided delegate to perform the login.

wwb
Aug 17, 2004

^^^Those are basically the same thing. The event is essentially a specifically formed delegate.

That said, you should try using an event, passing something like (object sender, LoginEventArgs e). LoginEventArgs should have whatever info you need to pass to do the login. And you could make it neato by adding a boolean for, say, LoginSuccessful. That way you can pass off to the delegate, which can set LoginSuccessful=true when the login is successful. Small scale IOC baby.

poopiehead
Oct 6, 2004

wwb posted:

^^^Those are basically the same thing. The event is essentially a specifically formed delegate.

poopiehead posted:

I can see two ways that are pretty much the same.

;)

wwb
Aug 17, 2004

Hehe. I claim the "before morning coffee" disclaimer.

Now, I am just remembering what an utter piece of poo poo VS 2003 is. Even with resharper. Especially when dealing with web projects you just recovered off a dead hard drive and it refuses to read the web projects. Geh.

Richard Noggin
Jun 6, 2005
Redneck By Default
C#/.NET 2.0: How do I get the user's profile path? I've looked at Environment.GetFolderPath(Environment.SpecialFolder.<whatever>, but I'm not seeing anything that returns the root of the profile path like the %userprofile% environment variable would. I could hack something together that strips off the extraneous path info, but I'd like to avoid that if possible.

csammis
Aug 26, 2003

Mental Institution

Richard Noggin posted:

C#/.NET 2.0: How do I get the user's profile path? I've looked at Environment.GetFolderPath(Environment.SpecialFolder.<whatever>, but I'm not seeing anything that returns the root of the profile path like the %userprofile% environment variable would. I could hack something together that strips off the extraneous path info, but I'd like to avoid that if possible.

Should I even ask why your application wants to know where %userprofile% is? There's a reason it's not a standard special folder :)

code:
Environment.ExpandEnvironmentVariables("%userprofile%");

Richard Noggin
Jun 6, 2005
Redneck By Default
Sure, you can ask. I'm using Rendezvous Proxy to allow me to connect my iTunes library at home. I have a dynamic IP and use a dynamic DNS service. Rendzvous allows you to enter a host name in the config, but it's converted and stored as an IP address from there on out. So, whenever my IP changes (daily, if not more), I have to go update Rendezvous. I'm writing a little app that will do a DNS lookup of my hostname and rewrite Rendezvous' config file (which is stored in %userprofile%) with the correct IP.

I could just make it so that the user has to enter the path to the config file, but I like having things done for me automagically.

Out of curiosity, why isn't it a special folder?

csammis
Aug 26, 2003

Mental Institution

Richard Noggin posted:

Out of curiosity, why isn't it a special folder?

Because nothing is supposed to reside in %userprofile% except for NTUSER.dat and the subfolders that make up %appdata%, the desktop, documents, etc. I suppose iTunes stores it there because it's the closest equivalent to the UNIX ~ that you can get on a Windows computer.

SLOSifl
Aug 10, 2002


I'm working on a little proof of concept for a plugin activation system and have a question.

<I just typed up a shitload of backstory and explanation and deleted it because it's irrelevant>

Can I modify an existing assembly using the Reflection.Emit namespace? I can easily generate an assembly in code, but want to roll another existng assembly in as well. In other words, I want to copy a few classes that are already compiled into a custom assembly that I am building procedurally.

Goon Matchmaker
Oct 23, 2003

I play too much EVE-Online
Are there any open source asp.net 2.0 (1.1 would work but 2.0 is preferred) E-Commerce apps out there?

Grid Commander
Jan 7, 2007

thank you mr. morrison
I looked for a while to try and find some *good* open source e-commerce app in .net or .net 2.0 but I had no luck with this.

I didn't really want to spend time writing my own, so....

Eventually, I broke down and just installed apache, mysql, php, and oscommerce on my windows box. Basically this is a lamp stack except it is on windows. So far it works wonderfully, plus I get the added benefit of an OS that doesn't need as much memory (clean XP Home install -- fully patched), and an OS that I am more familiar with.

Note that if you go this route, then I would suggest purchasing a good book on apache/mysql/php like "Beginning PHP and MySql 5" that will help you get the stuff installed.

On a side note -- I think it might be possible to host php on IIS? There might even be a php variant that targets MSIL. I didn't research that much though, so I can't say for sure.

Be prepared to spend a day or two figuring out how to get the install just right. I like Linux, but Linux application documentation seems to go out of date rather quickly ... and so it can be misleading.

Alternatively, just send me a message and I'll help you avoid the pain that I went through.

Anyway, good luck.

poopiehead
Oct 6, 2004

Grid Commander posted:

On a side note -- I think it might be possible to host php on IIS? There might even be a php variant that targets MSIL. I didn't research that much though, so I can't say for sure.

It can definitely be installed on IIS.

http://www.php.net/downloads.php

edit:

the above link is just to run on windows. The cgi version is what runs on IIS:

http://us2.php.net/security.cgi-bin

poopiehead fucked around with this message at 21:16 on Jan 18, 2007

wwb
Aug 17, 2004

E-Commerce: not really, OTOH, check out MS' starter kits, they have a web store one. I would note that .NET gives you so much out of the box, compared to PHP, that writing one from scratch is not as serious an undertaking as it would be in some other environments.

PHP runs fine on IIS, probably better than apache does on windows.

biznatchio
Mar 31, 2001


Buglord

Grid Commander posted:

On a side note -- I think it might be possible to host php on IIS? There might even be a php variant that targets MSIL. I didn't research that much though, so I can't say for sure.

Here's a pretty mature PHP compiler for .NET: http://www.php-compiler.net/doku.php

It allows you to create webpages in the traditional PHP manner, and also allows you to just use PHP as a language within ASP.NET instead, if so desired. You can also use it to run and/or compile PHP scripts as applications. It can also use PHP4 binary extensions.

It's supported on the Framework on Windows, and on Mono; and benchmarks have its performance as several times faster than PHP itself.

biznatchio fucked around with this message at 13:50 on Jan 18, 2007

Dromio
Oct 16, 2002
Sleeper
I have a "rookie" sort of question. I want an object to know information about it's parent. For example:

code:
class ParentObject
{
   ChildObject MyChild = new ChildObject();
   public string MyInfo = "This is important to the child.";
}

class ChildObject
{
   public string GetParentInfo()
   {
      ParentObject MyParent = new ParentObject(); 
      return ParentObject.MyInfo;
   }
}
My real situation is somewhat more complex, but it boils down to this. If ChildObject is "owned" by a ParentObject, I want to be able to get information from the Parent. What are my options?

So far I've been had a field in ChildObject which references the ParentObject and I'm using a special constructor to set the value. But this is causing some issues with Serialization and I'd like to be able to do something else. Is there special voodoo that might help me?

csammis
Aug 26, 2003

Mental Institution

Dromio posted:

I have a "rookie" sort of question. I want an object to know information about it's parent. For example:

...

Is there special voodoo that might help me?

Having a real object hierarchy would help, because both C# and Java have keywords ("base" and "super," respectively) that allow this sort of child->parent access.

If that's not possible for whatever reason, you could expose a property on the "child" in which you set the "parent" reference rather than doing it via the constructor, which would make serialization happy by maintaining the parameterless constructor.

Dromio
Oct 16, 2002
Sleeper
As far as I know, "base" relates to inheritance. I'm looking more for what the owner is (as my sample shows) regardless of inheritance.

I've been doing as you mentioned, where the ChildObject class contains a field of type ParentObject and I can set it either during construction or a method. But I'm looking for something more automatic.

Actually, another part of my problem is that I'm using System.Runtime.Serlialization and the BinaryFormatter, and it does NOT call the default constructors. And for some reason, it doesn't seem to be serializing the field properly.

Edit: Here's a better sample:

code:
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

[Serializable()]
public enum LocalizedTextTypes {
        DisplayText,
        Definition //And there are more
}

[Serializable()]
public class Step
{
  StepTextCollection StepTexts;
}

[Serializable()]
public class StepTextCollection : Dictionary<LocalizedTextTypes, LocalizedStepText>, ISerializable
{
  private string _otherStuff;  //This is serialized fine
  private Step _ParentStep;    //This is not.
  public Step(Step ParentStep)
  {
    _Parent = ParentStep; 
  }

  //Since we're inheriting from System.Collections.Generic.Dictionary, we have to
  //  provide the serializer's constructor.
  public StepTextCollection(SerializationInfo info, StreamingContext context) : base(info, context)
  {
  }
}
When serializing/deserializing the StepTextCollection objects, it's ignoring the _ParentStep field, but it's handling _otherStuff fine.

Dromio fucked around with this message at 22:13 on Jan 18, 2007

Victor
Jun 18, 2004
Dromio, are you aware that you can type [Serializable] instead of [Serializable()]? The former looks prettier to me, dunno about you.

Dromio
Oct 16, 2002
Sleeper

Victor posted:

Dromio, are you aware that you can type [Serializable] instead of [Serializable()]? The former looks prettier to me, dunno about you.

Thanks, it does look prettier :)

I was wrong about it also serializing the _otherStuff string, it wasn't. It looks like it's only using the serialization for it's base object, System.Collections.Generic.Dictionary. So, I have to write my own routines to serialize and deserialize the extra bits that I've added. I see a light at the end of my tunnel.

But I'd still be interested if there was any other way to keep up with a variable's "owner" like my original question.

Victor
Jun 18, 2004

Dromio posted:

But I'd still be interested if there was any other way to keep up with a variable's "owner" like my original question.
Do you have a collection of the children? If so, you can build a customized collection that takes the parent in its constructor; the Add method would assign the parent to children.

Essential
Aug 14, 2003
Hey all I have some very basic Asp.net questions (I just started getting into Asp.net but I have a vb6/vb.net 2005 background). I have been using vs 2005 for the last 2 years or so.

I'm having a hard time finding an online tutorial that explains how to design and set up a good web form. It's easy for desktop apps, either I use the visual designer or use code to place objects.

So now trying to build decent looking web apps I'm not sure how to place stuff on the form. I'm pretty sure it has to be done in code, not sure if it's done in style sheets, or in the <form></form> code or in the <div> code <asp:button maybe location stuff goes here??>? One of the tutorial's I went through had me adding stuff with a table object, but I thought that table's were not to be used nowadays?

What's making things harder is I'm picturing my web app to look almost identical to my desktop app but I know that the look will change drastically, I just can't help but see it that way.

I understand about master pages and that seems to work good for the menu but it's placing all the labels,text boxes, etc. that I'm having trouble with.

I'm not sure I'm making much sense here so I think I can sum it up with: How do I align stuff up and make everything look pretty and does anyone have a screenshot of a webapp they have created that is similar to a desktop app?

edit: just wanted to also ask if you guys use master pages, app_themes, or css? I may be confused but does the app_theme stuff replace css or not? And the website asp.net has a shitload of info, that a pretty good site to learn from?

Essential fucked around with this message at 08:05 on Jan 19, 2007

poopiehead
Oct 6, 2004

Essential posted:

Hey all I have some very basic Asp.net questions (I just started getting into Asp.net but I have a vb6/vb.net 2005 background). I have been using vs 2005 for the last 2 years or so.

I'm having a hard time finding an online tutorial that explains how to design and set up a good web form. It's easy for desktop apps, either I use the visual designer or use code to place objects.

So now trying to build decent looking web apps I'm not sure how to place stuff on the form. I'm pretty sure it has to be done in code, not sure if it's done in style sheets, or in the <form></form> code or in the <div> code <asp:button maybe location stuff goes here??>? One of the tutorial's I went through had me adding stuff with a table object, but I thought that table's were not to be used nowadays?

What's making things harder is I'm picturing my web app to look almost identical to my desktop app but I know that the look will change drastically, I just can't help but see it that way.

I understand about master pages and that seems to work good for the menu but it's placing all the labels,text boxes, etc. that I'm having trouble with.

I'm not sure I'm making much sense here so I think I can sum it up with: How do I align stuff up and make everything look pretty and does anyone have a screenshot of a webapp they have created that is similar to a desktop app?

Are you familiar with HTML? I've never seen an editor for web pages that works like the VS Form Designer and actually works well.

Essential
Aug 14, 2003

poopiehead posted:

Are you familiar with HTML? I've never seen an editor for web pages that works like the VS Form Designer and actually works well.

I'm familiar with the basics, although it's been a long, long time since I have even touched the stuff. Is most formatting done using standard html? That is to say using vs I assume then the html goes in the asp page file.

Those of you who use vs do you even bother with the designer? For example if you are building a form with 5 textboxes and 2 buttons do you go straight to the source code and manually add them there, including your html placement code or do you add them using the designer and let it generate the basic code, then go to the source code and add what you need?

Ok so it appears to me that most of the webform design stuff happens with html/css which is utilized by asp.net and therefore what I'm really looking for is an html/css primer?

Also I must be a real jerk to not realize I would need html/css for formatting

Essential fucked around with this message at 08:59 on Jan 19, 2007

poopiehead
Oct 6, 2004

Essential posted:

Also I must be a real jerk to not realize I would need html/css for formatting

I think MS did intend for people to use the designer, especialy coming from an app dev point of view. So it wasn't a ridiculous assumption. You definitely need to know HTML to work with it effectively, though.

I like w3schools for quick overviews. Here's a tutorial

I'd definitely try to get to the point where I can lay out a simple flat web page in html before diving into asp .net. Most introductory asp .net stuff assumes programming experience, which you do have, and html experience, which you will.

Essential
Aug 14, 2003

poopiehead posted:

I like w3schools for quick overviews. Here's a tutorial

Awesome, thanks for the link poopiehead, that should help a lot.

Victor
Jun 18, 2004

poopiehead posted:

I like w3schools for quick overviews. Here's a tutorial
Might I suggest the XHTML version?

csammis
Aug 26, 2003

Mental Institution

Dromio posted:

As far as I know, "base" relates to inheritance. I'm looking more for what the owner is (as my sample shows) regardless of inheritance.


Yes it does relate to inheritance, which is why I said it; I was confused by your "parent" and "child" descriptions in the simple example. Victor's suggestion about extending a collection class to do the property assigning is a good one.

Goonamatic
Sep 17, 2005
cunning linguist
Any know of an open source bittorrent client written in c#?

csammis
Aug 26, 2003

Mental Institution

Goonamatic posted:

Any know of an open source bittorrent client written in c#?

I believe there's a goon working on one. jonnii?

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Dromio posted:

But I'd still be interested if there was any other way to keep up with a variable's "owner" like my original question.
I have no idea what the answer might be, but unless I'm missing something, you're asking if an object can know when it is a member variable of a different object, and somehow access information about that object.

So given your first example of ParentClass and ChildClass, you might have code that did something like:
code:
ParentObject theParent = new ParentObject();
string parentInfo = theParent.MyInfo;
string childInfo = theParent.MyChild.GetParentInfo();
Console.WriteLine(parentInfo);
Console.WriteLine(childInfo);
and you'd get
code:
This is important to the child.
This is important to the child.
It seems to me that Victor's idea of using a constructor is the best idea. If you just wanted a ChildClass object to always know what it's a member of, then what happens if you make a ChildClass object that isn't a member of anything? And if you would never, ever, ever do that, then why would you ever want to access the Parent through the Child when you'll always have the Parent sitting around?

Adbot
ADBOT LOVES YOU

fankey
Aug 31, 2001

What's a good technique to inspect/interact with the Garbage Collector so I can make sure I don't have any dangling references hanging out there. I've looked at System.GC and there doesn't appear to be a way to list the objects that are ready for collection. At certain points in my code I should be 'releasing' all references to particular objects - I'd just like to verify that it's actually happened.

Commercial tools are fine if they work well.

  • Locked thread