private ActiveDirectoryHandlerResults CallPlan(string planName, StartPlanEnvelope planEnvelope)
    {
        IExecuteController ec = GetExecuteControllerInstance();
        StartPlanEnvelope  pe = planEnvelope;

        if (pe == null)
        {
            pe = new StartPlanEnvelope()
            {
                DynamicParameters = new Dictionary <string, string>()
            }
        }
        ;

        IEnumerable <KeyValuePair <string, string> > queryString = this.Request.GetQueryNameValuePairs();

        foreach (KeyValuePair <string, string> kvp in queryString)
        {
            pe.DynamicParameters.Add(kvp.Key, kvp.Value);
        }

        object reply = ec.StartPlanSync(pe, planName, setContentType: false);
        ActiveDirectoryHandlerResults result = null;
        Type replyType = reply.GetType();

        if (replyType == typeof(string))
        {
            try
            {
                result = YamlHelpers.Deserialize <ActiveDirectoryHandlerResults>((string)reply);
            }
            catch (Exception e)
            {
                try
                {
                    // Reply was not Json or Yaml.  See if Xml
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml((string)reply);
                    result = XmlHelpers.Deserialize <ActiveDirectoryHandlerResults>(doc.InnerXml);
                }
                catch (Exception)
                {
                    throw e;
                }
            }
        }
        else if (replyType == typeof(Dictionary <object, object>))
        {
            String str = YamlHelpers.Serialize(reply);
            result = YamlHelpers.Deserialize <ActiveDirectoryHandlerResults>(str);
        }
        else if (replyType == typeof(XmlDocument))
        {
            XmlDocument doc = (XmlDocument)reply;
            result = XmlHelpers.Deserialize <ActiveDirectoryHandlerResults>(doc.InnerXml);
        }

        return(result);
    }
    public string WhoAmI()
    {
        string planName = @"WhoAmI";

        IExecuteController ec = GetExecuteControllerInstance();
        StartPlanEnvelope  pe = new StartPlanEnvelope()
        {
            DynamicParameters = new Dictionary <string, string>()
        };

        return((string)ec.StartPlanSync(pe, planName, setContentType: false));
    }
Exemple #3
0
        public static StatusType GetStatus(IExecuteController ec, string planName, long id)
        {
            int        c      = 0;
            StatusType status = StatusType.New;

            while (c < 30)
            {
                System.Threading.Thread.Sleep(1000);
                try { Enum.TryParse(ec.GetPlanElements(planName, id, "Result:Status").ToString(), out status); } catch { }
                c = status < StatusType.Success ? c + 1 : int.MaxValue;
            }
            return(status);
        }
        public static IExecuteController GetExecuteControllerInstance(UrlHelper currentUrl, IPrincipal currentUser, AuthenticationHeaderValue authenticationHeader)
        {
            Assembly           a = Assembly.Load("Synapse.Server");
            Type               t = a.GetType("Synapse.Services.ExecuteController", true);
            IExecuteController c = Activator.CreateInstance(t) as IExecuteController;

            if (c != null)
            {
                c.CurrentUrl           = currentUrl;
                c.CurrentUser          = currentUser;
                c.AuthenticationHeader = authenticationHeader;
            }
            return(c);
        }
