public ListSubscriptionsResponse Get(ListSubscriptions request)
        {
            var subscriptions = Store.Find(Caller.UserId);

            logger.InfoFormat(@"Listed subscription for user {0}", Caller.UserId);

            return(new ListSubscriptionsResponse
            {
                Subscriptions = subscriptions
            });
        }
 public Subscriptions Get()
 {
     try
     {
         var subscriptions = ListSubscriptions.GetSubscriptions();
         return(subscriptions);
     }
     catch
     {
         return(null);
     }
 }
        public ListSubscriptionsResponse Get(ListSubscriptions request)
        {
            var subscriptions = Store.Find(Caller.UserId)
                                .Safe()
                                .ToList();

            logger.InfoFormat(@"[ServiceStack.Webhooks.ServiceInterface.SubscriptionService] Listed subscription for user {0}", Caller.UserId);

            return(new ListSubscriptionsResponse
            {
                Subscriptions = subscriptions
            });
        }
Beispiel #4
0
        public void ListSubscriptions()
        {
            var listsubs = new ListSubscriptions();

            var chargeResponse = listsubs.doListSubscriptions(ScKey);

            System.Console.WriteLine("chargeResponse:" + chargeResponse.ToString());

            JObject json = JObject.Parse(chargeResponse);

            // Assert.IsNotNull(chargeResponse.Data);
            Assert.AreEqual("success", (string)json.SelectToken("status"));
        }
        /// <summary>
        /// Inserts a contact into xDb using xConnect
        /// </summary>
        /// <param name="contact"></param>
        /// <returns></returns>
        public bool InsertContactAndAddContactToList(string source, string contactId, string alias, string firstName, string lastName, string title, string emailAddress, string listId)
        {
            // Identifier for a 'known' contact
            var identifier = new ContactIdentifier[]
            {
                new ContactIdentifier(source, contactId, ContactIdentifierType.Known),
                new ContactIdentifier(source + "_ALIAS", alias, ContactIdentifierType.Known)
            };

            // Create a new contact with the identifier
            var knownContact = new Sitecore.XConnect.Contact(identifier);

            var personalInfoFacet = new PersonalInformation()
            {
                Title     = title,
                FirstName = firstName,
                LastName  = lastName
            };


            Client.SetPersonal(knownContact, personalInfoFacet);

            var emailAddressList = new EmailAddressList(new EmailAddress(emailAddress, false), "SlackEmailAddress");

            Client.SetEmails(knownContact, emailAddressList);

            // if contact does not have list subscriptions then we need to add it
            if (knownContact.ListSubscriptions() == null)
            {
                var listSubscriptions = new ListSubscriptions();
                listSubscriptions.Subscriptions.Add(new ContactListSubscription(DateTime.Now, true, new Guid(listId)));
                Client.SetFacet <ListSubscriptions>(knownContact, ListSubscriptions.DefaultFacetKey, listSubscriptions);
            }
            else
            {
                knownContact.ListSubscriptions().Subscriptions.Add(new ContactListSubscription(DateTime.Now, true, new Guid(listId)));
            }

            Client.AddContact(knownContact);

            Client.Submit();

            // Get the last batch that was executed
            var operations = Client.LastBatch;

            return(true);
        }
        /// <summary>
        /// Inserts Interaction on existing contact
        /// </summary>
        /// <param name="contact"></param>
        /// <param name="slackId"></param>
        /// <param name="slackDateTime"></param>
        /// <param name="messageText"></param>
        /// <returns></returns>
        public bool AddContactToList(Contact knownContact, string listId)
        {
            // if contact does not have list subscriptions then we need to add it
            if (knownContact.ListSubscriptions() == null)
            {
                var listSubscriptions = new ListSubscriptions();
                listSubscriptions.Subscriptions.Add(new ContactListSubscription(DateTime.Now, true, new Guid(listId)));
                Client.SetFacet <ListSubscriptions>(knownContact, ListSubscriptions.DefaultFacetKey, listSubscriptions);
            }
            else
            {
                knownContact.ListSubscriptions().Subscriptions.Add(new ContactListSubscription(DateTime.Now, true, new Guid(listId)));
            }

            Client.Submit();

            return(true);
        }
 public void Initialize()
 {
     dto       = new ListSubscriptions();
     validator = new ListSubscriptionsValidator();
 }
