Ejemplo n.º 1
0
        public Task <Either <ActionResult, ContentSectionViewModel> > AddContentSection(
            Guid methodologyVersionId,
            ContentSectionAddRequest request,
            ContentListType contentType)
        {
            return(_persistenceHelper
                   .CheckEntityExists <MethodologyVersion>(methodologyVersionId)
                   .OnSuccess(CheckCanUpdateMethodology)
                   .OnSuccess(async methodology =>
            {
                var content = ContentListSelector[contentType](methodology);

                var orderForNewSection = request?.Order ??
                                         content.Max(contentSection => contentSection.Order) + 1;

                content
                .FindAll(contentSection => contentSection.Order >= orderForNewSection)
                .ForEach(contentSection => contentSection.Order++);

                var newContentSection = new ContentSection
                {
                    Id = Guid.NewGuid(),
                    Heading = "New section",
                    Order = orderForNewSection
                };

                content.Add(newContentSection);

                _context.MethodologyVersions.Update(methodology);
                await _context.SaveChangesAsync();
                return _mapper.Map <ContentSectionViewModel>(newContentSection);
            }));
        }
Ejemplo n.º 2
0
        protected override void OnLoaded(object sender, NodeEventArgs e)
        {
            base.OnLoaded(sender, e);

            _contentListType = (ContentListType)base.GetCachedData(CONTENTLISTTYPEKEY);

            if (_contentListType != null)
            {
                _fieldSettings = (List <FieldSetting>)base.GetCachedData(FIELDSETTINGSKEY);

                // check if fields need to be rebuilt. if the content type manager was restarted, fieldsettings come from cache,
                // but indexinginfos are not yet present in the lazy-filled ContentTypeManager.IndexingInfo dictionary -> call Build() to include them
                bool fieldsIncluded = true;
                foreach (var fieldSetting in _fieldSettings)
                {
                    if (fieldSetting.IndexingInfo == null)
                    {
                        fieldsIncluded = false;
                        break;
                    }
                }
                if (fieldsIncluded)
                {
                    return;
                }
            }

            Build();
            base.SetCachedData(FIELDSETTINGSKEY, _fieldSettings);
            base.SetCachedData(CONTENTLISTTYPEKEY, _contentListType);
        }
Ejemplo n.º 3
0
        // when create new
        internal static NodeData CreateNewNodeData(Node parent, NodeType nodeType, ContentListType listType, int listId)
        {
            var listTypeId    = listType == null ? 0 : listType.Id;
            var parentId      = parent == null ? 0 : parent.Id;
            var userId        = AccessProvider.Current.GetOriginalUser().Id;
            var now           = DataProvider.Current.RoundDateTime(DateTime.UtcNow);
            var name          = String.Concat(nodeType.Name, "-", now.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture));
            var path          = (parent == null) ? "/" + name : RepositoryPath.Combine(parent.Path, name);
            var versionNumber = new VersionNumber(1, 0, VersionStatus.Approved);

            var privateData = new NodeData(nodeType, listType)
            {
                IsShared   = false,
                SharedData = null,

                Id                = 0,
                NodeTypeId        = nodeType.Id,
                ContentListTypeId = listTypeId,
                ContentListId     = listId,

                ParentId  = parentId,
                Name      = name,
                Path      = path,
                Index     = 0,
                IsDeleted = false,

                CreationDate     = now,
                ModificationDate = now,
                CreatedById      = userId,
                ModifiedById     = userId,
                OwnerId          = userId,

                VersionId               = 0,
                Version                 = versionNumber,
                VersionCreationDate     = now,
                VersionModificationDate = now,
                VersionCreatedById      = userId,
                VersionModifiedById     = userId,

                Locked         = false,
                LockedById     = 0,
                ETag           = null,
                LockType       = 0,
                LockTimeout    = 0,
                LockDate       = DataProvider.Current.DateTimeMinValue,
                LockToken      = null,
                LastLockUpdate = DataProvider.Current.DateTimeMinValue,

                //TODO: IsSystem

                SavingState = default(ContentSavingState),
                ChangedData = null
            };

            privateData.VersionModificationDateChanged = false;
            privateData.VersionModifiedByIdChanged     = false;
            privateData.ModificationDateChanged        = false;
            privateData.ModifiedByIdChanged            = false;
            return(privateData);
        }
