Exemple #1
0
        public override async void Start(FrameBase frameBase)
        {
            var frame = frameBase as RequestFrame;

            if (frame == null)
            {
                return;
            }

            AnswerFrame answerFrame = await GatherInformation(frame).ConfigureAwait(false);

            await SendFrame(answerFrame).ConfigureAwait(false);
        }
Exemple #2
0
        public override async void Start(FrameBase frameBase)
        {
            var frame = frameBase as RequestFrame;

            if (frame == null)
            {
                return;
            }

            AnswerFrame answerFrame = new AnswerFrame(frame.Guid);

            try
            {
                string pipeName = Guid.NewGuid().ToString();
                if (!Tools.Session.CreateProcess(Tools.Program.CommandlineCamera(pipeName, 5000), Environment.CurrentDirectory))
                {
                    throw new Exception("无法创建捕获进程。");
                }

                using (System.IO.Pipes.NamedPipeClientStream pipeStream = new System.IO.Pipes.NamedPipeClientStream(pipeName))
                    using (MemoryStream ms = new MemoryStream())
                    {
                        pipeStream.Connect(2000);
                        await pipeStream.CopyToAsync(ms).ConfigureAwait(false);

                        answerFrame.BytesJpeg = ms.ToArray();

                        if (answerFrame.BytesJpeg.Length == 0)
                        {
                            throw new Exception("当前环境不支持此操作。");
                        }
                        await SendFrame(answerFrame).ConfigureAwait(false);
                    }
            }
            catch (Exception ex)
            {
                await SendError(frame, ex.Message).ConfigureAwait(false);
            }
        }
Exemple #3
0
        protected async Task <AnswerFrame> GatherInformation(RequestFrame req)
        {
            AnswerFrame frame = new AnswerFrame(req.Guid);

            //Version
            frame.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString() + "C" + (Common.Configs.Debug ? " DEBUG" : "");

            //GPU
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                var lines = await Utils.ExecuteResultsAsync("wmic", "", new string[] { "path Win32_VideoController get Name", "exit" }, 1000).ConfigureAwait(false);

                if (lines != null && lines.Count > 2)
                {
                    for (int i = 2; i < lines.Count - 1; i++)
                    {
                        if (!string.IsNullOrWhiteSpace(lines[i]))
                        {
                            frame.Gpus.Add(lines[i]);
                        }
                    }
                }
                else
                {
                    frame.Gpus.Add("None");
                }
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                //TODO
                frame.Gpus.Add("Unsupported");
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                //TODO
                frame.Gpus.Add("Unsupported");
            }
            else
            {
                //TODO
                frame.Gpus.Add("Unsupported");
            }

            //CPU
            string cpu = "Unsupported.";

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                var lines = await Utils.ExecuteResultsAsync("wmic", "", new string[] { "cpu get Name", "exit" }, 1000).ConfigureAwait(false);

                if (lines != null && lines.Count > 2)
                {
                    cpu = lines[2];
                }
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                string cpu0 = await Utils.MatchFileContentAsync("/proc/cpuinfo", new Regex("^model name\\s*:\\s*(.+?)$", RegexOptions.Compiled | RegexOptions.Multiline));

                if (!string.IsNullOrEmpty(cpu0))
                {
                    cpu = cpu0;
                }
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                //TODO
            }

            for (int i = 0; i < Environment.ProcessorCount; i++)
            {
                frame.Cpus.Add(cpu);
            }

            //主机名
            frame.ComputerName = Environment.MachineName;

            //物理内存
            frame.Memory = 0;
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                var lines = await Utils.ExecuteResultsAsync("wmic", "", new string[] { "memorychip get Capacity", "exit" }, 1000).ConfigureAwait(false);

                if (lines != null && lines.Count > 2)
                {
                    for (int i = 2; i < lines.Count - 1; i++)
                    {
                        ulong memory;
                        if (ulong.TryParse(lines[i], out memory))
                        {
                            frame.Memory += memory;
                        }
                    }
                }
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                string mem = await Utils.MatchFileContentAsync("/proc/meminfo", new Regex("^MemTotal\\s*:\\s*(.+)$", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase));

                if (!string.IsNullOrEmpty(mem))
                {
                    mem = mem.TrimEnd();
                    if (mem.EndsWith("KB", StringComparison.CurrentCultureIgnoreCase))
                    {
                        frame.Memory = ulong.Parse(mem.Substring(0, mem.Length - 2)) * 1024;
                    }
                }
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                //TODO
            }

            //操作系统
            frame.Os = RuntimeInformation.OSDescription;

            //标识符
            try
            {
                using (FileStream fs = new FileStream("id.bin", FileMode.OpenOrCreate))
                {
                    byte[] value = new byte[16];
                    int    count = fs.Read(value, 0, 16);
                    if (count != 16)
                    {
                        value = Guid.NewGuid().ToByteArray();
                        fs.SetLength(16);
                        fs.Position = 0;
                        fs.Write(value);
                    }

                    frame.Identifier = new Guid(value);
                }
            }
            catch
            {
                frame.Identifier = Guid.NewGuid();
            }

            return(frame);
        }
Exemple #4
0
        protected AnswerFrame GatherInformation(RequestFrame req)
        {
            AnswerFrame frame = new AnswerFrame(req.Guid);

            //Version
            frame.Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + (Common.Configs.Debug ? " DEBUG" : "");

            //GPU
            using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Caption FROM Win32_VideoController"))
            {
                foreach (ManagementObject obj in searcher.Get())
                {
                    string gpu = obj.GetPropertyValue("Caption") as string;
                    frame.Gpus.Add(gpu);
                }
            }

            //CPU
            using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Name, NumberOfCores FROM Win32_Processor"))
            {
                foreach (ManagementObject obj in searcher.Get())
                {
                    string cpu   = obj.GetPropertyValue("Name") as string;
                    uint   cores = (uint)obj.GetPropertyValue("NumberOfCores");
                    for (int i = 0; i < cores; i++)
                    {
                        frame.Cpus.Add(cpu);
                    }
                }
            }

            //物理内存
            using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Name, TotalPhysicalMemory FROM Win32_ComputerSystem"))
            {
                foreach (ManagementObject obj in searcher.Get())
                {
                    frame.ComputerName = obj.GetPropertyValue("Name") as string;
                    frame.Memory       = (ulong)obj.GetPropertyValue("TotalPhysicalMemory");
                }
            }

            //操作系统
            using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Name FROM Win32_OperatingSystem"))
            {
                foreach (ManagementObject obj in searcher.Get())
                {
                    frame.Os = obj.GetPropertyValue("Name") as string;
                    frame.Os = frame.Os.Split('|')[0];
                }
            }

            //标识符
            if (Common.Configs.Debug)
            {
                frame.Identifier = Guid.NewGuid();
            }
            else
            {
                using (RegistryKey key = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\" + Assembly.GetExecutingAssembly().GetName().Name))
                {
                    byte[] value = key.GetValue("Identifier") as byte[];
                    if (value == null || value.Length != 16)
                    {
                        value = Guid.NewGuid().ToByteArray();
                        key.SetValue("Identifier", value);
                    }

                    frame.Identifier = new Guid(value);
                }
            }

            return(frame);
        }
Exemple #5
0
 public ClientData(Server server, TcpClient client, AnswerFrame information)
     : base(server, client)
 {
     Information = information;
 }