public override void ExecuteCmdlet()
        {
            WebsitesClient = WebsitesClient ?? new WebsitesClient(CurrentSubscription, WriteDebug);

            if (!File.IsPresent && !Storage.IsPresent)
            {
                WebsitesClient.DisableApplicationDiagnostic(Name, WebsiteDiagnosticOutput.FileSystem);
                WebsitesClient.DisableApplicationDiagnostic(Name, WebsiteDiagnosticOutput.StorageTable);
            }
            else
            {
                if (File.IsPresent)
                {
                    WebsitesClient.DisableApplicationDiagnostic(Name, WebsiteDiagnosticOutput.FileSystem);
                }

                if (Storage.IsPresent)
                {
                    WebsitesClient.DisableApplicationDiagnostic(Name, WebsiteDiagnosticOutput.StorageTable);
                }
            }

            if (PassThru.IsPresent)
            {
                WriteObject(true);
            }
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the GetAzureWebsiteLogCommand class.
 /// </summary>
 /// <param name="channel">
 /// Channel used for communication with Azure's service management APIs.
 /// </param>
 /// <param name="deploymentChannel">
 /// Channel used for communication with the git repository.
 /// </param>
 public GetAzureWebsiteLogCommand(
     IWebsitesServiceManagement channel,
     IDeploymentServiceManagement deploymentChannel)
 {
     Channel           = channel;
     DeploymentChannel = deploymentChannel;
     WebsiteClient     = null;
 }
 /// <summary>
 /// Initializes a new instance of the GetAzureWebsiteLogCommand class.
 /// </summary>
 /// <param name="channel">
 /// Channel used for communication with Azure's service management APIs.
 /// </param>
 /// <param name="deploymentChannel">
 /// Channel used for communication with the git repository.
 /// </param>
 public GetAzureWebsiteLogCommand(
     IWebsitesServiceManagement channel,
     IDeploymentServiceManagement deploymentChannel)
 {
     Channel = channel;
     DeploymentChannel = deploymentChannel;
     WebsiteClient = null;
 }
예제 #4
0
        public override void ExecuteCmdlet()
        {
            WebsitesClient = WebsitesClient ?? new WebsitesClient(CurrentSubscription, WriteDebug);
            WebsitesClient.StartAzureWebsite(Name);

            if (PassThru.IsPresent)
            {
                WriteObject(true);
            }
        }
예제 #5
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            WebsiteClient = WebsiteClient ?? new WebsitesClient(CurrentSubscription, WriteDebug);

            if (Tail.IsPresent)
            {
                foreach (string logLine in WebsiteClient.StartLogStreaming(
                             Name,
                             Path,
                             Message,
                             StopCondition,
                             WaitInterval))
                {
                    WriteObject(logLine);
                }
            }
            else if (ListPath.IsPresent)
            {
                WriteObject(WebsiteClient.ListLogPaths(Name).Select <LogPath, string>(i => i.Name), true);
            }
        }
