/// <summary>
        /// This event occurs when the connection has been updated in XrmToolBox
        /// </summary>
        public override void UpdateConnection(
            IOrganizationService newService,
            ConnectionDetail detail,
            string actionName,
            object parameter)
        {
            base.UpdateConnection(newService, detail, actionName, parameter);

            if (mySettings != null && detail != null)
            {
                mySettings.LastUsedOrganizationWebappUrl = detail.WebApplicationUrl;
                LogInfo("Connection has changed to: {0}", detail.WebApplicationUrl);
            }
            LoadEntities();
            cboEntities.SelectedItem = null;
        }
Beispiel #2
0
        public void AddEnvironment(ConnectionDetail connectionDetail, IOrganizationService crm = null)
        {
            var oldCurrentEnvironment = this.EnvironmentList.FirstOrDefault(_ => string.Equals(_.Detail.ConnectionId, connectionDetail.ConnectionId));

            if (oldCurrentEnvironment != null)
            {
                this.EnvironmentList.Remove(oldCurrentEnvironment);
                this.messenger.Send(new ConnectionRemovedMessage(oldCurrentEnvironment));
            }

            var model = new ConnectionModel(connectionDetail, false, crm);

            this.EnvironmentList.Add(model);

            this.messenger.Send(new ConnectionAddedMessage(this.EnvironmentList.IndexOf(model), model));
        }
Beispiel #3
0
        public override void UpdateConnection(IOrganizationService newService, ConnectionDetail detail, string actionName = "", object parameter = null)
        {
            ConnectionDetail = detail;
            if (actionName == "AdditionalOrganization")
            {
                AdditionalConnectionDetails.Clear();
                AdditionalConnectionDetails.Add(detail);
                SetConnectionLabel(detail, "Target");
            }
            else
            {
                SetConnectionLabel(detail, "Source");
            }

            base.UpdateConnection(newService, detail, actionName, parameter);
        }
        public override void UpdateConnection(IOrganizationService newService, ConnectionDetail connectionDetail,
                                              string actionName = "", object parameter = null)
        {
            base.UpdateConnection(newService, connectionDetail, actionName, parameter);

            if (actionName == string.Empty)
            {
                SetSourceConnected();
            }
            else
            {
                SetTargetConnected();
            }

            tbbLoadMetadata.Enabled = Service != null && AdditionalConnectionDetails.Count > 0;
        }
Beispiel #5
0
        static public void TestSeparatePub()
        {
            ConnectionDetail conn     = new ConnectionDetail(hostName, port, exchName, exchType, "Separate", "Separate", uid, pwd);
            Exchange         pubExch  = new Exchange(conn);
            Queue            pubQueue = new Queue(pubExch, conn);

            for (int i = 0; i < 5; i++)
            {
                string outMsg = "Hello World " + i.ToString();
                SeparateRequests.Add(outMsg);
                pubQueue.PostMessage(outMsg);
            }

            pubQueue.Close();
            pubExch.Close();
        }
        private async Task <OrganizationDetail> RetrieveOrganizationAsync(ConnectionDetail currentDetail)
        {
            if (currentDetail.OrganizationId == null)
            {
                return(null);
            }
            WebRequest.GetSystemWebProxy();

            var service = await CrmConnectionHelper.GetDiscoveryServiceAsync(currentDetail);

            var request  = new RetrieveOrganizationsRequest();
            var response = (RetrieveOrganizationsResponse)service.Execute(request);


            return(response.Details.Where(d => d.OrganizationId == new Guid(currentDetail.OrganizationId)).FirstOrDefault());
        }
Beispiel #7
0
        /// <summary>
        /// Updates the connection status displayed on the main ToolStripDropDownButton
        /// </summary>
        /// <param name="isConnected">Indicates if the status is 'Connected'</param>
        /// <param name="detail">Connection details</param>
        public void SetConnectionStatus(bool isConnected, ConnectionDetail detail)
        {
            ToolStripDropDownButton btn = (ToolStripDropDownButton)Items[0];

            if (isConnected)
            {
                SetMessage("Connected!");
                btn.Text  = $"Connected to '{detail.ServerName} ({detail.OrganizationFriendlyName})'";
                btn.Image = (Image)resources.GetObject("server_lightning");
            }
            else
            {
                btn.Text  = "Not connected";
                btn.Image = (Image)resources.GetObject("server");
            }
        }
        /// <summary>
        /// This event occurs when the connection has been updated in XrmToolBox
        /// </summary>
        public override void UpdateConnection(IOrganizationService newService, ConnectionDetail detail, string actionName, object parameter)
        {
            base.UpdateConnection(newService, detail, actionName, parameter);

            // update the connection and clear out the related data
            EntitiesListControl.UpdateConnection(Service);
            EntityDropDown.UpdateConnection(Service);
            ClearSelectedEntitiesList();


            if (_mySettings != null && detail != null)
            {
                _mySettings.LastUsedOrganizationWebappUrl = detail.WebApplicationUrl;
                LogInfo("Connection has changed to: {0}", detail.WebApplicationUrl);
            }
        }
        public static string GetEntityReferenceUrl(this ConnectionDetail connectiondetail, EntityReference entref)
        {
            if (string.IsNullOrWhiteSpace(entref?.LogicalName) || Guid.Empty.Equals(entref.Id))
            {
                return(string.Empty);
            }
            var url = connectiondetail.GetFullWebApplicationUrl();

            url = string.Concat(url,
                                url.EndsWith("/") ? "" : "/",
                                "main.aspx?etn=",
                                entref.LogicalName,
                                "&pagetype=entityrecord&id=",
                                entref.Id.ToString());
            return(url);
        }
Beispiel #10
0
        private void btnReset_Click(object sender, EventArgs e)
        {
            updatedDetail           = new ConnectionDetail();
            txtOrganizationUrl.Text = string.Empty;
            txtHomeRealm.Text       = string.Empty;
            txtDomain.Text          = string.Empty;
            txtUsername.Text        = string.Empty;
            txtPassword.Text        = string.Empty;

            visitedPath.Clear();
            visitedPath.Add(pnlConnectUrl.Name);

            lblDescription.Text = Resources.ConnectionWizard_EnterUrlHeaderDescription;
            txtOrganizationUrl.Focus();
            DisplayPanel(pnlConnectUrl, btnGo);
        }