Beispiel #8
0
        public HttpResponseMessage Get(String hostName)
        {
            List <String> subList = new List <string>();

            Subscriptions subscriptions = ListSubscriptions.GetSubscriptions();

            foreach (var sub in subscriptions.value)
            {
                if (sub.id.Contains(SubscriptionFilter))
                {
                    subList.Add(sub.subscriptionId);
                }
            }

            String accessToken = "";

            accessToken = Adal.AccessToken();
            string authToken = "Bearer" + " " + accessToken;
            var    client    = new WebClient();

            client.Headers.Add("Authorization", authToken);
            client.Headers.Add("Content-Type", "application/json");
            ComputeVms masterComputeVmsList = new ComputeVms();

            masterComputeVmsList.value = new List <ComputeVm>();

            foreach (var subId in subList)
            {
                Uri    resourceGroupsUri = new Uri(String.Format("https://management.azure.com/subscriptions/{0}/providers/Microsoft.Compute/virtualmachines?api-version=2015-05-01-preview", subId));
                String text = "";
                text = client.DownloadString(resourceGroupsUri);
                ComputeVms computeVmsList = JsonConvert.DeserializeObject <ComputeVms>(text);
                foreach (var vm in computeVmsList.value)
                {
                    masterComputeVmsList.value.Add(vm);
                }
            }

            foreach (var vm in masterComputeVmsList.value)
            {
                ResourceGroup thisRg = ComputeResources.GetHostResourceGroup(accessToken, vm);
                if ((vm.tags != null) && (vm.tags.ContainsKey("AnsibleDomainSuffix")))
                {
                    vm.name = vm.name + "." + vm.tags["AnsibleDomainSuffix"];
                }
                else if ((thisRg.tags != null) && (thisRg.tags.ContainsKey("AnsibleDomainSuffix")))
                {
                    vm.name = vm.name + "." + thisRg.tags["AnsibleDomainSuffix"];
                }
            }

            ComputeVm thisComputeVm = masterComputeVmsList.value.Where(t => t.name.ToLower() == hostName.ToLower()).FirstOrDefault();

            if (thisComputeVm == null)
            {
                var response = this.Request.CreateResponse(HttpStatusCode.NotFound);
                return(response);
            }
            else
            {
                Dictionary <String, String> TagsDict = new Dictionary <String, String>();

                if (thisComputeVm.tags != null)
                {
                    foreach (var tag in thisComputeVm.tags.Where(t => t.Key.ToLower().StartsWith("ansible__")))
                    {
                        TagsDict.Add((tag.Key.ToLower().Replace("ansible__", "")), tag.Value);
                    }
                }


                String json     = JsonConvert.SerializeObject(TagsDict);
                var    response = this.Request.CreateResponse(HttpStatusCode.OK);
                response.Content = new StringContent(json, Encoding.UTF8, "application/json");
                return(response);
            }
        }
        private void SetContact(Contact target, Contact source)
        {
            // Default Facets
            if (source.Facets.ContainsKey(PersonalInformation.DefaultFacetKey))
            {
                if (target.Facets.ContainsKey(PersonalInformation.DefaultFacetKey))
                {
                    PersonalInformation sourceFacet = source.GetFacet <PersonalInformation>();
                    PersonalInformation targetFacet = target.GetFacet <PersonalInformation>();
                    targetFacet.Birthdate         = sourceFacet.Birthdate;
                    targetFacet.FirstName         = sourceFacet.FirstName;
                    targetFacet.Gender            = sourceFacet.Gender;
                    targetFacet.JobTitle          = sourceFacet.JobTitle;
                    targetFacet.Title             = sourceFacet.Title;
                    targetFacet.LastName          = sourceFacet.LastName;
                    targetFacet.MiddleName        = sourceFacet.MiddleName;
                    targetFacet.Nickname          = sourceFacet.Nickname;
                    targetFacet.PreferredLanguage = sourceFacet.PreferredLanguage;
                    targetFacet.Suffix            = sourceFacet.Suffix;
                    _client.SetFacet(target, PersonalInformation.DefaultFacetKey, targetFacet);
                }
                else
                {
                    _client.SetFacet(
                        target,
                        PersonalInformation.DefaultFacetKey,
                        source.GetFacet <PersonalInformation>().WithClearedConcurrency());
                }
            }

            if (source.Facets.ContainsKey(EmailAddressList.DefaultFacetKey))
            {
                if (target.Facets.ContainsKey(EmailAddressList.DefaultFacetKey))
                {
                    EmailAddressList sourceFacet = source.GetFacet <EmailAddressList>();
                    EmailAddressList targetFacet = target.GetFacet <EmailAddressList>();
                    targetFacet.Others         = sourceFacet.Others;
                    targetFacet.PreferredEmail = sourceFacet.PreferredEmail;
                    targetFacet.PreferredKey   = sourceFacet.PreferredKey;
                    _client.SetFacet(target, EmailAddressList.DefaultFacetKey, targetFacet);
                }
                else
                {
                    _client.SetFacet(
                        target,
                        EmailAddressList.DefaultFacetKey,
                        source.GetFacet <EmailAddressList>().WithClearedConcurrency());
                }
            }

            if (source.Facets.ContainsKey(AddressList.DefaultFacetKey))
            {
                if (target.Facets.ContainsKey(AddressList.DefaultFacetKey))
                {
                    AddressList sourceFacet = source.Addresses();
                    AddressList targetFacet = target.Addresses();
                    targetFacet.PreferredKey     = sourceFacet.PreferredKey;
                    targetFacet.Others           = sourceFacet.Others;
                    targetFacet.PreferredAddress = sourceFacet.PreferredAddress;
                    _client.SetAddresses(target, targetFacet);
                }
                else
                {
                    _client.SetAddresses(target, source.Addresses().WithClearedConcurrency());
                }
            }

            if (source.Facets.ContainsKey(PhoneNumberList.DefaultFacetKey))
            {
                if (target.Facets.ContainsKey(PhoneNumberList.DefaultFacetKey))
                {
                    PhoneNumberList sourceFacet = source.PhoneNumbers();
                    PhoneNumberList targetFacet = target.PhoneNumbers();
                    targetFacet.PreferredKey         = sourceFacet.PreferredKey;
                    targetFacet.Others               = sourceFacet.Others;
                    targetFacet.PreferredPhoneNumber = sourceFacet.PreferredPhoneNumber;
                    _client.SetPhoneNumbers(target, targetFacet);
                }
                else
                {
                    _client.SetPhoneNumbers(target, source.PhoneNumbers().WithClearedConcurrency());
                }
            }

            if (source.Facets.ContainsKey(ConsentInformation.DefaultFacetKey))
            {
                if (target.Facets.ContainsKey(ConsentInformation.DefaultFacetKey))
                {
                    ConsentInformation sourceFacet = source.ConsentInformation();
                    ConsentInformation targetFacet = target.ConsentInformation();
                    targetFacet.ConsentRevoked             = sourceFacet.ConsentRevoked;
                    targetFacet.DoNotMarket                = sourceFacet.DoNotMarket;
                    targetFacet.ExecutedRightToBeForgotten = sourceFacet.ExecutedRightToBeForgotten;
                    _client.SetConsentInformation(target, targetFacet);
                }
                else
                {
                    _client.SetConsentInformation(target, source.ConsentInformation().WithClearedConcurrency());
                }
            }

            if (source.Facets.ContainsKey(ListSubscriptions.DefaultFacetKey))
            {
                if (target.Facets.ContainsKey(ListSubscriptions.DefaultFacetKey))
                {
                    ListSubscriptions sourceFacet = source.ListSubscriptions();
                    ListSubscriptions targetFacet = target.ListSubscriptions();
                    targetFacet.Subscriptions = sourceFacet.Subscriptions;
                    _client.SetListSubscriptions(target, targetFacet);
                }
                else
                {
                    _client.SetListSubscriptions(target, source.ListSubscriptions().WithClearedConcurrency());
                }
            }

            if (source.Facets.ContainsKey(Avatar.DefaultFacetKey))
            {
                if (target.Facets.ContainsKey(Avatar.DefaultFacetKey))
                {
                    Avatar sourceFacet = source.Avatar();
                    Avatar targetFacet = target.Avatar();
                    targetFacet.MimeType = sourceFacet.MimeType;
                    targetFacet.Picture  = sourceFacet.Picture;
                    _client.SetAvatar(target, targetFacet);
                }
                else
                {
                    _client.SetAvatar(target, source.Avatar().WithClearedConcurrency());
                }
            }

            if (source.Facets.ContainsKey(EmailAddressHistory.DefaultFacetKey))
            {
                if (target.Facets.ContainsKey(EmailAddressHistory.DefaultFacetKey))
                {
                    EmailAddressHistory sourceFacet = source.GetFacet <EmailAddressHistory>();
                    EmailAddressHistory targetFacet = target.GetFacet <EmailAddressHistory>();
                    targetFacet.History = sourceFacet.History;
                    _client.SetFacet(target, EmailAddressHistory.DefaultFacetKey, targetFacet);
                }
                else
                {
                    _client.SetFacet(
                        target,
                        EmailAddressHistory.DefaultFacetKey,
                        source.GetFacet <EmailAddressHistory>().WithClearedConcurrency());
                }
            }

            if (source.Facets.ContainsKey("TestCombinations"))
            {
                if (target.Facets.ContainsKey("TestCombinations"))
                {
                    TestCombinationsData sourceFacet = source.Facets["TestCombinations"] as TestCombinationsData;
                    if (target.Facets["TestCombinations"] is TestCombinationsData targetFacet)
                    {
                        targetFacet.TestCombinations = sourceFacet?.TestCombinations;
                        _client.SetFacet(target, "TestCombinations", targetFacet);
                    }
                }
                else
                {
                    Facet oldFacet = source.Facets["TestCombinations"];
                    TestCombinationsData newFacet = new TestCombinationsData();
                    newFacet.TestCombinations = oldFacet.XObject["TestCombinations"]?.ToString();
                    _client.SetFacet(target, "TestCombinations", newFacet);
                }
            }

            // TODO Handle custom facets

            _client.Submit();
        }