/// <summary>
        /// Initializes a new instance of the <see cref="OrganizationSnapshot"/> class.
        /// </summary>
        /// <param name="connectionDetail">Object holding connection details to given organization.</param>
        /// <param name="reference">
        /// Instance of the <see cref="OrganizationSnapshot"/> class, serving as refenece. Only
        /// these solutions and assemblies will be included, that are already present in the reference.
        /// </param>
        public OrganizationSnapshot(ConnectionDetail connectionDetail, OrganizationSnapshot reference)
        {
            Solution[] solutions = null;
            PluginAssembly[] assemblies = null;
            DataCollection<Entity> entities = null;

            var organizationService = connectionDetail.GetOrganizationService();

            try
            {
                entities = organizationService.RetrieveMultiple(Helpers.CreateSolutionsQuery()).Entities;
                solutions = entities.ToArray<Entity>().Select(x => new Solution(x)).ToArray<Solution>();
                solutions = solutions.Where(x => reference.Solutions.Where(y => y.UniqueName == x.UniqueName).Count() > 0).ToArray<Solution>();

                entities = organizationService.RetrieveMultiple(Helpers.CreateAssembliesQuery()).Entities;
                assemblies = entities.ToArray<Entity>().Select(x => new PluginAssembly(x)).ToArray<PluginAssembly>();
                assemblies = assemblies.Where(x => reference.Assemblies.Where(y => y.UniqueName == x.UniqueName).Count() > 0).ToArray<PluginAssembly>();
            }
            catch (Exception ex)
            {
                // Hiding exceptions
            }

            this.ConnectionDetail = connectionDetail;
            this.Solutions = solutions;
            this.Assemblies = assemblies;
        }
