コード例 #1
0
        public override void Initialize(XElement configRoot)
        {
            // name
            var nameAttribute = configRoot.Attribute("name");
            if (nameAttribute == null) throw new Exception("Missing 'name' attribute on element CollectionProvider");
            Name = nameAttribute.Value;

            var identityAttribute = configRoot.Attribute("identifier");
            if (identityAttribute == null) throw new Exception("Missing 'identifier' attribute on element CollectionProvider");
            Identity = identityAttribute.Value;

            // description
            var descriptionAttribute = configRoot.Attribute("description");
            if (descriptionAttribute  == null)
            {
                // log warning
                Logging.LogWarning(0, "No description element for collection {0}", Name);
            } else
            {
                Description = descriptionAttribute.Value;
            }

            // dsn
            var dsnElement = configRoot.Elements("DsnConnection").FirstOrDefault();
            if (dsnElement == null)
            {
                throw new Exception("Missing 'DsnConnection' element as child of CollectionProvider");
            }
            _dataSourceConnectionString = dsnElement.Value.Trim();

            // publishing definitions
            foreach (var xElement in configRoot.Descendants("Definition"))
            {
                // add each definition to the collection
                var def = new ResourcePublishingDefinition
                              {
                                  ResourcePrefix = new Uri(GetElementValue(xElement, "ResourcePrefix")),
                                  UriTemplate = new UriTemplate(GetElementValue(xElement, "UriTemplate"))
                              };

                if (DoesElementExist(xElement, "SuppressFragmentsFeed"))
                {
                    def.SuppressFragmentsFeed = bool.Parse(GetElementValue(xElement, "SuppressFragmentsFeed"));
                }

                if (DoesElementExist(xElement, "FragmentsQuery"))
                {
                    def.FragmentsQuery = GetElementValue(xElement, "FragmentsQuery");
                    if (DoesElementExist(xElement, "SourceDataInLocalTime"))
                        def.SourceDataInLocalTime = bool.Parse(GetElementValue(xElement, "SourceDataInLocalTime"));
                } else
                {
                    def.NoTimeStampInData = true;
                    def.HashValueTable = GetElementValue(xElement, "HashValueTable");
                    // Axel was here
                    if (DoesElementExist(xElement, "HashValueFileName"))
                        def.HashValueFileName = GetElementValue(xElement, "HashValueFileName");
                    def.EntityIdColumn = GetElementValue(xElement, "EntityIdColumn");
                    def.HashValueKeyColumns = GetElementValues(xElement, "HashValueKeyColumn");
                    def.ValueCheckInterval = GetElementValue(xElement, "UpdateFrequency");
                }

                if (DoesElementExist(xElement, "EncodeIdForResourceId"))
                {
                    def.EncodeIdForResourceId = bool.Parse(GetElementValue(xElement, "EncodeIdForResourceId"));
                }

                // get FragmentGenerationDefinitions
                foreach (var fragmentGenerationDefinition in xElement.Descendants("FragmentGenerationDefinition"))
                {
                    var fragDef = new FragmentGenerationDefinition
                                      {
                                          SnapshotQuery = GetElementValue(fragmentGenerationDefinition, "SnapshotQuery"),
                                          FragmentQuery = GetElementValue(fragmentGenerationDefinition, "FragmentQuery")
                                      };

                    // get generic exclude columns
                    var rdfTemplatesElem = xElement.Descendants("RdfTemplates").FirstOrDefault();
                    if (rdfTemplatesElem.Attribute("genericExcludes") != null)
                    {
                        fragDef.GenericTemplateExcludeColumns = new List<string>(rdfTemplatesElem.Attribute("genericExcludes").Value.Split(','));
                    }

                    // get lines
                    var patternLines = new List<string>();
                    foreach (var lineElement in fragmentGenerationDefinition.Descendants("li"))
                    {
                        patternLines.Add(lineElement.Value.Replace("{{", "<").Replace("}}", ">"));
                    }
                    fragDef.RdfTemplateLines = patternLines;
                    def.FragmentGenerationDefinitions.Add(fragDef);
                }

                _publishingDefinitions.Add(def);
            }

            RawConfig = configRoot.ToString();
            IsEnabled = true;
        }
