private FieldList GetItemFieldsInternal(ItemDefinition item, VersionUri version, CallContext context)
        {
            var            list           = new FieldList();
            ControllerType controllerType = null;

            if (item.ID == FolderId || ControllerType.GetAllNamespaces().ContainsKey(item.ID.ToGuid()) || ((controllerType = ControllerType.GetControllerType(item.ID)) != null))
            {
                list.Add(FieldIDs.Icon, Themes.MapTheme("SoftwareV2/16x16/elements.png"));
                if (controllerType != null)
                {
                    list.Add(FieldIDs.DisplayName, controllerType.Description);
                }
                AddStandardFields(list);
            }
            else
            {
                var action = ControllerAction.GetControllerAction(item.ID);
                if (action != null)
                {
                    AddActionFields(list, action);
                    AddStandardFields(list);
                }
            }
            return(list.Count == 0 ? base.GetItemFields(item, version, context) : list);
        }
        protected virtual void AddActionFields(FieldList list, ControllerAction action)
        {
            list.Add(FieldIDs.Icon, Themes.MapTheme("SoftwareV2/16x16/element.png"));
            list.Add(FieldIDs.DisplayName, action.Description);
            list.Add(FieldIds.ControllerName, action.ControllerType.ControllerName);
            list.Add(FieldIds.ControllerAction, action.ActionName);

            var dataSourceTemplateAttribute = action.MethodInfo.GetCustomAttribute <DataSourceTemplateAttribute>();

            if (dataSourceTemplateAttribute != null)
            {
                list.Add(FieldIds.DataSourceTemplate, dataSourceTemplateAttribute.DataSourceTemplate);
            }

            var dataSourceLocationAttribute = action.MethodInfo.GetCustomAttribute <DataSourceLocationAttribute>();

            if (dataSourceLocationAttribute != null)
            {
                list.Add(FieldIds.DataSourceLocation, dataSourceLocationAttribute.DataSourceLocation);
            }

            var experienceEditorButtonsAttribute = action.MethodInfo.GetCustomAttribute <ExperienceEditorButtonsAttribute>();

            if (experienceEditorButtonsAttribute != null)
            {
                list.Add(FieldIds.PageEditorButtons, experienceEditorButtonsAttribute.ExperienceEditorButtons);
            }
        }
        public override ID GetParentID(ItemDefinition itemDefinition, CallContext context)
        {
            if (context.CurrentResult != null)
            {
                return(null);
            }

            if (itemDefinition.ID == FolderId)
            {
                return(ParentId);
            }

            if (ControllerType.GetAllNamespaces().ContainsKey(itemDefinition.ID.ToGuid()))
            {
                return(FolderId);
            }

            ControllerType controller = ControllerType.GetControllerType(itemDefinition.ID);

            if (controller != null)
            {
                return(new ID(controller.ParentId));
            }

            ControllerAction action = ControllerAction.GetControllerAction(itemDefinition.ID);

            if (action != null)
            {
                return(new ID(action.ControllerType.Id));
            }

            return(base.GetParentID(itemDefinition, context));
        }
        private bool EnsureSqlVersion(ItemDefinition itemDefinition, DataProvider sqlProvider, CallContext context)
        {
            var sqlVersion = GetSqlVersion(itemDefinition.ID, context, sqlProvider);

            if (sqlVersion != null)
            {
                return(true);
            }
            if (itemDefinition.ID == FolderId ||
                ControllerType.GetAllNamespaces().ContainsKey(itemDefinition.ID.ToGuid()) ||
                ControllerType.GetAllControllers().ContainsKey(itemDefinition.ID.ToGuid()) ||
                ControllerAction.GetControllerAction(itemDefinition.ID) != null)
            {
                var parentId = GetParentID(itemDefinition, context) ?? sqlProvider.GetParentID(itemDefinition, context);
                var itemdef  = GetItemDefinition(parentId, context) ?? sqlProvider.GetItemDefinition(parentId, context);
                if (!sqlProvider.CreateItem(itemDefinition.ID, itemDefinition.Name, itemDefinition.TemplateID, itemdef, context))
                {
                    return(false);
                }

                var item           = Database.GetItem(itemDefinition.ID);
                var existingFields = new ItemChanges(item);
                foreach (Field field in item.Fields)
                {
                    existingFields.SetFieldValue(field, item[field.ID]);
                }
                sqlProvider.SaveItem(itemDefinition, existingFields, context);
                return(true);
            }
            return(false);
        }
 static CodeFirstRenderingsDataProvider()
 {
     ((INotifyCollectionChanged)TypeFilters).CollectionChanged += (sender, args) =>
     {
         ControllerAction.Clear();
         ControllerType.Clear();
     };
 }
 void AddAllActions(IDList list, ControllerType controllerType, IDList existingList)
 {
     foreach (var action in ControllerAction.GetAllActions(controllerType.Id))
     {
         if (!existingList.Contains(new ID(action.Id)))
         {
             list.Add(new ID(action.Id));
         }
     }
 }
        protected virtual void AddActionFields(FieldList list, ControllerAction action)
        {
            list.Add(FieldIDs.Icon, Themes.MapTheme("SoftwareV2/16x16/element.png"));
            list.Add(FieldIDs.DisplayName, action.Description);
            list.Add(FieldIds.ControllerName, action.ControllerType.ControllerName);
            list.Add(FieldIds.ControllerAction, action.ActionName);
            var customAttributes = action.MethodInfo.GetCustomAttributes(true);

            foreach (var item in customAttributes.OfType <ActionAttribute>()
                     .SelectMany(customAttribute => customAttribute.GetFields()))
            {
                list.Add(item.Key, item.Value);
            }
        }
        void AddAllActions(IDList list, ControllerType controllerType, CallContext context)
        {
            var sqlProvider = GetSqlProvider(Database);

            foreach (var action in ControllerAction.GetAllActions(controllerType.Id).Where(a =>
            {
                return(GetSqlVersion(new ID(a.Id), context, sqlProvider) == null);
            }))
            {
                if (!list.Contains(new ID(action.Id)))
                {
                    list.Add(new ID(action.Id));
                }
            }
        }
        public override ItemDefinition GetItemDefinition(ID itemId, CallContext context)
        {
            Assert.ArgumentNotNull(itemId, "itemId");
            Assert.ArgumentNotNull(context, "context");
            if (context.CurrentResult != null)
            {
                return(null);
            }

            if (itemId == FolderId)
            {
                return(new ItemDefinition(itemId, FolderName, FolderTemplateId, this.MasterId));
            }


            var allNamespaces = ControllerType.GetAllNamespaces();
            var nspace        = allNamespaces.ContainsKey(itemId.ToGuid()) ? allNamespaces[itemId.ToGuid()] : null;

            if (!string.IsNullOrEmpty(nspace))
            {
                return(new ItemDefinition(itemId, ItemUtil.ProposeValidItemName(nspace.Replace(".", "_")), FolderTemplateId, this.MasterId));
            }

            var type = ControllerType.GetControllerType(itemId);

            if (type != null)
            {
                return(new ItemDefinition(itemId, ItemUtil.ProposeValidItemName(type.ControllerName), FolderTemplateId, this.MasterId));
            }

            var action = ControllerAction.GetControllerAction(itemId);

            if (action != null)
            {
                return(new ItemDefinition(itemId, ItemUtil.ProposeValidItemName(action.ActionName), ControllerRenderingId, this.MasterId));
            }

            return(base.GetItemDefinition(itemId, context));
        }
        public override ItemDefinition GetItemDefinition(ID itemId, CallContext context)
        {
            Assert.ArgumentNotNull(itemId, "itemId");
            Assert.ArgumentNotNull(context, "context");
            if (GetSqlVersion(itemId, context, GetSqlProvider(Database)) != null)
            {
                return(null);
            }

            if (itemId == FolderId)
            {
                return(new ItemDefinition(itemId, FolderName, FolderTemplateId, this.MasterId));
            }


            var allNamespaces = ControllerType.GetAllNamespaces();
            var nspace        = allNamespaces.ContainsKey(itemId.ToGuid()) ? allNamespaces[itemId.ToGuid()] : null;

            if (!string.IsNullOrEmpty(nspace))
            {
                return(new ItemDefinition(itemId, nspace, FolderTemplateId, this.MasterId));
            }

            var type = ControllerType.GetControllerType(itemId);

            if (type != null)
            {
                return(new ItemDefinition(itemId, type.ControllerName, FolderTemplateId, this.MasterId));
            }

            var action = ControllerAction.GetControllerAction(itemId);

            if (action != null)
            {
                return(new ItemDefinition(itemId, action.ActionName, ControllerRenderingId, this.MasterId));
            }

            return(base.GetItemDefinition(itemId, context));
        }
        public override VersionUriList GetItemVersions(ItemDefinition itemDefinition, CallContext context)
        {
            Assert.ArgumentNotNull(itemDefinition, "itemDefinition");
            Assert.ArgumentNotNull(context, "context");

            if (context.CurrentResult != null)
            {
                return(null);
            }
            if (itemDefinition.ID == FolderId ||
                ControllerType.GetAllNamespaces().ContainsKey(itemDefinition.ID.ToGuid()) ||
                ControllerType.GetAllControllers().ContainsKey(itemDefinition.ID.ToGuid()) ||
                ControllerAction.GetControllerAction(itemDefinition.ID) != null)
            {
                VersionUriList versionUriList = new VersionUriList();
                foreach (Language language in LanguageManager.GetLanguages(Database))
                {
                    versionUriList.Add(language, Version.First);
                }
                return(versionUriList);
            }
            return(null);
        }
        public override FieldList GetItemFields(ItemDefinition item, VersionUri version, CallContext context)
        {
            Assert.ArgumentNotNull(item, "item");
            Assert.ArgumentNotNull(version, "version");
            Assert.ArgumentNotNull(context, "context");

            if (GetSqlVersion(item.ID, context, GetSqlProvider(Database)) != null)
            {
                return(null);
            }

            var            list           = new FieldList();
            ControllerType controllerType = null;

            if (item.ID == FolderId || ControllerType.GetAllNamespaces().ContainsKey(item.ID.ToGuid()) || ((controllerType = ControllerType.GetControllerType(item.ID)) != null))
            {
                list.Add(FieldIDs.Icon, Themes.MapTheme("SoftwareV2/16x16/elements.png"));
                if (controllerType != null)
                {
                    list.Add(FieldIDs.DisplayName, controllerType.Description);
                }
            }
            else
            {
                var action = ControllerAction.GetControllerAction(item.ID);
                if (action != null && HttpContext.Current != null)
                {
                    AddActionFields(list, action);
                }
            }
            if (list.Count == 0)
            {
                return(base.GetItemFields(item, version, context));
            }

            return(list);
        }