コード例 #1
0
        public static unsafe void PrintConsoleWarning(string message)
        {
            IntPtr ptrWarning = WinImports.GetProcAddress(WinImports.GetModuleHandle("Tier0.dll"), "Warning");

            FMsg warningFunction = (FMsg)Marshal.GetDelegateForFunctionPointer(ptrWarning, typeof(FMsg));

            sbyte *msg = MemoryManager.StringToChar(message + "\n");

            warningFunction(msg);
        }
コード例 #2
0
ファイル: ProxyService.cs プロジェクト: radtek/Freya
        private void RadioReceiver(object sender, ReceivedRequestEventArgs args)
        {
            FMsg fMsg = JsonConvert.DeserializeObject <FMsg>(args.Request);

            if (fMsg.Type.Equals("CMD"))
            {
                Console.WriteLine("Get CMD: " + fMsg.Data);
                switch (fMsg.Data)
                {
                case "SetIdleTime":
                    foreach (Worker w in Workers)
                    {
                        if (w != null)
                        {
                            w.SetIdleTime(Convert.ToDouble(fMsg.Data2));
                        }
                    }
                    args.Response = JsonConvert.SerializeObject(s);
                    break;

                case "GetWorkerStatus":
                    string workerstatus = "";
                    foreach (Worker w in Workers)
                    {
                        if (w != null)
                        {
                            if (w.Type == FConstants.WorkerType.CPU)
                            {
                                workerstatus += (w.isRunning)? "C:" : "c:";
                            }
                            else if (w.Type == FConstants.WorkerType.AMD)
                            {
                                workerstatus += (w.isRunning) ? "A:" : "a:";
                            }
                            else if (w.Type == FConstants.WorkerType.nVidia)
                            {
                                workerstatus += (w.isRunning) ? "N:" : "n:";
                            }

                            workerstatus = workerstatus + w.Message + "\n";
                        }
                    }

                    args.Response = workerstatus;
                    break;

                case "MinerDisable":
                    foreach (Worker w in Workers)
                    {
                        if (w != null)
                        {
                            w.Enable = false;
                        }
                    }
                    s.MinerEnable = false;
                    args.Response = JsonConvert.SerializeObject(s);
                    break;

                case "MinerEnable":
                    foreach (Worker w in Workers)
                    {
                        if (w != null)
                        {
                            w.Enable = true;
                        }
                    }
                    s.MinerEnable = true;
                    args.Response = JsonConvert.SerializeObject(s);
                    break;

                case "GetStatus":
                    for (int w = 0; w < Workers.Length; w++)
                    {
                        if (Workers[w] != null)
                        {
                            s.MinerIsActive[w] = Workers[w].isRunning;
                        }
                        else
                        {
                            s.MinerIsActive[w] = false;
                        }
                    }
                    logger.WriteLine($"[Service] s.MinerIsActive {s.MinerIsActive[0]}|{s.MinerIsActive[1]}|{s.MinerIsActive[2]}");
                    args.Response = JsonConvert.SerializeObject(s);
                    break;

                case "SetUIPort":
                    s.UIPort = Convert.ToInt32(fMsg.Data2);
                    radioClient.SetPort(s.UIPort);
                    FFunc.SetRegKey("FreyaUIPort", s.UIPort);
                    logger.WriteLine($"[Service] Receive UI Port at {s.UIPort}");
                    args.Response = JsonConvert.SerializeObject(s);
                    break;

                case "RadioTest":
                    string ss = radioClient.Send(JsonConvert.SerializeObject(new FMsg {
                        Type = "MSG", Data = $"Service to UI radio test ... [Service Server Port {radioServer.Port}], [UI Port {radioClient.GetPort()}]", Loglevel = FConstants.FreyaLogLevel.FreyaInfo
                    }));
                    args.Response = $"[Service] s.MinerIsActive {s.MinerIsActive[0]}|{s.MinerIsActive[1]}|{s.MinerIsActive[2]}";
                    logger.WriteLine($"[Service] RadioTest sUIPort: {s.UIPort}, GetPort:{radioClient.GetPort()}");
                    break;

                case "StartProxy":
                    StartProxies();
                    args.Response = "OK";
                    break;

                case "StopProxy":
                    StopProxies();
                    args.Response = "OK";
                    break;

                case "WriteRegistry":
                    if (fMsg.Data2.Length > 0)
                    {
                        RegSetting.SetSettingsToRegisry(fMsg.Data2);
                        args.Response = "OK";
                        logger.WriteLine("[Service] Options writed to registry.");
                    }
                    else
                    {
                        args.Response = "NG";
                    }
                    s.UpdateMinerSwitch();

                    foreach (Worker w in Workers)
                    {
                        if (w != null)
                        {
                            w.AlwaysRun = RegSetting.hasRight(FConstants.FeatureByte.AlwaysRun) ? true : false;
                        }
                    }

                    string strbuf = "";
                    foreach (bool s in s.MinerSwitch)
                    {
                        strbuf = strbuf + s.ToString() + " |";
                    }
                    logger.WriteLine($"[Service] WorkerSwitch : {strbuf}");
                    break;

                default:
                    args.Response = "SCNG";
                    break;
                }
            }
            else
            {
                args.Response = "SCNG1";
            }

            args.Handled = true;
        }