示例#1
0
        protected override Clue MakeClueImpl(BroadcastMessage input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Announcement, input.broadcastGuid, accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_002_Uri_MustBeSet);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_001_Name_MustBeSet);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.PROPERTIES_003_Value_ShouldNotBeQuoted);

            var data = clue.Data.EntityData;

            data.Name = input.message;

            if (input.createdAt != null)
            {
                data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(input.createdAt.Value);
            }

            if (input.messageUrl != null && Uri.TryCreate(input.messageUrl, UriKind.Absolute, out var uri))
            {
                data.Uri = uri;
            }

            data.Properties[HubSpotVocabulary.Broadcast.BroadcastGuid]     = input.broadcastGuid;
            data.Properties[HubSpotVocabulary.Broadcast.CampaignGuid]      = input.campaignGuid;
            data.Properties[HubSpotVocabulary.Broadcast.Clicks]            = input.clicks.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Broadcast.ClientTag]         = input.clientTag.PrintIfAvailable(JsonUtility.Serialize);;
            data.Properties[HubSpotVocabulary.Broadcast.CreatedBy]         = input.createdBy.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Broadcast.FinishedAt]        = input.finishedAt.PrintIfAvailable(v => DateUtilities.EpochRef.AddMilliseconds(v.Value));
            data.Properties[HubSpotVocabulary.Broadcast.ForeignId]         = input.foreignId;
            data.Properties[HubSpotVocabulary.Broadcast.GroupGuid]         = input.groupGuid;
            data.Properties[HubSpotVocabulary.Broadcast.InteractionCounts] = input.interactionCounts.PrintIfAvailable(JsonUtility.Serialize);
            data.Properties[HubSpotVocabulary.Broadcast.Interactions]      = input.interactions.PrintIfAvailable(JsonUtility.Serialize);
            data.Properties[HubSpotVocabulary.Broadcast.LinkGuid]          = input.linkGuid;
            data.Properties[HubSpotVocabulary.Broadcast.LinkTaskQueueId]   = input.linkTaskQueueId;
            data.Properties[HubSpotVocabulary.Broadcast.RemoteContentId]   = input.remoteContentId.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Broadcast.RemoteContentType] = input.remoteContentType.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Broadcast.Status]            = input.status;
            data.Properties[HubSpotVocabulary.Broadcast.TaskQueued]        = input.taskQueueId;
            data.Properties[HubSpotVocabulary.Broadcast.TriggerAt]         = input.triggerAt.PrintIfAvailable(v => DateUtilities.EpochRef.AddMilliseconds(v.Value));
            data.Properties[HubSpotVocabulary.Broadcast.UpdatedBy]         = input.updatedBy.PrintIfAvailable();

            if (input.channelGuid != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Channel, EntityEdgeType.PartOf, input, s => s.channelGuid);
            }

            if (input.portalId != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.PartOf, input, s => s.portalId.ToString(), s => "HubSpot");
            }

            return(clue);
        }
示例#2
0
        protected override Clue MakeClueImpl(EngagementObject input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Activity, input.engagement.id.ToString(), accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_001_Name_MustBeSet);

            var data = clue.Data.EntityData;

            data.Name         = input.metadata.body ?? $"{input.engagement.type ?? "Engagement " + input.engagement.id}";
            data.CreatedDate  = DateUtilities.EpochRef.AddMilliseconds(input.engagement.createdAt);
            data.ModifiedDate = DateUtilities.EpochRef.AddMilliseconds(input.engagement.lastUpdated);

            data.Properties[HubSpotVocabulary.Engagement.Active]    = input.engagement.active.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Engagement.TimeStamp] = input.engagement.timestamp.PrintIfAvailable(v => DateUtilities.EpochRef.AddMilliseconds(v));
            data.Properties[HubSpotVocabulary.Engagement.Type]      = input.engagement.type;

            if (input.engagement.ownerId != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.Owns, input, s => s.engagement.ownerId.Value.ToString());
            }

            if (input.engagement.portalId != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.PartOf, input, s => s.engagement.portalId.ToString(), s => "Hubspot");
            }


            return(clue);
        }
示例#3
0
        protected override Clue MakeClueImpl(Table input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.List, input.id.ToString(), accountId);

            clue.ValidationRuleSuppressions.Add(CluedIn.Core.Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(CluedIn.Core.Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);

            var data = clue.Data.EntityData;

            data.Name        = input.name;
            data.Description = input.rowCount + " rows";
            data.Uri         = new Uri("http://app.hubspot.com/l/hubdb"); // TODO take from configuration

            if (input.createdAt != null && long.TryParse(input.createdAt.ToString(), out long date))
            {
                data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(date);
            }

            data.ModifiedDate = DateUtilities.EpochRef.AddMilliseconds(input.updatedAt);

            data.Properties[HubSpotVocabulary.Table.CreatedAt] = data.CreatedDate.PrintIfAvailable(v => v.Value.DateTime);
            data.Properties[HubSpotVocabulary.Table.UpdatedAt] = data.ModifiedDate.PrintIfAvailable(v => v.Value.DateTime);
            data.Properties[HubSpotVocabulary.Table.CreatedAt] = input.publishedAt.PrintIfAvailable(v => DateUtilities.EpochRef.AddMilliseconds(v.Value));

            data.Properties[HubSpotVocabulary.Table.RowCount]    = input.rowCount.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Table.Deleted]     = input.deleted.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Table.ColumnCount] = input.columnCount.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Table.Id]          = input.id.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Table.CreatedBy]   = input.createdBy.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Table.UseForPages] = input.useForPages.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Table.Name]        = input.name.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Table.UpdatedBy]   = input.updatedBy.PrintIfAvailable();

            if (input.createdBy != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.User, EntityEdgeType.CreatedBy, input, selector => input.createdBy.ToString());
            }

            if (input.updatedBy != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.User, EntityEdgeType.Modified, input, selector => input.updatedBy.ToString());
            }

            if (input.PortalId != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.Parent, input, selector => input.PortalId.ToString());
            }


            return(clue);
        }
示例#4
0
        protected override Clue MakeClueImpl(Workflow input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Process, input.id.ToString(), accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_002_Uri_MustBeSet);

            var data = clue.Data.EntityData;

            data.Name         = input.name;
            data.ModifiedDate = DateUtilities.EpochRef.AddMilliseconds(input.updatedAt);

            data.Properties[HubSpotVocabulary.Workflow.Actions] = input.actions.PrintIfAvailable(JsonUtility.Serialize);
            data.Properties[HubSpotVocabulary.Workflow.AllowContactToTriggerMultipleTimes] = input.allowContactToTriggerMultipleTimes.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Workflow.Enabled]            = input.enabled.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Workflow.GoalListIds]        = input.goalListIds.PrintIfAvailable(JsonUtility.Serialize);
            data.Properties[HubSpotVocabulary.Workflow.InsertingAt]        = input.insertedAt.PrintIfAvailable(v => DateUtilities.EpochRef.AddMilliseconds(v));
            data.Properties[HubSpotVocabulary.Workflow.Listening]          = input.listening.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Workflow.NutureTimeRange]    = input.nurtureTimeRange.PrintIfAvailable(JsonUtility.Serialize);
            data.Properties[HubSpotVocabulary.Workflow.OnlyExecOnBizDays]  = input.onlyExecOnBizDays.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Workflow.RecurringSetting]   = input.recurringSetting.PrintIfAvailable(JsonUtility.Serialize);
            data.Properties[HubSpotVocabulary.Workflow.SuppressionListIds] = input.suppressionListIds.PrintIfAvailable(JsonUtility.Serialize);
            data.Properties[HubSpotVocabulary.Workflow.TriggerSets]        = input.triggerSets.PrintIfAvailable(JsonUtility.Serialize);
            data.Properties[HubSpotVocabulary.Workflow.Type] = input.type;
            data.Properties[HubSpotVocabulary.Workflow.UnEnrollmentSetting] = input.unenrollmentSetting.PrintIfAvailable();

            if (input.lastUpdatedBy != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.ModifiedBy, input, s => s.lastUpdatedBy);
                var createdBy = new PersonReference(new EntityCode(EntityType.Person, HubSpotNameConstants.CodeOrigin, input.lastUpdatedBy));
                data.Authors.Add(createdBy);
            }

            if (input.originalAuthorUserId != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.CreatedBy, input, s => s.originalAuthorUserId.Value.ToString(CultureInfo.InvariantCulture));
            }

            if (input.portalId != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.PartOf, input, s => s.portalId.Value.ToString(CultureInfo.InvariantCulture), s => "HubSpot");
            }

            return(clue);
        }
示例#5
0
        protected override Clue MakeClueImpl(Template input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Template, input.id.ToString(), accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_002_Uri_MustBeSet);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.PROPERTIES_002_Unknown_VocabularyKey_Used);

            var data = clue.Data.EntityData;

            data.Name         = input.label;
            data.Description  = input.source;
            data.ModifiedDate = DateUtilities.EpochRef.AddMilliseconds(input.updated);

            data.Properties[HubSpotVocabulary.Template.CategoryId]               = input.category_id.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Template.CdnMinifiedUrl]           = input.cdn_minified_url;
            data.Properties[HubSpotVocabulary.Template.CdnUrl]                   = input.cdn_url;
            data.Properties[HubSpotVocabulary.Template.DeletedAt]                = input.deleted_at.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Template.Folder]                   = input.folder;
            data.Properties[HubSpotVocabulary.Template.GeneratedFromLayoutId]    = input.generated_from_layout_id.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Template.IsAvailableForNewContent] = input.is_available_for_new_content.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Template.IsFromLayout]             = input.is_from_layout.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Template.IsReadOnly]               = input.is_read_only.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Template.LinkedInStyleLayout]      = input.linked_style_id;
            data.Properties[HubSpotVocabulary.Template.Path]           = input.path;
            data.Properties[HubSpotVocabulary.Template.PortalId]       = input.portal_id.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Template.TemplateType]   = input.template_type;
            data.Properties[HubSpotVocabulary.Template.ThumbnailWidth] = input.thumbnail_width.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Template.Type]           = input.type;
            data.Properties[HubSpotVocabulary.Template.UpdatedBy]      = input.updated_by;

            if (input.category_id != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Tag, EntityEdgeType.PartOf, input, s => s.category_id.Value.ToString());
            }

            if (input.portal_id != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.PartOf, input, s => s.portal_id.ToString(), s => "HubSpot");
            }



            return(clue);
        }
示例#6
0
        protected override Clue MakeClueImpl([NotNull] Tweet input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Announcement, input.id.ToString(), accountId);

            var data = clue.Data.EntityData;

            if (!string.IsNullOrEmpty(input.text))
            {
                data.Name = input.text.ToString();
            }

            if (!string.IsNullOrEmpty(input.created_at))
            {
                if (DateTimeOffset.TryParse(input.created_at, out var createdDate))
                {
                    data.CreatedDate = createdDate;
                }
            }


            if (!string.IsNullOrEmpty(input.createdByScreenName))
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.User, EntityEdgeType.Created, input, input.createdByScreenName.ToLowerInvariant());
            }

            var vocab = new TwitterTweetVocabulary();

            if (!data.OutgoingEdges.Any())
            {
                _factory.CreateEntityRootReference(clue, EntityEdgeType.PartOf);
            }

            data.Properties[vocab.created_at]         = input.created_at.PrintIfAvailable();
            data.Properties[vocab.id]                 = input.id.PrintIfAvailable();
            data.Properties[vocab.id_str]             = input.id_str.PrintIfAvailable();
            data.Properties[vocab.text]               = input.text.PrintIfAvailable();
            data.Properties[vocab.display_text_range] = input.display_text_range.PrintIfAvailable();
            data.Properties[vocab.truncated]          = input.truncated.PrintIfAvailable();
            data.Properties[vocab.user]               = input.user.id.PrintIfAvailable();
            data.Properties[vocab.extended_tweet]     = input.extended_tweet.PrintIfAvailable();
            if (input.entities != null)
            {
                if (input.entities.urls.Count > 0)
                {
                    data.Properties[vocab.url] = input.entities.urls.Last().url;
                }
            }
            //data.Properties[vocab.entities] = input.entities.PrintIfAvailable();
            data.Properties[vocab.place] = input.place.PrintIfAvailable();

            return(clue);
        }
示例#7
0
        protected override Clue MakeClueImpl(CampaignEvent input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Calendar.Event, input.id, accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);

            var data = clue.Data.EntityData;

            data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(input.created);

            data.Properties[HubSpotVocabulary.CampaignEvent.AppName]         = input.appName;
            data.Properties[HubSpotVocabulary.CampaignEvent.Browser]         = input.browser.PrintIfAvailable(JsonUtility.Serialize);;
            data.Properties[HubSpotVocabulary.CampaignEvent.EmailCampaignId] = input.emailCampaignId.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.CampaignEvent.Hmid]            = input.hmid;
            data.Properties[HubSpotVocabulary.CampaignEvent.IpAddress]       = input.ipAddress;
            data.Properties[HubSpotVocabulary.CampaignEvent.Location]        = input.location.PrintIfAvailable(JsonUtility.Serialize);;
            data.Properties[HubSpotVocabulary.CampaignEvent.City]            = input.location?.city;
            data.Properties[HubSpotVocabulary.CampaignEvent.Country]         = input.location?.country;
            data.Properties[HubSpotVocabulary.CampaignEvent.State]           = input.location?.state;
            data.Properties[HubSpotVocabulary.CampaignEvent.Recipient]       = input.recipient;
            data.Properties[HubSpotVocabulary.CampaignEvent.Type]            = input.type;
            data.Properties[HubSpotVocabulary.CampaignEvent.UserAgent]       = input.userAgent;

            if (input.appId != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Application, EntityEdgeType.PartOf, input, s => s.appId.Value.ToString());
            }

            if (input.portalId != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.PartOf, input, s => s.portalId.ToString(), s => "HubSpot");
            }

            return(clue);
        }
示例#8
0
        protected override Clue MakeClueImpl(Topic input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Topic, input.id.ToString(), accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_002_Uri_MustBeSet);

            var data = clue.Data.EntityData;

            if (input.created != null)
            {
                data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(input.created.Value);
                data.Properties[HubSpotVocabulary.Topic.Created] = DateUtilities.EpochRef.AddMilliseconds(input.created.Value).ToString("o");
            }

            if (input.deletedAt != null)
            {
                data.Properties[HubSpotVocabulary.Topic.DeletedAt] = input.deletedAt.ToString();
            }
            if (input.description != null)
            {
                data.Description = input.description;
            }
            if (input.name != null)
            {
                data.Name = input.name;
            }
            if (input.portalId != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.PartOf, input, s => s.portalId.ToString(), s => "Hubspot");
                data.Properties[HubSpotVocabulary.Topic.PortalId] = input.portalId.ToString();
            }

            if (input.slug != null)
            {
                data.Properties[HubSpotVocabulary.Topic.Slug] = input.slug.ToString();
            }
            if (input.updated != null)
            {
                data.ModifiedDate = DateUtilities.EpochRef.AddMilliseconds(input.updated.Value);
                data.Properties[HubSpotVocabulary.Topic.Updated] = input.updated.ToString();
            }


            return(clue);
        }