예제 #6
0
        public override void ExecuteCmdlet()
        {
            if (CurrentSubscription == null)
            {
                throw new Exception(Resources.NoDefaultSubscriptionMessage);
            }

            if (!string.IsNullOrEmpty(Name))
            {
                // Show website
                Site websiteObject = RetryCall(s => Channel.GetSite(s, Name, "repositoryuri,publishingpassword,publishingusername"));
                if (websiteObject == null)
                {
                    throw new Exception(string.Format(Resources.InvalidWebsite, Name));
                }

                SiteConfig websiteConfiguration = null;
                InvokeInOperationContext(() =>
                {
                    websiteConfiguration = RetryCall(s => Channel.GetSiteConfig(s, websiteObject.WebSpace, websiteObject.Name));
                    WaitForOperation(CommandRuntime.ToString());
                });

                // Add to cache
                Cache.AddSite(CurrentSubscription.SubscriptionId, websiteObject);

                DiagnosticsSettings diagnosticsSettings = null;
                if (websiteObject.State == "Running")
                {
                    WebsitesClient = WebsitesClient ?? new WebsitesClient(CurrentSubscription, WriteDebug);
                    diagnosticsSettings = WebsitesClient.GetApplicationDiagnosticsSettings(Name);
                }

                // Output results
                WriteObject(new SiteWithConfig(websiteObject, websiteConfiguration, diagnosticsSettings), false);
            }
            else
            {
                // Show websites
                WebSpaces webspaces = null;
                InvokeInOperationContext(() =>
                {
                    webspaces = RetryCall(s => Channel.GetWebSpaces(s));
                    WaitForOperation(CommandRuntime.ToString());
                });

                List<Site> websites = new List<Site>();
                foreach (var webspace in webspaces)
                {
                    InvokeInOperationContext(() =>
                    {
                        websites.AddRange(RetryCall(s => Channel.GetSites(s, webspace.Name, "repositoryuri,publishingpassword,publishingusername")));
                        WaitForOperation(CommandRuntime.ToString());
                    });
                }

                // Add to cache
                Cache.SaveSites(CurrentSubscription.SubscriptionId, new Sites(websites));

                // Output results
                WriteWebsites(websites);
            }
        }
예제 #7
0
        public override void ExecuteCmdlet()
        {
            WebsitesClient = WebsitesClient ?? new WebsitesClient(CurrentSubscription, WriteDebug);
            string suffix = WebsitesClient.GetWebsiteDnsSuffix();

            if (Git && GitHub)
            {
                throw new Exception("Please run the command with either -Git or -GitHub options. Not both.");
            }

            if (Git)
            {
                PublishingUsername = GetPublishingUser();
            }

            WebSpaces webspaceList = null;
            InvokeInOperationContext(() => { webspaceList = RetryCall(s => Channel.GetWebSpacesWithCache(s)); });
            if (Git && webspaceList.Count == 0)
            {
                // If location is still empty or null, give portal instructions.
                string error = string.Format(Resources.PortalInstructions, Name);
                throw new Exception(!Git
                    ? error
                    : string.Format("{0}\n{1}", error, Resources.PortalInstructionsGit));
            }

            WebSpace webspace = null;
            if (string.IsNullOrEmpty(Location))
            {
                // If no location was provided as a parameter, try to default it
                webspace = webspaceList.FirstOrDefault();
                if (webspace == null)
                {
                    webspace = new WebSpace
                    {
                        GeoRegion = WebsitesClient.GetDefaultLocation(),
                        Subscription = CurrentSubscription.SubscriptionId,
                        Plan = "VirtualDedicatedPlan"
                    };
                }
            }
            else
            {
                // Find the webspace that corresponds to the georegion
                webspace = webspaceList.FirstOrDefault(w => w.GeoRegion.Equals(Location, StringComparison.OrdinalIgnoreCase));
                if (webspace == null)
                {
                    // If no webspace corresponding to the georegion was found, attempt to create it
                    webspace = new WebSpace
                    {
                        Name = Regex.Replace(Location.ToLower(), " ", "") + "webspace",
                        GeoRegion = Location,
                        Subscription = CurrentSubscription.SubscriptionId,
                        Plan = "VirtualDedicatedPlan"
                    };
                }
            }

            SiteWithWebSpace website = new SiteWithWebSpace
            {
                Name = Name,
                HostNames = new[] { string.Format("{0}.{1}", Name, suffix) },
                WebSpace = webspace.Name,
                WebSpaceToCreate = webspace
            };

            if (!string.IsNullOrEmpty(Hostname))
            {
                List<string> newHostNames = new List<string>(website.HostNames);
                newHostNames.Add(Hostname);
                website.HostNames = newHostNames.ToArray();
            }

            try
            {
                InvokeInOperationContext(() => RetryCall(s => Channel.CreateSite(s, webspace.Name, website)));

                // If operation succeeded try to update cache with new webspace if that's the case
                if (webspaceList.FirstOrDefault(ws => ws.Name.Equals(webspace.Name)) == null)
                {
                    Cache.AddWebSpace(CurrentSubscription.SubscriptionId, webspace);
                }

                Cache.AddSite(CurrentSubscription.SubscriptionId, website);
                SiteConfig websiteConfiguration = null;
                InvokeInOperationContext(() =>
                {
                    websiteConfiguration = RetryCall(s => Channel.GetSiteConfig(s, website.WebSpace, website.Name));
                    WaitForOperation(CommandRuntime.ToString());
                });
                WriteObject(new SiteWithConfig(website, websiteConfiguration));
            }
            catch (ProtocolException ex)
            {
                // Handle site creating indepently so that cmdlet is idempotent.
                string message = ProcessException(ex, false);
                if (message.Equals(string.Format(Resources.WebsiteAlreadyExistsReplacement,
                                                 Name)) && (Git || GitHub))
                {
                    WriteWarning(message);
                }
                else if (message.Equals(Resources.DefaultHostnamesValidation))
                {
                    WriteExceptionError(new Exception(Resources.InvalidHostnameValidation));
                }
                else
                {
                    WriteExceptionError(new Exception(message));
                }
            }

            if (Git || GitHub)
            {
                try
                {
                    Directory.SetCurrentDirectory(SessionState.Path.CurrentFileSystemLocation.Path);
                }
                catch (Exception)
                {
                    // Do nothing if session state is not present
                }

                LinkedRevisionControl linkedRevisionControl = null;
                if (Git)
                {
                    linkedRevisionControl = new GitClient(this);
                }
                else if (GitHub)
                {
                    linkedRevisionControl = new GithubClient(this, GithubCredentials, GithubRepository);
                }

                linkedRevisionControl.Init();

                CopyIisNodeWhenServerJsPresent();
                UpdateLocalConfigWithSiteName(Name, webspace.Name);

                InitializeRemoteRepo(webspace.Name, Name);

                Site updatedWebsite = RetryCall(s => Channel.GetSite(s, webspace.Name, Name, "repositoryuri,publishingpassword,publishingusername"));
                if (Git)
                {
                    AddRemoteToLocalGitRepo(updatedWebsite);
                }

                linkedRevisionControl.Deploy(updatedWebsite);
                linkedRevisionControl.Dispose();
            }
        }
