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
simble
May 11, 2004

poopiehead posted:

Is there anything wrong with this besides the fact that if MS changes their LinkButton Control, then my code might die?

Nothing really wrong with what you're doing here besides what you mentioned. The hack that I've been using for default buttons since early 1.1 was to create a blank image button at the top of the page/panel/div. Then, have the blank image button's on click handler simply call the button I want to have clicked while just passing back the same sender and event args. Hacky as all hell, but it gets the job done.

Adbot
ADBOT LOVES YOU

MrBishop
Sep 30, 2006

I see what you did there...

Soiled Meat
I see the Ajax extensions package for ASP.Net has been RTM. Looking at the release notes, MS "strongly suggests" you install VS 2005 SP1 before installing the extensions. I have no particular interest in installing SP1 at this time, is it going to hose my projects if I don't install it?

Goonamatic
Sep 17, 2005
cunning linguist

poopiehead posted:

I'm trying to make the defaultbutton for a textbox be a linkbutton. Sounds simple enough, but not really. There seems to be a bug(or at least weird feature) in ASP .NET that makes this not possible on firefox. Looking at their JS, they try to use the defaultbutton's click() method which firefox doesn't define for anchor tags.

This script fixes it so that there is a click method.
code:
var el = document.getElementById('<%=btnSearch.ClientID %>');
if(!el.click)
el.click = eval( "function (){  " + el.href.substring(11) + "; }")
In the linkbutton, the generated code has href="java script:__do_postback(....)", so I just grab that and call it.

Is there anything wrong with this besides the fact that if MS changes their LinkButton Control, then my code might die?

I just use my function


public static void SetDefaultButton(TextBox textBox, Button button)
{
textBox.Attributes.Add("onkeypress", "checkEnter('" + button.ClientID.ToString() + "', event);");

StringBuilder sb = new StringBuilder();

sb.Append("function checkEnter(btn, event)");
sb.Append("{");
sb.Append(" if (document.all)");
sb.Append(" {");
sb.Append(" if (event.keyCode == 13)");
sb.Append(" {");
sb.Append(" var o = document.getElementById(btn);");
sb.Append(" event.returnValue=false;");
sb.Append(" event.cancel = true;");
sb.Append(" o.click();");
sb.Append(" }");
sb.Append(" }");
sb.Append(" else if (document.getElementById)");
sb.Append(" {");
sb.Append(" if (event.which == 13)");
sb.Append(" {");
sb.Append(" var o = document.getElementById(btn);");
sb.Append(" event.returnValue=false;");
sb.Append(" event.cancel = true;");
sb.Append(" o.click();");
sb.Append(" }");
sb.Append(" }");
sb.Append(" else if (document.layers)");
sb.Append(" {");
sb.Append(" if(event.which == 13) ");
sb.Append(" {");
sb.Append(" var o = document.getElementById(btn);");
sb.Append(" event.returnValue=false;");
sb.Append(" event.cancel = true;");
sb.Append(" o.click();");
sb.Append(" }");
sb.Append(" }");
sb.Append("}");

textBox.Page.ClientScript.RegisterClientScriptBlock(textBox.Page.GetType(), "CheckEnter", sb.ToString(), true);
}

poopiehead
Oct 6, 2004

Goonamatic posted:

I just use my function


public static void SetDefaultButton(TextBox textBox, Button button)
{
textBox.Attributes.Add("onkeypress", "checkEnter('" + button.ClientID.ToString() + "', event);");

StringBuilder sb = new StringBuilder();

sb.Append("function checkEnter(btn, event)");
sb.Append("{");
sb.Append(" if (document.all)");
sb.Append(" {");
sb.Append(" if (event.keyCode == 13)");
sb.Append(" {");
sb.Append(" var o = document.getElementById(btn);");
sb.Append(" event.returnValue=false;");
sb.Append(" event.cancel = true;");
sb.Append(" o.click();");
sb.Append(" }");
sb.Append(" }");
sb.Append(" else if (document.getElementById)");
sb.Append(" {");
sb.Append(" if (event.which == 13)");
sb.Append(" {");
sb.Append(" var o = document.getElementById(btn);");
sb.Append(" event.returnValue=false;");
sb.Append(" event.cancel = true;");
sb.Append(" o.click();");
sb.Append(" }");
sb.Append(" }");
sb.Append(" else if (document.layers)");
sb.Append(" {");
sb.Append(" if(event.which == 13) ");
sb.Append(" {");
sb.Append(" var o = document.getElementById(btn);");
sb.Append(" event.returnValue=false;");
sb.Append(" event.cancel = true;");
sb.Append(" o.click();");
sb.Append(" }");
sb.Append(" }");
sb.Append("}");

textBox.Page.ClientScript.RegisterClientScriptBlock(textBox.Page.GetType(), "CheckEnter", sb.ToString(), true);
}

