public string GetValueFromMacro(string text, ReplacementValue strv, Dictionary <string, ITaskVariable> taskVariables)
        {
            string returnValue = text;

            switch (strv.ReplaceMethod)
            {
            case ReplaceMethod.EditObjectFromBinary:
                returnValue = EditAssemblyObject(strv.Value, returnValue, strv.Pattern, strv.Value);
                break;

            case ReplaceMethod.Text:
                var replacmentValue = GetValueFromMacro(strv.Value);
                if (replacmentValue.Contains("!"))
                {
                    returnValue = Regex.Replace(returnValue, strv.Pattern, GetValueFromMacro(replacmentValue));
                }
                else
                {
                    returnValue = Regex.Replace(returnValue, strv.Pattern, replacmentValue);
                }

                break;
            }

            return(returnValue);
        }
Exemple #2
0
        protected override void ExecuteCrmWorkFlowActivity(CodeActivityContext context, LocalWorkflowContext localContext)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (localContext == null)
            {
                throw new ArgumentNullException(nameof(localContext));
            }

            string stringToSearch   = StringToSearch.Get(context);
            string replacementValue = ReplacementValue.Get(context);
            string pattern          = Pattern.Get(context);

            if (string.IsNullOrEmpty(replacementValue))
            {
                replacementValue = "";
            }

            Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);

            string replacedString = regex.Replace(stringToSearch, replacementValue);

            ReplacedString.Set(context, replacedString);
        }
        public string GetValueFromMacro(string text, ReplacementValue trace)
        {
            string returnValue = text;

            switch (trace.ReplaceMethod)
            {
            case ReplaceMethod.EditObjectFromBinary:
                returnValue = EditAssemblyObject(trace.Value, returnValue, trace.Pattern, trace.Value);
                break;

            case ReplaceMethod.Text:
                var replacmentValue = GetValueFromMacro(trace.Value);
                if (replacmentValue.Contains("!"))
                {
                    returnValue = Regex.Replace(returnValue, trace.Pattern, GetValueFromMacro(replacmentValue));
                }
                else
                {
                    returnValue = Regex.Replace(returnValue, trace.Pattern, replacmentValue);
                }

                break;
            }

            return(returnValue);
        }
        protected override void Execute(CodeActivityContext executionContext)
        {
            ITracingService tracer = executionContext.GetExtension <ITracingService>();

            try
            {
                string stringToSearch   = StringToSearch.Get(executionContext);
                string replacementValue = ReplacementValue.Get(executionContext);
                string pattern          = Pattern.Get(executionContext);

                if (string.IsNullOrEmpty(replacementValue))
                {
                    replacementValue = "";
                }

                Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);

                string replacedString = regex.Replace(stringToSearch, replacementValue);

                ReplacedString.Set(executionContext, replacedString);
            }
            catch (Exception ex)
            {
                tracer.Trace("Exception: {0}", ex.ToString());
            }
        }
Exemple #5
0
        public void TestReplacementValueConstructorWithWhiteSpaceInstitutionIdParameter_ThrowsArgumentException()
        {
            //Arrange
            ReplacementValue myReplacementValue;

            //Act
            myReplacementValue = new ReplacementValue("Advent", " ");
        }
Exemple #6
0
        public void TestReplacementValueConstructorWithWhiteSpaceReplacementValueParameter_ThrowsArgumentException()
        {
            //Arrange
            ReplacementValue myReplacementValue;

            //Act
            myReplacementValue = new ReplacementValue(" ", "522bb79455449d881b004d27");
        }
Exemple #7
0
        public void TestReplacementValue_RemoveInstituionIdThatDoesNotExistInTheList_ThrowsArgumentException()
        {
            //Arrange
            ReplacementValue myReplacementValue = new ReplacementValue("Advent", "522bb79455449d881b004d27");

            //Act
            myReplacementValue.RemoveInstituionId("8899979455449d881b004d27");
        }
Exemple #8
0
        public void TestReplacementValue_AddInstitutionIdThatAlreadyExists_ThrowsArgumentException()
        {
            //Arrange
            ReplacementValue myReplacementValue =
                new ReplacementValue("Advent", "522bb79455449d881b004d27");

            //Act
            myReplacementValue.AddInsitutionId("522bb79455449d881b004d27");
        }
Exemple #9
0
        public void TestReplacementValue_RemoveInstitutionIdFromEmptyListOfInstitutionIds_ThrowsArgumentException()
        {
            //Arrange
            ReplacementValue myReplacementValue = new ReplacementValue("Advent", "522bb79455449d881b004d27");

            myReplacementValue.RemoveInstituionId("522bb79455449d881b004d27");

            //Act
            myReplacementValue.RemoveInstituionId("522bb79455449d881b004d27");
        }
