Exemple #1
0
        private bool MigrateEntityToLocal(OrganizationServiceProxy localProxy, BinaryStorageOptions.Providers.IBinaryStorageProvider storageProvider, Entity entity, string entityName, string documentBodyKey, string filenameKey)
        {
            if (!entity.Attributes.ContainsKey(documentBodyKey))
            {
                return(true);
            }

            string filename = (string)entity.Attributes[filenameKey];

            Notify(string.Format("Migrating '{0}' with filename '{1}' External -> CRM using {2}.", entityName, entity.Id.ToString() + "_" + filename, storageProvider.GetType().Name));
            if ((string)entity.Attributes[documentBodyKey] == BinaryStorageOptions.GenericConstants.EmptyBodyContent)
            {
                byte[] data = storageProvider.Read(entity.Id, filename);
                entity.Attributes[documentBodyKey] = Convert.ToBase64String(data);
                localProxy.Update(entity);
            }
            storageProvider.Delete(entity.Id, filename);
            Notify(string.Format("Migration of '{0}' with id '{1}' DONE.", entityName, entity.Id.ToString() + "_" + filename));
            return(true);
        }
Exemple #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);
        }
Exemple #3
0
        private bool MigrateEntityToExternal(OrganizationServiceProxy localProxy, BinaryStorageOptions.Providers.IBinaryStorageProvider storageProvider, Entity entity, string entityName, string documentBodyKey, string filenameKey, bool moveAnnotations)
        {
            if (!entity.Attributes.ContainsKey(documentBodyKey) || (string)entity.Attributes[documentBodyKey] == BinaryStorageOptions.GenericConstants.EmptyBodyContent)
            {
                return(true);
            }

            string fileName = (string)entity.Attributes[filenameKey];

            Notify(string.Format("Migrating '{0}' with filename '{1}' CRM -> External using {2}.", entityName, entity.Id.ToString() + "_" + fileName, storageProvider.GetType().Name));
            if (storageProvider.Create(entity.Id, fileName, Convert.FromBase64String((string)entity.Attributes[documentBodyKey])))
            {
                Notify(string.Format("Created '{0}' with filename '{1}'", entityName, entity.Id.ToString() + "_" + fileName));
                if (entityName == BinaryStorageOptions.CrmConstants.AttachmentEntityName || moveAnnotations)
                {
                    Notify(string.Format("Removing '{0}' with filename '{1}' from CRM.", entityName, entity.Id.ToString() + "_" + fileName));
                    entity.Attributes[BinaryStorageOptions.GenericConstants.Constants[entity.LogicalName][BinaryStorageOptions.GenericConstants.DocumentBodyAttributeKey]] = BinaryStorageOptions.GenericConstants.EmptyBodyContent;
                    localProxy.Update(entity);
                }
                Notify(string.Format("Migration of '{0}' with filename '{1}' DONE.", entityName, entity.Id.ToString() + "_" + fileName));
                return(true);
            }
            return(false);
        }