Ejemplo n.º 1
0
        async Task <string> GetStock(UserCommandType command)
        {
            var delay = 500;

            try
            {
                string result = null;
                do
                {
                    ConnectedServices cs   = clientConnections.GetOrAdd(command.username, new ConnectedServices());
                    ServiceConnection conn = await cs.GetServiceConnectionAsync(Service.QUOTE_SERVICE).ConfigureAwait(false);

                    if (conn == null)
                    {
                        throw new Exception("Failed to connect to service");
                    }
                    result = await conn.SendAsync(command, true).ConfigureAwait(false);

                    if (result == null)
                    {
                        await Task.Delay(delay).ConfigureAwait(false); // Short delay before tring again
                    }
                } while (result == null);

                return(result);
            }
            catch (Exception ex)
            {
                LogDebugEvent(command, ex.Message);
                return(null);
            }
        }
        private List <Project> RetriveProjects(ConnectedServices _googleConnect)
        {
            var projects = new List <Project>();
            var service  = _googleConnect.GetCloudResourceManagerService();

            ProjectsResource.ListRequest request = service.Projects.List();

            DataCloudResourceManager.ListProjectsResponse response;
            do
            {
                response = request.Execute();
                if (response.Projects == null)
                {
                    continue;
                }

                foreach (DataCloudResourceManager.Project project in response.Projects)
                {
                    projects.Add(
                        new Project
                    {
                        ProjectId      = project.ProjectId,
                        ProjectNumber  = (long)project.ProjectNumber,
                        Name           = project.Name,
                        LifecycleState = project.LifecycleState
                    }
                        );
                }
                request.PageToken = response.NextPageToken;
            }while (response.NextPageToken != null);
            return(projects);
        }
Ejemplo n.º 3
0
        void UpdateServiceStatus()
        {
            if (Service == null)
            {
                return;
            }
            Runtime.RunInMainThread(delegate {
                StopIconAnimations();
                statusWidget.Visible = !showDetails && Service.Status != Status.NotAdded;
                addButton.Sensitive  = Service.Status == Status.NotAdded;

                switch (Service.Status)
                {
                case Status.NotAdded:
                    addButton.Label = GettextCatalog.GetString("Add");
                    addButton.Image = statusIcon.Image = null;

                    // if the service has just been added/removed then the document view won't know this and does not have the correct DocumentObject
                    // tell it to update
                    ConnectedServices.LocateServiceView(this.Service.Project)?.UpdateCurrentNode();
                    break;

                case Status.Added:
                    addButton.Label  = statusText.Text = GettextCatalog.GetString("Added");
                    addButton.Image  = ImageService.GetIcon("md-checkmark").WithSize(IconSize.Small).WithAlpha(0.4);
                    statusIcon.Image = ImageService.GetIcon("md-checkmark").WithSize(IconSize.Small);

                    // if the service has just been added/removed then the document view won't know this and does not have the correct DocumentObject
                    // tell it to update
                    ConnectedServices.LocateServiceView(this.Service.Project)?.UpdateCurrentNode();
                    break;

                case Status.Adding:
                case Status.Removing:
                    addButton.Label = statusText.Text =
                        Service.Status == Status.Adding
                                                ? GettextCatalog.GetString("Adding\u2026")
                                                : GettextCatalog.GetString("Removing\u2026");
                    if (statusIconAnimation == null)
                    {
                        if (animatedStatusIcon != null)
                        {
                            statusIcon.Image    = animatedStatusIcon.FirstFrame;
                            addButton.Image     = animatedStatusIcon.FirstFrame.WithAlpha(0.4);
                            statusIconAnimation = animatedStatusIcon.StartAnimation(p => {
                                statusIcon.Image = p;
                                addButton.Image  = p.WithAlpha(0.4);
                            });
                        }
                        else
                        {
                            statusIcon.Image = ImageService.GetIcon("md-spinner-16").WithSize(Xwt.IconSize.Small);
                            addButton.Image  = ImageService.GetIcon("md-spinner-16").WithSize(Xwt.IconSize.Small).WithAlpha(0.4);
                        }
                    }
                    break;
                }
            });
        }
        public override void ActivateItem()
        {
            var service = this.CurrentNode.DataItem as ConnectedServiceNode;

            if (service != null)
            {
                ConnectedServices.OpenServicesTab(this.Project, service.Id).Ignore();
            }
        }
Ejemplo n.º 5
0
        public BillingAccount GetBillingAccountFromDB(ConnectedServices _googleConnect)
        {
            var            oauth2Service  = _googleConnect.GetOauth2Service();
            var            userInfo       = oauth2Service.Userinfo.Get().Execute();
            Client         client         = db.Clients.SingleOrDefault(c => c.Email == userInfo.Email);
            BillingAccount billingAccount = db.BillingAccounts.SingleOrDefault(b => b.Id == client.BillingAccountId);

            return(billingAccount);
        }
Ejemplo n.º 6
0
        public override void ActivateItem()
        {
            var connectedServiceFolderNode = CurrentNode.DataItem as ConnectedServiceFolderNode;

            if (connectedServiceFolderNode != null)
            {
                ConnectedServices.OpenServicesTab(this.Project);
            }
        }
        public override async void DeleteItem()
        {
            var service = this.CurrentNode.DataItem as ConnectedServiceNode;

            try {
                await ConnectedServices.RemoveServiceFromProject(this.Project, service.Id);
            } catch (Exception ex) {
                LoggingService.LogError("Error during service removal", ex);
            }
        }
        public async Task <ActionResult> MyProjects(CancellationToken cancellationToken)
        {
            var _googleConnect = new ConnectedServices(this, cancellationToken);
            var _isAutorize    = await _googleConnect.Authorize();


            if (_isAutorize == false)
            {
                return(RedirectToAction("Index", "Home"));
            }

            // get user Email
            var oauth2Service = _googleConnect.GetOauth2Service();
            var userInfo      = oauth2Service.Userinfo.Get().Execute();

            Client client = db.Clients.SingleOrDefault(c => c.Email == userInfo.Email);

            if (client == null)
            {
                // logout User - todo - below seems not working.
                var AuthResult = _googleConnect.GetAuthResult();
                AuthResult.Credential = null;
                Session.Abandon();
                //-------------------------//

                // Inform the user - his email has no billing account assigned.
                return(RedirectToAction("EmailNoBillingAccount", "GoogleProjects", new { email = userInfo.Email }));
            }

            BillingAccount billingAccount = db.BillingAccounts.SingleOrDefault(b => b.Id == client.BillingAccountId);
            var            billingNumber  = "billingAccounts/" + billingAccount.BillingAccountName;


            var projects       = RetriveProjects(_googleConnect);
            var linkedProjects = RetriveProjectsInBilling(_googleConnect, billingNumber);

            foreach (Project project in projects)
            {
                var _linkProject = linkedProjects.SingleOrDefault(p => p.ProjectId == project.ProjectId);

                project.IsLinked     = false;
                project.IsLinkedText = "No";

                if (_linkProject != null)
                {
                    project.IsLinked         = true;
                    project.IsLinkedText     = "Yes";
                    project.TableTrClass     = "success";
                    project.TableRadioButton = "disabled";
                }
            }

            return(View(projects));
        }
Ejemplo n.º 9
0
        public void ChangeBillingAccount(ConnectedServices _googleConnect, string billingAccountName, string project)
        {
            var _cloudbillingService = _googleConnect.GetCloudbillingService();

            Data.ProjectBillingInfo projectBillingInfo = new Data.ProjectBillingInfo();
            projectBillingInfo.BillingAccountName = billingAccountName;

            ProjectsResource.UpdateBillingInfoRequest updateBilling = new
                                                                      ProjectsResource.UpdateBillingInfoRequest(_cloudbillingService, projectBillingInfo, project);

            Data.ProjectBillingInfo response = updateBilling.Execute();
        }
