Example #1
0
        static async Task Main(string[] args)
        {
            var clientId = "1950a258-227b-4e31-a9cf-717495945fc2"; // "well-known" value: https://blogs.technet.microsoft.com/keithmayer/2014/12/30/leveraging-the-azure-service-management-rest-api-with-azure-active-directory-and-powershell-list-azure-administrators/
            var config   = LoadConfiguration(args);
            //var authorizationRule = "DefaultFullSharedAccessSignature";

            var creds = await UserTokenProvider.LoginByDeviceCodeAsync(clientId, (deviceCodeResult) =>
            {
                Console.WriteLine(deviceCodeResult.Message);
                return(true);
            });

            // Create resource group
            var resourceClient = new ResourceManagementClient(creds);

            resourceClient.SubscriptionId = config.SubscriptionId;
            await resourceClient.ResourceGroups.CreateOrUpdateAsync(config.ResourceGroupName, new ResourceGroup(config.Location));

            var nhManagemntClient = new NotificationHubsManagementClient(creds);

            nhManagemntClient.SubscriptionId = config.SubscriptionId;

            // Create namespace
            await nhManagemntClient.Namespaces.CreateOrUpdateAsync(config.ResourceGroupName, config.NamespaceName, new NamespaceCreateOrUpdateParameters(config.Location)
            {
                Sku = new Microsoft.Azure.Management.NotificationHubs.Models.Sku("standard")
            });

            // Create hub
            Microsoft.Azure.Management.NotificationHubs.Models.GcmCredential  gcmCreds  = null;
            Microsoft.Azure.Management.NotificationHubs.Models.ApnsCredential apnsCreds = null;
            if (config.GcmCreds != null)
            {
                gcmCreds = new Microsoft.Azure.Management.NotificationHubs.Models.GcmCredential
                {
                    GoogleApiKey = config.GcmCreds
                };
            }
            if (config.ApnsCreds != null)
            {
                var apnsCredsSplit = config.ApnsCreds.Replace("\\n", "\n").Split(";");
                apnsCreds = new Microsoft.Azure.Management.NotificationHubs.Models.ApnsCredential
                {
                    KeyId = apnsCredsSplit[0],
                    // Id
                    AppName = apnsCredsSplit[1],
                    // Prefix
                    AppId    = apnsCredsSplit[2],
                    Token    = apnsCredsSplit[3],
                    Endpoint = "https://api.development.push.apple.com:443/3/device"
                };
            }
            await nhManagemntClient.NotificationHubs.CreateOrUpdateAsync(config.ResourceGroupName, config.NamespaceName, config.HubName, new NotificationHubCreateOrUpdateParameters(config.Location)
            {
                GcmCredential  = gcmCreds,
                ApnsCredential = apnsCreds
            });

            Console.WriteLine($"Create NotificationHub {config.HubName}.");
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the PnsCredentialsResource class.
 /// </summary>
 /// <param name="id">Resource Id</param>
 /// <param name="name">Resource name</param>
 /// <param name="type">Resource type</param>
 /// <param name="location">Resource location</param>
 /// <param name="tags">Resource tags</param>
 /// <param name="sku">The sku of the created namespace</param>
 /// <param name="apnsCredential">The ApnsCredential of the created
 /// NotificationHub</param>
 /// <param name="wnsCredential">The WnsCredential of the created
 /// NotificationHub</param>
 /// <param name="gcmCredential">The GcmCredential of the created
 /// NotificationHub</param>
 /// <param name="mpnsCredential">The MpnsCredential of the created
 /// NotificationHub</param>
 /// <param name="admCredential">The AdmCredential of the created
 /// NotificationHub</param>
 /// <param name="baiduCredential">The BaiduCredential of the created
 /// NotificationHub</param>
 public PnsCredentialsResource(string id = default(string), string name = default(string), string type = default(string), string location = default(string), IDictionary <string, string> tags = default(IDictionary <string, string>), Sku sku = default(Sku), ApnsCredential apnsCredential = default(ApnsCredential), WnsCredential wnsCredential = default(WnsCredential), GcmCredential gcmCredential = default(GcmCredential), MpnsCredential mpnsCredential = default(MpnsCredential), AdmCredential admCredential = default(AdmCredential), BaiduCredential baiduCredential = default(BaiduCredential))
     : base(id, name, type, location, tags, sku)
 {
     ApnsCredential  = apnsCredential;
     WnsCredential   = wnsCredential;
     GcmCredential   = gcmCredential;
     MpnsCredential  = mpnsCredential;
     AdmCredential   = admCredential;
     BaiduCredential = baiduCredential;
     CustomInit();
 }
 /// <summary>
 /// Initializes a new instance of the NotificationHubProperties class.
 /// </summary>
 public NotificationHubProperties(string name = default(string), string registrationTtl = default(string), IList <SharedAccessAuthorizationRuleProperties> authorizationRules = default(IList <SharedAccessAuthorizationRuleProperties>), ApnsCredential apnsCredential = default(ApnsCredential), WnsCredential wnsCredential = default(WnsCredential), GcmCredential gcmCredential = default(GcmCredential), MpnsCredential mpnsCredential = default(MpnsCredential), AdmCredential admCredential = default(AdmCredential), BaiduCredential baiduCredential = default(BaiduCredential))
 {
     Name               = name;
     RegistrationTtl    = registrationTtl;
     AuthorizationRules = authorizationRules;
     ApnsCredential     = apnsCredential;
     WnsCredential      = wnsCredential;
     GcmCredential      = gcmCredential;
     MpnsCredential     = mpnsCredential;
     AdmCredential      = admCredential;
     BaiduCredential    = baiduCredential;
 }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the NotificationHubResource class.
 /// </summary>
 /// <param name="id">Resource Id</param>
 /// <param name="name">Resource name</param>
 /// <param name="type">Resource type</param>
 /// <param name="location">Resource location</param>
 /// <param name="tags">Resource tags</param>
 /// <param name="sku">The sku of the created namespace</param>
 /// <param name="notificationHubResourceName">The NotificationHub
 /// name.</param>
 /// <param name="registrationTtl">The RegistrationTtl of the created
 /// NotificationHub</param>
 /// <param name="authorizationRules">The AuthorizationRules of the
 /// created NotificationHub</param>
 /// <param name="apnsCredential">The ApnsCredential of the created
 /// NotificationHub</param>
 /// <param name="wnsCredential">The WnsCredential of the created
 /// NotificationHub</param>
 /// <param name="gcmCredential">The GcmCredential of the created
 /// NotificationHub</param>
 /// <param name="mpnsCredential">The MpnsCredential of the created
 /// NotificationHub</param>
 /// <param name="admCredential">The AdmCredential of the created
 /// NotificationHub</param>
 /// <param name="baiduCredential">The BaiduCredential of the created
 /// NotificationHub</param>
 public NotificationHubResource(string id = default(string), string name = default(string), string type = default(string), string location = default(string), IDictionary <string, string> tags = default(IDictionary <string, string>), Sku sku = default(Sku), string notificationHubResourceName = default(string), string registrationTtl = default(string), IList <SharedAccessAuthorizationRuleProperties> authorizationRules = default(IList <SharedAccessAuthorizationRuleProperties>), ApnsCredential apnsCredential = default(ApnsCredential), WnsCredential wnsCredential = default(WnsCredential), GcmCredential gcmCredential = default(GcmCredential), MpnsCredential mpnsCredential = default(MpnsCredential), AdmCredential admCredential = default(AdmCredential), BaiduCredential baiduCredential = default(BaiduCredential))
     : base(id, name, type, location, tags, sku)
 {
     NotificationHubResourceName = notificationHubResourceName;
     RegistrationTtl             = registrationTtl;
     AuthorizationRules          = authorizationRules;
     ApnsCredential  = apnsCredential;
     WnsCredential   = wnsCredential;
     GcmCredential   = gcmCredential;
     MpnsCredential  = mpnsCredential;
     AdmCredential   = admCredential;
     BaiduCredential = baiduCredential;
     CustomInit();
 }