예제 #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] == GenericConstants.EmptyBodyContent)
            {
                byte[] data = storageProvider.Read(entity.Id, filename);
                entity.Attributes[documentBodyKey] = Convert.ToBase64String(data);
                localProxy.Update(entity);

                var query = new QueryExpression(GenericConstants.AttachementExtensionEntityName);
                query.ColumnSet = new ColumnSet(false);
                query.Criteria  = new FilterExpression(LogicalOperator.And);
                query.Criteria.AddCondition(GenericConstants.AttachementExtensionEntityNameKey, ConditionOperator.Equal, entity.LogicalName);
                query.Criteria.AddCondition(GenericConstants.AttachementExtensionEntityIdKey, ConditionOperator.Equal, entity.Id.ToString());
                DataCollection <Entity> attachementExtensionEntities = localProxy.RetrieveMultiple(query).Entities;
                if (attachementExtensionEntities != null)
                {
                    foreach (var attachementExtensionEntity in attachementExtensionEntities)
                    {
                        localProxy.Delete(attachementExtensionEntity.LogicalName, attachementExtensionEntity.Id);
                    }
                }
            }
            storageProvider.Delete(entity.Id, filename);
            Notify(string.Format("Migration of '{0}' with id '{1}' DONE.", entityName, entity.Id.ToString() + "_" + filename));
            return(true);
        }
        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);
        }
        private bool MigrateEntityLocal(OrganizationServiceProxy localProxy, BinaryStorageOptions.Providers.IBinaryStorageProvider storageProvider, Entity entity, string entityName, string documentBodyKey, string filenameKey)
        {
            string fileName = (string)entity.Attributes[filenameKey];
            ConcurrentDictionary <Guid, string> externalEntries;

            while (!allExternalFileNames.TryGetValue(entityName, out externalEntries))
            {
                System.Threading.Thread.Sleep(new Random().Next(100, 500));
            }
            if (!fileName.StartsWith(BinaryStorageOptions.Constants.ExternalFilePrefix))
            {
                //Already migrated, skip
                return(true);
            }
            Notify(string.Format("Migrating '{0}' with filename '{1}' External -> CRM using {2}.", entityName, externalEntries[entity.Id], storageProvider.GetType().Name));
            fileName = fileName.Substring(BinaryStorageOptions.Constants.ExternalFilePrefix.Length);
            byte[] data = storageProvider.Read(entity.Id, fileName);
            entity.Attributes[filenameKey]     = fileName;
            entity.Attributes[documentBodyKey] = Convert.ToBase64String(data);
            localProxy.Update(entity);
            storageProvider.Delete(externalEntries[entity.Id]);             //Use the non lookup delete method.
            Notify(string.Format("Migration of '{0}' with id '{1}' DONE.", entityName, entity.Id.ToString() + "_" + fileName));
            return(true);
        }