Beispiel #1
0
        /// <summary>
        /// Gets the raw string (xml) from the broker db by URL
        /// </summary>
        /// <param name="Url">URL of the page</param>
        /// <returns>String with page xml or empty string if no page was found</returns>
        public string GetContentByUrl(string Url)
        {
            Page page = new Page();

            page.Title    = Randomizer.AnyString(15);
            page.Id       = Randomizer.AnyUri(64);
            page.Filename = Randomizer.AnySafeString(8) + ".html";

            PageTemplate pt = new PageTemplate();

            pt.Title = Randomizer.AnyString(20);
            Field ptfieldView = new Field();

            ptfieldView.Name = "view";
            ptfieldView.Values.Add("Standard");
            pt.MetadataFields = new FieldSet();
            pt.MetadataFields.Add(ptfieldView.Name, ptfieldView);

            page.PageTemplate = pt;

            page.ComponentPresentations = new List <ComponentPresentation>();

            string cpString = ComponentPresentationProvider.GetContent("");

            page.ComponentPresentations.Add(SerializerService.Deserialize <ComponentPresentation>(cpString));

            FieldSet metadataFields = new FieldSet();

            page.MetadataFields = metadataFields;

            return(SerializerService.Serialize <Page>(page));
        }
        /// <summary>
        /// Gets the raw string (xml) from the broker db by URL
        /// </summary>
        /// <param name="url">URL of the page</param>
        /// <returns>String with page xml or empty string if no page was found</returns>
        public string GetContentByUrl(string url)
        {
            if (ThrowPageNotFound)
            {
                return(string.Empty);
            }

            Page page = new Page();

            page.Title    = Randomizer.AnyString(15);
            page.Id       = Randomizer.AnyUri(64);
            page.Filename = Randomizer.AnySafeString(8) + ".html";

            PageTemplate pt = new PageTemplate();

            if (url.ToLower().Contains("model"))
            {
                pt.Title = "Standard";
            }
            else
            {
                pt.Title = Randomizer.AnyString(20);
            }
            Field ptfieldView = new Field();

            ptfieldView.Name = "view";
            ptfieldView.Values.Add("Standard");
            pt.MetadataFields = new FieldSet();
            pt.MetadataFields.Add(ptfieldView.Name, ptfieldView);

            page.PageTemplate = pt;

            page.ComponentPresentations = new List <ComponentPresentation>();

            string cpString = ComponentPresentationProvider.GetContent("");

            page.ComponentPresentations.Add(SerializerService.Deserialize <ComponentPresentation>(cpString));

            FieldSet metadataFields = new FieldSet();

            page.MetadataFields = metadataFields;

            return(SerializerService.Serialize <Page>(page));
        }
        /// <summary>
        /// Gets the raw string (xml) from the broker db by URL
        /// </summary>
        /// <param name="Url">URL of the page</param>
        /// <returns>String with page xml or empty string if no page was found</returns>
        public string GetContentByUrl(string Url)
        {
            Page page = new Page();

            page.Title    = Randomizer.AnyString(15);
            page.Id       = Randomizer.AnyUri(64);
            page.Filename = Randomizer.AnySafeString(8) + ".html";

            PageTemplate pt = new PageTemplate();

            pt.Title = Randomizer.AnyString(20);
            Field ptfieldView = new Field();

            ptfieldView.Name = "view";
            ptfieldView.Values.Add("Standard");
            pt.MetadataFields = new FieldSet();
            pt.MetadataFields.Add(ptfieldView.Name, ptfieldView);

            page.PageTemplate = pt;

            Schema schema = new Schema();

            schema.Title = Randomizer.AnyString(10);

            Component component = new Component();

            component.Title  = Randomizer.AnyString(30);
            component.Id     = Randomizer.AnyUri(16);
            component.Schema = schema;

            Field field1 = Randomizer.AnyTextField(6, 120, true);
            Field field2 = Randomizer.AnyTextField(8, 40, false);

            FieldSet fieldSet = new FieldSet();

            fieldSet.Add(field1.Name, field1);
            fieldSet.Add(field2.Name, field2);
            component.Fields = fieldSet;

            ComponentTemplate ct = new ComponentTemplate();

            ct.Title = Randomizer.AnyString(20);
            Field fieldView = new Field();

            fieldView.Name = "view";
            fieldView.Values.Add("DefaultComponentView");
            ct.MetadataFields = new FieldSet();
            ct.MetadataFields.Add(fieldView.Name, fieldView);

            ComponentPresentation cp = new ComponentPresentation();

            cp.Component         = component;
            cp.ComponentTemplate = ct;

            page.ComponentPresentations = new List <ComponentPresentation>();
            page.ComponentPresentations.Add(cp);

            FieldSet metadataFields = new FieldSet();

            page.MetadataFields = metadataFields;

            var           serializer = new XmlSerializer(typeof(Page));
            StringBuilder builder    = new StringBuilder();
            StringWriter  writer     = new StringWriter(builder);

            //XmlTextWriter writer = new XmlTextWriter(page.Filename, Encoding.UTF8);
            //serializer.Serialize(writer, page);
            serializer.Serialize(writer, page);
            string pageAsString = builder.ToString();

            return(pageAsString);
        }