public static DeliveryPointsDataset GetCustomers() { //Get roadshow customers DeliveryPointsDataset customers = null; DeliveryPointsServiceClient client = new DeliveryPointsServiceClient(); try { ObjectCache cache = MemoryCache.Default; customers = cache["customers"] as DeliveryPointsDataset; if (customers == null) { customers = new DeliveryPointsDataset(); DataSet ds = client.GetRoadshowCustomers(); if (ds != null) { customers.Merge(ds); } client.Close(); DateTimeOffset policy = new DateTimeOffset(DateTime.Now.AddMinutes(_cacheTimeout)); cache.Set("customers", customers, policy); } } catch (TimeoutException te) { client.Abort(); throw new ApplicationException(te.Message); } catch (FaultException <RoadshowFault> dfe) { client.Abort(); throw new ApplicationException(dfe.Detail.Message); } catch (FaultException fe) { client.Abort(); throw new ApplicationException(fe.Message); } catch (CommunicationException ce) { client.Abort(); throw new ApplicationException(ce.Message); } return(customers); }
public DataSet GetDeliveryPoints(DateTime startDate, DateTime lastUpated) { //Update a collection (dataset) of all delivery points DataSet points = new DataSet(); const string CSV_DELIM = ","; try { //Clear and fetch new data DataSet ds = new DeliveryPointsGateway().GetDeliveryPoints(startDate, lastUpated); if (ds != null && ds.Tables["DeliveryPointTable"] != null && ds.Tables["DeliveryPointTable"].Rows.Count > 0) { //Create a dataset of containing unique entries DeliveryPointsDataset _ds = new DeliveryPointsDataset(); _ds.Merge(ds); DeliveryPointsDataset rds = new DeliveryPointsDataset(); rds.Merge(_ds.DeliveryPointTable.Select("", "Account ASC")); Hashtable ht = new Hashtable(); string acct = ""; for (int i = 0; i < rds.DeliveryPointTable.Rows.Count; i++) { //Remove duplicate account entries acct = rds.DeliveryPointTable[i].Account; if (ht.ContainsKey(acct)) { rds.DeliveryPointTable[i].Delete(); } else { ht.Add(acct, null); //Keep track of keys (unique accounts) } } rds.AcceptChanges(); //Modify data for (int i = 0; i < rds.DeliveryPointTable.Rows.Count; i++) { //Set command as follows: // A: OpenDate > lastpDated; U: OpenDate <= lastUpdated DateTime opened = rds.DeliveryPointTable[i].OpenDate; rds.DeliveryPointTable[i].Command = (opened.CompareTo(lastUpated) > 0) ? "A" : "U"; //Remove commas from address fields rds.DeliveryPointTable[i].Building = rds.DeliveryPointTable[i].Building.Replace(CSV_DELIM, " "); rds.DeliveryPointTable[i].Address = rds.DeliveryPointTable[i].Address.Replace(CSV_DELIM, " "); rds.DeliveryPointTable[i].StopComment = rds.DeliveryPointTable[i].StopComment.Replace(CSV_DELIM, " "); } rds.AcceptChanges(); points.Merge(rds); } } catch (Exception ex) { throw new FaultException <TerminalsFault>(new TerminalsFault(ex.Message), "Service Error"); } return(points); }
public static DeliveryPointsDataset GetDeliveryPoints(DateTime startDate, DateTime lastUpated) { //Get delivery points DeliveryPointsDataset points = new DeliveryPointsDataset(); DeliveryPointsServiceClient client = new DeliveryPointsServiceClient(); try { DataSet ds = client.GetDeliveryPoints(startDate, lastUpated); if (ds != null) { points.Merge(ds); } client.Close(); } catch (TimeoutException te) { client.Abort(); throw new ApplicationException(te.Message); } catch (FaultException <TerminalsFault> dfe) { client.Abort(); throw new ApplicationException(dfe.Detail.Message); } catch (FaultException fe) { client.Abort(); throw new ApplicationException(fe.Message); } catch (CommunicationException ce) { client.Abort(); throw new ApplicationException(ce.Message); } return(points); }