Thanks for that. I think I'll end up using this cases when I don't want to use a Panel to set the DefaultButton because it renders a div tag that may mess with layout.

My current problem is with LinkButton though, which renders as something like this:
<a href="java script:__doPostBack('ct100_btn','')">Go</a>

MS's implementation of DefaultButton in 2.0 lets you choose a linkbutton as the default button but it tries to use the click() method to click it. That's fine in IE, but firefox doesn't have a click() method on the <a> tag object.

havelock
Jan 20, 2004

IGNORE ME
Soiled Meat

Goonamatic posted:

I just use my function


public static void SetDefaultButton(TextBox textBox, Button button)
{
textBox.Attributes.Add("onkeypress", "checkEnter('" + button.ClientID.ToString() + "', event);");

StringBuilder sb = new StringBuilder();

sb.Append("function checkEnter(btn, event)");
sb.Append("{");
sb.Append(" if (document.all)");
sb.Append(" {");
sb.Append(" if (event.keyCode == 13)");
sb.Append(" {");
sb.Append(" var o = document.getElementById(btn);");
sb.Append(" event.returnValue=false;");
sb.Append(" event.cancel = true;");
sb.Append(" o.click();");
sb.Append(" }");
sb.Append(" }");
sb.Append(" else if (document.getElementById)");
sb.Append(" {");
sb.Append(" if (event.which == 13)");
sb.Append(" {");
sb.Append(" var o = document.getElementById(btn);");
sb.Append(" event.returnValue=false;");
sb.Append(" event.cancel = true;");
sb.Append(" o.click();");
sb.Append(" }");
sb.Append(" }");
sb.Append(" else if (document.layers)");
sb.Append(" {");
sb.Append(" if(event.which == 13) ");
sb.Append(" {");
sb.Append(" var o = document.getElementById(btn);");
sb.Append(" event.returnValue=false;");
sb.Append(" event.cancel = true;");
sb.Append(" o.click();");
sb.Append(" }");
sb.Append(" }");
sb.Append("}");

textBox.Page.ClientScript.RegisterClientScriptBlock(textBox.Page.GetType(), "CheckEnter", sb.ToString(), true);
}

Unless I missed something, that string is static. There's no reason not to just use a literal for it. Even if you break it up on multiple lines.
string s = "line 1 " +
"line 2 " +
"line 3 ";

The compiler is smart enough to assemble one monster string for you.

poopiehead
Oct 6, 2004

havelock posted:

Unless I missed something, that string is static. There's no reason not to just use a literal for it. Even if you break it up on multiple lines.
string s = "line 1 " +
"line 2 " +
"line 3 ";

The compiler is smart enough to assemble one monster string for you.

Also using @"" works great for those situations because then you can read your javascript relatively easily.

code:
string js = @"
  function checkEnter(btn, event)
  {
    if (document.all)
    {
      if (event.keyCode == 13)
      {
        var o = document.getElementById(btn);
        event.returnValue=false;
        event.cancel = true;
        o.click();
      };
    }
  }";
That does make the file a bit bigger with all the spacing though.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



I'm trying to get an ItemsControl with its Items property bound to a data structure of mine to send updates back to that data structure when I change the order of the items in the collection.

This is how I change the order of the items:
code:
private void swapChildren(UIElement A, UIElement B)
{
	int Aindex = base.Items.IndexOf(A);
	int Bindex = base.Items.IndexOf(B);
	((System.Collections.ObjectModel.Collection<ContentControl>)ItemsSource)[Aindex] = B as ContentControl;
	((System.Collections.ObjectModel.Collection<ContentControl>)ItemsSource)[Bindex] = A as ContentControl;
}
However, nothing changes in the UI and the setter isn't being called. I would expect the layout of the control to change, for example, but that's not happening despite doing a base.UpdateLayout() call right after the swap. This results in a discrepency between the actual order in the .Items collection and the order they are displayed onscreen.

The items are displayed in a StackPanel nested in the ItemsControl which in turn is nested in a ScrollPanel, if any of that matters.

