Exemplo n.º 1
0
        public static IEnumerable <WindowsAzureSubscription> Import(Stream stream)
        {
            var publishData = DeserializePublishData(stream);
            PublishDataPublishProfile profile = publishData.Items.Single();

            return(profile.Subscription.Select(s => PublishSubscriptionToAzureSubscription(profile, s)));
        }
Exemplo n.º 2
0
        private static AzureSubscription PublishSubscriptionToAzureSubscription(
            ProfileClient azureProfileClient,
            PublishDataPublishProfile profile,
            PublishDataPublishProfileSubscription s,
            string environment)
        {
            var certificate = GetCertificate(profile, s);

            if (string.IsNullOrEmpty(environment))
            {
                var azureEnvironment = azureProfileClient.GetEnvironment(environment, s.ServiceManagementUrl ?? profile.Url, null);
                if (azureEnvironment != null)
                {
                    environment = azureEnvironment.Name;
                }
                else
                {
                    environment = EnvironmentName.AzureCloud;
                }
            }

            return(new AzureSubscription
            {
                Id = new Guid(s.Id),
                Name = s.Name,
                Environment = environment,
                Account = certificate.Thumbprint
            });
        }
Exemplo n.º 3
0
        private void New(string subscriptionsDataFile, X509Certificate2 certificate, string serviceEndpoint)
        {
            Validate.ValidateStringIsNullOrEmpty(GlobalPaths.AzureDirectory, Resources.AzureDirectoryName);

            Certificate          = certificate;
            SubscriptionManager  = SubscriptionsManager.Import(subscriptionsDataFile, null, certificate);
            ServiceConfiguration = new ServiceConfiguration {
                endpoint = serviceEndpoint
            };
            PublishSettings = new PublishData();

            var publishDataProfile = new PublishDataPublishProfile
            {
                ManagementCertificate = certificate.Thumbprint,
                Url = ServiceConfiguration.endpoint
            };

            if (SubscriptionManager.Subscriptions != null &&
                SubscriptionManager.Subscriptions.Count > 0)
            {
                var subscription = SubscriptionManager.Subscriptions.Values.First();

                ServiceConfiguration.subscription     = subscription.SubscriptionId;
                ServiceConfiguration.subscriptionName = subscription.SubscriptionName;
                publishDataProfile.Subscription       = new [] {
                    new PublishDataPublishProfileSubscription
                    {
                        Id   = subscription.SubscriptionId,
                        Name = subscription.SubscriptionName
                    }
                };
            }

            PublishSettings.Items = new [] { publishDataProfile };
        }
Exemplo n.º 4
0
        public static IEnumerable <AzureSubscription> ImportAzureSubscription(Stream stream, ProfileClient azureProfileClient, string environment)
        {
            var publishData = DeserializePublishData(stream);
            PublishDataPublishProfile profile = publishData.Items.Single();

            stream.Close();
            return(profile.Subscription.Select(s => PublishSubscriptionToAzureSubscription(azureProfileClient, profile, s, environment)));
        }
Exemplo n.º 5
0
 private static Uri GetManagementUri(PublishDataPublishProfile profile, PublishDataPublishProfileSubscription s)
 {
     if (!string.IsNullOrEmpty(s.ServiceManagementUrl))
     {
         return(new Uri(s.ServiceManagementUrl));
     }
     else if (!string.IsNullOrEmpty(profile.Url))
     {
         return(new Uri(profile.Url));
     }
     return(null);
 }
 private static Uri GetManagementUri(PublishDataPublishProfile profile, PublishDataPublishProfileSubscription s)
 {
     if (!string.IsNullOrEmpty(s.ServiceManagementUrl))
     {
         return new Uri(s.ServiceManagementUrl);
     }
     else if (!string.IsNullOrEmpty(profile.Url))
     {
         return new Uri(profile.Url);
     }
     return null;
 }
 private static WindowsAzureSubscription PublishSubscriptionToAzureSubscription(
     PublishDataPublishProfile profile,
     PublishDataPublishProfileSubscription s)
 {
     return(new WindowsAzureSubscription
     {
         Certificate = GetCertificate(profile, s),
         SubscriptionName = s.Name,
         ServiceEndpoint = GetManagementUri(profile, s),
         SubscriptionId = s.Id
     });
 }
 private static WindowsAzureSubscription PublishSubscriptionToAzureSubscription(
     PublishDataPublishProfile profile,
     PublishDataPublishProfileSubscription s)
 {
     return new WindowsAzureSubscription
     {
         Certificate = GetCertificate(profile, s),
         SubscriptionName = s.Name,
         ServiceEndpoint = GetManagementUri(profile, s),
         SubscriptionId = s.Id
     };
 }
