Esempio n. 1
0
        private List <ConsolePrintNetParameter> GetParameters()
        {
            ActionAsked formerAction = ActionAsked.None;

            if (cbActions.SelectedItem != null && cbActions.SelectedItem is ActionAsked)
            {
                formerAction = (ActionAsked)cbActions.SelectedItem;
            }
            Helper.SetSafeComboBox(cbActions, ActionAsked.ParametersFields);
            string resultJson = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ConsoleExeName, $"{ConsoleExeName}Result.json");

            Helper.SetSafeText(cbOutputFormat, OutputFormatEnum.JsonFile.ToString() + "=" + resultJson);
            try
            {
                RunCommand();
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message);
            }
            finally
            {
                if (formerAction != ActionAsked.None)
                {
                    Helper.SetSafeComboBox(this.cbActions, formerAction);
                }
            }

            List <ConsolePrintNetParameter> list = new List <ConsolePrintNetParameter>();

            if (File.Exists(resultJson))
            {
                object  rawObject     = JsonConvert.DeserializeObject(File.ReadAllText(resultJson));
                JObject resultJObject = rawObject as JObject;
                JArray  array         = resultJObject["parameters"]?.Value <JArray>();
                if (array != null)
                {
                    foreach (JToken item in array)
                    {
                        bool?hasDefaultValue           = item["hasDefaultValue"]?.Value <bool>();
                        ConsolePrintNetParameter param = new ConsolePrintNetParameter(item["name"]?.Value <string>(), item["promptText"]?.Value <string>());
                        if (!hasDefaultValue.HasValue || (hasDefaultValue.HasValue && !hasDefaultValue.Value))
                        {
                            list.Add(param);
                        }
                    }
                }
            }
            else
            {
                Logger.Log($"File result {resultJson} doesn't exist");
            }

            return(list);
        }
Esempio n. 2
0
        private static ActionAsked SafeEnumParse(string action)
        {
            ActionAsked result = ActionAsked.None;

            try
            {
                result = (ActionAsked)Enum.Parse(typeof(ActionAsked), action);
            }
            catch (Exception)
            {
                Logger.Log($"Cannot parse value {action}. Possible values: {Enum.GetValues(typeof(ActionAsked))} . ");
            }
            return(result);
        }
Esempio n. 3
0
        private bool GetConfigurationInfo()
        {
            bool        result       = false;
            ActionAsked formerAction = ActionAsked.None;

            if (cbActions.SelectedItem != null && cbActions.SelectedItem is ActionAsked)
            {
                formerAction = (ActionAsked)cbActions.SelectedItem;
            }
            Helper.SetSafeComboBox(cbActions, ActionAsked.PrintServerInfo);
            string currentReportName = GetWorkspaceFilename() != null?Path.GetFileNameWithoutExtension(GetWorkspaceFilename()) : ConsoleExeName;

            string resultJsonFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ConsoleExeName, $"{currentReportName}Result.json");

            Helper.SetSafeText(cbOutputFormat, OutputFormatEnum.JsonFile.ToString() + "=" + resultJsonFile);
            linkLabelJSon.Tag = resultJsonFile;

            try
            {
                RunCommand();
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message);
            }
            finally
            {
                if (formerAction != ActionAsked.None)
                {
                    Helper.SetSafeComboBox(this.cbActions, formerAction);
                }
            }

            if (File.Exists(resultJsonFile))
            {
                result = true;
                ReadConfigurationInfoFile(resultJsonFile);
                configurationInfoInitialized = true;
            }
            else
            {
                Logger.Log($"File result {resultJsonFile} doesn't exist");
            }
            return(result);
        }