Esempio n. 1
0
        private ContentTypeDefinitionRecord Acquire(ContentTypeDefinition contentTypeDefinition)
        {
            var result = _contentStorageManager
                         .Query <ContentTypeDefinitionRecord>(x => x.Name == contentTypeDefinition.Name)
                         .SingleOrDefault();

            if (result == null)
            {
                result = new ContentTypeDefinitionRecord {
                    Name = contentTypeDefinition.Name, DisplayName = contentTypeDefinition.DisplayName
                };
                _contentStorageManager.Store(result);
            }
            return(result);
        }
Esempio n. 2
0
        protected virtual ContentItem BuildNewVersion(ContentItem existingContentItem)
        {
            var contentItemRecord = existingContentItem.Record;

            // locate the existing and the current latest versions, allocate building version
            var existingItemVersionRecord = existingContentItem.VersionRecord;
            var buildingItemVersionRecord = new ContentItemVersionRecord {
                ContentItemRecord = contentItemRecord,
                Latest            = true,
                Published         = false,
                Data = existingItemVersionRecord.Data,
            };


            var latestVersion = contentItemRecord.Versions.SingleOrDefault(x => x.Latest);

            if (latestVersion != null)
            {
                latestVersion.Latest             = false;
                buildingItemVersionRecord.Number = latestVersion.Number + 1;
            }
            else
            {
                buildingItemVersionRecord.Number = contentItemRecord.Versions.Max(x => x.Number) + 1;
            }

            contentItemRecord.Versions.Add(buildingItemVersionRecord);
            _contentStorageManager.Store(buildingItemVersionRecord);

            var buildingContentItem = New(existingContentItem.ContentType);

            buildingContentItem.VersionRecord = buildingItemVersionRecord;

            var context = new VersionContentContext {
                Id                        = existingContentItem.Id,
                ContentType               = existingContentItem.ContentType,
                ContentItemRecord         = contentItemRecord,
                ExistingContentItem       = existingContentItem,
                BuildingContentItem       = buildingContentItem,
                ExistingItemVersionRecord = existingItemVersionRecord,
                BuildingItemVersionRecord = buildingItemVersionRecord,
            };

            Handlers.Invoke(handler => handler.Versioning(context), _logger);
            Handlers.Invoke(handler => handler.Versioned(context), _logger);

            return(context.BuildingContentItem);
        }
        public void Uninstall(string feature)
        {
            _logger.LogInformation("Uninstalling feature: {0}.", feature);

            var migrations = GetDataMigrations(feature);

            // apply update methods to each migration class for the module
            foreach (var migration in migrations)
            {
                // copy the object for the Linq query
                var tempMigration = migration;

                // get current version for this migration
                var dataMigrationRecord = GetDataMigrationRecord(tempMigration);

                var uninstallMethod = GetUninstallMethod(migration);
                if (uninstallMethod != null)
                {
                    uninstallMethod.Invoke(migration, new object[0]);
                }

                if (dataMigrationRecord == null)
                {
                    continue;
                }

                var record = _contentStorageManager.Query <DataMigrationDocument>(x => x != null).Single();
                record.DataMigrationRecords.Remove(dataMigrationRecord);
                _contentStorageManager.Store(record);
            }
        }
        public void UpdateShellDescriptor(int priorSerialNumber, IEnumerable <ShellFeature> enabledFeatures, IEnumerable <ShellParameter> parameters)
        {
            ShellDescriptorRecord shellDescriptorRecord = GetDescriptorRecord();
            var serialNumber = shellDescriptorRecord == null ? 0 : shellDescriptorRecord.SerialNumber;

            if (priorSerialNumber != serialNumber)
            {
                throw new InvalidOperationException(T("Invalid serial number for shell descriptor").ToString());
            }

            _logger.LogInformation("Updating shell descriptor for shell '{0}'...", _shellSettings.Name);

            if (shellDescriptorRecord == null)
            {
                shellDescriptorRecord = new ShellDescriptorRecord {
                    SerialNumber = 1
                };
                _contentStorageManager.Store(shellDescriptorRecord);
            }
            else
            {
                shellDescriptorRecord.SerialNumber++;
            }

            shellDescriptorRecord.Features.Clear();
            foreach (var feature in enabledFeatures)
            {
                shellDescriptorRecord.Features.Add(new ShellFeatureRecord {
                    Name = feature.Name, ShellDescriptorRecord = shellDescriptorRecord
                });
            }
            _logger.LogDebug("Enabled features for shell '{0}' set: {1}.", _shellSettings.Name, string.Join(", ", enabledFeatures.Select(feature => feature.Name)));


            shellDescriptorRecord.Parameters.Clear();
            foreach (var parameter in parameters)
            {
                shellDescriptorRecord.Parameters.Add(new ShellParameterRecord {
                    Component             = parameter.Component,
                    Name                  = parameter.Name,
                    Value                 = parameter.Value,
                    ShellDescriptorRecord = shellDescriptorRecord
                });
            }
            _logger.LogDebug("Parameters for shell '{0}' set: {1}.", _shellSettings.Name, string.Join(", ", parameters.Select(parameter => parameter.Name + "-" + parameter.Value)));

            _logger.LogInformation("Shell descriptor updated for shell '{0}'.", _shellSettings.Name);

            //_eventNotifier.Notify<IShellDescriptorManagerEventHandler>(
            //    e => e.Changed(GetShellDescriptorFromRecord(shellDescriptorRecord), _shellSettings.Name));
        }
Esempio n. 5
0
 public void Store(ContentItem contentItem)
 {
     _contentStorageManager.Store(contentItem.Record);
     _contentStorageManager.Store(contentItem.VersionRecord);
 }