private string GetAttributeName(ITracingService tracingService, CodeActivityContext executionContext)
        {
            string attributeName = AttributeName.Get <string>(executionContext) ?? throw new ArgumentNullException("Attribute Name is empty");

            tracingService.Trace("Attribute name:'{0}'", attributeName);
            return(attributeName);
        }
        private string GetAttributeName(Common context)
        {
            string attributeName = AttributeName.Get <string>(context.codeActivityContext) ?? throw new ArgumentNullException("Attribute Name is empty");

            context.tracingService.Trace("Attribute name:'{0}'", attributeName);
            return(attributeName);
        }
コード例 #3
0
        /// <summary>
        /// When implemented in a derived class, performs the execution of the activity.
        /// </summary>
        /// <param name="context">The execution context under which the activity executes.</param>
        protected override void Execute(CodeActivityContext context)
        {
            var attributeName              = AttributeName.Get(context);
            var attributeValue             = AttributeValue.Get(context);
            var createAttributeIfNotExists = CreateAttributeIfNotExists.Get(context);
            var directoryToSearch          = DirectoryToSearch.Get(context);
            var fileNamesToSearch          = FileNamesToSearch.Get(context);
            var commandLog = new CodeActivityContextCommandLog(context);
            var recursive  = Recursive.Get(context);
            var writeVerboseLogMessages = WriteVerboseLogMessages.Get(context);

            var command =
                new SetAssemblyAttributeInFilesCommand
            {
                AttributeName              = attributeName,
                AttributeValue             = attributeValue,
                CreateAttributeIfNotExists = createAttributeIfNotExists,
                DirectoryToSearch          = directoryToSearch,
                FileNamesToSearch          = fileNamesToSearch,
                CommandLog = commandLog,
                Recursive  = recursive,
                WriteVerboseLogMessages = writeVerboseLogMessages
            };

            var successful = command.Execute();

            if (false == successful)
            {
                commandLog.Error("The SetAssemblyAttributeInFiles activity failed.");
            }
        }
コード例 #4
0
        protected override void Execute(IWorkflowActivityContext context)
        {
            this.EnsureNotNull(context, nameof(context));

            var activityContext = context.GetExecutionContext();

            var primaryEntityId   = context.WorkflowContext.PrimaryEntityId;
            var primaryEntityName = context.WorkflowContext.PrimaryEntityName;
            var attributeName     = AttributeName.Get(activityContext);
            var primaryEntity     = RetrievePrimaryEntity(context, primaryEntityName, primaryEntityId, attributeName);

            var value = primaryEntity?.GetAttributeValue <Object>(attributeName);

            if (value == null)
            {
                return;
            }

            if (!(value is EntityReference))
            {
                throw new InvalidPluginExecutionException($"Invalid field value type {value.GetType().FullName}.");
            }

            var entityReference = (EntityReference)value;

            EntityLogicalName.Set(activityContext, entityReference.LogicalName);
            EntityId.Set(activityContext, entityReference.Id.ToString());
        }
コード例 #5
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
        }