コード例 #1
0
        public Common.ValidationResult ValidateSettings()
        {
            var vr = new Common.ValidationResult();

            this.ValidateUserName(vr);
            if (this.DiscoveryServiceUrl.IsNullOrEmptyTrim())
            {
                var msg = string.Format(CultureInfo.CurrentUICulture, Resources.SettingsErrorMesssage, Resources.CRMAdapterSettingsWebServiceUrlDisplayName);
                vr.AddError(msg);
            }

            if (Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows Identity Foundation", false) == null)
            {
                // WIF is not installed but the CRM 2011 adapter requires it
                var msg = string.Format(CultureInfo.CurrentCulture, Resources.WIFInstallationNotFoundExceptionMessage);
                vr.AddError(msg);
            }

            const bool SkipWsValidation  = false;
            bool       validWsConnection = this.ValidateWebServiceConnection();

            // Validate the user has proper web service priviledges
            if (!SkipWsValidation && !validWsConnection)
            {
                var msg = string.Format(CultureInfo.CurrentCulture, Resources.ConnectionValidationExceptionMessage, this.UserName, this.DiscoveryServiceUrl);
                vr.AddError(msg);
            }

            List <OrganizationDetail> details = this.GetAllOrganizations(vr);

            // Validate that there are organizations in CRM and that the user can retrieve them
            if (!SkipWsValidation && validWsConnection && details.Count == 0)
            {
                var msg = string.Format(CultureInfo.CurrentCulture, Resources.NoOrganizationsExceptionMessage);
                vr.AddError(msg);
            }

            // Validate the user has proper web service priviledges
            if (!SkipWsValidation && validWsConnection && details.Count > 0)
            {
                this.GetConfiguredOrganizations(true, vr);
            }

            return(vr);
        }
コード例 #2
0
        public List <OrganizationDetail> GetAllOrganizations(Common.ValidationResult validationResult)
        {
            // Retrieve the list of all organizations
            List <OrganizationDetail> detail = new List <OrganizationDetail>();

            try
            {
                detail = ServerConnection.DiscoverOrganizations(this.DiscoveryClient).ToList();
            }
            catch (Exception ex)
            {
                if (validationResult != null)
                {
                    validationResult.AddError(string.Format(CultureInfo.CurrentUICulture, Resources.RetrieveAllCompaniesExceptionMessage, ex.Message));
                }
            }

            return(detail);
        }
        /// <summary>
        /// Returns a <c>List</c> of <c>OrganizationDetail</c> objects that contains the <c>OrganizationDetail</c>s for each of the <c>Organization</c>s 
        /// that the user specified on the install adapter is associated to
        /// </summary>
        /// <returns>Returns a <c>List</c> of <c>OrganizationDetail</c>s</returns>
        internal List<OrganizationDetail> RetrieveOrgDetails()
        {
            Common.ValidationResult vr = new Common.ValidationResult();
            List<OrganizationDetail> orgs = this.InstallAdapter.GetAllOrganizations(vr);
            if (vr.Errors.Count > 0)
            {
                TraceLog.Error(string.Format(CultureInfo.InvariantCulture, vr.Errors[0].Message));
                this.PublishExceptionConfigurationMessage(vr.Errors[0].Message);
            }

            return orgs;
        }
コード例 #4
0
        public List <NameStringValuePair> GetConfiguredOrganizations(bool forceRefresh, Common.ValidationResult vr)
        {
            List <NameStringValuePair> orgs = null;

            lock (companyListCache)
            {
                {
                    string cacheKey = this.DiscoveryServiceUrl.ToString();

                    if (companyListCache.ContainsKey(cacheKey))
                    {
                        orgs = companyListCache[cacheKey];
                        if (forceRefresh)
                        {
                            orgs.Clear();
                        }
                    }
                    else
                    {
                        orgs = new List <NameStringValuePair>();
                        companyListCache.Add(cacheKey, orgs);
                    }

                    // We requery tras set to true.
                    if (orgs.Count == 0)
                    {
                        ColumnSet cols = new ColumnSet();
                        cols.AddColumn("name");
                        var query = new QueryExpression("organization");
                        query.ColumnSet = cols;

                        string originalOrganizationName = this.OrganizationName;
                        try
                        {
                            // Loop over all of the organizations an find the ones that have been setup for integration
                            // Save off the current orgname so we can reset it.
                            foreach (OrganizationDetail detail in this.GetAllOrganizations(vr))
                            {
                                try
                                {
                                    // Set the proxy to use the proper organization
                                    this.OrganizationName = detail.UniqueName;

                                    EntityCollection organizations = this.OrganizationService.RetrieveMultiple(query);
                                    Entity           setupOrg      = organizations.Entities.FirstOrDefault();
                                    if (setupOrg != null)
                                    {
                                        orgs.Add(new NameStringValuePair()
                                        {
                                            Name = detail.FriendlyName, Value = detail.UniqueName
                                        });
                                    }
                                    else if (vr != null)
                                    {
                                        vr.AddWarning(string.Format(CultureInfo.CurrentUICulture, Resources.ConfiguredOrganizationExceptionMessage, detail.FriendlyName));
                                    }
                                }
                                catch (Exception ex)
                                {
                                    if (vr != null)
                                    {
                                        vr.AddError(string.Format(CultureInfo.CurrentUICulture, Resources.RetrieveConfiguredCompanyExceptionMessage, detail.FriendlyName, ex.Message));
                                    }
                                }
                            }
                        }
                        finally
                        {
                            // set it back to the original value
                            this.OrganizationName = originalOrganizationName;
                        }
                    }
                }
            }

            return(orgs);
        }