Search Amazon.com:
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 $3,400 per month for bandwidth bills alone, and since we don't believe in shoving popup ads to our registered users, we try to make the money back through forum registrations.
«369 »
  • Post
  • Reply
Dromio
Oct 16, 2002
Sleeper

Vintersorg posted:

Oh, so I just learned that in asp.net you cannot have two forms on one page. So my idea above will not work. The entire site is created by a form itself. Not sure why, but it is. Could someone explain the significance of why a designer would choose it?

ASP.NET WebForms was designed to make the whole page a form (as the name implies). There's a lot of debate over the reasons this is a bad idea, but it is what it is. You can use ASP.NET MVC or many other frameworks if this isn't your cup of tea.

You can also hack in a second form in WebForms if you need... just put a closing </form> tag before yours, then open a new one after:

CODE:
<!-- Close the existing form tag that came from webforms -->
</form>
<!-- Your own form -->
<form id="myform" action="WhateverMyImageUploadEndpointIs">
...fields...
</form>
<!-- Open another form so the end result is well-formed -->
<form>

Adbot
ADBOT LOVES YOU

Ithaqua
Jul 18, 2003

Only in Kenya.

Vintersorg posted:

Oh, so I just learned that in asp.net you cannot have two forms on one page. So my idea above will not work. The entire site is created by a form itself. Not sure why, but it is. Could someone explain the significance of why a designer would choose it?

Make a user control.

Vintersorg
Mar 3, 2004

Three lives you shall have of me. No more, no less. Three and we are done.


Checking out those User Controls, thanks!

Boss came up to me and said we could either try a iFrame or even better just create an entire separate page since this is really for internal use only. They won't really need the default look of the site (cadets.ca).

