// Retrives all Regions from the current BU public static Region[] RetrieveRegions() { try { // Call the Web Services RetrievalResults retrievalResults = QueryServiceClient.RetrieveRegionsGrantingPermissions( SessionHeader, new RolePermission[] { }, false); // Checks if the process returned a valid result if (retrievalResults.Items == null) { throw new Exception("Retrieve Regions failed."); } else if (retrievalResults.Items.Length == 0) { throw new Exception("No Regions found."); } else { // Retrieves Regions completed successfully return(retrievalResults.Items.Cast <Region>().ToArray()); } } catch (Exception Ex) { throw new Exception(Ex.Message); } }
// Returns all Service Time Types from the select region public static ServiceTimeType[] RetreiveServiceTimeTypes() { try { // Call the Web Services RetrievalResults retrievalResults = QueryServiceClient.Retrieve( SessionHeader, RegionContext, new RetrievalOptions { PropertyInclusionMode = PropertyInclusionMode.All, Type = "ServiceTimeType" }); // Checks if the process returned a valid result if (retrievalResults.Items == null) { throw new Exception("Retrieve Service Windows Types failed."); } else if (retrievalResults.Items.Length == 0) { throw new Exception("No Service Widnows Type found for selected Region."); } else { // Retrieves Service Location completed successfully return(retrievalResults.Items.Cast <ServiceTimeType>().ToArray()); } } catch (Exception Ex) { throw new Exception(Ex.Message); } }
// Returns all Routing Sessions from the selected Region public static DailyRoutingSession[] RetrieveRouteSessions() { try { // Call the Web Services RetrievalResults retrievalResults = QueryServiceClient.Retrieve( SessionHeader, RegionContext, new RetrievalOptions { PropertyInclusionMode = PropertyInclusionMode.All, Type = "DailyRoutingSession" }); // Checks if the process returned a valid result if (retrievalResults.Items == null) { throw new Exception("Retrieve Route Sessions failed."); } else if (retrievalResults.Items.Length == 0) { throw new Exception("No Route Sessions found for the select user."); } else { // Retrieves Route Sessions completed successfully return(retrievalResults.Items.Cast <DailyRoutingSession>().ToArray()); } } catch (Exception Ex) { throw new Exception(Ex.Message); } }
// Searchs the Depot Name public static string[] SearchDepot(long depotEntityKey) { string[] r = new string[4]; // Means: No depot found. r[0] = "NOT FOUND"; // Name r[1] = "0.0000"; // Lat r[2] = "0.0000"; // Lon r[3] = "DEPOT ADDRESS NOT FOUND"; // Address // End try { // Call the Web Services RetrievalResults retrievalResults = QueryServiceClient.Retrieve( SessionHeader, RegionContext, new RetrievalOptions { PropertyInclusionMode = PropertyInclusionMode.All, Type = "Depot" }); // Checks if the process returned a valid result if (retrievalResults.Items != null | retrievalResults.Items.Length > 0) { // Loads all Depots into an array Depot[] Depots = retrievalResults.Items.Cast <Depot>().ToArray(); // Finds the Depot by EntityKey foreach (Depot depot in Depots) { if (depot.EntityKey == depotEntityKey) // Depot Found { r[0] = depot.Identifier; r[1] = depot.Address.AddressLine1 + ", " + depot.Address.Locality.AdminDivision3 + ", " // City + depot.Address.Locality.AdminDivision1 + ", " // State + depot.Address.Locality.PostalCode; r[2] = (depot.Coordinate.Latitude * 0.000001).ToString(); r[3] = (depot.Coordinate.Longitude * 0.000001).ToString(); // Exit loop break; } } } return(r); } catch (Exception Ex) { throw new Exception(Ex.Message); } }
// Returns all Service Order from the selected Route Session public static Order[] RetrieveServiceOrders(long sessionEntityKey) { try { // Call the Web Services RetrievalResults retrievalResults = QueryServiceClient.Retrieve( SessionHeader, RegionContext, new RetrievalOptions { Expression = new AndExpression { Expressions = new SimpleExpressionBase[] { new EqualToExpression { Left = new PropertyExpression { Name = "SessionEntityKey" }, Right = new ValueExpression { Value = sessionEntityKey } } } }, PropertyInclusionMode = PropertyInclusionMode.All, Type = "Order" }); // Checks if the process returned a valid result if (retrievalResults.Items == null) { throw new Exception("Retrieve Service Orders failed."); } else if (retrievalResults.Items.Length == 0) { throw new Exception("No Service Orders found for the Route Session " + sessionEntityKey.ToString() + "."); } else { // Retrieves Service Orders completed successfully return(retrievalResults.Items.Cast <Order>().ToArray()); } } catch (Exception Ex) { throw new Exception(Ex.Message); } }
private void RetrieveRegions(QueryServiceClient queryServiceClient) { List <Region> tempRegionList = new List <Region>(); WSU.MainServiceLogger.Info("Retrieve Regions."); foreach (long businessUnit in Config.BUSINESS_UNIT_ENTITY_KEY_FILTER) { RetrievalResults retrievalResults = queryServiceClient.Retrieve( SessionHeader, new MultipleRegionContext { BusinessUnitEntityKey = businessUnit, Mode = MultipleRegionMode.All }, new RetrievalOptions { PropertyInclusionMode = PropertyInclusionMode.All, Type = "Region" }); if (retrievalResults.Items == null) { throw new Exception("Retrieve Regions failed with a null result."); } else if (retrievalResults.Items.Length == 0) { throw new Exception("No Regions exist."); } else { tempRegionList.AddRange(retrievalResults.Items.Cast <Region>().OrderBy(region => region.Identifier).ToList()); } } if (tempRegionList.Any()) { WSU.MainServiceLogger.Debug("Retrieve Regions completed successfully."); Regions = tempRegionList.OrderBy(region => region.Identifier).ToList(); BusinessUnitEntityKeys = Regions.Select(region => region.BusinessUnitEntityKey).Distinct().ToList(); WSU.MainServiceLogger.Info(Config.BUSINESS_UNIT_ENTITY_KEY_FILTER.Length == 0 ? "Business Unit Entity Key Filter disabled. Use all Business Units." : ("Only use Business Units: " + string.Join(", ", Config.BUSINESS_UNIT_ENTITY_KEY_FILTER))); if (Config.BUSINESS_UNIT_ENTITY_KEY_FILTER.Length > 0) { List <long> invalidFilters = Config.BUSINESS_UNIT_ENTITY_KEY_FILTER.ToList(); invalidFilters.RemoveAll(filter => BusinessUnitEntityKeys.Contains(filter)); if (invalidFilters.Count > 0) { WSU.MainServiceLogger.Warn("Business Unit Entity Key Filter contains invalid entries: " + string.Join(", ", invalidFilters)); } WSU.MainServiceLogger.Debug("Applying Business Unit Entity Key Filter."); BusinessUnitEntityKeys.RemoveAll(entityKey => !Config.BUSINESS_UNIT_ENTITY_KEY_FILTER.Contains(entityKey)); if (BusinessUnitEntityKeys.Count == 0) { throw new Exception("No valid Business Units specified."); } Regions.RemoveAll(region => !Config.BUSINESS_UNIT_ENTITY_KEY_FILTER.Contains(region.BusinessUnitEntityKey)); } NotificationRegionIdentifiers = Regions.Select(region => new KeyValuePair <long, string>(region.EntityKey, region.Identifier)).ToList(); string[] regionIdentifiers = Regions.Select(region => region.Identifier).ToArray(); WSU.MainServiceLogger.Debug("Regions list contains: " + string.Join(", ", regionIdentifiers)); WSU.MainServiceLogger.Info(Config.REGION_FILTER.Length == 0 ? "Region Filter disabled. Use all Regions." : (Config.REGION_FILTER.Length == 1 && Config.REGION_FILTER[0] == "NONE" ? "All Regions disabled." : ("Only use Regions: " + string.Join(", ", Config.REGION_FILTER)))); if (Config.REGION_FILTER.Length == 1 && Config.REGION_FILTER[0] == "NONE") { Regions.Clear(); } else if (Config.REGION_FILTER.Length > 0) { List <string> invalidFilters = Config.REGION_FILTER.ToList(); invalidFilters.RemoveAll(filter => regionIdentifiers.Contains(filter)); if (invalidFilters.Count > 0) { WSU.MainServiceLogger.Warn("Region Filter contains invalid entries: " + string.Join(", ", invalidFilters)); } WSU.MainServiceLogger.Debug("Applying Region Filter."); Regions.RemoveAll(region => !Config.REGION_FILTER.Contains(region.Identifier)); if (Regions.Count == 0) { throw new Exception("No valid Regions specified."); } } if (Config.ENABLE_NOTIFICATIONS_PROCESS) { if (Config.NOTIFICATION_REGION_FILTER.Length == 0) { WSU.MainServiceLogger.Info("Notification Region Filter disabled. Use all Regions."); } else { WSU.MainServiceLogger.Info("For Notifications, only use Regions: " + string.Join(", ", Config.NOTIFICATION_REGION_FILTER)); List <string> invalidFilters = Config.NOTIFICATION_REGION_FILTER.ToList(); invalidFilters.RemoveAll(filter => regionIdentifiers.Contains(filter)); if (invalidFilters.Count > 0) { WSU.MainServiceLogger.Warn("Notification Region Filter contains invalid entries: " + string.Join(", ", invalidFilters)); } WSU.MainServiceLogger.Debug("Applying Notification Region Filter."); NotificationRegionIdentifiers.RemoveAll(pair => !Config.NOTIFICATION_REGION_FILTER.Contains(pair.Value)); if (NotificationRegionIdentifiers.Count == 0) { throw new Exception("No valid Notification Regions specified."); } } } } }