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
TheSleeper
Feb 20, 2003

Uziel posted:

I'm finally getting around to working on my project that uses MVC and MVVM for WPF with some shared code. I had previously asked about how to separate the project logically and am going for something like:
Project.Web.View
Project.Web.Controllers
Project.Client.View
Project.Client.ViewModels
Project.Model
Project.Data
Project.Tests.Unit

I have this mostly set up. I made the Controllers project a class library, but when I moved my controllers to this project, I lose the ability to scaffold views from a controller via right click. Did I setup the project wrong or is there another way to maintain this functionality?

Additionally, since I'm also new to Entity Framework, I wasn't sure which code went into Data vs Model in the above project structure. Would models only hold the basic model classes that inherit DbContexts and then the Data project house interfaces and classes with virtual properties that represent the data from the model? Getting slightly confused on this part. Is this unnecessary separation or call all of that go in Models and I don't need a separate Data project?

Screenshot of how I have it so far:


I haven't used Entity Framework, but from a quick glance I think you have that exactly backwards. It seems to me that everything that inherits from DbContexts should go in your Data project along with any interfaces and your Model project holds the thinner objects - just whatever you need for a given View.

There is always the chance I'm entirely wrong here since I've only worked one place that used MVC and not for very long.

Adbot
ADBOT LOVES YOU

Funking Giblet
Jun 28, 2004

Jiglightful!
Start with one project and split when you need to, you probably don't need to with a handful of classes per project. If you need to share some components, extract them into a project. I'd rather group library stuff by folder rather than project these days.

adaz
Mar 7, 2009

TheSleeper posted:

I haven't used Entity Framework, but from a quick glance I think you have that exactly backwards. It seems to me that everything that inherits from DbContexts should go in your Data project along with any interfaces and your Model project holds the thinner objects - just whatever you need for a given View.

There is always the chance I'm entirely wrong here since I've only worked one place that used MVC and not for very long.

This is how I've always done it when working with MVC, not that I'm doing it the right way though! All the DBContext access is hidden behind interfaces and the models don't have any references to them. I think in most of the starting MVC documentation it's defined as the repository pattern.

I, like Uziel, have always been slightly confused on Entity Framework generated models versus what I'm displaying in my views. Part of that is because most of my MVC projects are hitting DBs not specifically designed for whatever website so I tend to aggregate or leave off properties that are defined in the actual SQL tables and the autogenerated Entity classes.

I'm sure there is a way to generate the exact classes I need from EF I've just never sat down to figure it out, or if it'd even help that much. I mean the same table could be hit 5 different times for various models with subtly different properties on them, seems like an awful lot of work to custom define those in EF instead of just defining them in my project and using the autogenerated EF stuff to select the properties I want and then return my own models.

adaz fucked around with this message at 22:53 on Nov 24, 2012

omeg
Sep 3, 2012

Question about project structure.

I'm developing a set of applications that use 3rd party API assemblies to interface with an external application's (App) server. Those assemblies encapsulate web service calls and provide a set of classes that is essentially representation of App's object model (it's a large tree hierarchy). I need to support different versions of App and they come with different sets of API libraries.

I have my own shared library that acts as a mediator between my core code and the App's API libraries. Not everything is abstracted though, my core code often directly works with App's object model and thus needs to reference App's libraries. My core code is mostly the same regardless of App's version, but there are some variations here and there.

Question is, how to reference different versions of App's libraries in a sane way? Is it possible to have different version references in the same project (in separate build configurations for example)?

E: found this on SO: http://stackoverflow.com/questions/2923210/c-sharp-conditional-compilation-and-framework-targets
I'll tinker with the project file and see what I can come up with.

omeg fucked around with this message at 12:02 on Nov 26, 2012

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

omeg posted:

Question about project structure.

I'm developing a set of applications that use 3rd party API assemblies to interface with an external application's (App) server. Those assemblies encapsulate web service calls and provide a set of classes that is essentially representation of App's object model (it's a large tree hierarchy). I need to support different versions of App and they come with different sets of API libraries.

I have my own shared library that acts as a mediator between my core code and the App's API libraries. Not everything is abstracted though, my core code often directly works with App's object model and thus needs to reference App's libraries. My core code is mostly the same regardless of App's version, but there are some variations here and there.

Question is, how to reference different versions of App's libraries in a sane way? Is it possible to have different version references in the same project (in separate build configurations for example)?

I've hit a scenario similar to this with an application that integrated with Team Foundation Server 2010 and 2012. We ended up using linked files and MEF to load the appropriate assembly version at runtime.

For example,
Application
Application.TeamFoundation.2010
Application.TeamFoundation.2012