Binding is done like so:
code:
Binding tbBinding = new Binding("ControlCollection");
tbBinding.Source = stringCollection;
scrollingItems.SetBinding(ItemsControl.ItemsSourceProperty, tbBinding);
Also, if someone who is familliar with WPF thinks I'm doing this in a silly or overcomplex way please let me know because I'm just figuring things out as I go along so far :\

SLOSifl
Aug 10, 2002


Does Expression "Blend" Beta 1 not support SQL data sources yet?

fankey
Aug 31, 2001

SLOSifl posted:

Does Expression "Blend" Beta 1 not support SQL data sources yet?

I'm not sure if it does natively but it looks like you can use WCF to glue it together.

http://blogs.sqlxml.org/bryantlikes/archive/2006/09/21/Enabling-WPF-Magic-Using-WCF-_2D00_-Part-3.aspx

SLOSifl
Aug 10, 2002


fankey posted:

I'm not sure if it does natively but it looks like you can use WCF to glue it together.

http://blogs.sqlxml.org/bryantlikes/archive/2006/09/21/Enabling-WPF-Magic-Using-WCF-_2D00_-Part-3.aspx
Thanks, that seems reasonable.

I'm hoping to get far enough in to WPF to be able to make a decision between it and ASP.NET/AJAX. I am in charge of designing the UI for a new, large application, and higher-ups are convinced that being web based is the way to go. I'm not so sure. I want to examine all the options, and I'm more of an early adopter than a catch-up kind of designer.

csammis
Aug 26, 2003

Mental Institution

Munkeymon posted:

I'm trying to get an ItemsControl with its Items property bound to a data structure of mine to send updates back to that data structure when I change the order of the items in the collection.

First, it'd probably be better to post more of the code, including your data structure layout. I don't know what base is refering to without knowing where swapChildren is defined.

ItemsControl.UpdateLayout() checks whether visual children need a redraw, not logical children. You changed the order of the logical children, but the change hasn't shown up on the frontside. Try ItemsControl.Items.Refresh().

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



csammis posted:

First, it'd probably be better to post more of the code, including your data structure layout. I don't know what base is refering to without knowing where swapChildren is defined.

ItemsControl.UpdateLayout() checks whether visual children need a redraw, not logical children. You changed the order of the logical children, but the change hasn't shown up on the frontside. Try ItemsControl.Items.Refresh().

Thanks that did the trick for updating the visual. I just assumed that seeing if the children have the same logical order was part of whether they needed redrawn. Silly me I guess.

The swap method is called from here:
code:
protected override void OnPreviewMouseMove(MouseEventArgs e)
{
	base.OnPreviewMouseMove(e);

	// If no element is being dragged, there is nothing to do.
	if (this.ElementBeingDragged == null || !this.isDragInProgress)
		return;

	// Get the position of the mouse cursor, relative to the Canvas.
	Point cursorLocation = e.GetPosition(this);

	UIElement invadee = this.cursorOverNeighbor(cursorLocation);
	if (invadee != null)
	{
		this.swapChildren(invadee, this.ElementBeingDragged);
		base.Items.Refresh();
		this.origCursorLocation = e.GetPosition(this);
	}

	e.Handled = true;//need this
}
Edit: forgot to mention that this is in the code for my extended ItemsControl.

*nevermind what was here previously*

This is most of the data structue:
code:
class MyContainer : INotifyPropertyChanged
{
	private ObservableCollection<string> stringCollection;

	public Collection<ContentControl> ControlCollection
	{
		get
		{
			Collection<ContentControl> ret = new Collection<ContentControl>();
			foreach (string st in stringCollection)
			{
				ContentControl tmp;
				tmp = new Button();
				tmp.Content = st;
				ret.Add(tmp);
			}
			return ret;
		}
		set
		{
			Collection<ContentControl> incoming = value as Collection<ContentControl>;
			stringCollection.Clear();
			foreach (ContentControl cc in incoming)
			{
				stringCollection.Add(cc.Content as string);
			}
			PropertyChanged(this, new PropertyChangedEventArgs("ControlCollection"));
		}
	}

	public MyContainer() { stringCollection = new ObservableCollection<string>(); }

	public void Add(string st)
	{
		stringCollection.Add(st);
		if (PropertyChanged != null)
		{
			PropertyChanged(this, new PropertyChangedEventArgs("ControlCollection"));
		}
	}

	public event PropertyChangedEventHandler PropertyChanged;
}
There's annother property but it's read only and not really relevant. I first tried making it by doing MyContainer:ObserveableCollection<string> but I can't override Add() or call the PropertyChanged event with the right arguments to trigger updates in the bound objects.

Just made shure I was setting the binding mode to 2-way and I am :\

