public static bool DownloadFile(DownloadItem item, DataReceivedEventHandler handler, bool notify = true)
        {
            Utils.GetFile(item.Filename, Settings.PathToInstalls + "\\AcumaticaERPInstall.msi", Settings.AcumaticaS3Url);
            //System.IO.File.WriteAllBytes(Settings.PathToInstalls + "\\AcumaticaERPInstall.msi", ((MemoryStream)file).ToArray());
            while (downloading)
            {
                Application.DoEvents();
            }
            if (HasError)
            {
                if (notify)
                {
                    MessageBox.Show("There was an error downloading the file", "Download Error", MessageBoxButtons.OK);
                }
                else
                {
                    var e = DataReceivedEventArgsExt.Create("There was an error downloading the file");
                    handler.Invoke(null, e);
                }
                return(false);
            }
            RunScript(Utils.GetVersion(item), handler);//.Filename));
            Application.DoEvents();
            if (System.IO.File.Exists(Settings.PathToInstalls + "\\AcumaticaERPInstall.msi"))
            {
                try
                {
                    System.IO.File.Delete(Settings.PathToInstalls + "\\AcumaticaERPInstall.msi");
                }
                catch { }
            }
            var releaseFolder     = string.Format("{0}{1}", Settings.PathToInstalls, item.Version);      //Utils.GetVersionFolder(Utils.GetVersion(item), Settings.PathToInstalls);//.Filename));
            var installFolder     = string.Format("{0}{1}", Settings.PathToInstalls, item.PatchVersion); // Utils.GetVersion(item));//.Filename));
            var destinationFolder = string.Format("{0}\\{1}", releaseFolder, item.PatchVersion);         // Utils.GetVersion(item));//.Filename));

            try
            {
                if (!Directory.Exists(releaseFolder))
                {
                    Directory.CreateDirectory(releaseFolder);
                }
                Directory.Move(installFolder, destinationFolder);
            }
            catch
            {
                if (notify)
                {
                    MessageBox.Show(string.Format("There was an error moving the installation ({0}) \r\n into the release folder ({1}) \r\n you will need to move it manually.", Utils.GetVersion(item), releaseFolder), "Move Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    var e = DataReceivedEventArgsExt.Create(string.Format("There was an error moving the installation ({0}) \r\n into the release folder ({1}) \r\n you will need to move it manually.", Utils.GetVersion(item), releaseFolder));
                    handler.Invoke(null, e);
                }
                return(false);
            }
            return(true);
        }
 private void ServerProcess_OutputDataReceived(object sender, DataReceivedEventArgs e)
 {
     if (OnReceiveError != null)
     {
         OnReceiveError.Invoke(sender, e);
     }
 }
Beispiel #3
0
        public Process CreateProcess(ProcessStartInfo info)
        {
            Process process = null;

            if (Validation(info))
            {
                process = new Process
                {
                    EnableRaisingEvents = false,
                    StartInfo           = info,
                };

                process.OutputDataReceived += (sender, e) =>
                {
                    OutputDataReceived?.Invoke(e.Data);
                };
                process.ErrorDataReceived += (sender, e) =>
                {
                    ErrorDataReceived?.Invoke(e.Data);
                };
            }

            return(process);
        }
Beispiel #4
0
 private void OnErrorDataReceived(object sender, DataReceivedEventArgs e)
 {
     _errorDataReceived?.Invoke(sender, e);
 }
Beispiel #5
0
 private void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
 {
     _outputDataReceived?.Invoke(sender, e);
 }
Beispiel #6
0
 // wrap event-invocations in a protected virtual method
 protected virtual void OnServerOutputReceived(DataReceivedEventArgs e)
 {
     _serverOutputReceived?.Invoke(this, e);
 }
Beispiel #7
0
 private void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
 {
     DataReceivedEventHandler?.Invoke(sender, e);
 }
 /// <summary>
 /// Data received event handler.
 /// </summary>
 /// <param name="sender">Event sender.</param>
 /// <param name="e">Event argument.</param>
 public void OnDataReceived(object sender, DataReceivedEventArgs e)
 {
     DataReceivedEvent?.Invoke(sender, e);
 }
Beispiel #9
0
        public static async Task <ProcessResult> RunProcessAsync(string command, string arguments, int timeout, DataReceivedEventHandler dataReceived, DataReceivedEventHandler errorDataReceived)
        {
            var result = new ProcessResult();

            using (var process = new Process())
            {
                process.StartInfo.FileName        = command;
                process.StartInfo.Arguments       = arguments;
                process.StartInfo.UseShellExecute = false;
                //process.StartInfo.RedirectStandardInput = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError  = true;
                process.StartInfo.CreateNoWindow         = true;

                var outputBuilder    = new StringBuilder();
                var outputCloseEvent = new TaskCompletionSource <bool>();

                process.OutputDataReceived += (s, e) =>
                {
                    if (e.Data == null)
                    {
                        outputCloseEvent.SetResult(true);
                    }
                    else
                    {
                        outputBuilder.Append(e.Data);
                    }

                    dataReceived?.Invoke(s, e);
                };

                var errorBuilder    = new StringBuilder();
                var errorCloseEvent = new TaskCompletionSource <bool>();

                process.ErrorDataReceived += (s, e) =>
                {
                    if (e.Data == null)
                    {
                        errorCloseEvent.SetResult(true);
                    }
                    else
                    {
                        errorBuilder.Append(e.Data);
                    }

                    errorDataReceived?.Invoke(s, e);
                };

                var isStarted = process.Start();
                if (!isStarted)
                {
                    result.ExitCode = process.ExitCode;
                    return(result);
                }

                // Reads the output stream first and then waits because deadlocks are possible
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();

                // Creates task to wait for process exit using timeout
                var waitForExit = WaitForExitAsync(process, timeout);

                // Create task to wait for process exit and closing all output streams
                var processTask = Task.WhenAll(waitForExit, outputCloseEvent.Task, errorCloseEvent.Task);

                // Waits process completion and then checks it was not completed by timeout
                if (await Task.WhenAny(Task.Delay(timeout), processTask) == processTask && waitForExit.Result)
                {
                    result.ExitCode = process.ExitCode;
                    result.Output   = outputBuilder.ToString();
                    result.Error    = errorBuilder.ToString();
                }
                else
                {
                    try
                    {
                        // Kill hung process
                        process.Kill();
                    }
                    catch
                    {
                        // ignored
                    }
                }
            }

            return(result);
        }
Beispiel #10
0
 private void Exchange_ReciveHandler(byte[] data, int len, IPEndPoint arg3) =>
 DataReceivedEventHandler?.Invoke(data, len, arg3.Address);
Beispiel #11
0
 public void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
 {
     DataReceivedEventHandler?.Invoke(DateTime.Now, serialPort.ReadExisting());
 }