public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
        {
            string errorMessage;

            if (!Validate(out errorMessage))
            {
                throw new ArgumentException(errorMessage);
            }

            string lookupKey;

            if (!pInMsg.Context.TryRead(new ContextProperty(SourcePropertyPath), out lookupKey))
            {
                throw new InvalidOperationException("Could not find lookup key in context");
            }

            var util = new LookupUtilityService(_repository);

            var value = util.GetValue(ListName, lookupKey, DefaultValue);

            if (string.IsNullOrEmpty(value))
            {
                throw new InvalidOperationException("Could not find value for key " + lookupKey);
            }

            pInMsg.Context.Promote(new ContextProperty(DestinationPropertyPath), value);

            return(pInMsg);
        }
Beispiel #2
0
        public string GetValue(string list, string key, bool throwIfNotExists = false, bool allowDefaults = false)
        {
            string value;

            try
            {
                value = _lookupUtilityService.GetValue(list, key, throwIfNotExists, allowDefaults);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(string.Format("An exception was thrown in LookupUtility {0}", ex.ToString()));
                throw ex;
            }

            return(value);
        }
Beispiel #3
0
        public string GetValue(string list, string key, bool throwIfNotExists = false, bool allowDefaults = false)
        {
            Trace.WriteLine($"Getting value for list {list} and key {key}");
            string value;

            try
            {
                value = svc.GetValue(list, key, throwIfNotExists, allowDefaults);
                Trace.WriteLine($"Value returned {value}");
            }
            catch (Exception ex)
            {
                Trace.WriteLine(string.Format("An exception was thrown in LookupUtility {0}", ex.ToString()));
                throw ex;
            }

            return(value);
        }
        public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
        {
            string errorMessage;

            if (!Validate(out errorMessage))
            {
                throw new ArgumentException(errorMessage);
            }

            //component will not be executed if the property is set to true
            if (Disabled)
            {
                return(pInMsg);
            }

            //get the value from the provided property
            IBaseMessageContext context = pInMsg.Context;
            string key = (string)context.Read(new ContextProperty(PropertyPath)); // PropertyPath.Split('#')[1], PropertyPath.Split('#')[0]).ToString();

            //query the sharepoint table
            var    lookupService = new LookupUtilityService(new SharepointLookupRepository());
            string result        = "";

            try
            {
                result = lookupService.GetValue(ListName, key, true);
            }catch (ArgumentException ex)
            {
                if (ThrowException)
                {
                    throw ex;
                }
                else
                {
                    System.Diagnostics.EventLog.WriteEntry(pContext.PipelineName, ex.Message, System.Diagnostics.EventLogEntryType.Warning);
                }
            }

            //promote the result to the provided destination property
            if (PromoteProperty)
            {
                pInMsg.Context.Promote(new ContextProperty(DestinationPath), result);
            }
            else
            {
                pInMsg.Context.Write(new ContextProperty(DestinationPath), result);
            }

            return(pInMsg);
        }
 public void TestHappyPath()
 {
     Assert.AreEqual("ConfigValue", util.GetValue(list, "ConfigKey"));
     mock.Verify(util => util.LoadList(list), Times.Once);
 }