Beispiel #11
0
        static public void TestSeparate()
        {
            ConnectionDetail conn     = new ConnectionDetail("localhost", 5, "AnalysisFarm", "", "AnalysisRequest", "", "", "");
            Exchange         pubExch  = new Exchange(conn);
            Queue            pubQueue = new Queue(pubExch, conn);

            while (!Console.KeyAvailable)
            {
                if (pubQueue.IsEmpty)
                {
                    pubQueue.PostTestMessages();
                }
            }
            pubQueue.Close();
            pubExch.Close();
        }
        public ConnectionWizard(ConnectionDetail detail = null)
        {
            InitializeComponent();

            originalDetail = (ConnectionDetail)detail?.Clone();
            updatedDetail = new ConnectionDetail(true);

            visitedPath = new List<string> { pnlConnectUrl.Name };

            if (detail != null)
            {
                txtOrganizationUrl.Text = string.IsNullOrEmpty(detail.OriginalUrl) ? detail.WebApplicationUrl : detail.OriginalUrl;
                txtDomain.Text = detail.UserDomain;
                txtUsername.Text = detail.UserName;
                txtConnectionName.Text = detail.ConnectionName;
                chkSavePassword.Checked = detail.SavePassword;
                if (detail.PasswordIsEmpty || detail.SavePassword == false)
                {
                    txtPassword.PasswordChar = (char)0;
                    txtPassword.UseSystemPasswordChar = false;
                    txtPassword.Text = SpecifyPasswordText;
                    txtPassword.ForeColor = SystemColors.GrayText;
                }
                else
                {
                    txtPassword.PasswordChar = '•';
                    txtPassword.UseSystemPasswordChar = true;
                    txtPassword.Text = "@@PASSWORD@@";
                    txtPassword.ForeColor = SystemColors.ActiveCaptionText;
                }

                txtConnectionString.Text = detail.ConnectionString;
                txtHomeRealm.Text = detail.HomeRealmUrl;
                chkUseIntegratedAuthentication.Checked = !detail.IsCustomAuth;
                rbIfdYes.Checked = detail.UseIfd;
                txtTimeout.Text = string.Format("{0:dd\\.hh\\:mm\\:ss}", detail.Timeout);

                updatedDetail = (ConnectionDetail)originalDetail.Clone();

                lblHeader.Text = "Edit connection";

                if (originalDetail.UseConnectionString)
                {
                    llUseConnectionString_LinkClicked(null, null);
                }
            }
        }
        /// <summary>
        /// Attempts to lookup the user password.  First by reflection of the userPassword, then by the old public property, then by a config value, then by crying uncle and prompting the user for the password
        /// </summary>
        /// <returns></returns>
        public static string GetUserPassword(this ConnectionDetail connection)
        {
            try
            {
                if (connection.PasswordIsEmpty)
                {
                    return(string.Empty);
                }
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch
            {
                // Probably a pervious version of the XTB.  Attempt to soldier on...
            }

            var field = connection.GetType().GetField("userPassword", BindingFlags.Instance | BindingFlags.NonPublic);

            if (field != null)
            {
                return(Decrypt((string)field.GetValue(connection), "MsCrmTools", "Tanguy 92*", "SHA1", 2, "ahC3@bCa2Didfc3d", 256));
            }

            // Lookup Old Public Property
            var prop = connection.GetType().GetProperty("UserPassword", BindingFlags.Instance | BindingFlags.Public);

            if (prop != null)
            {
                return((string)prop.GetValue(connection));
            }

            // Lookup Config Value
            var password = ConfigurationManager.AppSettings["EarlyBoundGenerator.CrmSvcUtil.UserPassword"];

            if (!string.IsNullOrWhiteSpace(password))
            {
                return(password);
            }

            MessageBox.Show(@"Unable to find ""EarlyBoundGenerator.CrmSvcUtil.UserPassword"" in app.config.");

            // Ask User for value
            while (string.IsNullOrWhiteSpace(password))
            {
                password = Prompt.ShowDialog("Please enter your password:"******"Enter Password");
            }
            return(password);
        }
Beispiel #14
0
        public override void UpdateConnection(IOrganizationService newService, ConnectionDetail connectionDetail, string actionName = "", object parameter = null)
        {
            base.UpdateConnection(newService, connectionDetail, actionName, parameter);

            if (actionName == "AdditionalOrganization")
            {
                targetService = newService;
                targetDetail  = connectionDetail;
                SetConnectionLabel(connectionDetail, "Target");
            }
            else
            {
                service      = newService;
                sourceDetail = connectionDetail;
                SetConnectionLabel(connectionDetail, "Source");
            }
        }
        private void btnConnectWithConnectionString_Click(object sender, EventArgs e)
        {
            if (txtConnectionString.Text.Length == 0)
            {
                return;
            }

            updatedDetail = new ConnectionDetail(true)
            {
                UseConnectionString = true,
                ConnectionString    = txtConnectionString.Text
            };

            lblDescription.Text = Resources.ConnectionWizard_ConnectingHeaderDescription;
            DisplayPanel(pnlWaiting, null);
            Connect();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MainControlViewModel"/> class.
        /// </summary>
        /// <param name="organizationService">The organization service.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="connectionDetailOriginalUrl">The connection detail original URL.</param>
        public MainControlViewModel(IOrganizationService organizationService, Settings settings,
                                    ConnectionDetail connectionDetailOriginalUrl)
        {
            _settings                     = settings;
            _connectionDetail             = connectionDetailOriginalUrl;
            _outputLoggerService          = new OutputLoggerService(this);
            _metadataRepository           = new MetadataRepository(organizationService);
            _crmVersionRepository         = new CrmVersionRepository(organizationService);
            _earlyBoundSettingsRepository = new EarlyBoundSettingsRepository();
            _generationService            = new GenerationService(_metadataRepository);
            SettingsPath                  = settings.CurrentSettingsPath;

            CreateSettingPathIfNotExist();
            CheckVersion();
            LoadSettings();
            RefreshEntities();
        }
Beispiel #17
0
        static void TestSeparateRead()
        {
            ConnectionDetail conn     = new ConnectionDetail(hostName, port, exchName, exchType, "Separate", "Separate", uid, pwd);
            Exchange         subExch  = new Exchange(conn);
            Queue            subQueue = new Queue(subExch, conn);

            while (!subQueue.IsEmpty)
            {
                string gotOne = subQueue.ReadMessageAsString();
                if (SeparateRequests.Contains(gotOne))
                {
                    SeparateRequests.Remove(gotOne);
                }
            }
            subQueue.Close();
            subExch.Close();
        }
Beispiel #18
0
        private void FillConnectionDetailFromControls(ConnectionDetail detail)
        {
            detail.ConnectionName = txtConnectionName.Text;
            detail.OriginalUrl    = txtOrganizationUrl.Text;
            detail.UserDomain     = txtDomain.Text;
            detail.UserName       = txtUsername.Text;
            detail.SavePassword   = chkSavePassword.Checked;
            detail.IsCustomAuth   = !chkUseIntegratedAuthentication.Checked;
            detail.UseIfd         = rbIfdYes.Checked;
            detail.ConnectionId   = Guid.NewGuid();
            detail.UseOsdp        = isOffice365 || crmConnectionDetail.UseOsdp;
            detail.UseOnline      = isOnline;
            detail.UseSsl         = txtOrganizationUrl.Text.ToLower().StartsWith("https");
            detail.ServerName     = hostName;
            detail.Timeout        = TimeSpan.Parse(txtTimeout.Text);

            if (txtPassword.Text != "@@PASSWORD@@" && txtPassword.Text != SpecifyPasswordText)
            {
                detail.SetPassword(txtPassword.Text);
            }

            if (string.IsNullOrEmpty(hostPort))
            {
                if (useSsl)
                {
                    detail.ServerPort = 443;
                }
                else
                {
                    detail.ServerPort = 80;
                }
            }
            else
            {
                detail.ServerPort = int.Parse(hostPort);
            }

            if (isOnline)
            {
                detail.AuthType = isOffice365 || crmConnectionDetail.UseOsdp ? AuthenticationProviderType.OnlineFederation : AuthenticationProviderType.LiveId;
            }
            else
            {
                detail.AuthType = isIfd ? AuthenticationProviderType.Federation : AuthenticationProviderType.ActiveDirectory;
            }
        }
Beispiel #19
0
        private void Connect_Click(object sender, EventArgs e)
        {
            // Check data if authentication panel is the current displayed one
            if (pnlConnectAuthentication.Visible)
            {
                if (string.IsNullOrEmpty(txtDomain.Text) && txtDomain.Enabled ||
                    string.IsNullOrEmpty(txtUsername.Text) ||
                    string.IsNullOrEmpty(txtPassword.Text))
                {
                    MessageBox.Show(this, Resources.ConnectionWizard_PleaseEnterCredentials,
                                    Resources.ConnectionWizard_WarningTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);

                    return;
                }
            }

            if (updatedConnectionDetail == null)
            {
                updatedConnectionDetail = new ConnectionDetail();
            }
            FillConnectionDetailFromControls(updatedConnectionDetail);
            if (crmConnectionDetail == null)
            {
                lblDescription.Text = Resources.ConnectionWizard_ConnectingHeaderDescription;
                DisplayPanel(pnlWaiting);

                Connect();
            }
            else if (updatedConnectionDetail.IsConnectionBrokenWithUpdatedData(crmConnectionDetail))
            {
                if (DialogResult.Yes == MessageBox.Show(this, Resources.ConnectionWizard_NeedToTestConnectionAgain,
                                                        Resources.ConnectionWizard_QuestionHeaderTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {
                    lblDescription.Text = Resources.ConnectionWizard_ConnectingHeaderDescription;
                    DisplayPanel(pnlWaiting);

                    Connect();
                }
            }
            else
            {
                lblDescription.Text = Resources.ConnectionWizard_SuccessHeaderDescription;
                DisplayPanel(pnlConnected);
                txtConnectionName.Focus();
            }
        }
        public ConnectionWizard(ConnectionDetail detail = null)
        {
            InitializeComponent();

            originalDetail = (ConnectionDetail)detail?.Clone();
            updatedDetail = new ConnectionDetail(true);

            visitedPath = new List<string> { pnlConnectUrl.Name };

            if (detail != null)
            {
                txtOrganizationUrl.Text = string.IsNullOrEmpty(detail.OriginalUrl) ? detail.WebApplicationUrl : detail.OriginalUrl;
                txtDomain.Text = detail.UserDomain;
                txtUsername.Text = detail.UserName;
                txtConnectionName.Text = detail.ConnectionName;
                chkSavePassword.Checked = detail.SavePassword;
                if (detail.PasswordIsEmpty || detail.SavePassword == false)
                {
                    txtPassword.PasswordChar = (char)0;
                    txtPassword.UseSystemPasswordChar = false;
                    txtPassword.Text = SpecifyPasswordText;
                    txtPassword.ForeColor = Color.DarkGray;
                }
                else
                {
                    txtPassword.PasswordChar = '•';
                    txtPassword.UseSystemPasswordChar = true;
                    txtPassword.Text = "@@PASSWORD@@";
                    txtPassword.ForeColor = Color.Black;
                }

                txtConnectionString.Text = detail.ConnectionString;
                txtHomeRealm.Text = detail.HomeRealmUrl;
                chkUseIntegratedAuthentication.Checked = !detail.IsCustomAuth;
                rbIfdYes.Checked = detail.UseIfd;

                updatedDetail = (ConnectionDetail)originalDetail.Clone();

                lblHeader.Text = "Edit connection";

                if (originalDetail.UseConnectionString)
                {
                    llUseConnectionString_LinkClicked(null, null);
                }
            }
        }
Beispiel #21
0
        public static string GetOrgName(this ConnectionDetail detail)
        {
            var orgName = detail.OrganizationUrlName;

            if (string.IsNullOrWhiteSpace(orgName) &&
                !string.IsNullOrWhiteSpace(detail.WebApplicationUrl))
            {
                var startIndex = detail.WebApplicationUrl.LastIndexOf('/') + 1;
                var length     = detail.WebApplicationUrl.IndexOf('.') - startIndex;
                if (length > 0)
                {
                    orgName = detail.WebApplicationUrl.Substring(startIndex, length);
                }
            }

            return(orgName ?? string.Empty);
        }
Beispiel #22
0
        /// <summary>
        /// Sets the connections labels on either the source/target section
        /// </summary>
        /// <param name="serviceToLabel"></param>
        /// <param name="serviceType"></param>
        private void SetConnectionLabel(ConnectionDetail detail, string serviceType)
        {
            var connectionName = string.Format("{0} ({1})", detail.ServerName, detail.Organization);

            switch (serviceType)
            {
            case "Source":
                lblSource.Text      = connectionName;
                lblSource.ForeColor = Color.Green;
                break;

            case "Target":
                lblTarget.Text      = connectionName;
                lblTarget.ForeColor = Color.Green;
                break;
            }
        }
        public UpdaterServiceResponse <SolutionDetail> RetrieveSolution(ConnectionDetail connectionDetail, Guid solutionId)
        {
            var response = new UpdaterServiceResponse <SolutionDetail>();

            try
            {
                Console.WriteLine("Requesting Solution retrieve");
                var             client = connectionDetail.GetCrmServiceClient(true);
                QueryExpression query  = new QueryExpression
                {
                    EntityName = "solution",
                    ColumnSet  = new ColumnSet(new string[] { "friendlyname", "uniquename", "publisherid" }),
                    Criteria   = new FilterExpression()
                };
                query.Criteria.AddCondition("isvisible", ConditionOperator.Equal, true);
                query.Criteria.AddCondition("solutionid", ConditionOperator.Equal, solutionId);

                query.LinkEntities.Add(new LinkEntity("solution", "publisher", "publisherid", "publisherid", JoinOperator.Inner));
                query.LinkEntities[0].Columns.AddColumns("customizationprefix");
                query.LinkEntities[0].EntityAlias = "publisher";

                var retrieveSolutionResponse = client.RetrieveMultiple(query);
                var entity = retrieveSolutionResponse.Entities.FirstOrDefault();
                if (entity == null)
                {
                    return(null);
                }
                var solution = new SolutionDetail()
                {
                    SolutionId      = entity.Id,
                    PublisherPrefix = entity.GetAttributeValue <AliasedValue>("publisher.customizationprefix") == null ? null : entity.GetAttributeValue <AliasedValue>("publisher.customizationprefix").Value.ToString()
                };

                response.Payload      = solution;
                response.IsSuccessful = true;
                return(response);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                response.Error        = ex.ToString();
                response.IsSuccessful = false;
                return(response);
            }
        }
Beispiel #24
0
        /// <summary>
        /// This event occurs when the connection has been updated in XrmToolBox
        /// </summary>
        public override void UpdateConnection(IOrganizationService newService, ConnectionDetail detail, string actionName, object parameter)
        {
            base.UpdateConnection(newService, detail, actionName, parameter);
            service = newService;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            txtSearchCodeActivity.Text = string.Empty;
            FillAssemblies();
            FillWorkflows();

            ShowAssemblies(VISIBILITY_TYPES.COLLAPSED);

            if (mySettings != null && detail != null)
            {
                mySettings.LastUsedOrganizationWebappUrl = detail.WebApplicationUrl;
                LogInfo("Connection has changed to: {0}", detail.WebApplicationUrl);
            }
        }
Beispiel #25
0
        public override void UpdateConnection(IOrganizationService newService, ConnectionDetail detail,
                                              string actionName, object parameter)
        {
            base.UpdateConnection(newService, detail, actionName, parameter);

            if (actionName != "AdditionalOrganization")
            {
                organisationid = detail.ConnectionId.Value;
                SetConnectionLabel(detail.ConnectionName, ServiceType.Source);
                // init buttons -> value based on connection
                InitMappings();
                InitFilter();
                // Save settings file
                SettingFileHandler.SaveConfigData(settings);
                // Load entities when source connection changes
                PopulateEntities();
            }
        }
        public void UpdateConnection(IOrganizationService newService, ConnectionDetail detail, string actionName = "", object parameter = null)
        {
            this.detail = detail;
            if (actionName == "TargetOrganization")
            {
                targetServices.Add(detail.ConnectionName, newService);
                lastTargetService = new KeyValuePair <string, IOrganizationService>(detail.ConnectionName, newService);
                lstTargetEnvironments.Items.Add(new ListViewItem {
                    Text = detail.ConnectionName
                });
            }
            else
            {
                service = newService;

                SetConnectionLabel(detail, "Source");
            }
        }
Beispiel #27
0
        private IOrganizationService GetNewServiceClient(ConnectionDetail con)
        {
            var svc = con.ServiceClient;

            if (svc.ActiveAuthenticationType == Microsoft.Xrm.Tooling.Connector.AuthenticationType.OAuth)
            {
                return(svc.Clone());
            }

            try
            {
                return(con.GetCrmServiceClient(true));
            }
            catch
            {
                return(svc);
            }
        }
Beispiel #28
0
        public CrmOrganization(ConnectionDetail detail, ProgressIndicator prog, IOrganizationService Service)
        {
            if (detail == null)
            {
                throw new ArgumentNullException("detail");
            }

            OrganizationServiceUrl = detail.OrganizationServiceUrl;
            WebApplicationUrl      = detail.WebApplicationUrl;

            OrganizationFriendlyName = detail.OrganizationFriendlyName;
            OrganizationUniqueName   = detail.Organization;
            ServerBuild         = new Version(detail.OrganizationVersion);
            OrganizationService = Service;
            ConnectionDetail    = detail;

            OrganizationHelper.OpenConnection(this, OrganizationHelper.LoadMessages(this), prog);
        }
Beispiel #29
0
        /// <summary>
        /// Updates the connection status displayed on the main ToolStripDropDownButton
        /// </summary>
        /// <param name="isConnected">Indicates if the status is 'Connected'</param>
        /// <param name="detail">Connection details</param>
        public void SetConnectionStatus(bool isConnected, ConnectionDetail detail)
        {
            ToolStripDropDownButton btn = (ToolStripDropDownButton)this.Items[0];

            if (isConnected)
            {
                this.SetMessage("Connected!");
                btn.Text = string.Format("Connected to '{0} ({1})'",
                                         detail.ServerName,
                                         detail.OrganizationFriendlyName);
                btn.Image = (System.Drawing.Image)(resources.GetObject("server_lightning"));
            }
            else
            {
                btn.Text  = "Not connected";
                btn.Image = (System.Drawing.Image)(resources.GetObject("server"));
            }
        }
        /// <summary>
        /// Updates the connection status displayed on the main ToolStripDropDownButton
        /// </summary>
        /// <param name="isConnected">Indicates if the status is 'Connected'</param>
        /// <param name="detail">Connection details</param>
        public void SetConnectionStatus(bool isConnected, ConnectionDetail detail)
        {
            ToolStripDropDownButton btn = (ToolStripDropDownButton)this.Items[0];

            if (isConnected)
            {
                this.SetMessage("Connected!");
                btn.Text = string.Format("Connected to '{0} ({1})'",
                       detail.ServerName,
                       detail.OrganizationFriendlyName);
                btn.Image = (System.Drawing.Image)(resources.GetObject("server_lightning"));
            }
            else
            {
                btn.Text = "Not connected";
                btn.Image = (System.Drawing.Image)(resources.GetObject("server"));
            }
        }
Beispiel #31
0
 public void UpdateConnection(IOrganizationService newService, ConnectionDetail detail, string actionName = "", object parameter = null)
 {
     if (actionName == "TargetOrganization")
     {
         targetService = newService;
         SetConnectionLabel(targetService, "Target");
         ((OrganizationServiceProxy)((OrganizationService)targetService).InnerService).Timeout = new TimeSpan(
             0, 1, 0, 0);
     }
     else
     {
         service = newService;
         SetConnectionLabel(service, "Source");
         ((OrganizationServiceProxy)((OrganizationService)service).InnerService).Timeout = new TimeSpan(0, 1, 0,
                                                                                                        0);
         RetrieveSolutions();
     }
 }
Beispiel #32
0
        static public void StartClient()
        {
            string myExeLoc = "C:\\Projects\\JPD\\BBRepos\\ProcessWrappers\\Client\\bin\\Debug\\Client.exe";

            //myExeLoc = "D:\\Projects\\Workspaces\\BBRepos\\ProcessWrappers\\Client\\bin\\Debug\\Client.exe";
            //myExeLoc = "C:\\Projects\\JPD\\BBRepos\\Chess\\engines\\stockfish\\stockfish_5_32bit.exe";

            myHost = new ProcessWrapper();
            string modelParams = IOModelHelper.IOTypeParam[thisPass];

            switch (thisPass)
            {
            case IOType.PIPES:
                modelParams += " ";
                break;

            case IOType.QUEUES:
                modelParams += " ";
                break;

            case IOType.StdIO:
                modelParams += " ";
                break;
            }
            modelParams = "";

            if (thisPass == IOType.QUEUES)
            {
                string        clientID     = Guid.NewGuid().ToString();
                string        typeID       = "TestProcess.PrintSort";
                List <string> listenRoutes = new List <string>();
                List <string> postRoutes   = new List <string>();
                listenRoutes.Add(clientID + ".workUpdate." + typeID);
                listenRoutes.Add(clientID + ".workComplete." + typeID);
                postRoutes.Add(clientID + ".workRequest." + typeID);
                ConnectionDetail thisConn = new ConnectionDetail("localhost", 5672, "myExch", "topic", clientID, listenRoutes, "guest", "guest");

                modelParams  = "myExch|localhost|5672|guest|guest|";
                modelParams += clientID + ".workUpdate." + typeID + "|";
                modelParams += clientID + ".workComplete." + typeID + "|#|";
                modelParams += clientID + ".workRequest." + typeID;
            }
            myHost.Init(myExeLoc, thisPass, modelParams, ProcessControl);
        }
        public ConnectionWizard(ConnectionDetail detail = null)
        {
            InitializeComponent();

            originalDetail = (ConnectionDetail)detail?.Clone();
            updatedDetail = new ConnectionDetail(true);

            visitedPath = new List<string> { pnlConnectUrl.Name };

            if (detail != null)
            {
                txtOrganizationUrl.Text = string.IsNullOrEmpty(detail.OriginalUrl) ? detail.WebApplicationUrl : detail.OriginalUrl;
                txtDomain.Text = detail.UserDomain;
                txtUsername.Text = detail.UserName;
                txtConnectionName.Text = detail.ConnectionName;
                chkSavePassword.Checked = detail.SavePassword;
                if (detail.PasswordIsEmpty || detail.SavePassword == false)
                {
                    txtPassword.PasswordChar = (char)0;
                    txtPassword.UseSystemPasswordChar = false;
                    txtPassword.Text = SpecifyPasswordText;
                    txtPassword.ForeColor = Color.DarkGray;
                }
                else
                {
                    txtPassword.PasswordChar = '•';
                    txtPassword.UseSystemPasswordChar = true;
                    txtPassword.Text = "@@PASSWORD@@";
                    txtPassword.ForeColor = Color.Black;
                }

                txtHomeRealm.Text = detail.HomeRealmUrl;
                chkUseIntegratedAuthentication.Checked = !detail.IsCustomAuth;
                rbIfdYes.Checked = detail.UseIfd;

                updatedDetail = (ConnectionDetail)originalDetail.Clone();

                lblHeader.Text = "Edit connection";
            }
        }
Beispiel #34
0
        public void Run()
        {
            var cd = new ConnectionDetail()
            {
                UseIfd = RequestInformation("Use IFD") == "y",
                UserDomain = RequestInformation("Domain"),
                UserName = RequestInformation("Username"),
                UseSsl = RequestInformation("Use SSL") == "y",
                OrganizationServiceUrl = RequestInformation("Organization service url")
            };
            cd.SetPassword(RequestInformation("Password"));

            connectionManager = ConnectionManager.Instance;
            connectionManager.ConnectionSucceed += new ConnectionManager.ConnectionSucceedEventHandler(connectionManager_ConnectionSucceed);
            connectionManager.ConnectionFailed += new ConnectionManager.ConnectionFailedEventHandler(connectionManager_ConnectionFailed);
            connectionManager.RequestPassword += new ConnectionManager.RequestPasswordEventHandler(connectionManager_RequestPassword);
            connectionManager.UseProxy += new ConnectionManager.UseProxyEventHandler(connectionManager_UseProxy);
            connectionManager.StepChanged += new ConnectionManager.StepChangedEventHandler(connectionManager_StepChanged);
            connectionManager.ConnectToServer(cd);

            System.Console.ReadLine();
        }
        private void BGetOrganizationsClick(object sender, EventArgs e)
        {
            string warningMessage = string.Empty;
            bool goodAuthenticationData = false;
            bool goodServerData = false;

            // Check data filled by user
            if (rbAuthenticationIntegrated.Checked ||
                (
                rbAuthenticationCustom.Checked &&
                (tbUserDomain.Text.Length > 0 || cbUseIfd.Checked || cbUseOSDP.Checked) &&
                tbUserLogin.Text.Length > 0 &&
                tbUserPassword.Text.Length > 0
                )
                ||
                    (cbUseOnline.Checked && !string.IsNullOrEmpty(tbUserLogin.Text) &&
                    !string.IsNullOrEmpty(tbUserPassword.Text)))
                goodAuthenticationData = true;

            if (tbServerName.Text.Length > 0 || cbbOnlineEnv.SelectedIndex >= 0)
                goodServerData = true;

            int serverPort = 80;
            if (tbServerPort.Text.Length > 0)
            {
                if (!int.TryParse(tbServerPort.Text, out serverPort))
                {
                    MessageBox.Show(this, "Server port must be a integer value!", "Warning", MessageBoxButtons.OK,
                        MessageBoxIcon.Warning);
                    return;
                }
            }
            else
            {
                if (cbUseSsl.Checked)
                {
                    serverPort = 443;
                }
            }

            if (tbUserPassword.Text.IndexOf(";") >= 0)
            {
                warningMessage += "Password cannot contains semicolon character, which is a split character for Microsoft Dynamics CRM simplified connection strings\r\n";
            }

            if (!goodServerData)
            {
                warningMessage += "Please provide server name\r\n";
            }
            if (!goodAuthenticationData)
            {
                warningMessage += "Please fill all authentication textboxes\r\n";
            }

            if (warningMessage.Length > 0)
            {
                MessageBox.Show(this, warningMessage, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                // Save connection details in structure
                if (isCreationMode)
                {
                    detail = new ConnectionDetail();
                }

                detail.ConnectionName = tbName.Text;
                detail.IsCustomAuth = rbAuthenticationCustom.Checked;
                detail.UseSsl = cbUseSsl.Checked;
                detail.ServerName = (cbUseOSDP.Checked || cbUseOnline.Checked) ? cbbOnlineEnv.SelectedItem.ToString() : tbServerName.Text;
                detail.ServerPort = serverPort;
                detail.UserDomain = tbUserDomain.Text;
                detail.UserName = tbUserLogin.Text;

                if (tbUserPassword.Text != "@@PASSWORD@@")
                {
                    detail.SetPassword(tbUserPassword.Text);
                }

                detail.UseIfd = cbUseIfd.Checked;
                detail.UseOnline = cbUseOnline.Checked;
                detail.UseOsdp = cbUseOSDP.Checked;
                detail.HomeRealmUrl = (tbHomeRealmUrl.Text.Length > 0 ? tbHomeRealmUrl.Text : null);

                detail.AuthType = AuthenticationProviderType.ActiveDirectory;
                if (cbUseIfd.Checked)
                {
                    detail.AuthType = AuthenticationProviderType.Federation;
                }
                else if (cbUseOSDP.Checked)
                {
                    detail.AuthType = AuthenticationProviderType.OnlineFederation;
                }
                else if (cbUseOnline.Checked)
                {
                    detail.AuthType = AuthenticationProviderType.LiveId;
                }

                // Launch organization retrieval
                comboBoxOrganizations.Items.Clear();
                organizations = new List<OrganizationDetail>();
                Cursor = Cursors.WaitCursor;

                var bw = new BackgroundWorker();
                bw.DoWork += BwDoWork;
                bw.RunWorkerCompleted += BwRunWorkerCompleted;
                bw.RunWorkerAsync();
            }
        }
        private int GetImageIndex(ConnectionDetail detail)
        {
            if (detail.UseOnline)
            {
                return 2;
            }

            if (detail.UseOsdp)
            {
                return 2;
            }

            if (detail.UseIfd)
            {
                return 1;
            }

            return 0;
        }
        private void btnReset_Click(object sender, EventArgs e)
        {
            updatedDetail = new ConnectionDetail();
            txtOrganizationUrl.Text = string.Empty;
            txtHomeRealm.Text = string.Empty;
            txtDomain.Text = string.Empty;
            txtUsername.Text = string.Empty;
            txtPassword.Text = string.Empty;

            visitedPath.Clear();
            visitedPath.Add(pnlConnectUrl.Name);

            lblDescription.Text = Resources.ConnectionWizard_EnterUrlHeaderDescription;
            txtOrganizationUrl.Focus();
            DisplayPanel(pnlConnectUrl, btnGo);
        }
        private void btnFinish_Click(object sender, EventArgs e)
        {
            // Saving information to a connection detail
            if (crmConnectionDetail == null)
            {
                crmConnectionDetail = new ConnectionDetail();
            }

            if (serviceClient != null)
            {
                // This happens when the connection is created. When updating
                // a connection, the service client is not instanciated
                crmConnectionDetail.Organization = serviceClient.ConnectedOrgUniqueName;
                crmConnectionDetail.OrganizationFriendlyName = serviceClient.ConnectedOrgFriendlyName;
                crmConnectionDetail.OrganizationUrlName = serviceClient.ConnectedOrgUniqueName;
                crmConnectionDetail.OrganizationVersion = serviceClient.ConnectedOrgVersion.ToString();
                crmConnectionDetail.OrganizationDataServiceUrl = serviceClient.ConnectedOrgPublishedEndpoints[EndpointType.OrganizationDataService];
                crmConnectionDetail.OrganizationServiceUrl = serviceClient.ConnectedOrgPublishedEndpoints[EndpointType.OrganizationService];
            }

            if (crmConnectionDetail == null)
            {
                crmConnectionDetail = new ConnectionDetail();
            }
            FillConnectionDetailFromControls(crmConnectionDetail);

            crmConnectionDetail.ServiceClient = serviceClient;

            DialogResult = DialogResult.OK;
            Close();
        }
        protected override void OnLoad(EventArgs e)
        {
            if (detail != null)
            {
                initialDetail = (ConnectionDetail) detail.Clone();
                FillValues();
            }

            //if (proposeToConnect == false && isCreationMode == false)
            //{
            //    bValidate.Enabled = true;
            //}

            base.OnLoad(e);
        }
Beispiel #40
0
 /// <summary>
 /// Deletes a Crm connection from the connections list
 /// </summary>
 /// <param name="connectionToDelete">Details of the connection to delete</param>
 public void DeleteConnection(ConnectionDetail connectionToDelete)
 {
     ConnectionManager.Instance.ConnectionsList.Connections.Remove(connectionToDelete);
     ConnectionManager.Instance.SaveConnectionsFile();
 }
Beispiel #41
0
        /// <summary>
        /// Checks the existence of a user password and returns it
        /// </summary>
        /// <param name="detail">Details of the Crm connection</param>
        /// <returns>True if password defined</returns>
        public bool RequestPassword(ConnectionDetail detail)
        {
            if (!detail.PasswordIsEmpty)
                return true;

            bool returnValue = false;

            var pForm = new PasswordForm
            {
                UserLogin = detail.UserName,
                UserDomain = detail.UserDomain,
                StartPosition = FormStartPosition.CenterParent
            };

            MethodInvoker mi = delegate
            {
                if (pForm.ShowDialog(_innerAppForm) == DialogResult.OK)
                {
                    detail.SetPassword(pForm.UserPassword);
                    detail.SavePassword = pForm.SavePassword;
                    returnValue = true;
                }
            };

            if (_innerAppForm.InvokeRequired)
            {
                _innerAppForm.Invoke(mi);
            }
            else
            {
                mi();
            }

            return returnValue;
        }
Beispiel #42
0
        /// <summary>
        /// Creates or updates a Crm connection
        /// </summary>
        /// <param name="isCreation">Indicates if it is a connection creation</param>
        /// <param name="connectionToUpdate">Details of the connection to update</param>
        /// <returns>Created or updated connection</returns>
        public ConnectionDetail EditConnection(bool isCreation, ConnectionDetail connectionToUpdate)
        {
            var cForm = new ConnectionForm(isCreation) { StartPosition = FormStartPosition.CenterParent };

            if (!isCreation)
            {
                cForm.CrmConnectionDetail = connectionToUpdate;
            }

            if (cForm.ShowDialog(_innerAppForm) == DialogResult.OK)
            {
                if (cForm.DoConnect)
                {
                    ConnectionManager.Instance.ConnectToServer(cForm.CrmConnectionDetail);
                }

                //if (!cForm.CrmConnectionDetail.PasswordIsEmpty && !cForm.CrmConnectionDetail.SavePassword)
                //{
                //    cForm.CrmConnectionDetail.ErasePassword();
                //}

                if (isCreation)
                {
                    if (ConnectionManager.Instance.ConnectionsList.Connections.FirstOrDefault(
                        d => d.ConnectionId == cForm.CrmConnectionDetail.ConnectionId) == null)
                    {
                        ConnectionManager.Instance.ConnectionsList.Connections.Add(cForm.CrmConnectionDetail);
                    }
                }
                else
                {
                    foreach (ConnectionDetail detail in ConnectionManager.Instance.ConnectionsList.Connections)
                    {
                        if (detail.ConnectionId == cForm.CrmConnectionDetail.ConnectionId)
                        {
                            detail.UpdateAfterEdit(cForm.CrmConnectionDetail);
                        }
                    }
                }

                ConnectionManager.Instance.SaveConnectionsFile();

                return cForm.CrmConnectionDetail;
            }

            return null;
        }
        private void btnGo_Click(object sender, EventArgs e)
        {
            var url = txtOrganizationUrl.Text;

            Uri uri;
            if (!Uri.TryCreate(url, UriKind.Absolute, out uri))
            {
                MessageBox.Show(Resources.ConnectionWizard_InvalidUrl);
                return;
            }

            TimeSpan timeOut;
            if (!TimeSpan.TryParse(txtTimeout.Text, CultureInfo.InvariantCulture, out timeOut))
            {
                MessageBox.Show(this, Resources.ConnectionWizard_InvalidTimeoutValue, Resources.ConnectionWizard_WarningTitle,
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            useSsl = url.StartsWith("https");
            var urlWithoutProtocol = url.Remove(0, useSsl ? 8 : 7);
            var urlParts = urlWithoutProtocol.Split('/');
            var host = urlParts[0];
            var hostParts = host.Split(':');
            hostName = hostParts[0];
            hostPort = hostParts.Length == 2 ? hostParts[1] : null;
            orga = urlParts.Length > 1 && !urlParts[1].ToLower().StartsWith("main.aspx") ? urlParts[1] : null;
            txtDomain.Enabled = true;

            if (orga == null)
            {
                IPAddress ipa;
                if (!IPAddress.TryParse(hostName, out ipa))
                {
                    orga = hostName.Split('.')[0];
                }

                if (hostName.IndexOf("dynamics.com", StringComparison.Ordinal) > 0)
                {
                    // MFA test
                    //var t = new Task(() =>
                    //{
                    //    var svc1 = new CrmServiceClient("AuthType=OAuth;[email protected]; Password=pass@word1;Url=https://crm2016rtm.crm4.dynamics.com;AppId=7d770fd6-f087-40f0-b41f-e55bf556cdac;RedirectUri=http://www.xrmtoolbox.com;TokenCacheStorePath=c:\\temp;LoginPrompt=Always");
                    //    //var svc1 = new CrmServiceClient("AuthType=Office365;[email protected]; Password=Emeline18*;Url=https://crm2016rtm.crm4.dynamics.com;");
                    //});

                    //t.Start();

                    // return;

                    isOnline = true;
                    txtDomain.Enabled = false;

                    if (updatedConnectionDetail == null)
                    {
                        updatedConnectionDetail = new ConnectionDetail();
                    }
                    FillConnectionDetailFromControls(updatedConnectionDetail);

                    lblDescription.Text = Resources.ConnectionWizard_CredentialsHeaderDescription;
                    DisplayPanel(pnlConnectAuthentication);

                    if (txtDomain.Enabled)
                    {
                        txtDomain.Focus();
                    }
                    else
                    {
                        txtUsername.Focus();
                    }
                }
                else
                {
                    // IFD or AD??
                    // Requires additional information
                    visitedPath.Add(pnlConnectMoreActiveDirectoryInfo.Name);

                    if (updatedConnectionDetail == null)
                    {
                        updatedConnectionDetail = new ConnectionDetail();
                    }
                    FillConnectionDetailFromControls(updatedConnectionDetail);

                    lblDescription.Text = Resources.ConnectionWizard_IfdSelectionHeaderDescription;
                    DisplayPanel(pnlConnectMoreActiveDirectoryInfo);
                    rbIfdNo.Focus();
                }
            }
            else
            {
                if (chkUseIntegratedAuthentication.Checked)
                {
                    if (updatedConnectionDetail == null)
                    {
                        updatedConnectionDetail = new ConnectionDetail();
                    }

                    FillConnectionDetailFromControls(updatedConnectionDetail);
                    if (updatedConnectionDetail.IsConnectionBrokenWithUpdatedData(crmConnectionDetail))
                    {
                        lblDescription.Text = Resources.ConnectionWizard_ConnectingHeaderDescription;
                        DisplayPanel(pnlWaiting);
                        Connect();
                    }
                    else
                    {
                        lblDescription.Text = Resources.ConnectionWizard_SuccessHeaderDescription;
                        DisplayPanel(pnlConnected);
                        txtConnectionName.Focus();
                    }
                }
                else
                {
                    visitedPath.Add(pnlConnectAuthentication.Name);
                    lblDescription.Text = Resources.ConnectionWizard_CredentialsHeaderDescription;
                    DisplayPanel(pnlConnectAuthentication);
                    if (txtDomain.Enabled)
                    {
                        txtDomain.Focus();
                    }
                    else
                    {
                        txtUsername.Focus();
                    }
                }
            }
        }
        private void Connect_Click(object sender, EventArgs e)
        {
            // Check data if authentication panel is the current displayed one
            if (pnlConnectAuthentication.Visible)
            {
                if (string.IsNullOrEmpty(txtDomain.Text) && txtDomain.Enabled
                    || string.IsNullOrEmpty(txtUsername.Text)
                    || string.IsNullOrEmpty(txtPassword.Text))
                {
                    MessageBox.Show(this, Resources.ConnectionWizard_PleaseEnterCredentials,
                        Resources.ConnectionWizard_WarningTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);

                    return;
                }
            }

            if (updatedConnectionDetail == null)
            {
                updatedConnectionDetail = new ConnectionDetail();
            }
            FillConnectionDetailFromControls(updatedConnectionDetail);
            if (crmConnectionDetail == null)
            {
                lblDescription.Text = Resources.ConnectionWizard_ConnectingHeaderDescription;
                DisplayPanel(pnlWaiting);

                Connect();
            }
            else if (updatedConnectionDetail.IsConnectionBrokenWithUpdatedData(crmConnectionDetail))
            {
                if (DialogResult.Yes == MessageBox.Show(this, Resources.ConnectionWizard_NeedToTestConnectionAgain,
                        Resources.ConnectionWizard_QuestionHeaderTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {
                    lblDescription.Text = Resources.ConnectionWizard_ConnectingHeaderDescription;
                    DisplayPanel(pnlWaiting);

                    Connect();
                }
            }
            else
            {
                lblDescription.Text = Resources.ConnectionWizard_SuccessHeaderDescription;
                DisplayPanel(pnlConnected);
                txtConnectionName.Focus();
            }
        }
        private void BValidateClick(object sender, EventArgs e)
        {
            if (tbName.Text.Length == 0)
            {
                MessageBox.Show(this, "You must define a name for this connection!", "Warning", MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);
                return;
            }

            int serverPort = 80;
            if (tbServerPort.Text.Length > 0)
            {
                if (!int.TryParse(tbServerPort.Text, out serverPort))
                {
                    MessageBox.Show(this, "Server port must be a integer value!", "Warning", MessageBoxButtons.OK,
                        MessageBoxIcon.Warning);
                    return;
                }
            }
            else if (cbUseSsl.Checked)
            {
                serverPort = 443;
            }

            if (proposeToConnect && comboBoxOrganizations.Text.Length == 0 && comboBoxOrganizations.SelectedItem == null &&
                !(cbUseIfd.Checked || cbUseOSDP.Checked))
            {
                MessageBox.Show(this, "You must select an organization!", "Warning", MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);
                return;
            }

            if (tbUserPassword.Text.Length == 0 && (cbUseIfd.Checked || rbAuthenticationCustom.Checked))
            {
                MessageBox.Show(this, "You must define a password!", "Warning", MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);
                return;
            }

            if (detail == null)
                detail = new ConnectionDetail();

            // Save connection details in structure
            detail.ConnectionName = tbName.Text;
            detail.IsCustomAuth = rbAuthenticationCustom.Checked;
            detail.UseSsl = cbUseSsl.Checked;
            detail.UseOnline = cbUseOnline.Checked;
            detail.UseOsdp = cbUseOSDP.Checked;
            detail.ServerName = (cbUseOSDP.Checked || cbUseOnline.Checked)
                ? cbbOnlineEnv.SelectedItem.ToString()
                : tbServerName.Text;
            detail.ServerPort = serverPort;
            detail.UserDomain = tbUserDomain.Text;
            detail.UserName = tbUserLogin.Text;
            detail.SavePassword = chkSavePassword.Checked;
            detail.UseIfd = cbUseIfd.Checked;
            detail.HomeRealmUrl = (tbHomeRealmUrl.Text.Length > 0 ? tbHomeRealmUrl.Text : null);

            if (tbUserPassword.Text != "@@PASSWORD@@" && tbUserPassword.Text != "Please specify the password")
            {
                detail.SetPassword(tbUserPassword.Text);
            }

            TimeSpan timeOut;
            if (!TimeSpan.TryParse(tbTimeoutValue.Text, CultureInfo.InvariantCulture, out timeOut))
            {
                MessageBox.Show(this, "Wrong timeout value!\r\n\r\nExpected format : HH:mm:ss", "Warning",
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (isCreationMode && comboBoxOrganizations.SelectedItem == null)
            {
                MessageBox.Show(this, "You must discover organizations and select one to create a connection", "Warning",
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);

                return;
            }

            detail.Timeout = timeOut;

            OrganizationDetail selectedOrganization = comboBoxOrganizations.SelectedItem != null
                ? ((Organization) comboBoxOrganizations.SelectedItem).OrganizationDetail
                : null;
            if (selectedOrganization != null)
            {
                detail.OrganizationServiceUrl = selectedOrganization.Endpoints[EndpointType.OrganizationService];
                detail.WebApplicationUrl = selectedOrganization.Endpoints[EndpointType.WebApplication];
                detail.Organization = selectedOrganization.UniqueName;
                detail.OrganizationUrlName = selectedOrganization.UrlName;
                detail.OrganizationFriendlyName = selectedOrganization.FriendlyName;
                detail.OrganizationVersion = selectedOrganization.OrganizationVersion;
            }
            else if (initialDetail != null && initialDetail.IsConnectionBrokenWithUpdatedData(detail))
            {
                MessageBox.Show(this,
                    "You changed critical parameters for this connection! Please retrieve organizations to ensure your changes are valid",
                    "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            try
            {
                if (initialDetail == null || initialDetail.IsConnectionBrokenWithUpdatedData(detail))
                {
                    if (proposeToConnect || isCreationMode)
                    {
                        FillDetails();

                        if (proposeToConnect &&
                            MessageBox.Show(this, "Do you want to connect now to this server?", "Question",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            doConnect = true;
                        }
                    }
                }

                DialogResult = DialogResult.OK;
                Close();
            }
            catch (Exception error)
            {
                if (detail.OrganizationServiceUrl != null && detail.OrganizationServiceUrl.IndexOf(detail.ServerName, StringComparison.Ordinal) < 0)
                {
                    var uri = new Uri(detail.OrganizationServiceUrl);
                    var hostName = uri.Host;

                    const string format = "The server name you provided ({0}) is not the same as the one defined in deployment manager ({1}). Please make sure that the server name defined in deployment manager is reachable from you computer.\r\n\r\nError:\r\n{2}";
                    MessageBox.Show(this, string.Format(format, detail.ServerName, hostName,error.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(this, error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private OrganizationDetailCollection RetrieveOrganizations(ConnectionDetail currentDetail)
        {
            WebRequest.GetSystemWebProxy();

            var service = currentDetail.GetDiscoveryService();

            var request = new RetrieveOrganizationsRequest();
            var response = (RetrieveOrganizationsResponse)service.Execute(request);
            return response.Details;
        }
        private ListViewGroup GetGroup(ConnectionDetail detail)
        {
            string groupName;

            if (detail.UseOsdp)
            {
                groupName = "CRM Online - Office 365";
            }
            else if (detail.UseOnline)
            {
                groupName = "CRM Online - CTP";
            }
            else if (detail.UseIfd)
            {
                groupName = "Claims authentication - Internet Facing Deployment";
            }
            else
            {
                groupName = "OnPremise";
            }

            var group = lvConnections.Groups.Cast<ListViewGroup>().FirstOrDefault(g => g.Name == groupName);
            if (group == null)
            {
                group = new ListViewGroup(groupName, groupName);
                lvConnections.Groups.Add(group);
            }

            return group;
        }
        private void FillConnectionDetailFromControls(ConnectionDetail detail)
        {
            detail.ConnectionName = txtConnectionName.Text;
            detail.OriginalUrl = txtOrganizationUrl.Text;
            detail.UserDomain = txtDomain.Text;
            detail.UserName = txtUsername.Text;
            detail.SavePassword = chkSavePassword.Checked;
            detail.IsCustomAuth = !chkUseIntegratedAuthentication.Checked;
            detail.UseIfd = rbIfdYes.Checked;
            detail.ConnectionId = Guid.NewGuid();
            detail.UseOsdp = isOffice365 || crmConnectionDetail.UseOsdp;
            detail.UseOnline = isOnline;
            detail.UseSsl = txtOrganizationUrl.Text.ToLower().StartsWith("https");
            detail.ServerName = hostName;
            detail.Timeout = TimeSpan.Parse(txtTimeout.Text);

            if (txtPassword.Text != "@@PASSWORD@@" && txtPassword.Text != SpecifyPasswordText)
            {
                detail.SetPassword(txtPassword.Text);
            }

            if (string.IsNullOrEmpty(hostPort))
            {
                if (useSsl)
                {
                    detail.ServerPort = 443;
                }
                else
                {
                    detail.ServerPort = 80;
                }
            }
            else
            {
                detail.ServerPort = int.Parse(hostPort);
            }

            if (isOnline)
            {
                detail.AuthType = isOffice365 || crmConnectionDetail.UseOsdp ? AuthenticationProviderType.OnlineFederation : AuthenticationProviderType.LiveId;
            }
            else
            {
                detail.AuthType = isIfd ? AuthenticationProviderType.Federation : AuthenticationProviderType.ActiveDirectory;
            }
        }
        private void btnConnectWithConnectionString_Click(object sender, EventArgs e)
        {
            if (txtConnectionString.Text.Length == 0)
            {
                return;
            }

            updatedDetail = new ConnectionDetail(true)
            {
                UseConnectionString = true,
                ConnectionString = txtConnectionString.Text
            };

            lblDescription.Text = Resources.ConnectionWizard_ConnectingHeaderDescription;
            DisplayPanel(pnlWaiting, null);
            Connect();
        }