Esempio n. 1
0
        private IDataProvider GetProvider()
        {
            var firstOrDefault = ContentProviders.Get(HeadersCollection["content-type"]);

            if (firstOrDefault == null)
            {
                return(new TextDataProvider());
            }
            return(firstOrDefault);
        }
Esempio n. 2
0
        IRazorConfigInitializer IRazorConfigInitializer.InitializeByValues(
            Type baseType,
            string rootOperatorPath,
            RazorCodeLanguage language,
            string defaultExtension,
            string autoIncludeNameWithoutExtension,
            string sharedLocation,
            bool?includeGeneratedSourceCode,
            bool?htmlEncode,
            IEnumerable <string> references,
            IEnumerable <string> namespaces,
            IEnumerable <Func <IContentProvider> > contentProviders,
            bool replaceReferences,
            bool replaceNamespaces,
            bool replaceContentProviders
            )
        {
            EnsureNotReadonly();

            RootOperator.Path = rootOperatorPath ?? RootOperator.Path;

            Templates.BaseType         = baseType ?? Templates.BaseType;
            Templates.Language         = language ?? Templates.Language;
            Templates.DefaultExtension = (defaultExtension ?? Templates.DefaultExtension).EmptyAsNull();
            Templates.AutoIncludeName  = (autoIncludeNameWithoutExtension ?? Templates.AutoIncludeName).EmptyAsNull();
            Templates.SharedLocation   = (sharedLocation ?? Templates.SharedLocation).EmptyAsNull();
            if (includeGeneratedSourceCode != null)
            {
                Templates.IncludeGeneratedSourceCode = includeGeneratedSourceCode.Value;
            }
            if (htmlEncode != null)
            {
                Templates.HtmlEncode = htmlEncode.Value;
            }
            if (references != null)
            {
                References = replaceReferences ? references.ToList().AsReadOnly() : References.Union(references, StringComparer.InvariantCultureIgnoreCase).ToList().AsReadOnly();
            }
            if (namespaces != null)
            {
                Namespaces = replaceNamespaces ? namespaces.ToList().AsReadOnly() : Namespaces.Union(namespaces).ToList().AsReadOnly();
            }
            if (contentProviders != null)
            {
                ContentProviders = replaceContentProviders ? contentProviders.ToList().AsReadOnly() : ContentProviders.Union(contentProviders).ToList().AsReadOnly();
            }
            return(this);
        }
Esempio n. 3
0
        private void LoadSettingsFromXDocumentOrElseDefaults(XContainer config)
        {
            try {
                var rootDescendents = config.Descendants(_rootElementName);

                var xElements = rootDescendents as XElement[] ?? rootDescendents.ToArray();
                RootOperator = ConfigElement
                               .Create <RootOperatorElement>()
                               .TryLoadElement(xElements
                                               .Descendants("rootOperator")
                                               .SingleOrDefault()
                                               )
                               .CastTo <RootOperatorElement>();

                Templates = ConfigElement
                            .Create <TemplatesElement>()
                            .TryLoadElement(xElements
                                            .Descendants("templates")
                                            .SingleOrDefault()
                                            )
                            .CastTo <TemplatesElement>();

                Namespaces       = xElements.HasClearChildElement("namespaces") ? new List <string>() : CreateDefaultNamespaces();
                References       = xElements.HasClearChildElement("references") ? new List <string>() : CreateDefaultReferences();
                ContentProviders = xElements.HasClearChildElement("contentProviders") ? new List <Func <IContentProvider> >() : CreateDefaultContentProviders();

                Namespaces = xElements
                             .Descendants("namespaces")
                             .SingleOrDefault(new XElement("namespaces"))
                             .Descendants("add")
                             .Select(xe => xe.GetAttributeValue("namespace"))
                             .Union(Namespaces)
                             .ToList()
                             .AsReadOnly();

                References = xElements
                             .Descendants("references")
                             .SingleOrDefault(new XElement("references"))
                             .Descendants("add")
                             .Select(xe => xe.GetAttributeValue("reference"))
                             .Union(References, StringComparer.InvariantCultureIgnoreCase)
                             .ToList()
                             .AsReadOnly();

                var contentProviderElements =
                    xElements
                    .Descendants("contentProviders")
                    .SingleOrDefault(new XElement("contentProviders"))
                    .Descendants("add");

                ContentProviders = ContentProviders.ToList();
                foreach (var e in contentProviderElements)
                {
                    var el = e;
                    ContentProviders.Add(
                        () => Activator.CreateInstance(Type.GetType(el.GetAttributeValue("type"), true), true)
                        .CastTo <IContentProvider>()
                        .InitFromConfig(el)
                        );
                }
                ContentProviders = ContentProviders.CastTo <List <Func <IContentProvider> > >().AsReadOnly();
            }
            catch (TypeLoadException ex) {
                throw new TemplateConfigurationException("Unable to load type named '{0}' at your xipton.razor configuration. Please correct the corresponding configuration setting.".FormatWith(ex.TypeName), ex);
            }
            catch (Exception ex) {
                throw new TemplateConfigurationException("Unable to load the xipton.razor configuration. {0}. Please correct your xipton.razor configuration. Take a look at the inner exception(s) for details.".FormatWith(ex.Message), ex);
            }
        }
