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
JediGandalf
Sep 3, 2004

I have just the top prospect YOU are looking for. Whaddya say, boss? What will it take for ME to get YOU to give up your outfielders?

FinkieMcGee posted:

Basically we store each table as a datatable in a big Dictionary. Is this reasonable at all? I'm noticing a huge performance difference between going to our cached table, and going to the database for the same information. Going to the cache takes TWICE as long as going to the database!

Now I know that there is ACTUAL ASP.net caching, should I be using that, or is that not going to really yield a difference?
I'm curious to know how you're persisting this Dictionary object across pages/postbacks, if you're throwing this in the ViewState I'm going to hit you. Anyway, the cache is there to grab the same data over and over again without the overhead of making a DB call. The data in the cache shouldn't be large (i.e. no texts). If you have optimized queries and proper indexes in place, you probably won't even need the cache as DB calls would be very quick.

Moral of the Post: I'd use the ASP.NET caching instead of your all-in-one Dictionary and I'd use the cache where necessary.

Adbot
ADBOT LOVES YOU

FinkieMcGee
May 23, 2001

Look, I have to go identify our dead father's body. I'm sorry you're having a bad drug experience, but deal with it.

mintskoal posted:

There's really no good reason to be storing the tables in the cache. Use straight LINQ or SQL calls. I'm positive you're not under enough load to warrant using caching.

Just out of curiosity, how large are these tables and how much use is this app getting?

I agree, for the time being the application isn't being used enough to justify caching, but we're trying to get it to a point where there are several thousand users hitting it, and it is a pretty database heavy cache.

Some of the tables are small, but some of the tables (and the views especially) are really big. The app is database heavy.

And don't hit me, I didn't write this crap! It's persisted as a static dictionary across the application, I may just switch it over to the ASP caching (no one here really has a lot of experience with caching, I maybe have the most and I'm a rookie) so I need to put together a case to modify it before I start touching that stuff.

uXs
May 3, 2005

Mark it zero!

FinkieMcGee posted:

C#/ASP.NET Caching question, as I'm a rookie and I'm trying to understand what the hell is going on.

So we have a database and we store lookup and mapping tables from there in our cache. Now, the way we cache in our database is kind of... odd, I think.

Basically we store each table as a datatable in a big Dictionary. Is this reasonable at all? I'm noticing a huge performance difference between going to our cached table, and going to the database for the same information. Going to the cache takes TWICE as long as going to the database!

Now I know that there is ACTUAL ASP.net caching, should I be using that, or is that not going to really yield a difference?

