public static void Publish(this BO.GPSLocation @this)
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("GPSLocation", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "Publish")) {
         zAppDev.DotNet.Framework.Utilities.Serializer <DSS3_LogisticsPoolingForUrbanDistribution.BO.GPSLocation> gps = new zAppDev.DotNet.Framework.Utilities.Serializer <DSS3_LogisticsPoolingForUrbanDistribution.BO.GPSLocation>();
         string gpsjson   = gps.ToJson(@this, false);
         string base64gps = zAppDev.DotNet.Framework.Utilities.Common.Base64Encode(gpsjson);
         System.Collections.Generic.List <DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage> message = new System.Collections.Generic.List <DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage>();
         DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage mes1 = new DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage();
         DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage mes2 = new DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage();
         DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage mes3 = new DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage();
         mes1.type = "string"; mes1.val = "truck_location"; mes1.key = "topic"; mes2.type = "string"; mes2.val = (@this?.truck_license_plate ?? ""); mes2.key = "truck_location"; mes3.type = "string"; mes3.val = base64gps; mes3.key = "payload"; message?.Add(mes1);
         message?.Add(mes2);
         message?.Add(mes3);
         DSS3_LogisticsPoolingForUrbanDistribution.ExternalStructs.LocalPubSub.Publication publication = new DSS3_LogisticsPoolingForUrbanDistribution.ExternalStructs.LocalPubSub.Publication();
         System.Collections.Generic.List <DSS3_LogisticsPoolingForUrbanDistribution.ExternalStructs.LocalPubSub.PubMessage> apisPubMessage = new System.Collections.Generic.List <DSS3_LogisticsPoolingForUrbanDistribution.ExternalStructs.LocalPubSub.PubMessage>();
         foreach (var pubs in message ?? Enumerable.Empty <DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage>())
         {
             DSS3_LogisticsPoolingForUrbanDistribution.ExternalStructs.LocalPubSub.PubMessage pubMessage = (new DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessageDataTransformation.Transformer()).PubMessage_To_PubMessage(pubs);
             apisPubMessage.Add(pubMessage);
         }
         publication.publication = apisPubMessage.ToArray(); DSS3_LogisticsPoolingForUrbanDistribution.BLL.ExternalRestServices.LocalPubSubRestService.Publish(publication);
     }
 }
 public static void DeserializeMessage(string json)
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("Utils", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "DeserializeMessage")) {
         try {
             zAppDev.DotNet.Framework.Utilities.Serializer <System.Collections.Generic.List <DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage> > ser = new zAppDev.DotNet.Framework.Utilities.Serializer <System.Collections.Generic.List <DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage> >();
             zAppDev.DotNet.Framework.Utilities.Serializer <DSS3_LogisticsPoolingForUrbanDistribution.BO.OrderDTO> ord     = new zAppDev.DotNet.Framework.Utilities.Serializer <DSS3_LogisticsPoolingForUrbanDistribution.BO.OrderDTO>();
             System.Collections.Generic.List <DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage>             kvpairs = ser.FromJson(json);
             zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Warning, "Utils", DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseDebugMessage, "Starting message parsing... JSON contains " + (kvpairs?.Count() ?? 0) + " objects");
             foreach (var mes in kvpairs ?? Enumerable.Empty <DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage>())
             {
                 if ((mes?.key == "sarmed_order" && int.Parse((mes?.val ?? "")) > 0))
                 {
                     zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Warning, "Utils", DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseDebugMessage, "Order received!");
                     DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage payload = kvpairs?.FirstOrDefault((x) => x.key == "payload");
                     string orderjson = zAppDev.DotNet.Framework.Utilities.Common.Base64Decode((payload?.val ?? ""));
                     DSS3_LogisticsPoolingForUrbanDistribution.BO.OrderDTO tempDTO = ord.FromJson(orderjson);
                     DSS3_LogisticsPoolingForUrbanDistribution.BO.OrderWMS temp = (new DSS3_LogisticsPoolingForUrbanDistribution.BO.OrderTransformationDataTransformation.Transformer()).OrderWMS_To_OrderDTOReversed(tempDTO);
                     var _var0 = temp?.OrdID; DSS3_LogisticsPoolingForUrbanDistribution.BO.OrderWMS tempord = new DSS3_LogisticsPoolingForUrbanDistribution.DAL.Repository().GetAsQueryable <DSS3_LogisticsPoolingForUrbanDistribution.BO.OrderWMS>((x) => x.OrdID == _var0)?.FirstOrDefault();
                     if ((tempord != null))
                     {
                         zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Warning, "Utils", DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseDebugMessage, "Order found in database. Updating...");
                         tempord?.CopyFields(temp);
                         if ((tempord?.OrdRoutingStatus == 30))
                         {
                             tempord.ATA = DateTime.UtcNow; System.Collections.Generic.List <string> roles = new System.Collections.Generic.List <string>();
                             foreach (var role in zAppDev.DotNet.Framework.Identity.IdentityHelper.GetCurrentApplicationUser()?.Roles ?? Enumerable.Empty <zAppDev.DotNet.Framework.Identity.Model.ApplicationRole>())
                             {
                                 roles.Add((role?.Name ?? ""));
                             }
                             tempord.OrdStatus = 30; new DSS3_LogisticsPoolingForUrbanDistribution.DAL.Repository().Update <DSS3_LogisticsPoolingForUrbanDistribution.BO.OrderWMS>(tempord);
                             DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseSaveOrder((tempord?.OrdID ?? 0), roles.ToArray());
                         }
                         else
                         {
                             new DSS3_LogisticsPoolingForUrbanDistribution.DAL.Repository().Save <DSS3_LogisticsPoolingForUrbanDistribution.BO.OrderWMS>(tempord);
                             System.Collections.Generic.List <string> roles = new System.Collections.Generic.List <string>();
                             foreach (var role in zAppDev.DotNet.Framework.Identity.IdentityHelper.GetCurrentApplicationUser()?.Roles ?? Enumerable.Empty <zAppDev.DotNet.Framework.Identity.Model.ApplicationRole>())
                             {
                                 roles.Add((role?.Name ?? ""));
                             }
                             DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseUpdateDatasets((tempord?.Id ?? 0), roles.ToArray());
                         }
                     }
                     else
                     {
                         zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Info, "Utils", DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseDebugMessage, "New order received!");
                         if ((temp?.OrdRoutingStatus == 30))
                         {
                             temp.ATA = DateTime.UtcNow;
                         }
                         new DSS3_LogisticsPoolingForUrbanDistribution.DAL.Repository().Save <DSS3_LogisticsPoolingForUrbanDistribution.BO.OrderWMS>(temp);
                     }
                     zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Warning, "Utils", DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseDebugMessage, "Order saved successfully.");
                     zAppDev.DotNet.Framework.Data.MiniSessionManager.Instance.Session.Flush();
                     if ((temp?.OrdRoutingStatus == 20))
                     {
                         DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseOrderStarted((temp?.OrdID ?? 0), (temp?.OrdVchPlateNr ?? ""));
                     }
                     else if ((temp?.OrdRoutingStatus == 30))
                     {
                         DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseOrderFinished((temp?.OrdID ?? 0));
                     }
                     else
                     {
                         System.Collections.Generic.List <string> roles = new System.Collections.Generic.List <string>();
                         foreach (var role in zAppDev.DotNet.Framework.Identity.IdentityHelper.GetCurrentApplicationUser()?.Roles ?? Enumerable.Empty <zAppDev.DotNet.Framework.Identity.Model.ApplicationRole>())
                         {
                             roles.Add((role?.Name ?? ""));
                         }
                         DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseOnOrderReceive((temp?.OrdID ?? 0), (temp?.Warehouse ?? ""), (temp?.OrdDlsCity ?? ""), (temp?.OrdAgencyDescr ?? ""), roles.ToArray());
                     }
                 }
                 else if ((mes?.key == "truck_location"))
                 {
                     zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Info, "Utils", DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseDebugMessage, "Truck location received!");
                     DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage payload = kvpairs?.FirstOrDefault((x) => x.key == "payload");
                     string gpsjson = zAppDev.DotNet.Framework.Utilities.Common.Base64Decode((payload?.val ?? ""));
                     zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Info, "Utils", DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseDebugMessage, "gps data " + gpsjson);
                     zAppDev.DotNet.Framework.Utilities.Serializer <DSS3_LogisticsPoolingForUrbanDistribution.BO.GPSLocation> gps = new zAppDev.DotNet.Framework.Utilities.Serializer <DSS3_LogisticsPoolingForUrbanDistribution.BO.GPSLocation>();
                     DSS3_LogisticsPoolingForUrbanDistribution.BO.GPSLocation temp = gps.FromJson(gpsjson);
                     DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseOnGPSReceive((temp?.truck_license_plate ?? ""), (temp?.latitude?.ToString() ?? ""), (temp?.longitude?.ToString() ?? ""));
                 }
                 else if ((mes?.key == "sarmed_truck_recommendation" && int.Parse((mes?.val ?? "")) > 0))
                 {
                     DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage payload = kvpairs?.FirstOrDefault((x) => x.key == "payload");
                     string truckRec = zAppDev.DotNet.Framework.Utilities.Common.Base64Decode((payload?.val ?? ""));
                     zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Info, "Utils", DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseDebugMessage, "TruckRec " + truckRec);
                     zAppDev.DotNet.Framework.Utilities.Serializer <DSS3_LogisticsPoolingForUrbanDistribution.ExternalStructs.DisruptionAPI.TrucksRecommended> truckSer = new zAppDev.DotNet.Framework.Utilities.Serializer <DSS3_LogisticsPoolingForUrbanDistribution.ExternalStructs.DisruptionAPI.TrucksRecommended>();
                     DSS3_LogisticsPoolingForUrbanDistribution.ExternalStructs.DisruptionAPI.TrucksRecommended truck = truckSer.FromJson(truckRec);
                     System.Collections.Generic.List <string> roles = new System.Collections.Generic.List <string>();
                     foreach (var role in zAppDev.DotNet.Framework.Identity.IdentityHelper.GetCurrentApplicationUser()?.Roles ?? Enumerable.Empty <zAppDev.DotNet.Framework.Identity.Model.ApplicationRole>())
                     {
                         roles.Add((role?.Name ?? ""));
                     }
                     DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseOnNTUARecommendationReceive(truck.order_id, zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(truck.trucks_recommended, 0), roles.ToArray());
                 }
                 else if ((mes?.key == "sarmed_truck_eta"))
                 {
                     DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage payload = kvpairs?.FirstOrDefault((x) => x.key == "payload");
                     string trucketa = zAppDev.DotNet.Framework.Utilities.Common.Base64Decode((payload?.val ?? ""));
                     zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Info, "Utils", DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseDebugMessage, "Truck eta mess " + trucketa);
                     zAppDev.DotNet.Framework.Utilities.Serializer <DSS3_LogisticsPoolingForUrbanDistribution.BO.truck_eta> truckSer = new zAppDev.DotNet.Framework.Utilities.Serializer <DSS3_LogisticsPoolingForUrbanDistribution.BO.truck_eta>();
                     DSS3_LogisticsPoolingForUrbanDistribution.BO.truck_eta truck = truckSer.FromJson(trucketa);
                     var _var1 = truck?.order_id; DSS3_LogisticsPoolingForUrbanDistribution.BO.OrderWMS orderETA = new DSS3_LogisticsPoolingForUrbanDistribution.DAL.Repository().GetAsQueryable <DSS3_LogisticsPoolingForUrbanDistribution.BO.OrderWMS>((ordETA) => ordETA.OrdID == _var1)?.FirstOrDefault();
                     DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseOnETAReceived((truck?.truck_license_plate ?? ""), (truck?.eta ?? System.Data.SqlTypes.SqlDateTime.MinValue.Value), (truck?.order_id ?? 0));
                 }
                 else if ((mes?.key == "sarmed_truck_emissions"))
                 {
                     DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage payload = kvpairs?.FirstOrDefault((x) => x.key == "payload");
                     string truckemiss = zAppDev.DotNet.Framework.Utilities.Common.Base64Decode((payload?.val ?? ""));
                     zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Info, "Utils", DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseDebugMessage, "co2 " + truckemiss);
                     zAppDev.DotNet.Framework.Utilities.Serializer <DSS3_LogisticsPoolingForUrbanDistribution.BO.truck_emission> truckSer = new zAppDev.DotNet.Framework.Utilities.Serializer <DSS3_LogisticsPoolingForUrbanDistribution.BO.truck_emission>();
                     DSS3_LogisticsPoolingForUrbanDistribution.BO.truck_emission truck = truckSer.FromJson(truckemiss);
                     var   _var2 = truck?.truck_license_plate; DSS3_LogisticsPoolingForUrbanDistribution.BO.OrderWMS orderCOE = new DSS3_LogisticsPoolingForUrbanDistribution.DAL.Repository().GetAsQueryable <DSS3_LogisticsPoolingForUrbanDistribution.BO.OrderWMS>((ordco) => ordco.OrdVchPlateNr == _var2 && ordco.OrdRoutingStatus == 20)?.FirstOrDefault();
                     float?co2em = float.Parse((truck?.co2_emission ?? ""), System.Globalization.NumberStyles.Number | System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
                     co2em = co2em.GetValueOrDefault(0) / 1000; truck.co2_emission = (co2em?.ToString() ?? ""); DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseOnCO2Received((truck?.truck_license_plate ?? ""), (truck?.co2_emission ?? ""));
                 }
                 else if ((mes?.key == "sarmed_truck_delivery_time"))
                 {
                     DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage payload = kvpairs?.FirstOrDefault((x) => x.key == "payload");
                     string truckAVGtime = zAppDev.DotNet.Framework.Utilities.Common.Base64Decode((payload?.val ?? ""));
                     zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Info, "Utils", DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseDebugMessage, "avg time " + truckAVGtime);
                     zAppDev.DotNet.Framework.Utilities.Serializer <DSS3_LogisticsPoolingForUrbanDistribution.BO.AVGTime> avgSer = new zAppDev.DotNet.Framework.Utilities.Serializer <DSS3_LogisticsPoolingForUrbanDistribution.BO.AVGTime>();
                     DSS3_LogisticsPoolingForUrbanDistribution.BO.AVGTime avg = avgSer.FromJson(truckAVGtime);
                     new DSS3_LogisticsPoolingForUrbanDistribution.DAL.Repository().Save <DSS3_LogisticsPoolingForUrbanDistribution.BO.AVGTime>(avg);
                 }
             }
         }
         catch (System.Exception x) {
             zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Error, "Utils", DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseDebugMessage, x);
         }
     }
 }