示例#9
0
        protected override Clue MakeClueImpl(DealPipeline input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Process, input.pipelineId, accountId);

            clue.ValidationRuleSuppressions.Add(CluedIn.Core.Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(CluedIn.Core.Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);

            var data = clue.Data.EntityData;

            data.Name = input.label;
            data.Uri  = new Uri($"https://app.hubspot.com/sales-products-settings/{input.portalId}/deals/{input.pipelineId}"); // TODO take from configuration

            data.Properties[HubSpotVocabulary.DealPipeline.Active]       = input.active.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.DealPipeline.DisplayOrder] = input.displayOrder.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.DealPipeline.PipelineId]   = input.pipelineId;

            if (input.stages != null)
            {
                foreach (var stage in input.stages)
                {
                    var stageClue = CreateStageClue(stage, accountId);
                    //this.state.Status.Statistics.Tasks.IncrementTaskCount();
                    //this.state.Status.Statistics.Tasks.IncrementQueuedCount();
                    clue.ChildClues.Add(stageClue);

                    _factory.CreateIncomingEntityReference(clue, EntityType.ProcessStage, EntityEdgeType.PartOf, stage, s => s.stageId);
                }
            }

            _factory.CreateIncomingEntityReference(clue, EntityType.Provider.Root, EntityEdgeType.Parent, input, s => "HubSpot");


            return(clue);
        }
示例#10
0
        protected override Clue MakeClueImpl(Domain input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Note, input.id.ToString(), accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_002_Uri_MustBeSet);

            var data = clue.Data.EntityData;

            data.Name         = input.domain;
            data.CreatedDate  = DateUtilities.EpochRef.AddMilliseconds(input.created);
            data.ModifiedDate = DateUtilities.EpochRef.AddMilliseconds(input.updated);

            data.Properties[HubSpotVocabulary.Domain.ActualCName] = input.actual_cname;
            data.Properties[HubSpotVocabulary.Domain.ActualIp]    = input.actual_ip;
            data.Properties[HubSpotVocabulary.Domain.ConsecutiveNonResolvingCount] = input.consecutive_non_resolving_count.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Domain.Domain]                    = input.domain;
            data.Properties[HubSpotVocabulary.Domain.FullCategoryKey]           = input.full_category_key.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Domain.IsAnyPrimary]              = input.is_any_primary.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Domain.IsDnsCorrect]              = input.is_dns_correct.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Domain.IsInternalDomain]          = input.is_internal_domain.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Domain.IsLegacy]                  = input.is_legacy.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Domain.IsLegacyDomain]            = input.is_legacy_domain.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Domain.IsResolving]               = input.is_resolving.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Domain.ManuallyMarkedAsResolving] = input.manually_marked_as_resolving.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Domain.PortalId]                  = input.portal_id.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Domain.PrimaryBlogPost]           = input.primary_blog_post.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Domain.PrimaryEmail]              = input.primary_email.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Domain.PrimaryLandingPage]        = input.primary_landing_page.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Domain.PrimaryLegacyPage]         = input.primary_legacy_page.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Domain.PrimarySitePage]           = input.primary_site_page.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Domain.SecondaryToDomain]         = input.secondary_to_domain;
            data.Properties[HubSpotVocabulary.Domain.Updated]                   = input.updated.PrintIfAvailable();

            if (input.portal_id != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.PartOf, input, s => s.portal_id.ToString());
            }


            return(clue);
        }
示例#11
0
        protected override Clue MakeClueImpl(Form input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Form, input.guid, accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.PROPERTIES_002_Unknown_VocabularyKey_Used);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_002_Uri_MustBeSet);

            var data = clue.Data.EntityData;

            data.Name         = input.name;
            data.CreatedDate  = DateUtilities.EpochRef.AddMilliseconds(input.createdAt);
            data.ModifiedDate = DateUtilities.EpochRef.AddMilliseconds(input.updatedAt);

            data.Properties[HubSpotVocabulary.Form.Action]                 = input.action;
            data.Properties[HubSpotVocabulary.Form.CssClass]               = input.cssClass;
            data.Properties[HubSpotVocabulary.Form.Deletable]              = input.deletable.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Form.FollowUpId]             = input.followUpId;
            data.Properties[HubSpotVocabulary.Form.FormFieldGroups]        = input.formFieldGroups.PrintIfAvailable(JsonUtility.Serialize);
            data.Properties[HubSpotVocabulary.Form.Guid]                   = input.guid;
            data.Properties[HubSpotVocabulary.Form.IgnoreCurrentValues]    = input.ignoreCurrentValues.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Form.LeadNuturingCampaignId] = input.leadNurturingCampaignId;
            data.Properties[HubSpotVocabulary.Form.MetaData]               = input.metaData.PrintIfAvailable(JsonUtility.Serialize);
            data.Properties[HubSpotVocabulary.Form.Method]                 = input.method;
            data.Properties[HubSpotVocabulary.Form.MigratedFrom]           = input.migratedFrom;
            data.Properties[HubSpotVocabulary.Form.NotifyRecipients]       = input.notifyRecipients;
            data.Properties[HubSpotVocabulary.Form.PerformableHtml]        = input.performableHtml;
            data.Properties[HubSpotVocabulary.Form.Redirect]               = input.redirect;
            data.Properties[HubSpotVocabulary.Form.SubmitText]             = input.submitText;

            if (input.portalId != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.PartOf, input, s => s.portalId.ToString(), s => "HubSpot");
            }


            return(clue);
        }
示例#12
0
        protected override Clue MakeClueImpl(ContactList input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.List, input.listId.ToString(), accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.PROPERTIES_002_Unknown_VocabularyKey_Used);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_002_Uri_MustBeSet);

            var data = clue.Data.EntityData;

            data.Name = input.name;

            if (input.createdAt != null)
            {
                data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(input.createdAt.Value);
            }

            if (input.updatedAt != null)
            {
                data.ModifiedDate = DateUtilities.EpochRef.AddMilliseconds(input.updatedAt.Value);
            }

            data.Properties[HubSpotVocabulary.ContactList.Deleted]        = input.deleted.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.ContactList.Dynamic]        = input.dynamic.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.ContactList.Filters]        = input.filters.PrintIfAvailable(JsonUtility.Serialize);
            data.Properties[HubSpotVocabulary.ContactList.InternalListId] = input.internalListId.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.ContactList.ListId]         = input.listId.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.ContactList.MetaData]       = input.metaData.PrintIfAvailable(JsonUtility.Serialize);

            if (input.portalId != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.PartOf, input, s => s.portalId.Value.ToString(), s => "HubSpot");
            }


            return(clue);
        }
示例#13
0
        protected override Clue MakeClueImpl(Channel input, Guid accountId)
        {
            if (input == null)
                throw new ArgumentNullException(nameof(input));

            var clue = _factory.Create(EntityType.Channel, input.channelId, accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.PROPERTIES_002_Unknown_VocabularyKey_Used);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_002_Uri_MustBeSet);


            var data = clue.Data.EntityData;

            data.Name = input.name;
            data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(input.createdAt);
            data.ModifiedDate = DateUtilities.EpochRef.AddMilliseconds(input.updatedAt);

            data.Properties[HubSpotVocabulary.Channel.AccountId] = input.accountGuid;
            data.Properties[HubSpotVocabulary.Channel.ChannelId] = input.channelGuid;
            data.Properties[HubSpotVocabulary.Channel.DataMap] = input.dataMap.PrintIfAvailable(JsonUtility.Serialize); 
            data.Properties[HubSpotVocabulary.Channel.Email] = input.dataMap?.email;
            data.Properties[HubSpotVocabulary.Channel.FirstName] = input.dataMap?.firstName;
            data.Properties[HubSpotVocabulary.Channel.FullName] = input.dataMap?.fullName;
            data.Properties[HubSpotVocabulary.Channel.LastName] = input.dataMap?.lastName;
            data.Properties[HubSpotVocabulary.Channel.PageCategory] = input.dataMap?.pageCategory;
            data.Properties[HubSpotVocabulary.Channel.PageId] = input.dataMap?.pageId;
            data.Properties[HubSpotVocabulary.Channel.PageName] = input.dataMap?.pageName;
            data.Properties[HubSpotVocabulary.Channel.Picture] = input.dataMap?.picture;
            data.Properties[HubSpotVocabulary.Channel.ProfileUrl] = input.dataMap?.profileUrl;
            data.Properties[HubSpotVocabulary.Channel.UserId] = input.dataMap?.userId;
            data.Properties[HubSpotVocabulary.Channel.Type] = input.type;

            if (input.portalId != null)
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.PartOf, input, s => s.portalId.ToString(), s => "HubSpot");


            return clue;
        }
