# Wednesday, April 21, 2010

When talking about the Model View ViewModel (MVVM) , Model View Controller (MVC) or any other presentation patterns Model some people refer to it as the Database Model, others as the Domain Model. Well, it is actually referred as a Presentation Data Model.

Your database or domain types could have many properties that the View does not care about and it will be a waste of resources as well as a security risk to have all that data traveling back and fourth the network even if it is an intranet.

Another problem with using Database or Domain data in your MVVM is that any change to the database or domain will require to update all the clients and that could be very costly.

Let's assume for example that we have the following very simple Domain Model:

SSLDomain

and the following Database Model:

image

Note: I created the Database Model using the following NHibernate mapping:

     
 
<?xml version="1.0" encoding="utf-8"?>
<!--Generated with CyberBizSoft's NHibernate Helper on 12/16/2009 11:30:06 PM -->
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="CyberBizSoft.SSL.Domain" 
namespace="CBSI.SSL.Domain">
    <class name="Store" table="SSLStores" lazy="false" >
        <id name="ID" unsaved-value="0" column="ID" type="System.Int64">
            <generator class="identity" />
        </id>
        <property name="Name"/>
        <property name="Description"/>
        <component name="Contact" class="CBSI.Common.Domain.SingleContact, 
CyberBizSoft.Domain" >
            <component name="Address" class="CBSI.Common.Domain.Address, CyberBizSoft.Domain">
                <property name="Street" column="Street" />
                <property name="City" column="City" />
                <property name="State" column="State" />
                <property name="ZipCodeNumber" column="ZipCodeNumber" />
                <property name="Country" column="Country" />
            </component>
            <component name="Phone" class="CBSI.Common.Domain.Phone, CyberBizSoft.Domain">
                <property name="FullNumber" column="PhoneNumber"/>
            </component>
            <component name="Fax" class="CBSI.Common.Domain.Phone, CyberBizSoft.Domain">
                <property name="FullNumber" column="FaxNumber"/>
            </component>
            <component name="EMail" class="CBSI.Common.Domain.Url, CyberBizSoft.Domain">
                <property name="URL" column="EMailAddress"/>
            </component>
            <component name="Web" class="CBSI.Common.Domain.Url, CyberBizSoft.Domain">
                <property name="URL" column="WebAddress"/>
            </component>
        </component>
    </class>
    <!--Copyright (c) 2001 - 2009 by CyberBizSoft, Inc. All rights reserved.-->
</hibernate-mapping
 
     

 

Let's say that we have to create an interface only to change the Name and Description of this Store. Why would we have to bring all the other information into the client if we only need the Store's ID, Name & maybe Description?

Preferably we could create a very simple presentation data model (StoreNameModel) which we could adorn with presentation specific attributes,

class StoreNameModel
{
    [Key]
    public long ID { get; set; }
    [Required]
    public string Name { get; set; }
    public string Description { get; set; }
}

map the data from the Domain Store in the service to the StoreNameModel

public IQueryable<StoreNameModel> Stores()
{
    return from c in Repository.All
           orderby (c.Name)
           select new StoreNameModel() { ID = c.ID, Name = c.Name, Description = c.Description };
}

and then project it into the ViewModel in the client.

Update (4/23/10)

I found this post by Deepesh Mohnani about the WCF RIA Presentation Model    

 

 
posted on Wednesday, April 21, 2010 6:43:46 PM UTC  #    Comments [0]
# Tuesday, April 20, 2010

If you create a Silverlight application using the WCF RIA Services Class library and with the following walkthrough when you try to access the Context for the RIA application (WebContext) it is not there.

Since we did not enabled the WCF RIA Services for the Silverlight application the WebContext class is not generated in the client.

  image

You can verify this by selecting the Silverlight application in the Solution Explorer, click the Show All Files button in the Solution Explorer toolbar and then inspecting the hidden "Generated_Code" folder.

The workaround is to right click on the Silverlight application in the Solution Explorer, select Properties and  temporarily enable the WCF RIA Services by selecting the web project in the WCF RIA Service link.

 image

Then rebuild the solution find and copy the WebContext class in the file [YourServerAssemblyName].g.cs in the afore mentioned folder to a new file WebContext.cs somewhere in the Silverlight application project.

Now right click on the Silverlight application in the Solution Explorer again and select <No Project Set> in the WCF RIA Service link and rebuild again. "Generated_Code" folder content will be removed.

This is kind of a hack and I believe it could be solved if the WCF RIA Services Class Library template will check if the WebContext exists in the Silverlight application and if not exist it will generate it.

Update (4/26/2010)

If you move the WebContext.cs file to the WCF RIA Services library client make sure to update your app.xaml with the following:

<app:WebContext>
            <app:WebContext.Authentication>
                <appsvc:FormsAuthentication
DomainContextType="[TheNamespaceOfYourRIALibrary].AuthenticationContext,
[TheNameOfYourRIAClassAssembly ], Version= [X].0.0.0"/>
                <!--<appsvc:WindowsAuthentication/>-->
            </app:WebContext.Authentication
   </app:WebContext
posted on Tuesday, April 20, 2010 6:56:54 PM UTC  #    Comments [0]
# Sunday, April 18, 2010

Digging through my old backups I found the following application that was one of the first I built using Visual Studio for a private investigation firm way back in 1997:

clip_image001[8]

 

It has been a long love-hate relationship with Visual Studio. Happy Birthday Visual Studio!

posted on Sunday, April 18, 2010 5:41:08 PM UTC  #    Comments [0]
# Saturday, April 17, 2010

I completed the upgrade to VS 2010 but with some warnings. Apparently nothing important.

image

[04/16/10,16:44:37] Microsoft Visual Studio 2010 Professional - ENU: [2] WARNING:Warning 1946.Property 'System.AppUserModel.ExcludeFromShowInNewInstall' for shortcut 'WinDiff.lnk' could not be set.

[04/16/10,16:44:37] Microsoft Visual Studio 2010 Professional - ENU: [2] WARNING:Warning 1946.Property 'System.AppUserModel.ExcludeFromShowInNewInstall' for shortcut 'OLE-COM Object Viewer.lnk' could not be set.

[04/16/10,16:44:38] Microsoft Visual Studio 2010 Professional - ENU: [2] WARNING:Warning 1946.Property 'System.AppUserModel.ExcludeFromShowInNewInstall' for shortcut 'Manifest Generation and Editing Tool.lnk' could not be set.

[04/16/10,16:44:38] Microsoft Visual Studio 2010 Professional - ENU: [2] WARNING:Warning 1946.Property 'System.AppUserModel.ExcludeFromShowInNewInstall' for shortcut 'Install Microsoft FXCop.lnk' could not be set.

***EndOfSession***

 

Here is my list: (I removed Visual Studio 2005 but not 2008)

image

UPDATE

Later today (4/17/2010) I noticed the following entries in the Application Event Log:

Error in Template (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\Web\VisualBasic\1033\AdoNetEntityDataModelVB_ASPNET.zip), file (ModelObjectItemVB_ASPNET.vstemplate). Invalid template element (TemplateID) value (Microsoft.Data.Entity.Design.VSTemplate.ModelObjectItemVB_ASPNET).

Error in Template (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\Web\CSharp\1033\AdoNetEntityDataModelCSharp_ASPNET.zip), file (ModelObjectItemCS_ASPNET.vstemplate). Invalid template element (TemplateID) value (Microsoft.Data.Entity.Design.VSTemplate.ModelObjectItemCS_ASPNET).

Error in Template (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\Web\VisualBasic\1033\AdoNetDataServiceVBWebsite.zip), file (WebDataService.vstemplate).  Unknown attribute (_locID).

Error in Template (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\Web\VisualBasic\1033\AdoNetDataServiceVBWebsite.zip), file (WebDataService.vstemplate).  Unknown attribute (_locID).

Error in Template (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\Web\CSharp\1033\AdoNetDataServiceCSharpWebsite.zip), file (WebDataService.vstemplate).  Unknown attribute (_locID).

Error in Template (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\Web\CSharp\1033\AdoNetDataServiceCSharpWebsite.zip), file (WebDataService.vstemplate).  Unknown attribute (_locID).

Error in Template (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\VisualBasic\Web\1033\AdoNetDataServiceVBWap.zip), file (WebDataService.vstemplate).  Unknown attribute (_locID).

Error in Template (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\VisualBasic\Web\1033\AdoNetDataServiceVBWap.zip), file (WebDataService.vstemplate).  Unknown attribute (_locID).

Error in Template (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Web\1033\AdoNetDataServiceCSharpWap.zip), file (WebDataService.vstemplate).  Unknown attribute (_locID).

Error in Template (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Web\1033\AdoNetDataServiceCSharpWap.zip), file (WebDataService.vstemplate).  Unknown attribute (_locID).

 

Although all these Item Templates where present, I ran "DevEnv.exe /installvstemplates" from an Administrator Visual Studio Command Prompt (2010) just in case.

posted on Saturday, April 17, 2010 4:23:50 AM UTC  #    Comments [0]
# Tuesday, February 16, 2010

 

