예제 #1
0
        private void LoadLocalWebSites()
        {
            WebAdministration.UnloadServerManager();

            if (!WebAdministration.CanAdminister)
            {
                return;
            }

            try
            {
                var serverManager = WebAdministration.ServerManager;
                if (serverManager == null)
                {
                    return;
                }

                foreach (var s in serverManager.Sites)
                {
                    var comboBoxItem = new ComboBoxItem
                    {
                        Content = s.Name,
                        Tag     = s
                    };

                    Server.Items.Add(comboBoxItem);
                }
            }
            catch (Exception ex)
            {
                AppHost.Output.LogException(ex);
            }
        }
예제 #2
0
        public static bool RefreshLocalConnections()
        {
            WebAdministration.UnloadServerManager();

            dynamic serverManager;

            try
            {
                if (!WebAdministration.CanAdminister)
                {
                    return(false);
                }

                serverManager = WebAdministration.ServerManager;
                if (serverManager == null)
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }

            var modified = false;

            var folder = GetLocalConnectionFolder();

            AppHost.Files.CreateDirectory(folder);

            var localConnections = connections.Where(c => c.FileName.StartsWith(folder, StringComparison.InvariantCultureIgnoreCase)).ToList();

            try
            {
                foreach (var website in serverManager.Sites)
                {
                    string webRootPath;
                    string hostName;
                    try
                    {
                        hostName    = WebAdministration.GetWebSiteHostName(website);
                        webRootPath = WebAdministration.GetWebRootPath(website);
                    }
                    catch
                    {
                        continue;
                    }

                    var list = connections.Where(c => string.Compare(c.HostName, hostName, StringComparison.InvariantCultureIgnoreCase) == 0).ToList();

                    if (list.Any())
                    {
                        foreach (var connection in list)
                        {
                            if (localConnections.Contains(connection) && connection.WebRootPath != webRootPath)
                            {
                                connection.WebRootPath = webRootPath;
                                modified = true;
                            }

                            localConnections.Remove(connection);
                        }

                        continue;
                    }

                    var newConnection = new Connection
                    {
                        UserName            = "******",
                        Password            = "******",
                        HostName            = hostName,
                        DataServiceName     = "Hard Rock Web Service",
                        WebRootPath         = webRootPath,
                        Description         = hostName,
                        AutomaticallyUpdate = true
                    };

                    newConnection.FileName = GetFileName(newConnection, folder);

                    Add(newConnection);
                    modified = true;
                }
            }
            catch (Exception ex)
            {
                AppHost.Output.LogException(ex);
                return(false);
            }

            foreach (var connection in localConnections)
            {
                Remove(connection);
                modified = true;
            }

            if (modified)
            {
                Save();
            }

            return(modified);
        }