The way I used caching in this app I made is the following: everything (*) I read from the database is put in custom objects and generic lists of those objects. They got bound to dropdownlists and what have you with objectdatasources. Now for some dropdownlists that I needed a lot, I created a cache object that had functions to retrieve the lists from the cache (or retrieved them from the database and put them in the cache first if it didn't exist yet or was expired.)

So where normally it would ask some class to retrieve a list from the database, for those lists it would ask my cache class to retrieve the list from the cache. I don't really know if that improved performance really, but it was a neat thing to do :v:

Now I'm not really clear on how you're doing it. You're storing each table as a table in a Dictionary, but then what do you do with that Dictionary ? Are you putting that in the cache and retrieving it all the time ?

(*: There were, naturally, exceptions on this.)

Edit: ^^ Wait. That Dictionary is just in some static class ? I'm not 100% sure, but I think it's possible that the Dictionary is being recreated for every single call to the webserver. I doubt that it's persisted through postbacks, let alone sessions.

uXs fucked around with this message at 00:19 on Mar 19, 2008

FinkieMcGee
May 23, 2001

Look, I have to go identify our dead father's body. I'm sorry you're having a bad drug experience, but deal with it.
Just so you guys know, I'm noticing a big speed difference between doing Datatable selects (like we were doing) and using FindAll/Find in a generic list.

My old company did the objects stored in a cache, but no one here is familiar with caching, so it's a work in progress. Thanks for the advice.

Pivo
Aug 20, 2004


More questions. I wish I wasn't the only C# guy here at work. :( Sorry dudes. If you don't know off the top of your head don't go out of your way, I've been Googlin' for a while.

code:
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://buffed.baldhead.com/buster.wpf_backend/media/eclogo.jpg");
wr.IfModifiedSince = DateTime.Now;
WebResponse res = wr.GetResponse();
string lm = res.Headers[HttpResponseHeader.LastModified];
The file was modified 3/19/2008 20:50:37 GMT as indicated by res.Headers, but IfModifiedSince was set to 3/19/2008 21:57:31 GMT at the time of this post, and the server responds with the full JPG.

Is this a server config issue, or am I doing it wrong?

Potassium Problems
Sep 28, 2001
Looking at the MSDN page for IfModifiedSince, this comment was at the bottom, maybe this is ties into your problem?

quote:

These samples are fundamentally wrong. They're been written with the premise that IfModifiedSince on a web request is somehow the modification date of the file on the server. It isn't -- the request hasn't even been sent to the server yet.
This is how it's actually used:

1. You set IfModifiedSince on a request
2. You get a response with GetResponse()
3. (a) If the file hasn't been modified since the DateTime you set, the server returns the status code HttpStatusCode.NotModified, which is an error code, so the call throws a WebException. -or- (b) If it has been modified, the server returns the status code HttpStatusCode.Ok, and you can proceed as normal and handle the reponse stream.

Grigori Rasputin
Aug 21, 2000
WE DON'T NEED ROME TELLING US WHAT TO DO
I have a dropdown list and a listbox in an ASP app. At runtime, I want the user to be able select several names from the dropdown list and move them into the listbox. When the user has finished filling out the form, I want their selections to be submitted back to the DB and be recorded.

Here is my problem - the names are stored in the DB via their "NameID", which is the same as the value attribute in the dropdownlist (<option value=1... <option value=2... etc). When the user dumps the names into the listbox, these ID values are lost - there are ways I can get them back but not without a wimpy hack.

What's the best/most correct/righteous/efficient way to preserve this value between controls in ASP.NET?

wwb
Aug 17, 2004

These days, you should probably be handling that fully client-side with ajax. But, from a .NET perspective, both DropDownLists and ListBoxes implement IListControl, so you could actually pass the list items between the two pretty easily. What you need to do is:

1) Grab the selected value from the DDL.
2) Find the appropriate list item that matches said selected value.
3) Remove it from DDL's Items collection
4) Add it to LB's Items collection
5) gently caress a duck
6) Profit.

No Pants
Dec 10, 2000

Is there a way to get the names of the files contained in an IIS-hosted web site's browseable directory? I would create a web service to do it if I had access, but I don't.

