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.
 
  • Post
  • Reply
New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Newf posted:

That had occurred to me, but wouldn't a dictionary's default action be to overwrite the data associated with an existing key with the new data? I want to keep the original. In particular, the only thing that changes with the new inserts is a timestamp, but I'm only interested in knowing the earliest timestamp.

Semantically, it's a set of these objects, and the 'Key' here is itself data, so I don't like splitting the object into Key / Value.

Can you describe the initial problem in a little bit more detail? I'm always wary of the XY Problem rearing its head.

Adbot
ADBOT LOVES YOU

chippy
Aug 16, 2006

OK I DON'T GET IT

Newf posted:

Ah, that clarifies.

Overriding Equals did work (thanks Betjeman!), but I was confused because I knew that Add (and Contains) were supposed to be O(1), so I figured that it had to be checking with GetHashCode(). Makes sense that it's done as a first pass.

Thanks all.

Bear in mind that it's also recommended that if you override Equals(), you should also override GetHashCode(), to ensure that in any case where Equals() returns true for a pair of objects, GetHashCode() would return the same hash, and vice versa.

In Java at least, if you don't do this, you can get funky behaviour with Sets and other collections. I'm not 100% sure if this applies to C# too, but I would think it likely.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

chippy posted:

Bear in mind that it's also recommended that if you override Equals(), you should also override GetHashCode(), to ensure that in any case where Equals() returns true for a pair of objects, GetHashCode() would return the same hash, and vice versa.

In Java at least, if you don't do this, you can get funky behaviour with Sets and other collections. I'm not 100% sure if this applies to C# too, but I would think it likely.

You're correct.

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.

Ithaqua posted:

Can you describe the initial problem in a little bit more detail? I'm always wary of the XY Problem rearing its head.

It's really not a complicated issue, and either implementation works, I think. I've left it as it because the Equals override was only a couple of lines and I'd rather not have to wrap my Adds in Try/Catch blocks.