示例#14
0
        protected override Clue MakeClueImpl(Company input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Organization, input.companyId.ToString(), accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.PROPERTIES_002_Unknown_VocabularyKey_Used);

            var data = clue.Data.EntityData;

            data.Name = input.companyId.PrintIfAvailable();

            if (input.portalId != null)
            {
                data.Uri = new Uri($"https://app.hubspot.com/sales/{input.portalId}/company/{input.companyId}/");  // TODO take from configuration
            }
            data.Properties[HubSpotVocabulary.Company.CompanyId] = input.companyId.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Company.IsDeleted] = input.isDeleted.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Company.PortalId]  = input.portalId.PrintIfAvailable();

            if (input.portalId != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.PartOf, input, s => input.portalId.Value.ToString(), s => "HubSpot");
            }

            if (input.properties != null)
            {
                var properties = JsonUtility.Deserialize <Dictionary <string, Property> >(JsonUtility.Serialize(input.properties));

                foreach (var property in properties)
                {
                    if (property.Key == null || property.Value?.Value == null)
                    {
                        continue;
                    }

                    if (long.TryParse(property.Value.Value, out long d))
                    {
                        try
                        {
                            DateUtilities.EpochRef.AddMilliseconds(d);
                        }
                        catch
                        {
                            continue;
                        }
                    }

                    if (property.Key == "name")
                    {
                        data.Name = property.Value.Value;
                    }
                    else if (property.Key == "description")
                    {
                        data.Description = property.Value.Value;
                    }
                    else if (property.Key == "zip")
                    {
                        data.Properties[HubSpotVocabulary.Company.Zip] = property.Value.Value;
                    }
                    else if (property.Key == "country")
                    {
                        data.Properties[HubSpotVocabulary.Company.Country] = property.Value.Value;
                    }
                    else if (property.Key == "website")
                    {
                        data.Properties[HubSpotVocabulary.Company.Website] = property.Value.Value;
                    }
                    else if (property.Key == "days_to_close")
                    {
                        data.Properties[HubSpotVocabulary.Company.AnalyticsInformationDaystoClose] = property.Value.Value;
                    }
                    else if (property.Key == "address")
                    {
                        data.Properties[HubSpotVocabulary.Company.Address] = property.Value.Value;
                    }
                    else if (property.Key == "city")
                    {
                        data.Properties[HubSpotVocabulary.Company.City] = property.Value.Value;
                    }
                    else if (property.Key == "twitterhandle")
                    {
                        data.Properties[HubSpotVocabulary.Company.SocialMediaInformationTwitterHandle] = property.Value.Value;
                    }
                    else if (property.Key == "phone")
                    {
                        data.Properties[HubSpotVocabulary.Company.Phone] = property.Value.Value;
                    }
                    else if (property.Key == "state")
                    {
                        data.Properties[HubSpotVocabulary.Company.State] = property.Value.Value;
                    }
                    else if (property.Key == "company_notes")
                    {
                        data.Properties[HubSpotVocabulary.Company.Notes] = property.Value.Value;
                    }
                    else if (property.Key == "num_associated_contacts")
                    {
                        data.Properties[HubSpotVocabulary.Company.AssociateContactsCounts] = property.Value.Value;
                    }
                    else if (property.Key == "is_public")
                    {
                        data.Properties[HubSpotVocabulary.Company.IsPublic] = property.Value.Value;
                    }
                    else if (property.Key == "domain")
                    {
                        data.Properties[HubSpotVocabulary.Company.EmailDomain] = property.Value.Value;
                    }
                    else if (property.Key == "integrations")
                    {
                        data.Properties[HubSpotVocabulary.Company.Integrations] = property.Value.Value;
                    }
                    else if (property.Key == "createdate")
                    {
                        if (long.TryParse(property.Value.Value, out long date))
                        {
                            data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(date);
                        }
                        else
                        {
                            data.Properties[HubSpotVocabulary.Company.CompanyInformationCreateDate] = property.Value.Value;
                        }
                    }
                    else if (property.Key == "createddate")
                    {
                        if (long.TryParse(property.Value.Value, out long date))
                        {
                            data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(date);
                        }
                        else
                        {
                            data.Properties[HubSpotVocabulary.Company.CompanyInformationCreateDate] = property.Value.Value;
                        }
                    }
                    else if (property.Key == "hs_lastmodifieddate")
                    {
                        if (long.TryParse(property.Value.Value, out long date))
                        {
                            data.ModifiedDate = DateUtilities.EpochRef.AddMilliseconds(date);
                        }
                        else
                        {
                            data.Properties[HubSpotVocabulary.Company.CompanyInformationLastModifiedDate] = property.Value.Value;
                        }
                    }
                    else if (property.Key == "hs_analytics_source")
                    {
                        data.Properties[HubSpotVocabulary.Company.AnalyticsSource] = property.Value.Value;
                    }
                    else if (property.Key == "about_us")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationAboutUs] = property.Value.Value;
                    }
                    else if (property.Key == "facebookfans")
                    {
                        data.Properties[HubSpotVocabulary.Company.SocialMediaInformationFacebookFans] = property.Value.Value;
                    }
                    else if (property.Key == "photo" && !String.IsNullOrWhiteSpace(property.Value.Value))
                    {
                        var previewImagePart = _fileFetcher.FetchAsRawDataPart(property.Value.Value, "/RawData/PreviewImage", "preview_{0}".FormatWith(clue.OriginEntityCode.Key));
                        if (previewImagePart != null)
                        {
                            clue.Details.RawData.Add(previewImagePart);
                            clue.Data.EntityData.PreviewImage = new ImageReferencePart(previewImagePart);
                        }
                    }
                    else if (property.Key == "first_deal_created_date")
                    {
                        if (long.TryParse(property.Value.Value, out long date))
                        {
                            data.Properties[HubSpotVocabulary.Company.CompanyInformationFirstDealCreatedDate] = property.Value.Value;
                        }
                    }
                    else if (property.Key == "founded_year")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationYearFounded] = property.Value.Value;
                    }
                    else if (property.Key == "hs_analytics_first_timestamp")
                    {
                        if (long.TryParse(property.Value.Value, out long date))
                        {
                            data.Properties[HubSpotVocabulary.Company.AnalyticsInformationTimeFirstSeen] = DateUtilities.EpochRef.AddMilliseconds(date).ToString();
                        }
                    }
                    else if (property.Key == "hs_analytics_first_touch_converting_campaign")
                    {
                        data.Properties[HubSpotVocabulary.Company.AnalyticsInformationFirstTouchConvertingCampaign] = property.Value.Value;
                    }
                    else if (property.Key == "hs_analytics_first_visit_timestamp")
                    {
                        data.Properties[HubSpotVocabulary.Company.AnalyticsInformationTimeofFirstVisit] = property.Value.Value;
                    }
                    else if (property.Key == "hs_analytics_last_timestamp")
                    {
                        data.Properties[HubSpotVocabulary.Company.AnalyticsInformationTimeLastSeen] = property.Value.Value;
                    }
                    else if (property.Key == "hs_analytics_last_touch_converting_campaign")
                    {
                        data.Properties[HubSpotVocabulary.Company.AnalyticsInformationLastTouchConvertingCampaign] = property.Value.Value;
                    }
                    else if (property.Key == "hs_analytics_last_visit_timestamp")
                    {
                        data.Properties[HubSpotVocabulary.Company.AnalyticsInformationTimeofLastSession] = property.Value.Value;
                    }
                    else if (property.Key == "hs_analytics_num_page_views")
                    {
                        data.Properties[HubSpotVocabulary.Company.AnalyticsInformationNumberofPageviews] = property.Value.Value;
                    }
                    else if (property.Key == "hs_analytics_num_visits")
                    {
                        data.Properties[HubSpotVocabulary.Company.AnalyticsInformationNumberofVisits] = property.Value.Value;
                    }
                    else if (property.Key == "hs_analytics_source")
                    {
                        data.Properties[HubSpotVocabulary.Company.AnalyticsInformationOriginalSourceType] = property.Value.Value;
                    }
                    else if (property.Key == "hs_analytics_source_data_1")
                    {
                        data.Properties[HubSpotVocabulary.Company.AnalyticsInformationOriginalSourceData1] = property.Value.Value;
                    }
                    else if (property.Key == "hs_analytics_source_data_2")
                    {
                        data.Properties[HubSpotVocabulary.Company.AnalyticsInformationOriginalSourceData2] = property.Value.Value;
                    }
                    else if (property.Key == "hs_avatar_filemanager_key")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationAvatarFileManagerkey] = property.Value.Value;
                    }
                    else if (property.Key == "hubspot_owner_assigneddate")
                    {
                        if (long.TryParse(property.Value.Value, out long date))
                        {
                            data.Properties[HubSpotVocabulary.Company.CompanyInformationOwnerAssignedDate] = DateUtilities.EpochRef.AddMilliseconds(date).ToString();
                        }
                    }
                    else if (property.Key == "num_associated_contacts")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationAssociatedContacts] = property.Value.Value;
                    }
                    else if (property.Key == "num_associated_deals")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationAssociatedDeals] = property.Value.Value;
                    }
                    else if (property.Key == "recent_deal_amount")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationRecentDealAmount] = property.Value.Value;
                    }
                    else if (property.Key == "recent_deal_close_date")
                    {
                        if (long.TryParse(property.Value.Value, out long date))
                        {
                            data.Properties[HubSpotVocabulary.Company.CompanyInformationRecentDealCloseDate] = DateUtilities.EpochRef.AddMilliseconds(date).ToString();
                        }
                    }
                    else if (property.Key == "timezone")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationTimeZone] = property.Value.Value;
                    }
                    else if (property.Key == "total_money_raised")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationTotalMoneyRaised] = property.Value.Value;
                    }
                    else if (property.Key == "total_revenue")
                    {
                        if (input.Currency != null && !string.IsNullOrEmpty(property.Value.Value))
                        {
                            property.Value.Value = property.Value.Value + input.Currency;
                        }
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationTotalRevenue] = property.Value.Value;
                    }
                    else if (property.Key == "name")
                    {
                        if (!string.IsNullOrEmpty(property.Value.Value))
                        {
                            data.Name = property.Value.Value;
                        }
                    }
                    else if (property.Key == "twitterhandle")
                    {
                        data.Properties[HubSpotVocabulary.Company.SocialMediaInformationTwitterHandle] = property.Value.Value;
                    }
                    else if (property.Key == "phone")
                    {
                        if (!string.IsNullOrEmpty(property.Value.Value))
                        {
                            data.Properties[HubSpotVocabulary.Company.Phone] = property.Value.Value;
                        }
                    }
                    else if (property.Key == "twitterbio")
                    {
                        data.Properties[HubSpotVocabulary.Company.SocialMediaInformationTwitterBio] = property.Value.Value;
                    }
                    else if (property.Key == "twitterfollowers")
                    {
                        data.Properties[HubSpotVocabulary.Company.SocialMediaInformationTwitterFollowers] = property.Value.Value;
                    }
                    else if (property.Key == "address")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationStreetAddress] = property.Value.Value;
                    }
                    else if (property.Key == "address2")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationStreetAddress2] = property.Value.Value;
                    }
                    else if (property.Key == "facebook_company_page")
                    {
                        data.Properties[HubSpotVocabulary.Company.SocialMediaInformationFacebookCompanyPage] = property.Value.Value;
                    }
                    else if (property.Key == "city")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationCity] = property.Value.Value;
                    }
                    else if (property.Key == "linkedin_company_page")
                    {
                        data.Properties[HubSpotVocabulary.Company.SocialMediaInformationLinkedInCompanyPage] = property.Value.Value;
                    }
                    else if (property.Key == "linkedinbio")
                    {
                        data.Properties[HubSpotVocabulary.Company.SocialMediaInformationLinkedInBio] = property.Value.Value;
                    }
                    else if (property.Key == "state")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationStateRegion] = property.Value.Value;
                    }
                    else if (property.Key == "googleplus_page")
                    {
                        data.Properties[HubSpotVocabulary.Company.SocialMediaInformationGooglePlusPage] = property.Value.Value;
                    }
                    else if (property.Key == "engagements_last_meeting_booked")
                    {
                        data.Properties[HubSpotVocabulary.Company.LastMeetingBooked] = property.Value.Value;
                    }
                    else if (property.Key == "engagements_last_meeting_booked_campaign")
                    {
                        data.Properties[HubSpotVocabulary.Company.LastMeetingBookedCampaign] = property.Value.Value;
                    }
                    else if (property.Key == "engagements_last_meeting_booked_medium")
                    {
                        data.Properties[HubSpotVocabulary.Company.LastMeetingBookedMedium] = property.Value.Value;
                    }
                    else if (property.Key == "engagements_last_meeting_booked_source")
                    {
                        data.Properties[HubSpotVocabulary.Company.LastMeetingBookedSource] = property.Value.Value;
                    }
                    else if (property.Key == "hubspot_owner_id")
                    {
                        if (property.Value != null)
                        {
                            _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.OwnedBy, input, s => property.Value.Value.ToString());
                        }
                    }
                    else if (property.Key == "notes_last_contacted")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationLastContacted] = property.Value.Value;
                    }
                    else if (property.Key == "notes_last_updated")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationLastActivityDate] = property.Value.Value;
                    }
                    else if (property.Key == "notes_next_activity_date")
                    {
                        if (long.TryParse(property.Value.Value, out long date))
                        {
                            data.Properties[HubSpotVocabulary.Company.CompanyInformationNextActivityDate] = DateUtilities.EpochRef.AddMilliseconds(date).ToString();
                        }
                    }
                    else if (property.Key == "num_contacted_notes")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationNumberoftimescontacted] = property.Value.Value;
                    }
                    else if (property.Key == "num_notes")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationNumberofSalesActivities] = property.Value.Value;
                    }
                    else if (property.Key == "zip")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationPostalCode] = property.Value.Value;
                    }
                    else if (property.Key == "country")
                    {
                        if (!string.IsNullOrEmpty(property.Value.Value))
                        {
                            data.Properties[HubSpotVocabulary.Company.Country] = property.Value.Value;
                        }
                    }
                    else if (property.Key == "hubspot_team_id")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationHubSpotTeam] = property.Value.Value;
                    }
                    else if (property.Key == "website")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationWebsiteURL] = property.Value.Value;
                    }
                    else if (property.Key == "domain")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationCompanyDomainName] = property.Value.Value;
                    }
                    else if (property.Key == "numberofemployees")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationNumberofEmployees] = property.Value.Value;
                    }
                    else if (property.Key == "industry")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationIndustry] = property.Value.Value;
                    }
                    else if (property.Key == "annualrevenue")
                    {
                        if (input.Currency != null && !string.IsNullOrEmpty(property.Value.Value))
                        {
                            property.Value.Value = property.Value.Value + input.Currency;
                        }
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationAnnualRevenue] = property.Value.Value;
                    }
                    else if (property.Key == "lifecyclestage")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationLifecycleStage] = property.Value.Value;
                    }
                    else if (property.Key == "hs_lead_status")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationLeadStatus] = property.Value.Value;
                    }
                    else if (property.Key == "hs_parent_company_id")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationParentCompany] = property.Value.Value;
                    }
                    else if (property.Key == "type")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationType] = property.Value.Value;
                    }
                    else if (property.Key == "description")
                    {
                        if (!string.IsNullOrEmpty(property.Value.Value))
                        {
                            data.Description = property.Value.Value;
                        }
                    }
                    else if (property.Key == "hs_num_child_companies")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationNumberOfChildCompanies] = property.Value.Value;
                    }
                    else if (property.Key == "closedate")
                    {
                        if (long.TryParse(property.Value.Value, out long date))
                        {
                            data.Properties[HubSpotVocabulary.Company.CompanyInformationCloseDate] = DateUtilities.EpochRef.AddMilliseconds(date).ToString();
                        }
                    }
                    else if (property.Key == "first_contact_createdate")
                    {
                        if (long.TryParse(property.Value.Value, out long date))
                        {
                            data.Properties[HubSpotVocabulary.Company.CompanyInformationFirstContactCreateDate] = DateUtilities.EpochRef.AddMilliseconds(date).ToString();
                        }
                    }
                    else if (property.Key == "days_to_close")
                    {
                        data.Properties[HubSpotVocabulary.Company.AnalyticsInformationDaystoClose] = property.Value.Value;
                    }
                    else if (property.Key == "web_technologies")
                    {
                        data.Properties[HubSpotVocabulary.Company.CompanyInformationWebTechnologies] = property.Value.Value;
                    }
                    else if (property.Key == "company_address")
                    {
                        if (!string.IsNullOrEmpty(property.Value.Value))
                        {
                            data.Properties[HubSpotVocabulary.Company.Address] = property.Value.Value;
                        }
                    }
                    else
                    {
                        data.Properties[string.Format("hubspot.company.custom-{0}", property.Key)] = property.Value.Value;
                    }

                    if (properties.TryGetValue("photo", out Property photo))
                    {
                        if (!string.IsNullOrWhiteSpace(photo.Value))
                        {
                            var previewImagePart = _fileFetcher.FetchAsRawDataPart(photo.Value, "/RawData/PreviewImage", "preview_{0}".FormatWith(data.Name));
                            if (previewImagePart != null)
                            {
                                clue.Details.RawData.Add(previewImagePart);
                                clue.Data.EntityData.PreviewImage = new ImageReferencePart(previewImagePart, 255, 255);
                            }
                        }
                    }
                }
            }

            return(clue);
        }
示例#15
0
        protected override Clue MakeClueImpl(BlogPost input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.News, input.id.ToString(), accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_002_Uri_MustBeSet);

            var data = clue.Data.EntityData;

            data.Name        = input.name;
            data.Description = input.post_summary;

            if (input.created != null)
            {
                data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(input.created.Value);
            }

            if (input.updated != null)
            {
                data.ModifiedDate = DateUtilities.EpochRef.AddMilliseconds(input.updated.Value);
            }

            if (!string.IsNullOrEmpty(input.published_url))
            {
                data.Uri = new Uri(input.published_url);
            }

            if (input.url != null && Uri.TryCreate(input.url, UriKind.Absolute, out var uri))
            {
                data.Uri = uri;
            }

            data.Properties[HubSpotVocabulary.BlogPost.Archived]           = input.archived.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.BlogPost.BlogAuthor]         = input.blog_author.PrintIfAvailable(JsonUtility.Serialize);
            data.Properties[HubSpotVocabulary.BlogPost.Campaign]           = input.campaign.PrintIfAvailable(JsonUtility.Serialize);
            data.Properties[HubSpotVocabulary.BlogPost.CampaignName]       = input.campaign_name.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.BlogPost.ClonedFrom]         = input.cloned_from.PrintIfAvailable(JsonUtility.Serialize);
            data.Properties[HubSpotVocabulary.BlogPost.CommentCount]       = input.comment_count.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.BlogPost.DeletedAt]          = input.deleted_at.PrintIfAvailable(v => DateUtilities.EpochRef.AddMilliseconds(v.Value));
            data.Properties[HubSpotVocabulary.BlogPost.FeaturedImage]      = input.featured_image;
            data.Properties[HubSpotVocabulary.BlogPost.FooterHtml]         = input.footer_html;
            data.Properties[HubSpotVocabulary.BlogPost.FreezeDate]         = input.freeze_date.PrintIfAvailable(v => DateUtilities.EpochRef.AddMilliseconds(v.Value));
            data.Properties[HubSpotVocabulary.BlogPost.HasUserChanges]     = input.has_user_changes.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.BlogPost.HeadHtml]           = input.head_html;
            data.Properties[HubSpotVocabulary.BlogPost.HtmlTitle]          = input.html_title;
            data.Properties[HubSpotVocabulary.BlogPost.IsDraft]            = input.is_draft.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.BlogPost.MetaDescription]    = input.meta_description;
            data.Properties[HubSpotVocabulary.BlogPost.MetaKeywords]       = input.meta_keywords.PrintIfAvailable(JsonUtility.Serialize);
            data.Properties[HubSpotVocabulary.BlogPost.PerformableUrl]     = input.performable_url.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.BlogPost.PostBody]           = input.post_body;
            data.Properties[HubSpotVocabulary.BlogPost.PreviewImageSrc]    = input.preview_image_src.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.BlogPost.PreviewKey]         = input.preview_key;
            data.Properties[HubSpotVocabulary.BlogPost.ProcessingStatus]   = input.processing_status;
            data.Properties[HubSpotVocabulary.BlogPost.PublishDate]        = input.publish_date.PrintIfAvailable(v => DateUtilities.EpochRef.AddMilliseconds(v.Value));
            data.Properties[HubSpotVocabulary.BlogPost.PublishImmediately] = input.publish_immediately.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.BlogPost.PublishedUrl]       = input.published_url;
            data.Properties[HubSpotVocabulary.BlogPost.RssBody]            = input.rss_body;
            data.Properties[HubSpotVocabulary.BlogPost.RssSummary]         = input.rss_summary;
            data.Properties[HubSpotVocabulary.BlogPost.Slug]             = input.slug;
            data.Properties[HubSpotVocabulary.BlogPost.State]            = input.state;
            data.Properties[HubSpotVocabulary.BlogPost.StyleOverrideId]  = input.style_override_id.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.BlogPost.Subcategory]      = input.subcategory;
            data.Properties[HubSpotVocabulary.BlogPost.TopicsIds]        = input.topic_ids.PrintIfAvailable(JsonUtility.Serialize);
            data.Properties[HubSpotVocabulary.BlogPost.WidgetContainers] = input.widget_containers.PrintIfAvailable(JsonUtility.Serialize);
            data.Properties[HubSpotVocabulary.BlogPost.WidgetContainers] = input.widgetcontainers.PrintIfAvailable(JsonUtility.Serialize);
            data.Properties[HubSpotVocabulary.BlogPost.Widgets]          = input.widgets.PrintIfAvailable();

            if (input.author_user_id != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.CreatedBy, input, input.author_user_id.Value.ToString());
            }

            if (input.blog_author_id != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.CreatedBy, input, input.blog_author_id.Value.ToString());
            }

            if (input.campaign != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Marketing.Campaign, EntityEdgeType.For, input, input.campaign.ToString());
            }

            if (input.content_group_id != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Tag, EntityEdgeType.For, input, input.content_group_id.Value.ToString());
            }

            if (input.portal_id != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.PartOf, input, s => s.portal_id.ToString(), s => "HubSpot");
            }

            if (!String.IsNullOrWhiteSpace(input.featured_image))
            {
                var previewImagePart = _fileFetcher.FetchAsRawDataPart(input.featured_image, "/RawData/PreviewImage", "preview_{0}".FormatWith(clue.OriginEntityCode.Key));
                if (previewImagePart != null)
                {
                    clue.Details.RawData.Add(previewImagePart);
                    clue.Data.EntityData.PreviewImage = new ImageReferencePart(previewImagePart);
                }
            }

            return(clue);
        }