edit: corrected myself

Munkeymon fucked around with this message at 23:00 on Jan 24, 2007

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Victor posted:

I'm still confused. While MembershipProvider provides a ValidateUser method, it doesn't seem MS intended it to be restricted to authorization; otherwise, why would MembershipUser not implement IPrincipal or IIdentity? Let me put this another way: does anyone here use IPrincipal, MembershipUser, and ProfileProvider, all in the same app?

Do you typically maintain a 1:1 relationship between MembershipUser/IPrincipal and your custom, non-provider-model-based user data?

If I'm understanding you guys correctly, you don't find that ASP.NET provides any natural provider-model-supported location for user info like telephone number? It appears that it *does* have support for stuff like user options in ProfileProvider, and that it is reasonable to have multiple profiles for a given MembershipUser.
From http://www.theserverside.net/tt/articles/showarticle.tss?id=CreatingProfileProvider
"While Profile data is often thought of as an extension of Membership data, it's actually not related. You can have Profile data for users whether they are authenticated or not."

I dunno if this helps you out at all. Anyway, I did some reading, and it seems like MembershipProvider is for authentication info only. If you want to store some info, like a phone number, about a user, then it seems like ProfileProvider is where you'd put it. And it also seems like there would be no problem with having one ProfileProvider for configuration info and a second one for "user" info.

Of course, I have done approximately zero .net development, and if I had done any it would all be in an environment with Active Directory, so I'd probably just get all my info from there.

fankey
Aug 31, 2001

SLOSifl posted:

Thanks, that seems reasonable.

I'm hoping to get far enough in to WPF to be able to make a decision between it and ASP.NET/AJAX. I am in charge of designing the UI for a new, large application, and higher-ups are convinced that being web based is the way to go. I'm not so sure. I want to examine all the options, and I'm more of an early adopter than a catch-up kind of designer.

My experience with WPF so far shows that you should be able to integrate pretty much any technology into it. I currently have a WPF app that uses boost:threads, Apple Rendezvous and homebrew C++ UDP communications. Of course if you need to run in a browser you'll probably need to use WPF/E, which currently doesn't allow for C# code - you'd be limited to what you can do with the built in WPF bindings and javascript.

SLOSifl
Aug 10, 2002


fankey posted:

My experience with WPF so far shows that you should be able to integrate pretty much any technology into it. I currently have a WPF app that uses boost:threads, Apple Rendezvous and homebrew C++ UDP communications. Of course if you need to run in a browser you'll probably need to use WPF/E, which currently doesn't allow for C# code - you'd be limited to what you can do with the built in WPF bindings and javascript.
Oh, nice. WPF looks pretty cool.

It doesn't need to run in a browser. Nobody here can back up why they think it needs to. It's just management passing around buzzwords with their buddies over golf or whatever they do. I'm still waiting for the "let's look into this OOP thing" email.

Heffer
May 1, 2003

At the beginning of the year with my company, we try to pick projects for the year, as well as set training goals for ourselves. So here is a three part open ended post:

1) Can someone sell me on the new 3.0 technologies like WPF, WWF, and XAML? I know little about it, and haven't really seen what big advantages are offered by the new style of doing things.

2) Does anybody have any good resources for Sharepoint 2007? Recommended ways to deploy it? Comparisons to 2003? Examples of good use?

3) Can anyone recommend any training for new technologies that I should take this year? Kind of an open ended question, but I haven't set any training or skill goals for myself yet, so I'm trying to feel something out. A lot of people here have experiences that are lagging behind the curve (taking training for .NET because Visual Basic 6.0 is too stale), so I'm trying to make sure I'm a step ahead.

Victor
Jun 18, 2004
Heffer, what does your company do?

Jethro, thanks for looking into it a bit -- I think I'm going to post on the MSDN forums to see if I can get any MS folks telling me how they intended the classes to be used in a bit more detail.

Heffer
May 1, 2003

Victor posted:

Heffer, what does your company do?

Newspaper. Or really, several newspapers, along with subsidiaries that do any numerous amounts of media activities, from direct marketing to web advertising to mobile content.

My title is Web Developer, but I'm kind of grooming myself for a catch-all person for newer technologies. Tomorrow I could be working on deploying Sharepoint 2007 as a way for the Sales team to communicate with customers, or building a website for advertisers to submit custom graphics, or building a tool to comb through an Exchange folder for email attachments. Or anything at all. Anything. I am allowed to pick which technologies I use, and set my own training goals. So basically a blank canvas.

