Exemplo n.º 1
0
        /// <summary>
        /// Executes the query performing the underlying operation
        /// </summary>
        /// <typeparam name="T">The type used to define the query - CloudService or StorageAccount</typeparam>
        /// <param name="inputs">The Authentication inputs needed to fulfil the operation</param>
        /// <returns>An IQueryable interface</returns>
        public IQueryable <T> Execute <T>(LinqToAzureInputs inputs)
        {
            if (typeof(T) != GetValidType())
            {
                throw new InvalidQueryException("Mismatch between generic types StorageAccount type expected");
            }

            // Get the place name(s) to query the Web service with.
            var sf = new StorageFinder(_expression != null ? _expression.Body : null);
            var storageAccounts = sf.StorageAccounts;
            //if (storageAccounts.Count == 0)
            //    throw new InvalidQueryException("You must specify at least one place name in your query.");

            // Call the Web service and get the results.
            var manager = new SubscriptionManager(inputs.SubscriptionId);
            List <StorageAccount> accounts;

            try
            {
                var storageManager = manager.GetStorageManager();
                accounts = storageManager.ForStorageInformationQuery()
                           .AddCertificateFromStore(inputs.ManagementCertificateThumbprint)
                           .GetStorageAccountList(true);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Unable to query Windows Azure", ex);
            }

            return((IQueryable <T>)accounts.AsQueryable());
        }
        /// <summary>
        /// Adds IP addresses to the WASD firewall for a
        /// </summary>
        public void AddIpsToSqlFirewallFromCloudService(string cloudServiceName, bool removeAllOtherRules = true, DeploymentSlot slot = DeploymentSlot.Production)
        {
            if (ServerName == null)
            {
                throw new FluentManagementException("unable to continue without windows azure sql database server name", "SqlDatabaseClient");
            }

            if (removeAllOtherRules)
            {
                // get these rules
                var command = new ListFirewallRulesCommand(ServerName)
                {
                    SubscriptionId = _subscriptionId,
                    Certificate    = _managementCertificate
                };
                command.Execute();
                foreach (var rule in command.FirewallRules)
                {
                    var ruleCommand = new DeleteSqlFirewallRuleCommand(ServerName, rule.RuleName)
                    {
                        SubscriptionId = _subscriptionId,
                        Certificate    = _managementCertificate
                    };
                    ruleCommand.Execute();
                }
            }

            var inputs = new LinqToAzureInputs()
            {
                ManagementCertificateThumbprint = _managementCertificate.Thumbprint,
                SubscriptionId = _subscriptionId
            };
            // build up a filtered query to check the new account
            var cloudServiceQueryable = new LinqToAzureOrderedQueryable <CloudService>(inputs);
            // get only production deployments
            var query = from service in cloudServiceQueryable
                        where service.Deployments.Count != 0 &&
                        service.Deployments.Any(a => a.Slot == slot)
                        select service;
            var cloudService = query.First();
            // enumerate the cloud service deployment and add the ips to the database firewall
            var addRuleCommand = new AddNewFirewallRuleCommand(cloudServiceName,
                                                               cloudService.Deployments.First().RoleInstances.First().VirtualIpAddress,
                                                               cloudService.Deployments.First().RoleInstances.First().VirtualIpAddress)
            {
                SubscriptionId = _subscriptionId,
                Certificate    = _managementCertificate
            };

            addRuleCommand.ConfigureFirewallCommand(ServerName);
            addRuleCommand.Execute();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Executes the query performing the underlying operation
        /// </summary>
        /// <typeparam name="T">The type used to define the query - CloudService or StorageAccount</typeparam>
        /// <param name="inputs">The Authentication inputs needed to fulfil the operation</param>
        /// <returns>An IQueryable interface</returns>
        public IQueryable <T> Execute <T>(LinqToAzureInputs inputs)
        {
            if (typeof(T) != GetValidType())
            {
                throw new InvalidQueryException("Mismatch between generic types StorageAccount type expected");
            }

            // Get the place name(s) to query the Web service with.
            var    sf = new VirtualMachineFinder(_expression != null ? _expression.Body : null);
            string cloudServiceName = sf.CloudServiceName;

            if (String.IsNullOrEmpty(cloudServiceName))
            {
                throw new InvalidQueryException("You must specify a single cloud service in your query");
            }

            // Call the Web service and get the results.
            if (_roles == null)
            {
                // get the cert in the form of an x509v3
                var certificate = PublishSettingsExtractor.FromStore(inputs.ManagementCertificateThumbprint);
                try
                {
                    var properties = new WindowsVirtualMachineProperties()
                    {
                        CloudServiceName = cloudServiceName
                    };
                    var command = new GetVirtualMachineContextCommand(properties)
                    {
                        SubscriptionId = inputs.SubscriptionId,
                        Certificate    = certificate
                    };
                    command.Execute();
                    _roles = command.PersistentVm;
                }
                catch (Exception ex)
                {
                    throw new ApplicationException("Unable to query Windows Azure", ex);
                }
            }
            //return _roles.AsQueryable();
            return((IQueryable <T>)_roles.AsQueryable());
        }
Exemplo n.º 4
0
 /// <summary>
 /// Used to construct an ExecutionFactory
 /// </summary>
 /// <param name="expression">The expression reduced from the query</param>
 /// <param name="inputs">The inputs to Windows Azure</param>
 public ExecutionFactory(Expression expression, LinqToAzureInputs inputs)
 {
     _expression = expression;
     _inputs     = inputs;
 }