Application.TeamFoundation.2010 had all of the necessary abstract base classes, and those exact same code files were linked into the .2012 project to avoid code duplication. The base classes were subclassed in each project and the appropriate virtual/abstract methods were overridden as appropriate, and the subclasses used MetaDataAttributes to export their supported version to MEF. We then had some code that dug into the GAC to figure out what the highest installed version of the TFS object model was on that box and pulled the appropriate MEF-discovered version and passed it around via IoC.

omeg
Sep 3, 2012

I solved it by creating separate configurations for different versions (TC8/TC9) and editing project fies as follows:
code:
  <ItemGroup>
    <Reference Include="log4net">
      <HintPath>..\lib\log4net.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Core" />
  </ItemGroup>

  <ItemGroup Condition=" '$(Configuration)' == 'TC8 Debug' Or '$(Configuration)' == 'TC8 Release' ">
    <Reference Include="TcSoaClient">
      <HintPath>..\lib\TC8\TcSoaClient.dll</HintPath>
    </Reference>
    <Reference Include="TcSoaCoreStrong">
      <HintPath>..\lib\TC8\TcSoaCoreStrong.dll</HintPath>
    </Reference>
    <Reference Include="TcSoaStrongModel">
      <HintPath>..\lib\TC8\TcSoaStrongModel.dll</HintPath>
    </Reference>
  </ItemGroup>

  <ItemGroup Condition=" '$(Configuration)' == 'TC9 Debug' Or '$(Configuration)' == 'TC9 Release' ">
    <Reference Include="TcSoaClient">
      <HintPath>..\lib\TC9\TcSoaClient.dll</HintPath>
    </Reference>
    <Reference Include="TcSoaCoreStrong">
      <HintPath>..\lib\TC9\TcSoaCoreStrong.dll</HintPath>
    </Reference>
    <Reference Include="TcSoaStrongModel">
      <HintPath>..\lib\TC9\TcSoaStrongModel.dll</HintPath>
    </Reference>
  </ItemGroup>
There is one common reference section that contains stuff included by both versions. Then there are two mutually exclusive blocks that include specific versions depending on current configuration. It seems to work fine.

sephiroth838
Aug 24, 2012

adaz posted:

This is how I've always done it when working with MVC, not that I'm doing it the right way though! All the DBContext access is hidden behind interfaces and the models don't have any references to them. I think in most of the starting MVC documentation it's defined as the repository pattern.

I, like Uziel, have always been slightly confused on Entity Framework generated models versus what I'm displaying in my views. Part of that is because most of my MVC projects are hitting DBs not specifically designed for whatever website so I tend to aggregate or leave off properties that are defined in the actual SQL tables and the autogenerated Entity classes.

I'm sure there is a way to generate the exact classes I need from EF I've just never sat down to figure it out, or if it'd even help that much. I mean the same table could be hit 5 different times for various models with subtly different properties on them, seems like an awful lot of work to custom define those in EF instead of just defining them in my project and using the autogenerated EF stuff to select the properties I want and then return my own models.

You have to be careful if you hide the DBContext or EF model stuff behind another object or interface. The EF and DBContext can get rather cumbersome when a lot of queries are executed against the same DBContext object, because it will take the results of the queries and build its own relationships in the object. If lots of relationships are queried then its performance starts to drop off fast.

Hiding DBContext objects behind other objects or interfaces can fool a user of those interfaces into not realizing the performance implications. Of course this depends on how those wrapper objects are using the DBContext. If it builds a new DBContext for each query, then its a moot point anyways.

I prefer to use the DBContext as my model object directly and not do any wrapping at all, just pass the results of a DBContext query to whatever view needs to display. The resulting object should only contain what you need for the view anyways.

Sorry if I misunderstood the question/issue. I read up a ways, but didn't know where this one originated.

The Gripper
Sep 14, 2004
i am winner
Crosspostin' this from the Games thread because you guys use a lot of Visual Studio:

With the shader editor and a ton of .fbx and modeling capabilities in VS2012, I'm using it a lot more for fleshing ideas out but the toolbox (on the left in the picture below) sucks huge rear end to actually add new items to. To add a Material to it, I have to load an existing material onto the model, hit properties and browse to the path of my own material (even if it's in my project already, as Shader1.dgsl in the screencap).



Is there actually a way to add poo poo to that box without doing it this roundabout way (albeit, it only takes a few seconds in the browse dialog...). I feel like there should be an option to just drag compatible items into it, but that's not possible and "Choose Items" only deals with .exe and .dll importables. Hitting reset toolbox makes reference to custom toolbox items so I'm positive I'm just missing the button/menu item. I haven't needed to add custom items to the toolbox ever before, and MSDN isn't helping.

Also these new features are pretty fuckin' great.