fankey
Aug 31, 2001

SLOSifl posted:

Oh, nice. WPF looks pretty cool.

It doesn't need to run in a browser. Nobody here can back up why they think it needs to. It's just management passing around buzzwords with their buddies over golf or whatever they do. I'm still waiting for the "let's look into this OOP thing" email.

I think that you can look at WPF in a couple of different ways.

On one end is the whole XAML/Blend/Bindings part. This allows to you make an application with just some XML files. It also allows for the 'graphic designer' person to design the UI completely separate from the code. I think this is the main way MS is 'selling' WPF - as their next generation RAD tool.

The other way to look at it is as a replacement for Win32/MFC/Winforms. You can write a complete WPF app without a lick of XAML code anywhere. You can even write it in C++ if you like. WPF gives you a ( somewhat incomplete ) library of controls along with a fairly full featured hardware accelerated graphics engine. You also get easy restyling of the entire app which will enable you to make your application as garish as a $2 hooker with just a few XAML files.

I started out with the Win32 replacement mindset, writing in C++/CLI. For various reasons I determined that wasn't the best course of action. I've now settled somewhere between those two approaches ( although still pretty close to the second ) writing my app in C# but using XAML where applicable. This gives me the ability to use available XAML tools to create portions of my UI but in cases where writing code is the only solution I can do that as well.

Victor
Jun 18, 2004
Heffer, WPF isn't going to get anything unless you can target Windows-only machines, optionally with the requirement that it must run on the web, but can be restricted to IE only. Hopefully at some point in the future, Mono will support WPF, but for now it does not. Oh, and WPF is restricted to XP and Vista (and perhaps Server 2003, I forget).

fankey
Aug 31, 2001

Victor posted:

Heffer, WPF isn't going to get anything unless you can target Windows-only machines, optionally with the requirement that it must run on the web, but can be restricted to IE only. Hopefully at some point in the future, Mono will support WPF, but for now it does not. Oh, and WPF is restricted to XP and Vista (and perhaps Server 2003, I forget).

That's not entirely true. WPF/E works in IE 6 and 7 as well as Firefox 1.5 and 2.0. MS has also released a WPF/E plugin for Safari and Firefox on OSX. I've heard rumblings that it will also show up in Linux but I wouldn't hold my breath.

That said, it's up in the air as far as how feasible it is to write a 'real' application using WPF/E. And if you need the additional features that WPF brings you will need to be on XP/Vista.

I've played with WPF/E on both Firefox ( in Vista ) and Safari in OSX - it appears to work just fine.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Victor posted:

Heffer, WPF isn't going to get anything unless you can target Windows-only machines, optionally with the requirement that it must run on the web, but can be restricted to IE only. Hopefully at some point in the future, Mono will support WPF, but for now it does not. Oh, and WPF is restricted to XP and Vista (and perhaps Server 2003, I forget).

I think I remember reading a blog entry from the lead Mono developer talking aobut how he decided WPF wasn't worth supporting for some reason, so Mono devs will need to know whatever Gnome uses (IIRC).

Edit: is your quote button not showing up?

pig-fukr
Nov 3, 2002
Edit: n/m, magically it works now.

Maybe it's time to go back to professional cooking.

pig-fukr fucked around with this message at 02:24 on Jan 25, 2007

Victor
Jun 18, 2004
These three links should convince you that WPF/E will do nothing to enable rich applications, unless you simply mean some vector graphics and multimedia when you say "rich". The WPF/E designers have no intention to support controls that would overlap those already provided by HTML. The event documentation reference doesn't even talk about keyboard events, which is a dead giveaway. I would welcome evidence to the contrary of what I've said above, but as far as I can tell, WPF/E is pretty much a joke, at least for developing rich internet apps.

The Mono team is working on technologies "past 2.0": Olive. It remains to be seen whether they will start developing it in earnest.

I try to keep the quoting down when I can simply make my posts a few words longer and convey the same information. I think quotes clog up the thread, especially when someone quotes a post directly above.

fankey
Aug 31, 2001

Victor posted:

These three links should convince you that WPF/E will do nothing to enable rich applications, unless you simply mean some vector graphics and multimedia when you say "rich". The WPF/E designers have no intention to support controls that would overlap those already provided by HTML. The event documentation reference doesn't even talk about keyboard events, which is a dead giveaway. I would welcome evidence to the contrary of what I've said above, but as far as I can tell, WPF/E is pretty much a joke, at least for developing rich internet apps.


