Subversion Repository Public Repository

WOX2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using System;
using System.Collections.Generic;
using System.Threading;

/// <header>
/// <wox>
///     <version>1.0</version>
///     <author>Carlos R. Jaimez Gonzalez</author>
///     <author>Simon M. Lucas</author>
///     <site>http://woxserializer.sourceforge.net/</site>
/// </wox>
/// <wox>
///     <version>1.5</version>
///     <author>Steven M Lewis</author>
/// </wox>
/// <wox>
///     <version>2.0</version>
///     <author>George A Smith</author>
///     <svn>http://woxserializer.sourceforge.net/</svn>
///     <note>XML form for vs 2 is more compact and therefor incompatible with vs 1</note>
/// </wox>
/// </header>

namespace wox.serial.tests.objects
{
    public class Pharmacy
    {
        #region Delegates

        public delegate String PerscriptionApproval( String ssNumber, Perscription p );

        #endregion

        private static readonly Pharmacy gInstance = new Pharmacy();
        public static readonly Random RND = new Random();

        private readonly IDictionary<String, Patient> mPatients = new Dictionary<String, Patient>();

        private Pharmacy()
        {
        }

        public static Pharmacy Instance
        {
            get { return gInstance; }
        }

        /// <summary>
        /// get a Patient by Social number
        /// </summary>
        /// <param name="ssNumber"></param>
        /// <returns>possibly null patient</returns>
        public Patient GetPatient( String ssNumber )
        {
            Patient ret;
            mPatients.TryGetValue( ssNumber, out ret );
            return ret;
        }

        /// <summary>
        /// Add a perscription to an existing patnient
        /// </summary>
        /// <param name="ssNumber">SSN of an existing patioent</param>
        /// <param name="p">perscription ot add</param>
        public void AddPerscription( String ssNumber, Perscription p )
        {
            Patient ret;

            mPatients.TryGetValue( ssNumber, out ret );
            if ( ret == null )
            {
                throw new ArgumentException( "Cannot find patient " + ssNumber );
            }
            ret.AddPerscription( p );
        }

        /// <summary>
        /// Add a perscription to an existing patnient
        /// </summary>
        /// <param name="ssNumber">SSN of an existing patioent</param>
        /// <param name="p">perscription ot add</param>
        public Authorization AuthorizePerscription( String ssNumber, Perscription p )
        {
            var ret = new Authorization();
            ret.SSNumber = ssNumber;
            ret.Perscr = p;

            if ( RND.NextDouble() < 0.3 )
            {
                Thread.Sleep( (int) (10000 * RND.NextDouble()) );
            }


            if ( RND.NextDouble() < 0.5 )
            {
                ret.Authorized = true;
            }
            else
            {
                ret.Authorized = false;
                ret.RejectionReason = "Bad Karma";
            }
            return ret;
        }


        /// <summary>
        /// Approve a perscription - this needs to be Async
        /// </summary>
        /// <param name="ssNumber">SSN of an existing patioent</param>
        /// <param name="p">perscription ot add</param>
        public void ApprovePerscription( String ssNumber, Perscription p, IAsyncResult callback )
        {
            Patient ret;

            mPatients.TryGetValue( ssNumber, out ret );
            if ( ret == null )
            {
                throw new ArgumentException( "Cannot find patient " + ssNumber );
            }
            ret.AddPerscription( p );
        }

        public static void PerscriptionApprovalCallback( IAsyncResult iar )
        {
            var mc = (PerscriptionApproval) iar.AsyncState;
            String result = mc.EndInvoke( iar );
            Console.WriteLine( "Function value = {0}", result );
        }

        public static void CallMathCallback( PerscriptionApproval mathFunc, String ssNumber, Perscription p )
        {
            AsyncCallback cb = PerscriptionApprovalCallback;

            //  Console.WriteLine("BeginInvoke: {0}", start);
            mathFunc.BeginInvoke( ssNumber, p, cb, mathFunc );
        }


        /// <summary>
        /// Add a address to an existing patnient
        /// </summary>
        /// <param name="ssNumber">SSN of an existing patioent</param>
        /// <param name="p">address to add</param>
        public void AddAddress( String ssNumber, Address p )
        {
            Patient ret;
            mPatients.TryGetValue( ssNumber, out ret );
            if ( ret == null )
            {
                throw new ArgumentException( "Cannot find patient " + ssNumber );
            }
            ret.AddAddress( p );
        }

        /// <summary>
        /// Add a patient
        /// </summary>
        /// <param name="p">non-null patient</param>
        public void AddPatient( Patient p )
        {
            mPatients[p.SSNumber] = p;
        }

        /// <summary>
        /// Clear all Patients
        /// </summary>
        public void Clear()
        {
            mPatients.Clear();
        }
    }
}

Commits for WOX2/trunk/CSharp/tests/wox/serial/tests/objects/Pharmacy.cs

Diff revisions: vs.
Revision Author Commited Message
14 Diff Diff GeorgeS picture GeorgeS Fri 19 Feb, 2010 19:15:03 +0000
3 GeorgeS picture GeorgeS Thu 04 Feb, 2010 23:53:47 +0000