示例#16
0
        protected override Clue MakeClueImpl(CalendarEvent input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Calendar.Event, input.id, accountId);

            clue.ValidationRuleSuppressions.Add(CluedIn.Core.Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(CluedIn.Core.Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);

            var data = clue.Data.EntityData;

            data.Name        = input.name;
            data.Description = input.description;

            if (input.url != null)
            {
                data.Uri = new Uri(input.url);
            }

            data.Properties[HubSpotVocabulary.CalendarEvent.AvatarUrl]         = input.avatarUrl.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.CalendarEvent.Category]          = input.category;
            data.Properties[HubSpotVocabulary.CalendarEvent.CreatedById]       = input.createdById.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.CalendarEvent.DayOfWeek]         = input.eventDate.PrintIfAvailable(v => DateUtilities.EpochRef.AddMilliseconds(v).DayOfWeek);
            data.Properties[HubSpotVocabulary.CalendarEvent.EventDate]         = input.eventDate.PrintIfAvailable(v => DateUtilities.EpochRef.AddMilliseconds(v));
            data.Properties[HubSpotVocabulary.CalendarEvent.EventType]         = input.eventType;
            data.Properties[HubSpotVocabulary.CalendarEvent.PreviewKey]        = input.previewKey;
            data.Properties[HubSpotVocabulary.CalendarEvent.Recurring]         = input.recurring.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.CalendarEvent.SocialDisplayName] = input.socialDisplayName.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.CalendarEvent.SocialUserName]    = input.socialUsername.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.CalendarEvent.State]             = input.state;
            data.Properties[HubSpotVocabulary.CalendarEvent.TopicsIds]         = input.topicIds.PrintIfAvailable();

            if (input.campaignGuid != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Marketing.Campaign, EntityEdgeType.PartOf, input, s => s.campaignGuid);
            }

            if (input.categoryId != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Tag, EntityEdgeType.PartOf, input, s => s.categoryId.ToString());
            }

            if (input.contentGroupId != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Tag, EntityEdgeType.PartOf, input, s => s.contentGroupId.ToString());
            }

            if (input.contentId != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.News, EntityEdgeType.PartOf, input, s => s.contentId.ToString());
            }

            if (input.createdBy != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.CreatedBy, input, s => s.createdBy.ToString());
            }

            if (input.ownerId != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.OwnedBy, input, s => s.createdBy.ToString());
            }

            if (input.portalId != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.PartOf, input, s => s.portalId.ToString(), s => "HubSpot");
            }


            return(clue);
        }
示例#17
0
        protected override Clue MakeClueImpl(Meeting input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Calendar.Meeting, input.engagement.id.ToString(), accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);

            var data = clue.Data.EntityData;

            if (input.Reminder != null)
            {
                data.Properties[HubSpotVocabulary.Meeting.Reminder] = DateUtilities.EpochRef.AddMilliseconds(input.Reminder.Value).ToString();
            }
            if (input.associations != null)
            {
                if (input.associations.companyIds != null)
                {
                    foreach (var companyId in input.associations.companyIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Organization, EntityEdgeType.Parent, input, selector => companyId.ToString());
                    }
                }
                if (input.associations.contactIds != null)
                {
                    foreach (var contactId in input.associations.contactIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Contact, EntityEdgeType.PartOf, input, selector => contactId.ToString());
                    }
                }
                if (input.associations.dealIds != null)
                {
                    foreach (var dealId in input.associations.dealIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Sales.Deal, EntityEdgeType.Parent, input, selector => dealId.ToString());
                    }
                }
                if (input.associations.ownerIds != null)
                {
                    foreach (var ownerId in input.associations.ownerIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.OwnedBy, input, selector => ownerId.ToString());
                    }
                }
                if (input.associations.workflowIds != null)
                {
                    foreach (var workflowId in input.associations.workflowIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Process, EntityEdgeType.Parent, input, selector => workflowId.ToString());
                    }
                }
            }

            if (input.engagement != null)
            {
                if (input.engagement.id != null)
                {
                    //var url =
                    //data.Uri = new Uri(url);
                }
                if (input.engagement.createdAt != null)
                {
                    if (long.TryParse(input.engagement.createdAt.ToString(), out long date))
                    {
                        data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(date);
                    }
                }
                if (input.engagement.lastUpdated != null)
                {
                    if (long.TryParse(input.engagement.lastUpdated.ToString(), out long date))
                    {
                        data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(date);
                    }
                }
                if (input.engagement.timestamp != null)
                {
                    if (data.CreatedDate == null)
                    {
                        if (long.TryParse(input.engagement.createdAt.ToString(), out long date))
                        {
                            data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(date);
                        }
                    }
                }
                if (input.engagement.active != null)
                {
                    data.Properties[HubSpotVocabulary.Email.Active] = input.engagement.active.Value.ToString();
                }
                if (input.engagement.createdBy != null)
                {
                    _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.CreatedBy, input, selector => input.engagement.createdBy.ToString());
                }
                if (input.engagement.modifiedBy != null)
                {
                    _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.ModifiedBy, input, selector => input.engagement.modifiedBy.ToString());
                }
                if (input.engagement.ownerId != null)
                {
                    _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.OwnedBy, input, selector => input.engagement.ownerId.ToString());
                }
                if (input.engagement.portalId != null)
                {
                    _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.Parent, input, selector => input.engagement.portalId.ToString());
                }
            }

            try
            {
                var metadata = JsonUtility.Deserialize <Dictionary <string, object> >(JsonUtility.Serialize(input.metadata));

                if (metadata != null)
                {
                    foreach (var property in metadata)
                    {
                        if (property.Key == "startTime" && property.Value != null && !string.IsNullOrEmpty(property.Value.ToString()))
                        {
                            if (long.TryParse(property.Value.ToString(), out long startTime))
                            {
                                data.Properties[HubSpotVocabulary.Meeting.StartTime] = DateUtilities.EpochRef.AddMilliseconds(startTime).ToString();
                            }
                        }
                        else if (property.Key == "endTime" && property.Value != null && !string.IsNullOrEmpty(property.Value.ToString()))
                        {
                            if (long.TryParse(property.Value.ToString(), out long endTime))
                            {
                                data.Properties[HubSpotVocabulary.Meeting.EndTime] = DateUtilities.EpochRef.AddMilliseconds(endTime).ToString();
                            }
                        }
                        else if (property.Key == "title" && property.Value != null && !string.IsNullOrEmpty(property.Value.ToString()))
                        {
                            data.Name = property.Value.ToString();
                            //data.Properties[HubSpotVocabulary.Meeting.Title] = property.Value.ToString();
                        }
                        else if (property.Key == "body" && property.Value != null && !string.IsNullOrEmpty(property.Value.ToString()))
                        {
                            if (string.IsNullOrEmpty(data.Name))
                            {
                                data.Name = Regex.Replace(property.Value.ToString(), "<.*?>", String.Empty);
                            }
                            data.Description = Regex.Replace(property.Value.ToString(), "<.*?>", String.Empty);
                            if (Regex.Replace(property.Value.ToString(), "<.*?>", String.Empty).Length > 200)
                            {
                                data.Properties[HubSpotVocabulary.Meeting.Description] = property.Value.ToString();
                            }
                        }
                        else if (property.Key == "preMeetingProspectReminders")
                        {
                        }
                        else
                        {
                            if (property.Value != null && !string.IsNullOrEmpty(property.Value.ToString()))
                            {
                                data.Properties[string.Format("hubspot.meeting.custom-{0}", property.Key)] = property.Value.ToString();
                            }
                        }
                    }
                }
            }

            catch (Exception exception)
            {
                _log.Error(() => "Failed to parse metadata for Hubspot Meeting", exception);
            }
            if (data.Name == null)
            {
                data.Name = input.engagement.type + " at " + data.CreatedDate.Value.ToString("MM/dd/yyyy hh:mm tt", CultureInfo.InvariantCulture);
            }



            return(clue);
        }
示例#18
0
        protected override Clue MakeClueImpl(EngagementResult input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Activity, input.engagement.id.ToString(), accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_001_Name_MustBeSet);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_002_Uri_MustBeSet);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_003_Author_Name_MustBeSet);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_004_Invalid_EntityType);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_005_PreviewImage_RawData_MustBeSet);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_006_Created_Modified_Date_InFuture);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_007_Created_Modified_Date_InPast);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_008_Created_Modified_Date_UnixEpoch);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_009_Created_Modified_Date_MinDate);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_010_Created_Modified_Date_MaxDate);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.PROPERTIES_001_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.PROPERTIES_002_Unknown_VocabularyKey_Used);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.PROPERTIES_003_Value_ShouldNotBeQuoted);

            var data = clue.Data.EntityData;

            if (input.associations != null)
            {
                if (input.associations.companyIds != null)
                {
                    foreach (var association in input.associations.companyIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Organization, EntityEdgeType.PartOf, input, a => association.ToString());
                    }
                }

                if (input.associations.contactIds != null)
                {
                    foreach (var association in input.associations.contactIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.PartOf, input, a => association.ToString());
                    }
                }

                if (input.associations.dealIds != null)
                {
                    foreach (var association in input.associations.dealIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Sales.Deal, EntityEdgeType.PartOf, input, a => association.ToString());
                    }
                }

                if (input.associations.workflowIds != null)
                {
                    foreach (var association in input.associations.workflowIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Process, EntityEdgeType.PartOf, input, a => association.ToString());
                    }
                }
            }

            if (input.scheduledTasks != null)
            {
                foreach (var task in input.scheduledTasks)
                {
                    var r = JsonUtility.Deserialize <Dictionary <string, object> >(JsonUtility.Serialize(task));
                    foreach (var p in r)
                    {
                        if (p.Key == "uuid")
                        {
                            _factory.CreateIncomingEntityReference(clue, EntityType.Task, EntityEdgeType.PartOf, input, a => p.Value.ToString());
                        }
                    }
                }
            }


            if (input.attachments != null)
            {
                foreach (var association in input.attachments)
                //Download
                {
                }
            }

            if (input.engagement != null)
            {
                if (input.engagement.createdAt != null)
                {
                    if (long.TryParse(input.engagement.createdAt.ToString(), out long date))
                    {
                        data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(date);
                    }
                }

                if (input.engagement.lastUpdated != null)
                {
                    if (long.TryParse(input.engagement.lastUpdated.ToString(), out long date))
                    {
                        data.ModifiedDate = DateUtilities.EpochRef.AddMilliseconds(date);
                    }
                }

                if (input.engagement.createdBy != null)
                {
                    data.Authors.Add(new PersonReference(new EntityCode(EntityType.Person, HubSpotNameConstants.CodeOrigin, input.engagement.createdBy.Value)));
                }

                if (input.engagement.modifiedBy != null)
                {
                    data.LastChangedBy = new PersonReference(new EntityCode(EntityType.Person, HubSpotNameConstants.CodeOrigin, input.engagement.modifiedBy.Value));
                }

                if (input.engagement.active != null)
                {
                    data.Properties[HubSpotVocabulary.Engagement.Active] = input.engagement.active.ToString();
                }
                if (input.engagement.type != null)
                {
                    data.Properties[HubSpotVocabulary.Engagement.Type] = input.engagement.type.ToString();
                }
                if (input.engagement.timestamp != null)
                {
                    if (long.TryParse(input.engagement.timestamp.ToString(), out long timestamp))
                    {
                        data.Properties[HubSpotVocabulary.Engagement.TimeStamp] = DateUtilities.EpochRef.AddMilliseconds(timestamp).ToString();
                    }
                }

                if (input.engagement.ownerId != null)
                {
                    _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.PartOf, input, a => a.engagement.ownerId.ToString());
                }

                if (input.engagement.portalId != null)
                {
                    _factory.CreateIncomingEntityReference(clue, EntityType.Organization, EntityEdgeType.PartOf, input, a => a.engagement.portalId.ToString());
                }
            }

            if (input.metadata != null)
            {
                var metadata = JsonUtility.Deserialize <EngagementMetadata>(JsonUtility.Serialize(input.metadata));

                if (metadata.body != null)
                {
                    data.Name        = Regex.Replace(metadata.body, "<.*?>", String.Empty);
                    data.Description = Regex.Replace(metadata.body, "<.*?>", String.Empty) ?? metadata.status;
                }
                if (metadata.durationMilliseconds != null)
                {
                    data.Properties[HubSpotVocabulary.Engagement.Duration] = metadata.durationMilliseconds.ToString();
                }
                if (metadata.forObjectType != null)
                {
                    data.Properties[HubSpotVocabulary.Engagement.ObjectType] = metadata.forObjectType;
                }
                if (metadata.status != null)
                {
                    data.Properties[HubSpotVocabulary.Engagement.Status] = metadata.status;
                }
            }
            if (data.Name == null)
            {
                data.Name = input.engagement.type + " at " + data.CreatedDate.Value.ToString("MM/dd/yyyy hh:mm tt", CultureInfo.InvariantCulture);
            }

            return(clue);
        }
