Beispiel #1
0
        private static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                ShowHelp();
                return;
            }

            InquiryEntity ie     = new InquiryEntity();
            IFinder       finder = null;;
            string        FileName;
            bool          isNetworkMode = false;

            foreach (string arg in args)
            {
                if (arg.StartsWith("/"))
                {
                    switch (arg.Substring(1, 1))
                    {
                    case "m":
                        ie.Method = arg.Split(':')[1];
                        break;

                    case "p":
                        ie.Password = arg.Split(':')[1];
                        break;

                    case "u":
                        ie.UserName = arg.Split(':')[1];
                        break;

                    case "i":
                        ie.TaskFile = arg.Substring(arg.IndexOf(':') + 1);
                        break;

                    case "o":
                        ie.OutputFolder = arg.Substring(arg.IndexOf(':') + 1);
                        break;

                    case "1":
                        ie.File1 = arg.Substring(arg.IndexOf(':') + 1);
                        break;

                    case "2":
                        ie.File2 = arg.Substring(arg.IndexOf(':') + 1);
                        break;

                    case "c":
                        isNetworkMode = true;

                        int       port    = (arg.Contains(':')) ? int.Parse(arg.Split(':')[2]) : 9876;
                        IPAddress address = (arg.Contains(':')) ? IPAddress.Parse(arg.Split(':')[1]) : IPAddress.Loopback;
                        Client    client  = new Client(port, address);

                        client.Start();

                        break;

                    case "s":
                        isNetworkMode = true;

                        //todo а если задан только один параметр?
                        int       sport    = (arg.Contains(':')) ? int.Parse(arg.Split(':')[2]) : 9876;
                        IPAddress saddress = (arg.Contains(':')) ? IPAddress.Parse(arg.Split(':')[1]) : IPAddress.Any;
                        Server    server   = new Server(sport, saddress);

                        server.Start();

                        break;

                    case "h":
                    case "?":

                        ShowHelp();
                        break;

                    default:

                        Console.WriteLine("непонятная команда");
                        ShowHelp();

                        break;
                    }
                }
            }

            //todo do it better way
            if (!isNetworkMode)
            {
                if (!string.IsNullOrEmpty(ie.TaskFile))
                {
                    ie.Tasks = CSVFile.ReadCsvFile(ie.TaskFile);
                }

                if (ie.Method.Equals("wmi"))
                {
                    finder = new WMI(true, ie);
                }
                else if (ie.Method.Equals("ws"))
                {
                    //finder = new WindowsSearch(true);
                    finder = new WMI(true, ie);
                }
                else if (ie.Method.Equals("cmp"))
                {
                    CompareFiles(ie);
                    return;
                }

                if (ie.Tasks != null)
                {
                    foreach (TaskEntity task in ie.Tasks)
                    {
                        FileName = string.Format(
                            "{0}{1}-{2}-{3}.csv",
                            (!string.IsNullOrEmpty(ie.OutputFolder)) ? ie.OutputFolder : "",
                            task.Name,
                            DateTime.Now.ToString().Replace(":", "-"),
                            ie.Method);

                        CSVFile.WriteCsvFile(FileName, finder.Search(task));
                    }
                }
                else
                {
                    FileName = string.Format(
                        "{0}{1}-{2}-{3}.csv",
                        (!string.IsNullOrEmpty(ie.OutputFolder)) ? ie.OutputFolder : "",
                        Environment.MachineName,
                        DateTime.Now.ToString().Replace(":", "-"),
                        ie.Method);

                    CSVFile.WriteCsvFile(FileName, finder.Search("C:\\", "exe", "."));
                    //WriteCsvFile(FileName, finder.Search("D:\\projects\\ImAgent\\bin\\Debug\\netcoreapp3.1\\", "exe", "."));
                }
            }
        }