示例#1
0
        public static ScriptCode Create(string script, CryptoManager manager)
        {
            try
            {
                var resultScript = new ScriptCode(script);
                if (resultScript.Read(manager))
                {
                    return(resultScript);
                }

                return(null);
            }
            catch (Exception ex)
            {
                throw new Exception("The script could not be created.", ex);
            }
        }
示例#2
0
        private bool Read(CryptoManager manager)
        {
            try
            {
                if (String.IsNullOrEmpty(OriginalScript))
                {
                    logger.Warn("The script is empty.");
                    return(false);
                }

                if (!OriginalScript.Trim().StartsWith(ExecuteName))
                {
                    logger.Warn($"The command {ExecuteName} was not found.");
                    return(false);
                }

                var text = OriginalScript.Trim().Replace("\r\n", "\n");
                Code = Regex.Replace(text, $"{ExecuteName}[^\n]*\n", "", RegexOptions.Singleline).Trim();
                if (Code.IndexOf(Algorithm) > -1)
                {
                    Code = Code.Substring(0, Code.IndexOf(Algorithm)).Trim();
                }

                if (manager != null)
                {
                    CreateSignature(manager, OriginalScript);
                }

                //Read parameters with JSON
                var args = Regex.Match(OriginalScript, $"{ExecuteName}\\((\\[[^\\]]+\\])\\)", RegexOptions.Singleline).Groups[1].Value;

                try
                {
                    Parameters = JsonConvert.DeserializeObject <List <string> >(args);
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "The script arguments could not be read in JSON.");
                }

                if (Parameters == null)
                {
                    Parameters = new List <string>();
                }

                //Generate name for qlik table
                TableName = Regex.Match(text, $"({ExecuteName}[^\\)]*\\))", RegexOptions.Singleline).Groups[1].Value;
                if (String.IsNullOrEmpty(TableName))
                {
                    TableName = ExecuteName;
                }

                logger.Warn("Step1");

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "The script could not be read.");
                return(false);
            }
        }