예제 #8
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            if (Service.IsPresent)
            {
                IsDNSAvailable(CurrentContext.Subscription, Name);
            }
            else if (Storage.IsPresent)
            {
                IsStorageServiceAvailable(CurrentContext.Subscription, Name);
            }
            else if (Website.IsPresent)
            {
                WebsitesClient = WebsitesClient ?? new WebsitesClient(CurrentContext.Subscription, WriteDebug);
                IsWebsiteAvailable(Name);
            }
            else
            {
                ServiceBusClient = ServiceBusClient ?? new ServiceBusClientExtensions(CurrentContext.Subscription);
                IsServiceBusNamespaceAvailable(CurrentContext.Subscription.Id.ToString(), Name);
            }
        }
 public override void ExecuteCmdlet()
 {
     WebsitesClient = WebsitesClient ?? new WebsitesClient(CurrentSubscription, WriteDebug);
     WriteObject(WebsitesClient.ListAvailableLocations(), true);
 }
        public override void ExecuteCmdlet()
        {
            WebsitesClient = WebsitesClient ?? new WebsitesClient(CurrentSubscription, WriteDebug);

            Dictionary<DiagnosticProperties, object> properties = new Dictionary<DiagnosticProperties, object>();
            properties[DiagnosticProperties.LogLevel] = LogLevel;

            if (File.IsPresent)
            {
                WebsitesClient.EnableApplicationDiagnostic(Name, WebsiteDiagnosticOutput.FileSystem, properties);
            }
            else if (Storage.IsPresent)
            {
                string storageName = string.IsNullOrEmpty(StorageAccountName) ?
                    CurrentSubscription.CurrentStorageAccount : StorageAccountName;
                properties[DiagnosticProperties.StorageAccountName] = storageName;
                WebsitesClient.EnableApplicationDiagnostic(Name, WebsiteDiagnosticOutput.StorageTable, properties);
            }
            else
            {
                throw new PSArgumentException();
            }

            if (PassThru.IsPresent)
            {
                WriteObject(true);
            }
        }