Edit; ugh apparently adding it to the toolbox my roundabout way only works for the current session. If I restart VS the item stays in the toolbox, but stops reflecting changes to the shader (hitting Advanced in properties still brings up the correct, modified shader, though it's never applied to the model). I guess any quick way to apply a DGSL shader to an object would work fine, if that's possible.
Edit2; changing the graphics rendering engine fixes the shader, so I might file this as a bug though I'd still like to know how to either add materials to the toolbar, or apply a material to a model without it being in the toolbar.

The Gripper fucked around with this message at 17:04 on Nov 27, 2012

User0015
Nov 24, 2007

Please don't talk about your sexuality unless it serves the ~narrative~!

Sedro posted:

I made you a quick example here.

Been busy for Thanksgiving, but I wanted to give you a big thanks Sedro. I took your example and gave myself a couple homework assignments over Thanksgiving break: Add a ListView with multiple databound columns, and the ability to add my own with a button. Results: 100% Success :thumbsup:

Like all good homework though, I have a couple questions. Mainly, it's how binding, xaml and C# all work together. For example:

Question 1

code:
d:DataContext="{d:DesignInstance VideoExample:VideoLibraryViewModel, IsDesignTimeCreatable=False}" 
And in the code behind:

code:
DataContext = new VideoLibraryViewModel(); 
Reading an article on codeproject, they have an example with a student class and the property StudentName. In the code behind, they set this.DataContext = objstudent, an instance of the Student class. This lets them access StudentName using Binding Path="StudentName". In your example, you use DataContext twice. Once in the XAML and once in the codebehind, and your DataContext in the code behind isn't set to an instance (as far as I know) like it is in their example. Between these two lines, what's going on exactly?


Question 2

This line
code:
ItemsSource="{Binding Videos, Mode=OneWay}" 
From looking, I found this quote, "When you set the value of ItemsSource (either through DataBinding or by code), the control will generate the templated items internally." Problem is, I have no idea what they mean by 'generate the templated items internally.' I also noticed a lot of questions regarding the difference of ItemsSource vs DataContext. What's going on here compared to DataContext?

Question 3

These lines
code:
SelectedItem="{Binding SelectedVideo, Mode=TwoWay}"
...
Text="{Binding SelectedVideo.Filename
So in this little class, there's this thing called SelectedVideo that either returns an ObservableCollection<OurObjectType> or when it gets set (and it differs from the current one), it fires FirePropertyChanged, which calls up a PropertyChangedEventHandler event. So SelectedItem is a property of your ListBox, and you bound it to the property SelectedVideo, and it automatically knows/expects an ObservableCollection<of some type?> back or passed to? And it knows about SelectedVideo because of our DataContext/ItemsSource?

Question 4
code:
<ListBox.ItemTemplate>
                <!--
                    The item template decides how to display an item in the list.
                    If not used, WPF will call VideoViewModel.ToString()
                -->
                <DataTemplate DataType="{x:Type VideoExample:VideoViewModel}">
<TextBlock Text="{Binding ID, Mode=OneWay}"/>
So I get what the point of this is. If I take it out, it does exactly what I had happen at my first attempt at databinding: Some goofy ToString() conversion that is useless. So the binding part makes sense. But what's going on with the DataTemplate Datatype. . . stuff.

Che Delilas
Nov 23, 2009
FREE TIBET WEED

User0015 posted:

:words: about data binding.

I think I can help answer these.

Question 1:

He's not actually setting the DataContext twice here. What he's doing in the XAML is specifying d:DataContext. The key here is the "d," which is generally used to indicate design time (it's actually a namespace definition at the top of the XAML, specified as xmlns:d). Setting your design-time data context is mostly used to give Visual Studio Designer or Expression Blend a data context to work with that might be different from your live data context (because you don't want visual studio's designer tool to try and connect to a web service or something).

It's useful for providing dummy data to use so you can format the visual look of your controls. In this case, he's also specifying IsDesignTimeCreatable="False" which will make a dummy object for the designer to use as the data context, without giving you any sample data. To keep it clean, basically.

Bottom line: He's only specifying the actual (live) DataContext in the code behind. The d:DataContext is ignored when you actually run the program.

Question 2:

"Generate the templated items internally" means that program will do its level best to display the "items" in the list that it gets from its ItemsSource. What this usually means is that it's going to call each item's ToString() method and display the result as plain text in the control. Obviously with any kind of complex object this isn't going to be good enough, which is why we provide the control with a Template.

The other part of your question is easier: the difference between ItemsSource and DataContext.

Think of the DataContext as the starting point for all your bindings. Make it a class (this is usually the ViewModel in the MVVM pattern). A control's ItemsSource is, in contrast, a collection of data (often complex objects) that exists within the class you specified as the DataContext.

So for example, the DataContext in this case is an instance of VideoLibraryViewModel, while the ItemsSource in the ListBox is a collection of Videos. The VideoLibraryViewModel has, as one of its properties, an IList<VideoViewModel> called "Videos". Videos is what the ItemsSource property binds to, and it knows where Videos is because you specified the DataContext, or starting point, as an instance of VideoLibraryViewModel, which again, has Videos as one of its properties.

Question 3:

quote:

So SelectedItem is a property of your ListBox, and you bound it to the property SelectedVideo, and it automatically knows/expects an ObservableCollection<of some type?>

SelectedItem is a property of the ListBox, and it is bound to the property SelectedVideo. SelectedItem doesn't expect a collection, it expects a single object (in this case a VideoViewModel). It knows what type the object is because the ListBox's ItemsSource is an IList<VideoViewModel>, so each item must be a single VideoViewModel.

Basically what's happening here is that each time you select a different item from the list, the SelectedVideo property in your VideoLibraryViewModel gets updated because it is bound to the ListBox's SelectedItem property.

Question 4
The DataType property of the DataTemplate element just tells it, "This is how we are going to display any data of this type." In this case, it's specifying how to display VideoViewModel objects. It should be noted that the DataType property as its used here isn't strictly necessary since the DataTemplate is being specified within the specific ListBox and we're not displaying VideoViewModels anywhere else in the window, only in that ListBox.

Realize that DataTemplates are the blueprints for how you want to display a given object. You can make them as simple as a few TextBlocks or you can do all sorts of crazy formatting, spacing, colorization, anything you want. Think of them as a kind of miniature UserControl. In this example he only has one TextBlock and it's displaying the ID of the SelectedVideo, and nothing else about the SelectedVideo. In a more real-world application it would display the Name and Status as well, by including in the template two more TextBlocks bound to the respective properties.

Che Delilas fucked around with this message at 00:17 on Nov 28, 2012

adaz
Mar 7, 2009

sephiroth838 posted:

You have to be careful if you hide the DBContext or EF model stuff behind another object or interface. The EF and DBContext can get rather cumbersome when a lot of queries are executed against the same DBContext object, because it will take the results of the queries and build its own relationships in the object. If lots of relationships are queried then its performance starts to drop off fast.

Hiding DBContext objects behind other objects or interfaces can fool a user of those interfaces into not realizing the performance implications. Of course this depends on how those wrapper objects are using the DBContext. If it builds a new DBContext for each query, then its a moot point anyways.

I prefer to use the DBContext as my model object directly and not do any wrapping at all, just pass the results of a DBContext query to whatever view needs to display. The resulting object should only contain what you need for the view anyways.

Sorry if I misunderstood the question/issue. I read up a ways, but didn't know where this one originated.

That is actually a good point and one I hadn't considered because I tend to almost universally use DB context for single queries. Still, if I ever need to change the pattern it is a good thing to keep in mind.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
VS2012 Update 1 is out!

http://www.microsoft.com/visualstudio/eng/downloads#d-visual-studio-2012-update

The Gripper
Sep 14, 2004
i am winner
Are there updates other than the ones listed on the update overview page, because they're all pretty bad (or not useful to me). I was hoping the VC++ November CTP would be included but it doesn't seem like it (variadic templates, etc.)

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

The Gripper posted:

Are there updates other than the ones listed on the update overview page, because they're all pretty bad (or not useful to me). I was hoping the VC++ November CTP would be included but it doesn't seem like it (variadic templates, etc.)

The unit testing stuff is pretty useful.

I have no idea if it includes anything beyond the overview.

adaz
Mar 7, 2009

The Gripper posted:

Are there updates other than the ones listed on the update overview page, because they're all pretty bad (or not useful to me). I was hoping the VC++ November CTP would be included but it doesn't seem like it (variadic templates, etc.)

http://blogs.msdn.com/b/somasegar/archive/2012/11/26/visual-studio-2012-update-1-now-available.aspx

Good overview.

Also TFS update 1 is out but make sure you :siren: read the notes :siren: it is likely you will have to reset some poo poo once you apply the update

Sab669
Sep 24, 2009

How exactly does a KeyDown event work? I've got a "Quick Find" text box with a KeyDown event so that each time they press something, it tries to seek an object to a record with that unique column. So say I want to seek to a record "TEST". After I type the last T, I have to hit Tab or Enter for it to seek the object. Does a KeyDown get fired before it registers the actual button?

Tried it with a TextChanged event instead, which works.. but then it truncates the textbox to "TES" afterwards :confused:

Sab669 fucked around with this message at 16:17 on Nov 28, 2012

sephiroth838
Aug 24, 2012

Sab669 posted:

How exactly does a KeyDown event work? I've got a "Quick Find" text box with a KeyDown event so that each time they press something, it tries to seek an object to a record with that unique column. So say I want to seek to a record "TEST". After I type the last T, I have to hit Tab or Enter for it to seek the object. Does a KeyDown get fired before it registers the actual button?

Tried it with a TextChanged event instead, which works.. but then it truncates the textbox to "TES" afterwards :confused:

I'm not sure if it matters in your situation, but I tend to use keyup events more than keydown. If the user holds down the button, then keydown will trigger each time the letter repeats. If you are doing object searches on keydown and they hold down the key, it could cause some performance issues depending on how complicated the search is.

I don't think you should have to tab or hit enter for the keydown event to trigger, I'm guessing something else is going on there. The event should trigger as soon as the button is pressed. Is this ASP.NET or WinForms?

If its ASP.NET I would use something like jQuery or pure javascript to hook onto the textbox keyup event, then make an async ajax call to do your search and get results. In the complete handler for the ajax call put the search result in a popup list box that they can select from. Each new letter they type makes a new async ajax call which will clear the popup listbox and re-add new search results. If only one result is found, put it directly in the textbox they are typing in.

If its WinForms, then its pretty much the same thing, but without the async ajax call obviously.

*Edit* I'm pretty sure somewhere there is a control or library that can do this kind of thing for you, but making your own shouldn't be too tricky either.

diadem
Sep 20, 2003
eet bugz
I am dealing with a set of old brownfield code that uses SqlMembershipProvider (machinekey/appname combos), saving user data in Aspnet_Users.

I need to make a new project that implements modern functionality such as sending newly registered users a validation token over e-mail. While this is easy to do with Webmatrix, underneath the hood this relies on a different set of database tables, so it won't work with any of the existing projects.

Upgrading the existing projects is an extensive task that I do not currently have the resources for.

How do I get the functionality of modern membership providers without screwing up the database for all other projects?

User0015
Nov 24, 2007

Please don't talk about your sexuality unless it serves the ~narrative~!

Che Delilas posted:

Question 1: DataContext

As far as the example I saw goes, what's going on between setting the DataContext to an instance of a class, and to the class itself?

Thanks for the answers. I'm feeling a little more confident about what I want to do now.

Che Delilas
Nov 23, 2009
FREE TIBET WEED

User0015 posted:

As far as the example I saw goes, what's going on between setting the DataContext to an instance of a class, and to the class itself?

There's no setting the DataContext to "the class itself." You're always setting it to an instance of the class. If you do it in the code behind,
code:
this.DataContext = new VideoLibraryViewModel();
That's setting it to an instance of the class (a 'new' instance).

If you do it in the XAML (I'm assuming you're referring to this line from the example) :
code:
d:DataContext="{d:DesignInstance VideoExample:VideoLibraryViewModel, IsDesignTimeCreatable=False}"
it's still setting the DataContext to an instance of the VideoLibraryViewModel. Behind the scenes, it's pretty much doing exactly what the first set of code is doing: setting DataContext to a 'new' VideoLibraryViewModel using its default constructor (but do remember it's the design-time DataContext in this example).

It's just two different ways of doing the exact same thing.

Sedro
Dec 31, 2008
"d:DataContext" is a custom attached property that WPF doesn't even know about. It's defined in some Expression Blend namespace. It's not related to the FrameworkElement.DataContext DependencyProperty which controls the "root" of your binding.

I don't actually use UI designers; the design-time data context enables Resharper's XAML intellisense.

By the way, WiX 3.6 is out, including the burn bootstrapper which allows you to create a WPF UI for your installer.

Sedro fucked around with this message at 23:07 on Nov 28, 2012

Che Delilas
Nov 23, 2009
FREE TIBET WEED

Sedro posted:

I don't actually use UI designers; the design-time data context enables Resharper's XAML intellisense.

Does this mean that Resharper's XAML intellisense works on markup extensions? We don't use Resharper where I work but if it has intellisense where Visual Studio does not I might just make a push to have it purchased. I hate the lack of complete intellisense more than just about anything when it comes to WPF.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Che Delilas posted:

Does this mean that Resharper's XAML intellisense works on markup extensions? We don't use Resharper where I work but if it has intellisense where Visual Studio does not I might just make a push to have it purchased. I hate the lack of complete intellisense more than just about anything when it comes to WPF.

http://www.jetbrains.com/resharper/features/xaml_editor.html#Extended_XAML_IntelliSense

fankey
Aug 31, 2001

When using the XmlSerializer to serialize a List of objects, how to I go about renaming the element used for each instance in my List. For example, the following code
code:
using System;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace XmlTest
{
  public class Foo
  {
    public string Name { get; set; }
  }

  [System.Xml.Serialization.XmlRoot("Bars")]
  public class Foos : List<Foo>
  {
  }

  class Program
  {
    static void Main(string[] args)
    {
      XmlSerializer xml = new XmlSerializer(typeof(Foos));
      Foos foos = new Foos();
      foos.Add(new Foo() { Name = "you" });
      System.IO.StringWriter sw = new System.IO.StringWriter();
      xml.Serialize(sw, foos);
      Console.WriteLine(sw);
      Console.ReadKey();
    }
  }
}
outputs
code:
<?xml version="1.0" encoding="utf-16"?>
<Bars xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Foo>
    <Name>you</Name>
  </Foo>
</Bars>
I'd like to have it output
code:
<?xml version="1.0" encoding="utf-16"?>
<Bars xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Bar>
    <Name>you</Name>
  </Bar>
</Bars>
I can change the c# objects but the names used in the XML are already used for other classes in my code.

wwb
Aug 17, 2004

diadem posted:

I am dealing with a set of old brownfield code that uses SqlMembershipProvider (machinekey/appname combos), saving user data in Aspnet_Users.

I need to make a new project that implements modern functionality such as sending newly registered users a validation token over e-mail. While this is easy to do with Webmatrix, underneath the hood this relies on a different set of database tables, so it won't work with any of the existing projects.

Upgrading the existing projects is an extensive task that I do not currently have the resources for.

How do I get the functionality of modern membership providers without screwing up the database for all other projects?

This is doable, though you'll probably have to roll some of your own poo poo to make it go.

The old-school membership providers have an option to require approval, this is the underlying functionality you can leverage. From there it is pretty trivial to generate a token, stash it and use it as a key to approve an account.

Another angle on the underlying functionality is to require some group membership -- ie ApprovedUsers -- to get into things. This might work out better ui-wise as the unapproved membership stuff can get confusing unless you handle people who can't authenticate properly.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

fankey posted:

When using the XmlSerializer to serialize a List of objects, how to I go about renaming the element used for each instance in my List. For example, the following code

I can change the c# objects but the names used in the XML are already used for other classes in my code.

Try this:
code:
    [XmlTypeAttribute(AnonymousType = true)]
    public class Foo
    {
        public string Name { get; set; }
    }
    [XmlTypeAttribute(AnonymousType = true)]
    public class Bars 
    {
        [XmlElement("Bar")]
        public List<Foo> FooList { get; set; }

        public Bars()
        {
            FooList = new List<Foo>();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var xml = new XmlSerializer(typeof(Bars));
            var foos = new Bars();
            foos.FooList.Add(new Foo { Name = "you" } );
            using (var sw = new StringWriter())
            {
                xml.Serialize(sw, foos);
                Console.WriteLine(sw);
            }
            Console.ReadKey();
        }
    }
Honestly, I just ran it through xsd.exe and cleaned up the output a little.

New Yorp New Yorp fucked around with this message at 01:03 on Nov 29, 2012

fankey
Aug 31, 2001

Thanks, that works. The odd thing is if FooList doesn't have the XmlElement attribute it will generate
code:
<?xml version="1.0" encoding="utf-16"?>
<Bars xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <FooList>
    <Foo>
      <Name>you</Name>
    </Foo>
  </FooList>
</Bars>
With the XmlElement it generates
code:
<?xml version="1.0" encoding="utf-16"?>
<Bars xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Bar>
    <Name>you</Name>
  </Bar>
</Bars>
Not only does the XmlElement rename the element it removes the wrapping FooList element as well.

Edit : Which is exactly what MSDN says, if anyone cares...

quote:

If you apply the XmlElementAttribute to a field or property that returns an array, the items in the array are encoded as a sequence of XML elements.

In contrast if an XmlElementAttribute is not applied to such a field or property, the items in the array are encoded as a sequence of elements, nested under an element named after the field or property. (Use the XmlArrayAttribute and XmlArrayItemAttribute attributes to control how an array is serialized.)

fankey fucked around with this message at 01:21 on Nov 29, 2012

Sedro
Dec 31, 2008

Che Delilas posted:

Does this mean that Resharper's XAML intellisense works on markup extensions? We don't use Resharper where I work but if it has intellisense where Visual Studio does not I might just make a push to have it purchased. I hate the lack of complete intellisense more than just about anything when it comes to WPF.
It works for the binding markup extension. You can type Text="{Binding Path= and prompt it for properties on the type (taken from DataTemplate.DataType if you're in a DataTemplate, or the design data context, etc).

It won't work for custom MarkupExtensions (a markup extension can do anything). You could probably write a Resharper plugin or something.

If you don't use Resharper at work then I'm assuming nobody has used it before. Anyone who uses it won't be able to live without it. Once you start using the camel-case auto-completion and type importing, you won't be able to go back.

Crazy Mike
Sep 16, 2005

Now with 25% more kimchee.
My screw up at work today...

I wrote a program that sends a couple SQL queries on a timer. The first query calculates a number, the second query updates a table row with a message about what the number is and when it was calculated. I use a Timer that ticks every second to show a clock on the form, and decides whether to run the query based off DateTimePicker and ComboBox values. When I switched to the production server, the times did not match. I was using DateTime.Now to determine when to run the queries and select GETDATE()to determine when the calculation was performed. The two clocks were off by a minute. My boss would prefer basing time off the server instead of DateTime.Now.

So lets think of possible solutions...
1.) I know the clock is off by a minute so I will offset the program to run a minute later to compensate. This really doesn't solve anything though...

2.) I can just change the SQL string for the second query to have the time variable from the local machine instead of the server. This goes against the preference that we use the server time instead of the local machine time.

3.) My timer will query select GETDATE() at every tick to ensure that the time is synchronized. This results in a lot of unnecessary queries run, something I'm pretty sure we should avoid.