According to this and this, they're 'working on' keyboard events. Will they ever show up? Who knows - I've been burned by MS getting distracted by newer shinier technology in the past, that's for sure. I'm not a WPF/E evangelist or anything - we're probably going to use FLEX for the web interface portion of our app. I do find the idea intriguing - I like the idea of being able to use the same content/paradigm in both the Windows based GUI and the web based stuff. We have graphical widgets that'll need to be presented by both and if WPF/E turns out to be as powerful as FLEX/Flash that'd be great.

Right now I'd agree that WPF/E is not capable of a rich application. Basing your app on WPF/E on the hope that they'll add the features needed would be a bad idea. So would using WPF under the assumption that porting to WPF/E would be possibe.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!
Maybe this should go in the general programming megathread, but does anyone know if it's possible to tell csc.exe to look for a /reference in the GAC? I'm coding stuff on my computer in VS2005, but I want to compile stuff on the server it's being used on, and I don't think the server is guaranteed to have VS on it, and I probably don't want to use up the CPU cycles and memory to open it if it did.

So I wrote a perl script to parse the .csproj file and make an .rsp file for use with csc.exe, but if I'm referencing an assembly .dll that isn't part of the .NET framework it probably won't be in the framework or SDK directories, but it will almost certainly be in the GAC. So, uh, how do I put in my .rsp to look there, if I can?

EDIT: Hrm. It appears that I can't do that after all. But it probably doesn't matter anyway. I'll just have to figure out a good place to stick my assemblies so that they can be found by me easily.

Jethro fucked around with this message at 16:25 on Jan 25, 2007

theodop
Dec 30, 2005

rock solid, heart touching
I'm working on a project that remotely monitors logs over shared directories. One of the functions of this is to view the last line in a log file, because if the process it was logging has hosed itself, it will often show something useful. However, these files can range from a few kilobytes to hundreds of megabytes and it would be impossible to download the entire log file.

I'm basically looking for a way to skip all the way to the end of the file without using Read or ReadLine, then skip back and read the last line.

theodop fucked around with this message at 03:57 on Jan 25, 2007

Obsurveyor
Jan 10, 2003

theodop posted:

I'm basically looking for a way to skip all the way to the end of the file without using Read or ReadLine, then skip back and read the last line.
SetFilePointer() may do the trick for you. Just use FILE_END with a negative offset of however many bytes you want to go backwards.

theodop
Dec 30, 2005

rock solid, heart touching

Dodger_ posted:

SetFilePointer() may do the trick for you. Just use FILE_END with a negative offset of however many bytes you want to go backwards.

Thanks for the reply, but I'm using the .NET library. Also, I don't know the amount of bytes from the end I want to skip to because I don't know where the last line starts. I could probably, however, set the pointer to the end of the file (I hope this is possible with the .NET library) and read backwards character by character until I hit a line break?

marcan
Sep 3, 2006
(:(){ :|:;};:)
C# newb here (I've used C, Java, and others, but this is the first time I mess with C#)

