PageRenderTime 23ms CodeModel.GetById 16ms app.highlight 5ms RepoModel.GetById 0ms app.codeStats 0ms

/GolfSigma.Inventory.Console/Program.cs

http://github.com/golfsigma/inventory-client
C# | 260 lines | 111 code | 26 blank | 123 comment | 5 complexity | c1d4310572706685ff05437f1b54603c MD5 | raw file
  1using System;
  2using System.Collections.Generic;
  3using System.Linq;
  4using System.Text;
  5using System.Security.Cryptography;
  6
  7using GolfSigma.Inventory;
  8using GolfSigma.Inventory.Model;
  9
 10namespace GolfSigma.Inventory.Console
 11{
 12    class Program
 13    {
 14        static void Main(string[] args)
 15        {
 16            // Create a new instance of our client
 17            var client = new InventoryClient(
 18                "32633c3ea2d5450095414169786c308e",
 19                "V7XSVunann6Wa7HAU8IfEKaNGOAE2EcNOV10xaojRfjnAQUUOm4Pdr/RkXvLFu3czslylpEWrjNviD3PasFytg",
 20                new InventoryConfig()
 21                {
 22                    MaxErrorRetry = 0,
 23                    //ServiceURL = "http://ipv4.fiddler:54657",
 24                    ServiceURL = "http://inv.golfsigmaws.com:54657",
 25                    ProxyHost = "localhost",
 26                    ProxyPort = 8888,
 27                    UserAgent = "GolfSigma.Inventory.Console",
 28                    SetForwardedFor = false
 29                });
 30
 31            //byte[] secretkey = new Byte[64];
 32            //RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
 33            //rng.GetBytes(secretkey);
 34            //var key = Convert.ToBase64String(secretkey);
 35
 36            // Try and get a teetime
 37            //var result = client.GetTeeTime(
 38            //    new GetTeeTimeRequest(
 39            //        new Guid("e3c0570fe3304fe29eb94befed8f59d0")
 40            //        )
 41            //    );
 42
 43            // Try and get a search
 44            //var result = client.GetSearch(
 45            //    new GetSearchRequest(
 46            //        new Guid("9e5c514a833b45c6ba3689437db32613")
 47            //        )
 48            //    );
 49
 50            // Try and get inventory by searchId
 51            //var result = client.GetInventory(
 52            //    new GetInventoryRequest(
 53            //        new Guid("5531441c1dc74511b637b4c510602170")
 54            //        )
 55            //    );
 56
 57            // Try and get inventory in a single call by creating a search at the same time
 58            //var result = client.GetInventory(
 59            //        new PutSearchRequest()
 60            //        {
 61            //            Search = new Search()
 62            //            {
 63            //                ExternalId = "invClientLibrary",
 64            //                Date = DateTime.Now.AddDays(2).Date,
 65            //                MaxDaysOut = 1,
 66            //                Players = PlayerEnum.All,
 67            //                SearchType = SearchTypeEnum.SingleDay,
 68            //                TimeOfDay = new TimeSpan(9, 30, 0),
 69            //                Attributes = new List<TeeTimeAttributeEnum>()
 70            //                {
 71            //                    TeeTimeAttributeEnum.Holes18
 72            //                },
 73            //                CourseIds = new List<Guid>()
 74            //                {
 75            //                    new Guid("765bb849-4766-452a-aa0b-49a933dfb7bb")
 76            //                },
 77            //                Filters = new List<SearchFilter>()
 78            //                {
 79            //                    new SearchFilter(new Guid("90d280e6-a8e2-428a-992f-cb47b9c799d3"), "Interval", "30")
 80            //                }
 81            //            }
 82            //        }
 83            //    );
 84
 85            // Try and get similar tee-times
 86            //var result = client.GetSimilarTeeTimes(
 87            //    new GetSimilarTeeTimeRequest(
 88            //        new Guid("f9189ef2feaf4a68a2a4fbc7c43fbf84")
 89            //        )
 90            //    );
 91
 92            // Create a search
 93            //var result = client.PutSearch(
 94            //    new PutSearchRequest()
 95            //    {
 96            //        Search = new Search()
 97            //        {
 98            //            ExternalId = "invClientLibrary",
 99            //            Date = DateTime.Now.AddDays(7),
100            //            MaxDaysOut = 1,
101            //            Players = PlayerEnum.Threesome,
102            //            SearchType = SearchTypeEnum.SingleDay,
103            //            TimeOfDay = new TimeSpan(9, 30, 0),
104            //            Attributes = new List<TeeTimeAttributeEnum>()
105            //            {
106            //                TeeTimeAttributeEnum.Holes18,
107            //                TeeTimeAttributeEnum.MembersOnly
108            //            },
109            //            Filters = new List<SearchFilter>()
110            //            {
111            //                new SearchFilter(new Guid("22816dc4-538e-412e-8594-f46150e6520c"), "MinPrice", "20")
112            //            },
113            //            CourseIds = new List<ulong>()
114            //            {
115            //                8731
116            //            }
117            //        }
118            //    });
119
120            // Batch put multiple tee times
121            var start = DateTime.Now.Ticks;
122            var teeTimes = new List<Model.TeeTime>();
123            var random = new Random();
124            for (int d = 2; d <= 2; d++)
125            {
126                for (int a = 0; a < 15; a++)
127                {
128                    for (int i = 0; i < 200; i++)
129                    {
130                        teeTimes.Add(
131                            new TeeTime()
132                            {
133                                CourseId = GetRandomCourseId(random),
134                                MiscData = i.ToString(),
135                                Players = GetRandomPlayers(random),
136                                //Players = PlayerEnum.Twosome,
137                                Time = GetRandomDate(random, d),
138                                TotalPricePerPlayer = GetRandomPrice(random),
139                                WebSiteId = GetRandomWebsite(random),
140                                Attributes = new List<TeeTimeAttributeEnum>()
141                            {
142                                TeeTimeAttributeEnum.Holes18    
143                            },
144                                Fees = new Dictionary<FeeEnum, float>()
145                            {
146                                { FeeEnum.Green, GetRandomPrice(random) },
147                                { FeeEnum.Cart, GetRandomPrice(random) }
148                            }
149                            });
150                    }
151                    client.BatchPutTeeTimes(
152                        new BatchPutTeeTimesRequest(teeTimes)
153                        );
154                    teeTimes.Clear();
155                }
156            }
157
158            var end = DateTime.Now.Ticks;
159            var timespan = new TimeSpan(end - start);
160
161            // Put a single tee times
162            //var random = new Random();
163            //var result = client.PutTeeTime(
164            //    new PutTeeTimeRequest()
165            //    {
166            //        TeeTime = new TeeTime()
167            //        {
168            //            CourseId = 8731,
169            //            ApplicationData = "feeTest",
170            //            Players = PlayerEnum.All,
171            //            Time = GetRandomDate(random),
172            //            TotalPricePerPlayer = GetRandomPrice(random),
173            //            WebSiteId = 14,
174            //            Fees = new Dictionary<FeeEnum, float>()
175            //            {
176            //                { FeeEnum.Green, 45F },
177            //                { FeeEnum.Cart, 10F }
178            //            }
179            //        }
180            //    });
181
182            // Create a reservation
183            //var result = client.PutReservation(
184            //    new PutReservationRequest()
185            //    {
186            //        Reservation = new Reservation()
187            //        {
188            //            ExternalId = "shaunWasHere",
189            //            SearchId = 2,
190            //            TeeTimeId = 201,
191            //        }
192            //    });
193
194            // Get an existing reservation
195            //var result = client.GetReservation(
196            //    new GetReservationRequest()
197            //    {
198            //        ReservationId = new Guid("66dacf5c2cb04d4683317f3a3aae5fcc")
199            //    });
200        }
201
202        static DateTime GetRandomDate(Random random, int daysOut)
203        {
204            var randomSeconds = random.Next(0, 39600);
205
206            DateTime minDate = DateTime.Now.AddDays(daysOut).Date.AddHours(6);
207            var result = minDate.AddSeconds(randomSeconds);
208
209            return result.AddSeconds(-result.Second);
210        }
211
212        static float GetRandomPrice(Random random)
213        {
214            var rnd = new Random();
215            var randomAddition = random.Next(0, 10000);
216
217            float minPrice = 10;
218
219            return minPrice + (randomAddition / 100F);
220        }
221
222        static PlayerEnum GetRandomPlayers(Random random)
223        {
224            var rnd = new Random();
225            var randomAddition = random.Next(1, 4);
226
227            switch (randomAddition)
228            {
229                case 1: return PlayerEnum.Single;
230                case 2: return PlayerEnum.Twosome | PlayerEnum.Single;
231                case 3: return PlayerEnum.Threesome | PlayerEnum.Twosome;
232                case 4:
233                default: return PlayerEnum.All;
234            }
235        }
236
237        static UInt64 GetRandomCourseId(Random random)
238        {
239            var stringCourseIds = "427,443,474,484,491,515,516,530,554,558,562,566,8731,8732,581,619,631,654,684,698,714,8733,8734,8735,436,9748,9749,444,446,450,10148,456,9744,9745,9723,9724,466,470,477,478,496,502,504,505,514,533,537,538,548,551,556,559,560,563,564,569,570,572,587,591,594,595,600,601,633,634,642,644,649,665,670,672,676,677,679,683,10383,10384,689,700,702,708,10238,10239,9746,9747,713,9721,9722,722,724,728,729,733,9725,9726,9727,9728,9750,9751,9753,9754,9755,10240,10386";
240            var courseIds = new List<UInt64>();
241            foreach (var item in stringCourseIds.Split(new char[] { ',' }))
242            {
243                UInt64 courseId;
244                if (UInt64.TryParse(item, out courseId))
245                    courseIds.Add(courseId);
246            }
247
248            var randomCourseIndex = random.Next(0, courseIds.Count - 1);
249            return courseIds[randomCourseIndex];
250        }
251
252        static UInt32 GetRandomWebsite(Random random)
253        {
254            var webSiteIds = new UInt32[] { 9, 14, 11 };
255            var randomAddition = random.Next(0, webSiteIds.Length - 1);
256
257            return webSiteIds[randomAddition];
258        }
259    }
260}