4.) We run the program off the server instead of the local machine so that DateTime.Now and select GETDATE() are the same. Is this the right answer or is there a better way to solve this problem?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Crazy Mike posted:

My screw up at work today...

I wrote a program that sends a couple SQL queries on a timer. The first query calculates a number, the second query updates a table row with a message about what the number is and when it was calculated. I use a Timer that ticks every second to show a clock on the form, and decides whether to run the query based off DateTimePicker and ComboBox values. When I switched to the production server, the times did not match. I was using DateTime.Now to determine when to run the queries and select GETDATE()to determine when the calculation was performed. The two clocks were off by a minute. My boss would prefer basing time off the server instead of DateTime.Now.

So lets think of possible solutions...
1.) I know the clock is off by a minute so I will offset the program to run a minute later to compensate. This really doesn't solve anything though...

2.) I can just change the SQL string for the second query to have the time variable from the local machine instead of the server. This goes against the preference that we use the server time instead of the local machine time.

3.) My timer will query select GETDATE() at every tick to ensure that the time is synchronized. This results in a lot of unnecessary queries run, something I'm pretty sure we should avoid.

4.) We run the program off the server instead of the local machine so that DateTime.Now and select GETDATE() are the same. Is this the right answer or is there a better way to solve this problem?

If your application relies on the time being exactly the same between two environments, you're probably doing something wrong. What if your SQL server gets moved to a datacenter two time zones away?