Edit: Figured it out. Now to re-learn regular expressions. :(

No Pants fucked around with this message at 16:49 on Mar 20, 2008

zero87t
Mar 8, 2004
Does anyone know of a way to populate a DataGridView with data from an excel file using C#.

I can do it in VB but I am just learning C# and seem to be hung up somewhere on syntax.

Pivo
Aug 20, 2004


Lone_Strider posted:

Looking at the MSDN page for IfModifiedSince, this comment was at the bottom, maybe this is ties into your problem?

Unfortunately not. I noticed the example was wrong, they were using compare on a datetime and ifmodifiedsince, which is really weird, because obviously how would the class know what the mod date is before it makes a request.

Is-Modified-Since is an HTTP header that makes a server respond with a specific code if the file has not been changed since the If-Modified-Since date. It's so you don't have to download the whole file just to check for an updated version. For some reason, the header is being ignored in my case. The webserver is just a default Apache install and I'm pretty sure it supports the header, it's in HTTP/1.1 specs.

Dromio
Oct 16, 2002
Sleeper

Pivo posted:

Unfortunately not. I noticed the example was wrong, they were using compare on a datetime and ifmodifiedsince, which is really weird, because obviously how would the class know what the mod date is before it makes a request.

Is-Modified-Since is an HTTP header that makes a server respond with a specific code if the file has not been changed since the If-Modified-Since date. It's so you don't have to download the whole file just to check for an updated version. For some reason, the header is being ignored in my case. The webserver is just a default Apache install and I'm pretty sure it supports the header, it's in HTTP/1.1 specs.

I'm pretty sure it's the server. When I run your code against an image on my IIS site, GetResponse() throws a WebException -- "The remote server returned an error: (304) Not Modified." But if I run it against my apache2 server at home, it does not.

Dromio fucked around with this message at 14:41 on Mar 20, 2008

Pivo
Aug 20, 2004


Dromio posted:

I'm pretty sure it's the server. When I run your code against an image on my IIS site, GetResponse() throws a WebException -- "The remote server returned an error: (304) Not Modified." But if I run it against my apache2 server at home, it does not.

Bizzzzzzaaare. Thank you!

Grigori Rasputin
Aug 21, 2000
WE DON'T NEED ROME TELLING US WHAT TO DO

wwb posted:

These days, you should probably be handling that fully client-side with ajax. But, from a .NET perspective, both DropDownLists and ListBoxes implement IListControl, so you could actually pass the list items between the two pretty easily. What you need to do is:

1) Grab the selected value from the DDL.
2) Find the appropriate list item that matches said selected value.
3) Remove it from DDL's Items collection
4) Add it to LB's Items collection
5) gently caress a duck
6) Profit.

Thank you, I was trying to do this with ListItem and thought that I had done so - it turns out I was doing .add(blahitem.toString()) and that of course will not achieve what I want.

notflipmo
Feb 29, 2008
'
C# + .NET 3.5

I'm having some conundrums with regular expressions in my app.
I have a string containing essentially the following:

"lots of text and newline characters 2008-03-20 849.63 MB 7.71 GB 8.54 GB 2008-03-19 896.02 MB 4.44 GB 5.31 GB 2008-03-18 668.67 MB 1.28 GB 1.93 GB 2008-03-17 212.83 MB 16.35 MB 229.18 MB 2008-03-16 5.66 GB 8.49 GB 14.15 GB 2008-03-15 361.12 MB 2.39 GB 2.75 GB 2008-03-14 936.02 MB 2.38 GB 3.30 GB some more text and newline characters"
(The above are internet transfer stats from my ISP, date + in + out + total)

By using:

@"(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])"
and
@"([0-9]{1,3}\.[0-9]{2}\s(MB|GB))"

...I can match for example "2008-03-19" and "896.02 MB" respectively, but for the life of me I can't match "2008-03-19 896.02 MB".

Ultimately I would like to match each date together with the corresponding 3 transfer amounts, resulting in strings "2008-03-19 896.02 MB 4.44 GB 5.31 GB", "2008-03-18 668.67 MB 1.28 GB 1.93 GB" etc.

Any help on how I can combine the two working expressions? I've readin every regex resource I can find but I just can't work it :smithicide:

notflipmo fucked around with this message at 01:53 on Mar 21, 2008

FrantzX
Jan 28, 2007
code:
Regex r1 = new Regex(@"(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])");
Regex r2 = new Regex(@"([0-9]{1,3}\.[0-9]{2}\s(MB|GB))");
String input = @"2008-03-20 849.63 MB 7.71 GB 8.54 GB 2008-03-19 896.02 MB";

Match m1 = r1.Match(input);
Match m2 = null;

if (m1.Success == true)
{
	m2 = r2.Match(input, m1.Index + m1.Length);
	if (m2.Index != m1.Index + m1.Length + 1) m2 = null;
}
if m1 & m2 are not null, there's your match.

FrantzX
Jan 28, 2007

FrantzX posted:

code:
Regex r1 = new Regex(@"(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])");
Regex r2 = new Regex(@"([0-9]{1,3}\.[0-9]{2}\s(MB|GB))");
String input = @"2008-03-20 849.63 MB 7.71 GB 8.54 GB 2008-03-19 896.02 MB";