Exemple #2
0
        public List<Entity> GetAllFormsByTypeCode(int objectTypeCode, ConnectionDetail detail)
        {
            var qe = new QueryExpression("systemform")
            {
                ColumnSet = new ColumnSet(new[] { "name", "formxml" }),
                Criteria = new FilterExpression
                {
                    Conditions =
                    {
                        new ConditionExpression("objecttypecode", ConditionOperator.Equal, objectTypeCode),
                        new ConditionExpression("type", ConditionOperator.In, new[] {2,7}),
                        new ConditionExpression("iscustomizable", ConditionOperator.Equal, true)
                    }
                }
            };

            if (detail.OrganizationMajorVersion > 5)
            {
                qe.Criteria.Conditions.Add(new ConditionExpression("formactivationstate", ConditionOperator.Equal, 1));
            }

            try
            {
                return Service.RetrieveMultiple(qe).Entities.ToList();
            }
            catch
            {
                qe.Criteria.Conditions.RemoveAt(qe.Criteria.Conditions.Count - 1);
                return Service.RetrieveMultiple(qe).Entities.ToList();
            }
        }
        public CrmSystemViewList(IOrganizationService service, string entityName, ConnectionDetail connectionDetail)
        {
            this.service = service;
            this.entityName = entityName;
            this.connectionDetail = connectionDetail;

            InitializeComponent();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OrganizationSnapshot"/> class.
        /// </summary>
        /// <param name="connectionDetail">Object holding connection details to given organization.</param>
        public OrganizationSnapshot(ConnectionDetail connectionDetail)
        {
            var organizationService = connectionDetail.GetOrganizationService();

            this.ConnectionDetail = connectionDetail;
            this.Solutions = organizationService.RetrieveMultiple(Helpers.CreateSolutionsQuery()).Entities.Select(x => new Solution(x)).ToArray<Solution>();
            this.Assemblies = organizationService.RetrieveMultiple(Helpers.CreateAssembliesQuery()).Entities.Select(x => new PluginAssembly(x)).ToArray<PluginAssembly>();
        }
Exemple #5
0
        public CrmUserList(IOrganizationService service, bool selectMultipleUsers, ConnectionDetail connectionDetail)
        {
            this.service = service;
            this.connectionDetail = connectionDetail;

            InitializeComponent();

            lvUsers.MultiSelect = selectMultipleUsers;
        }
 public Logic(IOrganizationService service, ConnectionDetail connectionDetail, EntityMetadata metadata, string tempPostFix, bool migrateData)
 {
     SupportsExecuteMultipleRequest = connectionDetail.OrganizationMajorVersion >= Crm2013 ||
                                      (connectionDetail.OrganizationMajorVersion >= Crm2011 && int.Parse(connectionDetail.OrganizationVersion.Split('.')[3]) >= Rollup12);
     Service = service;
     TempPostfix = tempPostFix;
     MigrateData = migrateData;
     ValidLanguageCodes = GetValidLanguageCodes();
     Metadata = metadata;
 }
        public void UpdateConnection(IOrganizationService newService, ConnectionDetail connectionDetail, string actionName = "", object parameter = null)
        {
            service = newService;

            switch (actionName)
            {
                case "LoadMetadata":
                {
                    LoadMetadata();
                }
                    break;
            }
        }
 public void UpdateConnection(Microsoft.Xrm.Sdk.IOrganizationService newService, ConnectionDetail connectionDetail, string actionName = "", object parameter = null)
 {
     if (actionName == "TargetOrganization")
     {
         targetService = newService;
         SetConnectionLabel(connectionDetail, "Target");
     }
     else
     {
         service = newService;
         SetConnectionLabel(connectionDetail, "Source");
     }
 }
 /// <summary>
 /// override the UpdateConnection method so we can use two connections here
 /// </summary>
 /// <param name="newService"></param>
 /// <param name="detail"></param>
 /// <param name="actionName"></param>
 /// <param name="parameter"></param>
 public override 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, 2, 0, 0);
     }
     else
     {
         _service = newService;
         SetConnectionLabel(_service, "Source");
         ((OrganizationServiceProxy)((OrganizationService)_service).InnerService).Timeout = new TimeSpan(0, 2, 0, 0);
     }
 }
 public void UpdateConnection(IOrganizationService newService, ConnectionDetail detail, string actionName = "", object parameter = null)
 {
     this.detail = detail;
     if (actionName == "TargetOrganization")
     {
         targetService = newService;
         SetConnectionLabel(detail, "Target");
     }
     else
     {
         service = newService;
         SetConnectionLabel(detail, "Source");
         RetrieveSolutions();
     }
 }
 public void UpdateConnection(Microsoft.Xrm.Sdk.IOrganizationService newService, ConnectionDetail connectionDetail, string actionName = "", object parameter = null)
 {
     if (actionName == "TargetOrganization")
     {
         targetService = newService;
         SetConnectionLabel(connectionDetail, "Target");
         ((OrganizationServiceProxy)((OrganizationService)targetService).InnerService).Timeout = new TimeSpan(
             0, 1, 0, 0);
     }
     else
     {
         service = newService;
         SetConnectionLabel(connectionDetail, "Source");
         ((OrganizationServiceProxy)((OrganizationService)service).InnerService).Timeout = new TimeSpan(0, 1, 0, 0);
         LoadEntities();
     }
 }
 public void UpdateAfterEdit(ConnectionDetail editedConnection)
 {
     ConnectionName         = editedConnection.ConnectionName;
     OrganizationServiceUrl = editedConnection.OrganizationServiceUrl;
     CrmTicket                = editedConnection.CrmTicket;
     IsCustomAuth             = editedConnection.IsCustomAuth;
     Organization             = editedConnection.Organization;
     OrganizationFriendlyName = editedConnection.OrganizationFriendlyName;
     ServerName               = editedConnection.ServerName;
     ServerPort               = editedConnection.ServerPort;
     UseIfd       = editedConnection.UseIfd;
     UseOnline    = editedConnection.UseOnline;
     UseOsdp      = editedConnection.UseOsdp;
     UserDomain   = editedConnection.UserDomain;
     UserName     = editedConnection.UserName;
     userPassword = editedConnection.userPassword;
     UseSsl       = editedConnection.UseSsl;
     HomeRealmUrl = editedConnection.HomeRealmUrl;
 }
        public static OrganizationServiceProxy GetOrganizationServiceProxy(ConnectionDetail detail)
        {
            var    serviceUrl   = detail.OrganizationServiceUrl;
            string homeRealmUrl = null;

            ClientCredentials clientCredentials = new ClientCredentials();
            ClientCredentials deviceCredentials = null;

            if (detail.IsCustomAuth)
            {
                string username = detail.UserName;
                if (!string.IsNullOrEmpty(detail.UserDomain))
                {
                    username = $"{detail.UserDomain}\\{detail.UserName}";
                }
                clientCredentials.UserName.UserName = username;
                clientCredentials.UserName.Password = detail.UserPassword;
            }

            if (detail.UseOnline && !detail.UseOsdp)
            {
                do
                {
                    deviceCredentials = DeviceIdManager.LoadDeviceCredentials() ??
                                        DeviceIdManager.RegisterDevice();
                } while (deviceCredentials.UserName.Password.Contains(";") ||
                         deviceCredentials.UserName.Password.Contains("=") ||
                         deviceCredentials.UserName.Password.Contains(" ") ||
                         deviceCredentials.UserName.UserName.Contains(";") ||
                         deviceCredentials.UserName.UserName.Contains("=") ||
                         deviceCredentials.UserName.UserName.Contains(" "));
            }

            if (detail.UseIfd && !string.IsNullOrEmpty(detail.HomeRealmUrl))
            {
                homeRealmUrl = detail.HomeRealmUrl;
            }

            Uri serviceUri   = new Uri(serviceUrl);
            Uri homeRealmUri = homeRealmUrl == null ? null : Uri.IsWellFormedUriString(homeRealmUrl, UriKind.RelativeOrAbsolute) ? new Uri(homeRealmUrl) : null;

            return(new OrganizationServiceProxy(serviceUri, homeRealmUri, clientCredentials, deviceCredentials));
        }
        public ConnectionDetail CloneConnection(ConnectionDetail detail)
        {
            var newDetail = (ConnectionDetail)detail.Clone();

            newDetail.ConnectionId = Guid.NewGuid();

            int    cloneId = 0;
            string newName;

            do
            {
                cloneId++;
                newName = string.Format("{0} ({1})", newDetail.ConnectionName, cloneId);
            } while (Connections.Any(c => c.ConnectionName == newName));

            newDetail.ConnectionName = newName;

            Connections.Add(newDetail);

            return(newDetail);
        }
        /// <summary>
        /// Retrieves main forms for the specified entity
        /// </summary>
        /// <param name="logicalName">Entity logical name</param>
        /// <param name="oService">Crm organization service</param>
        /// <returns>Document containing all forms definition</returns>
        public static XmlDocument RetrieveEntityForms(string logicalName, IOrganizationService oService, ConnectionDetail detail)
        {
            var qe = new QueryExpression("systemform")
            {
                Criteria = new FilterExpression
                {
                    Conditions =
                    {
                        new ConditionExpression("objecttypecode", ConditionOperator.Equal, logicalName),
                        new ConditionExpression("type", ConditionOperator.In, new[] {2, 7}),
                    }
                },
                ColumnSet = new ColumnSet(true)
            };

            if (detail.OrganizationMajorVersion > 5)
            {
                qe.Criteria.Conditions.Add(new ConditionExpression("formactivationstate", ConditionOperator.Equal, 1));
            }

            EntityCollection ec = oService.RetrieveMultiple(qe);

            StringBuilder allFormsXml = new StringBuilder();
            allFormsXml.Append("<root>");

            foreach (Entity form in ec.Entities)
            {
                allFormsXml.Append(form["formxml"]);
            }

            allFormsXml.Append("</root>");

            XmlDocument docAllForms = new XmlDocument();
            docAllForms.LoadXml(allFormsXml.ToString());

            return docAllForms;
        }
        public bool IsConnectionBrokenWithUpdatedData(ConnectionDetail originalDetail)
        {
            if (originalDetail == null)
            {
                return(true);
            }
            if (originalDetail.HomeRealmUrl != HomeRealmUrl ||
                originalDetail.IsCustomAuth != IsCustomAuth ||
                originalDetail.Organization != Organization ||
                originalDetail.ServerName.ToLower() != ServerName.ToLower() ||
                originalDetail.ServerPort != ServerPort ||
                originalDetail.UseIfd != UseIfd ||
                originalDetail.UseOnline != UseOnline ||
                originalDetail.UseOsdp != UseOsdp ||
                originalDetail.UseSsl != UseSsl ||
                originalDetail.UserDomain.ToLower() != UserDomain.ToLower() ||
                originalDetail.UserName.ToLower() != UserName.ToLower() ||
                (SavePassword && !string.IsNullOrEmpty(userPassword) && originalDetail.userPassword != userPassword))
            {
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Updates the organization service used by the tool
        /// </summary>
        /// <param name="newService">Organization service</param>
        /// <param name="detail">Details of the connection</param>
        /// <param name="actionName">Action that requested a service update</param>
        /// <param name="parameter">Parameter passed when requesting a service update</param>
        public void UpdateConnection(IOrganizationService newService, ConnectionDetail detail, string actionName = "", object parameter = null)
        {
            service = newService;

            if (actionName == "WhoAmI")
            {
                ProcessWhoAmI();
            }
        }
Exemple #18
0
 public RequestPasswordEventArgs(ConnectionDetail connectionDetail)
 {
     ConnectionDetail = connectionDetail;
 }
Exemple #19
0
 /// <summary>
 /// Launch the Crm connection process
 /// </summary>
 /// <param name="detail">Details of the Crm connection</param>
 public void ConnectToServer(ConnectionDetail detail)
 {
     ConnectToServer(detail, null);
 }
 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();
     }
 }
 public UserSettingsHelper(IOrganizationService service, ConnectionDetail detail)
 {
     this.service = service;
     this.detail = detail;
 }
        private void SetConnectionLabel(ConnectionDetail detail, string serviceType)
        {
            switch (serviceType)
            {
                case "Source":
                    lbSourceValue.Text = detail.ConnectionName;
                    lbSourceValue.ForeColor = Color.Green;
                    break;

                case "Target":
                    lbTargetValue.Text = detail.ConnectionName;
                    lbTargetValue.ForeColor = Color.Green;
                    break;
            }
        }