For professional health providers who need to concentrate on providing the best solution to patient's health problems, the Medical Facility Manager is a health information management system that provides a single point of access to the practice information to providers, patients and vendors. The system will store all internal and external transactions within the facility by keeping record of every interaction between patients and providers including accounting. The system will save facilities 40 percent of clerical costs in the first year of use by allowing patients to self-register, schedule appointments and retrieving tests results online. Furthermore it will allow facilities to save on accounting costs since it implements claims, billing, payroll and general accounting tasks by using The Accounting Engine. Unlike the current antiquated systems with poor security record and insecure slow manual systems, Medical Facility Manager implements state of the art security and backup sub-systems and will comply with federal and state government security and reporting requirements.

clip_image002

posted on Tuesday, February 16, 2010 4:54:55 PM UTC  #    Comments [0]
# Thursday, January 21, 2010

One of the advantages of open source software is that it assist in troubleshooting and solving errors in your application.

Recently I ran into the following problem with ASP.NET MVC 2.0 RC.

image 

After some searching I found the following post:

ASP.NET MVC 2 problem with UpdateModel

I downloaded the ASP.NET MVC 2 RC source code, extracted the zip file, located the offending method and commented out the problem:

    public sealed class FormCollection : NameValueCollection, IValueProvider {

        public FormCollection() {
        }

        public FormCollection(NameValueCollection collection) {
            if (collection == null) {
                throw new ArgumentNullException("collection");
            }

            Add(collection);
        }

        public ValueProviderResult GetValue(string name) {
Commented Code
            //if (String.IsNullOrEmpty(name)) {
            //    throw new ArgumentException(MvcResources.Common_NullOrEmpty, "name");
            //}

            string[] rawValue = GetValues(name);
            if (rawValue == null) {
                return null;
            }

            string attemptedValue = this[name];
            return new ValueProviderResult(rawValue, attemptedValue, CultureInfo.CurrentCulture);
        }

        public IValueProvider ToValueProvider() {
            return this;
        }

        #region IValueProvider Members
        bool IValueProvider.ContainsPrefix(string prefix) {
            return ValueProviderUtil.CollectionContainsPrefix(AllKeys, prefix);
        }

        ValueProviderResult IValueProvider.GetValue(string key) {
            return GetValue(key);
        }
        #endregion

        private sealed class FormCollectionBinderAttribute : CustomModelBinderAttribute {

            // since the FormCollectionModelBinder.BindModel() method is thread-safe, we only need to keep
            // a single instance of the binder around
            private static readonly FormCollectionModelBinder _binder = new FormCollectionModelBinder();

            public override IModelBinder GetBinder() {
                return _binder;
            }

            // this class is used for generating a FormCollection object
            private sealed class FormCollectionModelBinder : IModelBinder {
                public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) {
                    if (controllerContext == null) {
                        throw new ArgumentNullException("controllerContext");
                    }

                    return new FormCollection(controllerContext.HttpContext.Request.Form);
                }
            }
        }

    }
}

 

After the solution was built,  I copied the output to the Libraries folder of the application:

 image

Removed the existing reference to System.Web.Mvc from the MVC Application and created a reference the the System.Web.Mvc in the Libraries folder.

image 

 

Then I commented out the  System.Web.Mvc GAC-version reference from web.config:

<compilation debug="true">
    <assemblies>
        <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <!--<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />-->
        <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="Microsoft.ReportViewer.Common, Version=9.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
    </assemblies>
    <buildProviders>
        <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </buildProviders>
</compilation>

and updated the /Views/web.config: (Replaced PublicKeyToken=31bf3856ad364e35 with PublicKeyToken=null)

 <pages validateRequest="false"
          pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL"
          pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL"
          userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL">
      <controls>
          <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL"
               namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>
  </pages>      
<!--<pages validateRequest="false" 
       pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" 
       pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" 
       userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <controls>
    <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" 
         namespace="System.Web.Mvc" tagPrefix="mvc" />
  </controls>
</pages>-->

 

posted on Thursday, January 21, 2010 9:48:01 PM UTC  #    Comments [0]
# Friday, March 27, 2009

This morning when I turned on my development computer I had the intention to re-factor some WPF user controls but every time I tried to open any of them in the designer Visual Studio 2008 will crash without any warning.

When I opened the Application error log I found the following message: 

Log Name:      Application
Source:        .NET Runtime
Date:          3/26/2009 11:07:53 AM
Event ID:      1023
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      SRV.Dev.CyberBizSoft.com
Description:
.NET Runtime version 2.0.50727.3074 - Fatal Execution Engine Error (70FC5FC0) (80131506)
Event Xml:
<Eventxmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <
System>
        <
ProviderName=".NET Runtime" />
        <
EventID Qualifiers="0">1023</EventID>
        <
