当前位置: 首页>>代码示例>>C#>>正文


C# Arguments.Exists方法代码示例

本文整理汇总了C#中System.Arguments.Exists方法的典型用法代码示例。如果您正苦于以下问题:C# Arguments.Exists方法的具体用法?C# Arguments.Exists怎么用?C# Arguments.Exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Arguments的用法示例。


在下文中一共展示了Arguments.Exists方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Start

        public void Start(string[] args)
        {
            string userInput = null;
            Arguments arguments = new Arguments(string.Join(" ", args));

            if (arguments.Exists("server"))
            {
                // Override default settings with user provided input. 
                m_clientHelper.PersistSettings = false;
                m_remotingClient.PersistSettings = false;
                if (arguments.Exists("server"))
                    m_remotingClient.ConnectionString = string.Format("Server={0}", arguments["server"]);
            }

            // Connect to service and send commands. 
            m_clientHelper.Connect();
            while (m_clientHelper.Enabled &&
                   string.Compare(userInput, "Exit", true) != 0)
            {
                // Wait for a command from the user. 
                userInput = Console.ReadLine();
                // Write a blank line to the console.
                Console.WriteLine();

                if (!string.IsNullOrEmpty(userInput))
                {
                    // The user typed in a command and didn't just hit <ENTER>. 
                    switch (userInput.ToUpper())
                    {
                        case "CLS":
                            // User wants to clear the console window. 
                            Console.Clear();
                            break;
                        case "EXIT":
                            // User wants to exit the telnet session with the service. 
                            if (m_telnetActive)
                            {
                                userInput = string.Empty;
                                m_clientHelper.SendRequest("Telnet -disconnect");
                            }
                            break;
                        default:
                            // User wants to send a request to the service. 
                            m_clientHelper.SendRequest(userInput);
                            if (string.Compare(userInput, "Help", true) == 0)
                                DisplayHelp();

                            break;
                    }
                }
            }
        }
开发者ID:rmc00,项目名称:gsf,代码行数:52,代码来源:ServiceClient.cs

示例2: Main

        static int Main(string[] arguments)
        {
            Arguments splitArguments=null;
            try
            {
                 splitArguments = new Arguments(arguments);
                ExceptionFunctions.ForceVerbose = splitArguments.Exists(Arguments.DefaultArgumentPrefix + "verbose");
                string operation = splitArguments.String(Arguments.OperationArgument, true);

                AdapterFunctions.RunOperation(operation, splitArguments);
                return 0;
            } catch (Exception error)
            {
                string message = string.Empty
                    + Arguments.ErrorArgument + " " + ExceptionFunctions.Write(error, !ExceptionFunctions.ForceVerbose) + Environment.NewLine
                    + "Arguments: " + string.Join(" ", arguments) + Environment.NewLine;
                //if (ExceptionFunctions.ForceVerbose)
                //{
                //    message += ProcessFunctions.WriteProcessHeritage() + Environment.NewLine;
                //    message += ProcessFunctions.WriteSystemVariables() + Environment.NewLine;
                //}
                Console.Write(message);
                if (ExceptionFunctions.ForceVerbose)
                {
                    SwishFunctions.MessageTextBox(message, false);
                }
                return -1;
            }
        }
开发者ID:swish-climate-impact-assessment,项目名称:swish-kepler-actors,代码行数:29,代码来源:Program.cs