예제 #11
0
        public override void ExecuteCmdlet()
        {
            WebsitesClient = WebsitesClient ?? new WebsitesClient(CurrentSubscription, WriteDebug);
            string suffix = WebsitesClient.GetWebsiteDnsSuffix();

            if (Git && GitHub)
            {
                throw new Exception("Please run the command with either -Git or -GitHub options. Not both.");
            }

            if (Git)
            {
                PublishingUsername = GetPublishingUser();
            }

            WebSpaces webspaceList = null;
            InvokeInOperationContext(() => { webspaceList = RetryCall(s => Channel.GetWebSpaces(s)); });
            if (Git && webspaceList.Count == 0)
            {
                // If location is still empty or null, give portal instructions.
                string error = string.Format(Resources.PortalInstructions, Name);
                throw new Exception(!Git
                    ? error
                    : string.Format("{0}\n{1}", error, Resources.PortalInstructionsGit));
            }

            WebSpace webspace = null;
            if (string.IsNullOrEmpty(Location))
            {
                // If no location was provided as a parameter, try to default it
                webspace = webspaceList.FirstOrDefault();
                if (webspace == null)
                {
                    string defaultLocation;

                    try
                    {
                        defaultLocation = WebsitesClient.GetDefaultLocation();
                    }
                    catch
                    {
                        throw new Exception(Resources.CreateWebsiteFailed);
                    }

                    webspace = new WebSpace
                    {
                        Name = Regex.Replace(defaultLocation.ToLower(), " ", "") + "webspace",
                        GeoRegion = defaultLocation,
                        Subscription = CurrentSubscription.SubscriptionId,
                        Plan = "VirtualDedicatedPlan"
                    };
                }
            }
            else
            {
                // Find the webspace that corresponds to the georegion
                webspace = webspaceList.FirstOrDefault(w => w.GeoRegion.Equals(Location, StringComparison.OrdinalIgnoreCase));
                if (webspace == null)
                {
                    // If no webspace corresponding to the georegion was found, attempt to create it
                    webspace = new WebSpace
                    {
                        Name = Regex.Replace(Location.ToLower(), " ", "") + "webspace",
                        GeoRegion = Location,
                        Subscription = CurrentSubscription.SubscriptionId,
                        Plan = "VirtualDedicatedPlan"
                    };
                }
            }

            SiteWithWebSpace website = new SiteWithWebSpace
            {
                Name = Name,
                HostNames = new[] { string.Format("{0}.{1}", Name, suffix) },
                WebSpace = webspace.Name,
                WebSpaceToCreate = webspace
            };

            if (!string.IsNullOrEmpty(Hostname))
            {
                List<string> newHostNames = new List<string>(website.HostNames);
                newHostNames.Add(Hostname);
                website.HostNames = newHostNames.ToArray();
            }

            try
            {
                CreateSite(webspace, website);
            }
            catch (EndpointNotFoundException)
            {
                // Create webspace with VirtualPlan failed, try with subscription id
                webspace.Plan = CurrentSubscription.SubscriptionId;
                CreateSite(webspace, website);
            }

            if (Git || GitHub)
            {
                try
                {
                    Directory.SetCurrentDirectory(SessionState.Path.CurrentFileSystemLocation.Path);
                }
                catch (Exception)
                {
                    // Do nothing if session state is not present
                }

                LinkedRevisionControl linkedRevisionControl = null;
                if (Git)
                {
                    linkedRevisionControl = new GitClient(this);
                }
                else if (GitHub)
                {
                    linkedRevisionControl = new GithubClient(this, GithubCredentials, GithubRepository);
                }

                linkedRevisionControl.Init();

                CopyIisNodeWhenServerJsPresent();
                UpdateLocalConfigWithSiteName(Name, webspace.Name);

                InitializeRemoteRepo(webspace.Name, Name);

                Site updatedWebsite = RetryCall(s => Channel.GetSite(s, webspace.Name, Name, "repositoryuri,publishingpassword,publishingusername"));
                if (Git)
                {
                    AddRemoteToLocalGitRepo(updatedWebsite);
                }

                linkedRevisionControl.Deploy(updatedWebsite);
                linkedRevisionControl.Dispose();
            }
        }
