Example #1
0
 private static void RemoveAttachmentResources()
 {
     //move attachment properties to format file resource
     try
     {
         if (RS.ResourceTypes.Exist(STR.Attachment))
         {
             IResourceList attachments = Core.ResourceStore.GetAllResources(STR.Attachment);
             for (int i = attachments.Count - 1; i >= 0; i--)
             {
                 IResource attachment = attachments[i];
                 IResource formatFile = attachment.GetLinkProp("Source");
                 if (formatFile != null)
                 {
                     formatFile.SetProp(Core.Props.Name, attachment.GetProp(Core.Props.Name));
                     formatFile.SetProp(Core.Props.Date, attachment.GetProp(Core.Props.Date));
                     formatFile.SetProp(PROP.AttachmentIndex, attachment.GetProp(PROP.AttachmentIndex));
                     if (attachment.HasProp(PROP.ResourceTransfer))
                     {
                         formatFile.SetProp(PROP.ResourceTransfer, true);
                     }
                     IResourceList froms = attachment.GetLinksFrom("Contact", PROP.From);
                     foreach (IResource from in froms)
                     {
                         formatFile.AddLink(PROP.From, from);
                     }
                     IResourceList tos = formatFile.GetLinksFrom("Contact", PROP.To);
                     foreach (IResource to in tos)
                     {
                         formatFile.AddLink(PROP.To, to);
                     }
                     attachment.Delete();
                 }
                 else
                 {
                     IResource mail = attachment.GetLinkProp(PROP.InternalAttachment);
                     if (mail != null)
                     {
                         attachment.AddLink(PROP.Attachment, mail);
                     }
                     attachment.ChangeType("UnknownFile");
                 }
             }
             RS.ResourceTypes.Delete(STR.Attachment);
         }
     }
     catch (StorageException) {}
 }
Example #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();
            }
        }
Example #3
0
        /**
         * finds or creates resource for a file
         * for the UnknowFile type creates transient resources
         */
        public IResource FindOrCreateFile(FileInfo fileInfo, bool createTransient)
        {
            string   resourceType;
            bool     indexIt       = false;
            DateTime lastWriteTime = IOTools.GetLastWriteTime(fileInfo);
            string   extension     = IOTools.GetExtension(fileInfo);
            int      size          = (int)IOTools.GetLength(fileInfo);
            string   name          = IOTools.GetName(fileInfo);

            IResource file = FindFile(fileInfo);

            if (file != null)
            {
                if (!Core.ResourceStore.IsOwnerThread())
                {
                    return((IResource)_resourceAP.RunUniqueJob(_cUpdatingFileJob, _findOrCreateFileDelegate, fileInfo, createTransient));
                }
                file.BeginUpdate();
                if (file.Type == FileProxy._unknownFileResourceType &&
                    (resourceType = _ftm.GetResourceTypeByExtension(extension)) != null)
                {
                    file.ChangeType(resourceType);
                    indexIt = true;
                }
                if (name != file.GetPropText(Core.Props.Name))
                {
                    file.SetProp(Core.Props.Name, name);
                    indexIt = true;
                }
                if (lastWriteTime != file.GetDateProp(Core.Props.Date))
                {
                    file.SetProp(Core.Props.Date, lastWriteTime);
                    indexIt = true;
                }
                indexIt = indexIt || (!file.IsTransient && !file.HasProp("InTextIndex"));
                file.SetProp(FileProxy._propSize, size);
                string filetype = FileSystemTypes.GetFileType(extension);
                file.SetProp(FileProxy._propFileType, filetype ?? "Unknown");
            }
            else
            {
                string    directoryName = IOTools.GetDirectoryName(fileInfo);
                IResource folder        = FindOrCreateDirectory(directoryName);
                if (folder == null)
                {
                    return(null);
                }
                resourceType = _ftm.GetResourceTypeByExtension(extension);

                /**
                 * look through pending file deletions
                 */
                IResourceList deletedFiles = Core.ResourceStore.FindResourcesWithProp(resourceType, FileProxy._propDeletedFile);
                deletedFiles = deletedFiles.Intersect(
                    Core.ResourceStore.FindResources(null, FileProxy._propSize, size), true);
                deletedFiles = deletedFiles.Intersect(
                    Core.ResourceStore.FindResources(null, Core.Props.Name, name), true);
                if (deletedFiles.Count > 0)
                {
                    file = deletedFiles[0];
                    if (!file.IsTransient)
                    {
                        if (!Core.ResourceStore.IsOwnerThread())
                        {
                            return((IResource)_resourceAP.RunUniqueJob(
                                       _cUpdatingFileJob, _findOrCreateFileDelegate, fileInfo, createTransient));
                        }
                        file.BeginUpdate();
                    }
                }
                if (file == null)
                {
                    if (resourceType != null && !createTransient)
                    {
                        if (!Core.ResourceStore.IsOwnerThread())
                        {
                            return((IResource)_resourceAP.RunUniqueJob(
                                       _cUpdatingFileJob, _findOrCreateFileDelegate, fileInfo, createTransient));
                        }
                        file    = Core.ResourceStore.BeginNewResource(resourceType);
                        indexIt = true;
                    }
                    else
                    {
                        if (!createTransient)
                        {
                            return(null);
                        }
                        if (resourceType == null)
                        {
                            resourceType = FileProxy._unknownFileResourceType;
                        }
                        file = Core.ResourceStore.NewResourceTransient(resourceType);
                    }
                }
                file.SetProp(FileProxy._propParentFolder, folder);
                file.SetProp(FileProxy._propDirectory, directoryName);
                file.SetProp(Core.Props.Name, name);
                file.SetProp(Core.Props.Date, lastWriteTime);
                file.SetProp(FileProxy._propSize, size);
                string filetype = FileSystemTypes.GetFileType(extension);
                file.SetProp(FileProxy._propFileType, filetype ?? "Unknown");
            }
            file.SetProp(FileProxy._propDeletedFile, false);
            if (!file.IsTransient)
            {
                file.EndUpdate();
                if (indexIt)
                {
                    Core.TextIndexManager.QueryIndexing(file.Id);
                }
            }
            return(file);
        }
Example #4
0
        private static void UpdateResources()
        {
            string[] lastTypes = ObjectStore.ReadString("UnknownFiles", "LastConf").Split(';');
            string[] types     = (Core.FileResourceManager as FileResourceManager).GetResourceTypes();
            if (types.Length == lastTypes.Length)
            {
                bool needUpdate = false;
                Array.Sort(types);
                Array.Sort(lastTypes);
                for (int i = 0; i < types.Length; ++i)
                {
                    if (types[i] != lastTypes[i])
                    {
                        needUpdate = true;
                        break;
                    }
                }
                // plugin configuration not changed
                if (!needUpdate)
                {
                    return;
                }
            }
            IResourceList   unknownRcs     = Core.ResourceStore.GetAllResources(_unknowFileResourceType);
            IProgressWindow progressWindow = Core.ProgressWindow;

            for (int i = 0, percents = 0; i < unknownRcs.Count && Core.State != CoreState.ShuttingDown; ++i)
            {
                if (progressWindow != null)
                {
                    progressWindow.UpdateProgress(percents / unknownRcs.Count, "Updating unknown resources", null);
                    percents += 100;
                }
                IResource unknown = unknownRcs[i];
                IResource source  = FileResourceManager.GetSource(unknown);
                if (source != null)
                {
                    string resourceType = Core.FileResourceManager.GetResourceTypeByExtension(
                        IOTools.GetExtension(unknown.GetPropText(Core.Props.Name)));
                    if (resourceType != null)
                    {
                        unknown.ChangeType(resourceType);
                    }
                }
            }
            foreach (IResourceType resType in Core.ResourceStore.ResourceTypes)
            {
                if (resType.HasFlag(ResourceTypeFlags.FileFormat) && !resType.OwnerPluginLoaded)
                {
                    IResourceList formatFiles = Core.ResourceStore.GetAllResources(resType.Name);
                    foreach (IResource formatFile in formatFiles)
                    {
                        formatFile.ChangeType(_unknowFileResourceType);
                    }
                }
            }
            StringBuilder confString = new StringBuilder();

            foreach (string restype in types)
            {
                confString.Append(restype);
                confString.Append(";");
            }
            ObjectStore.WriteString("UnknownFiles", "LastConf", confString.ToString().TrimEnd(';'));
        }