Esempio n. 4
0
 public XmlRpc(WebClient client, string url) : base(client, new Uri(url))
 {
     ContentProviders.Add("application/xml", new XmlRpcDataProvider());
     ContentProviders.Add("text/xml", new XmlRpcDataProvider());
     ContentProviders.Add("text/html", new HtmlObjectProvider(new Html.DocInfo(client, (this.Url))));
 }
Esempio n. 5
0
    private void SaveXML(bool noReload = false)
    {
        XMLView.EndEdit();

        //https://stackoverflow.com/questions/37145086/datagridview-remove-empty-rows-button
        for (int i = XMLView.Rows.Count - 1; i > -1; i--)
        {
            DataGridViewRow row = XMLView.Rows[i];
            if (!row.IsNewRow && row.Cells[0].Value == null)
            {
                XMLView.Rows.RemoveAt(i);
            }
        }

        List <Provider>  providerList  = new List <Provider>();
        List <PartColor> partColorList = new List <PartColor>();

        foreach (DataGridViewRow data in XMLView.Rows)
        {
            if (data.IsNewRow)
            {
                continue;
            }

            switch (ListType)
            {
            case XMLContentType.ContentProviders:
                Provider pro = new Provider();
                pro.Name = data.Cells[0].Value.ToString();
                pro.URL  = data.Cells[1].Value.ToString();
                pro.Icon = data.Cells[2].Value.ToString();
                providerList.Add(pro);
                break;

            case XMLContentType.PartColors:
                PartColor pc = new PartColor();
                pc.ColorRawName = data.Cells[0].Value.ToString();
                pc.ColorID      = Convert.ToInt32(data.Cells[1].Value);
                pc.ColorRGB     = data.Cells[2].Value.ToString();
                partColorList.Add(pc);
                break;

            default:
                break;
            }
        }

        //https://stackoverflow.com/questions/2129414/how-to-insert-xml-comments-in-xml-serialization
        switch (ListType)
        {
        case XMLContentType.ContentProviders:
            ContentProviders providers = new ContentProviders();
            providers.Providers = providerList.ToArray();

            XmlSerializer ser = new XmlSerializer(typeof(ContentProviders));

            using (FileStream fs = new FileStream(GlobalPaths.ConfigDir + "\\" + GlobalPaths.ContentProviderXMLName, FileMode.Create))
            {
                XmlWriter writer = XmlWriter.Create(fs, new XmlWriterSettings {
                    Indent = true
                });
                writer.WriteStartDocument();
                writer.WriteComment(GenerateComment("content providers"));
                ser.Serialize(writer, providers);
                writer.WriteEndDocument();
                writer.Flush();
            }
            break;

        case XMLContentType.PartColors:
            PartColors partColors = new PartColors();
            partColors.ColorList = partColorList.ToArray();

            XmlSerializer ser2 = new XmlSerializer(typeof(PartColors));

            using (FileStream fs = new FileStream(GlobalPaths.ConfigDir + "\\" + GlobalPaths.PartColorXMLName, FileMode.Create))
            {
                XmlWriter writer = XmlWriter.Create(fs, new XmlWriterSettings {
                    Indent = true
                });
                writer.WriteStartDocument();
                writer.WriteComment(GenerateComment("part colors"));
                ser2.Serialize(writer, partColors);
                writer.WriteEndDocument();
                writer.Flush();
            }
            break;

        default:
            break;
        }

        providerList.Clear();
        partColorList.Clear();

        string fileName = "";

        switch (ListType)
        {
        case XMLContentType.ContentProviders:
            fileName = GlobalPaths.ContentProviderXMLName;
            break;

        case XMLContentType.PartColors:
            fileName = GlobalPaths.PartColorXMLName;
            break;

        default:
            break;
        }

        if (!noReload)
        {
            MessageBox.Show(fileName + " has been saved! The list will now reload.", "XML Content Editor - File Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
            LoadXML(ListType);
        }
        else
        {
            MessageBox.Show(fileName + " has been saved!", "XML Content Editor - File Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }