Exemple #1
0
 internal static void QueueWeblink(IResource webLink, string URL, DateTime when)
 {
     if (when < DateTime.MaxValue)
     {
         FavoritesTools.TraceIfAllowed("Queueing " + URL + " to be processed at " + when);
         Core.NetworkAP.QueueJobAt(when, new FavoriteJob(webLink, URL));
     }
 }
Exemple #2
0
        private void EnumerateFavorites(string folder, IResource parent)
        {
            FileInfo[] files = IOTools.GetFiles(folder);
            if (files != null)
            {
                IResourceList weblinks          = BookmarkService.SubNodes("Weblink", parent);
                IntArrayList  processedWeblinks = new IntArrayList(files.Length);
                foreach (FileInfo fileInfo in files)
                {
                    IResource weblink = null;
                    try
                    {
                        if (fileInfo.Extension.ToLower() == ".url")
                        {
                            weblink = ProcessFavoriteFile(fileInfo, parent);
                        }
                        else if (fileInfo.Extension.ToLower() == ".lnk")
                        {
                            weblink = ProcessShortcut(fileInfo, parent);
                        }
                    }
                    catch (Exception e)
                    {
                        FavoritesTools.TraceIfAllowed(e.Message);
                        continue;
                    }
                    if (weblink != null)
                    {
                        processedWeblinks.Add(weblink.Id);
                    }
                }
                _bookmarkservice.DeleteBookmarks(weblinks.Minus(
                                                     Core.ResourceStore.ListFromIds(processedWeblinks, false)));
            }

            DirectoryInfo[] dirs = IOTools.GetDirectories(folder);
            if (dirs != null)
            {
                IResourceList folders          = BookmarkService.SubNodes("Folder", parent);
                IntArrayList  processedFolders = new IntArrayList(dirs.Length);
                foreach (DirectoryInfo dirInfo in dirs)
                {
                    IResource subfolder = _bookmarkservice.FindOrCreateFolder(parent, dirInfo.Name);
                    EnumerateFavorites(IOTools.GetFullName(dirInfo), subfolder);
                    processedFolders.Add(subfolder.Id);
                }
                _bookmarkservice.DeleteFolders(folders.Minus(
                                                   Core.ResourceStore.ListFromIds(processedFolders, false)));
            }
        }
Exemple #3
0
        /**
         * parse favorite file (.url), return corresponding weblink resource
         */
        private IResource ProcessFavoriteFile(FileInfo fileInfo, IResource parent)
        {
            FileStream stream = IOTools.OpenRead(fileInfo);

            if (stream != null)
            {
                using (StreamReader reader = new StreamReader(stream, Encoding.Default))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        string trimmedLine = line.Trim();
                        if (trimmedLine.ToLower().StartsWith("url="))
                        {
                            string url = trimmedLine.Substring(4, line.Length - 4).Trim();
                            FavoritesTools.TraceIfAllowed(
                                "Creating or updating '" + fileInfo.FullName + "', " + url);
                            return(CreateFavoriteResource(url, fileInfo, parent));
                        }
                    }
                }
            }
            return(null);
        }
Exemple #4
0
        private void DecoratedHttpReaderPredicate()
        {
            MethodInvoker method = _reader.NextMethod;

            _reader.InvokeAfterWait(null, null);   // clear readers methods
            if (_reader.Type == HttpReader.URLType.Undefined || method == null)
            {
                SetLastError("Protocol is not supported.");
                InvokeAfterWait(null, null);
                return;
            }

            /**
             * perform HttpReader work
             */
            method();

            /**
             * if there occured an http error save it and stop download
             */
            if (_reader.CurrentState == HttpReader.State.Error)
            {
                SetLastError(_reader.LastException.Message);
                InvokeAfterWait(null, null);
                return;
            }

            /**
             * if reading is performed the first time for the job, check whether
             * the content was changed or not from the last download attempt
             * stop download and set error if necessary
             */
            if (_lastState == HttpReader.State.Connecting &&
                (_reader.CurrentState == HttpReader.State.Done || _reader.CurrentState == HttpReader.State.Reading))
            {
                HttpWebResponse response = _reader.WebResponse;
                if (_webLink.HasProp("LastModified") && GetLastModified(response) <= LastModified())
                {
                    FavoritesTools.TraceIfAllowed(_reader.URL + " not modified, download stopped");
                    InvokeAfterWait(null, null);
                    return;
                }
            }

            /**
             * if download has finished, process response
             */
            if (_reader.CurrentState == HttpReader.State.Done)
            {
                FavoritesTools.TraceIfAllowed("_reader.CurrentState == HttpReader.State.Done");
                if (_reader.Type == HttpReader.URLType.File)
                {
                    Core.ResourceAP.QueueJob(new MethodInvoker(ProcessFile));
                }
                else if (_reader.Type == HttpReader.URLType.Web)
                {
                    Core.ResourceAP.QueueJob(new MethodInvoker(ProcessWebLink));
                }
            }
            _lastState = _reader.CurrentState;
            InvokeAfterWait(NextMethod, _reader.NextWaitHandle);
        }
Exemple #5
0
 public override void GroupFinished()
 {
     FavoritesTools.TraceIfAllowed("Finished download a group of " + _weblinks.Count + " weblinks");
 }
Exemple #6
0
 public override void GroupStarting()
 {
     FavoritesTools.TraceIfAllowed("Starting download a group of " + _weblinks.Count + " weblinks");
 }
Exemple #7
0
 internal static void ImmediateQueueWeblink(IResource webLink, string URL)
 {
     FavoritesTools.TraceIfAllowed("Queueing " + URL);
     Core.NetworkAP.QueueJob(JobPriority.Immediate, new FavoriteJob(webLink, URL));
 }