Service.WindowsService.DoWork C# (CSharp) Method

DoWork() public method

public DoWork ( string Program, string Input, string Compiler_args, win Language ) : Result
Program string
Input string
Compiler_args string
Language win
return Service.win.Result
        public win.Result DoWork(string Program, string Input, string Compiler_args, win.Languages Language)
        {
            using (var service = new win.Service())
            {
                try
                {
                    bool ProgramCompressed = false;
                    if (!string.IsNullOrEmpty(Program) && Program.Length > 1000)
                    {
                        ProgramCompressed = true;
                        Program = GlobalUtils.Utils.Compress(Program);
                    }
                    bool InputCompressed = false;
                    if (!string.IsNullOrEmpty(Input) && Input.Length > 1000)
                    {
                        InputCompressed = true;
                        Input = GlobalUtils.Utils.Compress(Input);
                    }

                    bool bytes = true;
                    var res = service.DoWork(Program, Input, Language, GlobalUtils.TopSecret.Service_user, GlobalUtils.TopSecret.Service_pass, Compiler_args, bytes, ProgramCompressed, InputCompressed);

                    if (bytes)
                    {
                        if (res.Errors_Bytes != null)
                            res.Errors = System.Text.Encoding.Unicode.GetString(res.Errors_Bytes);
                        if (res.Warnings_Bytes != null)
                            res.Warnings = System.Text.Encoding.Unicode.GetString(res.Warnings_Bytes);
                        if (res.Output_Bytes != null)
                            res.Output = System.Text.Encoding.Unicode.GetString(res.Output_Bytes);
                    }
                    if (res.IsOutputCompressed)
                        res.Output = GlobalUtils.Utils.Decompress(res.Output);

                    return res;
                }
                catch (Exception ex)
                {
                    return new win.Result()
                    {
                        System_Error = string.Format("Error while calling service: {0}", ex.Message)
                    };
                }
            }
        }

Usage Example

Example #1
0
        static RundotnetData RunWindows(RundotnetData data)
        {
            WindowsService service = new WindowsService();
            Service.win.Languages lang = Service.win.Languages.VCPP;

            switch (data.LanguageChoice)
            {
                case LanguagesEnum.VCPP:
                    lang = Service.win.Languages.VCPP;
                    break;
                case LanguagesEnum.VC:
                    lang = Service.win.Languages.VC;
                    break;
                default:
                    break;
            }
            Stopwatch watch = new Stopwatch();
            watch.Start();
            var res = service.DoWork(data.Program, data.Input, data.CompilerArgs, lang);
            watch.Stop();
            if (res != null)
            {
                if (string.IsNullOrEmpty(res.Stats))
                    res.Stats = "";
                else
                    res.Stats += ", ";
                res.Stats += string.Format("absolute service time: {0} sec", Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2));
                data.RunStats = res.Stats;
            }
            bool logged = false;
            if (!string.IsNullOrEmpty(res.System_Error))
            {
                reExp.Utils.Log.LogInfo("Windows " + res.System_Error, null, "RunDotNet");
                data.Errors.Add(res.System_Error);
                Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Windows: system error", (int)data.LanguageChoice, data.IsApi, false);
                return data;
            }
            if (!string.IsNullOrEmpty(res.Errors))
            {
                data.Errors.Add(res.Errors);
                if (!logged)
                {
                    Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Windows: error", (int)data.LanguageChoice, data.IsApi, false);
                    logged = true;
                }
            }
            if (res.Exit_Code < 0)
            {
                data.Errors.Add(res.Exit_Status);
                if (!logged)
                {
                    Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Windows: negative exit code", (int)data.LanguageChoice, data.IsApi, false);
                    logged = true;
                }
            }
            if (!string.IsNullOrEmpty(res.Warnings))
            {
                data.Warnings.Add(res.Warnings);
                if (!logged)
                {
                    Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Windows: warnings", (int)data.LanguageChoice, data.IsApi, true);
                    logged = true;
                }
            }
            data.Output = res.Output;
            if (res.Files != null)
            {
                data.Files = new List<string>();
                foreach (var f in res.Files)
                {
                    data.Files.Add(Convert.ToBase64String(f));
                }
            }
            if (!logged)
            {
                Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Windows: ok", (int)data.LanguageChoice, data.IsApi, true);
                logged = true;
            }
            return data;
        }