Also this page ( http://www.geekpedia.com/KB62_A-pag...e-Form-tag.html ) was awesome with people bitching up a storm.

BizarroAzrael
Apr 6, 2006

Samurai on the Prowl


This is a bit general, but I'll post it here since the thread is for the languages I'm most familiar with.

My education didn't have much low-level programming, I started with VB in college and did stuff like Actionscript and HTML at University, first doing "serious" programming in the last few years where I was recruited for a role with a lot of scripting (C#) in the games industry after doing a lot of testing. I feel fine with the actual programming, but I sometimes feel that I've learnt the wrong way, and that I sometimes am unable to express what I'm doing or struggle to understand what is being asked of me. Can anyone recommend a book or website, not necessarily focusing on C# or any particular language, that might help me perhaps be more confident that both I and my audience know what I'm talking about?

GrumpyDoctor
Jan 25, 2005

Trust me. I'm a doctor. An ANGRY doctor.

How can I get at the type parameter of a parameterized type? (It's my parameterized type so I can give it whatever it needs to facilitate this.) In C++, I'd do
C++ code:
template <typename T>
class Foo {
public:
    typedef T Bar;
};
I'm specifically trying to do this in F#, but if there's a C# way I can at least get some things to google. I know there are some possible reflection shenanigans but since the information is known at compile-time I thought it might be available then.

PDP-1
Oct 12, 2004

*click*


Is something like typeof(Foo<T>).GetGenericArguments() what you're looking for?

Zhentar
Sep 28, 2003

Brilliant Master Genius


^^ That would be among the reflection shenanigans to which he refers.

The type isn't known at the compile time. .NET generics are not templates, they only generate code for a single class, that is valid for all possible types that could be supplied.

ljw1004
Jan 18, 2005

rum


GrumpyDoctor posted:

How can I get at the type parameter of a parameterized type? (It's my parameterized type so I can give it whatever it needs to facilitate this.) I'm specifically trying to do this in F#

Here's an idiomatic way to write generic type parameters in functional languages. Use 'a (pronounced "alpha") or other apostrophe'd letters instead of capital T,U,V, to declare and refer to the type parameters.

code:
type 'a Foo =
  | Node of 'a Foo * 'a Foo
  | Leaf of 'a

let x = Node(Leaf "hello", Leaf "world")

let rec concat t =
    match t with
    | Node(left,right) -> (concat left) + (concat right)
    | Leaf(v) -> v

printfn "Concatenated tree: %A" (concat x)
Here's a more mutable manner of writing the same thing, more similar in style to imperative languages like C#/C++

code:
type 'a Bar(initialState:'a) = 
    let mutable state = initialState

    member x.GetState () = state
    member x.SetState (v) = state <- v

let y = Bar("hello")
y.SetState("world")
printfn "val = %A" (y.GetState ())
I should say that I don't understand exactly what you mean by "get at". If you're after "template specialization", you're out of luck! If you merely want to declare variables of that type, and do generic operations on them (e.g. the generic + operation in the first example), then the 'a trick is fine.

GrumpyDoctor
Jan 25, 2005

Trust me. I'm a doctor. An ANGRY doctor.

Zhentar posted:

^^ That would be among the reflection shenanigans to which he refers.

The type isn't known at the compile time. .NET generics are not templates, they only generate code for a single class, that is valid for all possible types that could be supplied.

Hm. F# does have something called statically resolved type parameters but I don't think it would help me here. That's good to know about .NET generics though!


My question is if there's a way for a' Foos to somehow provide the type of 'a to other code so that the other code can operate on 'as directly (and appropriately generically, obviously). The more I'm describing the problem, the more I'm thinking I'm SOL.

ljw1004
Jan 18, 2005

rum


GrumpyDoctor posted:

My question is if there's a way for a' Foos to somehow provide the type of 'a to other code so that the other code can operate on 'as directly (and appropriately generically, obviously). The more I'm describing the problem, the more I'm thinking I'm SOL.

Please clarify more about what you want to do. I'm still not getting it!

There are two ways you can provide the type to other code. You can provide it as a type at compile-time, in syntactic language constructs which expect a type:

code:
  type 'a Bar(initialState:'a) =
      member x.GetRRTI() = typeof<'a>
Here I've provided the type 'a to two other places in code (as an explicit type for the constructor parameter, and as a type argument for the typeof operator).

Also, in my original code, I called the + operator directly and generically, and it resolved to whichever + was appropriate. I could have constructed a tree with integers instead
code:
  let x = Node(Leaf 5, Leaf 10)
and instead of using a string + operator in my earlier example, it'd have picked an integer + operator.



You can also get a value of type System.Type, a kind of RTTI that represents what 'a was instantiated by. For instance,

code:
printfn "type = %A" (y.GetRTTI ()) // prints "System.String"
You can use this kind of thing to make runtime decisions based on the type of 'a (as opposed to compile-time decisions).

GrumpyDoctor
Jan 25, 2005

Trust me. I'm a doctor. An ANGRY doctor.

Well, I think I've pretty much confused myself into uselessness. That being said, whatever I'm doing now is working, but I'm not sure whether that's because of what you've told me or because design compromises I made before I asked my question actually did their job. (Fun fact: the parameterized type syntax you gave me doesn't actually seem to be anywhere in the F# language reference, which all uses angle brackets. Once I used your syntax and let the compiler automatically generalize what it could, everything went a lot smoother). At this point I don't even really remember what I was originally trying to do, now that I have something that works.

This was probably just another X/Y problem. I was looking for something equivalent to:
C++ code:
template <typename T>
class Foo {
public:
    typedef WrappedT T;
};

void bar() {
    Foo<int> a;
    a::WrappedT val1 = 6;
    a::WrappedT val2 = 9;
    doSomething(val1, val2);
    // or, you know, something useful
}
Your previous example didn't feel like it answered my question because it "provided" the type 'a by "providing" an 'a itself, which isn't what I was looking for. (Sorry for my terrible terminology - I suspect that if I had a better vocabulary for this I wouldn't even have the problem in the first place). Thanks for the help though!

ljw1004
Jan 18, 2005

rum


GrumpyDoctor posted:

This was probably just another X/Y problem. I was looking for something equivalent to:
C++ code:
template <typename T>
class Foo {
public:
    typedef WrappedT T;
};

void bar() {
    Foo<int> a;
    a::WrappedT val1 = 6;
    a::WrappedT val2 = 9;
    doSomething(val1, val2);
    // or, you know, something useful
}

I see. You're asking for a type alias (i.e. a name which refers to some other type), and you want this type alias to be qualified on an instance of some type.

In C++ it used to be important for abominations like "for(std::iterator<T1,Foo<T2>> i=...)", but in C++ that seems less pressing now that you can use type inference through the "auto" keyword.

I don't think you can do it in F#. I think the F# people tend to use type inference, which makes the need less pressing.

You can't do that in C#/VB. These languages have a deliberate design decision that people should by and large know types by their one true name rather than aliases. You can put "using" (C#) or "Imports" (VB) declarations at the top of the file to specify type aliases, and C# also allows type-aliases to be defined inside namespace declarations, but they can't go anywhere else (and can't go in the sort of place you're asking). Moreover, when you're using intellisense or tooltips, it always shows types by their canonical names rather than their aliases...

code:
using S1 = System.String;

namespace NS
{
    using S2 = System.String;

    static class Program
    {
        static void Main()
        {
            S1 a = "hello";
            var b = a; // hover over S1 or var and it shows "System.String"
        }
    }
}
PS. My 'a syntax is because I learnt the language in 1992 The fancy new kids on the block would write "type Foo<'a> = | Node of Foo<'a> * Foo<'a> | Leaf of 'a"

Sab669
Sep 24, 2009


This is kind of a random question, but is there a way to move where a form is displayed in Visual Studios in the designer?

Like this;

epalm
Nov 4, 2003



Sab669 posted:

is there a way to move where a form is displayed in Visual Studios in the designer?

Why?

epalm
Nov 4, 2003



Ok, I want to make absolutely sure of something relating to the unsubscribing of events.

The scenario is...

C# code:
class Program
{
    static void Main(string[] args)
    {
        new Program();
        Console.ReadLine();
    }

    public Program()
    {
        MyHat = new Hat() { Color = "Red" };
        MyHat.Color = "Blue";
        MyHat = new Hat() { Color = "Green" }; // the blue Hat is GC-able here, right?
        MyHat.Color = "Yellow";
        MyHat = null; // the yellow Hat is GC-able here, right?
    }

    Hat myHat;
    Hat MyHat
    {
        get { return myHat; }
        set
        {
            if (myHat != null)
                myHat.PropertyChanged -= MyHat_PropertyChanged; // is this necessary?

            myHat = value;

            if (myHat != null)
                myHat.PropertyChanged += MyHat_PropertyChanged;
        }
    }

    void MyHat_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        Console.WriteLine("the {0} property of my hat has changed", e.PropertyName);
    }
}

class Hat : INotifyPropertyChanged
{
    private string color = string.Empty;
    public string Color
    {
        get { return color; }
        set { color = value; NotifyPropertyChanged("Color"); }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    public void NotifyPropertyChanged(String propertyName)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
}
Is myHat.PropertyChanged -= MyHat_PropertyChanged; necessary? Seems to me that MyHat has a reference to Program (and not the other way around), so MyHat is free to be GC'd when it falls out of scope or is set to null. Right? So I don't really need to manually unsubscribe from that event handler?

epalm fucked around with this message at May 25, 2012 around 19:12

Sab669
Sep 24, 2009



Well, I got a new job recently and my monitor space is... significantly larger than what I'm used to. I can't seem to get a comfortable setting to work in when I'm looking at the designer.

I know it sounds kind of retarded and babyish, I wasn't sure if it was some easy thing to do that I just never learned / couldn't find on Google.

Zhentar
Sep 28, 2003

Brilliant Master Genius


The old Hat will maintain a strong reference to your Program class. So without the unsubscribe, the Program instance would not prevent the Hat instance from being GCed, but the Hat instance would prevent the Program instance from being GCed. Obviously, that's not a problem in this scenario, so no, it's not strictly necessary.

That said, I still think it would be a pretty good idea to stick to that pattern; you're opening yourself up to a lot of potential issues if you don't stick to it (like getting conflicting updates for two different Hats...).

If you just don't want to type that much, you could easily create a snippet that would do all of the work for you.

Ithaqua
Jul 18, 2003

Only in Kenya.

Zhentar posted:

The old Hat will maintain a strong reference to your Program class. So without the unsubscribe, the Program instance would not prevent the Hat instance from being GCed, but the Hat instance would prevent the Program instance from being GCed. Obviously, that's not a problem in this scenario, so no, it's not strictly necessary.

That said, I still think it would be a pretty good idea to stick to that pattern; you're opening yourself up to a lot of potential issues if you don't stick to it (like getting conflicting updates for two different Hats...).

If you just don't want to type that much, you could easily create a snippet that would do all of the work for you.

Yeah, I just stick to the rule "always unsubscribe to that which you subscribe", and it doesn't steer me wrong. Of course, that means you can't use lambdas for events, but that's not a big deal.

ljw1004
Jan 18, 2005

rum


Ithaqua posted:

Yeah, I just stick to the rule "always unsubscribe to that which you subscribe", and it doesn't steer me wrong. Of course, that means you can't use lambdas for events, but that's not a big deal.

Sure you can! Like this...

code:
Dim lambda As RoutedEventHandler = Sub(s,e)
                                     ' do stuff...
                                     RemoveHandler bmp.ImageOpened, lambda
                                   End Sub

AddHandler bmp.ImageOpened, lambda

epalm
Nov 4, 2003



ljw1004 posted:

Sure you can! Like this...

in C#?

Ithaqua
Jul 18, 2003

Only in Kenya.


Yeah, I forgot about that.

C# code:
var oc = new ObservableCollection<string>();
NotifyCollectionChangedEventHandler foo = (sender, args) => Console.WriteLine("foo");
oc.CollectionChanged += foo;
oc.CollectionChanged -= foo;

PhonyMcRingRing
Jun 6, 2002


Ithaqua posted:

Of course, that means you can't use lambdas for events, but that's not a big deal.

Sure as hell doesn't stop the WPF Toolkit's charting library from using them everywhere. That library leaks event handlers all over the drat place.

Sir DonkeyPunch
Mar 23, 2007

I didn't hear no bell


Sab669 posted:

This is kind of a random question, but is there a way to move where a form is displayed in Visual Studios in the designer?

Like this;


I wonder if you could undock the designer window...

I doubt there's a way to move the form itself because absolute positioning starts a 0,0 in the top left of the designer

IratelyBlank
Dec 2, 2004
The only easy day was yesterday

Does anyone know of a way to compare two images with some amount of error tolerance? Right now what I'm doing is hashing both images and comparing the hashes which leaves absolutely no room for error and on certain images I might have very subtle shading differences or something but the images are 99% the same.

Sedro
Dec 31, 2008


You're looking for a perceptual hash.

uXs
May 3, 2005

Mark it zero!

Sir DonkeyPunch posted:

I wonder if you could undock the designer window...

I doubt there's a way to move the form itself because absolute positioning starts a 0,0 in the top left of the designer

Drastic solution: use WPF. The WPF designer puts forms in the middle, I think.

Hughlander
May 11, 2005



I'm looking to code a simulation in C# that would enable a remote client to send a message to a server (Either message queue or WCF) and immediately get an acknowledgement that the message was delivered. But then the message itself wouldn't actually be processed for X minutes of time (Determined by the message.) I'd love for it all to be within a MSMQ type solution to guarantee the processing of the message. I've done something similar years ago in Java using JMS and a database as a priority queue, but I'm hoping that in the last 10 years there's something native in the .NET ecosystem that I could leverage.

Basically, I want something that acts as a message queue where there's entries in it, but each entry has a timestamp that's the earliest they should be processed. If the timestamp hasn't been reached, the queue looks empty when work is requested. If there are 5 messages in the queue that has reached the timestamp, they're processed in the order of the stamp, not the order of delivery/insertion.

Anything like that out there?

Uziel
Jun 28, 2004

Ask me about losing 200lbs, and becoming the Viking God of W&W.

This will probably lead into a bigger question, but I'm working on improving single user performance for an intranet application that has become business critical.

We are unfortunately storing large custom objects in session state (using session state server) and are paying a performance price due to the serialization/deserialization. I bought our team Ultra-Fast ASP.NET (http://www.amazon.com/Ultra-Fast-AS...r/dp/1430223839) and we are going through it, but given that we are using a single web server web garden, using cache for everything isn't ideal either (distributed cache also serializes/deserializes from what I understand).

I was starting to look into MVC, as its moving toward a stateless nature, but from what I've read there are still usages for session as our application is closer to "shopping cart" than basic "use a form to edit something in a database".

Any thoughts or opinions as to what direction we should be going? If more information would help, I can elaborate.

ljw1004
Jan 18, 2005

rum


Hughlander posted:

Basically, I want something that acts as a message queue where there's entries in it, but each entry has a timestamp that's the earliest they should be processed. If the timestamp hasn't been reached, the queue looks empty when work is requested. If there are 5 messages in the queue that has reached the timestamp, they're processed in the order of the stamp, not the order of delivery/insertion.

Azure message queues work mostly like this (look at the "optional validity timeout" on PutMessage, which is specified as a time delay rather than a timestamp).

Vintersorg
Mar 3, 2004

Three lives you shall have of me. No more, no less. Three and we are done.


edit: nvm, figured something out -- just need to set a virtual path

ps Ektron sucks

Vintersorg fucked around with this message at May 29, 2012 around 14:57

epalm
Nov 4, 2003



(WPF!)

Ok, standard task of clicking a button which initiates a long-running process, I want to disable the button, run an indeterminate progress bar, and when the process is finished, enable the button and stop the progress bar.

Obviously this isn't going to work:

C# code:
private void Button_Click(object sender, RoutedEventArgs e)
{
    string result = string.Empty;
    button.IsEnabled = false;
    progressBar.IsIndeterminate = true;
    
    result = RunLongProcess();
    
    textBox.Text = result;
    button.IsEnabled = true;
    progressBar.IsIndeterminate = false;
}
This works perfectly:

C# code:
private void Button_Click(object sender, RoutedEventArgs e)
{
    string result = string.Empty;
    button.IsEnabled = false;
    progressBar.IsIndeterminate = true;
    
    ThreadStart ts = delegate
    {
        result = RunLongProcess();

        Dispatcher.BeginInvoke(DispatcherPriority.Normal, (EventHandler)delegate
        {
            textBox.Text = result;
            button.IsEnabled = true;
            progressBar.IsIndeterminate = false;
        }, null, null);
    };

    ts.BeginInvoke(null, null);
}
How can I stuff the above into a pretty function? I've been playing with Tasks and Actions and I just need to stop thrashing and see a solid example.

PS: My code isn't really sitting in a button_click handler, and I'm not really assigning stuff to textboxes directly. Trust me when I say I love MVVM and DataBinding.

PPS: Forgot to mention, I can't waiiiit to use await! But we're not on .NET 4.5 yet, and won't be for a while, it seems.

epalm fucked around with this message at May 29, 2012 around 17:02

Ithaqua
Jul 18, 2003

Only in Kenya.

Vintersorg posted:

This might be a shot in the dark but does anyone know how to set a 1-dimensional array for metadata? We are using Ektron (think I mentioned this in other posts) and I am going by this guide on their site.

http://reference.ektron.com/develop...anager/add.aspx

Now when I go to add a image it's requesting Metadata to be set. The picture of the error is below and I am not sure what's up. Even on their own forums I have gotten no replies. Through Google I cannot find a way to set this thing. It seems like it's a built in function but if I could just pass it a empty array that would be fine too.





Can't you just do

C# code:
var metadataArray = new ContentMetadata[1];
metadataArray[0] = cMetaTypeData;
?

Vintersorg
Mar 3, 2004

Three lives you shall have of me. No more, no less. Three and we are done.


I'll try that out. But if not I found something else that is kind of a work around. Thanks Ithaqua!

fankey
Aug 31, 2001


epswing posted:

How can I stuff the above into a pretty function? I've been playing with Tasks and Actions and I just need to stop thrashing and see a solid example.
Use async
C# code:
private void Button_Click(object sender, RoutedEventArgs e)
{
    string result = string.Empty;
    button.IsEnabled = false;
    progressBar.IsIndeterminate = true;
    
    result = await RunLongProcess();
    
    textBox.Text = result;
    button.IsEnabled = true;
    progressBar.IsIndeterminate = false;
}

Ithaqua
Jul 18, 2003

Only in Kenya.

fankey posted:

Use async
C# code:
private void Button_Click(object sender, RoutedEventArgs e)
{
    string result = string.Empty;
    button.IsEnabled = false;
    progressBar.IsIndeterminate = true;
    
    result = await RunLongProcess();
    
    textBox.Text = result;
    button.IsEnabled = true;
    progressBar.IsIndeterminate = false;
}

He's probably not using .NET 4.5, but yes doing it async would be the way to go.

Of course, seeing codebehind in a WPF application is a sin.

fankey
Aug 31, 2001


Ithaqua posted:

He's probably not using .NET 4.5, but yes doing it async would be the way to go.

Of course, seeing codebehind in a WPF application is a sin.

If you are crazy like me you can use the Async CTP with VS2010. Working so far ( fingers crossed! ). The amount of code and complexity it removed from my code is worth the risk of a problem popping up.

epalm
Nov 4, 2003




I can't waiiiit to use await! But we're not on .NET 4.5 yet, and won't be for a while, it seems.

fankey
Aug 31, 2001


epswing posted:

I can't waiiiit to use await! But we're not on .NET 4.5 yet, and won't be for a while, it seems.
Before I switched to using Async I would sometimes use the following pattern.
code:
void RunLongProcessInThread(Action<string> processDone)
{
  Dispatcher disp = Dispatcher.CurrentDispatcher;
  ThreadStart ts = delegate
  {
    result = RunLongProcess();
    disp.BeginInvoke(DispatcherPriority.Normal, (EventHandler)delegate
    {
      processDone(result);
    }, null, null);
  };
}

private void Button_Click(object sender, RoutedEventArgs e)
{
    string result = string.Empty;
    button.IsEnabled = false;
    progressBar.IsIndeterminate = true;

    RunLongProcessInThread((text)=>
    {
      textBox.Text = result;
      button.IsEnabled = true;
      progressBar.IsIndeterminate = false;
    });
}

fankey fucked around with this message at May 29, 2012 around 17:15

ninjeff
Jan 19, 2004



epswing posted:

How can I stuff the above into a pretty function? I've been playing with Tasks and Actions and I just need to stop thrashing and see a solid example.

In VB because I can never remember C#'s byzantine switch syntax:
VB Script code:
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
    button.IsEnabled = False
    progressBar.IsIndeterminate = True

    Dim dispatcherScheduler = TaskScheduler.FromCurrentSynchronizationContext()

    Task.Factory.
        StartNew(Sub() RunLongProcess()).
        ContinueWith(Sub(t)
                         button.IsEnabled = True
                         progressBar.IsIndeterminate = False
                         Select Case t.Status
                             Case TaskStatus.RanToCompletion
                                 textBox.Text = t.Result
                             Case TaskStatus.Faulted
                                 textBox.Text = t.Exception.ToString()
                             Case TaskStatus.Canceled
                                 textBox.Text = "Canceled"
                         End Select
                     End Sub,
                     scheduler:=dispatcherScheduler)
End Sub
You could make a static instance of TaskScheduler on the dispatcher instead of creating a new one in each event handler, but you get the idea.

ninjeff fucked around with this message at May 29, 2012 around 17:52

Adbot
ADBOT LOVES YOU

Dietrich
Sep 11, 2001

Bullshit detected sir!


I published my first thing to NuGet, and holy poo poo is that easy and awesome. Anyone else using it?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply
«369 »