I'm having threading troubles. I'm trying to build an app to read data from a serial port and update a bunch of controls on a form in real time. In my current setup, a separate thread does the reading, and after processing it ends up calling Invoke on the form to run the GUI update code on the GUI thread. The problem is (I believe, from what I've been able to tell using lots of debug statements) that when I close the Form, the serial code does a join on the reading thread, which sometimes (in fact, almost always) happens to be waiting for a just-queued event on the GUI for updating. Since the event is queued after FormClosing, and FormClosing waits on the other thread, the app deadlocks. Removing the join just shifts the problem from a deadlock to an exception on the Invoke, as the Form is dead by then.

Any ideas on how to avoid this situation?

<edit> Replacing Invoke with BeginInvoke seems to work fine. Any other suggestions, or is this fine?

marcan fucked around with this message at 08:48 on Jan 25, 2007

poopiehead
Oct 6, 2004

marcan posted:

C# newb here (I've used C, Java, and others, but this is the first time I mess with C#)

I'm having threading troubles. I'm trying to build an app to read data from a serial port and update a bunch of controls on a form in real time. In my current setup, a separate thread does the reading, and after processing it ends up calling Invoke on the form to run the GUI update code on the GUI thread. The problem is (I believe, from what I've been able to tell using lots of debug statements) that when I close the Form, the serial code does a join on the reading thread, which sometimes (in fact, almost always) happens to be waiting for a just-queued event on the GUI for updating. Since the event is queued after FormClosing, and FormClosing waits on the other thread, the app deadlocks. Removing the join just shifts the problem from a deadlock to an exception on the Invoke, as the Form is dead by then.

Any ideas on how to avoid this situation?

<edit> Replacing Invoke with BeginInvoke seems to work fine. Any other suggestions, or is this fine?



You also might find the Abort method of the Thread class. When you start the thread, save the object and on FormClosing, call Abort. (never used the abort method myself but it looks like what you need)

biznatchio
Mar 31, 2001


Buglord

theodop posted:

Thanks for the reply, but I'm using the .NET library. Also, I don't know the amount of bytes from the end I want to skip to because I don't know where the last line starts. I could probably, however, set the pointer to the end of the file (I hope this is possible with the .NET library) and read backwards character by character until I hit a line break?

You can use either Seek(Int64, SeekOrigin) or set the Position property on the FileStream object to move to the end of the file. For example, the following block of code (warning: not tested) will seek and read the last kilobyte of the file, line by line. If your log lines are expected to be longer than 1024 bytes, you might want to seek backward a little further.

code:
long SEEK_LEN = 1024;
string res = null;
using (FileStream fs = new FileStream("C:/foo.txt"))
{
    fs.Seek(0 - SEEK_LEN, SeekOrigin.End);
    // Or:  fs.Position = Math.Max(0, fs.Length - SEEK_LEN);
    using (StreamReader sr = new StreamReader(fs))
    {
        while (!sr.EndOfStream)
        {
            res = sr.ReadLine();
        }
    }
}

Dromio
Oct 16, 2002
Sleeper
I'm back and feeling a bit dumb again.

I have a class which contains application data. The class needs a "dirty" flag so the application can warn the user when they need to save before closing the application. I'm doing something like this:

code:
    class DataClass
    {
        private bool _IsDirty;
        public bool IsDirty
        {
            get { return _IsDirty; }
        }

        private System.Drawing.Rectangle _MyRect = new System.Drawing.Rectangle(0, 0, 100, 100);

        public System.Drawing.Rectangle MyRect
        {
            get { return _MyRect; }
            set 
            {
                _IsDirty = true;    
                _MyRect = value; 
            }
        }
    }
My problem is that System.Drawing.Rectangle is a structure, not a class, so it's being passed by value, not reference. So if someone calls DataClassObject.MyRect.Inflate(100,100), it doesn't actually change the rectangle. And it doesn't call the accessor. So it doesn't work at all.

Am I going to have to write my own Rectangle class and implement all those Rectangle functions in it?

Victor
Jun 18, 2004

fankey posted:

According to this and this, they're 'working on' keyboard events.
Thank you! I've added these to my list (they should show up when clicking on links from my previous posts). It would appear that the philsophy stated by Michael Harsh has changed:

quote:

On the team, the way we think of WPF/E is this: WPF/E is a browser plug-in that augments the set of functionality provided by HTML to provide media, animation and vector graphics with the same programming model that the HTML DOM exposes. This CTP of WPF/E is not a UI technology that replaces HTML, it augments the capabilities.
This is excellent news. I wonder; does MS have any unified way to discuss what people want out of WPF/E? It would seem that blogs aren't a very good way to go about this...

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Victor posted:

This is excellent news. I wonder; does MS have any unified way to discuss what people want out of WPF/E? It would seem that blogs aren't a very good way to go about this...

Don't their forums count? There are plenty of microsoft people using them daily from the looks of it.

Victor
Jun 18, 2004

Munkeymon posted:

Don't their forums count? There are plenty of microsoft people using them daily from the looks of it.
I'm thinking more like a feature request site where you can request major features and minor features. The output would be nicely formatted and hierarchical, and there would be succinct and longer explanations for things so that viewers could quickly see a nice overview and dig into details when desired. For example, I might suggest a textbox control. Someone else might suggest that ctrl-A works in single-line textboxes (this is not a feature of normal single-line Windows textboxes. Someone might request intelligent undo/redo, like exists in Firefox's textareas. Add in trees, grids, tree-grid hybrids, etc. Maybe moderators prune the suggestions or put them in a "unedited" area like CodeProject, so that you can either view the edited version or unedited version. This way MS could gather statistics and whatnot. MS could give MSDN subscribers special access to these lists (maybe only MSDN subscribers can vote), as they are probably the people most likely to use the product. Forums are such a messy way to do things, although I guess MS could pay someone to read through every thread and do all this work themselves, instead of building a system to automate it.

genki
Nov 12, 2003

Victor posted:

I'm thinking more like a feature request site where you can request major features and minor features. The output would be nicely formatted and hierarchical, and there would be succinct and longer explanations for things so that viewers could quickly see a nice overview and dig into details when desired. For example, I might suggest a textbox control. Someone else might suggest that ctrl-A works in single-line textboxes (this is not a feature of normal single-line Windows textboxes. Someone might request intelligent undo/redo, like exists in Firefox's textareas. Add in trees, grids, tree-grid hybrids, etc. Maybe moderators prune the suggestions or put them in a "unedited" area like CodeProject, so that you can either view the edited version or unedited version. This way MS could gather statistics and whatnot. MS could give MSDN subscribers special access to these lists (maybe only MSDN subscribers can vote), as they are probably the people most likely to use the product. Forums are such a messy way to do things, although I guess MS could pay someone to read through every thread and do all this work themselves, instead of building a system to automate it.
1. I think it's mostly handled through the forums, and
2. blogs. For example, I think one of the MS folk explained why there was no grid control in a blog post.

Ultimately, I believe the reasoning is that they're focusing on providing a powerful new framework, and that people will come up with more specific solutions on their own, given the right tools (which they're theoretically providing).

fankey
Aug 31, 2001

Victor posted:

This is excellent news. I wonder; does MS have any unified way to discuss what people want out of WPF/E? It would seem that blogs aren't a very good way to go about this...
They just started a WPF wiki where they already have a page for feature requests. I couldn't find one specifically for WPF/E but maybe they're working one one.

Victor
Jun 18, 2004

fankey posted:

They just started a WPF wiki where they already have a page for feature requests. I couldn't find one specifically for WPF/E but maybe they're working one one.
That's more like it! As long as someone monitors that for malicious and inappropriate content, it could be quite useful. I should do some editing myself.

Adbot
ADBOT LOVES YOU

wwb
Aug 17, 2004

Jethro posted:

Maybe this should go in the general programming megathread, but does anyone know if it's possible to tell csc.exe to look for a /reference in the GAC? I'm coding stuff on my computer in VS2005, but I want to compile stuff on the server it's being used on, and I don't think the server is guaranteed to have VS on it, and I probably don't want to use up the CPU cycles and memory to open it if it did.

So I wrote a perl script to parse the .csproj file and make an .rsp file for use with csc.exe, but if I'm referencing an assembly .dll that isn't part of the .NET framework it probably won't be in the framework or SDK directories, but it will almost certainly be in the GAC. So, uh, how do I put in my .rsp to look there, if I can?

EDIT: Hrm. It appears that I can't do that after all. But it probably doesn't matter anyway. I'll just have to figure out a good place to stick my assemblies so that they can be found by me easily.

Presuming you are using 2.0 here, you really want to use MsBuild. If you are using 1.x, you probably want to use NAnt rather than a pearl script. Both of which packages should be able to handle that for you.

I, myself, really dislike using GAC'd resources. I tend to deploy a local copy of assemblies inasmuch as is possible.

quote:

I'm still confused. While MembershipProvider provides a ValidateUser method, it doesn't seem MS intended it to be restricted to authorization; otherwise, why would MembershipUser not implement IPrincipal or IIdentity? Let me put this another way: does anyone here use IPrincipal, MembershipUser, and ProfileProvider, all in the same app?

Do you typically maintain a 1:1 relationship between MembershipUser/IPrincipal and your custom, non-provider-model-based user data?

If I'm understanding you guys correctly, you don't find that ASP.NET provides any natural provider-model-supported location for user info like telephone number? It appears that it *does* have support for stuff like user options in ProfileProvider, and that it is reasonable to have multiple profiles for a given MembershipUser.

Sorry for the short & delayed responses, was on a bit of a deadline the last couple days.

Anyhow, the point of the MembershipProvider is to provide authorization/authentication detail. People see an email address and kind of say, gee, shouldn't I have non-auth stuff here, but I would argue that is related to authorization (confirming/resetting passwords).

How Membership plays into the underlying systems (IPrincipal/IIdentity) is that the MembershipProvider is responsible for populating the HttpContext.User variable with the appropriate IPrincipal object at the appropriate time.

Remember, the point of the MembershipProvider is really to provide a bridge from the UI layer (IE: Join wizard control doohicky) to the underlying membership store in a standardized manner.

The proper place for stuff like phone numbers is the Profile. But the default profile sucks for more than toy apps. Especially if you consider datamining scenarios. There is no way to look inside the profile or select based on things in the profile aside from opening them from the web project and walking through the list. That said, it is a handy enough place to store user info, but I would generally use a custom provider in a production application.

Hope this helps.

  • Locked thread