Exemple #10
0
        public void TestReplacementValueConstructor_WhiteSpaceTrimmedFromArgumentReplacementValue()
        {
            //Arrange
            ReplacementValue myReplacementValue;

            //Act
            myReplacementValue = new ReplacementValue("  Advent  ", "522bb79455449d881b004d27");

            //Assert
            Assert.AreEqual("advent", myReplacementValue._ReplacementValue);
        }
Exemple #11
0
        public void TestReplacementValue_getCout()
        {
            //Arrange
            ReplacementValue myReplacementValue;

            //Act
            myReplacementValue = new ReplacementValue("Advent", "522bb79455449d881b004d27");
            myReplacementValue.AddInsitutionId("999bb79455449d881b004d27");

            //Assert
            Assert.AreEqual(2, myReplacementValue.getCount());
        }
Exemple #12
0
        public void TestReplacementValueEquals_InstancesDoNotHaveEqualInstitutionIdLists()
        {
            //Arrange
            ReplacementValue instance1;
            ReplacementValue instance2;

            //Act
            instance1 = new ReplacementValue("Advent", "888bb79455449d881b004d27");
            instance2 = new ReplacementValue("Advent", "333bb79455449d881b004d27");

            //Assert
            Assert.AreNotEqual(instance1, instance2);
        }
Exemple #13
0
        public void TestReplacementValueEquals_InstancesAreEqual()
        {
            //Arrange
            ReplacementValue instance1;
            ReplacementValue instance2;

            //Act
            instance1 = new ReplacementValue("Advent", "333bb79455449d881b004d27");
            instance2 = new ReplacementValue("Advent", "333bb79455449d881b004d27");

            //Assert
            Assert.AreEqual(instance1, instance2);
        }
Exemple #14
0
        public void TestReplacementValue_getInstitutionIds()
        {
            //Arrange
            ReplacementValue myReplacementValue;

            //Act
            myReplacementValue = new ReplacementValue("Advent", "522bb79455449d881b004d27");
            myReplacementValue.AddInsitutionId("999bb79455449d881b004d27");

            //Assert
            CollectionAssert.AreEqual(new List <String> {
                "522bb79455449d881b004d27", "999bb79455449d881b004d27"
            }, myReplacementValue.getInsitutionIds());
        }
        private List <ReplacementValue> GetReplacementValues(XmlNodeList nodes)
        {
            List <ReplacementValue> returnList = new List <ReplacementValue>();

            foreach (XmlNode replacement in nodes)
            {
                ReplacementValue newReplacement = new ReplacementValue();
                newReplacement.Pattern       = replacement["MatchPattern"].InnerText;
                newReplacement.Value         = replacement["ReplaceValue"].InnerText;
                newReplacement.ReplaceMethod = (ReplaceMethod)Enum.Parse(typeof(ReplaceMethod), replacement["ReplaceMethod"].InnerText);
                newReplacement.Global        = Convert.ToBoolean(replacement.Attributes["Global"].Value);
                returnList.Add(newReplacement);
            }

            return(returnList);
        }
Exemple #16
0
        public void TestReplacementValueEquals_InstancesHaveSameElementsButDifferentOrder_ShouldFail()
        {
            //Arrange
            ReplacementValue instance1;
            ReplacementValue instance2;

            //Act
            instance1 = new ReplacementValue("Advent", "333bb79455449d881b004d27");
            instance1.AddInsitutionId("888bb79455449d881b004d27");

            instance2 = new ReplacementValue("Advent", "888bb79455449d881b004d27");
            instance2.AddInsitutionId("333bb79455449d881b004d27");

            //Assert
            Assert.AreNotEqual(instance1, instance2);
        }
Exemple #17
0
        protected override void ExecuteCrmWorkFlowActivity(CodeActivityContext context, LocalWorkflowContext localContext)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (localContext == null)
            {
                throw new ArgumentNullException(nameof(localContext));
            }

            string stringToSearch   = StringToSearch.Get(context);
            string valueToReplace   = ValueToReplace.Get(context);
            string replacementValue = ReplacementValue.Get(context);

            if (string.IsNullOrEmpty(replacementValue))
            {
                replacementValue = "";
            }

            string replacedString = stringToSearch.Replace(valueToReplace, replacementValue);

            ReplacedString.Set(context, replacedString);
        }
Exemple #18
0
        protected override void Execute(CodeActivityContext executionContext)
        {
            ITracingService tracer = executionContext.GetExtension <ITracingService>();

            try
            {
                string stringToSearch   = StringToSearch.Get(executionContext);
                string valueToReplace   = ValueToReplace.Get(executionContext);
                string replacementValue = ReplacementValue.Get(executionContext);

                if (string.IsNullOrEmpty(replacementValue))
                {
                    replacementValue = "";
                }

                string replacedString = stringToSearch.Replace(valueToReplace, replacementValue);

                ReplacedString.Set(executionContext, replacedString);
            }
            catch (Exception ex)
            {
                tracer.Trace("Exception: {0}", ex.ToString());
            }
        }