示例#1
0
        public void HandleMessage(JSONStatus jsonStatus)
        {
            switch (jsonStatus.Status)
            {
            case JSONStatus.StatusTypes.Opened:
                Status = StatusTypes.Connected;
                break;

            case JSONStatus.StatusTypes.Waiting:
                SendNextStep();
                break;

            case JSONStatus.StatusTypes.Ready:
                MainWindow.RunCompleted();
                break;

            case JSONStatus.StatusTypes.Stopped:

                break;
            }
        }
示例#2
0
        /// <summary>
        /// Load Colors from Config File.
        /// </summary>
        /// <returns></returns>
        internal static bool LoadConfig(bool refresh = false)
        {
            bool missingColumn = false;
            bool retVal        = true;

            if (!Directory.Exists("Data"))
            {
                Directory.CreateDirectory("Data");
            }

            DataTable dt = GetConfigData(refresh);

            if (dt != null)
            {
                //validate all columns exists
                foreach (string colum in Defs.ConfigColumnNames)
                {
                    if (!dt.Columns.Contains(colum))
                    {
                        Log.Error($"Missing column: {colum} in {TABLE_NAMES.Configuration} from:\n {DataFile}");
                        missingColumn = true;
                        break;
                    }
                }
            }

            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];

                // ##### ConnectionTimeoutSec #####
                if (GetField <int>(dr, "ConnectionTimeoutSec", out int connectionTimeout))
                {
                    if (connectionTimeout > 60)
                    {
                        connectionTimeout = 60;
                    }
                    else if (connectionTimeout < 5)
                    {
                        connectionTimeout = 5;
                    }

                    Defs.ConnectionTimeout = TimeSpan.FromSeconds(connectionTimeout);
                }
                else
                {
                    missingColumn = true;
                }

                // ##### ConnectionTimeoutSec #####
                if (GetField <string>(dr, "TextEditor", out string textEditor))
                {
                    Defs.TextEditor = textEditor;
                }
                else
                {
                    missingColumn = true;
                }

                // ##### DirectoryColor #####
                if (GetField <ConsoleColor>(dr, "DirectoryColor", out ConsoleColor directoryColor))
                {
                    Log.Directories = directoryColor;
                }
                else
                {
                    missingColumn = true;
                }


                // ##### StickyColor #####
                if (GetField <ConsoleColor>(dr, "StickyColor", out ConsoleColor stickyColor))
                {
                    Log.Sticky = stickyColor;
                }
                else
                {
                    missingColumn = true;
                }


                // ##### FullPermissionsBGColor #####
                if (GetField <ConsoleColor>(dr, "FullPermissionsBGColor", out ConsoleColor fullPermissionsBGColor))
                {
                    Log.FullPermissionsBG = fullPermissionsBGColor;
                }
                else
                {
                    missingColumn = true;
                }


                // ##### FullPermissionsFGColor #####
                if (GetField <ConsoleColor>(dr, "FullPermissionsFGColor", out ConsoleColor fullPermissionsFGColor))
                {
                    Log.FullPermissionsFG = fullPermissionsFGColor;
                }
                else
                {
                    missingColumn = true;
                }


                // ##### BlockSpecialFileColor #####
                if (GetField <ConsoleColor>(dr, "BlockSpecialFileColor", out ConsoleColor blockSpecialFileColor))
                {
                    Log.BlockSpecialFile = blockSpecialFileColor;
                }
                else
                {
                    missingColumn = true;
                }


                // ##### CharacterSpecialFileColor #####
                if (GetField <ConsoleColor>(dr, "CharacterSpecialFileColor", out ConsoleColor characterSpecialFileColor))
                {
                    Log.CharacterSpecialFile = characterSpecialFileColor;
                }
                else
                {
                    missingColumn = true;
                }


                // ##### SymbolicLinkColor #####
                if (GetField <ConsoleColor>(dr, "SymbolicLinkColor", out ConsoleColor symbolicLinkColor))
                {
                    Log.SymbolicLink = symbolicLinkColor;
                }
                else
                {
                    missingColumn = true;
                }


                // ##### PromptColor #####
                if (GetField <ConsoleColor>(dr, "PromptColor", out ConsoleColor promptColor))
                {
                    Log.Prompt = promptColor;
                }
                else
                {
                    missingColumn = true;
                }
            }
            else
            {
                missingColumn = true;
            }

            if (missingColumn)
            {
                if (dt != null)
                {
                    ConfigData.DropTable(dt);
                }

                List <JSONWorker.FIELD_VALUE> fieldValues = new List <JSONWorker.FIELD_VALUE>();
                fieldValues.Add(new JSONWorker.FIELD_VALUE {
                    FieldName = "ConnectionTimeoutSec", Value = $"{Defs.ConnectionTimeout.TotalSeconds}"
                });
                fieldValues.Add(new JSONWorker.FIELD_VALUE {
                    FieldName = "TextEditor", Value = $"{Defs.TextEditor}"
                });
                fieldValues.Add(new JSONWorker.FIELD_VALUE {
                    FieldName = "DirectoryColor", Value = $"{Log.Directories}"
                });
                fieldValues.Add(new JSONWorker.FIELD_VALUE {
                    FieldName = "StickyColor", Value = $"{Log.Sticky}"
                });
                fieldValues.Add(new JSONWorker.FIELD_VALUE {
                    FieldName = "FullPermissionsBGColor", Value = $"{Log.FullPermissionsBG}"
                });
                fieldValues.Add(new JSONWorker.FIELD_VALUE {
                    FieldName = "FullPermissionsFGColor", Value = $"{Log.FullPermissionsFG}"
                });
                fieldValues.Add(new JSONWorker.FIELD_VALUE {
                    FieldName = "BlockSpecialFileColor", Value = $"{Log.BlockSpecialFile}"
                });
                fieldValues.Add(new JSONWorker.FIELD_VALUE {
                    FieldName = "CharacterSpecialFileColor", Value = $"{Log.CharacterSpecialFile}"
                });
                fieldValues.Add(new JSONWorker.FIELD_VALUE {
                    FieldName = "SymbolicLinkColor", Value = $"{Log.SymbolicLink}"
                });
                fieldValues.Add(new JSONWorker.FIELD_VALUE {
                    FieldName = "PromptColor", Value = $"{Log.Prompt}"
                });

                //provide all possible colors in config, so user changing config, knows which colors to choose from.
                StringBuilder sb = new StringBuilder();
                foreach (string name in Enum.GetNames(typeof(ConsoleColor)))
                {
                    if (sb.Length > 0)
                    {
                        sb.Append(", ");
                    }
                    sb.Append(name);
                }
                fieldValues.Add(new JSONWorker.FIELD_VALUE {
                    FieldName = "AvailableColors", Value = sb.ToString()
                });

                JSONStatus rs = ConfigData.UpdateRecord(TABLE_NAMES.Configuration.ToString(), fieldValues, null, true);
                if (rs.Status != RESULT_STATUS.OK)
                {
                    Log.Error(rs.Description);
                    retVal = false;
                }
            }

            //During startup only, we want to clear out the table
            //from this JSON and recreated it, when called apon.
            //This ensures any new commands to be displayed as well.
            DeleteInternalCommandsHelp();
            SyncTranslationData();

            return(retVal);
        }