1) is horrible and brittle.
2) Is hacky
3) Is horrible for the exact reason you said.
4) is probably horrible because you shouldn't need to rely on one particular environment for the correct operation of your application.

If all the application does is send some queries to the SQL server on a timer, the problem is that you're approaching the problem incorrectly. Make a stored procedure and use the SQL agent to run a job on a timer.

The Gripper
Sep 14, 2004
i am winner
Submitted a VS2012 bug earlier and got a response that I have 4 business days to supply a video of the bug in action. I've never been more tempted to put dicks all throughout a video just for the inconvenience of having to record a video on a deadline.

ljw1004
Jan 18, 2005

rum

The Gripper posted:

Submitted a VS2012 bug earlier and got a response that I have 4 business days to supply a video of the bug in action. I've never been more tempted to put dicks all throughout a video just for the inconvenience of having to record a video on a deadline.

Sorry about that. We've heard other complaints about our requests for videos. I wonder if you could send me the Connect ID / URL of your bug, and I'll follow up internally?


We in VS get a huge volume of Connect bugs. Many of them have historically been too vague for us to get anywhere with: by the time the devs have cleared their existing work backlog and got a chance to look at the bug, and found that they couldn't repro it, and written back to the original bug submitter for more information, that submitter had already moved onto other things.

