Exemple #1
0
        public static string GetEntryPointToStartModeling(Dictionary <string, string> options)
        {
            byte[] subjectArray = Encoding.UTF8.GetBytes(options["subject"]);
            byte[] nameOfModel  = Encoding.UTF8.GetBytes(options["model"]);

            byte[] requestLine = new byte[subjectArray.Length + 4 + 4 + nameOfModel.Length];

            requestLine[0] = subjectArray.Length == 7 ? (byte)7 : (byte)8;
            requestLine[1] = 0;
            requestLine[2] = 0;
            requestLine[3] = 0;
            int k = 4;

            foreach (byte i in subjectArray)
            {
                requestLine[k] = i;
                k++;
            }
            UInt32 val = (UInt32)nameOfModel.Length;

            requestLine[k++] = (byte)(val & 0xff);
            requestLine[k++] = (byte)((val >> 8) & 0xff);
            requestLine[k++] = (byte)((val >> 16) & 0xff);
            requestLine[k++] = (byte)((val >> 24) & 0xff);
            foreach (byte i in nameOfModel)
            {
                requestLine[k] = i;
                k++;
            }

            IntPtr in_params = Marshal.AllocHGlobal(requestLine.Length);

            Marshal.Copy(requestLine, 0, in_params, requestLine.Length);


            uint   out_byte_count;
            IntPtr out_params;
            uint   a = ControlSystemEntryPoint(3, in_params, (uint)requestLine.Length, out out_params, out out_byte_count);


            if (a == 0)
            {
                Marshal.FreeHGlobal(in_params);
                byte[] temp = new byte[out_byte_count];
                Marshal.Copy(out_params, temp, 0, (int)out_byte_count);
                string process = Encoding.UTF8.GetString(temp);
                ProcessKeeper.WriteNewProcess(new Tuple <string, string>(process, options["subject"]));
                return(process);
            }
            else
            {
                uint   pSize;
                IntPtr error  = ControlSystemGetErrorDescription(a, out pSize);
                var    result = Marshal.PtrToStringUTF8(error);
                return(result);
            }
        }
Exemple #2
0
        private static string GetEntryPointToCheckStatus(Request request)
        {
            byte[] nameOfProcess       = Encoding.UTF8.GetBytes(request.Parameters["process"]);
            byte[] nameOfProcessLength = BitConverter.GetBytes(nameOfProcess.Length);
            byte[] requestLine         = new byte[nameOfProcessLength.Length + nameOfProcess.Length];

            int k = 0;

            foreach (byte i in nameOfProcessLength)
            {
                requestLine[k] = i;
                k++;
            }
            foreach (byte i in nameOfProcess)
            {
                requestLine[k] = i;
                k++;
            }

            IntPtr in_params = Marshal.AllocHGlobal(requestLine.Length);

            Marshal.Copy(requestLine, 0, in_params, requestLine.Length);
            uint   out_byte_count;
            IntPtr out_params;
            uint   a = ControlSystemEntryPoint(4, in_params, (uint)requestLine.Length, out out_params, out out_byte_count);

            if (a == 0)
            {
                Marshal.FreeHGlobal(in_params);
                byte[] temp = new byte[out_byte_count];
                Marshal.Copy(out_params, temp, 0, (int)out_byte_count);

                Console.WriteLine(Encoding.Default.GetString(temp));
                if (temp[0].ToString() == "0")
                {
                    return("Процесс с заданным именем не существует");
                }
                else if (temp[0].ToString() == "1")
                {
                    return($"{DateTime.Now} - процесс выполняется");
                }
                else if (temp[0].ToString() == "2")
                {
                    Tuple <byte[], string> result = GetEntryPointToGetResult(request);
                    if (result.Item1 != null)
                    {
                        string status = WriteToFile(result.Item1, request);

                        if (status == "Failed to write to file")
                        {
                            return(status);
                        }

                        if (ProcessKeeper.GetSubjectAreaOfProcess(request.Parameters["process"]) == "radio_hf")
                        {
                            GetImage(request.Parameters["process"]);
                            return(request.Headers["Host"] + "/" + $"{request.Parameters["process"]}.resultsbmp");
                        }
                        else
                        {
                            return(request.Headers["Host"] + "/" + $"{request.Parameters["process"]}.results");
                        }
                    }
                    else
                    {
                        return(result.Item2);
                    }
                }

                else
                {
                    return("Unknown error");
                }
            }
            else
            {
                uint   pSize;
                IntPtr error  = ControlSystemGetErrorDescription(a, out pSize);
                var    result = Marshal.PtrToStringUTF8(error);
                return(result);
            }
        }