Ejemplo n.º 4
0
        public override void DeleteContentListType(ContentListType contentListType)
        {
            var ct = _schema.ContentListTypes.FirstOrDefault(p => p.Name == contentListType.Name);

            if (ct != null)
            {
                _schema.ContentListTypes.Remove(ct);
            }
        }
Ejemplo n.º 5
0
        public NodeData(NodeType nodeType, ContentListType contentListType)
        {
            staticDataIsModified = new bool[StaticDataSlotCount];
            staticData           = new object[StaticDataSlotCount];

            PropertyTypes = NodeTypeManager.GetDynamicSignature(nodeType.Id, contentListType == null ? 0 : contentListType.Id);

            dynamicData = new Dictionary <int, object>();
        }
Ejemplo n.º 6
0
        public NodeData(NodeType nodeType, ContentListType contentListType)
        {
            staticDataIsModified = new bool[StaticDataSlotCount];
            staticData           = new object[StaticDataSlotCount];

            PropertyTypes   = NodeTypeManager.GetDynamicSignature(nodeType.Id, contentListType == null ? 0 : contentListType.Id);
            TextPropertyIds = PropertyTypes.Where(p => p.DataType == DataType.Text).Select(p => p.Id).ToArray();

            dynamicData = new Dictionary <int, object>();
        }
Ejemplo n.º 7
0
        //---- when create new
        internal static NodeData CreateNewNodeData(Node parent, NodeType nodeType, ContentListType listType, int listId)
        {
            var listTypeId    = listType == null ? 0 : listType.Id;
            var parentId      = parent == null ? 0 : parent.Id;
            var userId        = AccessProvider.Current.GetOriginalUser().Id;
            var name          = String.Concat(nodeType.Name, "-", DateTime.Now.ToString("yyyyMMddHHmmss")); //Guid.NewGuid().ToString();
            var path          = (parent == null) ? "/" + name : RepositoryPath.Combine(parent.Path, name);
            var now           = DateTime.Now;
            var versionNumber = new VersionNumber(1, 0, VersionStatus.Approved);
            //---- when create new
            var privateData = new NodeData(nodeType, listType)
            {
                IsShared   = false,
                SharedData = null,

                Id                = 0,
                NodeTypeId        = nodeType.Id,
                ContentListTypeId = listTypeId,
                ContentListId     = listId,

                ParentId    = parentId,
                Name        = name,
                Path        = path,
                Index       = 0,
                IsDeleted   = false,
                IsInherited = true,

                NodeCreationDate     = now,
                NodeModificationDate = now,
                NodeCreatedById      = userId,
                NodeModifiedById     = userId,

                VersionId        = 0,
                Version          = versionNumber,
                CreationDate     = now,
                ModificationDate = now,
                CreatedById      = userId,
                ModifiedById     = userId,

                Locked         = false,
                LockedById     = 0,
                ETag           = null,
                LockType       = 0,
                LockTimeout    = 0,
                LockDate       = DataProvider.Current.DateTimeMinValue,
                LockToken      = null,
                LastLockUpdate = DataProvider.Current.DateTimeMinValue,
            };

            privateData.ModificationDateChanged     = false;
            privateData.ModifiedByIdChanged         = false;
            privateData.NodeModificationDateChanged = false;
            privateData.NodeModifiedByIdChanged     = false;
            return(privateData);
        }
Ejemplo n.º 8
0
        public override void DeleteContentListType(ContentListType contentListType)
        {
            StringBuilder sb = new StringBuilder();

            if (contentListType == null)
            {
                throw new ArgumentNullException("contentListType");
            }
            sb.Append(CreateCommentLine("Delete ContentListType '", contentListType.Name, "'"));
            sb.Append("DELETE FROM [dbo].[SchemaPropertySetsPropertyTypes] WHERE PropertySetId = ").Append(contentListType.Id).AppendLine();
            sb.Append("DELETE FROM [dbo].[SchemaPropertySets] WHERE PropertySetId = ").Append(contentListType.Id).AppendLine();
            AddScript(sb);
        }
Ejemplo n.º 9
0
 public Task <Either <ActionResult, List <ContentSectionViewModel> > > GetContentSectionsAsync(
     Guid methodologyId, ContentListType contentType)
 {
     return(_persistenceHelper
            .CheckEntityExists <Methodology>(methodologyId)
            .OnSuccess(CheckCanViewMethodology)
            .OnSuccess(EnsureMethodologyContentAndAnnexListsNotNull)
            .OnSuccess(methodology =>
     {
         var content = ContentListSelector[contentType](methodology);
         return OrderedContentSections(content);
     }));
 }
