Esempio n. 1
0
        public override async Task Run()
        {
            //get the event payload from the Salesforce notification event
            var sfEventPayloads = Payload.CratesOfType <EventReportCM>().ToList().SelectMany(er => er.Content.EventPayload).ToList();

            if (sfEventPayloads.Count == 0 ||
                !sfEventPayloads.Any(payload => payload.Label.Equals("Salesforce Event Notification Payload")))
            {
                RequestPlanExecutionTermination("External event data is missing");
                return;
            }

            //if payload contains Salesforce Notification, get it from the payload storage
            var curEventReport   = Payload.CratesOfType <EventReportCM>().Single(er => er.Content.Manufacturer.Equals("Salesforce")).Content;
            var curEventPayloads = curEventReport.EventPayload.CrateContentsOfType <StandardPayloadDataCM>().Single().PayloadObjects;

            //for each payload,
            curEventPayloads.ForEach(p =>
            {
                //create SalesforceEventCM with the values. The values are:
                //Object ID          -> Id of the newly created or updated Salesforce Object
                //Object Type        -> Type of the newly created or updated Salesforce Object (ex., Lead, Account or Contact
                //Occured Event      -> Cause of this notification (ex., Create or Updated)
                //Created Date       -> Date at which the object is created
                //LastModified Date  -> Date at which the object is last modified
                var sfEvent = new SalesforceEventCM
                {
                    ObjectId         = p.PayloadObject.Single(requiredProperty => requiredProperty.Key.Equals("ObjectId")).Value,
                    ObjectType       = p.PayloadObject.Single(requiredProperty => requiredProperty.Key.Equals("ObjectType")).Value,
                    OccuredEvent     = p.PayloadObject.Single(requiredProperty => requiredProperty.Key.Equals("OccuredEvent")).Value,
                    CreatedDate      = p.PayloadObject.Single(requiredProperty => requiredProperty.Key.Equals("CreatedDate")).Value,
                    LastModifiedDate = p.PayloadObject.Single(requiredProperty => requiredProperty.Key.Equals("LastModifiedDate")).Value
                };

                //store the SalesforceEventCM into the current payload
                Payload.ReplaceByLabel(Crate.FromContent("Salesforce Event", sfEvent));
            });

            var runtimeCrateLabel = GenerateRuntimeDataLabel();

            var salesforceObjectFields = Storage.FirstCrate <CrateDescriptionCM>().Content.CrateDescriptions.First(x => x.Label == runtimeCrateLabel).Fields;

            //for each Salesforce event notification
            var sfEventsList = Payload.CrateContentsOfType <SalesforceEventCM>().ToList();

            foreach (var sfEvent in sfEventsList)
            {
                //get the object fields as Standard Table Data
                var resultObjects = await _salesforceManager.Query(
                    sfEvent.ObjectType.ToEnum <SalesforceObjectType>(),
                    salesforceObjectFields,
                    $"ID = '{sfEvent.ObjectId}'",
                    AuthorizationToken);

                Payload.Add(Crate <StandardTableDataCM> .FromContent(runtimeCrateLabel, resultObjects));
            }
        }
Esempio n. 2
0
        public override async Task Run()
        {
            var salesforceObject = ActivityUI.SalesforceObjectSelector.selectedKey;

            if (string.IsNullOrEmpty(salesforceObject))
            {
                throw new ActivityExecutionException(
                          "No Salesforce object is selected",
                          ActivityErrorCode.DESIGN_TIME_DATA_MISSING);
            }
            var salesforceObjectFields = Storage
                                         .FirstCrate <FieldDescriptionsCM>(x => x.Label == QueryFilterCrateLabel)
                                         .Content
                                         .Fields;

            var filterValue   = ActivityUI.SalesforceObjectFilter.Value;
            var filterDataDTO = JsonConvert.DeserializeObject <List <FilterConditionDTO> >(filterValue);
            //If without filter, just get all selected objects
            //else prepare SOQL query to filter the objects based on the filter conditions
            var parsedCondition = string.Empty;

            if (filterDataDTO.Count > 0)
            {
                parsedCondition = FilterConditionHelper.ParseConditionToText(filterDataDTO);
            }

            var resultObjects = await _salesforceManager
                                .Query(
                salesforceObject.ToEnum <SalesforceObjectType>(),
                salesforceObjectFields,
                parsedCondition,
                AuthorizationToken
                );

            Payload.Add(
                Crate <StandardTableDataCM>
                .FromContent(
                    RuntimeDataCrateLabel,
                    resultObjects
                    )
                );
        }
        public override async Task Run()
        {
            var feedText = FeedText;

            if (IsPostingToQueryiedChatter)
            {
                try
                {
                    var chatters = await _salesforceManager.Query(SelectedChatter.ToEnum <SalesforceObjectType>(),
                                                                  new[] { new FieldDTO("Id") },
                                                                  FilterConditionHelper.ParseConditionToText(JsonConvert.DeserializeObject <List <FilterConditionDTO> >(ChatterFilter)),
                                                                  AuthorizationToken);

                    var tasks = new List <Task <string> >(chatters.Table.Count);
                    foreach (var chatterId in chatters.DataRows.Select(x => x.Row[0].Cell.Value))
                    {
                        Logger.Info($"Posting message to chatter id: {chatterId}");

                        tasks.Add(_salesforceManager.PostToChatter(StripHTML(feedText), chatterId, AuthorizationToken).ContinueWith(x =>
                        {
                            Logger.Info($"Posting message to chatter succeded with feedId: {x.Result}");
                            return(x.Result);
                        }));
                    }
                    await Task.WhenAll(tasks);

                    //If we did not find any chatter object we don't fail activity execution but rather returns empty list and inform caller about it
                    if (!chatters.HasDataRows)
                    {
                        Logger.Info("No salesforce objects were found to use as chatter id.");
                        Success($"No {SelectedChatter} that satisfies specified conditions were found. No message were posted");
                    }
                    else
                    {
                        var resultPayload = new StandardPayloadDataCM();
                        resultPayload.PayloadObjects.AddRange(tasks.Select(x => new PayloadObjectDTO(new KeyValueDTO(FeedIdKeyName, x.Result))));
                        Payload.Add(Crate <StandardPayloadDataCM> .FromContent(PostedFeedCrateLabel, resultPayload));
                    }
                }
                catch (Exception ex)
                {
                    RaiseError(ex.Message);
                    return;
                }
            }
            else
            {
                var incomingChatterId = IncomingChatterId;
                if (string.IsNullOrWhiteSpace(incomingChatterId))
                {
                    throw new ActivityExecutionException("Upstream crates doesn't contain value for feed parent Id");
                }

                Logger.Info($"Posting message to chatter id: {incomingChatterId}");

                var feedId = await _salesforceManager.PostToChatter(StripHTML(feedText), incomingChatterId, AuthorizationToken);

                Logger.Info($"Posting message to chatter succeded with feedId: {feedId}");

                Payload.Add(Crate.FromContent(PostedFeedCrateLabel, new StandardPayloadDataCM(new KeyValueDTO(FeedIdKeyName, feedId))));
            }
        }