//mmddyyyy format private Summary TargetProcessSummary(string strDate) { Summary summary = null; try { lock (_doTPWorkSync) { DateTime requestedDate = strDate.StringToDateTime(); DateTime previousMonday = requestedDate.StartOfWeek(DayOfWeek.Monday); previousMonday = previousMonday.AddDays(-1); //hack requestedDate = requestedDate.AddDays(1); // & hack to get the number right (as they should be) //Step 1 : Collect all emails summary = new Summary(strDate.StringToDateTime()); var webClient = new WebClient(); //webClient.Headers.Add("Authorization", "Basic YXR1bGM6dGVzdGluZw=="); //atul's key webClient.Headers.Add("Authorization", "Basic a2V2aW5tOlJVQ3Jhenky"); //kevin's key JavaScriptSerializer jss = new JavaScriptSerializer(); jss.RegisterConverters(new JavaScriptConverter[] { new DynamicJsonConverter() }); var nextLink = "http://tp.yaharasoftware.com/api/v1/Users?format=json"; while (nextLink != null) { Stream data = webClient.OpenRead(nextLink); StreamReader reader = new StreamReader(data); string json = reader.ReadToEnd(); //Debug.WriteLine(json); data.Close(); reader.Close(); dynamic tpEntry = jss.Deserialize(json, typeof(object)) as dynamic; int count = tpEntry.Items.Count; for (int i = 0; i < count; i++) { try { string email = tpEntry.Items[i]["Email"].ToLower(); if (!email.Contains("yahara") || tpEntry.Items[i]["IsActive"] == false) continue; EmployeeDetail ed = new EmployeeDetail(); ed.Id = tpEntry.Items[i]["Id"]; ed.Name = tpEntry.Items[i]["FirstName"] + " " + tpEntry.Items[i]["LastName"]; ed.Email = tpEntry.Items[i]["Email"]; summary.ListOfItems.Add(ed); } catch { //ignore and move on } } try { if (tpEntry.Next != null) nextLink = tpEntry.Next; else nextLink = null; } catch (KeyNotFoundException) { nextLink = null; } } //Step 2 : Collect all times for this week //var nextTimeLink = "http://tp.yaharasoftware.com/api/v1/Times?format=json&take=1000&where=(Date%20gt%20'2012-04-16')%20and%20(Date%20lt%20'2012-04-19')"; var nextTimeLink = "http://tp.yaharasoftware.com/api/v1/Times?format=json&take=1000&where=(Date%20gt%20'" + previousMonday.ToString("yyyy-MM-dd") + "')%20and%20(Date%20lt%20'" + requestedDate.ToString("yyyy-MM-dd") + "')"; while (nextTimeLink != null) { Stream data = webClient.OpenRead(nextTimeLink); StreamReader reader = new StreamReader(data); string json = reader.ReadToEnd(); //Debug.WriteLine(json); data.Close(); reader.Close(); dynamic tpEntry = jss.Deserialize(json, typeof(object)) as dynamic; int count = tpEntry.Items.Count; for (int i = 0; i < count; i++) { try { int Id = tpEntry.Items[i]["User"]["Id"]; var ed = (from l in summary.ListOfItems where l.Id == Id select l).FirstOrDefault(); if (ed == null) continue; DateTime dateTimeSpentOn = tpEntry.Items[i]["Date"]; decimal timeSpent = tpEntry.Items[i]["Spent"]; if ((requestedDate.GetEndOfDay().CompareTo(dateTimeSpentOn) >= 0) && (previousMonday.Date.CompareTo(dateTimeSpentOn) <= 0)) { (from l in summary.ListOfItems where l.Id == Id select l).First().TotalHoursLogged += timeSpent; } } catch { //ignore and move on } } try { if (tpEntry.Next != null) nextTimeLink = tpEntry.Next; else nextTimeLink = null; } catch (KeyNotFoundException) { nextTimeLink = null; } } EmployeeDetailComparer dc = new EmployeeDetailComparer(); summary.ListOfItems.Sort(dc); } } catch { ;//Exception swallowing technology } return summary; }
//mmddyyyy format private Summary WebShadowSummary(string strDate) { Summary summary = null; try { lock (_doTPWorkSync) { DateTime requestedDate = strDate.StringToDateTime(); DateTime previousMonday = requestedDate.StartOfWeek(DayOfWeek.Monday); ForecastSummary fs = GetForecast(previousMonday.DateTimeToString(), requestedDate.DateTimeToString()); summary = new Summary(strDate.StringToDateTime()); summary.ListOfItems = new List<EmployeeDetail>(fs.Resources.Count); foreach (ResourceSummary rs in fs.Resources) { EmployeeDetail ed = new EmployeeDetail(); ed.TotalHoursLogged = (decimal)rs.TotalHoursRecorded; ed.Name = rs.Resource.FirstName + " " + rs.Resource.LastName; summary.ListOfItems.Add(ed); } EmployeeDetailComparer dc = new EmployeeDetailComparer(); summary.ListOfItems.Sort(dc); } } catch { ;//Exception Swallowing Technology } return summary; }