Exemplo n.º 1
0
        protected virtual void Dispose(bool dispose)
        {
            if (_Instructions != null)
            {
                foreach (Instruction i in _Instructions)
                {
                    i.Exceptions.Clear();
                }

                foreach (Instruction i in _Instructions)
                {
                    try
                    {
                        i.Dispose();
                    }
                    catch { }
                }

                _Instructions.Clear();
            }

            InstructionSetContainer.Clear();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Used to replace tokens in a string from the searchSpace of interest
        ///
        /// e.g.
        ///
        /// Session["[CompanyX DBAddress]"] = "192.168.100.100"
        /// Session["[CompanyX DBUser]"] = "sa"
        ///
        /// string sqlConn = Server=[CompanyX DBAddress];Database=myDataBase;User Id=[CompanyX DBUser];
        /// sqlConn = ReplaceTokens(sqlConn, FailureAction.ThrowException, SearchSpace.Session)
        ///
        /// </summary>
        /// <param name="tokenizedString"></param>
        /// <param name="failureAction"></param>
        /// <param name="searchSpace"></param>
        /// <returns>String with tokens replaced</returns>
        protected string ReplaceTokens(string tokenizedString, FailureAction failureAction, SearchSpace searchSpace = SearchSpace.InstructionSetContainer | SearchSpace.Session | SearchSpace.Cache)
        {
            if (String.IsNullOrEmpty(tokenizedString))
            {
                throw new ArgumentNullException(nameof(tokenizedString));
            }

            string        xform  = tokenizedString;
            List <string> tokens = new List <string>();

            foreach (Match m in _Regex.Matches(tokenizedString))
            {
                tokens.Add(m.Value);
            }

            tokens = tokens.Distinct().ToList();

            foreach (string t in tokens.ToList())
            {
                if ((searchSpace & SearchSpace.InstructionSetContainer) != 0)
                {
                    if (InstructionSetContainer.ContainsKey(t))
                    {
                        xform = xform.Replace(t, (string)InstructionSetContainer[t]);
                        tokens.Remove(t);
                        continue;
                    }

                    string x = t.Replace("[", "");
                    x = x.Replace("]", "");

                    if (InstructionSetContainer.ContainsKey(x))
                    {
                        xform = xform.Replace(t, (string)InstructionSetContainer[x]);
                        tokens.Remove(t);
                        continue;
                    }
                }

                if ((searchSpace & SearchSpace.Session) != 0)
                {
                    if (STEM.Sys.Global.Session.ContainsKey(t))
                    {
                        xform = xform.Replace(t, (string)STEM.Sys.Global.Session[t]);
                        tokens.Remove(t);
                        continue;
                    }

                    string x = t.Replace("[", "");
                    x = x.Replace("]", "");

                    if (STEM.Sys.Global.Session.ContainsKey(x))
                    {
                        xform = xform.Replace(t, (string)STEM.Sys.Global.Session[x]);
                        tokens.Remove(t);
                        continue;
                    }
                }

                if ((searchSpace & SearchSpace.Cache) != 0)
                {
                    if (STEM.Sys.Global.Cache.ContainsKey(t))
                    {
                        xform = xform.Replace(t, (string)STEM.Sys.Global.Cache[t]);
                        tokens.Remove(t);
                        continue;
                    }

                    string x = t.Replace("[", "");
                    x = x.Replace("]", "");

                    if (STEM.Sys.Global.Cache.ContainsKey(x))
                    {
                        xform = xform.Replace(t, (string)STEM.Sys.Global.Cache[x]);
                        tokens.Remove(t);
                        continue;
                    }
                }
            }

            if (tokens.Count > 0)
            {
                switch (failureAction)
                {
                case FailureAction.ReturnInput:
                    return(tokenizedString);

                case FailureAction.ReturnNull:
                    return(null);

                case FailureAction.ThrowException:
                    Exception e = new Exception("Tokens not found: " + String.Join(",", tokens));
                    STEM.Sys.EventLog.WriteEntry("InstructionSet.ReplaceTokens", e.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error);
                    throw e;
                }
            }

            return(xform);
        }