コード例 #2
0
        public override void Initialize(XElement configRoot)
        {
            // name
            var nameAttribute = configRoot.Attribute("name");

            if (nameAttribute == null)
            {
                throw new Exception("Missing 'name' attribute on element CollectionProvider");
            }
            Name = nameAttribute.Value;

            var identityAttribute = configRoot.Attribute("identifier");

            if (identityAttribute == null)
            {
                throw new Exception("Missing 'identifier' attribute on element CollectionProvider");
            }
            Identity = identityAttribute.Value;

            // description
            var descriptionAttribute = configRoot.Attribute("description");

            if (descriptionAttribute == null)
            {
                // log warning
                Logging.LogWarning(0, "No description element for collection {0}", Name);
            }
            else
            {
                Description = descriptionAttribute.Value;
            }

            // dsn
            var dsnElement = configRoot.Elements("DsnConnection").FirstOrDefault();

            if (dsnElement == null)
            {
                throw new Exception("Missing 'DsnConnection' element as child of CollectionProvider");
            }
            _dataSourceConnectionString = dsnElement.Value.Trim();

            // publishing definitions
            foreach (var xElement in configRoot.Descendants("Definition"))
            {
                // add each definition to the collection
                var def = new ResourcePublishingDefinition
                {
                    ResourcePrefix = new Uri(GetElementValue(xElement, "ResourcePrefix")),
                    UriTemplate    = new UriTemplate(GetElementValue(xElement, "UriTemplate"))
                };

                if (DoesElementExist(xElement, "SuppressFragmentsFeed"))
                {
                    def.SuppressFragmentsFeed = bool.Parse(GetElementValue(xElement, "SuppressFragmentsFeed"));
                }

                if (DoesElementExist(xElement, "FragmentsQuery"))
                {
                    def.FragmentsQuery = GetElementValue(xElement, "FragmentsQuery");
                    if (DoesElementExist(xElement, "SourceDataInLocalTime"))
                    {
                        def.SourceDataInLocalTime = bool.Parse(GetElementValue(xElement, "SourceDataInLocalTime"));
                    }
                }
                else
                {
                    def.NoTimeStampInData = true;
                    def.HashValueTable    = GetElementValue(xElement, "HashValueTable");
                    // Axel was here
                    if (DoesElementExist(xElement, "HashValueFileName"))
                    {
                        def.HashValueFileName = GetElementValue(xElement, "HashValueFileName");
                    }
                    def.EntityIdColumn      = GetElementValue(xElement, "EntityIdColumn");
                    def.HashValueKeyColumns = GetElementValues(xElement, "HashValueKeyColumn");
                    def.ValueCheckInterval  = GetElementValue(xElement, "UpdateFrequency");
                }

                if (DoesElementExist(xElement, "EncodeIdForResourceId"))
                {
                    def.EncodeIdForResourceId = bool.Parse(GetElementValue(xElement, "EncodeIdForResourceId"));
                }

                // get FragmentGenerationDefinitions
                foreach (var fragmentGenerationDefinition in xElement.Descendants("FragmentGenerationDefinition"))
                {
                    var fragDef = new FragmentGenerationDefinition
                    {
                        SnapshotQuery = GetElementValue(fragmentGenerationDefinition, "SnapshotQuery"),
                        FragmentQuery = GetElementValue(fragmentGenerationDefinition, "FragmentQuery")
                    };

                    // get generic exclude columns
                    var rdfTemplatesElem = xElement.Descendants("RdfTemplates").FirstOrDefault();
                    if (rdfTemplatesElem.Attribute("genericExcludes") != null)
                    {
                        fragDef.GenericTemplateExcludeColumns = new List <string>(rdfTemplatesElem.Attribute("genericExcludes").Value.Split(','));
                    }

                    // get lines
                    var patternLines = new List <string>();
                    foreach (var lineElement in fragmentGenerationDefinition.Descendants("li"))
                    {
                        patternLines.Add(lineElement.Value.Replace("{{", "<").Replace("}}", ">"));
                    }
                    fragDef.RdfTemplateLines = patternLines;
                    def.FragmentGenerationDefinitions.Add(fragDef);
                }

                _publishingDefinitions.Add(def);
            }

            RawConfig = configRoot.ToString();
            IsEnabled = true;
        }