예제 #12
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            WebsitesClient = WebsitesClient ?? new WebsitesClient(CurrentSubscription, WriteDebug);
            string suffix = WebsitesClient.GetWebsiteDnsSuffix();

            Site website = null;
            SiteConfig websiteConfig = null;

            InvokeInOperationContext(() =>
            {
                try
                {
                    website = RetryCall(s => Channel.GetSite(s, Name, null));
                    websiteConfig = RetryCall(s => Channel.GetSiteConfig(s, website.WebSpace, Name));
                }
                catch (CommunicationException ex)
                {
                    WriteErrorDetails(ex);
                }
            });

            if (website == null)
            {
                throw new Exception(string.Format(Resources.InvalidWebsite, Name));
            }

            bool changes = false;
            SiteWithConfig websiteConfigUpdate = new SiteWithConfig(website, websiteConfig);
            if (SiteWithConfig != null)
            {
                websiteConfigUpdate = SiteWithConfig;
                changes = true;
            }

            if (NumberOfWorkers != null && !NumberOfWorkers.Equals(websiteConfig.NumberOfWorkers))
            {
                changes = true;
                websiteConfigUpdate.NumberOfWorkers = NumberOfWorkers;
            }

            if (DefaultDocuments != null && !DefaultDocuments.Equals(websiteConfig.DefaultDocuments))
            {
                changes = true;
                websiteConfigUpdate.DefaultDocuments = DefaultDocuments;
            }

            if (NetFrameworkVersion != null && !NetFrameworkVersion.Equals(websiteConfig.NetFrameworkVersion))
            {
                changes = true;
                websiteConfigUpdate.NetFrameworkVersion = NetFrameworkVersion;
            }

            if (PhpVersion != null && !PhpVersion.Equals(websiteConfig.PhpVersion))
            {
                changes = true;
                websiteConfigUpdate.PhpVersion = PhpVersion;
            }

            if (RequestTracingEnabled != null && !RequestTracingEnabled.Equals(websiteConfig.RequestTracingEnabled))
            {
                changes = true;
                websiteConfigUpdate.RequestTracingEnabled = RequestTracingEnabled;
            }

            if (HttpLoggingEnabled != null && !HttpLoggingEnabled.Equals(websiteConfig.HttpLoggingEnabled))
            {
                changes = true;
                websiteConfigUpdate.HttpLoggingEnabled = HttpLoggingEnabled;
            }

            if (DetailedErrorLoggingEnabled != null && !DetailedErrorLoggingEnabled.Equals(websiteConfig.DetailedErrorLoggingEnabled))
            {
                changes = true;
                websiteConfigUpdate.DetailedErrorLoggingEnabled = DetailedErrorLoggingEnabled;
            }

            if (AppSettings != null && !AppSettings.Equals(websiteConfig.AppSettings))
            {
                changes = true;
                websiteConfigUpdate.AppSettings = AppSettings;
            }

            if (Metadata != null && !Metadata.Equals(websiteConfig.Metadata))
            {
                changes = true;
                websiteConfigUpdate.Metadata = Metadata;
            }

            if (ConnectionStrings != null && !ConnectionStrings.Equals(websiteConfig.ConnectionStrings))
            {
                changes = true;
                websiteConfigUpdate.ConnectionStrings = ConnectionStrings;
            }

            if (HandlerMappings != null && !HandlerMappings.Equals(websiteConfig.HandlerMappings))
            {
                changes = true;
                websiteConfigUpdate.HandlerMappings = HandlerMappings;
            }

            bool siteChanges = false;
            Site websiteUpdate = new Site
            {
                Name = Name,
                HostNames = new[] { string.Format("{0}.{1}", Name, suffix) }
            };
            if (HostNames != null)
            {
                siteChanges = true;
                List<string> newHostNames = new List<string> { string.Format("{0}.{1}", Name, suffix) };
                newHostNames.AddRange(HostNames);
                websiteUpdate.HostNames = newHostNames.ToArray();
            }

            if (changes)
            {
                InvokeInOperationContext(() =>
                {
                    try
                    {
                        RetryCall(s => Channel.UpdateSiteConfig(s, website.WebSpace, Name, websiteConfigUpdate.GetSiteConfig()));
                    }
                    catch (CommunicationException ex)
                    {
                        WriteErrorDetails(ex);
                    }
                });
            }

            if (siteChanges)
            {
                InvokeInOperationContext(() =>
                {
                    try
                    {
                        RetryCall(s => Channel.UpdateSite(s, website.WebSpace, Name, websiteUpdate));
                    }
                    catch (CommunicationException ex)
                    {
                        WriteErrorDetails(ex);
                    }
                });
            }

            if (PassThru.IsPresent)
            {
                WriteObject(true);
            }
        }
