static void Main(string[] args)
        {
            try
            {
                int chose = 9;
                StartClient sc = new StartClient();
                while (chose != 0)
                {
                    Console.WriteLine("1.Total Space \n 2.Free Space \n 0.Exit");
                    chose = Convert.ToInt32(Console.ReadLine());
                    switch (chose)
                    {
                        case 1:
                            {
                            Console.WriteLine("Enter disk Letter");
                                string name = Console.ReadLine();
                                Console.WriteLine(sc.TotalSpace(name));
                            }
                            break;
                        case 2:
                            {
                                Console.WriteLine("Enter disk Letter");
                                string name = Console.ReadLine();
                                Console.WriteLine(sc.FreeSpace(name));
                            }
                            break;
                    }

                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #2
0
        static async Task Main()
        {
            if (File.Exists(ClientConfigPath) && File.Exists(DBConfigPath))
            {
                string ClientConfigJsonData = await File.ReadAllTextAsync(ClientConfigPath).ConfigureAwait(false);

                string DBConfigJsonData = await File.ReadAllTextAsync(DBConfigPath).ConfigureAwait(false);

                JsonSerializer.Deserialize <ClientConfig>(ClientConfigJsonData);
                JsonSerializer.Deserialize <DBConfig>(DBConfigJsonData);

                await StartClient.Start().ConfigureAwait(false);
            }
            else
            {
                if (!Directory.Exists(ConfigDirPath))
                {
                    Console.WriteLine("Config directory is not exist.");
                    Console.WriteLine("Create Config directory...");

                    Directory.CreateDirectory(ConfigDirPath);
                }

                JsonSerializerOptions SerializerOptions = new JsonSerializerOptions {
                    WriteIndented = true,
                    Encoder       = JavaScriptEncoder.Create(UnicodeRanges.All),
                };

                if (!File.Exists(ClientConfigPath))
                {
                    Console.WriteLine("ClientConfig file is not exist.");
                    Console.WriteLine("Please write ClientConfig file.");
                    Console.WriteLine("Writing ClientConfig file...");

                    string ClientConfigString = JsonSerializer.Serialize(new ClientConfig(), SerializerOptions);
                    await File.WriteAllTextAsync(ClientConfigPath, ClientConfigString).ConfigureAwait(false);
                }
                if (!File.Exists(DBConfigPath))
                {
                    Console.WriteLine("DBConfig file is not exist.");
                    Console.WriteLine("Please write DBConfig file.");
                    Console.WriteLine("Writing DBConfig file...");

                    string DBConfigString = JsonSerializer.Serialize(new DBConfig(), SerializerOptions);
                    await File.WriteAllTextAsync(DBConfigPath, DBConfigString).ConfigureAwait(false);
                }
            }
        }
Example #3
0
        public async Task <bool> StartClient(Guid socketAddress, ClientStartArgs clientStartArgs, string apiKey)
        {
            var client = new Client
            {
                ScriptName   = clientStartArgs.ScriptName,
                ScriptArgs   = clientStartArgs.ScriptArgs,
                IsRepoScript = false,
                Username     = clientStartArgs.Username,
                Password     = clientStartArgs.Password
            };

            if (clientStartArgs.Proxy != null)
            {
                client.UseProxy  = true;
                client.ProxyIp   = clientStartArgs.Proxy.Ip;
                client.ProxyPort = clientStartArgs.Proxy.Port;
                client.ProxyUser = clientStartArgs.Proxy.Username;
                client.ProxyPass = clientStartArgs.Proxy.Password;
            }

            var startClientPayload = new Payload
            {
                Type       = "start:client",
                Session    = apiKey,
                QuickStart = new QuickStart(client)
            };

            var startClient = new StartClient(socketAddress, startClientPayload);

            var content = new StringContent(JsonConvert.SerializeObject(startClient), Encoding.UTF8, MediaTypeNames.Application.Json);

            var request = CreateRequest(apiKey);

            request.Method     = HttpMethod.Post;
            request.RequestUri = new Uri(SendCommandUrl);
            request.Content    = content;

            var httpResponse = await _httpClient.SendAsync(request);

            return(httpResponse.IsSuccessStatusCode);
        }
Example #4
0
        static int Main(string[] argv)
        {
            bool        help        = false;
            bool        version     = false;
            bool        once        = false;
            StartClient startClient = StartClient.No;
            var         config      = new TypeCobolConfiguration();

            config.CommandLine = string.Join(" ", argv);
            var pipename = "TypeCobol.Server";

            var p = TypeCobolOptionSet.GetCommonTypeCobolOptions(config);

            //Add custom options for CLI
            p.Add(string.Format("USAGE\n {0} [OPTIONS]... [PIPENAME]\n VERSION:\n {1} \n DESCRIPTION: \n Run the TypeCObol parser server", PROGNAME, PROGVERSION));
            p.Add("k|startServer:",
                  "Start the server if not already started, and executes commandline.\n" + "By default the server is started in window mode\n" + "'{hidden}' hide the window.",
                  v =>
            {
                if ("hidden".Equals(v, StringComparison.InvariantCultureIgnoreCase))
                {
                    startClient = StartClient.HiddenWindow;
                }
                else
                {
                    startClient = StartClient.NormalWindow;
                }
            });
            p.Add("1|once", "Parse one set of files and exit. If present, this option does NOT launch the server.", v => once = (v != null));
            p.Add("h|help", "Output a usage message and exit.", v => help = (v != null));
            p.Add("V|version", "Output the version number of " + PROGNAME + " and exit.", v => version = (v != null));


            //Add DefaultCopies to running session
            var folder = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);

            config.CopyFolders.Add(folder + @"\DefaultCopies\");

            try {
                List <string> args;
                try {
                    args = p.Parse(argv);
                } catch (OptionException ex) {
                    return(exit(ReturnCode.FatalError, ex.Message));
                }

                if (help)
                {
                    p.WriteOptionDescriptions(Console.Out);
                    return(0);
                }
                if (version)
                {
                    Console.WriteLine(PROGVERSION);
                    return(0);
                }
                if (config.Telemetry)
                {
                    AnalyticsWrapper.Telemetry.DisableTelemetry = false; //If telemetry arg is passed enable telemetry
                }

                if (config.OutputFiles.Count == 0 && config.ExecToStep >= ExecutionStep.Generate)
                {
                    config.ExecToStep = ExecutionStep.SemanticCheck; //If there is no given output file, we can't run generation, fallback to SemanticCheck
                }
                if (config.OutputFiles.Count > 0 && config.InputFiles.Count != config.OutputFiles.Count)
                {
                    return(exit(ReturnCode.OutputFileError, "The number of output files must be equal to the number of input files."));
                }

                if (args.Count > 0)
                {
                    pipename = args[0];
                }


                //"startClient" will be true when "-K" is passed as an argument in command line.
                if (startClient != StartClient.No && once)
                {
                    pipename = "TypeCobol.Server";
                    using (NamedPipeClientStream namedPipeClient = new NamedPipeClientStream(pipename))
                    {
                        try {
                            namedPipeClient.Connect(100);
                        } catch (TimeoutException tEx) {
                            System.Diagnostics.Process          process   = new System.Diagnostics.Process();
                            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                            if (startClient == StartClient.NormalWindow)
                            {
                                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
                            }
                            else
                            {
                                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                            }
                            startInfo.FileName  = "cmd.exe";
                            startInfo.Arguments = @"/c " + folder + Path.DirectorySeparatorChar + "TypeCobol.CLI.exe";
                            process.StartInfo   = startInfo;
                            process.Start();

                            namedPipeClient.Connect(1000);
                        }

                        namedPipeClient.WriteByte(68);

                        ConfigSerializer configSerializer = new ConfigSerializer();
                        var configBytes = configSerializer.Serialize(config);

                        namedPipeClient.Write(configBytes, 0, configBytes.Length);
                        //Wait for the response "job is done"
                        var returnCode = namedPipeClient.ReadByte(); //Get running server ReturnCode
                        return(exit((ReturnCode)returnCode, ""));
                    }
                }

                //option -1
                else if (once)
                {
                    var returnCode = CLI.runOnce(config);
                    if (returnCode != ReturnCode.Success)
                    {
                        return(exit(returnCode, "Operation failled"));
                    }
                }
                else
                {
                    runServer(pipename);
                }
            }
            catch (Exception e) {
                AnalyticsWrapper.Telemetry.TrackException(e);
                return(exit(ReturnCode.FatalError, e.Message));
            }

            return(exit((int)ReturnCode.Success, "Success"));
        }
Example #5
0
        static int Main(string[] argv)
        {
            bool        help        = false;
            bool        version     = false;
            bool        once        = false;
            StartClient startClient = StartClient.No;
            var         config      = new Config();
            var         pipename    = "TypeCobol.Server";

            var p = new OptionSet()
            {
                "USAGE",
                "  " + PROGNAME + " [OPTIONS]... [PIPENAME]",
                "",
                "VERSION:",
                "  " + PROGVERSION,
                "",
                "DESCRIPTION:",
                "  Run the TypeCobol parser server.",
                { "k|startServer:", "Start the server if not already started, and executes commandline.\n" +
                  "By default the server is started in window mode\n" +
                  "'{hidden}' hide the window.", v =>
                  {
                      if ("hidden".Equals(v, StringComparison.InvariantCultureIgnoreCase))
                      {
                          startClient = StartClient.HiddenWindow;
                      }
                      else
                      {
                          startClient = StartClient.NormalWindow;
                      }
                  } },
                { "1|once", "Parse one set of files and exit. If present, this option does NOT launch the server.", v => once = (v != null) },
                { "i|input=", "{PATH} to an input file to parse. This option can be specified more than once.", v => config.InputFiles.Add(v) },
                { "o|output=", "{PATH} to an ouput file where to generate code. This option can be specified more than once.", v => config.OutputFiles.Add(v) },
                { "d|diagnostics=", "{PATH} to the error diagnostics file.", v => config.ErrorFile = v },
                { "s|skeletons=", "{PATH} to the skeletons files.", v => config.skeletonPath = v },
                { "a|autoremarks", "Enable automatic remarks creation while parsing and generating Cobol", v => config.AutoRemarks = true },
                { "hc|haltonmissingcopy=", "HaltOnMissingCopy will generate a file to list all the absent copies", v => config.HaltOnMissingCopyFilePath = v },
                { "ets|exectostep=", "ExecToStep will execute TypeCobol Compiler until the included given step (Scanner/0, Preprocessor/1, SyntaxCheck/2, SemanticCheck/3, Generate/4)", v => Enum.TryParse(v.ToString(), true, out config.ExecToStep) },
//				{ "p|pipename=",  "{NAME} of the communication pipe to use. Default: "+pipename+".", (string v) => pipename = v },
                { "e|encoding=", "{ENCODING} of the file(s) to parse. It can be one of \"rdz\"(this is the default), \"zos\", or \"utf8\". "
                  + "If this option is not present, the parser will attempt to guess the {ENCODING} automatically.",
                  v => config.Format = CLI.CreateFormat(v, ref config) },
                { "y|intrinsic=", "{PATH} to intrinsic definitions to load.\nThis option can be specified more than once.", v => config.Copies.Add(v) },
                { "c|copies=", "Folder where COBOL copies can be found.\nThis option can be specified more than once.", v => config.CopyFolders.Add(v) },
                { "dp|dependencies=", "Path to folder containing programs to load and to use for parsing a generating the input program.", v => config.Dependencies.Add(v) },
                { "h|help", "Output a usage message and exit.", v => help = (v != null) },
                { "V|version", "Output the version number of " + PROGNAME + " and exit.", v => version = (v != null) },
            };


            //Add DefaultCopies to running session
            var folder = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);

            config.CopyFolders.Add(folder + @"\DefaultCopies\");

            try {
                List <string> args;
                try {
                    args = p.Parse(argv);
                } catch (OptionException ex) {
                    return(exit(1, ex.Message));
                }

                if (help)
                {
                    p.WriteOptionDescriptions(Console.Out);
                    return(0);
                }
                if (version)
                {
                    Console.WriteLine(PROGVERSION);
                    return(0);
                }
                if (config.OutputFiles.Count == 0 && config.ExecToStep >= ExecutionStep.Generate)
                {
                    config.ExecToStep = ExecutionStep.SemanticCheck; //If there is no given output file, we can't run generation, fallback to SemanticCheck
                }
                if (config.OutputFiles.Count > 0 && config.InputFiles.Count != config.OutputFiles.Count)
                {
                    return(exit(2, "The number of output files must be equal to the number of input files."));
                }

                if (args.Count > 0)
                {
                    pipename = args[0];
                }


                //"startClient" will be true when "-K" is passed as an argument in command line.
                if (startClient != StartClient.No && once)
                {
                    pipename = "TypeCobol.Server";
                    using (NamedPipeClientStream namedPipeClient = new NamedPipeClientStream(pipename))
                    {
                        try {
                            namedPipeClient.Connect(100);
                        } catch (TimeoutException tEx) {
                            System.Diagnostics.Process          process   = new System.Diagnostics.Process();
                            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                            if (startClient == StartClient.NormalWindow)
                            {
                                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
                            }
                            else
                            {
                                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                            }
                            startInfo.FileName  = "cmd.exe";
                            startInfo.Arguments = @"/c " + folder + Path.DirectorySeparatorChar + "TypeCobol.CLI.exe";
                            process.StartInfo   = startInfo;
                            process.Start();

                            namedPipeClient.Connect(1000);
                        }
                        namedPipeClient.WriteByte(68);


                        ConfigSerializer configSerializer = new ConfigSerializer();
                        var configBytes = configSerializer.Serialize(config);

                        namedPipeClient.Write(configBytes, 0, configBytes.Length);
                        //Wait for the response "job is done"
                        namedPipeClient.ReadByte();
                    }
                }

                //option -1
                else if (once)
                {
                    CLI.runOnce(config);
                }
                else
                {
                    runServer(pipename);
                }
            }
            catch (Exception e) {
                return(exit(1, e.Message));
            }
            return(0);
        }