예제 #3
0
 public static void Publish(this BO.OrderWMS @this)
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("OrderWMS", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "Publish")) {
         zAppDev.DotNet.Framework.Utilities.Serializer <DSS3_LogisticsPoolingForUrbanDistribution.BO.OrderDTO> ord = new zAppDev.DotNet.Framework.Utilities.Serializer <DSS3_LogisticsPoolingForUrbanDistribution.BO.OrderDTO>();
         DSS3_LogisticsPoolingForUrbanDistribution.BO.OrderDTO ordDTO = (new DSS3_LogisticsPoolingForUrbanDistribution.BO.OrderTransformationDataTransformation.Transformer()).OrderWMS_To_OrderDTO(@this);
         string order    = ord.ToJson(ordDTO);
         string encorder = zAppDev.DotNet.Framework.Utilities.Common.Base64Encode(order);
         System.Collections.Generic.List <DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage> message = new System.Collections.Generic.List <DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage>();
         DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage mes1 = new DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage();
         DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage mes2 = new DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage();
         DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage mes3 = new DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage();
         mes1.type = "string"; mes1.val = "sarmed_order"; mes1.key = "topic"; mes2.type = "int"; mes2.val = "1"; mes2.key = "sarmed_order"; mes3.type = "string"; mes3.val = encorder; mes3.key = "payload"; message?.Add(mes1);
         message?.Add(mes2);
         message?.Add(mes3);
         DSS3_LogisticsPoolingForUrbanDistribution.ExternalStructs.LocalPubSub.Publication publication = new DSS3_LogisticsPoolingForUrbanDistribution.ExternalStructs.LocalPubSub.Publication();
         System.Collections.Generic.List <DSS3_LogisticsPoolingForUrbanDistribution.ExternalStructs.LocalPubSub.PubMessage> apisPubMessage = new System.Collections.Generic.List <DSS3_LogisticsPoolingForUrbanDistribution.ExternalStructs.LocalPubSub.PubMessage>();
         foreach (var pubs in message ?? Enumerable.Empty <DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessage>())
         {
             DSS3_LogisticsPoolingForUrbanDistribution.ExternalStructs.LocalPubSub.PubMessage pubMessage = (new DSS3_LogisticsPoolingForUrbanDistribution.BO.PubMessageDataTransformation.Transformer()).PubMessage_To_PubMessage(pubs);
             apisPubMessage.Add(pubMessage);
         }
         publication.publication = apisPubMessage.ToArray(); DSS3_LogisticsPoolingForUrbanDistribution.BLL.ExternalRestServices.LocalPubSubRestService.Publish(publication);
     }
 }