Match m1 = r1.Match(input);
Match m2 = null;

if (m1.Success == true)
{
	m2 = r2.Match(input, m1.Index + m1.Length);
	if (m2.Success == false || m2.Index != m1.Index + m1.Length + 1) m2 = null;
}
if m1 & m2 are not null, there's your match.

Potassium Problems
Sep 28, 2001

notflipmo posted:

Ultimately I would like to match each date together with the corresponding 3 transfer amounts, resulting in strings "2008-03-19 896.02 MB 4.44 GB 5.31 GB", "2008-03-18 668.67 MB 1.28 GB 1.93 GB" etc.

Any help on how I can combine the two working expressions? I've readin every regex resource I can find but I just can't work it :smithicide:
\d{4}-\d{2}-\d{2}\s(\d*\.\d*\s(MB|GB)\s*){3}

when ran against your sample above, it returned

code:
2008-03-20 849.63 MB 7.71 GB 8.54 GB
2008-03-19 896.02 MB 4.44 GB 5.31 GB
2008-03-18 668.67 MB 1.28 GB 1.93 GB
2008-03-17 212.83 MB 16.35 MB 229.18 MB
2008-03-16 5.66 GB 8.49 GB 14.15 GB
2008-03-15 361.12 MB 2.39 GB 2.75 GB
2008-03-14 936.02 MB 2.38 GB 3.30 GB

Potassium Problems fucked around with this message at 02:56 on Mar 21, 2008

notflipmo
Feb 29, 2008
'
Oh wow, thanks guys.

Figured out my problem, original string has two whitespace characters between each date and transfer amount. Your suggestions and the way HTML ignores multiple whitespaces when I posted it to the forums provided me with an early morning epiphany.

Final regex is as follows:
(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])(\s\s[0-9]{1,3}\.[0-9]{2}\s(MB|GB)){3}

..which matches everything like a champ. :woop:

notflipmo fucked around with this message at 12:07 on Mar 21, 2008

DemiShadow
Oct 19, 2002
I feel retarded asking this, but I can't find a way to google it to get a good answer.

In visual studio 2005, how do you get the property description in the properties box to show up when it is gone? I have tried dragging up from the bottom of the properties box, but I can't get the descriptions to show up. It's a very simple problem, but it's kinda bothering me.

Edit: Looks like it was just one of those dumb things visual studio does. Restarting the program got it back. I guess I should shut up and reboot before asking stupid questiongs.

DemiShadow fucked around with this message at 12:26 on Mar 21, 2008

notflipmo
Feb 29, 2008
'

DemiShadow posted:

I feel retarded asking this, but I can't find a way to google it to get a good answer.

In visual studio 2005, how do you get the property description in the properties box to show up when it is gone? I have tried dragging up from the bottom of the properties box, but I can't get the descriptions to show up. It's a very simple problem, but it's kinda bothering me.

Edit: Looks like it was just one of those dumb things visual studio does. Restarting the program got it back. I guess I should shut up and reboot before asking stupid questiongs.
In any case, in VS2008, right-clicking anywhere inside the properties box brings up a "Reset | Commands | Descriptions" menu which lets you toggle the decription-box.

Dromio
Oct 16, 2002
Sleeper
Anyone see what I'm doing wrong with log4net in my ASP.NET project? I've got three loggers defined in the web.config:

code:
<log4net>
    <!-- Output appenders -->
    <appender name="OutputDebugStringAppender" type="log4net.Appender.OutputDebugStringAppender">
	<layout type="log4net.Layout.PatternLayout">
	    <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"/>
	</layout>
    </appender>
    <!-- Loggers -->
    <logger name="ServiceCallsLogger">
      <level value="DEBUG"/>
      <appender-ref ref="OutputDebugStringAppender"/>
    </logger>
    <logger name="UserLogger">
      <level value="DEBUG"/>
      <appender-ref ref="OutputDebugStringAppender"/>
    </logger>
    <logger name="InternalCodeLogger">
      <level value="DEBUG"/>
      <appender-ref ref="OutputDebugStringAppender"/>
    </logger>