So we made two changes to improve the "repro" rate on bugs. First, we wrote this extension.

http://visualstudiogallery.msdn.microsoft.com/f8a5aac8-0418-4f88-9d34-bdbe2c4cfe72

If you download it, and report bugs through it, then it gathers much more of the information we need to repro, and it completely bypasses the Tier 1 triage.


For bugs that are filed through Connect, they go through the folks in "Tier 1 triage". Their job is to make sure they can repro the bug. If they don't get enough information to repro the bug after a few days, then they close the bug as "inactive" -- but will reactivate the bug as soon as they get the information.. These two approaches have together given us a much higher repro rate, and much higher bug-fix rate, so overall we're happy with them. (Maybe we should promote the tool more?)

But sometimes I've found that Tier 1 Triage asks for video repros in inappropriate situations -- times when the developers themselves would have had enough knowledge of the code to make do without being such a burden on you the bug submitter. That's unfortunate but is the inevitable price of having triage. We just need to monitor how they're doing.

The Gripper
Sep 14, 2004
i am winner

ljw1004 posted:

Sorry about that. We've heard other complaints about our requests for videos. I wonder if you could send me the Connect ID / URL of your bug, and I'll follow up internally?
Haha fortunately I have some screen recording software on here anyway so it only took about 20 minutes to record, but I can imagine people just abandoning it if they had to do it. I don't think most people would even have a clue how to make a video of it and not have it be an unreasonably large size.

