示例#1
0
        private void SetLocalSite([NotNull] object sender, [NotNull] SelectionChangedEventArgs e)
        {
            Debug.ArgumentNotNull(sender, nameof(sender));
            Debug.ArgumentNotNull(e, nameof(e));

            var text = Server.Text;

            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            string webRootPath;
            string hostName;

            try
            {
                dynamic website = null;
                foreach (var item in Server.Items.OfType <ComboBoxItem>())
                {
                    if (item.IsSelected)
                    {
                        website = item.Tag;
                        break;
                    }
                }

                if (website == null)
                {
                    return;
                }

                hostName    = WebAdministration.GetWebSiteHostName(website);
                webRootPath = WebAdministration.GetWebRootPath(website);
            }
            catch
            {
                return;
            }

            e.Handled = true;

            Dispatcher.BeginInvoke(new Action(delegate { Server.Text = hostName; }));
            WebRootPath.Text = webRootPath;
        }
示例#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);
        }