コード例 #3
0
 public DataSourceManager(OdbcCollectionProvider provider, ResourcePublishingDefinition definition)
 {
     _provider = provider;
     _definition = definition;
 }
コード例 #4
0
        public override Stream GetFragment(string id, string contentType)
        {
            // need to see which definition we match
            ResourcePublishingDefinition definition = null;
            UriTemplateMatch             match      = null;

            foreach (var resourcePublishingDefinition in _publishingDefinitions)
            {
                var newuri = new Uri(id);
                match = resourcePublishingDefinition.UriTemplate.Match(resourcePublishingDefinition.ResourcePrefix, newuri);
                if (match != null)
                {
                    definition = resourcePublishingDefinition;
                    break;
                }
            }

            if (definition == null)
            {
                throw new Exception("Unable to find matching definition for uri " + id);
            }

            var sb = new StringBuilder();

            foreach (var generationDefinition in definition.FragmentGenerationDefinitions)
            {
                try
                {
                    var data = ExecuteQuery(_dataSourceConnectionString, generationDefinition.FragmentQuery.Replace("[[id]]", match.BoundVariables["id"]));
                    foreach (DataRow row in data.Rows)
                    {
                        var dra = new DbDataRow(row);
                        foreach (var line in generationDefinition.RdfTemplateLines)
                        {
                            var linePattern = new NTripleLinePattern(line);
                            linePattern.GenerateNTriples(sb, dra, generationDefinition.GenericTemplateExcludeColumns, contentType.Equals("xml"));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logging.LogError(1, "Error processing definition {0} {1} {2} {3}", ex.Message, generationDefinition.SnapshotQuery, _dataSourceConnectionString, ex.StackTrace);
                }
            }

            try
            {
                var g          = new Graph();
                var parser     = new NTriplesParser(TokenQueueMode.SynchronousBufferDuringParsing);
                var triplesStr = sb.ToString();
                parser.Load(g, new StringReader(triplesStr));

                if (contentType.Equals("xml"))
                {
                    var ms           = new MemoryStream();
                    var sw           = new StreamWriter(ms, Encoding.UTF8);
                    var rdfxmlwriter = new RdfXmlWriter();

                    var strw = new System.IO.StringWriter();
                    rdfxmlwriter.Save(g, strw);
                    var data = strw.ToString();

                    data = data.Replace("~~~2B~~~", "%2B");
                    data = data.Replace("~~~SLASH~~~", "%2F");
                    data = data.Replace("utf-16", "utf-8");
                    sw.Write(data);
                    sw.Flush();
                    ms.Seek(0, SeekOrigin.Begin);
                    return(ms);
                }
                else
                {
                    var ms = new MemoryStream();
                    var sw = new StreamWriter(ms);
                    sw.Write(triplesStr);
                    sw.Flush();
                    ms.Seek(0, SeekOrigin.Begin);
                    return(ms);
                }
            }
            catch (Exception ex)
            {
                Logging.LogError(1, "Error getting fragment {0} {1}", ex.Message, ex.StackTrace);
                throw;
            }
        }
コード例 #5
0
 public DataSourceManager(OdbcCollectionProvider provider, ResourcePublishingDefinition definition)
 {
     _provider   = provider;
     _definition = definition;
 }