예제 #13
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            WebsiteClient = WebsiteClient ?? new WebsitesClient(CurrentSubscription, WriteDebug);

            if (Tail.IsPresent)
            {
                foreach (string logLine in WebsiteClient.StartLogStreaming(
                    Name,
                    Path,
                    Message,
                    StopCondition,
                    WaitInterval))
                {
                    WriteObject(logLine);
                }
            }
            else if (ListPath.IsPresent)
            {
                WriteObject(WebsiteClient.ListLogPaths(Name).Select<LogPath, string>(i => i.Name), true);
            }
        }
        public override void ExecuteCmdlet()
        {
            WebsitesClient = WebsitesClient ?? new WebsitesClient(CurrentSubscription, WriteDebug);

            switch (Type)
            {
                case WebsiteDiagnosticType.Site:
                    WebsitesClient.EnableSiteDiagnostic(
                        Name,
                        WebServerLogging,
                        DetailedErrorMessages,
                        FailedRequestTracing);
                    break;
                case WebsiteDiagnosticType.Application:
                    Dictionary<DiagnosticProperties, object> properties = new Dictionary<DiagnosticProperties, object>();
                    properties[DiagnosticProperties.LogLevel] = LogLevel;

                    if (Output == WebsiteDiagnosticOutput.StorageTable)
                    {
                        string storageName = string.IsNullOrEmpty(StorageAccountName) ?
                            CurrentSubscription.CurrentStorageAccount : StorageAccountName;
                        properties[DiagnosticProperties.StorageAccountName] = storageName;
                    }

                    WebsitesClient.EnableApplicationDiagnostic(Name, Output, properties);
                    break;
                default:
                    throw new PSArgumentException();
            }

            if (PassThru.IsPresent)
            {
                WriteObject(true);
            }
        }
        public override void ExecuteCmdlet()
        {
            WebsitesClient = WebsitesClient ?? new WebsitesClient(CurrentSubscription, WriteDebug);

            switch (Type)
            {
                case WebsiteDiagnosticType.Site:
                    WebsitesClient.DisableSiteDiagnostic(
                        Name,
                        WebServerLogging,
                        DetailedErrorMessages,
                        FailedRequestTracing);
                    break;
                case WebsiteDiagnosticType.Application:
                    WebsitesClient.DisableApplicationDiagnostic(Name, Output);
                    break;
                default:
                    throw new PSArgumentException();
            }

            if (PassThru.IsPresent)
            {
                WriteObject(true);
            }
        }
 public override void ExecuteCmdlet()
 {
     WebsitesClient = WebsitesClient ?? new WebsitesClient(CurrentSubscription, WriteDebug);
     WriteObject(WebsitesClient.ListAvailableLocations(), true);
 }