Code organization
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Code organization

  1. #1
    Join Date
    Aug 2011
    Posts
    3

    Code organization

    Hi!

    I’m developing an application where I use wcf services (vb.net - visual studio 2010) . I use the web services to:

    1.Send an xml schema populated with data
    2.Get a list of available web services
    3.Get a specific xsd schema

    What I have to do is:

    1.Get a xsd schema form the authority and use this xsd to generate a xml populated with data
    2.Call the webservice where I can specify a number for a specific xsd schema , and get the xsd schema in return. Then I can validat my xml schema against it before I send it to the authority
    3.Use a web service where my xml string is bound to a string property of a method of the wcf service and I send the xml file to the authority

    My xsd looks (almost) like this:

    Code:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:br="http://www.br.se/or" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <!--title='Tittle' lang='E'-->
      <xs:element name="Schema">
        <xs:annotation>
          <xs:documentation>
            <br:txt br:lang="E" br:txttype="LEDE">
              <p>Some text</p>
            </br:txt>
          </xs:documentation>
          <xs:documentation>
     
     
    …………………………
     
     
    <xs:complexType>
          <xs:sequence>
            <xs:element minOccurs="0" ref="Information"/>
            <xs:element minOccurs="0" ref="Payer"/>
          </xs:sequence>
          <xs:attribute fixed="105" name="numberr" type="xs:integer" use="required"/>
          <xs:attribute fixed="10360" name="externalnumberr" type="xs:integer" use="required"/>
                <xs:attribute fixed="Title" name="title" type="xs:string" use="optional"/>
          <xs:attribute fixed="4895" name="groupid" type="xs:positiveInteger" use="optional"/>
          <xs:attribute name="id" use="optional">
            <xs:simpleType>
              <xs:restriction base="xs:string">
                <xs:enumeration value="761065">
                  <xs:annotation>
                    <xs:documentation>Text</xs:documentation>
                  </xs:annotation>
                </xs:enumeration>
              </xs:restriction>
            </xs:simpleType>
          </xs:attribute>
          <xs:anyAttribute/>
        </xs:complexType>
      </xs:element>
    <xs:element name="Info">
        <xs:annotation>
          <xs:documentation>
            <br:txt br:lang="E" br:txttype="LEDE">
              <p>Some Text</p>
            </br:txt>
          </xs:documentation>
        </xs:annotation>
        <xs:complexType>
          <xs:sequence>
            <xs:element ref="Task">
              <xs:annotation>
                <xs:documentation>
                  <br:txt br:lang="E" br:txttype="LEDE">
                    <p>Some text</p>
                  </br:txt>
                </xs:documentation>
              </xs:annotation>
            </xs:element>
            <xs:element ref="Year">
              <xs:annotation>
                <xs:documentation>
                  <br:txt br:lang="E" br:txttype="LEDE">
                    <p>Some Text</p>
                  </br:txt>
                </xs:documentation>
              </xs:annotation>
            </xs:element>
            <xs:element minOccurs="0" ref="Taskowner"/>
          </xs:sequence>
          <xs:attribute fixed="4877" name="id" type="xs:positiveInteger" use="required"/>
        </xs:complexType>
      </xs:element>
    <xs:element name="TaskSpesialTask">
        <xs:annotation>
          <xs:documentation>
            <br:info br:type="some txt">1</br:info>
          </xs:documentation>
        </xs:annotation>
        <xs:complexType>
          <xs:simpleContent>
            <xs:extension base="List1">
              <xs:attribute fixed="212" name="schemaid" type="xs:positiveInteger" use="required"/>
            </xs:extension>
          </xs:simpleContent>
        </xs:complexType>
      </xs:element>
      <xs:simpleType name="List2">
        <xs:annotation>
          <xs:documentation>
            <br:info br:type="id">2</br:info>
          </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
          <xs:length value="1"/>
          <xs:enumeration value="1">
            <xs:annotation>
              <xs:documentation>
                <br:txt br:lang="E" br:txttype="LEDE">
                  <p>Some text</p>
                </br:txt>
              </xs:documentation>
            </xs:annotation>
          </xs:enumeration>
          <xs:enumeration value="2">
            <xs:annotation>
              <xs:documentation>
                <br:txt br:lang="E" br:txttype="LEDE">
                  <p>Some text</p>
                </br:txt>
              </xs:documentation>
            </xs:annotation>
          </xs:enumeration>
        </xs:restriction>
      </xs:simpleType>
    <xs:element name="Year">
        <xs:annotation>
          <xs:documentation>
            <br:info br:type="pl">2</br:info>
          </xs:documentation>
        </xs:annotation>
        <xs:complexType>
          <xs:simpleContent>
            <xs:extension base="Format">
              <xs:attribute fixed="692" name="schemaid" type="xs:positiveInteger" use="required"/>
            </xs:extension>
          </xs:simpleContent>
        </xs:complexType>
      </xs:element>
      <xs:simpleType name="Format">
        <xs:annotation>
          <xs:documentation>
            <br:info br:type="id">6</br:info>
          </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:gYear"/>
      </xs:simpleType>
    <xs:element name="TaskOwner">
        <xs:annotation>
          <xs:documentation>
            <br:txt br:lang="E" br:txttype="LEDE">
              <p>Some Text</p>
            </br:txt>
          </xs:documentation>
        </xs:annotation>
        <xs:complexType>
          <xs:sequence>
            <xs:element ref="TaskoOwnerNumber">
              <xs:annotation>
              </xs:annotation>
            </xs:element>
            <xs:element minOccurs="0" ref="TaskOwnerName">
              <xs:annotation>
              </xs:annotation>
            </xs:element>
            <xs:element minOccurs="0" ref="TaskOwnerAdress
              <xs:annotation>
              </xs:annotation>
            </xs:element>
            <xs:element minOccurs="0" ref="TaskOwnerPhone">
              <xs:annotation>
              </xs:annotation>
            </xs:element>
            <xs:element minOccurs="0" ref="TaskOwnerEmail">
              <xs:annotation>  
              </xs:annotation>
            </xs:element>
          </xs:sequence>
          <xs:attribute fixed="48" name="id" type="xs:positiveInteger" use="required"/>
        </xs:complexType>
      </xs:element>
    <xs:element name="TaskOwnerNumber">
        <xs:annotation>
        </xs:annotation>
        <xs:complexType>
          <xs:simpleContent>
            <xs:extension base="TextFormat">
              <xs:attribute fixed="21" name="id" type="xs:positiveInteger" use="required"/>
            </xs:extension>
          </xs:simpleContent>
        </xs:complexType>
      </xs:element>
      <xs:simpleType name="TextFormat">
        <xs:annotation>
          <xs:documentation>
            <br:info br:type="id">1</br:info>
          </xs:documentation>
          <xs:documentation>
            <br:txt br:lang="E" br:txttype="F">
              <p>Wrong number</p>
            </brreg:tekst>
          </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:string">
          <xs:length value="9"/>
        </xs:restriction>
      </xs:simpleType>
      <xs:element name="TaskOwner name">
        <xs:annotation> 
        </xs:annotation>
        <xs:complexType>
          <xs:simpleContent>
            <xs:extension base="TextFormat">
              <xs:attribute fixed="2" name="id" type="xs:positiveInteger" use="required"/>
            </xs:extension>
          </xs:simpleContent>
        </xs:complexType>
      </xs:element>
      <xs:element name="TaskOwner Adress">
        <xs:annotation>
        </xs:annotation>
      </xs:element>
     
    And so on for phone and email
     
     <xs:element name="Payers">
        <xs:annotation>
        </xs:annotation>
        <xs:complexType>
          <xs:sequence>
            <xs:element maxOccurs="20000" minOccurs="0" ref="PayersInfo"/>
            <xs:element minOccurs="0" ref="PaymentTotal">
              <xs:annotation>
              </xs:annotation>
            </xs:element>
            <xs:element minOccurs="0" ref="NumberOfPayers">
              <xs:annotation>
              </xs:annotation>
            </xs:element>
          </xs:sequence>
          <xs:attribute fixed="410" name="id" type="xs:positiveInteger" use="required"/>
        </xs:complexType>
      </xs:element>
      <xs:element name="PayersInfo">
        <xs:annotation>
        </xs:annotation>
        <xs:complexType>
          <xs:sequence>
            <xs:element minOccurs="0" ref="PayerBirthNumber">
              <xs:annotation>
              </xs:annotation>
            </xs:element>
            <xs:element minOccurs="0" ref="PayerNumber">
              <xs:annotation>
              </xs:annotation>
            </xs:element>
            <xs:element minOccurs="0" ref="PayerBirthDay">
              <xs:annotation>
              </xs:annotation>
            </xs:element>
            <xs:element minOccurs="0" ref="PayerName">
              <xs:annotation>
              </xs:annotation>
            </xs:element>
            <xs:element minOccurs="0" ref="PayerAdress">
              <xs:annotation>
              </xs:annotation>
            </xs:element>
            <xs:element minOccurs="0" ref="PayerPhone">
              <xs:annotation>
              </xs:annotation>
            </xs:element>
            <xs:element minOccurs="0" ref="PayerEmail">
              <xs:annotation>
              </xs:annotation>
            </xs:element>
            <xs:element minOccurs="0" ref="PayerSum">
              <xs:annotation>
              </xs:annotation>
            </xs:element>
          </xs:sequence>
          <xs:attribute fixed="48" name="id" type="xs:positiveInteger" use="required"/>
        </xs:complexType>
      </xs:element>
      <xs:element name="PayerBirthNumber">
        <xs:annotation>
        </xs:annotation>
        <xs:complexType>
          <xs:simpleContent>
            <xs:extension base="TextFormat">
              <xs:attribute fixed="2305" name="id" type="xs:positiveInteger" use="required"/>
            </xs:extension>
          </xs:simpleContent>
        </xs:complexType>
      </xs:element>
      <xs:simpleType name="TextFormat">
        <xs:annotation>
        </xs:annotation>
        <xs:restriction base="xs:string">
          <xs:length value="11"/>
        </xs:restriction>
      </xs:simpleType>
     
     
    And so on for PayerNumber, PayerBirthDay, PAYerNAMe, PayerAdress, PayerPhone, PayerEmail…..
     
    </xs:schema>
    (Pleas ignore if something is left out in the xsd - it is there just so I can explain my problem better)

    I use XSD.exe to auto generate a vb class from my xsd schema.

    My auto generated classes looks like this and they are stored in a file called Schema.vb


    Code:
    Partial Public Class Schema
    	Private info As Info
    	Private payers As Payers
    
    	Public Sub New()
            	MyBase.New
        	End Sub
    
    	Public Property Info() As Info
    	End Property
    	
    	Public Property Payers() As Payers
    	End Property
    End class
    
    Partial Public Class Info
    	Private year As Year
    	Private taskOwner As TaskOwner
    
    	Public Sub New()
            	MyBase.New
        	End Sub
    
    	Public Property Year() As Year
    	End Property
    	
    	Public Property TaskOwner() As TaskOwner
    	End Property	
    End Class
    
    Partial Public Class Year
    	Public Sub New()
            	MyBase.New
        	End Sub
    End Class
    
    Partial Public Class TaskOwner
    	Private taskOwnerName As TaskOwnerName
    	.....
    	Private taskOwnerEmail As TaskOwnerEmail
    
    	Public Sub New()
            	MyBase.New
        	End Sub
    
    	Public Property TaskOwnerName() As TaskOwnerName
    	End Property
    	
    	Public Property TaskOwnerName() As TaskOwnerName
    	End Property	
    End Class
    
    Partial Public Class TaskOwnerName
    End class
    
    ....
    
    Partial Public Class TaskOwnerEmail
    End Class
    
    Partial Public Class Task
    	Private valuefield As TaskType
    
    	Public Sub New()
            	MyBase.New
        	End Sub
    
    	Public Property Value() As TaskType
    	End Property
    End Class
    
    
    Public Enum TaskTypeValue
    	<System.Xml.Serialization.XmlEnumAttribute("1")>  _
        	Item1
        	
    	<System.Xml.Serialization.XmlEnumAttribute("2")>  _
        	Item2
    End Enum
    
    
    Partial Public Class Payers
    	Private payersInfo() As PayersInfo - Array of PayersObjects
    	Private paymentTotal AS PaymentTotal
    	Private numberOfPayers AS NumberOfPayers
    	
    	Public Sub New()
            	MyBase.New
        	End Sub
    	
    	Public Property PayersInfo() As PayersInfo()
    	End Property
    	
    	Public Property PaymentTotal() As PaymentTotal
    	End Property
    
    	Public Property NumberOfPayers() As NumberOfPayers
    	End Property
    End Class
    
    Partial Public Class PaymentTotal
    	Public Sub New()
            	MyBase.New
        	End Sub
    End Class
    
    Partial Public Class NumberOfPayers
    	Public Sub New()
            	MyBase.New
        	End Sub
    End Class
    
    Partial Public Class PayersInfo
    	Private payerBirthnumberAs PayerBirthnumber
    	.....
    	Private payerEmail As PayerEmail
    
    	Public Sub New()
            	MyBase.New
        	End Sub
    
    	Public Property PayerBirthnumber() As PayerBirthnumber
    	End Property
    	......
    	Public Property PayerEmail() As PayerEmail
    	End Property
    End class
    
    Partial Public Class PayerBirthnumber
    	Public Sub New()
            	MyBase.New
        	End Sub
    End Class
    
    ....
    
    Partial Public Class PayerEmail
    	Public Sub New()
            	MyBase.New
        	End Sub
    End Class
    I'm not quite sure how I can use the auto generated partial classes.

    I have another Class SendSchema that populates the partial class objects, serialize the object to an xml and ships the xml to the wcf.

    But when I use the partial classes in the sendSchema class I have to instantiate all my partial classes like this


    Code:
    Dim schema_Obj = New Skjema
    Dim info_Obj As New Info
    Dim year_Obj as New Year
    Dim taskOwner_Obj as New TaskOwner
    and so on until I have done this for all my partial classes

    When I populate the objects with data I have to say


    Code:
    schema_obj.info_obj.task_Obj.Value = TaskType.Item1
    schema_Obj.info_Obj.year_Obj.Value = "2011"
    schema_Obj.info_Obj.taskOwner_Obj.taskOwnerName_Obj.value="Bob"
    and so on.

    Then I have to serialize my Schema Object (this is the object holding all the information stored in all other objects - Info,TaskoOwner....) like this

    Code:
    Dim memorystream As New System.IO.MemoryStream
    Dim ser As New XmlSerializer(GetType(Schema))
    
    ser.Serialize(memorystream, schema_obj)
    I have multiple xsd schema I have to do this for, and the schemas is changing once a year.

    My questions is:

    1. Is deserialization and serialization the best approach for me?
    2. Is it possible to automate the deserialization step (xsd to class) in any way?
    3. How can I use my partial classes without train wreck the code (Law Of Demeter)

    I very much appreciate all the help I can get on this!!

    Thanks in advance!!
    Last edited by solstorm; August 19th, 2011 at 01:10 AM. Reason: Instert [code][/code]

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,875

    Re: Code organization

    Nobody can/will read that mess. Use code tags

    Code:
    ' Like THIS
    If it's only 3 questions, just show a few lines of RELEVANT code for each question.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Aug 2011
    Posts
    3

    Re: Code organization

    I'm very sorry but I could not figure out how I could write my code sections in a code block. And I am not able to edit my post.... can I delet my post an post again?

  4. #4
    DataMiser is online now Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,785

    Re: Code organization

    You can post again in this thread [code] Your Code [/code] gives you
    Code:
    Your Code
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    Aug 2011
    Posts
    3

    Re: Code organization

    Thank you for your help, I have reposted with the tags.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center