Exemplo n.º 9
0
        public void Setup()
        {
            PublishData publishData = General.DeserializeXmlFile<PublishData>("Azure.publishsettings");
            PublishDataPublishProfile publishProfile = publishData.Items[0];
            this.serializedCert = publishProfile.ManagementCertificate;
            this.subscriptionID = publishProfile.Subscription[0].Id;

            XElement root = XElement.Load("SqlDatabaseSettings.xml");
            this.serverLocation = root.Element("ServerLocation").Value;

            new NewAzureSqlDatabaseServerFirewallRule();
        }
 private static X509Certificate2 GetCertificate(PublishDataPublishProfile profile,
     PublishDataPublishProfileSubscription s)
 {
     string certificateString;
     if (!string.IsNullOrEmpty(s.ManagementCertificate))
     {
         certificateString = s.ManagementCertificate;
     }
     else
     {
         certificateString = profile.ManagementCertificate;
     }
     return WindowsAzureCertificate.FromPublishSettingsString(certificateString);
 }
 private static WindowsAzureSubscription PublishSubscriptionToAzureSubscription(
     PublishDataPublishProfile profile,
     PublishDataPublishProfileSubscription s)
 {
     return(new WindowsAzureSubscription
     {
         Certificate = GetCertificate(profile, s),
         SubscriptionName = s.Name,
         ServiceEndpoint = GetManagementUri(profile, s),
         ResourceManagerEndpoint = null,
         SubscriptionId = s.Id,
         SqlDatabaseDnsSuffix = WindowsAzureEnvironmentConstants.AzureSqlDatabaseDnsSuffix,
     });
 }
 private static WindowsAzureSubscription PublishSubscriptionToAzureSubscription(
     PublishDataPublishProfile profile,
     PublishDataPublishProfileSubscription s)
 {
     return new WindowsAzureSubscription
     {
         Certificate = GetCertificate(profile, s),
         SubscriptionName = s.Name,
         ServiceEndpoint = GetManagementUri(profile, s),
         ResourceManagerEndpoint = null,
         SubscriptionId = s.Id,
         SqlDatabaseDnsSuffix = WindowsAzureEnvironmentConstants.AzureSqlDatabaseDnsSuffix,
     };
 }
Exemplo n.º 13
0
        private static X509Certificate2 GetCertificate(PublishDataPublishProfile profile,
                                                       PublishDataPublishProfileSubscription s)
        {
            string certificateString;

            if (!string.IsNullOrEmpty(s.ManagementCertificate))
            {
                certificateString = s.ManagementCertificate;
            }
            else
            {
                certificateString = profile.ManagementCertificate;
            }
            return(WindowsAzureCertificate.FromPublishSettingsString(certificateString));
        }
Exemplo n.º 14
0
        private static X509Certificate2 GetCertificate(PublishDataPublishProfile profile,
                                                       PublishDataPublishProfileSubscription s)
        {
            string certificateString;

            if (!string.IsNullOrEmpty(s.ManagementCertificate))
            {
                certificateString = s.ManagementCertificate;
            }
            else
            {
                certificateString = profile.ManagementCertificate;
            }

            X509Certificate2 certificate = new X509Certificate2(Convert.FromBase64String(certificateString), string.Empty);

            AzureSession.DataStore.AddCertificate(certificate);

            return(certificate);
        }
Exemplo n.º 15
0
        private void New(string subscriptionsDataFile, X509Certificate2 certificate, string serviceEndpoint)
        {
            Validate.ValidateStringIsNullOrEmpty(GlobalPaths.AzureDirectory, Resources.AzureDirectoryName);

            Certificate = certificate;
            SubscriptionManager = SubscriptionsManager.Import(subscriptionsDataFile, null, certificate);
            ServiceConfiguration = new ServiceConfiguration { endpoint = serviceEndpoint };
            PublishSettings = new PublishData();

            var publishDataProfile = new PublishDataPublishProfile
            {
                Url = ServiceConfiguration.endpoint
            };

            if (Certificate != null)
            {
                publishDataProfile.ManagementCertificate = certificate.Thumbprint;
            }

            if (SubscriptionManager.Subscriptions != null &&
                SubscriptionManager.Subscriptions.Count > 0)
            {
                var subscription = SubscriptionManager.Subscriptions.Values.First();

                ServiceConfiguration.subscription = subscription.SubscriptionId;
                ServiceConfiguration.subscriptionName = subscription.SubscriptionName;
                publishDataProfile.Subscription = new [] {
                    new PublishDataPublishProfileSubscription
                    {
                        Id = subscription.SubscriptionId,
                        Name = subscription.SubscriptionName
                    }
                };
            }

            PublishSettings.Items = new [] { publishDataProfile };
        }
Exemplo n.º 16
0
        public void LoadPublishProfile(PublishDataPublishProfile profile_)
        {
            new DelegateCommandBW((o) =>
            {
                try
                {
                    var profile        = o as PublishDataPublishProfile;
                    LoadingRingMessage = true;
                    Message            = "Loading Publish Profile";
                    if (profile.Subscription.Count() != 0)
                    {
                        var _sub = new List <Subscription>();

                        MobileDbContext ctx = new MobileDbContext();

                        foreach (var subscription in profile.Subscription)
                        {
                            _sub.Add(new Subscription()
                            {
                                Id   = Guid.Parse(subscription.Id),
                                Name = subscription.Name,
                                Cert = subscription.ManagementCertificate
                            });

                            var subId = Guid.Parse(subscription.Id);
                            //Check If subscription already exist in the database
                            if (!ctx.Subscriptions.Any(u => u.Id == subId))
                            {
                                Message         = String.Format("New Subscription : {0} added", subscription.Name);
                                var subToInsert = new Subscription()
                                {
                                    Id   = subId,
                                    Name = subscription.Name,
                                    Cert = subscription.ManagementCertificate
                                };
                                ctx.Subscriptions.Add(subToInsert);
                                Application.Current.Dispatcher.Invoke(() =>
                                {
                                    Subscriptions.Add(subToInsert);
                                });
                            }
                            //Else Check if the certificate has changed, take the last certificate
                            else if (ctx.Subscriptions.Find(subId) != null)
                            {
                                var sub = ctx.Subscriptions.Find(subId);
                                if (sub.Cert != subscription.ManagementCertificate)
                                {
                                    sub.Cert = subscription.ManagementCertificate;
                                    Message  = String.Format("Certificate change for Subscription :{0}",
                                                             subscription.Name);
                                }
                            }
                        }
                        ctx.SaveChanges();
                        Message = "Publish Profile Loaded";
                    }
                    else
                    {
                        Message = "No subscription found in the publish profile";
                    }
                }
                catch (Exception e)
                {
                    Message = e.Message;
                }

                finally
                {
                    LoadingRingMessage = false;
                }
            }).Execute(profile_);
        }