コード例 #1
0
ファイル: SampleProvider.cs プロジェクト: SmartFire/SDShare
 public override IEnumerable<IFragment> GetFragments(DateTime since, DateTime before)
 {
     // make use of the fragment class to create this collection
     var fragment = new Fragment();
     fragment.PublishDate = DateTime.UtcNow; // the date the entity was updated
     fragment.ResourceId = "http://www.brightstardb.com/sample/person/1"; // the value to be returned in GetFragment id
     fragment.ResourceUri = "http://www.brightstardb.com/sample/person/1"; // the value to of the ResourceUri in the fragment ATOM. Usually the same as ResourceId
     fragment.ResourceName = "The Fragment Name"; // the name to updated entity
     return new List<IFragment> {fragment};
 }
コード例 #2
0
        public override IEnumerable<IFragment> GetFragments(DateTime since, DateTime before)
        {
            // get list of all odata type collections
            var xmlReader = XmlReader.Create(_odataEndpoint, new XmlReaderSettings() { CloseInput = true });
            var serviceDocument = ServiceDocument.Load(xmlReader);           
            if (serviceDocument.Workspaces.Count == 0) throw new Exception("No workspace found in service document");
            xmlReader.Close();

            var workspace = serviceDocument.Workspaces[0];
            foreach (var resourceCollectionInfo in workspace.Collections)
            {
                var queryUrl = _odataEndpoint + resourceCollectionInfo.Link;
                SyndicationFeed feed = null;
                XmlReader reader = null;
                try
                {
                    reader = XmlReader.Create(queryUrl, new XmlReaderSettings() { CloseInput = true});                    
                    feed = SyndicationFeed.Load(reader);                        
                    reader.Close();
                } catch(Exception e)
                {
                    Logging.LogError(1, "Unable to fetch odata collection data {0} {1}", queryUrl, e.Message);
                    if (reader != null) reader.Close();
                }

                if (feed != null)
                {
                    // issue a query against each collection to find all entries that have changed since the give date                    
                    foreach (var syndicationItem in feed.Items)
                    {
                        Fragment fragment = null;
                        try {
                            if (syndicationItem.LastUpdatedTime.UtcDateTime > since)
                            {
                                fragment = new Fragment()
                                                {
                                                    PublishDate = syndicationItem.LastUpdatedTime.UtcDateTime,
                                                    ResourceId = syndicationItem.Id,
                                                    ResourceName = syndicationItem.Title.Text,
                                                    ResourceUri = syndicationItem.Id
                                                };
                            }
                        } catch(Exception e)
                        {
                            Logging.LogError(1, "Unable to build fragment {0} {1}", e.Message, e.StackTrace);
                        }
                        if (fragment != null) yield return fragment;
                    }
                }
            }
            yield break;
        }
コード例 #3
0
        public override IEnumerable <IFragment> GetFragments(DateTime since, DateTime before)
        {
            // get list of all odata type collections
            var xmlReader = XmlReader.Create(_odataEndpoint, new XmlReaderSettings()
            {
                CloseInput = true
            });
            var serviceDocument = ServiceDocument.Load(xmlReader);

            if (serviceDocument.Workspaces.Count == 0)
            {
                throw new Exception("No workspace found in service document");
            }
            xmlReader.Close();

            var workspace = serviceDocument.Workspaces[0];

            foreach (var resourceCollectionInfo in workspace.Collections)
            {
                var             queryUrl = _odataEndpoint + resourceCollectionInfo.Link;
                SyndicationFeed feed     = null;
                XmlReader       reader   = null;
                try
                {
                    reader = XmlReader.Create(queryUrl, new XmlReaderSettings()
                    {
                        CloseInput = true
                    });
                    feed = SyndicationFeed.Load(reader);
                    reader.Close();
                } catch (Exception e)
                {
                    Logging.LogError(1, "Unable to fetch odata collection data {0} {1}", queryUrl, e.Message);
                    if (reader != null)
                    {
                        reader.Close();
                    }
                }

                if (feed != null)
                {
                    // issue a query against each collection to find all entries that have changed since the give date
                    foreach (var syndicationItem in feed.Items)
                    {
                        Fragment fragment = null;
                        try {
                            if (syndicationItem.LastUpdatedTime.UtcDateTime > since)
                            {
                                fragment = new Fragment()
                                {
                                    PublishDate  = syndicationItem.LastUpdatedTime.UtcDateTime,
                                    ResourceId   = syndicationItem.Id,
                                    ResourceName = syndicationItem.Title.Text,
                                    ResourceUri  = syndicationItem.Id
                                };
                            }
                        } catch (Exception e)
                        {
                            Logging.LogError(1, "Unable to build fragment {0} {1}", e.Message, e.StackTrace);
                        }
                        if (fragment != null)
                        {
                            yield return(fragment);
                        }
                    }
                }
            }
            yield break;
        }
