DataModel.cs :  » Database » Berkeley-DB » getting_started » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Database » Berkeley DB 
Berkeley DB » getting_started » DataModel.cs
/*
 * This software is licensed according to the "Modified BSD License",
 * where the following substitutions are made in the license template:
 * <OWNER> = Karl Waclawek
 * <ORGANIZATION> = Karl Waclawek
 * <YEAR> = 2005, 2006
 * It can be obtained from http://opensource.org/licenses/bsd-license.html.
 */

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using BerkeleyDb;
using Kds.Serialization;
using Kds.Serialization.Buffer;

namespace getting_started{
  public class Vendor
  {
    internal string name;
    internal string street;
    internal string city;
    internal string state;
    internal string zipCode;
    internal string phoneNumber;
    internal SalesRep salesRep;

    public string Name {
      get { return name; }
      set { name = value; }
    }

    public string Street {
      get { return street; }
      set { street = value; }
    }

    public string City {
      get { return city; }
      set { city = value; }
    }

    public string State {
      get { return state; }
      set { state = value; }
    }

    public string ZipCode {
      get { return zipCode; }
      set { zipCode = value; }
    }

    public string PhoneNumber {
      get { return phoneNumber; }
      set { phoneNumber = value; }
    }

    public SalesRep SalesRep {
      get { return salesRep; }
      set { salesRep = value; }
    }
  }

  public class VendorField: ReferenceField<Vendor>
  {
    public VendorField(Formatter fmt, bool isDefault) : base(fmt, isDefault) { }

    protected override void SerializeValue(Vendor value) {
      Fmt.Serialize<string>(value.Name);
      Fmt.Serialize<string>(value.Street);
      Fmt.Serialize<string>(value.City);
      Fmt.Serialize<string>(value.State);
      Fmt.Serialize<string>(value.ZipCode);
      Fmt.Serialize<string>(value.PhoneNumber);
      Fmt.Serialize<SalesRep>(value.SalesRep);
    }

    protected override void DeserializeInstance(ref Vendor instance) {
      if (instance == null)
        instance = new Vendor();
    }

    protected override void DeserializeMembers(Vendor instance) {
      Fmt.Deserialize<string>(ref instance.name);
      Fmt.Deserialize<string>(ref instance.street);
      Fmt.Deserialize<string>(ref instance.city);
      Fmt.Deserialize<string>(ref instance.state);
      Fmt.Deserialize<string>(ref instance.zipCode);
      Fmt.Deserialize<string>(ref instance.phoneNumber);
      Fmt.Deserialize<SalesRep>(ref instance.salesRep);
    }

    protected override void SkipValue() {
      if (Fmt.Skip<string>())
      if (Fmt.Skip<string>())
      if (Fmt.Skip<string>())
      if (Fmt.Skip<string>())
      if (Fmt.Skip<string>())
      if (Fmt.Skip<string>())
      Fmt.Skip<SalesRep>();
    }
  }

  public class SalesRep
  {
    internal string name;
    internal string phoneNumber;

    public string Name {
      get { return name; }
      set { name = value; }
    }

    public string PhoneNumber {
      get { return phoneNumber; }
      set { phoneNumber = value; }
    }
  }

  public class SalesRepField: ReferenceField<SalesRep>
  {
    public SalesRepField(Formatter fmt, bool isDefault) : base(fmt, isDefault) { }

    protected override void SerializeValue(SalesRep value) {
      Fmt.Serialize<string>(value.Name);
      Fmt.Serialize<string>(value.PhoneNumber);
    }

    protected override void DeserializeInstance(ref SalesRep instance) {
      if (instance == null)
        instance = new SalesRep();
    }

    protected override void DeserializeMembers(SalesRep instance) {
      string val = null;  // when using a property we need an intermediate variable
      Fmt.Deserialize<string>(ref val);
      instance.Name = val;
      Fmt.Deserialize<string>(ref instance.phoneNumber);
    }

    protected override void SkipValue() {
      if (Fmt.Skip<string>())
      Fmt.Skip<string>();
    }
  }

  public class StockItem
  {
    internal string name;
    internal string category;
    internal string vendor;
    internal string sku;
    internal float? price;
    internal int? quantity;

    public string Name {
      get { return name; }
      set { name = value; }
    }

    public string Category {
      get { return category; }
      set { category = value; }
    }

    public string Vendor {
      get { return vendor; }
      set { vendor = value; }
    }

    public string Sku {
      get { return sku; }
      set { sku = value; }
    }

    public float? Price {
      get { return price; }
      set { price = value; }
    }

    public int? Quantity {
      get { return quantity; }
      set { quantity = value; }
    }
  }

  public class StockItemField: ReferenceField<StockItem>
  {
    public StockItemField(Formatter fmt, bool isDefault) : base(fmt, isDefault) { }

    protected override void SerializeValue(StockItem value) {
      Fmt.Serialize<string>(value.name);
      Fmt.Serialize<string>(value.category);
      Fmt.Serialize<string>(value.vendor);
      Fmt.Serialize<string>(value.sku);
      Fmt.Serialize<float>(value.price);
      Fmt.Serialize<int>(value.quantity);
    }

    protected override void DeserializeInstance(ref StockItem instance) {
      if (instance == null)
        instance = new StockItem();
    }

    protected override void DeserializeMembers(StockItem instance) {
      Fmt.Deserialize<string>(ref instance.name);
      Fmt.Deserialize<string>(ref instance.category);
      Fmt.Deserialize<string>(ref instance.vendor);
      Fmt.Deserialize<string>(ref instance.sku);
      instance.price = Fmt.Deserialize<float>();
      instance.quantity = Fmt.Deserialize<int>();
    }

    protected override void SkipValue() {
      if (Fmt.Skip<string>())
      if (Fmt.Skip<string>())
      if (Fmt.Skip<string>())
      if (Fmt.Skip<string>())
      if (Fmt.Skip<float>())
      Fmt.Skip<int>();
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.