ljw1004 posted:

We in VS get a huge volume of Connect bugs. Many of them have historically been too vague for us to get anywhere with: by the time the devs have cleared their existing work backlog and got a chance to look at the bug, and found that they couldn't repro it, and written back to the original bug submitter for more information, that submitter had already moved onto other things.

So we made two changes to improve the "repro" rate on bugs. First, we wrote this extension.

http://visualstudiogallery.msdn.microsoft.com/f8a5aac8-0418-4f88-9d34-bdbe2c4cfe72

If you download it, and report bugs through it, then it gathers much more of the information we need to repro, and it completely bypasses the Tier 1 triage.
I saw that, but figured that since my issue wasn't a crash or anything serious/production-halting (just an inconsistency with how some of the new Graphics tools act between sessions) that it wouldn't be very useful. I'll install it and keep it around for next time though, thanks.

ljw1004 posted:

But sometimes I've found that Tier 1 Triage asks for video repros in inappropriate situations -- times when the developers themselves would have had enough knowledge of the code to make do without being such a burden on you the bug submitter. That's unfortunate but is the inevitable price of having triage. We just need to monitor how they're doing.
I figured it was an automatic canned response sent out after a certain number of hours, and all I could think was "ugh this is such an insignificant bug that I don't even know if a video is worth submitting".

