Esempio n. 1
0
        public object GetPlanElements(string planUniqueName, long planInstanceId, string elementPath, SerializationType serializationType = SerializationType.Json, bool setContentType = true)
        {
            InitPlanServer();

            string context = GetContext(nameof(GetPlanStatus),
                                        nameof(planUniqueName), planUniqueName, nameof(planInstanceId), planInstanceId,
                                        nameof(elementPath), elementPath, nameof(serializationType), serializationType);

            try
            {
                SynapseServer.Logger.Debug(context);

                PlanElementParms pep = new PlanElementParms {
                    Type = serializationType
                };
                pep.ElementPaths.Add(elementPath);

                object result = _server.GetPlanElements(planUniqueName, planInstanceId, pep);

                if (setContentType)
                {
                    return(GetHttpResponse(result, serializationType));
                }
                else
                {
                    return(result);
                }
            }
            catch (Exception ex)
            {
                SynapseServer.Logger.Error(
                    Utilities.UnwindException(context, ex, asSingleLine: true));
                throw;
            }
        }
Esempio n. 2
0
        public object GetPlanElements(string planUniqueName, long planInstanceId, [FromBody] PlanElementParms elementParms)
        {
            InitPlanServer();

            string context = GetContext(nameof(GetPlanStatus),
                                        nameof(planUniqueName), planUniqueName, nameof(planInstanceId), planInstanceId);

            try
            {
                SynapseServer.Logger.Debug(context);
                return(_server.GetPlanElements(planUniqueName, planInstanceId, elementParms));
            }
            catch (Exception ex)
            {
                SynapseServer.Logger.Error(
                    Utilities.UnwindException(context, ex, asSingleLine: true));
                throw;
            }
        }
Esempio n. 3
0
        public object GetPlanElements(string planUniqueName, long planInstanceId, string elementPath, SerializationType serializationType = SerializationType.Json, bool setContentType = true)
        {
            InitPlanServer();

            string context = GetContext(nameof(GetPlanStatus),
                                        nameof(planUniqueName), planUniqueName, nameof(planInstanceId), planInstanceId,
                                        nameof(elementPath), elementPath, nameof(serializationType), serializationType);

            try
            {
                SynapseServer.Logger.Debug(context);

                PlanElementParms pep = new PlanElementParms();
                pep.Type = serializationType;
                pep.ElementPaths.Add(elementPath);

                object result = _server.GetPlanElements(planUniqueName, planInstanceId, pep);

                if (setContentType)
                {
                    Encoding encoding = serializationType == SerializationType.Xml ? Encoding.Unicode : Encoding.UTF8;
                    netHttp.HttpResponseMessage response = new netHttp.HttpResponseMessage(System.Net.HttpStatusCode.OK);
                    response.Content = new netHttp.StringContent(GetStringContent(result, serializationType),
                                                                 encoding, SerializationContentType.GetContentType(serializationType));
                    return(response);
                }
                else
                {
                    return(result);
                }
            }
            catch (Exception ex)
            {
                SynapseServer.Logger.Error(
                    Utilities.UnwindException(context, ex, asSingleLine: true));
                throw;
            }
        }
        public async Task <object> GetPlanElementsAsync(string planUniqueName, long planInstanceId, PlanElementParms elementParms)
        {
            string requestUri = $"{_rootPath}/{planUniqueName}/{planInstanceId}/part/";

            return(await PostAsync <PlanElementParms, object>(elementParms, requestUri));
        }
 public object GetPlanElements(string planUniqueName, long planInstanceId, PlanElementParms elementParms)
 {
     return(GetPlanElementsAsync(planUniqueName, planInstanceId, elementParms).Result);
 }
Esempio n. 6
0
        public object GetPlanElements(string planUniqueName, long planInstanceId, PlanElementParms elementParms)
        {
            Plan   plan   = GetPlanStatus(planUniqueName, planInstanceId);
            object result = YamlHelpers.SelectElements(plan, elementParms.ElementPaths);

            List <object> results = new List <object>();

            if (result is List <object> )
            {
                result = (List <object>)result;
            }
            else
            {
                results.Add(result);
            }

            for (int i = 0; i < results.Count; i++)
            {
                if (results[i] != null)
                {
                    switch (elementParms.Type)
                    {
                    case SerializationType.Yaml:
                    {
                        string yaml = results[i] is Dictionary <object, object>?
                                      YamlHelpers.Serialize(results[i]) : results[i].ToString();

                        try { results[i] = YamlHelpers.Deserialize(yaml); }
                        catch { results[i] = yaml; }
                        break;
                    }

                    case SerializationType.Json:
                    {
                        string json = results[i] is Dictionary <object, object>?
                                      YamlHelpers.Serialize(results[i], serializeAsJson : true) : results[i].ToString();

                        try { results[i] = Newtonsoft.Json.Linq.JObject.Parse(json); }
                        catch { results[i] = json; }
                        break;
                    }

                    case SerializationType.Xml:
                    {
                        try
                        {
                            System.Xml.XmlDocument xml = new System.Xml.XmlDocument();
                            xml.LoadXml(results[i].ToString());
                            results[i] = xml;
                        }
                        catch { }
                        break;
                    }

                    case SerializationType.Html:
                    case SerializationType.Unspecified:
                    {
                        //no-op
                        //results[i] = results[i].ToString();
                        break;
                    }
                    }
                }
            }

            if (results.Count == 1)
            {
                return(results[0]);
            }
            else
            {
                return(results);
            }
        }