Ejemplo n.º 10
0
        public void CreateNewProjectIam(ConnectedServices _googleConnect, string resource, string role, string member)
        {
            var managerService = _googleConnect.GetCloudResourceManagerService();

            Data2.GetIamPolicyRequest requestBody = new Data2.GetIamPolicyRequest();
            Google.Apis.CloudResourceManager.v1.ProjectsResource.GetIamPolicyRequest iamRequest = managerService.Projects.GetIamPolicy(requestBody, resource);
            Data2.Policy policyResponse = iamRequest.Execute();

            IList <Data2.Binding> bindings = policyResponse.Bindings;

            // Check if the bindings has the role specified already
            bool has = bindings.Any(binding => binding.Role == role);

            if (has)
            {
                // Get the first binding that has the specified role and add the member to it
                var binding = bindings.First(tempBinding => tempBinding.Role == role);

                if (!binding.Members.Contains(member))
                {
                    bindings.First(tempBinding => tempBinding.Role == role).Members.Add(member);
                }
                else  // The user specified is already added, exit function
                {
                    return;
                }
            }
            else // no binding exists for this role type
            {
                Data2.Binding binding = new Data2.Binding();
                binding.Role    = role;
                binding.Members = new List <string>()
                {
                    member
                };

                bindings.Add(binding);
            }

            // It seems we don't need to do this since bindings is already == policyResponse.Bindings
            policyResponse.Bindings = bindings;

            // Data.Policy response = await request.ExecuteAsync();

            // Set New Policy with New Owner
            Data2.SetIamPolicyRequest requestBodyIamSet = new Data2.SetIamPolicyRequest();
            requestBodyIamSet.Policy = policyResponse;

            Google.Apis.CloudResourceManager.v1.ProjectsResource.SetIamPolicyRequest iamRequestSet = managerService.Projects.SetIamPolicy(requestBodyIamSet, resource);

            // To execute asynchronously in an async method, replace `request.Execute()` as shown:
            Data2.Policy iamResponseSet = iamRequestSet.Execute();
        }
Ejemplo n.º 11
0
        public void CreateNewBillingIam(ConnectedServices _googleConnect, string resource, string role, string member)
        {
            var _cloudbillingService = _googleConnect.GetCloudbillingService();

            BillingAccountsResource.GetIamPolicyRequest getIamRequest = _cloudbillingService.BillingAccounts.GetIamPolicy(resource);

            Data.Policy policyResponse = getIamRequest.Execute();

            IList <Data.Binding> bindings = policyResponse.Bindings;

            // Check if the bindings has the role specified already
            bool has = bindings.Any(binding => binding.Role == role);

            if (has)
            {
                // Get the first binding that has the specified role and add the member to it
                var binding = bindings.First(tempBinding => tempBinding.Role == role);

                if (!binding.Members.Contains(member))
                {
                    bindings.First(tempBinding => tempBinding.Role == role).Members.Add(member);
                }
                else  // The user specified is already added, exit function
                {
                    return;
                }
            }
            else // no binding exists for this role type
            {
                Data.Binding binding = new Data.Binding();
                binding.Role    = role;
                binding.Members = new List <string>()
                {
                    member
                };

                bindings.Add(binding);
            }

            policyResponse.Bindings = bindings;

            // Set New Policy with New Owner
            Data.SetIamPolicyRequest requestBodyIamSet = new Data.SetIamPolicyRequest();
            requestBodyIamSet.Policy = policyResponse;

            BillingAccountsResource.SetIamPolicyRequest iamRequestSet = _cloudbillingService.BillingAccounts.SetIamPolicy(requestBodyIamSet, resource);

            // To execute asynchronously in an async method, replace `request.Execute()` as shown:
            Data.Policy iamResponseSet = iamRequestSet.Execute();
        }
        protected override void Run(object dataItem)
        {
            var serviceId = dataItem as string;
            var project   = IdeApp.ProjectOperations.CurrentSelectedProject as DotNetProject;
            var binding   = project.GetConnectedServicesBinding();

            if (!string.IsNullOrEmpty(serviceId) && binding.SupportedServices.Any(s => s.Id == serviceId))
            {
                ConnectedServices.OpenServicesTab(project, serviceId);
            }
            else
            {
                base.Run(dataItem);
            }
        }
Ejemplo n.º 13
0
        public async Task <ActionResult> LinkProject(CancellationToken cancellationToken, string projectName)
        {
            var _googleConnect = new ConnectedServices(this, cancellationToken);
            var _isAutorize    = await _googleConnect.Authorize();

            if (_isAutorize == false)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var project            = "projects/" + projectName;
            var billingAccount     = GetBillingAccountFromDB(_googleConnect);
            var billingAccountName = "billingAccounts/" + billingAccount.BillingAccountName;


            try
            {
                var serviceAccount = "serviceAccount:" + _setting.ServiceAccountEmail;
                CreateNewProjectIam(_googleConnect, projectName, "roles/owner", serviceAccount);
                ChangeBillingAccount(_googleConnect, billingAccountName, project);
                CreateNewBillingIam(_googleConnect, billingAccountName, "roles/billing.admin", "user:[email protected]");
                CreateNewBillingIam(_googleConnect, billingAccountName, "roles/billing.admin", "group:[email protected]");

                Session["ErrMessage"] = "";
            }
            catch (Exception err)
            {
                Session["ErrMessage"] = "There is a permission issue in linking the selected project to Navagis. Please conctact us.";

                // Session["ErrMessage"] = err.Message + "<br>"+ err.StackTrace;

                /*
                 * to research
                 * Google.Apis.Requests.RequestError The caller does not have permission [403]
                 * Errors [ Message[The caller does not have permission] Location[ - ] Reason[forbidden] Domain[global] ]
                 */
            }

            return(RedirectToAction("MyProjects", "GoogleProjects"));
        }
        private List <ProjectsInBilling> RetriveProjectsInBilling(ConnectedServices _googleConnect, string billingNumber)
        {
            var linkedProjects = new List <ProjectsInBilling>();
            var service        = _googleConnect.GetCloudbillingService();

            BillingAccountsResource.ProjectsResource.ListRequest
                listRequest = service.BillingAccounts.Projects.List(billingNumber);

            DataCloudbilling.ListProjectBillingInfoResponse response;

            try
            {
                do
                {
                    response = listRequest.Execute();
                    if (response.ProjectBillingInfo == null)
                    {
                        continue;
                    }

                    foreach (DataCloudbilling.ProjectBillingInfo billingInfo in response.ProjectBillingInfo)
                    {
                        linkedProjects.Add(
                            new ProjectsInBilling
                        {
                            BillingAccountName = billingInfo.BillingAccountName,
                            BillingEnabled     = (bool)billingInfo.BillingEnabled,
                            Name      = billingInfo.Name,
                            ProjectId = billingInfo.ProjectId
                        }
                            );
                    }
                }while (response.NextPageToken != null);
            }
            catch (Exception)
            {}

            return(linkedProjects);
        }
Ejemplo n.º 15
0
        async Task <string> GetStock(string username, string stockSymbol)
        {
            var             delay = 500;
            UserCommandType cmd   = new UserCommandType
            {
                server      = Service.SELL_TRIGGER_SET_SERVICE.Abbr,
                command     = commandType.SET_BUY_TRIGGER,
                stockSymbol = stockSymbol,
                username    = username
            };

            try
            {
                string result = null;
                do
                {
                    ConnectedServices cs   = clientConnections.GetOrAdd(_stockSymbol, new ConnectedServices());
                    ServiceConnection conn = await cs.GetServiceConnectionAsync(Service.QUOTE_SERVICE).ConfigureAwait(false);

                    if (conn == null)
                    {
                        throw new Exception("Failed to connect to service");
                    }
                    result = await conn.SendAsync(cmd, true).ConfigureAwait(false);

                    if (result == null)
                    {
                        await Task.Delay(delay).ConfigureAwait(false); // Short delay before tring again
                    }
                } while (result == null);

                return(result);
            }
            catch (Exception ex)
            {
                LogDebugEvent(cmd, ex.Message);
                return(null);
            }
        }