It might be worth noting in the response that you can use Windows Media Encoder to create reasonably-sized screen recordings, because just googling for video recording software throws you literally into the deep end of internet crapware. The one legitimate program on the first page of results creates 2GB raw videos for every 90 seconds, for example.

Edit; This is the bug I submitted but don't bother chasing it up because it has almost no negative effect on me as a user, I just figured since I'd stumbled onto it it wouldn't hurt to let you guys know about it.

The Gripper fucked around with this message at 06:07 on Nov 29, 2012

akadajet
Sep 14, 2003

Che Delilas posted:

Does this mean that Resharper's XAML intellisense works on markup extensions? We don't use Resharper where I work but if it has intellisense where Visual Studio does not I might just make a push to have it purchased. I hate the lack of complete intellisense more than just about anything when it comes to WPF.

I wouldn't buy Resharper for the XAML intellisense. It's there for property members once you've got the correct design context set up, but the code completion is no where near as good as it is for C#.

That said, I would recommend Resharper for all of the C# refactoring/code navigation stuff. It really does save a lot of time.

Uziel
Jun 28, 2004

Ask me about losing 200lbs, and becoming the Viking God of W&W.
Regarding revision control and NuGet.
I created a new MVC4 project and commited it to a Visual SVN repository. Tortoise skipped over the packages directory. Someone else pulled the solution and they are missing a bunch of the references that were in the packages directory. The NuGet package manager shows no packages are installed, even though packages.config in the project root has them all listed. Is there any way to get NuGet to pick up on the missing packages folder and redownload them all, or should I instead be having the packages folder under revision control (I'd rather not)?

Edit: The answer was to right click on the solution and enable NuGet Package Restore.

Uziel fucked around with this message at 20:44 on Nov 29, 2012

Cryolite
Oct 2, 2006
sodium aluminum fluoride
If you're using VS2012 you can right-click on the solution and select "Enable NuGet Package Restore" to do this.

e: blast! Wasn't fast enough.

Uziel
Jun 28, 2004

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

Cryolite posted:

If you're using VS2012 you can right-click on the solution and select "Enable NuGet Package Restore" to do this.

e: blast! Wasn't fast enough.
This actually works in VS2010 also.

Hibame
Feb 20, 2008
Make sure under Tools > Options > Package Manager that you check "Allow NuGet to download missing packages during build". Enabling the option makes sharing package restorable projects cake as everything is downloaded when you try and do the first build.

wwb
Aug 17, 2004

Uziel posted:

Regarding revision control and NuGet.
I created a new MVC4 project and commited it to a Visual SVN repository. Tortoise skipped over the packages directory. Someone else pulled the solution and they are missing a bunch of the references that were in the packages directory. The NuGet package manager shows no packages are installed, even though packages.config in the project root has them all listed. Is there any way to get NuGet to pick up on the missing packages folder and redownload them all, or should I instead be having the packages folder under revision control (I'd rather not)?

Edit: The answer was to right click on the solution and enable NuGet Package Restore.

The right answer is to have that poo poo under revision control. Nothing beats trying to hunt down an ancient version of some library for some ancient app that needs to be emergency migrated because the crappy ancient server it lived on died and you are rebuilding from source. For the love of christ keep the binary deps with the source.

Adbot
ADBOT LOVES YOU

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
This includes stuff like the compiler you're using, by the way.

You should be able to check out your repository at any point and compile something bit-identical (with the exception of any embedded date stamps) to what you could build when you did that commit.

  • Locked thread