Example #1
0
        /// <summary>
        /// Produce a byte array containing only the headers.
        /// </summary>
        /// <returns>Byte array.</returns>
        public byte[] ToHeaderBytes()
        {
            string header = "";

            if (!String.IsNullOrEmpty(Id))
            {
                header += "Id: " + Id + Environment.NewLine;
            }
            header += "SyncRequest: " + SyncRequest + Environment.NewLine;
            header += "SyncResponse: " + SyncResponse + Environment.NewLine;
            header += "TimeoutMs: " + TimeoutMs.ToString() + Environment.NewLine;
            header += "SourceIp: " + SourceIp + Environment.NewLine;
            header += "SourcePort: " + SourcePort.ToString() + Environment.NewLine;
            header += "DestinationIp: " + DestinationIp + Environment.NewLine;
            header += "Type: " + Type.ToString() + Environment.NewLine;
            header += "ContentLength: " + ContentLength.ToString() + Environment.NewLine;
            header += Environment.NewLine;

            return(Encoding.UTF8.GetBytes(header));
        }
Example #2
0
        internal byte[] ToHeaderBytes()
        {
            string header = "";

            if (!String.IsNullOrEmpty(Id))
            {
                header += "Id: " + Id + Environment.NewLine;
            }
            header += "IsBroadcast: " + IsBroadcast + Environment.NewLine;
            header += "SyncRequest: " + SyncRequest + Environment.NewLine;
            header += "SyncResponse: " + SyncResponse + Environment.NewLine;
            header += "TimeoutMs: " + TimeoutMs.ToString() + Environment.NewLine;
            header += "SourceIpPort: " + SourceIpPort + Environment.NewLine;
            header += "DestinationIpPort: " + DestinationIpPort + Environment.NewLine;
            header += "Type: " + Type.ToString() + Environment.NewLine;
            header += "Metadata: " + Common.SerializeJson(Metadata, false) + Environment.NewLine;
            header += "ContentLength: " + ContentLength.ToString() + Environment.NewLine;
            header += Environment.NewLine;

            return(Encoding.UTF8.GetBytes(header));
        }
Example #3
0
        /// <summary>
        /// Start the gpg process.
        /// </summary>
        public void Exec()
        {
            ProcessStartInfo pInfo = new ProcessStartInfo("/usr/bin/gpg", OptionsString());

            pInfo.WorkingDirectory       = "/usr/bin";
            pInfo.CreateNoWindow         = true;
            pInfo.UseShellExecute        = false;
            pInfo.RedirectStandardInput  = true;
            pInfo.RedirectStandardOutput = true;
            pInfo.RedirectStandardError  = true;
            pInfo.StandardErrorEncoding  = Encoding.UTF8;
            pInfo.StandardOutputEncoding = Encoding.UTF8;

            try {
                _processObject = Process.Start(pInfo);
            } catch {}

            ThreadStart outputEntry  = new ThreadStart(StandardOutputReader);
            Thread      outputThread = new Thread(outputEntry);

            outputThread.Start();
            ThreadStart errorEntry  = new ThreadStart(StandardErrorReader);
            Thread      errorThread = new Thread(errorEntry);

            errorThread.Start();

            _processObject.StandardInput.Close();

            if (_processObject.WaitForExit(TimeoutMs))
            {
                // The process ended before the Timeout
                if (!outputThread.Join(TimeoutMs))
                {
                    outputThread.Abort();
                }
                if (!errorThread.Join(TimeoutMs))
                {
                    errorThread.Abort();
                }
            }
            else
            {
                _outputString = "";
                _errorString  = String.Format("Timed out after {0} milliseconds.", TimeoutMs.ToString());
                _processObject.Kill();

                // Process timed out.. kill it.
                if (outputThread.IsAlive)
                {
                    outputThread.Abort();
                }
                if (errorThread.IsAlive)
                {
                    errorThread.Abort();
                }
            }

            // Check the results
            _exitcode = _processObject.ExitCode;
            if (_exitcode != 0)
            {
                if (_errorString == "")
                {
                    throw new GPGException(String.Format("[{0}]: Unknown error.", _processObject.ExitCode.ToString()));
                }
            }
        }