Exemple #5
0
        public static T ExecuteAsync <T>(IExecuteController ec, string planName, StartPlanEnvelope pe, string path = "Actions[0]:Result:ExitData")
        {
            long       id     = ec.StartPlan(pe, planName);
            StatusType status = Task.Run(() => GetStatus(ec, planName, id)).Result;

            if (status == StatusType.Success)
            {
                return(YamlHelpers.Deserialize <T>(ec.GetPlanElements(planName, id, path).ToString()));
            }
            else
            {
                return(default(T));
            }
        }
        public static object WaitForTerminalStatusOrTimeout(IExecuteController ec, string planName, long id,
                                                            string path = "Actions[0]:Result:ExitData", SerializationType serializationType = SerializationType.Json,
                                                            int pollingIntervalSeconds = 1, int timeoutSeconds = 120)
        {
            StatusType status = Task.Run(() => GetStatus(ec, planName, id, pollingIntervalSeconds, timeoutSeconds)).Result;

            try
            {
                return(ec.GetPlanElements(planName, id, path, serializationType, setContentType: false));
            }
            catch
            {
                return(status);
            }
        }
        public static StatusType GetStatus(IExecuteController ec, string planName, long id, int pollingIntervalSeconds = 1, int timeoutSeconds = 120)
        {
            //ensure valid values
            pollingIntervalSeconds = pollingIntervalSeconds < 1 ? 1 : pollingIntervalSeconds;
            timeoutSeconds         = timeoutSeconds < 1 ? 120 : timeoutSeconds;

            int        c      = 0;
            StatusType status = StatusType.New;

            while (c < timeoutSeconds)
            {
                Thread.Sleep(pollingIntervalSeconds * 1000);
                try { Enum.TryParse(ec.GetPlanElements(planName, id, "Result:Status", setContentType: false).ToString(), out status); } catch { }
                c = status < StatusType.Success ? c + 1 : int.MaxValue;
            }
            return(status);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="deviceID"></param>
        /// <param name="controller"></param>
        public frmXD100ModbusTemperatureControl(string stationName, int deviceID, IExecuteController controller)
        {
            InitializeComponent();
            this.txtStationName.Text = stationName.Trim();

            BindDatas();

            this.ucotControlLine1.Size     = this.ucTimeControlLine21.Size;
            this.ucotControlLine1.Location = this.ucTimeControlLine21.Location;

            this.ucValveOpenDegree1.Size     = this.ucTimeControlLine21.Size;
            this.ucValveOpenDegree1.Location = this.ucTimeControlLine21.Location;

            this._deviceID   = deviceID;
            this._controller = controller;

            this._controller.ResultEvent += new EventHandler(_controller_ResultEvent);
        }
Exemple #9
0
 public static ExecuteResult Execute(ExecuteArgs executeArgs, IExecuteController controller = null)
 {
Exemple #10
0
 public static Task <StatusType> GetStatusAsync(IExecuteController ec, string planName, long id)
 {
     return(Task.Run(() => GetStatus(ec, planName, id)));
 }
Exemple #11
0
        public static Task <StatusType> ExecuteAsync(IExecuteController ec, string planName, StartPlanEnvelope pe, out long id)
        {
            long pid = id = ec.StartPlan(pe, "GetOrgUnit");

            return(Task.Run(() => GetStatus(ec, planName, pid)));
        }
Exemple #12
0
        public static ExecuteResult Execute(ExecuteArgs executeArgs, IExecuteController controller = null, NPath outputFile = null)
        {
            using (var p = NewProcess(executeArgs))
            {
                FileStream fOut, fError;
                string     tempOutputFile, tempErrorFile;

                lock (FileLocker)
                {
                    tempOutputFile = outputFile == null?Path.GetTempFileName() : outputFile.ToString();

                    tempErrorFile = Path.GetTempFileName();
                    fOut          = File.Create(tempOutputFile);
                    fError        = File.Create(tempErrorFile);
                }

                var stopWatch = new Stopwatch();
                stopWatch.Start();

                using (
                    StreamWriter outputWriter = new StreamWriter(fOut, Encoding.UTF8),
                    errorWriter = new StreamWriter(fError, Encoding.UTF8))
                {
                    p.OutputDataReceived += (sender, args) =>
                    {
                        outputWriter.WriteLine(args.Data);
                        if (controller != null)
                        {
                            controller.OnStdoutReceived(args.Data);
                        }
                    };
                    p.ErrorDataReceived += (sender, args) =>
                    {
                        errorWriter.WriteLine(args.Data);
                        if (controller != null)
                        {
                            controller.OnStderrReceived(args.Data);
                        }
                    };
                    lock (PipeLocker)
                    {
                        p.Start();
                        p.BeginOutputReadLine();
                        p.BeginErrorReadLine();
                    }

                    p.WaitForExit();
                    p.CancelErrorRead();
                    p.CancelOutputRead();
                }

                string output = "";
                string error;
                lock (FileLocker)
                {
                    if (controller != null)
                    {
                        controller.AboutToCleanup(tempOutputFile, tempErrorFile);
                    }

                    if (outputFile == null)
                    {
                        output = File.ReadAllText(tempOutputFile, Encoding.UTF8);
                        File.Delete(tempOutputFile);
                    }

                    error = File.ReadAllText(tempErrorFile, Encoding.UTF8);
                    File.Delete(tempErrorFile);
                }

                stopWatch.Stop();
                var result = new ExecuteResult()
                {
                    ExitCode = p.ExitCode,
                    StdOut   = outputFile == null ? output : "in outputfile",
                    StdErr   = error,
                    Duration = TimeSpan.FromMilliseconds(stopWatch.ElapsedMilliseconds)
                };

                return(result);
            }
        }
    public object ExecutePlan(string planname, string url)
    {
        string            planName = planname;
        StartPlanEnvelope pe       = GetPlanEnvelope();

        String body       = this.Request.Content?.ReadAsStringAsync().Result;
        string user       = this.User?.Identity?.Name;
        string requestUri = this.Request.RequestUri.ToString();

        if (url != null)
        {
            pe.DynamicParameters.Add("url", url);

            // Split URL into Individual Parts, Pass Into Plan as "url_#"
            string[] parts = url.Split('\\', '/');
            for (int i = 0; i < parts.Length; i++)
            {
                pe.DynamicParameters.Add($"url_{i + 1}", parts[i]);
            }
        }

        if (body != null)
        {
            pe.DynamicParameters.Add("body", body);
            try
            {
                Dictionary <string, string> bodyDictionary = YamlHelpers.Deserialize <Dictionary <string, string> >(body);
                foreach (KeyValuePair <string, string> kvp in bodyDictionary)
                {
                    if (!(pe.DynamicParameters.ContainsKey(kvp.Key)))
                    {
                        pe.DynamicParameters.Add(kvp.Key, kvp.Value);
                    }
                }
            }
            catch { }
        }

        pe.DynamicParameters.Add("method", this.Request.Method.ToString());
        pe.DynamicParameters.Add("requesturi", requestUri);

        int queryIndex = requestUri.IndexOf('?');

        if (queryIndex > 0)
        {
            pe.DynamicParameters.Add("query", requestUri.Substring(queryIndex + 1));
        }
        if (user != null)
        {
            pe.DynamicParameters.Add("user", user);
        }

        // Add Query String values into Plan Envelope Exactly As Provided
        IEnumerable <KeyValuePair <string, string> > queryKvp = this.Request.GetQueryNameValuePairs();

        foreach (KeyValuePair <string, string> kvp in queryKvp)
        {
            if (pe.DynamicParameters.ContainsKey(kvp.Key))
            {
                string value = pe.DynamicParameters[kvp.Key].ToString();
                pe.DynamicParameters[kvp.Key] = $"{value},{kvp.Value}";
            }
            else
            {
                pe.DynamicParameters.Add(kvp.Key, kvp.Value);
            }
        }

        IExecuteController ec = GetExecuteControllerInstance();

        return(ec.StartPlanSync(pe, planName, serializationType: SerializationType.Unspecified, setContentType: true, timeoutSeconds: 3600));
    }
    private ActiveDirectoryHandlerResults CallPlan(string planName, StartPlanEnvelope planEnvelope)
    {
        IExecuteController ec = GetExecuteControllerInstance();
        StartPlanEnvelope  pe = planEnvelope;

        if (pe == null)
        {
            pe = new StartPlanEnvelope()
            {
                DynamicParameters = new Dictionary <string, string>()
            }
        }
        ;

        // Add Query String values into Plan Envelope Exactly As Provided
        IEnumerable <KeyValuePair <string, string> > queryString = this.Request.GetQueryNameValuePairs();

        foreach (KeyValuePair <string, string> kvp in queryString)
        {
            pe.DynamicParameters.Add(kvp.Key, kvp.Value);
        }

        object reply = ec.StartPlanSync(pe, planName, setContentType: false);
        ActiveDirectoryHandlerResults result = null;
        Type replyType = reply.GetType();

        if (replyType == typeof(Dictionary <object, object>))
        {
            String str = YamlHelpers.Serialize(reply);
            result = YamlHelpers.Deserialize <ActiveDirectoryHandlerResults>(str);
        }
        else if (replyType == typeof(XmlDocument))
        {
            XmlDocument doc = (XmlDocument)reply;
            result = XmlHelpers.Deserialize <ActiveDirectoryHandlerResults>(doc.InnerXml);
        }
        else
        {
            try
            {
                result = YamlHelpers.Deserialize <ActiveDirectoryHandlerResults>(reply.ToString());
            }
            catch (Exception)
            {
                try
                {
                    // Reply was not Json or Yaml.  See if Xml
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(reply.ToString());
                    result = XmlHelpers.Deserialize <ActiveDirectoryHandlerResults>(doc.InnerXml);
                }
                catch (Exception)
                {
                    // Reply was of unknown type.  Put Raw Output In Return Object
                    result = new ActiveDirectoryHandlerResults();
                    ActiveDirectoryObjectResult error  = new ActiveDirectoryObjectResult();
                    ActiveDirectoryStatus       status = new ActiveDirectoryStatus();

                    status.StatusId = AdStatusType.NotSupported;
                    status.Message  = $"Unable To Parse ObjectType [{replyType}].";
                    status.ActionId = ActionType.None;
                    error.Statuses.Add(status);

                    error.TypeId = AdObjectType.None;
                    error.Object = reply;
                    result.Add(error);
                }
            }
        }

        return(result);
    }