</log4net>
I have a static class that exposes those loggers:
code:
public class Loggers
{
    public static readonly ILog UserActionLogger = LogManager.GetLogger("UserLogger");
    public static readonly ILog CodeLogger = LogManager.GetLogger("InternalCodeLogger");
    public static readonly ILog ServiceLogger = LogManager.GetLogger("ServiceCallsLogger");
}
Now, if I call Loggers.CodeLogger.Debug("BOO") it works, but if I call Loggers.UserActionLogger.Debug("BOO") it doesn't. Anyone see a stupid mistake?

Edit: Doh, I'm using dbgview from sysinternals and it was set to filter everything but the Service and Code loggers. That's a stupid mistake, right there.

Dromio fucked around with this message at 16:21 on Mar 21, 2008

Grigori Rasputin
Aug 21, 2000
WE DON'T NEED ROME TELLING US WHAT TO DO
Anyone know any open source game libraries? I need something like a checkers/chess/othello grid to prototype something for a friend and want to avoid the trouble of writing one from scratch if possible. Was just going to do a C# form app since I can probably whip that together most quickly.

PBateman
Mar 11, 2007
Hey, another newbie C# question here

I made a method called CardGen()

CardGen() basically just generates a random number (with some limitations, shouldn't be necessary to state)

then, in my Main()

I do something like:

Program p = new Program()
if (x=6)
{
p.CardGen()
p.CardGen()
}

I'm trying to generate a different random number twice, but the problem is it seems to generate the same number both times. I can't really find a solution online since I don't know what to ask, any help would be appreciated, thanks.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

LetoAtreides posted:

Hey, another newbie C# question here

I made a method called CardGen()

CardGen() basically just generates a random number (with some limitations, shouldn't be necessary to state)

then, in my Main()

I do something like:

Program p = new Program()
if (x=6)
{
p.CardGen()
p.CardGen()
}

I'm trying to generate a different random number twice, but the problem is it seems to generate the same number both times. I can't really find a solution online since I don't know what to ask, any help would be appreciated, thanks.
The problem you are describing would seem to indicate that there is a problem with the CardGen() method, so why don't you post that?

Also, when you do, use the [ code ] [ /code ] tags so that things like spacing and indentation work right.

PBateman
Mar 11, 2007
alright, here it is. Thing is, if I put cardgen() once outside the main method and then once inside the main method, it'll output two different cards

code:
        public void cardGen()
        {
            //deck array
            object[] deckArray = { "Ace", 2, 3, 4, 5, 6, 7, 8, 9, 10, "Jack", "Queen", "King" };

            //card type array
            string[] cardArray = { "Diamonds", "Spades", "Hearts", "Clubs" };

            //take a value from each array and combine it
            Random randomNumber = new Random();
            int number = randomNumber.Next(0, deckArray.Length);
            int card = randomNumber.Next(0, cardArray.Length);
            Console.WriteLine("Your card is {0} of {1}", deckArray[number], cardArray[card]);
        }

Horse Cock Johnson
Feb 11, 2005

Speed has everything to do with it. You see, the speed of the bottom informs the top how much pressure he's supposed to apply. Speed's the name of the game.
A simple/quick/easy/dirty solution to your issue is putting a call to System.Threading.Thread.Sleep between your calls to the CardGen() method. I'm not 100% positive how the Random class generates its numbers, but like most random number generators it's based in part of the current system time.

You can also pass an integer to the constructor for the Random class that will act as a seed for the random number generator. Passing random values to the constructor on each call will give you different output.


Using the code you posted (with some additions to make it run)...

code:
Program p = new Program();

int x = 6;

if (x==6)
{
	p.CardGen();
	System.Threading.Thread.Sleep(1000);
	p.CardGen();
}

Console.ReadLine();
...gives the output...

code:
Your card is 3 of Spades
Your card is 8 of Diamonds
(No changes made to the CardGen() method itself)

Horse Cock Johnson fucked around with this message at 03:11 on Mar 22, 2008

PBateman
Mar 11, 2007
nice, I just tried it and it works great :) Good to know that its not some weird flaw in my code. Guess their random number generator is system timed based.

Thanks for the help

panda6
Feb 16, 2008
Formerly SLOSifl
You could also use a static Random object, so you don't have to needlessly burden yourself with adding Sleeps between every call to your card generator.

DLCinferno
Feb 22, 2003

Happy
Oh Christ, please don't use a Thread.Sleep to seed your random numbers.

uXs
May 3, 2005

Mark it zero!

LetoAtreides posted:

alright, here it is. Thing is, if I put cardgen() once outside the main method and then once inside the main method, it'll output two different cards

code:
        public void cardGen()
        {
            //deck array
            object[] deckArray = { "Ace", 2, 3, 4, 5, 6, 7, 8, 9, 10, "Jack", "Queen", "King" };

            //card type array
            string[] cardArray = { "Diamonds", "Spades", "Hearts", "Clubs" };

            //take a value from each array and combine it
            Random randomNumber = new Random();
            int number = randomNumber.Next(0, deckArray.Length);
            int card = randomNumber.Next(0, cardArray.Length);
            Console.WriteLine("Your card is {0} of {1}", deckArray[number], cardArray[card]);
        }


I think the problem is that you're making a new Random object each time you call your method. If you make 2 of them at practically the same instant, you can get the same "random" value.

The following would probably work better:

code:
public class RandomCardGenerator
  {
  private static Random randomNumber = new Random();

  public static void CardGen()
    {
    ...
    int number = randomNumber.Next(0, deckArray.Length);
    int card = randomNumber.Next(0, cardArray.Length);
    ...
    }
  }
And then you can call that with just:

code:
RandomCardGenerator.CardGen();
The first time the static method is invoked, it will create the Random object, and it will use the same object for subsequent calls to the method. Random is good for making series of random numbers, so the results will be random enough.

Code not tested in any way. Also I don't know how thread-safe this is, but I don't think you care.

tk
Dec 10, 2003

Nap Ghost
I like to use System.Security.Cryptography for my random numbers.

code:
int Random(int max)
{
	byte[] b = new byte[1];
	RandomNumberGenerator.Create().GetNonZeroBytes(b);

	int result = (int)b[0];

	if (result > 255 - (255 % max))
		return Random(max);
	return result % max;
}
I'm sure this is against some rules somewhere, but I don't particularly care.

tk fucked around with this message at 15:05 on Mar 22, 2008

csammis
Aug 26, 2003

Mental Institution

Mr. Herlihy posted:

A simple/quick/easy/dirty solution to your issue is putting a call to System.Threading.Thread.Sleep between your calls to the CardGen() method.

Really? :psyduck:

Leto, to learn more about this, look up the concept of "seeding" a random number generator. Basically, RNGs are actually random sequence generator, and that sequence is dependent on the "seed" that you create the Random object with. The same seed causes the same sequence. If you use the Random(int) constructor, you can use your own seed value, but Random() with no parameters uses the system time, and you were creating two new Random objects fast enough that they generated the same sequence.

The correct solution in this situation is to use one Random() object for each "shuffle" of the deck. Also, get those Deck and Card array creations the hell out of the method. They will never ever change from call to call, and should be in a higher scope so you don't have to keep creating them over and over.

Dromio
Oct 16, 2002
Sleeper
I've never really understood databinding. Maybe someone can help.

Right now I'm trying to whip up a quick one-page webapp that displays log lists. I've got a class for the log messages like this:
code:
public class LogMessage
{
   public string Message;
   public DateTime Occurance;
}
I have a method that returns a List<LogMessage> and I'd like to databind it to a datagrid. I'm using it like this:
code:
ResultsGrid.DataSource = GetTheList();
ResultsGrid.DataBind();
And the datagrid is defined like this:
code:
<asp:GridView ID="grdResults" runat="server" AutoGenerateColumns="false">
       <Columns>
           <asp:BoundField HeaderText="Message" DataField="Message" />
       </Columns>
</asp:GridView>
But when I DataBind() I get an exception-- "A field or property with the name 'Message' was not found on the selected data source."

Any idea what I'm doing wrong?

csammis
Aug 26, 2003

Mental Institution

Dromio posted:

But when I DataBind() I get an exception-- "A field or property with the name 'Message' was not found on the selected data source."

Any idea what I'm doing wrong?

I don't know about ASP, but at least in WPF only properties can be databound, not class members.

code:
public class LogMessage
{
  private string message;

  public string Message
  {
    get { return message; }
  }

  private DateTime occurance;

  public DateTime Occurance
  {
    get { return occurance; }
  }
}

PBateman
Mar 11, 2007
thanks for the replies above, I'm reading more and trying out your suggestions now.

Dromio
Oct 16, 2002
Sleeper

csammis posted:

I don't know about ASP, but at least in WPF only properties can be databound, not class members.

That's the critical fact I've been missing. Thank you very much!

cowboy beepboop
Feb 24, 2001

I'm trying to synchronise 250+ grid's columns, using the SharedSizeGroup property of the columns and I'm running into performance and layout problems.

Each grid is only 1 row with 2 columns and lives inside a ListBox. As you've probably guessed by now I'm doing this simply so I can have columns inside a ListBox.

I imagine the code that gets generated (from DataTemplates and bindings and all sorts of things) looks something like this:
code:
<ListBox>
  <ListBoxItem>
    <Grid>
      <Grid.ColumnsDefinitions>
        <ColumnDefinition Width="*" SharedSizeGroup="SharedColumn" />
        <ColumnDefinition Width="Auto" />
      </Grid.ColumnsDefinitions>
      <!-- The single row goes here -->
    </Grid>
  </ListBoxItem>
  
  <ListBoxItem> is repeated some 250 times ...

</ListBox>
As soon as SharedSizeGroup is set to true (on the parent ListBox), I run into big problems with scrolling. It's really slow as it appears to calculate the width for the * column only on the visible ListBoxItems, and updates each time you scroll. This also causes the left column to dance around as the max width for the left column changes depending what's in view.

1) Is there a better way to do this?
2) Is it possible to calculate the maximum width needed by the left column, set it for the all of the grids, then lock this value in?

