private string GetExternalPath(BinaryStorageOptions.Configuration.IConfigurationProvider configurationProvider) { string description = string.Format("{0} - ", configurationProvider.StorageProviderType); switch (configurationProvider.StorageProviderType) { case BinaryStorageOptions.Providers.BinaryStorageProviderType.AzureBlob: BinaryStorageOptions.Configuration.AzureBlobStorageConfiguration blobConfig = (BinaryStorageOptions.Configuration.AzureBlobStorageConfiguration)configurationProvider.Configuration; description += blobConfig.Container; break; case BinaryStorageOptions.Providers.BinaryStorageProviderType.AzureFile: BinaryStorageOptions.Configuration.AzureFileStorageConfiguration fileConfig = (BinaryStorageOptions.Configuration.AzureFileStorageConfiguration)configurationProvider.Configuration; description += (fileConfig.Share + "/" + fileConfig.Folder).TrimEnd('/'); break; } return(description); }
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()); if (annotationConfigProvider.StorageProviderType == BinaryStorageOptions.Providers.BinaryStorageProviderType.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()); if (attachmentConfigProvider.StorageProviderType == BinaryStorageOptions.Providers.BinaryStorageProviderType.CrmDefault) { MessageBox.Show("The provider is set to 'CrmDefault'. This means no migration will happen.", "Default Settings", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } migrateGroup.Text = string.Format("Connected. External Storage Provider : {0}, {1}", GetExternalPath(annotationConfigProvider), GetExternalPath(attachmentConfigProvider)); migrateGroup.Enabled = true; } catch (Exception ex) { MessageBox.Show("Something very bad happened : " + ex.ToString(), "Oops", MessageBoxButtons.OK, MessageBoxIcon.Error); authGroup.Enabled = true; txtOrganizationServiceUrl.Enabled = false; } }
private bool MigrateEntity(Guid id, string entityName, string documentBodyKey, string filenameKey, bool moveExternal) { 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()); 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); } 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); }