Esempio n. 1
0
 private void btnConnect_Click(object sender, EventArgs e)
 {
     try
     {
         authGroup.Enabled = false;
         txtOrganizationServiceUrl.Enabled = false;
         serviceManagement = ServiceConfigurationFactory.CreateManagement <IOrganizationService>(new Uri(txtOrganizationServiceUrl.Text));
         authCredentials   = new AuthenticationCredentials();
         if (IfdSelected)
         {
             authCredentials.ClientCredentials.UserName.UserName = txtUsername.Text;
             authCredentials.ClientCredentials.UserName.Password = txtPassword.Text;
             authCredentials = serviceManagement.Authenticate(authCredentials);
             proxy           = new OrganizationServiceProxy(serviceManagement, authCredentials.SecurityTokenResponse);
         }
         else
         {
             authCredentials.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
             proxy = new OrganizationServiceProxy(serviceManagement, authCredentials.ClientCredentials);
         }
         BinaryStorageOptions.Configuration.IConfigurationProvider annotationConfigProvider =
             BinaryStorageOptions.Configuration.Factory.GetConfigurationProvider(proxy, BinaryStorageOptions.CrmConstants.AnnotationEntityName, GetUnsecurePluginConfiguration(proxy, BinaryStorageOptions.CrmConstants.AnnotationEntityName), GetSecurePluginConfiguration(proxy, BinaryStorageOptions.CrmConstants.AnnotationEntityName));
         if (annotationConfigProvider.StorageProviderType == BinaryStorageOptions.Providers.StorageProviderType.CrmDefault)
         {
             MessageBox.Show("The provider is set to 'CrmDefault'.  This means no migration will happen.", "Default Settings", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             return;
         }
         BinaryStorageOptions.Configuration.IConfigurationProvider attachmentConfigProvider =
             BinaryStorageOptions.Configuration.Factory.GetConfigurationProvider(proxy, BinaryStorageOptions.CrmConstants.AttachmentEntityName, GetUnsecurePluginConfiguration(proxy, BinaryStorageOptions.CrmConstants.AttachmentEntityName), GetSecurePluginConfiguration(proxy, BinaryStorageOptions.CrmConstants.AttachmentEntityName));
         if (attachmentConfigProvider.StorageProviderType == BinaryStorageOptions.Providers.StorageProviderType.CrmDefault)
         {
             MessageBox.Show("The provider is set to 'CrmDefault'.  This means no migration will happen.", "Default Settings", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             return;
         }
         ShowLoadedSettings(annotationConfigProvider, attachmentConfigProvider);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Something very bad happened : " + ex.ToString(), "Oops", MessageBoxButtons.OK, MessageBoxIcon.Error);
         authGroup.Enabled = true;
         txtOrganizationServiceUrl.Enabled = false;
     }
 }
Esempio n. 2
0
        private bool MigrateEntity(Guid id, string entityName, string documentBodyKey, string filenameKey, bool moveExternal, bool moveAnnotations)
        {
            OrganizationServiceProxy localProxy = null;
            bool success = false;

            try
            {
                if (IfdSelected)
                {
                    localProxy = new OrganizationServiceProxy(serviceManagement, authCredentials.SecurityTokenResponse);
                }
                else
                {
                    localProxy = new OrganizationServiceProxy(serviceManagement, authCredentials.ClientCredentials);
                }
                BinaryStorageOptions.Configuration.IConfigurationProvider configProvider  = BinaryStorageOptions.Configuration.Factory.GetConfigurationProvider(proxy, entityName, GetUnsecurePluginConfiguration(localProxy, entityName), GetSecurePluginConfiguration(localProxy, entityName));
                BinaryStorageOptions.Providers.IBinaryStorageProvider     storageProvider = BinaryStorageOptions.Providers.Factory.GetStorageProvider(configProvider);
                Entity entity = localProxy.Retrieve(entityName, id, new ColumnSet(true));
                if (moveExternal)
                {
                    success = MigrateEntityToExternal(localProxy, storageProvider, entity, entityName, documentBodyKey, filenameKey, moveAnnotations);
                }
                else
                {
                    success = MigrateEntityToLocal(localProxy, storageProvider, entity, entityName, documentBodyKey, filenameKey);
                }
            }
            catch (Exception ex)
            {
                NotifyError(ex.ToString());
            }
            finally
            {
                if (localProxy != null)
                {
                    localProxy.Dispose();
                    localProxy = null;
                }
            }
            return(success);
        }