public static WebServicesClientProtocol ServerInit(WebServicesClientProtocol proxy, ServerProxyConfigurator cnfg, int serverId)
        {
            // get server info
            ServerInfo server = ServerController.GetServerByIdInternal(serverId);

            if (server == null)
                throw new Exception(String.Format("Server with ID {0} was not found", serverId));

            // set AD integration settings
            cnfg.ServerSettings.ADEnabled = server.ADEnabled;
            cnfg.ServerSettings.ADAuthenticationType = AuthenticationTypes.Secure;
            try
            {
                cnfg.ServerSettings.ADAuthenticationType = (AuthenticationTypes)Enum.Parse(typeof(AuthenticationTypes), server.ADAuthenticationType, true);
            }
            catch { /* ignore */ }
            cnfg.ServerSettings.ADRootDomain = server.ADRootDomain;
            cnfg.ServerSettings.ADUsername = server.ADUsername;
            cnfg.ServerSettings.ADPassword = server.ADPassword;

            // set timeout
            cnfg.Timeout = ConfigSettings.ServerRequestTimeout;

            return ServerInit(proxy, cnfg, server.ServerUrl, server.Password);
        }
        public static WebServicesClientProtocol Init(WebServicesClientProtocol proxy, int serviceId)
        {
            ServerProxyConfigurator cnfg = new ServerProxyConfigurator();

            // get service
            ServiceInfo service = ServerController.GetServiceInfo(serviceId);

            if (service == null)
                throw new Exception(String.Format("Service with ID {0} was not found", serviceId));

            // set service settings
            StringDictionary serviceSettings = ServerController.GetServiceSettings(serviceId);
            foreach (string key in serviceSettings.Keys)
                cnfg.ProviderSettings.Settings[key] = serviceSettings[key];

            // get provider
            ProviderInfo provider = ServerController.GetProvider(service.ProviderId);
            cnfg.ProviderSettings.ProviderGroupID = provider.GroupId;
            cnfg.ProviderSettings.ProviderCode = provider.ProviderName;
            cnfg.ProviderSettings.ProviderName = provider.DisplayName;
            cnfg.ProviderSettings.ProviderType = provider.ProviderType;

            // init service on the server level
            return ServerInit(proxy, cnfg, service.ServerId);
        }
        private static WebsitePanel.Providers.OS.OperatingSystem GetOS(int packageId)
        {
            var esServiceInfo = ServerController.GetServiceInfo(GetEnterpriseStorageServiceID(packageId));
            var esProviderInfo = ServerController.GetProvider(esServiceInfo.ProviderId);

            var osGroups = ServerController.GetResourceGroupByName(ResourceGroups.Os);
            var osProviders = ServerController.GetProvidersByGroupID(osGroups.GroupId);

            var regexResult = Regex.Match(esProviderInfo.ProviderType, "Windows([0-9]+)");

            if (regexResult.Success)
            {
                foreach (var osProvider in osProviders)
                {
                    BoolResult result = ServerController.IsInstalled(esServiceInfo.ServerId, osProvider.ProviderId);

                    if (result.IsSuccess && result.Value)
                    {
                        var os = new WebsitePanel.Providers.OS.OperatingSystem();
                        ServerProxyConfigurator cnfg = new ServerProxyConfigurator();

                        cnfg.ProviderSettings.ProviderGroupID = osProvider.GroupId;
                        cnfg.ProviderSettings.ProviderCode = osProvider.ProviderName;
                        cnfg.ProviderSettings.ProviderName = osProvider.DisplayName;
                        cnfg.ProviderSettings.ProviderType = osProvider.ProviderType;

                        ServiceProviderProxy.ServerInit(os, cnfg, esServiceInfo.ServerId);

                        return os;
                    }
                }
            }

            return null;
        }
        /// <summary>
        /// Get webserver (IIS) installed on server connected with packageId
        /// </summary>
        /// <param name="packageId">packageId parametr</param>
        /// <returns>Configurated webserver or null</returns>
        private static WebServer GetWebServer(int packageId)
        {
            try
            {
                var webGroup = ServerController.GetResourceGroupByName(ResourceGroups.Web);
                var webProviders = ServerController.GetProvidersByGroupID(webGroup.GroupId);
                var esServiceInfo = ServerController.GetServiceInfo(GetEnterpriseStorageServiceID(packageId));

                var serverId = esServiceInfo.ServerId;

                foreach (var webProvider in webProviders)
                {
                    BoolResult result = ServerController.IsInstalled(serverId, webProvider.ProviderId);

                    if (result.IsSuccess && result.Value)
                    {
                        WebServer web = new WebServer();
                        ServerProxyConfigurator cnfg = new ServerProxyConfigurator();

                        cnfg.ProviderSettings.ProviderGroupID = webProvider.GroupId;
                        cnfg.ProviderSettings.ProviderCode = webProvider.ProviderName;
                        cnfg.ProviderSettings.ProviderName = webProvider.DisplayName;
                        cnfg.ProviderSettings.ProviderType = webProvider.ProviderType;

                        //// set service settings
                        //StringDictionary serviceSettings = ServerController.GetServiceSettings(serviceId);
                        //foreach (string key in serviceSettings.Keys)
                        //    cnfg.ProviderSettings.Settings[key] = serviceSettings[key];
                        cnfg.ProviderSettings.Settings["aspnet40path"] = @"%WINDIR%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll";
                        cnfg.ProviderSettings.Settings["aspnet40x64path"] = @"%WINDIR%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll";

                        ServiceProviderProxy.ServerInit(web, cnfg, serverId);

                        return web;
                    }
                }
            }
            catch { /*something wrong*/ }

            return null;
        }
        private static WebServicesClientProtocol ServerInit(WebServicesClientProtocol proxy,
            ServerProxyConfigurator cnfg, string serverUrl, string serverPassword)
        {
            // set URL & password
            cnfg.ServerUrl = serverUrl;
            cnfg.ServerPassword = serverPassword;

            // configure proxy!
            cnfg.Configure(proxy);

            return proxy;
        }