Пример #1
0
        public IActionResult FlowRoutes(FlowData flowData)
        {
            try
            {
                var jsonRoutes = JObject.Parse(flowData.routes);

                var jsonRoutesList = jsonRoutes["routes"].ToList <JToken>();

                var newJObject = new JObject();

                foreach (var attribute in jsonRoutesList)
                {
                    newJObject.Add(attribute);
                }

                var twinCollection = new TwinCollection(newJObject, new JObject());

                dynamic routes = twinCollection;

                var extraModules = !string.IsNullOrEmpty(flowData.extraModules)
                                        ? flowData.extraModules.Split(',', StringSplitOptions.RemoveEmptyEntries)
                                        : new string[0];

                return(CreatedAtRoute(routes, extraModules));
            }
            catch (Exception)
            {
                Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
                return(new JsonResult(null));
            }
        }
Пример #2
0
        public IActionResult Flow(FlowData flowData)
        {
            try
            {
                var connectionString = flowData.cs;

                var registryManager = RegistryManager.CreateFromConnectionString(connectionString);

                var twin = registryManager.GetTwinAsync(flowData.dn, "$edgeHub").Result;

                var desired = twin.Properties.Desired;

                var routes = desired["routes"];

                var extraModules = !string.IsNullOrEmpty(flowData.extraModules)
                        ? flowData.extraModules.Split(',', StringSplitOptions.RemoveEmptyEntries)
                        : new string[0];

                return(CreatedAtRoute(routes, extraModules));
            }
            catch (Exception)
            {
                Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
                return(new JsonResult(null));
            }
        }
Пример #3
0
        public IActionResult Flow(FlowData a)
        {
            try
            {
                dynamic routes;
                if (a.routes != null)
                {
                    JObject jsonRoutes     = JObject.Parse(a.routes);
                    var     jsonRoutesList = jsonRoutes["routes"].ToList <JToken>();
                    JObject newJObject     = new JObject();
                    foreach (var attribute in jsonRoutesList)
                    {
                        newJObject.Add(attribute);
                    }
                    TwinCollection twinCollection = new TwinCollection(newJObject, new JObject());
                    routes = twinCollection;
                }

                else
                {
                    var connectionString = a.cs;

                    var registryManager = RegistryManager.CreateFromConnectionString(connectionString);

                    var twin = registryManager.GetTwinAsync(a.dn, "$edgeHub").Result;

                    var desired = twin.Properties.Desired;

                    routes = desired["routes"];
                }

                List <Route> routeList = ExtractEdgeHubRoutes(routes);

                List <Module> moduleList = ExtractRoutes(routeList);

                var jsonObject = ConstructFlowChart(routeList, moduleList);

                return(new JsonResult(jsonObject));
            }
            catch (Exception)
            {
                Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
                return(new JsonResult(null));
            }
        }