Exemple #23
0
        private void ManageConnectionControl()
        {
            cManager = ConnectionManager.Instance;
            cManager.RequestPassword += (sender, e) => fHelper.RequestPassword(e.ConnectionDetail);
            cManager.StepChanged += (sender, e) => ccsb.SetMessage(e.CurrentStep);
            cManager.ConnectionSucceed += (sender, e) =>
            {
                var parameter = e.Parameter as ConnectionParameterInfo;
                if (parameter != null)
                {
                    Controls.Remove(parameter.InfoPanel);
                    parameter.InfoPanel.Dispose();
                }

                currentConnectionDetail = e.ConnectionDetail;
                service = e.OrganizationService;
                ccsb.SetConnectionStatus(true, e.ConnectionDetail);
                ccsb.SetMessage(string.Empty);

                if (parameter != null)
                {
                    var control = parameter.ConnectionParmater as UserControl;
                    if (control != null)
                    {
                        var pluginModel = control.Tag as Lazy<IXrmToolBoxPlugin, IPluginMetadata>;
                        if (pluginModel == null)
                        {
                            // Actual Plugin was passed, Just update the plugin's Tab.
                            UpdateTabConnection((TabPage)control.Parent);
                        }
                        else
                        {
                            this.DisplayPluginControl(pluginModel);
                        }
                    }
                    else if (parameter.ConnectionParmater.ToString() == "ApplyConnectionToTabs" && tabControl1.TabPages.Count > 1)
                    {
                        ApplyConnectionToTabs();
                    }
                    else
                    {
                        var args = parameter.ConnectionParmater as RequestConnectionEventArgs;
                        if (args != null)
                        {
                            var userControl = (UserControl)args.Control;

                            args.Control.UpdateConnection(e.OrganizationService, currentConnectionDetail, args.ActionName, args.Parameter);

                            userControl.Parent.Text = string.Format("{0} ({1})",
                                userControl.Parent.Text.Split(' ')[0],
                                e.ConnectionDetail.ConnectionName);
                        }
                    }
                }
                else if (tabControl1.TabPages.Count > 1)
                {
                    ApplyConnectionToTabs();
                }

                this.StartPluginWithConnection();
            };
            cManager.ConnectionFailed += (sender, e) =>
            {
                this.Invoke(new Action(() =>
                {
                    var infoPanel = ((ConnectionParameterInfo)e.Parameter).InfoPanel;
                    Controls.Remove(infoPanel);
                    if (infoPanel != null) infoPanel.Dispose();

                    MessageBox.Show(this, e.FailureReason, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    currentConnectionDetail = null;
                    service = null;
                    ccsb.SetConnectionStatus(false, null);
                    ccsb.SetMessage(e.FailureReason);

                    this.StartPluginWithConnection();
                }));
            };

            fHelper = new FormHelper(this);
            ccsb = new CrmConnectionStatusBar(fHelper) { Dock = DockStyle.Bottom };
            Controls.Add(ccsb);
        }
Exemple #24
0
 private Task launchInitialConnection(ConnectionDetail connectionDetail)
 {
     return new Task(() => ConnectionManager.Instance.ConnectToServer(connectionDetail));
 }
 public void UpdateAfterEdit(ConnectionDetail editedConnection)
 {
     ConnectionName = editedConnection.ConnectionName;
     OrganizationServiceUrl = editedConnection.OrganizationServiceUrl;
     CrmTicket = editedConnection.CrmTicket;
     IsCustomAuth = editedConnection.IsCustomAuth;
     Organization = editedConnection.Organization;
     OrganizationFriendlyName = editedConnection.OrganizationFriendlyName;
     ServerName = editedConnection.ServerName;
     ServerPort = editedConnection.ServerPort;
     UseIfd = editedConnection.UseIfd;
     UseOnline = editedConnection.UseOnline;
     UseOsdp = editedConnection.UseOsdp;
     UserDomain = editedConnection.UserDomain;
     UserName = editedConnection.UserName;
     userPassword = editedConnection.userPassword;
     UseSsl = editedConnection.UseSsl;
     HomeRealmUrl = editedConnection.HomeRealmUrl;
 }
        public bool IsConnectionBrokenWithUpdatedData(ConnectionDetail originalDetail)
        {
            if (originalDetail == null)
            {
                return true;
            }
            if (originalDetail.HomeRealmUrl != HomeRealmUrl
               || originalDetail.IsCustomAuth != IsCustomAuth
               || originalDetail.Organization != Organization
               || originalDetail.ServerName.ToLower() != ServerName.ToLower()
               || originalDetail.ServerPort != ServerPort
               || originalDetail.UseIfd != UseIfd
               || originalDetail.UseOnline != UseOnline
               || originalDetail.UseOsdp != UseOsdp
               || originalDetail.UseSsl != UseSsl
               || originalDetail.UserDomain.ToLower() != UserDomain.ToLower()
               || originalDetail.UserName.ToLower() != UserName.ToLower()
               || (SavePassword && !string.IsNullOrEmpty(userPassword) && originalDetail.userPassword != userPassword))
            {
                return true;
            }

            return false;
        }
Exemple #27
0
        public static CrmConnections LoadFromFile(string filePath)
        {
            var crmConnections = new CrmConnections();

            if (!File.Exists(filePath))
            {
                return(crmConnections);
            }

            using (var fStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                if (fStream.Length == 0)
                {
                    return(crmConnections);
                }

                var doc = XDocument.Load(fStream);
                var crmConnectionsElt = doc.Element("CrmConnections");
                if (crmConnectionsElt == null)
                {
                    return(crmConnections);
                }

                var connectionsElt = crmConnectionsElt.Element("Connections");
                if (connectionsElt == null)
                {
                    return(crmConnections);
                }

                var useMruDisplayElt = connectionsElt.Element("UseMruDisplay");
                if (useMruDisplayElt != null)
                {
                    crmConnections.UseMruDisplay = useMruDisplayElt.Value == "true";
                }

                var proxyElt = connectionsElt.Element("Proxy");
                if (proxyElt != null)
                {
                    var useCustomProxyElt = proxyElt.Element("UseCustomProxy");
                    if (useCustomProxyElt != null)
                    {
                        crmConnections.UseCustomProxy = useCustomProxyElt.Value == "true";
                    }
                    var useInternetExplorerProxyElt = proxyElt.Element("UseInternetExplorerProxy");
                    if (useInternetExplorerProxyElt != null)
                    {
                        crmConnections.UseInternetExplorerProxy = useInternetExplorerProxyElt.Value == "true";
                    }
                    var addressElt = proxyElt.Element("Address");
                    if (addressElt != null)
                    {
                        crmConnections.ProxyAddress = addressElt.Value;
                    }
                    var usernameElt = proxyElt.Element("Username");
                    if (usernameElt != null)
                    {
                        crmConnections.UserName = usernameElt.Value;
                    }
                    var passwordElt = proxyElt.Element("Password");
                    if (passwordElt != null)
                    {
                        crmConnections.Password = passwordElt.Value;
                    }
                    var byPassProxyOnLocalElt = proxyElt.Element("ByPassProxyOnLocal");
                    if (byPassProxyOnLocalElt != null)
                    {
                        crmConnections.ByPassProxyOnLocal = byPassProxyOnLocalElt.Value == "true";
                    }
                    var useDefaultCredentialsElt = proxyElt.Element("UseDefaultCredentials");
                    if (useDefaultCredentialsElt != null)
                    {
                        crmConnections.UseDefaultCredentials = useDefaultCredentialsElt.Value == "true";
                    }
                }

                foreach (var elt in doc.Descendants("ConnectionDetail"))
                {
                    var cd = new ConnectionDetail();

                    var authElement = elt.Element("AuthType");
                    if (authElement != null)
                    {
                        cd.AuthType =
                            (AuthenticationProviderType)
                            Enum.Parse(typeof(AuthenticationProviderType), authElement.Value);
                    }

                    var connectionIdElement = elt.Element("ConnectionId");
                    cd.ConnectionId = connectionIdElement != null ? new Guid(connectionIdElement.Value) : Guid.NewGuid();

                    var connectionNameElement = elt.Element("ConnectionName");
                    cd.ConnectionName = connectionNameElement != null ? connectionNameElement.Value : null;

                    var homeRealmUrlElement = elt.Element("HomeRealmUrl");
                    cd.HomeRealmUrl = homeRealmUrlElement != null ? homeRealmUrlElement.Value : null;

                    var isCustomAuthElement = elt.Element("IsCustomAuth");
                    cd.IsCustomAuth = isCustomAuthElement != null && isCustomAuthElement.Value == "true";

                    var organizationElement = elt.Element("Organization");
                    if (organizationElement != null)
                    {
                        cd.Organization = organizationElement.Value;
                    }

                    var originalUrlElement = elt.Element("OriginalUrl");
                    if (originalUrlElement != null)
                    {
                        cd.OriginalUrl = originalUrlElement.Value;
                    }

                    var organizationFriendlyNameElement = elt.Element("OrganizationFriendlyName");
                    if (organizationFriendlyNameElement != null)
                    {
                        cd.OrganizationFriendlyName = organizationFriendlyNameElement.Value;
                    }

                    var organizationServiceUrlElement = elt.Element("OrganizationServiceUrl");
                    if (organizationServiceUrlElement != null)
                    {
                        cd.OrganizationServiceUrl = organizationServiceUrlElement.Value;
                    }

                    var organizationDataServiceUrlElement = elt.Element("OrganizationDataServiceUrl");
                    if (organizationDataServiceUrlElement != null)
                    {
                        cd.OrganizationDataServiceUrl = organizationDataServiceUrlElement.Value;
                    }

                    var organizationUrlNameElement = elt.Element("OrganizationUrlName");
                    if (organizationUrlNameElement != null)
                    {
                        cd.OrganizationUrlName = organizationUrlNameElement.Value;
                    }

                    var organizationVersionElement = elt.Element("OrganizationVersion");
                    if (organizationVersionElement != null)
                    {
                        cd.OrganizationVersion = organizationVersionElement.Value;
                    }

                    var savePasswordElement = elt.Element("SavePassword");
                    cd.SavePassword = savePasswordElement != null && savePasswordElement.Value == "true";

                    var serverNameElement = elt.Element("ServerName");
                    if (serverNameElement != null)
                    {
                        cd.ServerName = serverNameElement.Value;
                    }

                    var serverPortElement = elt.Element("ServerPort");
                    if (serverPortElement != null)
                    {
                        int serverPort = string.IsNullOrEmpty(serverPortElement.Value)
                            ? 80
                            : int.Parse(serverPortElement.Value);

                        cd.ServerPort = serverPort;
                    }

                    var timeOutElement = elt.Element("Timeout");
                    if (timeOutElement != null)
                    {
                        long timeoutValue = string.IsNullOrEmpty(timeOutElement.Value)
                           ? 1200000000
                           : long.Parse(timeOutElement.Value);

                        cd.TimeoutTicks = timeoutValue;
                    }

                    var useIfdElement = elt.Element("UseIfd");
                    cd.UseIfd = useIfdElement != null && useIfdElement.Value == "true";
                    var useOnlineElement = elt.Element("UseOnline");
                    cd.UseOnline = useOnlineElement != null && useOnlineElement.Value == "true";
                    var useOsdpElement = elt.Element("UseOsdp");
                    cd.UseOsdp = useOsdpElement != null && useOsdpElement.Value == "true";
                    var useSslElement = elt.Element("UseSsl");
                    cd.UseSsl = useSslElement != null && useSslElement.Value == "true";

                    var userDomainElement = elt.Element("UserDomain");
                    if (timeOutElement != null)
                    {
                        cd.UserDomain = userDomainElement.Value;
                    }

                    var userNameElement = elt.Element("UserName");
                    if (userNameElement != null)
                    {
                        cd.UserName = userNameElement.Value;
                    }

                    var userPasswordElement = elt.Element("UserPassword");
                    if (userPasswordElement != null)
                    {
                        cd.SetPassword(userPasswordElement.Value, true);
                    }

                    var webApplicationUrlElement = elt.Element("WebApplicationUrl");
                    if (webApplicationUrlElement != null)
                    {
                        cd.WebApplicationUrl = webApplicationUrlElement.Value;
                    }

                    var lastUsedOnElt = elt.Element("LastUsedOn");
                    if (lastUsedOnElt != null)
                    {
                        cd.LastUsedOn = DateTime.Parse(lastUsedOnElt.Value, CultureInfo.InvariantCulture.DateTimeFormat);
                    }

                    var customInfo = elt.Element("CustomInformation");
                    if (customInfo != null)
                    {
                        cd.CustomInformation = new Dictionary <string, string>();
                        foreach (var custel in customInfo.Elements())
                        {
                            cd.CustomInformation.Add(custel.Name.LocalName, custel.Value);
                        }
                    }

                    crmConnections.Connections.Add(cd);
                }
            }

            return(crmConnections);
        }
 /// <summary>
 /// Launch the Crm connection process
 /// </summary>
 /// <param name="detail">Details of the Crm connection</param>
 public void ConnectToServer(ConnectionDetail detail)
 {
     ConnectToServer(detail, null);
 }
Exemple #29
0
 public RuleManager(string entityName, IOrganizationService service, ConnectionDetail detail)
 {
     this.entityName = entityName;
     this.service = service;
     this.detail = detail;
 }
        /// <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 static CrmConnections LoadFromFile(string filePath)
        {
            var crmConnections = new CrmConnections();

            if (!File.Exists(filePath))
            {
                return crmConnections;
            }

            using (var fStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                if (fStream.Length == 0)
                {
                    return crmConnections;
                }

                var doc = XDocument.Load(fStream);
                var crmConnectionsElt = doc.Element("CrmConnections");
                if (crmConnectionsElt == null)
                    return crmConnections;

                var connectionsElt = crmConnectionsElt.Element("Connections");
                if (connectionsElt == null)
                    return crmConnections;

                 var useMruDisplayElt = connectionsElt.Element("UseMruDisplay");
                if (useMruDisplayElt != null)
                {
                    crmConnections.UseMruDisplay = useMruDisplayElt.Value == "true";
                }

                var proxyElt = connectionsElt.Element("Proxy");
                if (proxyElt != null)
                {
                    var useCustomProxyElt = proxyElt.Element("UseCustomProxy");
                    if(useCustomProxyElt != null)
                        crmConnections.UseCustomProxy = useCustomProxyElt.Value == "true";
                    var useInternetExplorerProxyElt = proxyElt.Element("UseInternetExplorerProxy");
                    if (useInternetExplorerProxyElt != null)
                        crmConnections.UseInternetExplorerProxy = useInternetExplorerProxyElt.Value == "true";
                    var addressElt = proxyElt.Element("Address");
                    if (addressElt != null)
                        crmConnections.ProxyAddress = addressElt.Value;
                    var usernameElt = proxyElt.Element("Username");
                    if (usernameElt != null)
                        crmConnections.UserName = usernameElt.Value;
                    var passwordElt = proxyElt.Element("Password");
                    if (passwordElt != null)
                        crmConnections.Password = passwordElt.Value;
                    var byPassProxyOnLocalElt = proxyElt.Element("ByPassProxyOnLocal");
                    if (byPassProxyOnLocalElt != null)
                        crmConnections.ByPassProxyOnLocal = byPassProxyOnLocalElt.Value == "true";
                    var useDefaultCredentialsElt = proxyElt.Element("UseDefaultCredentials");
                    if (useDefaultCredentialsElt != null)
                        crmConnections.UseDefaultCredentials = useDefaultCredentialsElt.Value == "true";
                }

                foreach (var elt in doc.Descendants("ConnectionDetail"))
                {
                    var cd = new ConnectionDetail();

                    var authElement = elt.Element("AuthType");
                    if (authElement != null)
                    {
                        cd.AuthType =
                            (AuthenticationProviderType)
                                Enum.Parse(typeof (AuthenticationProviderType), authElement.Value);
                    }

                    var connectionIdElement = elt.Element("ConnectionId");
                    cd.ConnectionId = connectionIdElement != null ? new Guid(connectionIdElement.Value) : Guid.NewGuid();

                    var connectionNameElement = elt.Element("ConnectionName");
                    cd.ConnectionName = connectionNameElement != null ? connectionNameElement.Value : null;

                    var homeRealmUrlElement = elt.Element("HomeRealmUrl");
                    cd.HomeRealmUrl = homeRealmUrlElement != null ? homeRealmUrlElement.Value : null;

                    var isCustomAuthElement = elt.Element("IsCustomAuth");
                    cd.IsCustomAuth = isCustomAuthElement != null && isCustomAuthElement.Value == "true";

                    var organizationElement = elt.Element("Organization");
                    if (organizationElement != null)
                    {
                        cd.Organization = organizationElement.Value;
                    }

                    var organizationFriendlyNameElement = elt.Element("OrganizationFriendlyName");
                    if (organizationFriendlyNameElement != null)
                    {
                        cd.OrganizationFriendlyName = organizationFriendlyNameElement.Value;
                    }

                    var organizationServiceUrlElement = elt.Element("OrganizationServiceUrl");
                    if (organizationServiceUrlElement != null)
                    {
                        cd.OrganizationServiceUrl = organizationServiceUrlElement.Value;
                    }

                    var organizationUrlNameElement = elt.Element("OrganizationUrlName");
                    if (organizationUrlNameElement != null)
                    {
                        cd.OrganizationUrlName = organizationUrlNameElement.Value;
                    }

                    var organizationVersionElement = elt.Element("OrganizationVersion");
                    if (organizationVersionElement != null)
                    {
                        cd.OrganizationVersion = organizationVersionElement.Value;
                    }

                    var savePasswordElement = elt.Element("SavePassword");
                    cd.SavePassword = savePasswordElement != null && savePasswordElement.Value == "true";

                    var serverNameElement = elt.Element("ServerName");
                    if (serverNameElement != null)
                    {
                        cd.ServerName = serverNameElement.Value;
                    }

                    var serverPortElement = elt.Element("ServerPort");
                    if (serverPortElement != null)
                    {
                        int serverPort = string.IsNullOrEmpty(serverPortElement.Value)
                            ? 80
                            : int.Parse(serverPortElement.Value);

                        cd.ServerPort = serverPort;
                    }

                    var timeOutElement = elt.Element("Timeout");
                    if (timeOutElement != null)
                    {
                         long timeoutValue = string.IsNullOrEmpty(timeOutElement.Value)
                            ? 1200000000
                            : long.Parse(timeOutElement.Value);

                        cd.TimeoutTicks = timeoutValue;
                    }

                    var useIfdElement = elt.Element("UseIfd");
                    cd.UseIfd = useIfdElement != null && useIfdElement.Value == "true";
                    var useOnlineElement = elt.Element("UseOnline");
                    cd.UseOnline = useOnlineElement != null && useOnlineElement.Value == "true";
                    var useOsdpElement = elt.Element("UseOsdp");
                    cd.UseOsdp = useOsdpElement != null && useOsdpElement.Value == "true";
                    var useSslElement = elt.Element("UseSsl");
                    cd.UseSsl = useSslElement != null && useSslElement.Value == "true";

                    var userDomainElement = elt.Element("UserDomain");
                    if (timeOutElement != null)
                    {
                        cd.UserDomain = userDomainElement.Value;
                    }

                    var userNameElement = elt.Element("UserName");
                    if (userNameElement != null)
                    {
                        cd.UserName = userNameElement.Value;
                    }

                    var userPasswordElement = elt.Element("UserPassword");
                    if (userPasswordElement != null)
                    {
                        cd.SetPassword(userPasswordElement.Value, true);
                    }

                    var webApplicationUrlElement = elt.Element("WebApplicationUrl");
                    if (webApplicationUrlElement != null)
                    {
                        cd.WebApplicationUrl = webApplicationUrlElement.Value;
                    }

                    var lastUsedOnElt = elt.Element("LastUsedOn");
                    if (lastUsedOnElt != null)
                    {
                        cd.LastUsedOn = DateTime.Parse(lastUsedOnElt.Value, CultureInfo.InvariantCulture.DateTimeFormat);
                    }

                    crmConnections.Connections.Add(cd);
                }
            }

            return crmConnections;
        }
        /// <summary>
        /// Launch the Crm connection process
        /// </summary>
        /// <param name="detail">Details of the Crm connection</param>
        /// <param name="connectionParameter">A parameter to retrieve after connection</param>
        public void ConnectToServer(ConnectionDetail detail, object connectionParameter)
        {
            var parameters = new List<object> { detail, connectionParameter };

            // Runs the connection asynchronously
            var worker = new BackgroundWorker();
            worker.DoWork += WorkerDoWork;
            worker.RunWorkerCompleted += WorkerRunWorkerCompleted;
            worker.RunWorkerAsync(parameters);
        }
 public void CopyPasswordTo(ConnectionDetail detail)
 {
     detail.userPassword = userPassword;
 }
 public RequestPasswordEventArgs(ConnectionDetail connectionDetail)
 {
     ConnectionDetail = connectionDetail;
 }
        public bool IsConnectionBrokenWithUpdatedData(ConnectionDetail updatedDetail)
        {
            if (updatedDetail.AuthType != AuthType
               || updatedDetail.CrmTicket != CrmTicket
               || updatedDetail.HomeRealmUrl != HomeRealmUrl
               || updatedDetail.IsCustomAuth != IsCustomAuth
               || updatedDetail.Organization != Organization
               || updatedDetail.OrganizationFriendlyName != OrganizationFriendlyName
               || updatedDetail.OrganizationServiceUrl != OrganizationServiceUrl
               || updatedDetail.OrganizationUrlName != OrganizationUrlName
               || updatedDetail.ServerName != ServerName
               || updatedDetail.ServerPort != ServerPort
               || updatedDetail.UseIfd != UseIfd
               || updatedDetail.UseOnline != UseOnline
               || updatedDetail.UseOsdp != UseOsdp
               || updatedDetail.UseSsl != UseSsl
               || updatedDetail.UserDomain != UserDomain
               || updatedDetail.UserName != UserName
               || (SavePassword && updatedDetail.userPassword != userPassword)
               || (!SavePassword && !string.IsNullOrEmpty(updatedDetail.userPassword) && updatedDetail.userPassword != userPassword))
            {
                return true;
            }

            return false;
        }
 public void CopyPasswordTo(ConnectionDetail detail)
 {
     detail.userPassword = userPassword;
 }
        private void open_FileOk(object sender, CancelEventArgs e)
        {
            var dialog = (OpenFileDialog)sender;

            if (!e.Cancel)
            {
                var document = new XmlDocument();
                document.Load(dialog.FileName);

                // TODO: re-enable and fix ((SelectParameters)this.CurrentPage).Snapshot = Helpers.LoadSolutionFile(dialog.FileName);

                var connection = new ConnectionDetail
                {
                    Organization = "ReferenceFile",
                    OrganizationFriendlyName = "Reference File",
                    OrganizationServiceUrl = dialog.FileName
                };

                this.ConnectionDetail = connection;

                this.OnConnectionUpdated(new ConnectionUpdatedEventArgs(null, connection));
            }
        }