예제 #4
0
 public static DSS1_RetailerDriverStockOptimisation.ExternalStructs.Elasticsearch.Must GetQueryStringQuery(string q)
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("MakeRequest", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "GetQueryStringQuery")) {
         DSS1_RetailerDriverStockOptimisation.ExternalStructs.Elasticsearch.Must must = new DSS1_RetailerDriverStockOptimisation.ExternalStructs.Elasticsearch.Must();
         if (((q == null || q == "")))
         {
             zAppDev.DotNet.Framework.Utilities.Serializer <DSS1_RetailerDriverStockOptimisation.ExternalStructs.Elasticsearch.MatchAll> serializer = new zAppDev.DotNet.Framework.Utilities.Serializer <DSS1_RetailerDriverStockOptimisation.ExternalStructs.Elasticsearch.MatchAll>();
             must.match_all = serializer.FromJson("{\"must\": {\"match_all\": {}}");
         }
         else
         {
             DSS1_RetailerDriverStockOptimisation.ExternalStructs.Elasticsearch.QueryString queryString = new DSS1_RetailerDriverStockOptimisation.ExternalStructs.Elasticsearch.QueryString();
             queryString.AnalyzeWildcard = true; queryString.Query = q; must.QueryString = queryString;
         }
         return(must);
     }
 }
        public static object InnerConsume <T>(RestServiceConsumptionOptions options, string serviceName, int retries,
                                              ServiceConsumptionContainer resultBag)
        {
            OAuth2TokenData currentOAuth2TokenData = null;

            if (options.SecurityType == RestSecurityType.OAuth2)
            {
                currentOAuth2TokenData = GetOAuth2Token.GetAuthToken(options, serviceName, Utilities.Web.GetContext());
            }

            using (var client = GetHttpClient(options, currentOAuth2TokenData))
            {
                switch (options.Verb)
                {
                case RestHTTPVerb.GET:
                    resultBag.HttpResponseMessage = client.GetAsync("").Result;
                    break;

                case RestHTTPVerb.POST:

                    switch (options.PostType)
                    {
                    case PostType.JSON:
                        var jsonSerialized = new Utilities.Serializer <object>().ToJson(options.Data, false, options.IgnoreNullValues);
                        resultBag.HttpResponseMessage = client
                                                        .PostAsync("", new StringContent(jsonSerialized, Encoding.UTF8, "application/json"))
                                                        .Result;

                        if (!resultBag.HttpResponseMessage.IsSuccessStatusCode)
                        {
                            log4net.LogManager.GetLogger(typeof(RestServiceConsumer)).Error(jsonSerialized);
                        }
                        //response = client.PostAsJsonAsync("", options.Data).Result;
                        break;

                    case PostType.XML:
                        var xml         = new zAppDev.DotNet.Framework.Utilities.Serializer <object>().ToXml(options.Data, true);
                        var httpContent = new StringContent(xml, Encoding.UTF8, "application/xml");
                        resultBag.HttpResponseMessage = client.PostAsync("", httpContent).Result;
                        break;

                    default:
                        /*
                         *                                  HttpContent content
                         *                                      = new FormUrlEncodedContent(
                         *                                          ConvertNameValueCollectionToKeyValuePair(
                         *                                              HttpUtility.ParseQueryString(options.Data + "")));
                         *                                  response = client.PostAsync("", content).Result;
                         */
                        resultBag.HttpResponseMessage = client.PostAsync("", PrepareFormData(options)).Result;
                        //response = client.PostAsync("", options.Data).Result;
                        break;
                    }

                    /*var str = JsonConvert.SerializeObject(options.Data);
                     *
                     * var logger = LogManager.GetLogger(typeof (RestServiceConsumer));
                     * if (str == "\"" + options.Data + "\"")
                     * {
                     *
                     * logger.Debug("POSTing as FORM");
                     * logger.DebugFormat("because: {0} == {1}", str, "\"" + options.Data + "\"");
                     *
                     * HttpContent content
                     *  = new FormUrlEncodedContent(
                     *      ConvertNameValueCollectionToKeyValuePair(
                     *          HttpUtility.ParseQueryString(options.Data.ToString())));
                     * response = client.PostAsync("", content).Result;
                     * }
                     * else
                     * {
                     * logger.Debug("POSTing as JSON");
                     *
                     * response = client.PostAsJsonAsync("", options.Data).Result;
                     * }*/

                    break;

                case RestHTTPVerb.PUT:
#if NETFRAMEWORK
                    switch (options.PostType)
                    {
                    case PostType.JSON:
                        resultBag.HttpResponseMessage = client.PutAsJsonAsync("", options.Data).Result;
                        break;

                    case PostType.XML:
                        resultBag.HttpResponseMessage = client.PutAsXmlAsync("", options.Data).Result;
                        break;

                    default:
                        resultBag.HttpResponseMessage = client.PutAsync("", PrepareFormData(options)).Result;

                        break;
                    }
                    break;
#else
                    throw new NotImplementedException("InnerConsume not implement for .Net Core");
#endif
                case RestHTTPVerb.DELETE:
                    resultBag.HttpResponseMessage = client.DeleteAsync("").Result;
                    break;

                default:
                    throw new ApplicationException("Uknown Http Verb: " + options.Verb);
                }

                if (options.SecurityType == RestSecurityType.OAuth2 && resultBag.HttpResponseMessage.StatusCode == HttpStatusCode.Unauthorized && retries == 0)
                {
                    return(new OAuth2InvalidToken());
                }

                if (resultBag.HttpResponseMessage.IsSuccessStatusCode)
                {
                    var setCookieHeader =
                        resultBag.HttpResponseMessage.Headers.FirstOrDefault(a => a.Key?.ToLower() == "set-cookie");
                    if (Utilities.Web.GetContext() != null && setCookieHeader.Value != null && setCookieHeader.Value.Any())
                    {
                        Utilities.Web.GetContext().Items["ServiceAuthCookie"] = setCookieHeader;
                    }

                    options.Type = RestResultType.STRING;

                    string contentType = resultBag.HttpResponseMessage.Content.Headers.ContentType?.ToString()
                                         ??
                                         (resultBag.HttpResponseMessage.Content.Headers.ToList()
                                          .FirstOrDefault(a => a.Key.ToLower() == "content-type")
                                          .Value?.FirstOrDefault() ?? "");

                    if (contentType.Contains("/json"))
                    {
                        options.Type = RestResultType.JSON;
                    }
                    else if (contentType.Contains("/xml"))
                    {
                        options.Type = RestResultType.XML;
                    }

                    var stringResult = resultBag.HttpResponseMessage.Content.ReadAsStringAsync().Result;
                    if (typeof(T) == typeof(string))
                    {
                        return(stringResult);
                    }

                    try
                    {
                        switch (options.Type)
                        {
                        case RestResultType.STRING:
                            return(stringResult);

                        case RestResultType.JSON:
                            return(JsonConvert.DeserializeObject <T>(stringResult));

                        case RestResultType.XML:
                            using (var stringReader = new StringReader(stringResult))
                            {
                                var serializer = new XmlSerializer(typeof(T));
                                return((T)serializer.Deserialize(stringReader));
                            }

                        default:
                            log4net.LogManager.GetLogger(typeof(RestServiceConsumer))
                            .Warn($"Don't know how to convert response to type: {options.Type}");
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        log4net.LogManager.GetLogger(typeof(RestServiceConsumer))
                        .Error($"Could not deserialize to type: {options.Type}, returning raw string!", e);

                        return(stringResult);
                    }


                    /*switch (options.Type)
                     * {
                     *  case RestResultType.STRING:
                     *      return response.Content.ReadAsStringAsync().Result;
                     *  case RestResultType.JSON:
                     *      object convertedJson;
                     *      var stream = response.Content.ReadAsStreamAsync().Result;
                     *      try
                     *      {
                     *          convertedJson = response.Content.ReadAsAsync<T>().Result;
                     *      }
                     *      catch
                     *      {
                     *          stream.Seek(0, SeekOrigin.Begin);
                     *          convertedJson = response.Content.ReadAsAsync<string>().Result;
                     *      }
                     *      return convertedJson;
                     *  case RestResultType.XML:
                     *      var s = response.Content.ReadAsStringAsync().Result;
                     *      if (typeof (T) == typeof (string))
                     *      {
                     *          return s;
                     *      }
                     *      var stringReader = new StringReader(s);
                     *      var serializer = new XmlSerializer(typeof (T));
                     *      return (T) serializer.Deserialize(stringReader);
                     *
                     * }*/
                    return(default(T));
                }


                throw new ApplicationException($"{(int)resultBag.HttpResponseMessage.StatusCode} ({resultBag.HttpResponseMessage.ReasonPhrase})");
            }
        }
예제 #6
0
 public static decimal?CalculatePathCost(this BO.Shipment @this, System.Collections.Generic.List <DSS3_LogisticsPoolingForUrbanDistribution.BO.ShippingOrder> Orders)
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("Shipment", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "CalculatePathCost")) {
         System.Collections.Generic.List <string> coordinates = new System.Collections.Generic.List <string>();
         coordinates.Add((@this?.DeparturePoint?.Coordinates?.CoordinateY ?? 0) + "," + (@this?.DeparturePoint?.Coordinates?.CoordinateX ?? 0));
         zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Error, "Shipment", DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseDebugMessage, coordinates.FirstOrDefault());
         foreach (var i in Orders ?? Enumerable.Empty <DSS3_LogisticsPoolingForUrbanDistribution.BO.ShippingOrder>())
         {
             string departure = (i?.DeparturePoint?.Coordinates?.CoordinateY ?? 0) + "," + (i?.DeparturePoint?.Coordinates?.CoordinateX ?? 0);
             string arrival   = (i?.ArrivalPoint?.Coordinates?.CoordinateY ?? 0) + "," + (i?.ArrivalPoint?.Coordinates?.CoordinateX ?? 0);
             if ((((coordinates.Contains(departure)) == false) && i?.DeparturePoint != @this?.FinalDestination))
             {
                 coordinates.Add(departure);
             }
             if ((((coordinates.Contains(arrival)) == false) && i?.ArrivalPoint != @this?.FinalDestination))
             {
                 coordinates.Add(arrival);
             }
         }
         string FinalCoordinate = (@this?.FinalDestination?.Coordinates?.CoordinateY ?? 0) + "," + (@this?.FinalDestination?.Coordinates?.CoordinateX ?? 0);
         coordinates.Add(FinalCoordinate);
         while ((coordinates.Contains("0,0")))
         {
             coordinates.Remove("0,0");
         }
         string coord = "";
         foreach (var i in coordinates ?? Enumerable.Empty <string>())
         {
             if (coord == "")
             {
                 coord = coord + i;
             }
             else
             {
                 coord = coord + "," + i;
             }
         }
         DSS3_LogisticsPoolingForUrbanDistribution.ExternalStructs.Router_Mapotempo.Router_MapotempoRoot response = DSS3_LogisticsPoolingForUrbanDistribution.BLL.ExternalRestServices.Router_MapotempoRestService.route("time", "true", "true", "true", "200", "EUR", "en", coord, "inlecom-1-pe3io4Ui5aimobich1oot0eilothongo");
         zAppDev.DotNet.Framework.Utilities.Serializer <DSS3_LogisticsPoolingForUrbanDistribution.ExternalStructs.Router_Mapotempo.Router_MapotempoRoot> serializer = new zAppDev.DotNet.Framework.Utilities.Serializer <DSS3_LogisticsPoolingForUrbanDistribution.ExternalStructs.Router_Mapotempo.Router_MapotempoRoot>();
         zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Info, "Shipment", DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseDebugMessage, serializer.ToJson(response));
         decimal?time         = (zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(response.features, 0)).properties.router.total_time / 3600;
         decimal?distance     = (zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(response.features, 0)).properties.router.total_distance / 1000;
         decimal?DistanceCost = distance.GetValueOrDefault(0) * (@this?.VehiculeType?.CalculatedDistanceCost ?? 0);
         decimal?TimeCost     = time.GetValueOrDefault(0) * (@this?.VehiculeType?.CalculatedTimeCost ?? 0);
         decimal?TotalCost    = new decimal?();
         if (@this?.VehiculeType?.AmortizationType1?.Label == "technical")
         {
             TotalCost = TimeCost.GetValueOrDefault(0) + DistanceCost.GetValueOrDefault(0) + (@this?.VehiculeType?.CalculatedOwnershipCost ?? 0) * distance.GetValueOrDefault(0);
         }
         else
         {
             TotalCost = TimeCost.GetValueOrDefault(0) + DistanceCost.GetValueOrDefault(0) + (@this?.VehiculeType?.CalculatedOwnershipCost ?? 0) * time.GetValueOrDefault(0);
         }
         TotalCost = TotalCost.GetValueOrDefault(0) * (1 + (@this?.VehiculeType?.OverHeadCost ?? 0) / 100); return(TotalCost);
     }
 }
 public static void ConsumeGoogleGeocode(this BO.MapPoint @this, string address)
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("MapPoint", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "ConsumeGoogleGeocode")) {
         DSS5_SupplyChainFinancialsOptimisation.ExternalStructs.GoogleGeocode.Root response = new DSS5_SupplyChainFinancialsOptimisation.ExternalStructs.GoogleGeocode.Root();
         try {
             response = DSS5_SupplyChainFinancialsOptimisation.BLL.ExternalRestServices.GoogleGeocodeRestService.GeoLocation(address);
         }
         catch (System.Exception x) {
             zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Error, "MapPoint", DSS5_SupplyChainFinancialsOptimisation.Hubs.EventsHub.RaiseDebugMessage, x);
             zAppDev.DotNet.Framework.Utilities.Serializer <DSS5_SupplyChainFinancialsOptimisation.ExternalStructs.GoogleGeocode.Root> ser = new zAppDev.DotNet.Framework.Utilities.Serializer <DSS5_SupplyChainFinancialsOptimisation.ExternalStructs.GoogleGeocode.Root>();
             zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Error, "MapPoint", DSS5_SupplyChainFinancialsOptimisation.Hubs.EventsHub.RaiseDebugMessage, "google geocode response " + ser.ToJson(response));
             throw x;
         }
         @this.Latitude = double.Parse(zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(response.results, 0).geometry.location.lat, System.Globalization.NumberStyles.Number | System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture); @this.Longitude = double.Parse(zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(response.results, 0).geometry.location.lng, System.Globalization.NumberStyles.Number | System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
     }
 }
