Ejemplo n.º 1
0
        public static void Deal(string content)
        {
            bool success = JsonUtil.ParseStruct <OperationStruct>(content, out OperationStruct os);

            if (success)
            {
                switch (os.type)
                {
                case OperationType.Add:
                    OperationClerk.AddProcess(os.pathName);
                    break;

                case OperationType.Remove:
                    OperationClerk.RemoveProcess(os.pathName);
                    break;

                case OperationType.Start:
                    OperationClerk.StartProcess(os.pathName, os.args);
                    break;

                case OperationType.Stop:
                    OperationClerk.StopProcess(os.pathName);
                    break;

                default:
                    LogClerk.Warn("Invalid OperationType.");
                    break;
                }
            }
        }
Ejemplo n.º 2
0
 public static bool ParseStruct <T>(string content, out T sdu)
 {
     try
     {
         sdu = JsonConvert.DeserializeObject <T>(content);
         return(true);
     }
     catch (JsonException e)
     {
         LogClerk.Warn($"Deserialize object failed: {e.Message}");
         sdu = default;
         return(false);
     }
 }
Ejemplo n.º 3
0
 public bool RemoveNurseryItem(string pathName)
 {
     foreach (ToolStripItem item in NurseryMenu.DropDownItems)
     {
         if (item.ToolTipText != null && item.ToolTipText.Equals(pathName))
         {
             BeginInvoke(new CrossThreadDelegate(() =>
             {
                 NurseryMenu.DropDownItems.Remove(item);
             }));
             LogClerk.Info($"Removed {pathName}");
             return(true);
         }
     }
     LogClerk.Warn($"Menu item not exit while removing it: {pathName}");
     return(false);
 }
Ejemplo n.º 4
0
        public static void Deal(string content)
        {
            bool success = JsonUtil.ParseStruct <NurseryStruct>(content, out NurseryStruct ns);

            if (success)
            {
                switch (ns.type)
                {
                case NurseryType.Setting:
                    DealWithConfig(ns.content);
                    break;

                case NurseryType.Operation:
                    OperationClerk.Deal(ns.content);
                    break;

                default:
                    LogClerk.Warn($"Invalid nursery type. {content}");
                    break;
                }
            }
        }
Ejemplo n.º 5
0
        public static void Send(object sdu)
        {
            NurseryStruct?pdu = null;

            switch (sdu)
            {
            case OperationStruct os:
                pdu = PDU(NurseryType.Operation, JsonConvert.SerializeObject(os));
                break;

            case Dictionary <int, InformationStruct> lis:
                pdu = PDU(NurseryType.Information, JsonConvert.SerializeObject(lis));
                break;

            default:
                LogClerk.Warn("Invalid nursery SDU type.", 2);
                break;
            }
            if (pdu != null)
            {
                MessageManager.Send(pdu);
            }
        }