The initial problem is to keep a list of objects (they're boats, incidentally) who have requested a service. Each boat, after requesting service, will receive a default service until the service is configured (server side) for them by an administrator. I just want to keep a list of boats who have requested service but remain unconfigured. I also want the dates at which they first requested service. So the bean is just a unique identifier for the boat (the key in my problem), the boat's "common name", and the date of the service request. It's possible for a boat to make several service requests before the administrator configures them, but I don't want double/triple/ ect records of that.

Betjeman
Jul 14, 2004

Biker, Biker, Biker GROOVE!

uXs posted:

That... looks like a completely different problem?

The problem happened to us (and again, may be completely different to your problem, I'm not sitting at your desk) that the call to the web service was not reporting the actual error, but instead simply failing at the attempt to connect to the web service in teh production environment. Only sticking in shitloads of trace code to try and find out what the problem was revealed the error.

The symptom was the same, that I could access a web service from a browser, from SoapUI, from anywhere but the app installed in an IIS environment. You said you can connect if using different credentials, so your problem does suggest it's a permissions issue?

E: sorry misread the bit about it working from a browser then working from your application. Maybe your browser is accessing via different credentials, and therefore creating whatever files the web service connection needs to be in the temp directory?

Betjeman fucked around with this message at 16:03 on Jul 16, 2014

uXs
May 3, 2005

Mark it zero!

Betjeman posted:

The problem happened to us (and again, may be completely different to your problem, I'm not sitting at your desk) that the call to the web service was not reporting the actual error, but instead simply failing at the attempt to connect to the web service in teh production environment. Only sticking in shitloads of trace code to try and find out what the problem was revealed the error.

The symptom was the same, that I could access a web service from a browser, from SoapUI, from anywhere but the app installed in an IIS environment. You said you can connect if using different credentials, so your problem does suggest it's a permissions issue?

E: sorry misread the bit about it working from a browser then working from your application. Maybe your browser is accessing via different credentials, and therefore creating whatever files the web service connection needs to be in the temp directory?

Yeah I think I'll mess around with the credentials some more. But if I can't find it easily I'll just download the wsdl on application startup to circumvent the problem.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Newf posted:

It's really not a complicated issue, and either implementation works, I think. I've left it as it because the Equals override was only a couple of lines and I'd rather not have to wrap my Adds in Try/Catch blocks.

The initial problem is to keep a list of objects (they're boats, incidentally) who have requested a service. Each boat, after requesting service, will receive a default service until the service is configured (server side) for them by an administrator. I just want to keep a list of boats who have requested service but remain unconfigured. I also want the dates at which they first requested service. So the bean is just a unique identifier for the boat (the key in my problem), the boat's "common name", and the date of the service request. It's possible for a boat to make several service requests before the administrator configures them, but I don't want double/triple/ ect records of that.

Personally, I'd use a Dictionary and check .ContainsKey before insertion, but I don't think there's a functional difference. It just seems more appropriate to me to use a Dictionary when you're working with keys and values.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Bognar posted:

Personally, I'd use a Dictionary and check .ContainsKey before insertion, but I don't think there's a functional difference. It just seems more appropriate to me to use a Dictionary when you're working with keys and values.

I'm with you. And I've seen too many bad GetHashCode overrides.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
It doesn't help that there's no definitive library method for combining hash codes. Tuple<T1, T2> uses this:

C# code:
internal static int CombineHashCodes(int h1, int h2) { 
    return (((h1 << 5) + h1) ^ h2);
} 

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.

My prejudice towards sets here probably comes from my math background. I do recognize that it's better practice to use a dictionary, specifically for the reason Ithaqua mentioned of constructing lovely hash codes. In this case though, the hash code is just inheriting from String.GetHashCode(), so there's no chance that it's bad...

raminasi
Jan 25, 2005

a last drink with no ice
If I'm inheriting from an abstract class, is there really no way to make one of the overridden properties more accessible without essentially duplicating it?

ljw1004
Jan 18, 2005

rum

Newf posted:

My prejudice towards sets here probably comes from my math background. I do recognize that it's better practice to use a dictionary, specifically for the reason Ithaqua mentioned of constructing lovely hash codes. In this case though, the hash code is just inheriting from String.GetHashCode(), so there's no chance that it's bad...

There is a chance that it's bad! e.g.

code:
class C {
   public string s {get; set;}
   public override int GetHashCode() {return s==null ? 0 : s.GetHashCode();}
}
This is bad because if ever the string changes while an instance of "C" is inside the HashSet, then it will be in there under the previous has-code rather than the new one.

The general rule is: only compute GetHashCode from fields/properties that are guaranteed not to change after construction, e.g. because they have the readonly modifier

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

GrumpyDoctor posted:

If I'm inheriting from an abstract class, is there really no way to make one of the overridden properties more accessible without essentially duplicating it?

Use the new keyword and make a call to base.SomeMethod? It's still essentially duplication, but you get to keep the same name.

raminasi
Jan 25, 2005

a last drink with no ice

Bognar posted:

Use the new keyword and make a call to base.SomeMethod? It's still essentially duplication, but you get to keep the same name.

I wasn't clear. I have:

C# code:
public abstract class AbstractButt
{
    protected int Size { get; }
}
Now when I make:

C# code:
public class ConcreteButt : AbstractButt
{
    protected override int Size { get { return 10; } }
}
I want to make Size available, say, internally, but I can't do that, right?

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
Ah, if you're implementing an abstract method/property then no you can't change access rights.

gnatalie
Jul 1, 2003

blasting women into space
According to our lord and savior Jon Skeet, the answer is no:

Jon Skeet posted:

It's a shame that you can't widen access in C# as you can in Java, but
I'm glad you can't narrow it as that would break Liskov's
substitutability rule (depending on what it actually meant to narrow
the access, of course).

b0lt
Apr 29, 2005

ljw1004 posted:

There is a chance that it's bad! e.g.

code:
class C {
   public string s {get; set;}
   public override int GetHashCode() {return s==null ? 0 : s.GetHashCode();}
}
This is bad because if ever the string changes while an instance of "C" is inside the HashSet, then it will be in there under the previous has-code rather than the new one.

The general rule is: only compute GetHashCode from fields/properties that are guaranteed not to change after construction, e.g. because they have the readonly modifier

The better rule is don't use mutable values as keys to a hashmap. The even better rule is don't use mutable values.

Sedro
Dec 31, 2008

GrumpyDoctor posted:

If I'm inheriting from an abstract class, is there really no way to make one of the overridden properties more accessible without essentially duplicating it?
Explicit interface implementation might work for you. Just cast or implicitly convert to IButt when you need to access the property.
C# code:
public interface IButt
{
    int Size { get; }
}

public abstract class AbstractButt
{
    protected abstract int Size { get; }
}

public class ConcreteButt : AbstractButt, IButt
{
    protected override int Size { get { return 10; } }
    int IButt.Size { get { return Size; } }
}

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


I have a List<DataRecord> dataRecords that I want to display in a WPF DataGrid. DataRecord is defined more or less as follows:

C# code:
public class DataRecord
{
   public ulong Yeartime { get; set; }
   public List<DataItem> Items {get; set; }
}

public class DataItem
{
   public MetaData Info {get; set;}
   public object Data {get; set;} // any of IntX, UIntX, single, double, byte[], char[]
   public string DataAsString { get { /* ... */ } }
}

public class MetaData
{
   public string Name {get; set;}
   public DataType Type {get; set;} // enum, not important
   // ...
}
This info is being filled by reading a file, which is where I learn the number of DataItems in a single record and their metadata (and of course the data itself).

Setting my DataGrid's ItemSource to dataRecords does more or less what I expected: give me two columns of Yeartime and Items, the former being the numbers I expect and the latter being "(Collection)".

I want to programmatically break out that List<DataItem> each into their own column, with the header being item.Info.Name and the cell data being item.DataAsString.

How would I go about this? Binding is a confusing and horrifying subject to me, I'm just barely getting started with C# and .NET let alone WPF :ohdear:

Ciaphas fucked around with this message at 21:01 on Jul 16, 2014

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Ciaphas posted:

I have a List<DataRecord> dataRecords that I want to display in a WPF DataGrid. DataRecord is defined more or less as follows:

C# code:
public class DataRecord
{
   public ulong Yeartime { get; set; }
   public List<DataItem> Items {get; set; }
}

public class DataItem
{
   public MetaData Info {get; set;}
   public object Data {get; set;} // any of IntX, UIntX, single, double, byte[], char[]
   public string DataAsString { get { /* ... */ } }
}

public class MetaData
{
   public string Name {get; set;}
   public DataType Type {get; set;} // enum, not important
   // ...
}
This info is being filled by reading a file, which is where I learn the number of DataItems in a single record and their metadata (and of course the data itself).

Setting my DataGrid's ItemSource to dataRecords does more or less what I expected: give me two columns of Yeartime and Items, the former being the numbers I expect and the latter being "(Collection)".

I want to programmatically break out that List<DataItem> each into their own column, with the header being item.Info.Name and the cell data being item.DataAsString.

How would I go about this? Binding is a confusing and horrifying subject to me, I'm just barely getting started with C# and .NET let alone WPF :ohdear:

You can either define a template column to display the additional stuff, or let part of your viewmodel's behavior be to transform and project the data into a type intended for display.

Option 1:
code:
//SomeRecords is an ObservableCollection<DataRecord>

<DataGrid ItemsSource="{Binding SomeRecords}" AutoGenerateColumns="False">
    <DataGrid.Columns>
        <DataGridTemplateColumn>
            <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <Grid>
                <TextBlock Text="{Binding Yeartime}"/>
                </Grid>
            </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
        <DataGridTemplateColumn>
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <Grid>
                        <DataGrid ItemsSource="{Binding Items}"/>
                    </Grid>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>

kingcrimbud
Mar 1, 2007
Oh, Great. Now what?

kingcrimbud posted:

I'm trying to combine a few components of the Enterprise Library. In this instance, I want to implement some retry logic (Transient Fault Handling) but I want to add this in behind-the-scenes (via Unity Interception). I'm using interception elsewhere but I can't seem to figure out the syntax needed to add these two components together.

For interception, this will essentially be a no-op, but is where I can add my retry logic, within an IInterceptionBehavior:

code:
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
{
    return getNext()(input, getNext);
}
Let's assume that I want to retry an awaitable service call, that takes in a single request object and returns a single response object:

code:
public async Response DoSomething(Request)
I've injected my RetryPolicy into my implementation of IInterceptionBehavior, which contains the Invoke method above. But how do I combine the two? it'd be along the lines of this, but a whole lot messier I'm assuming:

code:
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
{
    return this.RetryPolicy.ExecuteAsync(getNext()(input, getNext));
}
Anyone have experience with this?

tl;dr I know how to use Transient Fault Handling and Unity Interception, but don't know how to combine them together

Bueller? Anyone? I still haven't figured this out.

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Ithaqua posted:

You can either define a template column to display the additional stuff, or let part of your viewmodel's behavior be to transform and project the data into a type intended for display.

Option 1:
code:
//SomeRecords is an ObservableCollection<DataRecord>

<DataGrid ItemsSource="{Binding SomeRecords}" AutoGenerateColumns="False">
    <DataGrid.Columns>
        <DataGridTemplateColumn>
            <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <Grid>
                <TextBlock Text="{Binding Yeartime}"/>
                </Grid>
            </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
        <DataGridTemplateColumn>
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <Grid>
                        <DataGrid ItemsSource="{Binding Items}"/>
                    </Grid>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>

I ended up (after a lot of fuss and bother) going for Option 2, sort of. I turned off autogeneration in the datagrid, made its ItemsSource my list of DataRecords, and, in my xaml code-behind, generated, bound, and added the individual columns by selecting out the name and numeric index of each DataItem.

I don't have the code in front of me but it was something like this.
C# code:
// AllDataRecords is List<DataRecord>
var columns = myViewModel.AllDataRecords.First().Select((x,i)=>new { Name = x.Info.Name, Index = i });

foreach (var c in columns)
{
   Binding b = new Binding(string.Format("Items[{0}].DataAsString", c.Index));
   dataGrid.Columns.Add(new DataGridTextColumn() { Header = c.Name, Binding = b });
}
I don't know how robust it is, or if there was a LINQ alternative to that particular Select syntax, or how much of this is gonna change later, or even if this is remotely idiomatic or not, but it does work. Now I've got the problem that the DataGrid is very very slow to scroll (some 200mb of data, with 20 columns and 500k rows), but one step at a time I suppose.

Mr. Crow
May 22, 2008

Snap City mayor for life

Ciaphas posted:

I ended up (after a lot of fuss and bother) going for Option 2, sort of. I turned off autogeneration in the datagrid, made its ItemsSource my list of DataRecords, and, in my xaml code-behind, generated, bound, and added the individual columns by selecting out the name and numeric index of each DataItem.

I don't have the code in front of me but it was something like this.
C# code:
// AllDataRecords is List<DataRecord>
var columns = myViewModel.AllDataRecords.First().Select((x,i)=>new { Name = x.Info.Name, Index = i });

foreach (var c in columns)
{
   Binding b = new Binding(string.Format("Items[{0}].DataAsString", c.Index));
   dataGrid.Columns.Add(new DataGridTextColumn() { Header = c.Name, Binding = b });
}
I don't know how robust it is, or if there was a LINQ alternative to that particular Select syntax, or how much of this is gonna change later, or even if this is remotely idiomatic or not, but it does work. Now I've got the problem that the DataGrid is very very slow to scroll (some 200mb of data, with 20 columns and 500k rows), but one step at a time I suppose.

I want to say datagrids don't use virtualizingstackpanels by default so maybe look into that for a quick fix to the performance.

There will be some other costs to using one though which you may or may not care about (no smooth scrolling for example).

Also I'd strongly recommend not building that by hand in the code behind, the XAML is made for this stuff and that's not what Ithaqa was talking about with option two.

Mr. Crow fucked around with this message at 03:56 on Jul 17, 2014

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Yeah, I sort of realized that wasn't quite the Option Two being presented after I posted. I'm new to the whole MVVM thing too though--in fact this is literally my first go at making GUI anything since Visual Basic 6.0 in high school--so it took me a while to realize. :(

I tried for several hours today to get binding to work in the XAML, but I kept getting blindsided mostly by the fact that the number of Items in each DataRecord, though the same across records, is completely unknown until runtime. (Their types are unknown, too, but that's what that DataAsString property is for :v:) What can I do in the XAML to set up those column definitions without that knowledge?

(The fact that my data is essentially a list of lists with some metadata leaves me confused too, but I'm sure the solution to that problem is simpler.)

Ciaphas fucked around with this message at 05:02 on Jul 17, 2014

Mr. Crow
May 22, 2008

Snap City mayor for life

Ciaphas posted:

Yeah, I sort of realized that wasn't quite the Option Two being presented after I posted. I'm new to the whole MVVM thing too though--in fact this is literally my first go at making GUI anything since Visual Basic 6.0 in high school--so it took me a while to realize. :(

I tried for several hours today to get binding to work in the XAML, but I kept getting blindsided mostly by the fact that the number of Items in each DataRecord, though the same across records, is completely unknown until runtime. (Their types are unknown, too, but that's what that DataAsString property is for :v:) What can I do in the XAML to set up those column definitions without that knowledge?

(The fact that my data is essentially a list of lists with some metadata leaves me confused too, but I'm sure the solution to that problem is simpler.)

You never really explained why Ithaqua's example failed you? It should have worked generally as-is; the second column wouldn't look exactly like you want, but nothing some header styles and templates can't fix.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
Yeah, the Option #2 I was talking about was more along these lines:

You have your collection of DataRecords. Those obviously aren't intended for display as-is -- it's some sort of DTO. It represents the raw data you got back from something.

You should be, at some point prior to that object hitting your view, transforming it into a model intended for actual display. Automapper can help here, or you can do it by hand. Once you have a nice, simple model of the data that's intended for display, you just bind that to your data grid and you're golden.

Sedro
Dec 31, 2008

kingcrimbud posted:

Bueller? Anyone? I still haven't figured this out.
This seems to work

Service:
C# code:
public class Request { public string Body { get; set; } }
public class Response { public string Body { get; set; } }

public interface IMyService
{
    Task<Response> DoSomethingAsync(Request request);
}

public class MyService : IMyService
{
    int i = 0;

    public async Task<Response> DoSomethingAsync(Request request)
    {
        await Task.Delay(TimeSpan.FromSeconds(1));

        // simulate transient failure
        if (i < 3)
        {
            ++i;
            Console.WriteLine("Failure " + i);
            throw new Exception("Failure " + i);
        }

        // eventual success
        return new Response { Body = request.Body };
    }
}
Behavior:
C# code:
public class RetryBehavior : IInterceptionBehavior
{
    static MethodBase DoSomethingAsync = typeof(IMyService).GetMethod("DoSomethingAsync");

    readonly RetryPolicy policy = RetryPolicy.DefaultFixed;

    public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
    {
        if (input.MethodBase == DoSomethingAsync)
        {
            // inject retry policy
            var task = policy.ExecuteAsync(() =>
            {
                var result = getNext()(input, getNext);
                return result.ReturnValue as Task<Response>;
            });
            return input.CreateMethodReturn(task);
        }

        return getNext()(input, getNext);
    }

    public IEnumerable<Type> GetRequiredInterfaces()
    {
        yield return typeof(IMyService);
    }

    public bool WillExecute
    {
        get { return true; }
    }
}
Usage:
C# code:
var container = new UnityContainer();
container.AddNewExtension<Interception>();
container.RegisterType<IMyService, MyService>(
    new Interceptor<InterfaceInterceptor>(),
    new InterceptionBehavior<RetryBehavior>());

var service = container.Resolve<IMyService>();
var future = service.DoSomethingAsync(new Request { Body = "butts" });
var response = future.GetAwaiter().GetResult(); // can't await in a console app
Console.WriteLine(response.Body);
Output:
code:
Failure 1
Failure 2
Failure 3
butts

JawnV6
Jul 4, 2004

So hot ...
I have a C program that compiles cleanly on Linux/OSX. I need it to run on Windows. There is some light file i/o and a lot of usage of a COM port.

I am familiar with C#'s COM port handling and so far I'm able to communicate to the device. Before I get into the heavy lifting of duplicating the C program's functionality in C#, is there a lighter path than this? I've spent two nights on skype trying to walk a technician through using this under linux and a rewrite is looking better and better.

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Ithaqua posted:

Yeah, the Option #2 I was talking about was more along these lines:

You have your collection of DataRecords. Those obviously aren't intended for display as-is -- it's some sort of DTO. It represents the raw data you got back from something.

You should be, at some point prior to that object hitting your view, transforming it into a model intended for actual display. Automapper can help here, or you can do it by hand. Once you have a nice, simple model of the data that's intended for display, you just bind that to your data grid and you're golden.

Thanks, I'll look up Automapper. This explanation kind of makes more sense with what I understand about MVVM anyway.


Mr. Crow posted:

You never really explained why Ithaqua's example failed you? It should have worked generally as-is; the second column wouldn't look exactly like you want, but nothing some header styles and templates can't fix.

Yesterday it displayed absolutely nothing so I abandoned it, but I tried it again this morning and it worked :pwn:. I must have typoed the first ItemsSource or something and not noticed.

As you say, it looks like arse, but it does work, and I can probably figure out how to mess with those data templates. I'm going to try the second option as Ithaqua described it first, since that reorganizing will help me later anyway.

(Context, I'm trying to make a graphical diff application for the files we're working with. Up to now we've used a utility to convert them to CSV and throw those into Beyond Compare, which works but has a few important limitations that make it a pain in the rear end. So I figured I'd cut my teeth on learning C#, .NET, MVVM, and WPF all at once by putting this together.

I may have overreached myself :suicide:)


(edit) Oh, AutoMapper is third party? That's out then, my work machine has no internet access (don't ask).

I'm a little stumped at the moment at how to go about it manually. If I'm understanding things, I'd want to flatten what I've got above into something like this, right?

C# code:
class DataRecordDisplay
{
   public ulong Yeartime {get; set;}
   public string NameOfItem1 {get; set;}
   public string NameOfItem2 {get; set;}
   // etc.
}
Problems are, the autogenerated column headers are named by the name of the properties, so I'd have to name the properties at runtime somehow. Ditto not knowing how many properties this class would even have until runtime. That almost sounds like I'd have to learn some Reflection stuff, but that's making a bit of a mountain out of a molehill I think.

I'm sure I'm being stupid and there's a simpler way to go about it :(

Ciaphas fucked around with this message at 19:09 on Jul 17, 2014

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.
I've thrown a bootstrap tarp over a .net webforms app. I used this starter template and things have gone peachy with one little hickup. The markup for the navbar is in my WebApp.master markup file, which is then followed by a ContentPlaceHolder for my pages to go. The problem is that I'm not sure how best to go about altering the nav element that's tagged as 'active' when clicking from one page to the next.

code:
...
    <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <a class="navbar-brand" href="#">Project name</a>
        </div>
        <div class="collapse navbar-collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Home</a></li>  <-- this element stuck as 'active'
            <li><a href="#about">Page1</a></li>
            <li><a href="#contact">Page2a></li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </div>

    <div class="container" style="padding-top: 65px;">
      <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server" />
    </div>
...
My first thought is to put something in the Page_Load of WebApp.Master.cs that reads Request.Url and then assigns the class="active" decoration to the appropriate element. Doing some poking though, and it doesn't look like code-behind files enjoy working with DOM elements (probably because the html is output after all of the code-behind has run?).


edit: Ok, that worked. I gave each <li> an id and runat="server" and something along the lines of

code:
if (Request.Url.ToString().Contains("Page1"))
  Page1.Attributes["class"] = "active";
works just fine.

Newf fucked around with this message at 19:26 on Jul 17, 2014

ljw1004
Jan 18, 2005

rum

JawnV6 posted:

I have a C program that compiles cleanly on Linux/OSX. I need it to run on Windows. There is some light file i/o and a lot of usage of a COM port.

I am familiar with C#'s COM port handling and so far I'm able to communicate to the device. Before I get into the heavy lifting of duplicating the C program's functionality in C#, is there a lighter path than this? I've spent two nights on skype trying to walk a technician through using this under linux and a rewrite is looking better and better.

When I ported C code from linux to windows, I just kept it in C/C++. If it already used FILE* in C, then it was easy to make that work under windows. (However I never did any COM port stuff). I didn't understand from your post why you also want it in C# ?

kingcrimbud
Mar 1, 2007
Oh, Great. Now what?

Sedro posted:

A beautiful example

These lines are a lot simpler than I thought they would be:

code:

            {
                var result = getNext()(input, getNext);
                return result.ReturnValue as Task<Response>;
            });
            return input.CreateMethodReturn(task);

Now sure why I expected a complicated solution, this looks perfect. Thank you!

wwb
Aug 17, 2004

Ran headlong into a windows thing that someone here might have ran into -- it seems that Visual Studio 2013 installed HyperV with Update 2 because of windows phone. Unfortunately hyperv breaks networking on VirtualBox and I need that function a lot more than I need to be able to emulate windows phone. Anyhow, I didn't figure this out until after I tried to upgrade virtualbox and ended up with a bunch of screweyness in the network stack somewhereas I can't seem to uninstall or reinstall it. Moreover, I can't remove hyperv at all -- I can uncheck the box, it runs the uninstall, reboots and then hangs at about 36% before rolling back my changes. I've looked in a few of the obvious places but I haven't found any rhyme or reason to this, is there some other tree I should bark up? Or has anyone run into this at all -- everything from google seems to be about people having problems installing hyperv not removing it.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

wwb posted:

Ran headlong into a windows thing that someone here might have ran into -- it seems that Visual Studio 2013 installed HyperV with Update 2 because of windows phone. Unfortunately hyperv breaks networking on VirtualBox and I need that function a lot more than I need to be able to emulate windows phone. Anyhow, I didn't figure this out until after I tried to upgrade virtualbox and ended up with a bunch of screweyness in the network stack somewhereas I can't seem to uninstall or reinstall it. Moreover, I can't remove hyperv at all -- I can uncheck the box, it runs the uninstall, reboots and then hangs at about 36% before rolling back my changes. I've looked in a few of the obvious places but I haven't found any rhyme or reason to this, is there some other tree I should bark up? Or has anyone run into this at all -- everything from google seems to be about people having problems installing hyperv not removing it.

Can you uninstall virtualbox entirely?

wwb
Aug 17, 2004

I failed to mention but yes, I did uninstall virtualbox to eliminate that variable. Though I didn't do more than the uninstall so that might be a good tree to bark up.

For content: VSO is offline right now: http://blogs.msdn.com/b/vsoservice/archive/2014/07/18/vso-services-are-unavailable-7-18-investigating.aspx; wonder how much the shops that are using TFS in the cloud are doing . . .

wwb fucked around with this message at 16:23 on Jul 18, 2014

Dr. Poz
Sep 8, 2003

Dr. Poz just diagnosed you with a serious case of being a pussy. Now get back out there and hit them till you can't remember your kid's name.

Pillbug

wwb posted:

Ran headlong into a windows thing that someone here might have ran into -- it seems that Visual Studio 2013 installed HyperV with Update 2 because of windows phone. Unfortunately hyperv breaks networking on VirtualBox and I need that function a lot more than I need to be able to emulate windows phone. Anyhow, I didn't figure this out until after I tried to upgrade virtualbox and ended up with a bunch of screweyness in the network stack somewhereas I can't seem to uninstall or reinstall it. Moreover, I can't remove hyperv at all -- I can uncheck the box, it runs the uninstall, reboots and then hangs at about 36% before rolling back my changes. I've looked in a few of the obvious places but I haven't found any rhyme or reason to this, is there some other tree I should bark up? Or has anyone run into this at all -- everything from google seems to be about people having problems installing hyperv not removing it.

I've run into this before as well but I was able to resolve it by turning off Hyper-V in the Add/Remove Windows Features section of Programs. You're saying that when you do that it goes through the motions of uninstalling it but then hangs and rolls back?

Fuck them
Jan 21, 2011

and their bullshit
:yotj:
Is there any rule of thumb as far as MessageBox.show vs actually throwing up some markup and code-behind if you're doing something in WPF? I'm displaying what amounts to a list of "YO these numbers are invalid or were entered wrong" and would rather avoid mucking with markup whenever possible.

OTOH if it's now idiomatic to do something else besides a modal popup I might as well get busy.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

gently caress them posted:

Is there any rule of thumb as far as MessageBox.show vs actually throwing up some markup and code-behind if you're doing something in WPF? I'm displaying what amounts to a list of "YO these numbers are invalid or were entered wrong" and would rather avoid mucking with markup whenever possible.

OTOH if it's now idiomatic to do something else besides a modal popup I might as well get busy.

It's your call, really. If you need styling and flexibility, use a WPF control. If you don't, use a regular old messagebox.

One thing to keep in mind: Displaying messageboxes (either framework-provided or custom) is not a viewmodel concern. I usually tackle it by raising an event in my viewmodel, then having the view handle displaying it. The reason is, as always, separation of concerns. If you want to test your viewmodel, you'll can't test it if it's popping up new views or messageboxes. If you raise an event, you can hook something up to the event to simulate results.

crashdome
Jun 28, 2011
How about a validation error on the control instead of a modal? Are you just validating data entry?

Adbot
ADBOT LOVES YOU

Mr. Crow
May 22, 2008

Snap City mayor for life

gently caress them posted:

Is there any rule of thumb as far as MessageBox.show vs actually throwing up some markup and code-behind if you're doing something in WPF? I'm displaying what amounts to a list of "YO these numbers are invalid or were entered wrong" and would rather avoid mucking with markup whenever possible.

OTOH if it's now idiomatic to do something else besides a modal popup I might as well get busy.

I'm not really following you're question, but as your application evolves and becomes more complex you'll find you probably want/need to roll your own dialog window, which is pretty simple (is this your question??).

The MVVM approach to showing dialogs is to use some sort of IDialogService, MVVM-light has a good system as do the other MVVM frameworks, http://msdn.microsoft.com/en-us/magazine/jj694937.aspx.

You may also want to look at the built-in validation framework, for showing validation errors.

Otherwise... I'm an idiot and you'll need to expand on your question more.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply