Beispiel #1
0
        private void ProcessFile()
        {
            if (_webLink.IsDeleted)  // if favorite resource was deleted then do nothing
            {
                return;
            }
            FileInfo fileInfo   = _reader.fileInfo;
            Stream   readStream = _reader.ReadStream;

            using ( readStream )
            {
                DateTime lastWriteTime = IOTools.GetLastWriteTime(fileInfo);
                if (!_webLink.HasProp("LastModified") || lastWriteTime > LastModified() ||
                    _webLink.HasProp(Core.Props.LastError))
                {
                    bool      isShowed   = BookmarkService.BookmarkSynchronizationFrequency(_webLink) > 0;
                    IResource formatFile = _webLink.GetLinkProp("Source");
                    _webLink.BeginUpdate();
                    if (formatFile != null)
                    {
                        formatFile.BeginUpdate();
                    }
                    else
                    {
                        string resourceType = Core.FileResourceManager.GetResourceTypeByExtension(fileInfo.Extension);
                        if (resourceType == null)
                        {
                            resourceType = "UnknownFile";
                        }
                        formatFile = Core.ResourceStore.BeginNewResource(resourceType);
                        _webLink.AddLink("Source", formatFile);
                    }
                    if (_webLink.HasProp(Core.Props.LastError))
                    {
                        SetLastError(null);
                    }
                    _webLink.SetProp("LastModified", lastWriteTime);
                    formatFile.SetProp(Core.Props.Size, (int)readStream.Length);
                    formatFile.SetProp(FavoritesPlugin._propContent, readStream);
                    if (isShowed)
                    {
                        formatFile.SetProp(Core.Props.Date, lastWriteTime);
                        formatFile.SetProp(FavoritesPlugin._propIsUnread, true);
                        Core.FilterEngine.ExecRules(StandardEvents.ResourceReceived, _webLink);
                    }
                    if (formatFile.Type != "UnknownFile")
                    {
                        Core.TextIndexManager.QueryIndexing(formatFile.Id);
                    }
                    _webLink.EndUpdate();
                    formatFile.EndUpdate();
                }
            }
        }
Beispiel #2
0
        private void ProcessWebLink()
        {
            Stream readStream = _reader.ReadStream;

            if (readStream == null || _webLink.IsDeleted)  // if favorite resource was deleted then do nothing
            {
                return;
            }
            int             propContent = FavoritesPlugin._propContent;
            HttpWebResponse response    = _reader.WebResponse;
            // check whether http stream differs from earlier saved one
            bool differs = true;

            ///////////////////////////////////////////////////////////////////////////////
            /// the following if statement is a workaround over invalid processing by
            /// HttpReader the Not-Modified-Since header. .NET 1.1 was throwing the
            /// exception if content not modified, .NET 1.1 SP1 just returns empty stream
            ///////////////////////////////////////////////////////////////////////////////
            if (readStream.Length == 0 && !_webLink.HasProp(Core.Props.LastError))
            {
                return;
            }

            IResource formatFile = _webLink.GetLinkProp("Source");

            if (formatFile != null && formatFile.HasProp(propContent))
            {
                Stream savedStream = formatFile.GetBlobProp(propContent);
                using ( savedStream )
                {
                    if (savedStream.Length == readStream.Length)
                    {
                        differs = false;
                        for (int i = 0; i < readStream.Length; ++i)
                        {
                            if (( byte )savedStream.ReadByte() != ( byte )readStream.ReadByte())
                            {
                                readStream.Position = 0;
                                differs             = true;
                                break;
                            }
                        }
                    }
                }
            }
            if (differs)
            {
                DateTime lastModified = GetLastModified(response);
                bool     isShowed     = BookmarkService.BookmarkSynchronizationFrequency(_webLink) > 0;
                // content changed, so set properties and proceed with indexing

                string resourceType = "UnknownFile";
                if (!String.IsNullOrEmpty(response.ContentType))
                {
                    resourceType = (Core.FileResourceManager as FileResourceManager).GetResourceTypeByContentType(response.ContentType);
                    if (resourceType == null)
                    {
                        resourceType = "UnknownFile";
                    }
                }
                _webLink.BeginUpdate();
                if (formatFile != null)
                {
                    formatFile.BeginUpdate();
                    if (resourceType != "UnknownFile" && formatFile.Type != resourceType)
                    {
                        formatFile.ChangeType(resourceType);
                    }
                }
                else
                {
                    formatFile = Core.ResourceStore.BeginNewResource(resourceType);
                    _webLink.AddLink("Source", formatFile);
                }
                if (_webLink.HasProp(Core.Props.LastError))
                {
                    SetLastError(null);
                }
                _webLink.SetProp("LastModified", lastModified);
                string redirectedUrl = _reader.RedirectUrl;
                if (redirectedUrl != null && redirectedUrl.Length > 0)
                {
                    _webLink.SetProp(FavoritesPlugin._propURL, redirectedUrl);
                }
                if (_reader.ETag.Length > 0)
                {
                    _webLink.SetProp(FavoritesPlugin._propETag, _reader.ETag);
                }
                // try to get charset from content-type or from content itself
                string charset = _reader.CharacterSet;
                if (charset != null)
                {
                    _webLink.SetProp(Core.FileResourceManager.PropCharset, charset);
                }
                formatFile.SetProp(Core.Props.Size, (int)readStream.Length);
                formatFile.SetProp(propContent, readStream);
                if (isShowed)
                {
                    formatFile.SetProp(Core.Props.Date, lastModified);
                    formatFile.SetProp(FavoritesPlugin._propIsUnread, true);
                    Core.FilterEngine.ExecRules(StandardEvents.ResourceReceived, _webLink);
                }
                if (formatFile.Type != "UnknownFile")
                {
                    Core.TextIndexManager.QueryIndexing(formatFile.Id);
                }
                _webLink.EndUpdate();
                formatFile.EndUpdate();
            }
        }