示例#19
0
        protected override Clue MakeClueImpl(Ticket input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Support.Ticket, input.ObjectId.ToString(), accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.PROPERTIES_002_Unknown_VocabularyKey_Used);

            var data = clue.Data.EntityData;

            data.Uri = new Uri(
                $"https://app.hubspot.com/tickets/{input.PortalId.Value}/tickets?ticketId={input.ObjectId}");  // TODO take from configuration
            data.Properties[HubSpotVocabulary.Product.Version]   = input.Version.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Product.IsDeleted] = input.IsDeleted.PrintIfAvailable();

            if (input.Properties != null)
            {
                try
                {
                    var jobject    = JObject.Parse(JsonUtility.Serialize(input.Properties));
                    var properties = new List <Property>();
                    jobject.Properties().ForEach(c =>
                                                 properties.Add(new Property
                    {
                        Name      = c.Name,
                        Value     = c.Value["value"]?.ToString(),
                        Timestamp = c.Value["timestamp"]?.ToString(),
                        Source    = c.Value["source"]?.ToString(),
                        SourceId  = c.Value["sourceId"]?.ToString()
                    }));

                    foreach (var r in properties)
                    {
                        if (r.Name == "closed_date")
                        {
                            long epoch = long.MinValue;
                            if (!long.TryParse(r.Timestamp, out epoch))
                            {
                                long.TryParse(r.Value, out epoch);
                            }
                            if (epoch != long.MinValue)
                            {
                                if (DateUtilities.EpochRef.AddMilliseconds(epoch) != null)
                                {
                                    data.Properties[HubSpotVocabulary.Ticket.ClosedDate] = DateUtilities.EpochRef.AddMilliseconds(epoch).ToString("o");
                                }
                            }
                        }
                        else if (r.Name == "created_by")
                        {
                            if (r.Value != null)
                            {
                                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.User, EntityEdgeType.CreatedBy, input, p => r.Value);
                            }
                            data.Properties[HubSpotVocabulary.Ticket.CreatedBy] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "createdate")
                        {
                            long epoch = long.MinValue;
                            if (!long.TryParse(r.Timestamp, out epoch))
                            {
                                long.TryParse(r.Value, out epoch);
                            }
                            if (epoch != long.MinValue)
                            {
                                data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(epoch);
                            }
                            if (data.CreatedDate != null)
                            {
                                data.Properties[HubSpotVocabulary.Ticket.CreatedDate] = data.CreatedDate.Value.ToString("o");
                            }
                            if (r.SourceId != null)
                            {
                                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.User, EntityEdgeType.CreatedBy, input, c => r.SourceId);
                            }
                        }
                        else if (r.Name == "first_agent_reply_date")
                        {
                            long epoch = long.MinValue;
                            if (!long.TryParse(r.Timestamp, out epoch))
                            {
                                long.TryParse(r.Value, out epoch);
                            }
                            if (epoch != long.MinValue)
                            {
                                if (DateUtilities.EpochRef.AddMilliseconds(epoch) != null)
                                {
                                    data.Properties[HubSpotVocabulary.Ticket.FirstAgentResponseDate] = DateUtilities.EpochRef.AddMilliseconds(epoch).ToString("o");
                                }
                            }
                        }
                        else if (r.Name == "hs_lastactivitydate")
                        {
                            long epoch = long.MinValue;
                            if (!long.TryParse(r.Timestamp, out epoch))
                            {
                                long.TryParse(r.Value, out epoch);
                            }
                            if (epoch != long.MinValue)
                            {
                                if (DateUtilities.EpochRef.AddMilliseconds(epoch) != null)
                                {
                                    data.Properties[HubSpotVocabulary.Ticket.LastActivityDate] = DateUtilities.EpochRef.AddMilliseconds(epoch).ToString("o");
                                }
                            }
                        }
                        else if (r.Name == "hs_lastcontacted")
                        {
                            long epoch = long.MinValue;
                            if (!long.TryParse(r.Timestamp, out epoch))
                            {
                                long.TryParse(r.Value, out epoch);
                            }
                            if (epoch != long.MinValue)
                            {
                                if (DateUtilities.EpochRef.AddMilliseconds(epoch) != null)
                                {
                                    data.Properties[HubSpotVocabulary.Ticket.LastContactedDate] = DateUtilities.EpochRef.AddMilliseconds(epoch).ToString("o");
                                }
                            }
                        }
                        else if (r.Name == "hs_lastmodifieddate")
                        {
                            long epoch = long.MinValue;
                            if (!long.TryParse(r.Timestamp, out epoch))
                            {
                                long.TryParse(r.Value, out epoch);
                            }
                            if (epoch != long.MinValue)
                            {
                                data.ModifiedDate = DateUtilities.EpochRef.AddMilliseconds(epoch);
                            }
                            if (data.ModifiedDate != null)
                            {
                                data.Properties[HubSpotVocabulary.Ticket.LastModifiedDate] = data.ModifiedDate.Value.ToString("o");
                            }
                        }
                        else if (r.Name == "hs_nextactivitydate")
                        {
                            long epoch = long.MinValue;
                            if (!long.TryParse(r.Timestamp, out epoch))
                            {
                                long.TryParse(r.Value, out epoch);
                            }
                            if (epoch != long.MinValue)
                            {
                                if (DateUtilities.EpochRef.AddMilliseconds(epoch) != null)
                                {
                                    data.Properties[HubSpotVocabulary.Ticket.NextActivityDate] = DateUtilities.EpochRef.AddMilliseconds(epoch).ToString("o");
                                }
                            }
                        }
                        else if (r.Name == "last_engagement_date")
                        {
                            long epoch = long.MinValue;
                            if (!long.TryParse(r.Timestamp, out epoch))
                            {
                                long.TryParse(r.Value, out epoch);
                            }
                            if (epoch != long.MinValue)
                            {
                                if (DateUtilities.EpochRef.AddMilliseconds(epoch) != null)
                                {
                                    data.Properties[HubSpotVocabulary.Ticket.DateOfLastEngagement] = DateUtilities.EpochRef.AddMilliseconds(epoch).ToString("o");
                                }
                            }
                        }
                        else if (r.Name == "last_reply_date")
                        {
                            long epoch = long.MinValue;
                            if (!long.TryParse(r.Timestamp, out epoch))
                            {
                                long.TryParse(r.Value, out epoch);
                            }
                            if (epoch != long.MinValue)
                            {
                                if (DateUtilities.EpochRef.AddMilliseconds(epoch) != null)
                                {
                                    data.Properties[HubSpotVocabulary.Ticket.LastCustomerReplyDate] = DateUtilities.EpochRef.AddMilliseconds(epoch).ToString("o");
                                }
                            }
                        }
                        else if (r.Name == "hubspot_owner_assigneddate")
                        {
                            long epoch = long.MinValue;
                            if (!long.TryParse(r.Timestamp, out epoch))
                            {
                                long.TryParse(r.Value, out epoch);
                            }
                            if (epoch != long.MinValue)
                            {
                                if (DateUtilities.EpochRef.AddMilliseconds(epoch) != null)
                                {
                                    data.Properties[HubSpotVocabulary.Ticket.OwnerAssignedDate] = DateUtilities.EpochRef.AddMilliseconds(epoch).ToString("o");
                                }
                            }
                        }
                        else if (r.Name == "hubspot_owner_id")
                        {
                            if (r.Value != null)
                            {
                                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.User, EntityEdgeType.OwnedBy, input, p => r.Value);
                            }
                            data.Properties[HubSpotVocabulary.Ticket.TicketOwner] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "hs_custom_inbox")
                        {
                            data.Properties[HubSpotVocabulary.Ticket.CustomInboxID] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "hs_num_times_contacted")
                        {
                            data.Properties[HubSpotVocabulary.Ticket.NumberOfTimesContacted] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "hs_pipeline")
                        {
                            data.Properties[HubSpotVocabulary.Ticket.Pipeline] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "hs_pipeline_stage")
                        {
                            data.Properties[HubSpotVocabulary.Ticket.TicketStatus] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "hs_resolution")
                        {
                            data.Properties[HubSpotVocabulary.Ticket.Resolution] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "hs_ticket_category")
                        {
                            data.Properties[HubSpotVocabulary.Ticket.Category] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "hs_ticket_id")
                        {
                            data.Properties[HubSpotVocabulary.Ticket.TicketId] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "hs_ticket_priority")
                        {
                            data.Properties[HubSpotVocabulary.Ticket.Priority] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "nps_follow_up_answer")
                        {
                            data.Properties[HubSpotVocabulary.Ticket.NPSfollowup] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "nps_follow_up_question_version")
                        {
                            data.Properties[HubSpotVocabulary.Ticket.NPSfollowupQuestion] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "nps_score")
                        {
                            data.Properties[HubSpotVocabulary.Ticket.ConversationNPSscore] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "source_thread_id")
                        {
                            data.Properties[HubSpotVocabulary.Ticket.ReferenceToeEmailThread] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "time_to_close")
                        {
                            data.Properties[HubSpotVocabulary.Ticket.TimeToClose] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "time_to_first_agent_reply")
                        {
                            data.Properties[HubSpotVocabulary.Ticket.TimeToFirstAgentReply] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "subject")
                        {
                            data.Properties[HubSpotVocabulary.Ticket.TicketName] = data.Name = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "content")
                        {
                            data.Properties[HubSpotVocabulary.Ticket.TicketDescription] = data.Description = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "source_type")
                        {
                            data.Properties[HubSpotVocabulary.Ticket.Source] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "source_ref")
                        {
                            data.Properties[HubSpotVocabulary.Ticket.ReferenceToSourceSpecificObject] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "tags")
                        {
                            data.Properties[HubSpotVocabulary.Ticket.Tags] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "hubspot_team_id")
                        {
                            data.Properties[HubSpotVocabulary.Ticket.HubSpotTeam] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "hs_all_owner_ids")
                        {
                            data.Properties[HubSpotVocabulary.Ticket.AllOwnerIds] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "hs_all_team_ids")
                        {
                            data.Properties[HubSpotVocabulary.Ticket.AllTeamIds] = r.Value.PrintIfAvailable();
                        }
                        else
                        {
                            data.Properties[string.Format("hubspot.ticket.custom-{0}", r.Name)] = r.Value.PrintIfAvailable();
                        }
                    }
                }
                catch (Exception exception)
                {
                    _log.Error(() => "Failed to parse properties for Hubspot Ticket", exception);
                }
            }

            if (input.Associations != null)
            {
                if (input.Associations.Companies.Any())
                {
                    foreach (var t in input.Associations.Companies)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Organization, EntityEdgeType.Involves, input, p => t.ToString());
                    }
                }

                if (input.Associations.Contacts.Any())
                {
                    foreach (var t in input.Associations.Contacts)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Contact, EntityEdgeType.Involves, input, p => t.ToString());
                    }
                }

                if (input.Associations.Engagements.Any())
                {
                    foreach (var t in input.Associations.Engagements)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Activity, EntityEdgeType.Involves, input, p => t.ToString());
                    }
                }
            }

            return(clue);
        }
示例#20
0
        protected override Clue MakeClueImpl(LineItem input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Sales.Order, input.ObjectId.ToString(), accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_001_Name_MustBeSet);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_002_Uri_MustBeSet);

            var data = clue.Data.EntityData;

            data.Properties[HubSpotVocabulary.LineItem.Version]   = input.Version.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.LineItem.IsDeleted] = input.IsDeleted.PrintIfAvailable();

            if (input.Properties != null)
            {
                try
                {
                    var jobject    = JObject.Parse(JsonUtility.Serialize(input.Properties));
                    var properties = new List <Property>();
                    if (jobject?.Properties() != null)
                    {
                        jobject.Properties().ForEach(c =>
                                                     properties.Add(new Property
                        {
                            Name      = c.Name,
                            Value     = c.Value["value"]?.ToString(),
                            Timestamp = c.Value["timestamp"]?.ToString(),
                            Source    = c.Value["source"]?.ToString(),
                            SourceId  = c.Value["sourceId"]?.ToString()
                        }));
                    }

                    foreach (var r in properties)
                    {
                        if (r.Name == "createdate")
                        {
                            long epoch = long.MinValue;
                            if (!long.TryParse(r.Timestamp, out epoch))
                            {
                                long.TryParse(r.Value, out epoch);
                            }
                            if (epoch != long.MinValue)
                            {
                                data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(epoch);
                            }
                            if (data.CreatedDate != null)
                            {
                                data.Properties[HubSpotVocabulary.LineItem.CreateDate] = data.CreatedDate.Value.ToString("o");
                            }
                            if (r.SourceId != null)
                            {
                                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.User, EntityEdgeType.CreatedBy, input, c => r.SourceId);
                            }
                        }

                        else if (r.Name == "hs_lastmodifieddate")
                        {
                            long epoch = long.MinValue;
                            if (!long.TryParse(r.Timestamp, out epoch))
                            {
                                long.TryParse(r.Value, out epoch);
                            }
                            if (epoch != long.MinValue)
                            {
                                data.ModifiedDate = DateUtilities.EpochRef.AddMilliseconds(epoch);
                            }
                            if (data.ModifiedDate != null)
                            {
                                data.Properties[HubSpotVocabulary.LineItem.LastModifiedDate] = data.ModifiedDate.Value.ToString("o");
                            }
                        }

                        else if (r.Name == "hs_recurring_billing_end_date")
                        {
                            long epoch = long.MinValue;
                            if (!long.TryParse(r.Timestamp, out epoch))
                            {
                                long.TryParse(r.Value, out epoch);
                            }
                            if (epoch != long.MinValue)
                            {
                                if (DateUtilities.EpochRef.AddMilliseconds(epoch) != null)
                                {
                                    data.Properties[HubSpotVocabulary.LineItem.EndDate] = DateUtilities.EpochRef.AddMilliseconds(epoch).ToString("o");
                                }
                            }
                        }

                        else if (r.Name == "hs_recurring_billing_start_date")
                        {
                            long epoch = long.MinValue;
                            if (!long.TryParse(r.Timestamp, out epoch))
                            {
                                long.TryParse(r.Value, out epoch);
                            }
                            if (epoch != long.MinValue)
                            {
                                if (DateUtilities.EpochRef.AddMilliseconds(epoch) != null)
                                {
                                    data.Properties[HubSpotVocabulary.LineItem.StartDate] = DateUtilities.EpochRef.AddMilliseconds(epoch).ToString("o");
                                }
                            }
                        }

                        else if (r.Name == "hs_deal_closed_won_date")
                        {
                            long epoch = long.MinValue;
                            if (!long.TryParse(r.Timestamp, out epoch))
                            {
                                long.TryParse(r.Value, out epoch);
                            }
                            if (epoch != long.MinValue)
                            {
                                if (DateUtilities.EpochRef.AddMilliseconds(epoch) != null)
                                {
                                    data.Properties[HubSpotVocabulary.LineItem.Dealclosedwondate] = DateUtilities.EpochRef.AddMilliseconds(epoch).ToString("o");
                                }
                            }
                        }

                        else if (r.Name == "hs_product_id")
                        {
                            if (r.Value != null && r.Value.ToString() != string.Empty)
                            {
                                _factory.CreateIncomingEntityReference(clue, EntityType.Product, EntityEdgeType.Parent, input, c => r.Value.ToString());
                            }

                            data.Properties[HubSpotVocabulary.LineItem.ProductID] = r.Value.PrintIfAvailable();
                        }

                        else if (r.Name == "name")
                        {
                            data.Properties[HubSpotVocabulary.LineItem.Name] = data.Name = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "description")
                        {
                            data.Properties[HubSpotVocabulary.LineItem.Productdescription] = data.Description = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "amount")
                        {
                            data.Properties[HubSpotVocabulary.LineItem.Amount] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "price")
                        {
                            data.Properties[HubSpotVocabulary.LineItem.Productprice] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "quantity")
                        {
                            data.Properties[HubSpotVocabulary.LineItem.Quantity] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "recurringbillingfrequency")
                        {
                            data.Properties[HubSpotVocabulary.LineItem.Recurringbillingfrequency] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "discount")
                        {
                            data.Properties[HubSpotVocabulary.LineItem.DiscountAmount] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "hs_discount_percentage")
                        {
                            data.Properties[HubSpotVocabulary.LineItem.DiscountPercentage] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "tax")
                        {
                            data.Properties[HubSpotVocabulary.LineItem.Tax] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "hs_recurring_billing_period")
                        {
                            data.Properties[HubSpotVocabulary.LineItem.Term] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "hs_cost_of_goods_sold")
                        {
                            data.Properties[HubSpotVocabulary.LineItem.Costofgoodssold] = r.Value.PrintIfAvailable();
                        }
                        else
                        {
                            data.Properties[string.Format("hubspot.lineitem.custom-{0}", r.Name)] = r.Value.PrintIfAvailable();
                        }
                    }
                }
                catch (Exception exception)
                {
                    _log.Error(() => "Could not parse HubSpot Line Item Properies", exception);
                }

                if (input.Associations.Any())
                {
                    foreach (var association in input.Associations)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Sales.Deal, EntityEdgeType.PartOf, input, s => association.ToString());
                    }
                }

                if (!data.OutgoingEdges.Any() && input.PortalId != null)
                {
                    _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.PartOf, input, s => s.PortalId.ToString(), s => "Hubspot");
                }
            }

            return(clue);
        }
