public void ShouldNotConvertOtherRecordSeparator()
        {
            Separator separator = new Separator("X");

            separator.ToString().Should().Be("X");
            separator.Get().Should().Be("X");
        }
        public void ShouldConvertCrlfRecordSeparator()
        {
            Separator separator = new Separator("CRLF");

            separator.ToString().Should().Be("CRLF");
            separator.Get().Should().Be("\r\n");
        }
Exemple #3
0
        protected override void ExecuteWorkflowLogic()
        {
            var allStrings = new List <string>();

            var properties = GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);

            properties.ToList().ForEach(p =>
            {
                if (p.PropertyType.IsSubclassOf(typeof(InArgument)) &&
                    p.Name.StartsWith("In"))
                {
                    var property      = (Argument)p.GetValue(this);
                    var propertyValue = property.Get(Context.ExecutionContext);

                    if (propertyValue != null)
                    {
                        allStrings.Add((string)propertyValue);
                    }
                }
            });

            var separator = Separator.Get(Context.ExecutionContext) ?? string.Empty;

            var result = string.Join(separator, allStrings);

            Result.Set(Context.ExecutionContext, result);
        }
Exemple #4
0
        protected override void Execute(CodeActivityContext executionContext)
        {
            #region "Load CRM Service from context"

            Common objCommon = new Common(executionContext);
            objCommon.tracingService.Trace("ConcatenateFromQuery -- Start!");
            #endregion

            #region "Read Parameters"
            var fetchXml = FetchXml.Get(executionContext);
            if (string.IsNullOrEmpty(fetchXml))
            {
                return;
            }
            objCommon.tracingService.Trace($"FetchXML={fetchXml}");

            var attributeFieldName = AttributeName.Get(executionContext);
            objCommon.tracingService.Trace($"AttributeName={attributeFieldName}");

            var separator = Separator.Get(executionContext);
            objCommon.tracingService.Trace($"Separator={separator}");

            var format = FormatString.Get(executionContext);
            objCommon.tracingService.Trace($"FormatString={format}");

            IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>();

            #endregion

            #region "Concatenation Execution"
            string pagingCookie = null;

            bool          hasMoreRecords   = false;
            bool          canPerformPaging = fetchXml.IndexOf("top=", StringComparison.CurrentCultureIgnoreCase) < 0;
            int           pageNumber       = canPerformPaging ? 1 : 0;
            int           fetchCount       = canPerformPaging ? 250 : 0;
            List <string> stringValues     = new List <string>();
            do
            {
                objCommon.tracingService.Trace($"Fetch PageNumber={pageNumber}");

                fetchXml = fetchXml.Replace("{PARENT_GUID}", context.PrimaryEntityId.ToString());

                string xml = CreateXml(fetchXml, pagingCookie, pageNumber, fetchCount);
                RetrieveMultipleRequest fetchRequest1 = new RetrieveMultipleRequest
                {
                    Query = new FetchExpression(xml)
                };
                EntityCollection returnCollection =
                    ((RetrieveMultipleResponse)objCommon.service.Execute(fetchRequest1)).EntityCollection;
                bool attributeNamesSentToTrace = false;
                foreach (var entity in returnCollection.Entities)
                {
                    if (!entity.Attributes.Any())
                    {
                        continue;
                    }

                    if (!attributeNamesSentToTrace)
                    {
                        var attributeNames = entity.Attributes.Select(a => a.Key).Aggregate((x, y) => x + "," + y);
                        objCommon.tracingService.Trace($"List of attributes available: {attributeNames}");
                        attributeNamesSentToTrace = true;
                    }

                    object attribute = null;
                    if (!string.IsNullOrEmpty(attributeFieldName))
                    {
                        if (entity.Attributes.ContainsKey(attributeFieldName))
                        {
                            attribute = entity.Attributes[attributeFieldName];
                        }
                    }
                    else
                    {
                        attribute = entity.Attributes.First().Value;
                    }

                    if (attribute == null)
                    {
                        continue;
                    }

                    if (attribute is AliasedValue)
                    {
                        attribute = ((AliasedValue)attribute).Value;
                    }

                    if (attribute is EntityReference)
                    {
                        attribute = ((EntityReference)attribute).Name;
                    }
                    else if (attribute is Money)
                    {
                        attribute = ((Money)attribute).Value;
                    }
                    else if (attribute is OptionSetValue)
                    {
                        attribute = ((OptionSetValue)attribute).Value;
                        if (entity.FormattedValues.ContainsKey(attributeFieldName))
                        {
                            attribute = entity.FormattedValues[attributeFieldName];
                        }
                    }

                    var attributeValueAsString = string.Format($"{{0:{format}}}", attribute);
                    stringValues.Add(attributeValueAsString);
                }

                if (canPerformPaging && returnCollection.MoreRecords)
                {
                    pageNumber++;
                    pagingCookie   = returnCollection.PagingCookie;
                    hasMoreRecords = returnCollection.MoreRecords;
                }
            } while (hasMoreRecords);

            if (stringValues.Any())
            {
                var concatenatedString = stringValues.Aggregate((x, y) => x + separator + y);
                objCommon.tracingService.Trace($"Concatenated string: {concatenatedString}");
                ConcatenatedString.Set(executionContext, concatenatedString);
            }
            else
            {
                objCommon.tracingService.Trace("No data found to concatenate");
            }

            objCommon.tracingService.Trace("ConcatenateFromQuery -- Done!");

            #endregion
        }