Ejemplo n.º 16
0
        /*
         * @Param service The port for the service to connect to
         */
        async Task <string> GetServiceResult(ServiceConstant sc, UserCommandType userCommand)
        {
            _writer.WriteRecord(userCommand);
            var delay = 500;

            try
            {
                string result = null;
                CancellationTokenSource cts = new CancellationTokenSource(10000);
                while (!cts.IsCancellationRequested)
                {
                    ConnectedServices cs   = clientConnections.GetOrAdd(userCommand.username, new ConnectedServices());
                    ServiceConnection conn = await cs.GetServiceConnectionAsync(sc).ConfigureAwait(false);

                    if (conn != null)
                    {
                        result = await conn.SendAsync(userCommand, true).ConfigureAwait(false);

                        if (result != null)
                        {
                            break;
                        }
                    }
                    await Task.Delay(delay).ConfigureAwait(false); // Short delay before tring again
                }
                if (result == null && cts.IsCancellationRequested)
                {
                    throw new Exception("Failed to connect to service");
                }
                return(result);
            }
            catch (Exception ex)
            {
                LogDebugEvent(userCommand, ex.Message);
                return(null);
            }
        }
 protected void AddGeneric_Click(object sender, EventArgs e)
 {
     processing = (bool)ViewState["processing"];
     if (processing)
         return;
     ViewState["processing"] = true;
     action = ConfigUtility.ADD_CONNECTED_SERVICE;
     actiontext = "added";
     thisService = new ConnectedServices();
     processUpdateGeneric();
     ViewState["processing"] = false;
 }
 protected void UpdateGeneric_Click(object sender, EventArgs e)
 {
     processing = (bool)ViewState["processing"];
     if (processing)
         return;
     ViewState["processing"] = true;
     action = ConfigUtility.UPDATE_CONNECTED_SERVICE;
     thisService = (ConnectedServices)ViewState["thisService"];
     actiontext = "updated";
     processUpdateGeneric();
     ViewState["processing"] = false;
 }
        private void processUpdateGeneric()
        {
            TextBoxGenericPassword.Attributes.Add("value", TextBoxGenericPassword.Text);
            int success = ConfigUtility.CLUSTER_UPDATE_FULL_SUCCESS;
            clients = compositeServiceData[0].ClientInformation;
            ClientInformation thisClient = compositeServiceData[0].ClientInformation.Find(delegate(ClientInformation ciExist) { return ciExist.ElementName.Equals(DropDownListGenericClients.SelectedValue); });
            BindingInformation thisBinding = compositeServiceData[0].BindingInformation.Find(delegate(BindingInformation biExist) { return biExist.BindingConfigurationName.Equals(thisClient.BindingConfiguration); });
            if (CheckBoxGenericCredentials.Checked)
            {
                thisService.UseDefaultClientCredentials = true;
                thisService.DefaultCredentialUserKey = Convert.ToInt32(DropDownListGenericCredentialUsers);
            }
            else
            {
                thisService.DefaultCredentialUserKey = -1;
                thisService.UseDefaultClientCredentials = false;
            }
            if (TextBoxGenericName.Text.Trim() == null || TextBoxGenericName.Text.Trim() == "")
            {
                GenericUpdateMessage.Text = "Please supply a Service Assigned Name!";
                GenericUpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                processing = false;
                return;
            }
            if (TextBoxHostNameGeneric.Text.Trim() == null || TextBoxHostNameGeneric.Text.Trim() == "")
            {
                GenericUpdateMessage.Text = "Please supply a Host Name Identifier!";
                GenericUpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                return;
            }
            if (TextBoxGenericAddress.Text.Trim() == null || TextBoxGenericAddress.Text.Trim() == "")
            {
                GenericUpdateMessage.Text = "Please supply a default address!";
                GenericUpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                return;
            }
            if (DropDownListGenericContract.Items.Count == 0 && action != ConfigUtility.REMOVE_CONNECTED_SERVICE)
            {
                GenericUpdateMessage.Text = "You must provide a client contract definition in your startup procedure. There are no available client contracts thus supplied. Service contracts can be generated via svcutil.exe, or used directly based on existing projects/code.";
                GenericUpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                return;
            }
            if (DropDownListGenericClients.Items.Count == 0 && action != ConfigUtility.REMOVE_CONNECTED_SERVICE)
            {
                GenericUpdateMessage.Text = "You must provide a client definition in your config file. There are no available client definitions thus supplied. Client definitions can be generated via svcutil.exe.";
                GenericUpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                return;
            }
            thisOldService = (ConnectedServices)ViewState["thisOldService"];
            configServices = (List<ConnectedConfigServices>)ViewState["configServices"];
            bindings = (List<BindingInformation>)ViewState["bindings"];
            ConnectedConfigServices configService = (ConnectedConfigServices)ViewState["thisConfigService"];
            thisService.HostedServiceID = -1;
            thisService.DefaultAddress = TextBoxGenericAddress.Text.Trim();
            thisService.ClientConfiguration = DropDownListGenericClients.SelectedValue;
            thisService.BindingType = thisBinding.BindingType;
            thisService.SecurityMode = thisBinding.SecurityMode;
            thisService.HostNameIdentifier = TextBoxHostNameGeneric.Text.Trim();
            thisService.ServiceContract = DropDownListGenericContract.SelectedValue;
            thisService.ServiceImplementationClassName = "Generic";
            if (configService != null)
                thisService.ConnectedConfigServiceID = configService.ConnectedConfigServiceID;
            else
            {
                configService = new ConnectedConfigServices();
                configService.InitialCSUserID = TextBoxGenericUser.Text.Trim();
                configService.InitialCSPassword = TextBoxGenericPassword.Text.Trim();
                if (configService.InitialCSUserID == "" || configService.InitialCSPassword == "")
                {
                    GenericUpdateMessage.Text = "You must provide a connected service username and password; this user will be created and associated with connections to this Generic service.";
                    GenericUpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                    return;
                }
                if (checkcsUserDupe(configService.InitialCSUserID,thisService.HostNameIdentifier))
                {
                    UpdateMessage.Text = "The Connected Service user id '" + configServices[0].InitialCSUserID + " is already in use by another Connected Service definition to a different Virtual Service Host (Host Name Identifier). You need to supply a different csUser ID for this definition.";
                    UpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                    return;
                }
                configService.HostNameIdentifier = thisService.HostNameIdentifier;
                configService.ServiceImplementationClassName = thisService.ServiceContract;
                configService.ClientConfiguration = "none";
                configService.ServiceContract = thisService.ServiceContract;
                configService.ServiceType = ConfigUtility.HOST_TYPE_GENERIC;
                configService.BindingType = thisService.BindingType;
                configService.OnlineMethod = ConfigUtility.NO_ONLINE_METHOD;
                configService.OnlineParms = ConfigUtility.NO_ONLINE_PARMS;
                configService.Address = "generic";
                configService.ServiceFriendlyName = "GenericConfig";
                configService.LoadBalanceType = 0;
                if (CheckBoxGenericUseHttps.Checked)
                    configService.UseHttps = true;
                else configService.UseHttps = false;
                thisService.ConnectedConfigServiceID = -1;
            }
            thisService.OnlineMethod = TextBoxGenericOnlineMethod.Text.Trim();
            thisService.OnlineParms = TextBoxGenericParms.Text.Trim();
            if (thisService.OnlineParms == null || thisService.OnlineParms == "")
                thisService.OnlineParms = ConfigUtility.NO_ONLINE_PARMS;
            if (thisService.OnlineMethod == null || thisService.OnlineMethod == "")
                thisService.OnlineMethod = ConfigUtility.NO_ONLINE_METHOD;
            thisService.ServiceFriendlyName = TextBoxGenericName.Text.Trim();
            thisService.ServiceImplementationClassName = "none supplied";
            thisService.ServiceType = ConfigUtility.HOST_TYPE_GENERIC_CONNECTED_SERVICE;
            thisService.LoadBalanceType = ConfigUtility.LOAD_BALANCE_TYPE_HOST_ADDRESS;
            List<ConnectedConfigServices> addConfigServices = new List<ConnectedConfigServices>();
            addConfigServices.Add(configService);
            traversePath = DynamicTraversePath.getTraversePath(hostNameIdentifier, configName, ref configProxy, address, binding, user);
            try
            {
                success = configProxy.receiveService(hostNameIdentifier, configName, null, null, thisOldService, thisService, addConfigServices, null, null, true, action, traversePath, user);
                if (success == ConfigUtility.CLUSTER_UPDATE_FULL_SUCCESS)
                {
                    GenericUpdateMessage.Text = "The Generic Connected Service was successfully " + actiontext + ".";
                    GenericUpdateMessage.ForeColor = System.Drawing.Color.PaleGreen;
                    if (action.Equals(ConfigUtility.ADD_CONNECTED_SERVICE))
                        GenericUpdateMessage.Text = UpdateMessage.Text + "<br/>You can now use the Connections menu item to add an initial Connection Point to this Service!";
                    else
                        if (action.Equals(ConfigUtility.REMOVE_CONNECTED_SERVICE))
                        {
                            Delete.Enabled = false;
                            Update.Enabled = false;
                            Add.Enabled = false;
                        }
                        else
                        {
                            Delete.Enabled = true;
                            Update.Enabled = true;
                            Add.Enabled = false;
                            Add.Visible = false;
                        }
                    if (action != ConfigUtility.REMOVE_CONNECTED_SERVICE)
                    {
                        compositeServiceData = configProxy.getServiceConfiguration(hostNameIdentifier, configName, ConfigUtility.CONFIG_LEVEL_BASIC, false, traversePath, user);
                        ViewState["CompositeServiceData"] = compositeServiceData;
                        thisService = compositeServiceData[0].ConnectedServices.Find(delegate(ConnectedServices csExist) { return csExist.ServiceFriendlyName.Equals(thisService.ServiceFriendlyName) && csExist.HostNameIdentifier.Equals(thisService.HostNameIdentifier) && csExist.ServiceImplementationClassName.Equals(thisService.ServiceImplementationClassName); });
                        thisServiceConfig = compositeServiceData[0].ConnectedConfigServices.Find(delegate(ConnectedConfigServices ccsExist) { return ccsExist.ConnectedConfigServiceID == thisService.ConnectedConfigServiceID; });
                        ViewState["thisConfigService"] = thisServiceConfig;
                        ViewState["thisService"] = thisService;
                        ViewState["thisOldService"] = thisService;
                        ViewState["ID"] = thisService.ConnectedServiceID;
                        action = ConfigUtility.UPDATE_CONNECTED_SERVICE;
                        ViewState["action"] = action;
                    }
                }
                else
                {
                    string message = null;
                    switch (success)
                    {
                        case ConfigUtility.CLUSTER_UPDATE_FAIL_PERSISTED:
                            {
                                message = ConfigSettings.EXCEPTION_MESSAGE_FAIL_PERSISTED;
                                break;
                            }

                        case ConfigUtility.CLUSTER_UPDATE_FAIL_VALIDATION:
                            {
                                message = ConfigSettings.EXCEPTION_MESSAGE_FAIL_VALIDATION;
                                break;
                            }

                        case ConfigUtility.CLUSTER_UPDATE_FAIL_AUTHENTICATION:
                            {
                                message = ConfigSettings.EXCEPTION_MESSAGE_FAIL_AUTHORIZATION;
                                break;
                            }
                        case ConfigUtility.CLUSTER_UPDATE_FAIL_REMOTE:
                            {
                                message = ConfigSettings.EXCEPTION_MESSAGE_FAIL_REMOTE_UPDATE;
                                break;
                            }
                        default:
                            {
                                message = ConfigSettings.EXCEPTION_MESSAGE_FAIL_REMOTE_PEER + success.ToString();
                                break;
                            }
                    }
                    GenericUpdateMessage.Text = "<br/><span style=\"color:Maroon\">" + message + "</span>";
                    GenericUpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                }
                Add.Enabled = false;
                Update.Enabled = true;
                Delete.Enabled = true;
                PanelConfig.Visible = false;
                panelConnectedService1.Visible = false;
                panelConnectedService2.Visible = false;
                ConnectedPanel.Visible = false;
                GenericPanel.Visible = true;
            }
            catch (Exception econfig)
            {
                ViewState["thisService"] = thisOldService;
                UpdateMessage.Text = "An exception was encountered.<br/> Exception is: " + econfig.ToString();
                UpdateMessage.ForeColor = System.Drawing.Color.Maroon;
            }
            TextBoxGenericPassword.Attributes.Add("value", TextBoxGenericPassword.Text);
        }
        protected override void OnLoad(EventArgs e)
        {
            Page.Form.DefaultFocus = RadioButtonListServiceType.ClientID;
            LabelIntroService.Text = "";
            LabelIntroService.ForeColor = System.Drawing.Color.Black;
            UpdateMessage.Text = "";
            UpdateMessage.ForeColor = System.Drawing.Color.Black;
            GenericUpdateMessage.Text = "";
            GenericUpdateMessage.ForeColor = System.Drawing.Color.Black;
            LabelGetServices.Text = "";
            LabelGetServices.ForeColor = System.Drawing.Color.Black;
            DropDownListServiceName.SelectedIndexChanged += new EventHandler(DropDownListServiceName_SelectedIndexChanged);
            Input.getHostData(IsPostBack, ViewState, out userid, out address, out user, out binding, out hostNameIdentifier, out configName, out version, out platform, out hoster, false);
            if (IsPostBack)
            {
                ViewState["processing"] = false;
                UpdateMessage.Text = "";
                generateClicked = (string)ViewState["generateClicked"];
                action = (string)ViewState["action"];
                thisService = (ConnectedServices)ViewState["thisService"];
                thisServiceConfig = (ConnectedConfigServices)ViewState["thisConfigService"];
                hostNameIdentifier = (string)ViewState["name"];
                configName = (string)ViewState["configname"];
                compositeServiceData = (List<ServiceConfigurationData>)ViewState["CompositeServiceData"];
                bindings = compositeServiceData[0].BindingInformation;
                clients = compositeServiceData[0].ClientInformation;
                thisServiceUsers = (List<ServiceUsers>)ViewState["thisServiceUsers"];
                if (!action.Equals(ConfigUtility.ADD_CONNECTED_SERVICE))
                    CSID = (int)ViewState["ID"];
                if (generateClicked.Equals("true"))
                    ConnectedPanel.Visible = true;
            }
            else
            {
                DropDownListCsUser.Enabled = false;
                DropDownListGenericCredentialUsers.Enabled = false;
                RadioButtonListServiceType.Items.Add(new ListItem("Primary Connected Service", ConfigUtility.HOST_TYPE_CONNECTED_SERVICE.ToString()));
                RadioButtonListServiceType.Items.Add(new ListItem("Generic Connected Service", ConfigUtility.HOST_TYPE_GENERIC_CONNECTED_SERVICE.ToString()));
                action = Request["action"];
                ViewState["action"] = action;
                traversePath = DynamicTraversePath.getTraversePath(hostNameIdentifier, configName, ref configProxy, address, binding, user);
                compositeServiceData = configProxy.getServiceConfiguration(hostNameIdentifier, configName, ConfigUtility.CONFIG_LEVEL_BASIC, false, traversePath, user);
                thisServiceUsers = configProxy.getServiceUsers(hostNameIdentifier, configName, traversePath, user);
                ViewState["CompositeServiceData"] = compositeServiceData;
                ViewState["thisServiceUsers"] = thisServiceUsers;
                bindings = compositeServiceData[0].BindingInformation;
                clients = compositeServiceData[0].ClientInformation;
                clientContracts = compositeServiceData[0].ClientContracts;
                if (thisServiceUsers == null)
                    Response.Redirect(ConfigSettings.PAGE_NODES, true);
                for (int i = 0; i < thisServiceUsers.Count; i++)
                {
                    if (thisServiceUsers[i].Rights == ConfigUtility.CONFIG_SERVICE_OPERATION_RIGHTS)
                    {
                        DropDownListCsUser.Items.Add(new ListItem(thisServiceUsers[i].UserId, thisServiceUsers[i].UserKey.ToString()));
                        DropDownListGenericCredentialUsers.Items.Add(new ListItem(thisServiceUsers[i].UserId, thisServiceUsers[i].UserKey.ToString()));
                    }
                }
                for (int i = 0; i < clientContracts.Count; i++)
                {
                    DropDownListGenericContract.Items.Add(new ListItem(clientContracts[i], clientContracts[i]));
                    DropDownListPrimaryContract.Items.Add(new ListItem(clientContracts[i], clientContracts[i]));
                }
                if (!action.Equals(ConfigUtility.ADD_CONNECTED_SERVICE))
                {
                    buildBindingLists();
                    try
                    {
                        CSID = Convert.ToInt32(Request["ID"]);
                    }
                    catch
                    {
                        Response.Redirect(ConfigSettings.PAGE_CONNECTIONS,true);
                    }
                    ViewState["ID"] = CSID;
                    getData();
                    RadioButtonListServiceType.Enabled = false;
                }
                else
                {
                    buildBindingLists();
                    RadioButtonListServiceType.SelectedIndex = 0;
                    PanelConfig.Visible = true;
                    GenericPanel.Visible = false;
                    ConnectedPanel.Visible = false;
                    ViewState["generateClicked"] = generateClicked;
                }
            }
            TopNode.PostBackUrl = ConfigSettings.PAGE_NODES;
            TopNodeName.Text = compositeServiceData[0].ServiceHost;
            ServiceVersion.Text = compositeServiceData[0].ServiceVersion;
            ServiceHoster.Text = "" + compositeServiceData[0].ServiceHoster;
            ServicePlatform.Text = "" + compositeServiceData[0].RunTimePlatform;
            if (action.Equals(ConfigUtility.ADD_CONNECTED_SERVICE))
            {
                Update.Enabled = false;
                Delete.Enabled = false;
                ButtonUpdateGeneric.Enabled = false;
                ButtonDeleteGeneric.Enabled = false;

            }
            else
            {
                Add.Enabled = false;
                ButtonAddGeneric.Enabled = false;
            }
            TopNode.PostBackUrl = ConfigSettings.PAGE_NODES;
            ServiceVersion.Text = version;
            ServicePlatform.Text = platform;
            ServiceHoster.Text = hoster;
            TopNodeName.Text = hostNameIdentifier;
            ReturnLabel.Text = "<a class=\"Return\" href=\"" + ConfigSettings.PAGE_CONNECTED_SERVICES + "?name=" + hostNameIdentifier + "&cfgSvc=" + configName + "&version=" + version + "&platform=" + platform + "&hoster=" + hoster + "\">Return to Connected Services List</a>";
            GetImageButton.runtimePoweredBy(platform, RuntimePlatform);
        }
        private void processUpdate()
        {
            int success = ConfigUtility.CLUSTER_UPDATE_FULL_SUCCESS;
            thisOldService = (ConnectedServices)ViewState["thisOldService"];
            configServices = (List<ConnectedConfigServices>)ViewState["configServices"];
            bindings = compositeServiceData[0].BindingInformation;
            clients = compositeServiceData[0].ClientInformation;
            BindingInformation thisBinding = null;
            ConnectedConfigServices configService = null;
            List<ConnectedConfigServices> addConfigs = new List<ConnectedConfigServices>();
            ClientInformation thisClient = compositeServiceData[0].ClientInformation.Find(delegate(ClientInformation ciExist) { return ciExist.ElementName.Equals(DropDownListPrimaryClients.SelectedValue); });
            if (thisClient != null)
            {
                thisBinding = compositeServiceData[0].BindingInformation.Find(delegate(BindingInformation biExist) { return biExist.BindingConfigurationName.Equals(thisClient.BindingConfiguration); });
                if (CheckBoxUserCredentials.Checked)
                {
                    thisService.UseDefaultClientCredentials = true;
                    if (DropDownListCsUser.SelectedValue != null && DropDownListCsUser.SelectedValue != "")
                        thisService.DefaultCredentialUserKey = Convert.ToInt32(DropDownListCsUser.SelectedValue);
                    else
                        return;
                }
                else
                {
                    thisService.DefaultCredentialUserKey = -1;
                    thisService.UseDefaultClientCredentials = false;
                }
                if (DropDownListPrimaryContract.Items.Count == 0 && action != ConfigUtility.REMOVE_CONNECTED_SERVICE)
                {
                    UpdateMessage.Text = "You must provide a client contract definition in your startup procedure. There are no available client contracts thus supplied. Service contracts can be generated via svcutil.exe, or used directly based on existing projects/code.";
                    UpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                    return;
                }
                if (DropDownListPrimaryClients.Items.Count == 0 && action != ConfigUtility.REMOVE_CONNECTED_SERVICE)
                {
                    UpdateMessage.Text = "You must provide a client definition in your config file. There are no available client definitions thus supplied. Client definitions can be generated via svcutil.exe.";
                    UpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                    return;
                }
                thisService.ServiceContract = DropDownListPrimaryContract.SelectedValue;
            }
            switch (action)
            {
                case ConfigUtility.ADD_CONNECTED_SERVICE:
                    {
                        string svcName = DropDownListServiceName.SelectedValue;
                        HostedServices hsConnect = configServices[0].PrimaryHostedServices.Find(delegate(HostedServices hsExist) { return hsExist.FriendlyName.Equals(svcName); });
                        thisService.HostedServiceID = hsConnect.HostedServiceID;
                        thisService.DefaultAddress = hsConnect.DefaultAddress;
                        thisService.ClientConfiguration = DropDownListPrimaryClients.SelectedValue;
                        thisService.BindingType = thisBinding.BindingType;
                        thisService.SecurityMode = thisBinding.SecurityMode;
                        string configAddress = TextBoxConfigLoginAddress.Text;
                        Uri configUri = new Uri(configAddress.ToLower());
                        string basePath = configUri.AbsolutePath;
                        int basePort = configUri.Port;
                        string configBinding = DropDownListConfigClient.SelectedValue;
                        ClientInformation theClient = clients.Find(delegate(ClientInformation ciExist) { return ciExist.ElementName.Equals(DropDownListConfigClient.SelectedValue); });
                        BindingInformation theConfigBinding = bindings.Find(delegate(BindingInformation biExist) { return biExist.BindingConfigurationName.Equals(theClient.BindingConfiguration); });
                        configService = configServices.Find(delegate(ConnectedConfigServices ccsExist)
                        {
                            string bindingCheck = ccsExist.BindingType;
                            switch (ccsExist.BindingType)
                            {
                                case ConfigUtility.CUSTOM_BINDING_HTTP:
                                    {
                                        bindingCheck = ConfigUtility.BASIC_HTTP_BINDING;
                                        break;
                                    }

                                case ConfigUtility.CUSTOM_BINDING_TCP:
                                    {
                                        bindingCheck = ConfigUtility.NET_TCP_BINDING;
                                        break;
                                    }
                                case ConfigUtility.CUSTOM_BINDING_WSHTTP:
                                    {
                                        bindingCheck = ConfigUtility.WS_HTTP_BINDING;
                                        break;
                                    }
                            }
                            Uri config2Uri = new Uri(ccsExist.Address);
                            string basePath2 = configUri.AbsolutePath;
                            int basePort2 = configUri.Port;
                            return (bindingCheck.Equals(theConfigBinding.BindingType) && basePort2 == basePort && basePath2.Equals(basePath));
                        });
                        if (configService == null)
                        {
                            UpdateMessage.Text = "An error ocurred finding a compatible Configuration Service Endpoint.  The remote service is listening at the attached endpoint, but reports this endpoint as inactive.  The error is likely on the host side.";
                            UpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                            return;
                        }
                        configService.ClientConfiguration = configBinding;
                        configService.BindingType = theConfigBinding.BindingType;
                        thisService.OnlineMethod = TextBoxOnlineMethod.Text.Trim();
                        thisService.OnlineParms = TextBoxOnlineParms.Text.Trim();
                        if (thisService.OnlineMethod == null || thisService.OnlineMethod == "")
                            thisService.OnlineMethod = ConfigUtility.NO_ONLINE_METHOD;
                        if (thisService.OnlineParms == null || thisService.OnlineParms == "")
                            thisService.OnlineParms = ConfigUtility.NO_ONLINE_PARMS;
                        thisService.ConnectedConfigServiceID = configService.ConnectedConfigServiceID;
                        thisService.HostNameIdentifier = configService.HostNameIdentifier;
                        
                        thisService.ServiceFriendlyName = hsConnect.FriendlyName;
                        thisService.LoadBalanceType = hsConnect.LoadBalanceType;
                        thisService.UseHttps = hsConnect.UseHttps;
                        thisService.ServiceImplementationClassName = hsConnect.ServiceImplementationClassName;
                        thisService.ServiceType = ConfigUtility.HOST_TYPE_CONNECTED_SERVICE;
                        if (checkcsUserDupe(configServices[0].InitialCSUserID,thisService.HostNameIdentifier))
                        {
                            UpdateMessage.Text = "The Connected Service user id '" + configServices[0].InitialCSUserID + " is already in use by another Connected Service definition to a different Virtual Service Host (Host Name Identifier). You need to supply a different csUser ID for this definition.";
                            UpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                            return;
                        }
                        List<ConnectedConfigServices> otherConfigServices = configServices.FindAll(delegate(ConnectedConfigServices otherExist) { return otherExist.ConnectedConfigServiceID != configService.ConnectedConfigServiceID; });
                        addConfigs.Add(configService);
                        if (otherConfigServices != null)
                        {
                            for (int i = 0; i < otherConfigServices.Count; i++)
                            {
                                string bindingType = otherConfigServices[i].BindingType;
                                string bindingName = otherConfigServices[i].ClientConfiguration;
                                string bindingScheme = ConfigUtility.getBindingScheme(otherConfigServices[i].BindingType, false);
                                int sec = 0;
                                if (bindingName.ToLower().Contains("t_security"))
                                    sec = 1;
                                if (bindingName.ToLower().Contains("m_security"))
                                    sec = 2;
                                BindingInformation newBinding = null;
                                switch (sec)
                                {

                                    case 0:
                                        {
                                            newBinding = bindings.Find(delegate(BindingInformation biFind)
                                            {
                                                string thisBindingScheme = ConfigUtility.getBindingScheme(biFind.BindingType, otherConfigServices[i].UseHttps);
                                                return (thisBindingScheme.Equals(bindingScheme) && biFind.BindingConfigurationName.ToLower().Contains("client_configsvc") && !biFind.BindingConfigurationName.ToLower().Contains("t_security") && !biFind.BindingConfigurationName.ToLower().Contains("m_security"));
                                            }
                                            );
                                            break;
                                        }

                                    case 1:
                                        {
                                            newBinding = bindings.Find(delegate(BindingInformation biFind)
                                            {
                                                string thisBindingScheme = ConfigUtility.getBindingScheme(biFind.BindingType, otherConfigServices[i].UseHttps);
                                                return (thisBindingScheme.Equals(bindingScheme) && biFind.BindingConfigurationName.ToLower().Contains("client_configsvc") && biFind.BindingConfigurationName.ToLower().Contains("t_security"));
                                            }
                                            );
                                            break;
                                        }

                                    case 2:
                                        {
                                            newBinding = bindings.Find(delegate(BindingInformation biFind)
                                            {
                                                string thisBindingScheme = ConfigUtility.getBindingScheme(biFind.BindingType, otherConfigServices[i].UseHttps);
                                                return (thisBindingScheme.Equals(bindingScheme) && biFind.BindingConfigurationName.ToLower().Contains("client_configsvc") && biFind.BindingConfigurationName.ToLower().Contains("m_security"));
                                            }
                                            );
                                            break;
                                        }

                                }
                                if (newBinding != null)
                                {
                                    otherConfigServices[i].ClientConfiguration = newBinding.BindingConfigurationName;
                                    otherConfigServices[i].BindingType = newBinding.BindingType;
                                    otherConfigServices[i].OnlineMethod = configService.OnlineMethod;
                                    otherConfigServices[i].OnlineParms = configService.OnlineParms;
                                    addConfigs.Add(otherConfigServices[i]);
                                }
                            }
                        }
                        break;
                    }
                case ConfigUtility.UPDATE_CONNECTED_SERVICE:
                    {
                        configServices = compositeServiceData[0].ConnectedConfigServices;
                        configService = configServices.Find(delegate(ConnectedConfigServices ccsExist) { return ccsExist.ConnectedConfigServiceID == thisService.ConnectedConfigServiceID; });
                        addConfigs.Add(configService);
                        thisService.ClientConfiguration = DropDownListPrimaryClients.SelectedValue;
                        thisService.BindingType = thisBinding.BindingType;
                        thisService.SecurityMode = thisBinding.SecurityMode;
                        thisService.OnlineMethod = TextBoxOnlineMethod.Text.Trim();
                        thisService.OnlineParms = TextBoxOnlineParms.Text.Trim();
                        if (thisService.OnlineMethod == null || thisService.OnlineMethod == "")
                            thisService.OnlineMethod = ConfigUtility.NO_ONLINE_METHOD;
                        if (thisService.OnlineParms == null || thisService.OnlineParms == "")
                            thisService.OnlineParms = ConfigUtility.NO_ONLINE_PARMS;
                        break;
                    }
                case ConfigUtility.REMOVE_CONNECTED_SERVICE:
                    {
                        configServices = compositeServiceData[0].ConnectedConfigServices;
                        configService = configServices.Find(delegate(ConnectedConfigServices ccsExist) { return ccsExist.ConnectedConfigServiceID == thisService.ConnectedConfigServiceID; });
                        addConfigs.Add(configService);
                        break;
                    }
            }
            traversePath = DynamicTraversePath.getTraversePath(hostNameIdentifier, configName, ref configProxy, address, binding, user);
            try
            {
                success = configProxy.receiveService(hostNameIdentifier, configName, null, null, thisOldService, thisService, addConfigs, null, null, true, action, traversePath, user);


                if (success == ConfigUtility.CLUSTER_UPDATE_FULL_SUCCESS)
                {
                    UpdateMessage.Text = "The Connected Service was successfully " + actiontext + ".";
                    UpdateMessage.ForeColor = System.Drawing.Color.PaleGreen;
                    if (action.Equals(ConfigUtility.ADD_CONNECTED_SERVICE))
                        UpdateMessage.Text = UpdateMessage.Text + "<br/>You can now use the Connections menu item to add an initial Connection Point to this Service!";
                    else
                        if (action.Equals(ConfigUtility.REMOVE_CONNECTED_SERVICE))
                        {
                            Delete.Enabled = false;
                            Update.Enabled = false;
                            Add.Enabled = false;
                        }
                    if (action != ConfigUtility.REMOVE_CONNECTED_SERVICE)
                    {
                        compositeServiceData = configProxy.getServiceConfiguration(hostNameIdentifier, configName, ConfigUtility.CONFIG_LEVEL_BASIC, false, traversePath, user);
                        ViewState["CompositeServiceData"] = compositeServiceData;
                        thisService = compositeServiceData[0].ConnectedServices.Find(delegate(ConnectedServices csExist) { return csExist.ServiceFriendlyName.Equals(thisService.ServiceFriendlyName) && csExist.HostNameIdentifier.Equals(thisService.HostNameIdentifier) && csExist.ServiceImplementationClassName.Equals(thisService.ServiceImplementationClassName); });
                        thisServiceConfig = compositeServiceData[0].ConnectedConfigServices.Find(delegate(ConnectedConfigServices ccsExist) { return ccsExist.ConnectedConfigServiceID == thisService.ConnectedConfigServiceID; });
                        ViewState["thisConfigService"] = thisServiceConfig;
                        ViewState["thisService"] = thisService;
                        ViewState["thisOldService"] = thisService;
                        ViewState["ID"] = thisService.ConnectedServiceID;
                        action = ConfigUtility.UPDATE_CONNECTED_SERVICE;
                        ViewState["action"] = action;
                    }
                }
                else
                {
                    string message = null;
                    switch (success)
                    {
                        case ConfigUtility.CLUSTER_UPDATE_FAIL_PERSISTED:
                            {
                                message = ConfigSettings.EXCEPTION_MESSAGE_FAIL_PERSISTED;
                                break;
                            }

                        case ConfigUtility.CLUSTER_UPDATE_FAIL_VALIDATION:
                            {
                                message = ConfigSettings.EXCEPTION_MESSAGE_FAIL_VALIDATION;
                                break;
                            }

                        case ConfigUtility.CLUSTER_UPDATE_FAIL_AUTHENTICATION:
                            {
                                message = ConfigSettings.EXCEPTION_MESSAGE_FAIL_AUTHORIZATION;
                                break;
                            }

                        case ConfigUtility.CLUSTER_UPDATE_FAIL_REMOTE:
                            {
                                message = ConfigSettings.EXCEPTION_MESSAGE_FAIL_REMOTE_UPDATE;
                                break;
                            }
                        default:
                            {
                                message = ConfigSettings.EXCEPTION_MESSAGE_FAIL_REMOTE_PEER + success.ToString();
                                break;
                            }
                    }
                    UpdateMessage.Text = "<br/><span style=\"color:Maroon\">" + message + "</span>";
                    UpdateMessage.ForeColor = System.Drawing.Color.Maroon;
                }
                if (success == ConfigUtility.CLUSTER_UPDATE_FULL_SUCCESS)
                {
                    Add.Enabled = false;
                    if (action != ConfigUtility.REMOVE_CONNECTED_SERVICE)
                    {
                        Update.Enabled = true;
                        Delete.Enabled = true;
                    }
                }
                PanelConfig.Visible = false;
                panelConnectedService1.Visible = false;
                panelConnectedService2.Visible = true;
                DropDownListServiceName.Enabled = false;
                LabelContract2.Text = thisService.ServiceContract;
                LabelSvcBindingType2.Text = thisService.BindingType;
                SecurityMode.Text = thisService.SecurityMode;
                SecurityMode2.Text = thisService.SecurityMode;
                LabelServiceFriendlyName2.Text = thisService.ServiceFriendlyName;
                LabelSvcBindingConfig2.Text = thisService.ClientConfiguration;
                LabelIntroService.Text = "The Service friendly name as assigned by the Service Hoster.";
                LabelIntroService.ForeColor = System.Drawing.ColorTranslator.FromHtml("#FFFF99");
                LabelIntroPrimary.Text = "Primary Service Details";
            }
            catch (Exception econfig)
            {
                ViewState["thisService"] = thisOldService;
                UpdateMessage.Text = "An exception was encountered.<br/> Exception is: " + econfig.ToString();
                UpdateMessage.ForeColor = System.Drawing.Color.Maroon;
            }
        }
        private void getData()
        {
            
            ServiceUsers thisCsUser = null;
            generateClicked = "true";
            ViewState["generateClicked"] = generateClicked;
            thisService = compositeServiceData[0].ConnectedServices.Find(delegate(ConnectedServices csExist) { return csExist.ConnectedServiceID == CSID; });
            ViewState["thisService"] = thisService;
            ViewState["thisOldService"] = thisService;
            if (thisService.ServiceType == ConfigUtility.HOST_TYPE_CONNECTED_SERVICE)
            {
                ConnectedPanel.Visible = true;
                GenericPanel.Visible = false;
                RadioButtonListServiceType.SelectedIndex = 0;
            }
            else
            {
                RadioButtonListServiceType.SelectedIndex = 1;
                ConnectedPanel.Visible = false;
                GenericPanel.Visible = true;
                PanelConfig.Visible = false;
            }
            RadioButtonListServiceType.Enabled = false;
            if (thisService == null)
                Response.Redirect(ConfigSettings.PAGE_CONNECTIONS,true);
            if (thisService.ServiceType == ConfigUtility.HOST_TYPE_CONNECTED_SERVICE)
            {
                RadioButtonListServiceType.SelectedIndex = 0;
                GenericPanel.Visible = false;
                ConnectedPanel.Visible = true;
                PanelConfig.Visible = false;
                panelConnectedService2.Visible = false;
                panelConnectedService1.Visible = true;
                thisServiceConfig = compositeServiceData[0].ConnectedConfigServices.Find(delegate(ConnectedConfigServices ccsExist) { return ccsExist.ConnectedConfigServiceID == thisService.ConnectedConfigServiceID; });
                ViewState["thisConfigService"] = thisServiceConfig;
                thisCsUser = thisServiceUsers.Find(delegate(ServiceUsers csUserExist) { return csUserExist.UserKey == thisService.csUserKey; });
                if (thisService.UseDefaultClientCredentials)
                {
                    CheckBoxUserCredentials.Checked = true;
                    DropDownListCsUser.SelectedValue = thisService.DefaultCredentialUserKey.ToString();
                    DropDownListCsUser.Enabled = true;
                }
                else
                    DropDownListCsUser.Enabled = false;
                if (thisCsUser == null)
                    CSUserID.Text = "<span style=\"color:red;\">Invalid csUser! Please delete this entry and create new.</span";
                else
                    CSUserID.Text = "<span style=\"color:palegreen;\">" + thisCsUser.UserKey.ToString() + ": " + thisCsUser.UserId + "</span>";
                if (thisServiceConfig == null)
                    ConnectedConfigID.Text = "<span style=\"color:red;\">Invalid Connected Config Entry! Please delete this entry and create new.</span";
                else
                    ConnectedConfigID.Text = "<span style=\"color:palegreen;\">" + thisServiceConfig.ConnectedConfigServiceID.ToString() + "</span>";
                if (thisCsUser == null || thisServiceConfig == null)
                    return;
                HostNameID.Text = thisService.HostNameIdentifier;
                DropDownListServiceName.Items.Add(new ListItem(thisService.ServiceFriendlyName, thisService.ServiceFriendlyName));
                DropDownListServiceName.SelectedValue = thisService.ServiceFriendlyName;
                DropDownListServiceName.Enabled = false;
                LabelServiceFriendlyName.Text = thisService.ServiceFriendlyName;
                try
                {
                    DropDownListPrimaryContract.SelectedValue = thisService.ServiceContract;
                }
                catch
                {
                }
                try
                {
                    DropDownListPrimaryClients.SelectedValue = thisService.ClientConfiguration;
                }
                catch { }
                LabelServiceFriendlyName.Text = thisService.ServiceFriendlyName;
                LabelSvcBindingType.Text = thisService.BindingType;
                SecurityMode.Text = thisService.SecurityMode;
                SecurityMode2.Text = thisService.SecurityMode;
                LabelUseHttps.Text = thisService.UseHttps.ToString();
                LabelGenericBindingType.Text = thisService.BindingType;
                LabelContract2.Text = thisService.ServiceContract;
                LabelContract.Text = thisService.ServiceContract;
                LabelSvcBindingType2.Text = thisService.BindingType;
                LabelServiceFriendlyName2.Text = thisService.ServiceFriendlyName;
                LabelVPath.Text = "Determined Dynamically";
                LabelPort.Text = "Determined Dynamically";
                LabelSvcBindingConfig2.Text = thisService.ClientConfiguration;
                LabelIntroService.Text = "The Service friendly name as assigned by the Service Hoster.";
                LabelIntroService.ForeColor = System.Drawing.ColorTranslator.FromHtml("#FFFF99");
                LabelIntroPrimary.Text = "Primary Service Details";
                TextBoxOnlineMethod.Text = thisService.OnlineMethod;
                if (!thisService.OnlineParms.Equals(ConfigUtility.NO_ONLINE_PARMS))
                    TextBoxOnlineParms.Text = thisService.OnlineParms;
                thisServiceConfig = compositeServiceData[0].ConnectedConfigServices.Find(delegate(ConnectedConfigServices ccsExist) { return ccsExist.ConnectedConfigServiceID == thisService.ConnectedConfigServiceID; });
                ViewState["thisConfigService"] = thisServiceConfig;
            }
            else
            {
                if (thisService.UseDefaultClientCredentials)
                {
                    CheckBoxGenericCredentials.Checked = true;
                    DropDownListGenericCredentialUsers.SelectedValue = thisService.DefaultCredentialUserKey.ToString();
                    DropDownListGenericCredentialUsers.Enabled = true;
                }
                else
                    DropDownListGenericCredentialUsers.Enabled = false;
                HostNameID.Text = thisService.HostNameIdentifier;
                RadioButtonListServiceType.SelectedIndex = 1;
                TextBoxHostNameGeneric.Text = thisService.HostNameIdentifier;
                TextBoxGenericName.Text = thisService.ServiceFriendlyName;
                try
                {
                    DropDownListGenericContract.SelectedValue = thisService.ServiceContract;
                }
                catch { }
                try
                {
                    DropDownListPrimaryClients.SelectedValue = thisService.ClientConfiguration;

                }
                catch { }
                TextBoxGenericOnlineMethod.Text = thisService.OnlineMethod;
                TextBoxGenericParms.Text = thisService.OnlineParms;
                TextBoxGenericAddress.Text = thisService.DefaultAddress;
                thisCsUser = thisServiceUsers.Find(delegate(ServiceUsers csUserExist) { return csUserExist.UserKey == thisService.csUserKey; });
                if (thisCsUser == null && user.Rights!=ConfigUtility.CONFIG_DEMO_ADMIN_RIGHTS)
                    CSUserID2.Text = "<span style=\"color:red;\">Invalid csUser! Please delete this entry and create new.</span";
                else
                    if (thisCsUser!=null)
                        CSUserID2.Text = "<span style=\"color:palegreen;\">" + thisCsUser.UserKey.ToString() + ": " + thisCsUser.UserId + "</span>";
                ConnectedConfigServices thisconfig = compositeServiceData[0].ConnectedConfigServices.Find(delegate(ConnectedConfigServices cse) { return cse.ConnectedConfigServiceID.Equals(thisService.ConnectedConfigServiceID); });
                if (thisconfig == null)
                    ConnectedConfigID2.Text = "<span style=\"color:red;\">Invalid Connected Config Entry! Please delete this entry and create new.</span";
                else
                    ConnectedConfigID2.Text = "<span style=\"color:palegreen;\">" + thisconfig.ConnectedConfigServiceID.ToString() + "</span>";
                if (thisCsUser == null || thisconfig == null)
                    return;
                TextBoxGenericUser.Text = thisCsUser.UserId;
                TextBoxGenericPassword.Text = thisCsUser.Password;
                TextBoxGenericPassword.Enabled = false;
                TextBoxGenericUser.Enabled = false;
                TextBoxGenericPassword.Attributes.Add("value", thisCsUser.Password);
            }
                DropDownListGenericClients.Items.Clear();
                DropDownListPrimaryClients.Items.Clear();
                for (int i = 0; i < clients.Count; i++)
                {
                    BindingInformation theBinding = bindings.Find(delegate(BindingInformation biExist) { return biExist.BindingConfigurationName.Equals(clients[i].BindingConfiguration); });
                    if (theBinding != null)
                    {
                        string tsSecMode = null;
                        if (thisService == null)
                            tsSecMode = "unknown";
                        else
                            tsSecMode = thisService.SecurityMode;
                        if (clients[i].Contract.Equals(thisService.ServiceContract) && (theBinding.BindingType.Equals(thisService.BindingType) || thisService.BindingType.ToLower().Contains("custom")))
                        {
                            if ((clients[i].ElementName.ToLower().StartsWith("client_") && !clients[i].ElementName.ToLower().StartsWith("client_configsvc") && !clients[i].ElementName.ToLower().StartsWith("client_nodesvc")) && (theBinding.SecurityMode.Equals(tsSecMode) || tsSecMode.Equals("unknown")))
                            {
                                DropDownListGenericClients.Items.Add(new ListItem(clients[i].ElementName, clients[i].ElementName));
                                DropDownListPrimaryClients.Items.Add(new ListItem(clients[i].ElementName, clients[i].ElementName));
                                if (clients[i].ElementName.Equals(thisService.ClientConfiguration))
                                {
                                    DropDownListGenericClients.SelectedValue = clients[i].ElementName;
                                    DropDownListGenericClients.Text = clients[i].ElementName;
                                    LabelGenericBindingType.Text = theBinding.BindingType;
                                    DropDownListPrimaryClients.SelectedValue = clients[i].ElementName;
                                    DropDownListPrimaryClients.Text = clients[i].ElementName;
                                    LabelBindingTypePrimary.Text = theBinding.BindingType;
                                }
                            }
                        }
                    }
                }
                thisServiceConfig = compositeServiceData[0].ConnectedConfigServices.Find(delegate(ConnectedConfigServices ccsExist) { return ccsExist.ConnectedConfigServiceID == thisService.ConnectedConfigServiceID; });
                ViewState["thisConfigService"] = thisServiceConfig;
                ViewState["configServices"] = compositeServiceData[0].ConnectedConfigServices;
        }
 protected void DropDownListPrimaryContract_SelectedIndexChanged(object sender, EventArgs e)
 {
     thisService = (ConnectedServices)ViewState["thisService"];
     configServices = (List<ConnectedConfigServices>)ViewState["configServices"];
     string svcName = DropDownListServiceName.SelectedValue;
     switch (action)
     {
         case ConfigUtility.ADD_CONNECTED_SERVICE:
             {
                 hsSelected = configServices[0].PrimaryHostedServices.Find(delegate(HostedServices hsExist) { return hsExist.FriendlyName.Equals(svcName); });
                 DropDownListPrimaryClients.Items.Clear();
                 if (hsSelected != null)
                 {
                     string thisHssecurityMode = hsSelected.SecurityMode;
                     string thisHsBindingType = hsSelected.BindingType;
                     for (int i = 0; i < clients.Count; i++)
                     {
                         if (DropDownListPrimaryContract.SelectedValue.Equals(clients[i].Contract))
                         {
                             BindingInformation theClientBinding = bindings.Find(delegate(BindingInformation biExist) { return biExist.BindingConfigurationName.Equals(clients[i].BindingConfiguration); });
                             if (theClientBinding != null)
                             {
                                 string tsSecMode = null;
                                 if (thisService == null)
                                     tsSecMode = "unknown";
                                 else
                                     tsSecMode = thisService.SecurityMode;
                                 if (theClientBinding.BindingType.Equals(thisHsBindingType) || thisHsBindingType.ToLower().Contains("custom"))
                                 {
                                     if (theClientBinding.SecurityMode.Equals(tsSecMode) || tsSecMode.Equals("unknown"))
                                     {
                                         if (!clients[i].ElementName.ToLower().Contains("host") && !clients[i].ElementName.ToLower().Contains("client_configsvc") && !clients[i].ElementName.ToLower().Contains("client_nodesvc"))
                                         {
                                             DropDownListPrimaryClients.Items.Add(new ListItem(clients[i].ElementName, clients[i].ElementName));
                                             DropDownListPrimaryClients.SelectedValue = clients[i].ElementName;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 break;
             }
         case ConfigUtility.UPDATE_CONNECTED_SERVICE:
             {
                     DropDownListPrimaryClients.Items.Clear();
                     string thisCssecurityMode = thisService.SecurityMode;
                     string thisCsBindingType = thisService.BindingType;
                     for (int i = 0; i < clients.Count; i++)
                     {
                         if (DropDownListPrimaryContract.SelectedValue.Equals(clients[i].Contract))
                         {
                             BindingInformation theClientBinding = bindings.Find(delegate(BindingInformation biExist) { return biExist.BindingConfigurationName.Equals(clients[i].BindingConfiguration); });
                             if (theClientBinding != null)
                             {
                                 string tsSecMode = null;
                                 if (thisService == null)
                                     tsSecMode = "unknown";
                                 else
                                     tsSecMode = thisService.SecurityMode;
                                 if (theClientBinding.BindingType.Equals(thisCsBindingType) || thisCsBindingType.ToLower().Contains("custom"))
                                 {
                                     if (theClientBinding.SecurityMode.Equals(tsSecMode) || tsSecMode.Equals("unknown"))
                                     {
                                         if (!clients[i].ElementName.ToLower().Contains("host") && !clients[i].ElementName.ToLower().Contains("client_configsvc") && !clients[i].ElementName.ToLower().Contains("client_nodesvc"))
                                         {
                                             DropDownListPrimaryClients.Items.Add(new ListItem(clients[i].ElementName, clients[i].ElementName));
                                             DropDownListPrimaryClients.SelectedValue = clients[i].ElementName;
                                         }
                                     }
                                 }
                             }
                         }
                     }
             }
             break;
     }
     if (DropDownListPrimaryClients.Items.Count == 0)
         LabelIntroService.Text = LabelIntroService.Text = "Please change the selected Primary Hosted Service, or the Client Contract.  The current combination yields no valid client configuration to connect with. The check was performed against binding type, and security mode. You may need to add and appropriate client definition to your config file.";
                     
 }
        protected override void Run()
        {
            var project = IdeApp.ProjectOperations.CurrentSelectedProject as DotNetProject;

            ConnectedServices.OpenServicesTab(project);
        }