示例#21
0
        protected override Clue MakeClueImpl(Deal input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Sales.Deal, input.dealId.ToString(), accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.PROPERTIES_002_Unknown_VocabularyKey_Used);

            var data = clue.Data.EntityData;

            data.Name = input.dealId.Value.ToString(CultureInfo.InvariantCulture);

            if (input.associations != null)
            {
                if (input.associations != null)
                {
                    if (input.associations.associatedCompanyIds != null)
                    {
                        foreach (var company in input.associations.associatedCompanyIds)
                        {
                            _factory.CreateIncomingEntityReference(clue, EntityType.Organization, EntityEdgeType.PartOf, input, s => company.ToString());
                        }
                    }

                    if (input.associations.associatedDealIds != null)
                    {
                        foreach (var company in input.associations.associatedDealIds)
                        {
                            _factory.CreateIncomingEntityReference(clue, EntityType.Sales.Deal, EntityEdgeType.PartOf, input, s => company.ToString());
                        }
                    }

                    if (input.associations.associatedVids != null)
                    {
                        foreach (var company in input.associations.associatedVids)
                        {
                            _factory.CreateIncomingEntityReference(clue, EntityType.Activity, EntityEdgeType.PartOf, input, s => company.ToString());
                        }
                    }
                }
            }
            if (input.portalId != null)
            {
                if (data.OutgoingEdges.Count == 0)
                {
                    _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.PartOf, input, s => s.portalId.ToString(), s => "Hubspot");
                }

                string url = $"https://app.hubspot.com/sales/{input.portalId}/deal/{input.dealId}/";  // TODO take from configuration
                data.Uri = new Uri(url);
            }

            if (input.properties != null)
            {
                JObject allProperties = JObject.Parse(JsonUtility.Serialize(input.properties));

                foreach (var property in allProperties)
                {
                    string         val  = null;
                    DateTimeOffset?date = null;
                    if (property.Value["value"] != null && property.Value["value"].ToString() != null)
                    {
                        val = property.Value["value"].ToString();
                        if (long.TryParse(val, out long epoch))
                        {
                            try
                            {
                                date = DateUtilities.EpochRef.AddMilliseconds(epoch);
                            }
                            catch
                            {
                            }
                        }
                    }
                    if (val == null)
                    {
                        continue;
                    }

                    if (property.Key == "hs_analytics_source")
                    {
                        data.Properties[HubSpotVocabulary.Deal.AnalyticsInformationOriginalSourceType] = val;
                    }
                    else if (property.Key == "hs_analytics_source_data_1")
                    {
                        data.Properties[HubSpotVocabulary.Deal.AnalyticsInformationOriginalSourceData1] = val;
                    }
                    else if (property.Key == "hs_analytics_source_data_2")
                    {
                        data.Properties[HubSpotVocabulary.Deal.AnalyticsInformationOriginalSourceData2] = val;
                    }
                    else if (property.Key == "hs_lastmodifieddate")
                    {
                        if (date.HasValue)
                        {
                            data.ModifiedDate = date.Value;
                        }
                    }
                    else if (property.Key == "hubspot_owner_assigneddate")
                    {
                        if (date.HasValue)
                        {
                            data.Properties[HubSpotVocabulary.Deal.DealInformationOwnerAssignedDate] = date.Value.ToString();
                        }
                    }
                    else if (property.Key == "dealname")
                    {
                        data.Name = val;
                    }
                    else if (property.Key == "amount")
                    {
                        if (input.Currency != null && !string.IsNullOrEmpty(val))
                        {
                            val = val + input.Currency;
                        }
                        data.Properties[HubSpotVocabulary.Deal.DealInformationAmount] = val;
                    }
                    else if (property.Key == "dealstage")
                    {
                        data.Properties[HubSpotVocabulary.Deal.DealInformationDealStage] = val;
                    }
                    else if (property.Key == "pipeline")
                    {
                        data.Properties[HubSpotVocabulary.Deal.DealInformationPipeline] = val;
                    }
                    else if (property.Key == "closedate")
                    {
                        if (date.HasValue)
                        {
                            data.Properties[HubSpotVocabulary.Deal.DealInformationCloseDate] = date.Value.ToString();
                        }
                    }
                    else if (property.Key == "createdate")
                    {
                        if (date.HasValue)
                        {
                            data.CreatedDate = date.Value;
                        }
                    }
                    else if (property.Key == "engagements_last_meeting_booked")
                    {
                        if (date.HasValue)
                        {
                            data.Properties[HubSpotVocabulary.Deal.LastMeetingBooked] = date.Value.ToString();
                        }
                    }
                    else if (property.Key == "engagements_last_meeting_booked_campaign")
                    {
                        if (date.HasValue)
                        {
                            data.Properties[HubSpotVocabulary.Deal.LastMeetingBookedCampaign] = date.Value.ToString();
                        }
                    }
                    else if (property.Key == "engagements_last_meeting_booked_medium")
                    {
                        if (date.HasValue)
                        {
                            data.Properties[HubSpotVocabulary.Deal.LastMeetingBookedMedium] = date.Value.ToString();
                        }
                    }
                    else if (property.Key == "engagements_last_meeting_booked_source")
                    {
                        data.Properties[HubSpotVocabulary.Deal.LastMeetingBookedSource] = val;
                    }
                    else if (property.Key == "hubspot_owner_id")
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.OwnedBy, input, s => val.ToString());
                    }
                    else if (property.Key == "notes_last_contacted")
                    {
                        if (date.HasValue)
                        {
                            data.Properties[HubSpotVocabulary.Deal.DealInformationLastContacted] = date.Value.ToString();
                        }
                    }
                    else if (property.Key == "notes_last_updated")
                    {
                        if (date.HasValue)
                        {
                            data.Properties[HubSpotVocabulary.Deal.DealInformationLastActivityDate] = date.Value.ToString();
                        }
                    }
                    else if (property.Key == "notes_next_activity_date")
                    {
                        if (date.HasValue)
                        {
                            data.Properties[HubSpotVocabulary.Deal.DealInformationNextActivityDate] = date.Value.ToString();
                        }
                    }
                    else if (property.Key == "num_contacted_notes")
                    {
                        data.Properties[HubSpotVocabulary.Deal.DealInformationNumberoftimescontacted] = val;
                    }
                    else if (property.Key == "num_notes")
                    {
                        data.Properties[HubSpotVocabulary.Deal.DealInformationNumberofSalesActivities] = val;
                    }
                    else if (property.Key == "hs_createdate")
                    {
                        if (date.HasValue)
                        {
                            data.CreatedDate = date.Value;
                        }
                    }
                    else if (property.Key == "hubspot_team_id")
                    {
                        data.Properties[HubSpotVocabulary.Deal.DealInformationHubSpotTeam] = val;
                    }
                    else if (property.Key == "dealtype")
                    {
                        data.Properties[HubSpotVocabulary.Deal.DealInformationDealType] = val;
                    }
                    else if (property.Key == "description")
                    {
                        data.Description = val;
                    }
                    else if (property.Key == "num_associated_contacts")
                    {
                        data.Properties[HubSpotVocabulary.Deal.DealInformationNumberofContacts] = val;
                    }
                    else if (property.Key == "closed_lost_reason")
                    {
                        data.Properties[HubSpotVocabulary.Deal.DealInformationClosedLostReason] = val;
                    }
                    else if (property.Key == "closed_won_reason")
                    {
                        data.Properties[HubSpotVocabulary.Deal.DealInformationClosedWonReason] = val;
                    }
                    else
                    {
                        data.Properties[string.Format("hubspot.deal.custom-{0}", property.Key)] = val;
                    }
                }
            }

            return(clue);
        }
示例#22
0
        protected override Clue MakeClueImpl(Email input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Mail, input.engagement.id?.ToString(), accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);
            //clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_001_Name_MustBeSet);
            //clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_002_Uri_MustBeSet);
            //clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_003_Author_Name_MustBeSet);
            //clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_004_Invalid_EntityType);
            //clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_005_PreviewImage_RawData_MustBeSet);
            //clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_006_Created_Modified_Date_InFuture);
            //clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_007_Created_Modified_Date_InPast);
            //clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_008_Created_Modified_Date_UnixEpoch);
            //clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_009_Created_Modified_Date_MinDate);
            //clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_010_Created_Modified_Date_MaxDate);
            //clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.PROPERTIES_001_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.PROPERTIES_002_Unknown_VocabularyKey_Used);
            //clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.PROPERTIES_003_Value_ShouldNotBeQuoted);

            var data = clue.Data.EntityData;

            if (input.associations != null)
            {
                if (input.associations.companyIds != null)
                {
                    foreach (var companyId in input.associations.companyIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Organization, EntityEdgeType.Parent, input, selector => companyId.ToString());
                    }
                }
                if (input.associations.contactIds != null)
                {
                    foreach (var contactId in input.associations.contactIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Contact, EntityEdgeType.Parent, input, selector => contactId.ToString());
                    }
                }
                if (input.associations.dealIds != null)
                {
                    foreach (var dealId in input.associations.dealIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Sales.Deal, EntityEdgeType.Parent, input, selector => dealId.ToString());
                    }
                }
                if (input.associations.ownerIds != null)
                {
                    foreach (var ownerId in input.associations.ownerIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.OwnedBy, input, selector => ownerId.ToString());
                    }
                }
                if (input.associations.workflowIds != null)
                {
                    foreach (var workflowId in input.associations.workflowIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Process, EntityEdgeType.Parent, input, selector => workflowId.ToString());
                    }
                }
            }

            if (input.engagement != null)
            {
                if (input.engagement.portalId != null && input.engagement.id != null && input.engagement.ownerId != null)
                {
                    var url =
                        $"https://app.hubspot.com/sales/{input.engagement.portalId}/tasks?taskId={input.engagement.id}&ownerId={input.engagement.ownerId}";  // TODO take from configuration
                    data.Uri = new Uri(url);
                }
                if (input.engagement.createdAt != null)
                {
                    if (long.TryParse(input.engagement.createdAt.ToString(), out long date))
                    {
                        data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(date);
                    }
                }
                if (input.engagement.lastUpdated != null)
                {
                    if (long.TryParse(input.engagement.lastUpdated.ToString(), out long date))
                    {
                        data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(date);
                    }
                }
                if (input.engagement.timestamp != null)
                {
                    if (data.CreatedDate == null)
                    {
                        if (long.TryParse(input.engagement.createdAt.ToString(), out long date))
                        {
                            data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(date);
                        }
                    }
                }
                if (input.engagement.active != null)
                {
                    data.Properties[HubSpotVocabulary.Email.Active] = input.engagement.active.ToString();
                }
                if (input.engagement.createdBy != null)
                {
                    _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.CreatedBy, input, selector => input.engagement.createdBy.ToString());
                }
                if (input.engagement.modifiedBy != null)
                {
                    _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.ModifiedBy, input, selector => input.engagement.modifiedBy.ToString());
                }
                if (input.engagement.ownerId != null)
                {
                    _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.OwnedBy, input, selector => input.engagement.ownerId.ToString());
                }
                if (input.engagement.portalId != null)
                {
                    _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.Parent, input, selector => input.engagement.portalId.ToString());
                }
            }

            try
            {
                if (input.metadata != null)
                {
                    if (input.metadata.from?.email != null)
                    {
                        if (input.metadata.from.lastName != null)
                        {
                            if (input.metadata.from.firstName != null)
                            {
                                var personReference = new PersonReference(input.metadata.from.firstName + ' ' + input.metadata.from.lastName,
                                                                          new EntityCode(EntityType.Infrastructure.User, CodeOrigin.CluedIn.CreateSpecific("email"), input.metadata.from.email));

                                data.Authors.Add(personReference);
                                data.LastChangedBy = personReference;
                            }
                            else
                            {
                                var personReference = new PersonReference(input.metadata.from.lastName,
                                                                          new EntityCode(EntityType.Infrastructure.User, CodeOrigin.CluedIn.CreateSpecific("email"), input.metadata.from.email));

                                data.Authors.Add(personReference);
                                data.LastChangedBy = personReference;
                            }
                        }
                        else
                        {
                            var personReference = new PersonReference(new EntityCode(EntityType.Infrastructure.User, CodeOrigin.CluedIn.CreateSpecific("email"), input.metadata.from.email));

                            data.Authors.Add(personReference);
                            data.LastChangedBy = personReference;
                        }

                        data.Properties[HubSpotVocabulary.Email.FromEmail]     = input.metadata.from.email;
                        data.Properties[HubSpotVocabulary.Email.FromFirstName] = input.metadata.from.firstName;
                        data.Properties[HubSpotVocabulary.Email.FromLastName]  = input.metadata.from.lastName;
                    }
                    if (input.metadata.to != null)
                    {
                        foreach (EmailPerson recipient in input.metadata.to)
                        {
                            if (recipient != null)
                            {
                                if (recipient.email != null && recipient.firstName != null && recipient.lastName != null)
                                {
                                    var entityCode = new EntityCode(EntityType.Infrastructure.User, CodeOrigin.CluedIn.CreateSpecific("email"), recipient.email);

                                    var entityEdge = new EntityEdge(
                                        EntityReference.CreateByKnownCode(clue.OriginEntityCode),
                                        EntityReference.CreateByKnownCode(entityCode, recipient.firstName + ' ' + recipient.lastName),
                                        EntityEdgeType.Recipient);

                                    data.OutgoingEdges.Add(entityEdge);
                                }
                                if (recipient.email != null && recipient.lastName != null)
                                {
                                    var entityCode = new EntityCode(EntityType.Infrastructure.User, CodeOrigin.CluedIn.CreateSpecific("email"), recipient.email);

                                    var entityEdge = new EntityEdge(
                                        EntityReference.CreateByKnownCode(clue.OriginEntityCode),
                                        EntityReference.CreateByKnownCode(entityCode, recipient.lastName),
                                        EntityEdgeType.Recipient);

                                    data.OutgoingEdges.Add(entityEdge);
                                }
                                else if (recipient.email != null)
                                {
                                    var entityCode = new EntityCode(EntityType.Infrastructure.User, CodeOrigin.CluedIn.CreateSpecific("email"), recipient.email);

                                    var entityEdge = new EntityEdge(
                                        EntityReference.CreateByKnownCode(clue.OriginEntityCode),
                                        EntityReference.CreateByKnownCode(entityCode),
                                        EntityEdgeType.Recipient);

                                    data.OutgoingEdges.Add(entityEdge);
                                }
                            }
                        }
                    }
                    if (input.metadata?.bcc != null)
                    {
                        foreach (EmailPerson recipient in input.metadata.bcc)
                        {
                            if (recipient != null)
                            {
                                if (recipient.email != null && recipient.firstName != null && recipient.lastName != null)
                                {
                                    var entityCode = new EntityCode(EntityType.Infrastructure.User, CodeOrigin.CluedIn.CreateSpecific("email"), recipient.email);

                                    var entityEdge = new EntityEdge(
                                        EntityReference.CreateByKnownCode(clue.OriginEntityCode),
                                        EntityReference.CreateByKnownCode(entityCode, recipient.firstName + ' ' + recipient.lastName),
                                        EntityEdgeType.Recipient);

                                    data.OutgoingEdges.Add(entityEdge);
                                }
                                if (recipient.email != null && recipient.lastName != null)
                                {
                                    var entityCode = new EntityCode(EntityType.Infrastructure.User, CodeOrigin.CluedIn.CreateSpecific("email"), recipient.email);

                                    var entityEdge = new EntityEdge(
                                        EntityReference.CreateByKnownCode(clue.OriginEntityCode),
                                        EntityReference.CreateByKnownCode(entityCode, recipient.lastName),
                                        EntityEdgeType.Recipient);

                                    data.OutgoingEdges.Add(entityEdge);
                                }
                                else if (recipient.email != null)
                                {
                                    var entityCode = new EntityCode(EntityType.Infrastructure.User, CodeOrigin.CluedIn.CreateSpecific("email"), recipient.email);

                                    var entityEdge = new EntityEdge(
                                        EntityReference.CreateByKnownCode(clue.OriginEntityCode),
                                        EntityReference.CreateByKnownCode(entityCode),
                                        EntityEdgeType.Recipient);

                                    data.OutgoingEdges.Add(entityEdge);
                                }
                            }
                        }
                    }
                    if (input.metadata.cc != null)
                    {
                        foreach (EmailPerson recipient in input.metadata.cc)
                        {
                            if (recipient != null)
                            {
                                if (recipient.email != null && recipient.firstName != null && recipient.lastName != null)
                                {
                                    var entityCode = new EntityCode(EntityType.Infrastructure.User, CodeOrigin.CluedIn.CreateSpecific("email"), recipient.email);

                                    var entityEdge = new EntityEdge(
                                        EntityReference.CreateByKnownCode(clue.OriginEntityCode),
                                        EntityReference.CreateByKnownCode(entityCode, recipient.firstName + ' ' + recipient.lastName),
                                        EntityEdgeType.Recipient);

                                    data.OutgoingEdges.Add(entityEdge);
                                }
                                if (recipient.email != null && recipient.lastName != null)
                                {
                                    var entityCode = new EntityCode(EntityType.Infrastructure.User, CodeOrigin.CluedIn.CreateSpecific("email"), recipient.email);

                                    var entityEdge = new EntityEdge(
                                        EntityReference.CreateByKnownCode(clue.OriginEntityCode),
                                        EntityReference.CreateByKnownCode(entityCode, recipient.lastName),
                                        EntityEdgeType.Recipient);

                                    data.OutgoingEdges.Add(entityEdge);
                                }
                                else if (recipient.email != null)
                                {
                                    var entityCode = new EntityCode(EntityType.Infrastructure.User, CodeOrigin.CluedIn.CreateSpecific("email"), recipient.email);

                                    var entityEdge = new EntityEdge(
                                        EntityReference.CreateByKnownCode(clue.OriginEntityCode),
                                        EntityReference.CreateByKnownCode(entityCode),
                                        EntityEdgeType.Recipient);

                                    data.OutgoingEdges.Add(entityEdge);
                                }
                            }
                        }
                    }
                    if (input.metadata.subject != null)
                    {
                        data.Name = input.metadata.subject;
                    }
                    if (input.metadata.html != null)
                    {
                        data.Properties[HubSpotVocabulary.Email.HtmlBody] = input.metadata.html;
                    }
                    if (input.metadata.body != null)
                    {
                        data.Properties[HubSpotVocabulary.Email.Body] = input.metadata.body;
                    }
                    if (input.metadata.text != null)
                    {
                        data.Properties[HubSpotVocabulary.Email.Text] = input.metadata.text;
                    }
                    if (input.metadata.sentVia != null)
                    {
                        data.Properties[HubSpotVocabulary.Email.SentVia] = input.metadata.sentVia;
                    }
                    if (input.metadata.custom != null)
                    {
                        foreach (var p in input.metadata.custom)
                        {
                            data.Properties[string.Format("hubspot.company.custom-{0}", p.Key)] = p.Value.ToString();
                        }
                    }
                }
            }

            catch (Exception e)
            {
                _log.Error(() => "Failed to parse value.metadata for Hubspot Email", e);
            }
            if (data.Name == null)
            {
                data.Name = input.engagement.type + " at " + data.CreatedDate.Value.ToString("MM/dd/yyyy hh:mm tt", CultureInfo.InvariantCulture);
            }

            return(clue);
        }