Level>2</Level>
        <
Task>0</Task>
        <
Keywords>0x80000000000000</Keywords>
        <
TimeCreated SystemTime="2009-03-26T15:07:53.000Z" />
        <
EventRecordID>186149</EventRecordID>
        <
Channel>Application</Channel>
        <
Computer>SRV.Dev.CyberBizSoft.com</Computer>
        <
Security/>
    </
System>
    <
EventData>
        <
Data>.NET Runtime version 2.0.50727.3074 - Fatal Execution Engine Error (70FC5FC0) (80131506)

</Data>
    </EventData>
</Event>

After some online searching I found the following thread with this link to a hotfix to this problem. 

posted on Friday, March 27, 2009 2:43:16 AM UTC  #    Comments [0]
# Thursday, March 12, 2009

Earlier I posted about this problem I had with NHibernate, SQL CE 3.5.1.0 & ClickOnce. Well I found a workaround and it is very simple.

Instead of setting the "System.Data.SqlServerCe" reference property "Copy Local" to True,  when you are ready to deploy, set that reference property to false and on the ClickOnce Publish menu click on the "Application Files" button and change it from "Prerequisite (Auto)" to "Include".

Click for a bigger image!

You still have to set the "System.Data.SqlServerCe" reference property "Copy Local" to True while debugging your application locally for Nhibernate to work properly.

Remember to set it to false before publishing your application if not ClickOnce will remind you with the dreaded System.ArgumentException when launching the application. :-)

Click for a bigger image!

posted on Thursday, March 12, 2009 7:59:53 PM UTC  #    Comments [0]

Found Workaround!

I had wasted so much time with this ClickOnce error that I decided to create a new project and copy everything from the "bad" project and recreate all the references.

The deployment to ClickOnce worked fine but as soon as I logged into the application I got the following error from NHibernate:

image

The type initializer for 'CBSI.GL.Application.GLSetupService' threw an exception. (InnerException: Could not create the driver from NHibernate.Driver.SqlServerCeDriver.) (InnerException: Exception has been thrown by the target of an invocation.) (InnerException: The IDbCommand and IDbConnection implementation in the assembly System.Data.SqlServerCe could not be found. Ensure that the assembly System.Data.SqlServerCe is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use <qualifyAssembly/> element in the application configuration file to specify the full name of the assembly.)!

I had forgotten in the new project that with NHibernate you need to set the "System.Data.SqlServerCe" reference property "Copy Local" to True. As soon as I compiled and tested the debugging local copy it worked fine but when I deployed to ClickOnce the System.ArgumentException was back.

Since I noticed that I had a compiler warning and NHibernate.Driver.SqlServerCeDriver exception message say to "use <qualifyAssembly/> element" I added the following to my app.config:

<runtime>
    <assemblybinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentassembly>
            <assemblyidentity culture="neutral" publickeytoken="89845dcd8080cc91" 
name="System.Data.SqlServerCe" />
            <bindingredirect newVersion="3.5.1.0" oldVersion="3.5.0.0" />
        </dependentassembly>
        <qualifyAssembly partialName="System.Data.SqlServerCe" 
fullName="System.Data.SqlServerCe,version=3.5.1.0,publicKeyToken=89845dcd8080cc91,culture=neutral"/>
    </assemblybinding>
</runtime>    

It didn't work either!

I found the culprit, SQL CE 3.5.1.0 but apparently it is either ClickOnce or NHibernate with .NET 3.5 SP1.

If someone has a workable solution please let me know!

posted on Thursday, March 12, 2009 12:36:55 AM UTC  #    Comments [0]
# Friday, November 02, 2007

Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination are omnipotent. The slogan press on has solved and always will solve the problems of the human race.  No person was ever honored for what he received. Honor has been the reward for what he gave.

(John) Calvin Coolidge

My name is Santos Ray Victorero, II, I am a software developer, architect and consultant specializing in building customized business solutions. I have worked with computers since 1981 and have a Bachelor’s degree in Electrical Engineering from Florida Atlantic University.

Over the past thirty-years some of the technologies I have worked with include mainframes, minicomputers and microcomputers.  I have also developed several business applications including Payroll Systems, Point-of-Sale applications, School Management Systems, Private Investigation tools, Inventory Systems, Cargo Managers, etc…

Since September of 2000 I have been developing applications using the .NET Framework (alpha version). In 2001 I began working on a business framework that makes it easier to create customized business solutions.

My hobbies include music, reading and boating.  I mostly read books about business, software architecture and programming but I love to read anything as long as it is interesting.

Worldwide Institute of Software Architects

posted on Friday, November 02, 2007 3:32:48 AM UTC  #    Comments [0]