notflipmo
Feb 29, 2008
'
C# + .NET 3.5

Learn me some XML please :(

config.xml:
code:
<config>
	<limit>13312</limit>
	<interval>20</interval>
	<process>utorrent.exe</process>
	<process>dc++.exe</process>
</config>
Basically I would like to write readConfiguration(), which reads the file config.xml
and saves the limit and interval values to ints, and the process values to any suitable storeage class, most likely a string array since I don't expect more than a few process entries.

I figured it would be fun to use an XML configuration file in this project just to have used .NETs mechanisms for XML. But amongst XmlDocuments, XmlReaders, XmlElements, XmlNodes, my brain seems to have melted and I can't seem to grasp it.
I now feel exceedingly dense, after googling all day long and understanding very little :saddowns:

code:
        private void readConfiguration()
        {
            XmlDocument xd = new XmlDocument();
            xd.Load("config.xml");


        }

Beyond this, I haven't been able to make any sense of it all...

Adbot
ADBOT LOVES YOU

csammis
Aug 26, 2003

Mental Institution
code:
private void readConfiguration()
{
  XmlDocument xd = new XmlDocument();
  xd.Load("config.xml");

  XmlNode limitNode = xd.SelectSingleNode("/config/limit");
  if(limitNode != null)
  {
    int limit = Int32.Parse(limitNode.InnerText);
  }
}
...and so on. Note that this doesn't do any error checking whatsoever, including ensuring that the limit node's InnerText property (a) exists, (b) is a number. Also this was off the top of my head so it might not be completely valid.

Basically, the SelectSingleNode method will be your friend. Read up on XPath to learn how to select nodes from the document.

  • Locked thread