コード例 #4
0
        public override IEnumerable<IFragment> GetFragments(DateTime since, DateTime before)
        {
            foreach (var definition in _publishingDefinitions)
            {
                if (definition.SuppressFragmentsFeed) continue;
                if (definition.DataSourceManager != null)
                {
                    foreach (var info in definition.DataSourceManager.ListLastUpdated(since))
                    {
                        var psi = definition.UriTemplate.BindByPosition(definition.ResourcePrefix, Uri.EscapeDataString(info.EntityId));
                        yield return
                            new Fragment { PublishDate =
                                           new DateTime(info.LastUpdated.Year,
                                                        info.LastUpdated.Month,
                                                        info.LastUpdated.Day,
                                                        info.LastUpdated.Hour,
                                                        info.LastUpdated.Minute,
                                                        info.LastUpdated.Second,
                                                        0, DateTimeKind.Utc),
                                                        ResourceId = Uri.EscapeUriString(psi.AbsoluteUri),
                                                        ResourceName = info.EntityId,
                                                        ResourceUri = psi.AbsoluteUri };
                    }
                }
                else
                {
                    if (since.Equals(DateTime.MinValue)) since = SqlDateTime.MinValue.Value;
                    if (before.Equals(DateTime.MaxValue)) before = SqlDateTime.MaxValue.Value;

                    var queryParams = new List<object> {definition.SourceDataInLocalTime ? since.ToLocalTime() : since};

                    var query = definition.FragmentsQuery;
                    query = query.Replace("[[since]]", "?");

                    if (query.Contains("[[before]]"))
                    {
                        query = query.Replace("[[before]]", "?");
                        queryParams.Add(before);
                    }

                    var data = ExecuteQuery(_dataSourceConnectionString, query, queryParams.ToArray());

                    if (!(data.Columns.Contains("id") && data.Columns.Contains("name")))
                    {
                        throw new Exception("One of the required columns (id, name) was not present.");
                    }

                    foreach (DataRow row in data.Rows)
                    {
                        var fragment = new Fragment();
                        var rowId =  row["id"].ToString().Trim();
                        rowId = Uri.EscapeDataString(rowId);
                        var uri = definition.UriTemplate.BindByPosition(definition.ResourcePrefix, rowId);
                        if (data.Columns.Contains("updated"))
                        {
                            var value = (DateTime) row["updated"];
                            var localDateTime = new DateTime(value.Year, value.Month, value.Day, value.Hour, value.Minute, value.Second, 0, DateTimeKind.Local);
                            fragment.PublishDate = localDateTime.ToUniversalTime();
                        }
                        else
                        {
                            fragment.PublishDate = DateTime.UtcNow;
                        }
                        fragment.ResourceName = row["name"].ToString();
                        fragment.ResourceUri = uri.AbsoluteUri;
                        fragment.ResourceId = Uri.EscapeUriString(uri.AbsoluteUri);

                        yield return fragment;
                    }
                }
            }
        }
コード例 #5
0
        public override IEnumerable <IFragment> GetFragments(DateTime since, DateTime before)
        {
            foreach (var definition in _publishingDefinitions)
            {
                if (definition.SuppressFragmentsFeed)
                {
                    continue;
                }
                if (definition.DataSourceManager != null)
                {
                    foreach (var info in definition.DataSourceManager.ListLastUpdated(since))
                    {
                        var psi = definition.UriTemplate.BindByPosition(definition.ResourcePrefix, Uri.EscapeDataString(info.EntityId));
                        yield return
                            (new Fragment {
                            PublishDate =
                                new DateTime(info.LastUpdated.Year,
                                             info.LastUpdated.Month,
                                             info.LastUpdated.Day,
                                             info.LastUpdated.Hour,
                                             info.LastUpdated.Minute,
                                             info.LastUpdated.Second,
                                             0, DateTimeKind.Utc),
                            ResourceId = Uri.EscapeUriString(psi.AbsoluteUri),
                            ResourceName = info.EntityId,
                            ResourceUri = psi.AbsoluteUri
                        });
                    }
                }
                else
                {
                    if (since.Equals(DateTime.MinValue))
                    {
                        since = SqlDateTime.MinValue.Value;
                    }
                    if (before.Equals(DateTime.MaxValue))
                    {
                        before = SqlDateTime.MaxValue.Value;
                    }

                    var queryParams = new List <object> {
                        definition.SourceDataInLocalTime?since.ToLocalTime() : since
                    };

                    var query = definition.FragmentsQuery;
                    query = query.Replace("[[since]]", "?");

                    if (query.Contains("[[before]]"))
                    {
                        query = query.Replace("[[before]]", "?");
                        queryParams.Add(before);
                    }

                    var data = ExecuteQuery(_dataSourceConnectionString, query, queryParams.ToArray());

                    if (!(data.Columns.Contains("id") && data.Columns.Contains("name")))
                    {
                        throw new Exception("One of the required columns (id, name) was not present.");
                    }

                    foreach (DataRow row in data.Rows)
                    {
                        var fragment = new Fragment();
                        var rowId    = row["id"].ToString().Trim();
                        rowId = Uri.EscapeDataString(rowId);
                        var uri = definition.UriTemplate.BindByPosition(definition.ResourcePrefix, rowId);
                        if (data.Columns.Contains("updated"))
                        {
                            var value         = (DateTime)row["updated"];
                            var localDateTime = new DateTime(value.Year, value.Month, value.Day, value.Hour, value.Minute, value.Second, 0, DateTimeKind.Local);
                            fragment.PublishDate = localDateTime.ToUniversalTime();
                        }
                        else
                        {
                            fragment.PublishDate = DateTime.UtcNow;
                        }
                        fragment.ResourceName = row["name"].ToString();
                        fragment.ResourceUri  = uri.AbsoluteUri;
                        fragment.ResourceId   = Uri.EscapeUriString(uri.AbsoluteUri);

                        yield return(fragment);
                    }
                }
            }
        }