示例#23
0
        protected override Clue MakeClueImpl(Product input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Product, input.ObjectId.ToString(), accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.PROPERTIES_002_Unknown_VocabularyKey_Used);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_001_Name_MustBeSet);

            var data = clue.Data.EntityData;

            data.Uri = new Uri($"https://app.hubspot.com/settings/{input.PortalId}/sales/products");  // TODO take from configuration

            data.Properties[HubSpotVocabulary.Product.Version]   = input.Version.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Product.IsDeleted] = input.IsDeleted.PrintIfAvailable();

            if (input.Properties != null)
            {
                try
                {
                    var jobject    = JObject.Parse(JsonUtility.Serialize(input.Properties));
                    var properties = new List <Property>();
                    jobject.Properties().ForEach(c =>
                                                 properties.Add(new Property
                    {
                        Name      = c.Name,
                        Value     = c.Value["value"]?.ToString(),
                        Timestamp = c.Value["timestamp"]?.ToString(),
                        Source    = c.Value["source"]?.ToString(),
                        SourceId  = c.Value["sourceId"]?.ToString()
                    }));

                    foreach (var r in properties)
                    {
                        if (r.Name == "createdate")
                        {
                            long epoch = long.MinValue;
                            if (!long.TryParse(r.Timestamp, out epoch))
                            {
                                long.TryParse(r.Value, out epoch);
                            }
                            if (epoch != long.MinValue)
                            {
                                data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(epoch);
                            }
                            if (data.CreatedDate != null)
                            {
                                data.Properties[HubSpotVocabulary.Product.CreateDate] = data.CreatedDate.Value.ToString("o");
                            }
                            if (r.SourceId != null)
                            {
                                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.User, EntityEdgeType.CreatedBy, input, c => r.SourceId);
                            }
                        }

                        else if (r.Name == "hs_lastmodifieddate")
                        {
                            long epoch = long.MinValue;
                            if (!long.TryParse(r.Timestamp, out epoch))
                            {
                                long.TryParse(r.Value, out epoch);
                            }
                            if (epoch != long.MinValue)
                            {
                                data.ModifiedDate = DateUtilities.EpochRef.AddMilliseconds(epoch);
                            }
                            if (data.ModifiedDate != null)
                            {
                                data.Properties[HubSpotVocabulary.Product.LastModifiedDate] = data.ModifiedDate.Value.ToString("o");
                            }
                        }

                        else if (r.Name == "hs_recurring_billing_start_date")
                        {
                            long epoch = long.MinValue;
                            if (!long.TryParse(r.Timestamp, out epoch))
                            {
                                long.TryParse(r.Value, out epoch);
                            }
                            if (epoch != long.MinValue)
                            {
                                if (DateUtilities.EpochRef.AddMilliseconds(epoch) != null)
                                {
                                    data.Properties[HubSpotVocabulary.Product.StartDate] = DateUtilities.EpochRef.AddMilliseconds(epoch).ToString("o");
                                }
                            }
                        }

                        else if (r.Name == "name")
                        {
                            data.Properties[HubSpotVocabulary.Product.Name] = data.Name = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "hs_avatar_filemanager_key")
                        {
                            data.Properties[HubSpotVocabulary.Product.AvatarFileManagerkey] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "description")
                        {
                            data.Properties[HubSpotVocabulary.Product.Productdescription] = data.Description = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "price")
                        {
                            data.Properties[HubSpotVocabulary.Product.Productprice] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "recurringbillingfrequency")
                        {
                            data.Properties[HubSpotVocabulary.Product.Recurringbillingfrequency] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "discount")
                        {
                            data.Properties[HubSpotVocabulary.Product.DiscountAmount] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "hs_discount_percentage")
                        {
                            data.Properties[HubSpotVocabulary.Product.DiscountPercentage] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "tax")
                        {
                            data.Properties[HubSpotVocabulary.Product.Tax] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "hs_recurring_billing_period")
                        {
                            data.Properties[HubSpotVocabulary.Product.Term] = r.Value.PrintIfAvailable();
                        }
                        else if (r.Name == "hs_cost_of_goods_sold")
                        {
                            data.Properties[HubSpotVocabulary.Product.Costofgoodssold] = r.Value.PrintIfAvailable();
                        }
                        else
                        {
                            data.Properties[string.Format("hubspot.product.custom-{0}", r.Name)] = r.Value.PrintIfAvailable();
                        }
                    }
                }

                catch (Exception exception)
                {
                    _log.Error(() => "Could not parse HubSpot Product Properies", exception);
                }
            }

            if (!data.OutgoingEdges.Any() && input.PortalId != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.PartOf, input, s => s.PortalId.ToString(), s => "Hubspot");
            }


            return(clue);
        }
示例#24
0
        protected override Clue MakeClueImpl(Row input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.List.Item, input.Id.ToString(), accountId);

            clue.ValidationRuleSuppressions.Add(CluedIn.Core.Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(CluedIn.Core.Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);

            var data = clue.Data.EntityData;

            if (input.Name != null)
            {
                data.Name = input.Name.ToString();
            }

            if (input.CreatedAt != null && long.TryParse(input.CreatedAt.ToString(), out long date))
            {
                data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(date);
            }

            data.Uri = new Uri("http://app.hubspot.com/l/hubdb");  // TODO take from configuration

            data.Properties[HubSpotVocabulary.Row.Name] = input.Name.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Row.Id]   = input.Id.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.Row.Path] = input.Path.PrintIfAvailable();
            if (data.CreatedDate.HasValue)
            {
                data.Properties[HubSpotVocabulary.Row.CreatedAt] = data.CreatedDate.Value.DateTime.ToString("O");
            }

            if (input.Table != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.List, EntityEdgeType.PartOf, input, selector => input.Table.Value.ToString());
            }

            try
            {
                JObject jobject = null;
                if (input.Values != null)
                {
                    jobject = JObject.Parse(input.Values.ToString());
                }

                if (jobject != null)
                {
                    foreach (var p in jobject.Properties())
                    {
                        if (p.Value != null)
                        {
                            if (int.TryParse(p.Name, out int n) && input.Columns.Exists(c => c.id == n))
                            {
                                data.Properties[string.Format("hubspot.product.custom-{0}", input.Columns.Find(c => c.id == n).name)] = p.Value.ToString();
                            }
                            else
                            {
                                data.Properties[string.Format("hubspot.product.custom-{0}", p.Name)] = p.Value.ToString();
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                _log.Error(() => "Failed to parse columns for Hubspot Row", exception);
            }

            return(clue);
        }
示例#25
0
        protected override Clue MakeClueImpl(Call input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.PhoneCall, input.engagement.id.ToString(), accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.PROPERTIES_002_Unknown_VocabularyKey_Used);

            var data = clue.Data.EntityData;

            if (input.associations != null)
            {
                if (input.associations.contactIds != null)
                {
                    foreach (var contactId in input.associations.contactIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Contact, EntityEdgeType.Parent, input, selector => contactId.ToString());
                    }
                }
                if (input.associations.dealIds != null)
                {
                    foreach (var dealId in input.associations.dealIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Sales.Deal, EntityEdgeType.Parent, input, selector => dealId.ToString());
                    }
                }
                if (input.associations.ownerIds != null)
                {
                    foreach (var ownerId in input.associations.ownerIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.OwnedBy, input, selector => ownerId.ToString());
                    }
                }
                if (input.associations.workflowIds != null)
                {
                    foreach (var workflowId in input.associations.workflowIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Process, EntityEdgeType.Parent, input, selector => workflowId.ToString());
                    }
                }
                if (input.associations.companyIds != null)
                {
                    if (data.OutgoingEdges.Count == 0)
                    {
                        foreach (var companyId in input.associations.companyIds)
                        {
                            _factory.CreateIncomingEntityReference(clue, EntityType.Organization, EntityEdgeType.Parent, input, selector => companyId.ToString());
                        }
                    }
                }
            }

            if (input.engagement != null)
            {
                if (input.engagement.portalId != null && input.engagement.id != null && input.engagement.ownerId != null)
                {
                    string url = string.Format("https://app.hubspot.com/sales/{0}/tasks?taskId={1}&ownerId={2}", input.engagement.portalId, input.engagement.id, input.engagement.ownerId);
                    data.Uri = new Uri(url);
                }
                if (input.engagement.createdAt != null)
                {
                    if (long.TryParse(input.engagement.createdAt.ToString(), out long date))
                    {
                        data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(date);
                    }
                }
                if (input.engagement.lastUpdated != null)
                {
                    if (long.TryParse(input.engagement.lastUpdated.ToString(), out long date))
                    {
                        data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(date);
                    }
                }
                if (input.engagement.timestamp != null)
                {
                    if (data.CreatedDate == null)
                    {
                        if (long.TryParse(input.engagement.createdAt.ToString(), out long date))
                        {
                            data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(date);
                        }
                    }
                }
                if (data.CreatedDate != null)
                {
                    data.Name = "Call at " + data.CreatedDate.Value.ToString("MM/dd/yyyy hh:mm tt", CultureInfo.InvariantCulture);
                }
                if (input.engagement.active != null)
                {
                    data.Properties[HubSpotVocabulary.Email.Active] = input.engagement.active.Value.ToString();
                }
                if (input.engagement.createdBy != null)
                {
                    _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.CreatedBy, input, selector => input.engagement.createdBy.ToString());
                }
                if (input.engagement.modifiedBy != null)
                {
                    _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.ModifiedBy, input, selector => input.engagement.modifiedBy.ToString());
                }
                if (input.engagement.ownerId != null)
                {
                    _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.OwnedBy, input, selector => input.engagement.ownerId.ToString());
                }
                if (input.engagement.portalId != null)
                {
                    if (data.OutgoingEdges.Count == 0)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.Parent, input, selector => input.engagement.portalId.ToString());
                    }
                }
            }

            try
            {
                var metadata = JsonUtility.Deserialize <Dictionary <string, object> >(JsonUtility.Serialize(input.metadata));

                if (metadata != null)
                {
                    foreach (var property in metadata)
                    {
                        if (property.Key == "toNumber" && property.Value != null && !string.IsNullOrEmpty(property.Value.ToString()))
                        {
                            data.Properties[HubSpotVocabulary.Call.ToNumber] = property.Value.ToString();
                        }
                        else if (property.Key == "fromNumber" && property.Value != null && !string.IsNullOrEmpty(property.Value.ToString()))
                        {
                            data.Properties[HubSpotVocabulary.Call.FromNumber] = property.Value.ToString();
                        }
                        else if (property.Key == "status" && property.Value != null && !string.IsNullOrEmpty(property.Value.ToString()))
                        {
                            data.Properties[HubSpotVocabulary.Call.Status] = property.Value.ToString();
                        }
                        else if (property.Key == "externalId" && property.Value != null && !string.IsNullOrEmpty(property.Value.ToString()))
                        {
                            data.Properties[HubSpotVocabulary.Call.ExternalId] = property.Value.ToString();
                        }
                        else if (property.Key == "durationMilliseconds" && property.Value != null && !string.IsNullOrEmpty(property.Value.ToString()))
                        {
                            data.Properties[HubSpotVocabulary.Call.Duration] = property.Value.ToString();
                        }
                        else if (property.Key == "externalAccountId" && property.Value != null && !string.IsNullOrEmpty(property.Value.ToString()))
                        {
                            _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.Parent, input, selector => property.Value.ToString());
                            data.Properties[HubSpotVocabulary.Call.ExternalAccountId] = property.Value.ToString();
                        }
                        else if (property.Key == "recordingUrl" && property.Value != null && !string.IsNullOrEmpty(property.Value.ToString()))
                        {
                            data.Properties[HubSpotVocabulary.Call.RecordingUrl] = property.Value.ToString();
                        }
                        else if (property.Key == "body" && property.Value != null && !string.IsNullOrEmpty(property.Value.ToString()))
                        {
                            data.Name = Regex.Replace(property.Value.ToString(), "<.*?>", String.Empty);
                            data.Properties[HubSpotVocabulary.Call.Body] = Regex.Replace(property.Value.ToString(), "<.*?>", String.Empty);
                        }
                        else if (property.Key == "disposition" && property.Value != null && !string.IsNullOrEmpty(property.Value.ToString()))
                        {
                            data.Properties[HubSpotVocabulary.Call.Disposition] = property.Value.ToString();
                        }
                        else
                        {
                            if (property.Value != null && !string.IsNullOrEmpty(property.Value.ToString()))
                            {
                                data.Properties[string.Format("hubspot.call.custom-{0}", property.Key)] = property.Value.ToString();
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                _log.Error(() => "Failed to parse metadata for Hubspot Call", exception);
            }
            if (data.Name == null)
            {
                data.Name = input.engagement.type + " at " + data.CreatedDate.Value.ToString("MM/dd/yyyy hh:mm tt", CultureInfo.InvariantCulture);
            }

            return(clue);
        }
示例#26
0
        protected override Clue MakeClueImpl(Note input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Note, input.engagement.id.ToString(), accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.PROPERTIES_002_Unknown_VocabularyKey_Used);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.METADATA_002_Uri_MustBeSet);


            var data = clue.Data.EntityData;

            if (input.attachments != null)
            {
                foreach (var attachment in input.attachments)
                {
                    var r = JsonUtility.Deserialize <KeyValuePair <string, object> >(JsonUtility.Serialize(attachment));

                    if (r.Key == "id")
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Files.File, EntityEdgeType.Parent, input, selector => r.Value.ToString());
                    }
                }
            }

            if (input.associations != null)
            {
                if (input.associations.companyIds != null)
                {
                    foreach (var companyId in input.associations.companyIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Organization, EntityEdgeType.Parent, input, selector => companyId.ToString());
                    }
                }
                if (input.associations.contactIds != null)
                {
                    foreach (var contactId in input.associations.contactIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Contact, EntityEdgeType.Parent, input, selector => contactId.ToString());
                    }
                }
                if (input.associations.dealIds != null)
                {
                    foreach (var dealId in input.associations.dealIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Sales.Deal, EntityEdgeType.Parent, input, selector => dealId.ToString());
                    }
                }
                if (input.associations.ownerIds != null)
                {
                    foreach (var ownerId in input.associations.ownerIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.OwnedBy, input, selector => ownerId.ToString());
                    }
                }
                if (input.associations.workflowIds != null)
                {
                    foreach (var workflowId in input.associations.workflowIds)
                    {
                        _factory.CreateIncomingEntityReference(clue, EntityType.Process, EntityEdgeType.Parent, input, selector => workflowId.ToString());
                    }
                }
            }

            if (input.engagement != null)
            {
                if (input.engagement.createdAt != null)
                {
                    if (long.TryParse(input.engagement.createdAt.ToString(), out long date))
                    {
                        data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(date);
                    }
                }
                if (input.engagement.lastUpdated != null)
                {
                    if (long.TryParse(input.engagement.lastUpdated.ToString(), out long date))
                    {
                        data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(date);
                    }
                }
                if (input.engagement.timestamp != null)
                {
                    if (data.CreatedDate == null)
                    {
                        if (long.TryParse(input.engagement.createdAt.ToString(), out long date))
                        {
                            data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(date);
                        }
                    }
                }
                if (input.engagement.active != null)
                {
                    data.Properties[HubSpotVocabulary.Email.Active] = input.engagement.active.Value.ToString();
                }
                if (input.engagement.createdBy != null)
                {
                    _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.CreatedBy, input, selector => input.engagement.createdBy.ToString());
                }
                if (input.engagement.modifiedBy != null)
                {
                    _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.ModifiedBy, input, selector => input.engagement.modifiedBy.ToString());
                }
                if (input.engagement.ownerId != null)
                {
                    _factory.CreateIncomingEntityReference(clue, EntityType.Person, EntityEdgeType.OwnedBy, input, selector => input.engagement.ownerId.ToString());
                }
                if (input.engagement.portalId != null)
                {
                    _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.Parent, input, selector => input.engagement.portalId.ToString());
                }
            }

            try
            {
                var metadata = JsonUtility.Deserialize <Dictionary <string, object> >(JsonUtility.Serialize(input.metadata));

                if (metadata != null)
                {
                    foreach (var property in metadata)
                    {
                        if (property.Key == "body")
                        {
                            if (property.Value != null && !string.IsNullOrEmpty(property.Value.ToString()))
                            {
                                data.Name        = Regex.Replace(property.Value.ToString(), "<.*?>", String.Empty);
                                data.Description = Regex.Replace(property.Value.ToString(), "<.*?>", String.Empty);
                                data.Properties[HubSpotVocabulary.Note.Body] = property.Value.ToString();
                            }
                        }
                        else
                        {
                            if (property.Value != null)
                            {
                                data.Properties[string.Format("hubspot.note.custom-{0}", property.Key)] = property.Value.ToString();
                            }
                        }
                    }
                }
            }

            catch (Exception exception)
            {
                _log.Error(() => "Failed to parse metadata for Hubspot Note", exception);
            }
            if (data.Name == null)
            {
                data.Name = input.engagement.type + " at " + data.CreatedDate.Value.ToString("MM/dd/yyyy hh:mm tt", CultureInfo.InvariantCulture);
            }


            return(clue);
        }