示例3: Start

        /// <summary>
        /// Handles service start event.
        /// </summary>
        /// <param name="args">Service start arguments.</param>
        public virtual void Start(string[] args)
        {
            string userInput = null;
            Arguments arguments = new Arguments(string.Join(" ", args));

            if (arguments.Exists("OrderedArg1") && arguments.Exists("restart"))
            {
                string serviceName = arguments["OrderedArg1"];

                if (Common.IsPosixEnvironment)
                {
                    string serviceCommand = FilePath.GetAbsolutePath(serviceName);

                    try
                    {
                        Command.Execute(serviceCommand, "stop");
                    }
                    catch (Exception ex)
                    {
                        WriteLine("Failed to stop the {0} daemon: {1}\r\n", serviceName, ex.Message);
                    }

                    try
                    {
                        Command.Execute(serviceCommand, "start");
                    }
                    catch (Exception ex)
                    {
                        WriteLine("Failed to restart the {0} daemon: {1}\r\n", serviceName, ex.Message);
                    }
                }
                else
                {
                    // Attempt to access service controller for the specified Windows service
                    ServiceController serviceController = ServiceController.GetServices().SingleOrDefault(svc => string.Compare(svc.ServiceName, serviceName, StringComparison.OrdinalIgnoreCase) == 0);

                    if (serviceController != null)
                    {
                        try
                        {
                            if (serviceController.Status == ServiceControllerStatus.Running)
                            {
                                WriteLine("Attempting to stop the {0} Windows service...", serviceName);

                                serviceController.Stop();

                                // Can't wait forever for service to stop, so we time-out after 20 seconds
                                serviceController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(20.0D));

                                if (serviceController.Status == ServiceControllerStatus.Stopped)
                                    WriteLine("Successfully stopped the {0} Windows service.", serviceName);
                                else
                                    WriteLine("Failed to stop the {0} Windows service after trying for 20 seconds...", serviceName);

                                // Add an extra line for visual separation of service termination status
                                WriteLine("");
                            }
                        }
                        catch (Exception ex)
                        {
                            WriteLine("Failed to stop the {0} Windows service: {1}\r\n", serviceName, ex.Message);
                        }
                    }

                    // If the service failed to stop or it is installed as stand-alone debug application, we try to forcibly stop any remaining running instances
                    try
                    {
                        Process[] instances = Process.GetProcessesByName(serviceName);

                        if (instances.Length > 0)
                        {
                            int total = 0;
                            WriteLine("Attempting to stop running instances of the {0}...", serviceName);

                            // Terminate all instances of service running on the local computer
                            foreach (Process process in instances)
                            {
                                process.Kill();
                                total++;
                            }

                            if (total > 0)
                                WriteLine("Stopped {0} {1} instance{2}.", total, serviceName, total > 1 ? "s" : "");

                            // Add an extra line for visual separation of process termination status
                            WriteLine("");
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteLine("Failed to terminate running instances of the {0}: {1}\r\n", serviceName, ex.Message);
                    }

                    // Attempt to restart Windows service...
                    if (serviceController != null)
                    {
//.........这里部分代码省略.........
开发者ID:avs009,项目名称:gsf,代码行数:101,代码来源:ServiceClientBase.cs

示例4: Start

        /// <summary>
        /// Handles service start event.
        /// </summary>
        /// <param name="args">Service start arguments.</param>
        public virtual void Start(string[] args)
        {
            string userInput = null;
            Arguments arguments = new Arguments(string.Join(" ", args));

            if (arguments.Exists("OrderedArg1") && arguments.Exists("restart"))
            {
                string serviceName = arguments["OrderedArg1"];

                // Attempt to access service controller for the specified Windows service
                ServiceController serviceController = ServiceController.GetServices().SingleOrDefault(svc => string.Compare(svc.ServiceName, serviceName, true) == 0);

                if (serviceController != null)
                {
                    try
                    {
                        if (serviceController.Status == ServiceControllerStatus.Running)
                        {
                            Console.WriteLine("Attempting to stop the {0} Windows service...", serviceName);

                            serviceController.Stop();

                            // Can't wait forever for service to stop, so we time-out after 20 seconds
                            serviceController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(20.0D));

                            if (serviceController.Status == ServiceControllerStatus.Stopped)
                                Console.WriteLine("Successfully stopped the {0} Windows service.", serviceName);
                            else
                                Console.WriteLine("Failed to stop the {0} Windows service after trying for 20 seconds...", serviceName);

                            // Add an extra line for visual separation of service termination status
                            Console.WriteLine("");
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Failed to stop the {0} Windows service: {1}\r\n", serviceName, ex.Message);
                    }
                }

                // If the service failed to stop or it is installed as stand-alone debug application, we try to forcibly stop any remaining running instances
                try
                {
                    Process[] instances = Process.GetProcessesByName(serviceName);

                    if (instances.Length > 0)
                    {
                        int total = 0;
                        Console.WriteLine("Attempting to stop running instances of the {0}...", serviceName);

                        // Terminate all instances of service running on the local computer
                        foreach (Process process in instances)
                        {
                            process.Kill();
                            total++;
                        }

                        if (total > 0)
                            Console.WriteLine(string.Format("Stopped {0} {1} instance{2}.", total, serviceName, total > 1 ? "s" : ""));

                        // Add an extra line for visual separation of process termination status
                        Console.WriteLine("");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Failed to terminate running instances of the {0}: {1}\r\n", serviceName, ex.Message);
                }

                // Attempt to restart Windows service...
                if (serviceController != null)
                {
                    try
                    {
                        // Refresh state in case service process was forcibly stopped
                        serviceController.Refresh();

                        if (serviceController.Status != ServiceControllerStatus.Running)
                            serviceController.Start();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Failed to restart the {0} Windows service: {1}\r\n", serviceName, ex.Message);
                    }
                }
            }
            else
            {
                if (arguments.Exists("server"))
                {
                    // Override default settings with user provided input. 
                    m_clientHelper.PersistSettings = false;
                    m_remotingClient.PersistSettings = false;
                    m_remotingClient.ConnectionString = string.Format("Server={0}", arguments["server"]);
                }

//.........这里部分代码省略.........
开发者ID:avs009,项目名称:gsf,代码行数:101,代码来源:ServiceClientBase.cs

示例5: Start

        public void Start()
        {
            string userInput = null;
            string[] args = Arguments.ToArgs(Environment.CommandLine);
            Arguments arguments = new Arguments(string.Join(" ", args.Where(arg => !arg.StartsWith("--filter=", StringComparison.OrdinalIgnoreCase))));

            if (arguments.Exists("server"))
            {
                // Override default settings with user provided input.
                m_clientHelper.PersistSettings = false;
                m_remotingClient.PersistSettings = false;
                if (arguments.Exists("server"))
                    m_remotingClient.ConnectionString = string.Format("Server={0}", arguments["server"]);
            }

            // Set the status message filter from command line args before connecting to the service
            m_clientHelper.StatusMessageFilter = Enumerable.Range(0, args.Length)
                .Where(index => args[index].StartsWith("--filter=", StringComparison.OrdinalIgnoreCase))
                .Select(index => Regex.Replace(args[index], "^--filter=", "", RegexOptions.IgnoreCase))
                .FirstOrDefault() ?? ClientHelper.DefaultStatusMessageFilter;

            // Connect to service and send commands.
            m_clientHelper.Connect();
            while (m_clientHelper.Enabled &&
                   string.Compare(userInput, "Exit", true) != 0)
            {
                // Wait for a command from the user.
                userInput = Console.ReadLine();
                // Write a blank line to the console.
                Console.WriteLine();

                if (!string.IsNullOrEmpty(userInput))
                {
                    // The user typed in a command and didn't just hit <ENTER>.
                    switch (userInput.ToUpper())
                    {
                        case "CLS":
                            // User wants to clear the console window.
                            Console.Clear();
                            break;
                        case "EXIT":
                            // User wants to exit the telnet session with the service.
                            if (m_telnetActive)
                            {
                                userInput = string.Empty;
                                m_clientHelper.SendRequest("Telnet -disconnect");
                            }
                            break;
                        default:
                            // User wants to send a request to the service.
                            m_clientHelper.SendRequest(userInput);
                            if (string.Compare(userInput, "Help", true) == 0)
                                DisplayHelp();

                            break;
                    }
                }
            }
        }
开发者ID:GridProtectionAlliance,项目名称:openXDA,代码行数:59,代码来源:ServiceClient.cs

示例6: Main

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            if (!s_singleInstanceMutex.WaitOne(0, true))
                Environment.Exit(1);

            bool runAsService;
            bool runAsApplication;

            Arguments args = new Arguments(Environment.CommandLine, true);

            if (args.Count == 0)
            {
#if DEBUG
                runAsService = false;
                runAsApplication = true;
#else
                runAsService = true;
                runAsApplication = false;
#endif
            }
            else
            {
                runAsService = args.Exists("RunAsService");
                runAsApplication = args.Exists("RunAsApplication");

                if (!runAsService && !runAsApplication && !args.Exists("RunAsConsole"))
                {
                    MessageBox.Show("Invalid argument. If specified, argument must be one of: -RunAsService, -RunAsApplication or -RunAsConsole.");
                    Environment.Exit(1);
                }
            }

            if (runAsService)
            {
                // Run as Windows Service.
                ServiceBase.Run(new ServiceBase[] { Host });
            }
            else if (runAsApplication)
            {
                // Run as Windows Application.
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new DebugHost(Host));
            }
            else
            {
                string shellHostedServiceName = Host.ServiceName + "Shell.exe";
                string shellHostedServiceFileName = FilePath.GetAbsolutePath(shellHostedServiceName);
                string shellHostedServiceConfigFileName = FilePath.GetAbsolutePath(shellHostedServiceName + ".config");
                string serviceConfigFileName = FilePath.GetAbsolutePath(Host.ServiceName + ".exe.config");

                try
                {
                    File.Copy(serviceConfigFileName, shellHostedServiceConfigFileName, true);
#if MONO
                    Process hostedServiceSession = Process.Start("mono", shellHostedServiceFileName);
#else
                    Process hostedServiceSession = Process.Start(shellHostedServiceFileName);
#endif
                    if ((object)hostedServiceSession != null)
                    {
                        hostedServiceSession.WaitForExit();

                        try
                        {
                            File.Copy(shellHostedServiceConfigFileName, serviceConfigFileName, true);
                        }
                        catch
                        {
                            // Do not report exception if config file could not be updated
                        }

                        Environment.Exit(hostedServiceSession.ExitCode);
                    }
                    else
                    {
                        MessageBox.Show($"Failed to start \"{Host.ServiceName}\" as a shell hosted service.");
                        Environment.Exit(1);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Failed to start \"{Host.ServiceName}\" as a shell hosted service: {ex.Message}");
                    Environment.Exit(1);
                }
            }
        }
开发者ID:GridProtectionAlliance,项目名称:openHistorian,代码行数:90,代码来源:Program.cs

示例7: Main

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            ServiceHost host = new ServiceHost();

            bool runAsService;
            bool runAsApplication;

            Arguments args = new Arguments(Environment.CommandLine, true);

            if (args.Count > 1)
            {
                MessageBox.Show("Too many arguments. If specified, argument must be one of: -RunAsService, -RunAsApplication or -RunAsConsole.");
                Environment.Exit(1);
            }

            if (args.Count == 0)
            {
            #if DEBUG
                runAsService = false;
                runAsApplication = true;
            #else
                runAsService = true;
                runAsApplication = false;
            #endif
            }
            else
            {
                runAsService = args.Exists("RunAsService");
                runAsApplication = args.Exists("RunAsApplication");

                if (!runAsService && !runAsApplication && !args.Exists("RunAsConsole"))
                {
                    MessageBox.Show("Invalid argument. If specified, argument must be one of: -RunAsService, -RunAsApplication or -RunAsConsole.");
                    Environment.Exit(1);
                }
            }

            if (runAsService)
            {
                // Run as Windows Service.
                ServiceBase.Run(new ServiceBase[] { host });
            }
            else if (runAsApplication)
            {
                // Run as Windows Application.
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new DebugHost(host));
            }
            else
            {
                string hostedServiceSessionName = host.ServiceName + "Shell.exe";
                Process hostedServiceSession = Process.Start(hostedServiceSessionName);

                if ((object)hostedServiceSession != null)
                {
                    hostedServiceSession.WaitForExit();
                    Environment.Exit(hostedServiceSession.ExitCode);
                }
                else
                {
                    MessageBox.Show(string.Format("Failed to start \"{0}\" with a hosted service.", hostedServiceSessionName));
                    Environment.Exit(1);
                }
            }
        }
开发者ID:GridProtectionAlliance,项目名称:substationSBG,代码行数:69,代码来源:Program.cs

示例8: RunOperation


//.........这里部分代码省略.........
            case CommandOperation:
                {
                    string inputFileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument, true));
                    string command = splitArguments.String(Arguments.DefaultArgumentPrefix + "command", true);
                    string outputFileName = splitArguments.OutputFileName();
                    StataCommand(inputFileName, outputFileName, command);
                    Console.Write(outputFileName);
                }
                break;

            case AppendOperation:
                {
                    string input1FileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument + "1", true));
                    string input2FileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument + "2", true));
                    string outputFileName = splitArguments.OutputFileName();
                    outputFileName = Append(input1FileName, input2FileName, outputFileName);
                    Console.Write(outputFileName);
                }
                break;

            case RemoveColumnsOperation:
                {
                    string inputFileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument, true));
                    List<string> variableNames = splitArguments.StringList(Arguments.DefaultArgumentPrefix + "variables", true, true);
                    string outputFileName = splitArguments.OutputFileName();
                    RemoveColumns(inputFileName, outputFileName, variableNames);
                    Console.Write(outputFileName);
                }
                break;

            case DisplayOperation:
                {
                    string inputFileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument, true));
                    Display(inputFileName);
                }
                break;

            case DisplayClientOperation:
                {
                    string inputFileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument, true));
                    DisplayClient(inputFileName);
                }
                break;

            case TestOperation:
                {
                    bool silent = splitArguments.Exists(Arguments.DefaultArgumentPrefix + "silent");

                    List<string> lines = new List<string>();
                    lines.Add("Arguments: " + splitArguments.ArgumentString);
                    lines.Add("Startup path: " + Application.StartupPath);
                    lines.Add("Working directory: " + Environment.CurrentDirectory);

                    if (ProcessFunctions.KeplerProcess != null)
                    {
                        lines.Add("Keper process:");
                        lines.Add(ProcessFunctions.WriteProcessInformation(ProcessFunctions.KeplerProcess));
                    } else
                    {
                        lines.Add("Keper process: Not found");
                    }

                    lines.Add("Current process heritage: ");

                    lines.AddRange(ProcessFunctions.WriteProcessHeritage().Split(new string[] { Environment.NewLine }, StringSplitOptions.None));
                    lines.AddRange(ProcessFunctions.WriteSystemVariables().Split(new string[] { Environment.NewLine }, StringSplitOptions.None));
                    if (!silent)
                    {
                        SwishFunctions.MessageTextBox("Test display", lines, false);
                    }
                    Console.Write(string.Join(Environment.NewLine, lines));
                }
                break;

            case TemporaryFileNameOperation:
                {
                    string fileName = FileFunctions.TempoaryOutputFileName(string.Empty);
                    if (FileFunctions.FileExists(fileName))
                    {
                        File.Delete(fileName);
                    }
                    Console.Write(fileName);
                }
                break;

            case ReplaceOperation:
                {
                    string inputFileName = FileFunctions.AdjustFileName(splitArguments.String(Arguments.InputArgument, true));
                    string outputFileName = splitArguments.OutputFileName();
                    string condition = splitArguments.String(Arguments.DefaultArgumentPrefix + "condition", true);
                    string value = splitArguments.String(Arguments.DefaultArgumentPrefix + "value", true);
                    Replace(inputFileName, outputFileName, condition, value);
                    Console.Write(outputFileName);
                }
                break;

            default:
                throw new Exception("Unknown operation \"" + operation + "\"");
            }
        }
开发者ID:swish-climate-impact-assessment,项目名称:swish-kepler-actors,代码行数:101,代码来源:AdapterFunctions.cs


注:本文中的System.Arguments.Exists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。