예제 #8
0
 public static void InitAddressGeocoordinates()
 {
     using (new zAppDev.DotNet.Framework.Profiling.Profiler("RegionalAgent", zAppDev.DotNet.Framework.Profiling.AppDevSymbolType.ClassOperation, "InitAddressGeocoordinates")) {
         try {
             foreach (var ra in new DSS3_LogisticsPoolingForUrbanDistribution.DAL.Repository().GetAll <DSS3_LogisticsPoolingForUrbanDistribution.BO.RegionalAgent>() ?? Enumerable.Empty <DSS3_LogisticsPoolingForUrbanDistribution.BO.RegionalAgent>())
             {
                 DSS3_LogisticsPoolingForUrbanDistribution.BO.MapPoints mapPoint = new DSS3_LogisticsPoolingForUrbanDistribution.BO.MapPoints();
                 DSS3_LogisticsPoolingForUrbanDistribution.ExternalStructs.GoogleGeocode.Root response = DSS3_LogisticsPoolingForUrbanDistribution.BLL.ExternalRestServices.GoogleGeocodeRestService.GeoLocation((ra?.AgencyAddress ?? ""));
                 zAppDev.DotNet.Framework.Utilities.Serializer <DSS3_LogisticsPoolingForUrbanDistribution.ExternalStructs.GoogleGeocode.Root> ser = new zAppDev.DotNet.Framework.Utilities.Serializer <DSS3_LogisticsPoolingForUrbanDistribution.ExternalStructs.GoogleGeocode.Root>();
                 zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Info, "RegionalAgent", DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseDebugMessage, "google response " + ser.ToJson(response));
                 if ((response.results.Length == 0))
                 {
                     continue;
                 }
                 DSS3_LogisticsPoolingForUrbanDistribution.BO.GeoCoordinates addressCoordinates = new DSS3_LogisticsPoolingForUrbanDistribution.BO.GeoCoordinates();
                 addressCoordinates.Latitude = float.Parse(zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(response.results, 0).geometry.location.lat, System.Globalization.NumberStyles.Number | System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture); addressCoordinates.Longitude = float.Parse(zAppDev.DotNet.Framework.Utilities.Common.GetItemFromArray(response.results, 0).geometry.location.lng, System.Globalization.NumberStyles.Number | System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture); ra.AddressCoordinates = addressCoordinates; new DSS3_LogisticsPoolingForUrbanDistribution.DAL.Repository().Update <DSS3_LogisticsPoolingForUrbanDistribution.BO.RegionalAgent>(ra);
             }
         }
         catch (System.Exception x) {
             zAppDev.DotNet.Framework.Utilities.DebugHelper.Log(zAppDev.DotNet.Framework.Utilities.DebugMessageType.Error, "RegionalAgent", DSS3_LogisticsPoolingForUrbanDistribution.Hubs.EventsHub.RaiseDebugMessage, x);
         }
     }
 }