示例#27
0
        protected override Clue MakeClueImpl(FileMetaData input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Files.File, input.id.ToString(), accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.PROPERTIES_002_Unknown_VocabularyKey_Used);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.DATA_001_File_MustBeIndexed);

            var data = clue.Data.EntityData;

            data.Name         = input.name;
            data.CreatedDate  = DateUtilities.EpochRef.AddMilliseconds(input.created);
            data.DocumentSize = input.size;

            if (input.url != null)
            {
                data.Uri = new Uri(input.url);
            }

            data.Properties[HubSpotVocabulary.FileMetaData.AltKey]     = input.alt_key;
            data.Properties[HubSpotVocabulary.FileMetaData.AltKeyHash] = input.alt_key_hash;
            data.Properties[HubSpotVocabulary.FileMetaData.AltUrl]     = input.alt_url;
            data.Properties[HubSpotVocabulary.FileMetaData.Archived]   = input.archived.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.FileMetaData.DeletedAt]  = input.deleted_at.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.FileMetaData.Extension]  = input.extension;
            data.Properties[HubSpotVocabulary.FileMetaData.FolderId]   = input.folder_id.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.FileMetaData.Height]     = input.height.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.FileMetaData.IsCtaImage] = input.is_cta_image.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.FileMetaData.Meta]       = input.meta.PrintIfAvailable(JsonUtility.Serialize);
            data.Properties[HubSpotVocabulary.FileMetaData.PortalId]   = input.portal_id.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.FileMetaData.Title]      = input.title;
            data.Properties[HubSpotVocabulary.FileMetaData.Type]       = input.type;
            data.Properties[HubSpotVocabulary.FileMetaData.Updated]    = input.updated.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.FileMetaData.EmbedUrl]   = input.url;
            data.Properties[HubSpotVocabulary.FileMetaData.EditUrl]    = input.url;
            data.Properties[HubSpotVocabulary.FileMetaData.Version]    = input.version.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.FileMetaData.Width]      = input.width.PrintIfAvailable();

            if (input.portal_id != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.PartOf, input, s => s.portal_id.Value.ToString(), s => "HubDpot");
            }

            // TODO Figure out how to do file indexing
            if (input.name != null)
            {
                //try
                //{
                //    string filename = $"{input.name}.{input.extension}";
                //    var fileData = _fileFetcher.FetchAsBytes(input.url);

                //    if (_state.TaskFactory == null)
                //        _state.TaskFactory = new TaskFactory(); // BF - this will prevent indexing occuring if not present while testing

                //    var fileIndexer = new HubSpotFileIndexer(_state, _context);
                //    fileIndexer.Index(fileData, filename, clue).Wait();
                //}
                //catch (Exception exception)
                //{
                //    _log.Warn(() => "Could not download HubSpot File", exception);
                //}
            }

            return(clue);
        }
示例#28
0
        protected override Clue MakeClueImpl(Campaign input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Marketing.Campaign, input.id.ToString(), accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);

            var data = clue.Data.EntityData;

            if (input.name != null)
            {
                data.Name = input.name;
            }
            if (input.subject != null)
            {
                data.Description = input.subject;
            }

            if (input.appId != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Application, EntityEdgeType.PartOf, input, s => s.appId.Value.ToString());
            }

            if (input.appName != null)
            {
                data.Properties[HubSpotVocabulary.Campaign.AppName] = input.appName;
            }
            if (input.contentId != null)
            {
                data.Properties[HubSpotVocabulary.Campaign.ContentId] = input.contentId.ToString();
            }
            if (input.counters != null)
            {
                data.Properties[HubSpotVocabulary.Campaign.Counters] = JsonUtility.Serialize(input.counters);
                if (input.counters.delivered != null)
                {
                    data.Properties[HubSpotVocabulary.Campaign.Delivered] = input.counters.delivered.Value.ToString();
                }
                if (input.counters.open != null)
                {
                    data.Properties[HubSpotVocabulary.Campaign.Open] = input.counters.open.Value.ToString();
                }
                if (input.counters.processed != null)
                {
                    data.Properties[HubSpotVocabulary.Campaign.Processed] = input.counters.processed.Value.ToString();
                }
                if (input.counters.sent != null)
                {
                    data.Properties[HubSpotVocabulary.Campaign.Sent] = input.counters.sent.Value.ToString();
                }
            }

            if (input.numIncluded != null)
            {
                data.Properties[HubSpotVocabulary.Campaign.NumIncluded] = input.numIncluded.ToString();
            }
            if (input.numQueued != null)
            {
                data.Properties[HubSpotVocabulary.Campaign.NumQueued] = input.numQueued.ToString();
            }
            if (input.subType != null)
            {
                data.Properties[HubSpotVocabulary.Campaign.SubType] = input.subType;
            }
            if (input.type != null)
            {
                data.Properties[HubSpotVocabulary.Campaign.Type] = input.type;
            }


            return(clue);
        }
示例#29
0
        protected override Clue MakeClueImpl(PropertyDefinition input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Note, input.Groupname + input.Name, accountId);

            clue.ValidationRuleSuppressions.Add(CluedIn.Core.Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(CluedIn.Core.Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);

            var data = clue.Data.EntityData;

            data.Description = input.Description;
            data.Name        = input.Name;

            if (input.Createdat.HasValue)
            {
                data.CreatedDate = DateUtilities.EpochRef.AddMilliseconds(input.Createdat.Value);
            }
            if (data.CreatedDate != null)
            {
                data.Properties[HubSpotVocabulary.PropertyDefinition.CreatedAt] = data.CreatedDate.Value.ToString("o");
            }

            if (input.Updatedat.HasValue)
            {
                data.ModifiedDate = DateUtilities.EpochRef.AddMilliseconds(input.Updatedat.Value);
            }
            if (data.ModifiedDate != null)
            {
                data.Properties[HubSpotVocabulary.PropertyDefinition.UpdatedAt] = data.ModifiedDate.Value.ToString("o");
            }

            if (input.Createduserid != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.User, EntityEdgeType.CreatedBy, input, c => input.Createduserid.Value.ToString());
            }

            if (input.Updateduserid != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.User, EntityEdgeType.ModifiedBy, input, c => input.Updateduserid.Value.ToString());
            }

            data.Properties[HubSpotVocabulary.PropertyDefinition.Name]                          = input.Name.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.Label]                         = input.Label.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.Description]                   = input.Description.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.GroupName]                     = input.Groupname.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.Type]                          = input.Type.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.FieldType]                     = input.Fieldtype.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.Hidden]                        = input.Hidden.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.Options]                       = input.Options.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.Calculated]                    = input.Calculated.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.ExternalOptions]               = input.Externaloptions.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.HubspotDefined]                = input.Hubspotdefined.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.FormField]                     = input.Formfield.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.DisplayOrder]                  = input.Displayorder.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.ReadonlyValue]                 = input.Readonlyvalue.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.ReadonlyDefinition]            = input.Readonlydefinition.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.Deleted]                       = input.Deleted.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.MutableDefinitionNotDeletable] = input.Mutabledefinitionnotdeletable.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.Favorited]                     = input.Favorited.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.FavoritedOrder]                = input.Favoritedorder.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.DisplayMode]                   = input.Displaymode.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.ShowCurrencySymbol]            = input.Showcurrencysymbol.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.CreatedUserId]                 = input.Createduserid.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.TextDisplayHint]               = input.Textdisplayhint.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.NumberDisplayHint]             = input.Numberdisplayhint.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.OptionsAreMutable]             = input.Optionsaremutable.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.ReferencedObjectType]          = input.Referencedobjecttype.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.IsCustomizedDefault]           = input.Iscustomizeddefault.PrintIfAvailable();
            data.Properties[HubSpotVocabulary.PropertyDefinition.UpdatedUserId]                 = input.Updateduserid.PrintIfAvailable();


            return(clue);
        }
示例#30
0
        protected override Clue MakeClueImpl(Owner input, Guid accountId)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var clue = _factory.Create(EntityType.Person, input.ownerId.ToString(), accountId);

            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_001_Outgoing_Edge_MustExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.EDGES_002_Incoming_Edge_ShouldNotExist);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.PROPERTIES_002_Unknown_VocabularyKey_Used);
            clue.ValidationRuleSuppressions.Add(Constants.Validation.Rules.ENTITYTYPE_001_Person_MustNotBeUsedDirectly);

            var data = clue.Data.EntityData;

            if (input.firstName != null && input.lastName != null)
            {
                data.Name = $"{input.firstName} {input.lastName}";
            }

            data.CreatedDate  = DateUtilities.EpochRef.AddMilliseconds(input.createdAt);
            data.ModifiedDate = DateUtilities.EpochRef.AddMilliseconds(input.updatedAt);

            if (input.ownerId != null)
            {
                data.Codes.Add(new EntityCode(EntityType.Person, HubSpotNameConstants.CodeOrigin, input.ownerId.ToString()));
            }

            if (input.email != null)
            {
                data.Codes.Add(new EntityCode(EntityType.Person, HubSpotNameConstants.CodeOrigin, input.email));
            }

            if (input.remoteList != null)
            {
                var remoteList = JsonUtility.Deserialize <JArray>(JsonUtility.Serialize(input.remoteList));
                JsonUtility.Deserialize <Dictionary <string, object> >(remoteList.First.ToString()).TryGetValue("remoteId", out var remoteId);

                if (remoteId != null)
                {
                    data.Codes.Add(new EntityCode(EntityType.Person, HubSpotNameConstants.CodeOrigin, remoteId.ToString()));
                }
            }

            if (input.portalId != null)
            {
                data.Uri = new Uri($"https://app.hubspot.com/user-preferences/{input.portalId}/");  // TODO take from configuration
            }
            data.Properties[HubSpotVocabulary.Owner.Email]     = input.email;
            data.Properties[HubSpotVocabulary.Owner.FirstName] = input.firstName;
            data.Properties[HubSpotVocabulary.Owner.LastName]  = input.lastName;
            data.Properties[HubSpotVocabulary.Owner.Type]      = input.type;

            if (input.portalId != null)
            {
                _factory.CreateIncomingEntityReference(clue, EntityType.Infrastructure.Site, EntityEdgeType.PartOf, input, s => s.portalId.ToString(), s => "HubSpot");
            }

            return(clue);
        }