/// <summary>
        /// Creates AutoContent which specifies a parent document
        /// </summary>
        /// <param name="values">The document property values to use</param>
        /// <param name="parentDocType">The type of the parent document</param>
        public ChildContentFactory(DocumentTypeBase values, Type parentDocType)
            : base(values)
        {
            if(parentDocType == null)
            {
                throw new ArgumentNullException("parentDocType", "ChildContentFactory requires a parent document type");
            }

            //Get the factory type of the parent type
            var attr = parentDocType.GetInitialisedAttribute<ContentFactoryAttribute>();
            if (attr == null)
            {
                throw new InvalidOperationException("Parent type '" + parentDocType.Name + "' specified for Umbraco content '" + values.NodeDetails.Name + "' does not have a [ContentFactory] or [AutoContent] attribute");
            }
            else
            {
                _parentFactory = attr.Factory;
            }
        }
 /// <summary>
 /// <para>Registers a content factory to be used to create default content for a document type</para>
 /// </summary>
 /// <param name="factory">A type with a parameterless constructor which implements IContentFactory</param>
 /// <param name="sortOrder">The sort order for the document amongst its' siblings</param>
 public ContentFactoryAttribute(Type factory, int sortOrder = 10)
 {
     _factory = Activator.CreateInstance(factory) as IContentFactory;
     SortOrder = sortOrder;
 }
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="factory">The content factory</param>
 public ContentServiceFactory(IContentFactory factory)
 {
     _factory = factory;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="api">The current api</param>
 /// <param name="factory">The content factory</param>
 public ContentTypeService(IApi api, IContentFactory factory)
 {
     _api     = api;
     _factory = factory;
 }
        private void PreprocessElement(XmlDocument document, XmlElement element, ref List <PreprocessorAreaData> datas, PreprocessorAreaData parentArea = null)
        {
            List <XmlElement> nodes = element.ChildNodes.OfType <XmlElement>().ToList();

            foreach (XmlElement subElement in nodes)
            {
                if (subElement == null)
                {
                    continue;
                }

                switch (subElement.Name.ToLower())
                {
                case "mssqlauditorpreprocessor":
                {
                    string className = subElement.Attributes["preprocessor"].Value;

                    XmlAttribute idAttr        = subElement.Attributes["id"];
                    XmlAttribute nameAttr      = subElement.Attributes["name"];
                    XmlAttribute columnAttr    = subElement.Attributes["column"];
                    XmlAttribute rowAttr       = subElement.Attributes["row"];
                    XmlAttribute colSpanAttr   = subElement.Attributes["colspan"];
                    XmlAttribute rowSpanAttr   = subElement.Attributes["rowspan"];
                    XmlAttribute vertTestAlign = subElement.Attributes["text-vertical-align"];
                    XmlAttribute textAlign     = subElement.Attributes["text-align"];

                    string id          = "";
                    string preprocName = "unnamed";

                    if (nameAttr != null)
                    {
                        preprocName = nameAttr.Value;
                    }

                    if (idAttr != null)
                    {
                        id = idAttr.Value;
                    }

                    int col     = ParseIntAttribute(columnAttr, 1);
                    int row     = ParseIntAttribute(rowAttr, 1);
                    int colSpan = ParseIntAttribute(colSpanAttr, 1);
                    int rowSpan = ParseIntAttribute(rowSpanAttr, 1);

                    VerticalTextAlign?preprocVertTestAlign = null;

                    if (vertTestAlign != null)
                    {
                        VerticalTextAlign tempVertTestAlign;

                        if (Enum.TryParse(vertTestAlign.Value, out tempVertTestAlign))
                        {
                            preprocVertTestAlign = tempVertTestAlign;
                        }
                    }

                    TextAlign preprocTestAlign = TextAlign.Left;

                    if (textAlign != null)
                    {
                        if (!Enum.TryParse(textAlign.Value, out preprocTestAlign))
                        {
                            preprocTestAlign = TextAlign.Left;
                        }
                    }

                    IPreprocessor preprocessor =
                        (from proc in this._availablePreprocessors where proc.GetType().Name == className select proc)
                        .FirstOrDefault();

                    if (preprocessor != null)
                    {
                        string          configuration = subElement.InnerXml;
                        IContentFactory factory       = preprocessor.CreateContentFactory(id, configuration);

                        PreprocessorData data = new PreprocessorData
                        {
                            ContentFactory    = factory,
                            Name              = preprocName,
                            Column            = col,
                            Row               = row,
                            ColSpan           = colSpan,
                            RowSpan           = rowSpan,
                            VerticalTextAlign = preprocVertTestAlign,
                            TextAlign         = preprocTestAlign
                        };

                        XmlElement newSubElement = document.CreateElement("div");

                        newSubElement.SetAttribute("style", "margin:0; padding:0;");
                        newSubElement.InnerXml = string.Empty;

                        element.ReplaceChild(newSubElement, subElement);

                        if (parentArea != null)
                        {
                            parentArea.Preprocessors.Add(data);
                        }
                        else
                        {
                            log.ErrorFormat(
                                "Invalid configuration: <mssqlauditorpreprocessor> is not embedded in <mssqlauditorpreprocessors>. " +
                                "Are you using old style configuration file?" + Environment.NewLine +
                                "Silently ignoring '{0}' with id='{1}' and name='{2}'",
                                className,
                                id,
                                preprocName
                                );

                            throw new ArgumentOutOfRangeException(
                                      "document",
                                      "Invalid configuration: <mssqlauditorpreprocessor> is not embedded in <mssqlauditorpreprocessors>!"
                                      );
                        }
                        continue;
                    }
                    break;
                }

                case "mssqlauditorpreprocessors":
                {
                    XmlAttribute idAttr       = subElement.Attributes["id"];
                    XmlAttribute nameAttr     = subElement.Attributes["name"];
                    XmlAttribute rowsAttr     = subElement.Attributes["rows"];
                    XmlAttribute columnsAttr  = subElement.Attributes["columns"];
                    XmlAttribute splitterAttr = subElement.Attributes["splitter"];

                    string id       = "";
                    string name     = "unnamed";
                    string rows     = "";
                    string columns  = "";
                    string splitter = "";

                    if (nameAttr != null)
                    {
                        name = nameAttr.Value;
                    }
                    if (idAttr != null)
                    {
                        id = idAttr.Value;
                    }
                    if (columnsAttr != null)
                    {
                        columns = columnsAttr.Value;
                    }
                    if (rowsAttr != null)
                    {
                        rows = rowsAttr.Value;
                    }
                    if (splitterAttr != null)
                    {
                        splitter = splitterAttr.Value;
                    }

                    PreprocessorAreaData container = new PreprocessorAreaData(id, name, columns, rows);

                    if (string.Equals(splitter, "no", StringComparison.InvariantCultureIgnoreCase))
                    {
                        container.NoSplitter = true;
                    }

                    datas.Add(container);

                    PreprocessElement(document, subElement, ref datas, container);

                    container.CheckPreprocessors();

                    continue;
                }
                }

                PreprocessElement(document, subElement, ref datas);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="api">The current api</param>
 public PostController(IApi api, PostEditService editService, IContentFactory factory, IHubContext <Hubs.PreviewHub> hub) : base(api)
 {
     _editService = editService;
     _factory     = factory;
     _hub         = hub;
 }
Exemplo n.º 7
0
 public PostService(IApi api, IContentFactory factory)
 {
     _api     = api;
     _factory = factory;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="factory">The content factory</param>
 /// <param name="mapper">The AutoMapper instance to use</param>
 public ContentService(IContentFactory factory, IMapper mapper)
 {
     _factory = factory;
     _mapper  = mapper;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="api">The current api</param>
 public PageService(IApi api, IContentFactory factory, ManagerLocalizer localizer)
 {
     _api       = api;
     _factory   = factory;
     _localizer = localizer;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="api">The current api</param>
 public SiteController(IApi api, SiteContentEditService service, IContentFactory factory) : base(api)
 {
     _service = service;
     _factory = factory;
 }
Exemplo n.º 11
0
 public ContentManager(IContentFactory contentFactory)
 {
     this.contentFactory = contentFactory;
 }