Ejemplo n.º 10
0
        protected override void OnLoaded(object sender, NodeEventArgs e)
        {
            base.OnLoaded(sender, e);

            _contentListType = (ContentListType)base.GetCachedData(CONTENTLISTTYPEKEY);
            if (_contentListType != null)
            {
                _fieldSettings = (List <FieldSetting>)base.GetCachedData(FIELDSETTINGSKEY);
                return;
            }

            Build();
            base.SetCachedData(FIELDSETTINGSKEY, _fieldSettings);
            base.SetCachedData(CONTENTLISTTYPEKEY, _contentListType);
        }
Ejemplo n.º 11
0
        private void Build(IXPathNavigable definitionXml, Dictionary <string, List <string> > bindings, bool modify)
        {
            XPathNavigator      nav   = definitionXml.CreateNavigator();
            XmlNamespaceManager nsres = new XmlNamespaceManager(nav.NameTable);
            XPathNavigator      root  = nav.SelectSingleNode("/*[1]", nsres);

            nsres.AddNamespace("x", root.NamespaceURI);
            List <FieldSetting> fieldSettings;

            Dictionary <string, FieldDescriptor> fieldDescriptorList = ParseContentTypeElement(root, nsres);

            _contentListType = ManageContentListType(fieldDescriptorList, bindings, modify, out fieldSettings);

            _fieldSettings = fieldSettings;
            SetFieldSlots();
        }
Ejemplo n.º 12
0
        private bool RemoveUnusedFields(Dictionary <string, FieldDescriptor> fieldInfoList, Dictionary <string, List <string> > oldBindings, ContentListType listType, SchemaEditor editor)
        {
            bool hasChanges = false;

            for (int i = _fieldSettings.Count - 1; i >= 0; i--)
            {
                FieldSetting oldType      = _fieldSettings[i];
                bool         needtoDelete = !fieldInfoList.ContainsKey(oldType.Name);
                if (!needtoDelete)
                {
                    FieldDescriptor newType = fieldInfoList[oldType.Name];
                    if (oldType.DataTypes.Length != newType.DataTypes.Length)
                    {
                        needtoDelete = true;
                    }
                    else
                    {
                        for (int j = 0; j < oldType.DataTypes.Length; j++)
                        {
                            if (oldType.DataTypes[j] != newType.DataTypes[j])
                            {
                                needtoDelete = true;
                                break;
                            }
                        }
                    }
                }
                if (needtoDelete)
                {
                    hasChanges = true;
                    foreach (string binding in oldType.Bindings)
                    {
                        PropertyType oldPropertyType = editor.PropertyTypes[binding];
                        editor.RemovePropertyTypeFromPropertySet(oldPropertyType, listType);
                    }
                    _fieldSettings.RemoveAt(i);
                    oldBindings.Remove(oldType.Name);
                }
            }
            return(hasChanges);
        }
Ejemplo n.º 13
0
        private FieldSetting CreateNewFieldType(FieldDescriptor fieldInfo, Dictionary <string, List <string> > newBindings, ContentListType listType, SlotTable slotTable, SchemaEditor editor)
        {
            List <string> bindList = new List <string>();

            foreach (RepositoryDataType slotType in FieldManager.GetDataTypes(fieldInfo.FieldTypeShortName))
            {
                if (slotType == RepositoryDataType.NotDefined)
                {
                    continue;
                }
                int    slotNumber = slotTable.ReserveSlot((DataType)slotType);
                string binding    = EncodeBinding(slotType, slotNumber);
                bindList.Add(binding);

                PropertyType pt = editor.PropertyTypes[binding];
                if (pt == null)
                {
                    pt = editor.CreateContentListPropertyType((DataType)slotType, slotNumber);
                }
                editor.AddPropertyTypeToPropertySet(pt, listType);
            }
            newBindings.Add(fieldInfo.FieldName, bindList);

            return(FieldSetting.Create(fieldInfo, bindList, null));
        }
Ejemplo n.º 14
0
 public override void DeleteContentListType(ContentListType contentListType)
 {
     WriteLog(MethodInfo.GetCurrentMethod(), contentListType.Name);
 }
 public void DeleteContentListType(ContentListType contentListType)
 {
     _target.GetType().GetMethod("DeleteContentListType").Invoke(_target, new object[] { contentListType });
 }
Ejemplo n.º 16
0
 public override void DeleteContentListType(ContentListType contentListType)
 {
     throw new NotSupportedException();
 }