Ejemplo n.º 1
0
        public bool CanRenameResource(IResource res)
        {
            IBookmarkProfile profile = _bookmarkService.GetOwnerProfile(res);
            string           error;

            return((res.Type == "Weblink" || res.Type == "Folder") &&
                   (profile == null || profile.CanRename(res, out error)));
        }
Ejemplo n.º 2
0
 private void ProcessResourceStream(IResource resource, IResource source, TextReader reader,
                                    IResourceTextConsumer consumer)
 {
     _currentIndexedRes = resource;
     try
     {
         using (HTMLParser parser = new HTMLParser(reader))
         {
             parser.CloseReader = false;
             parser.AddTagHandler("link", LinkHandler);
             int    docID = resource.Id;
             string fragment;
             while (!parser.Finished)
             {
                 fragment = parser.ReadNextFragment();
                 if (fragment.Length > 0)
                 {
                     if (parser.InHeading)
                     {
                         consumer.AddDocumentHeading(docID, fragment);
                     }
                     else
                     {
                         consumer.AddDocumentFragment(docID, fragment);
                     }
                 }
             }
             // check whether source resource is favorite and has non-empty name property
             // if it hasn't, or has name equyal to URL then set name from the title of HTML stream
             if (source != null && source.Type == "Weblink")
             {
                 IBookmarkService service = (IBookmarkService)Core.PluginLoader.GetPluginService(typeof(IBookmarkService));
                 if (service != null)
                 {
                     string name = source.GetPropText(Core.Props.Name);
                     string url  = string.Empty;
                     if (Core.ResourceStore.PropTypes.Exist("URL"))
                     {
                         url = source.GetPropText("URL");
                         if (url.StartsWith("http://") || url.StartsWith("file://"))
                         {
                             url = url.Substring("http://".Length);
                         }
                         else if (url.StartsWith("ftp://"))
                         {
                             url = url.Substring("ftp://".Length);
                         }
                     }
                     if (url.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
                     {
                         foreach (char invalidChar in Path.GetInvalidPathChars())
                         {
                             url = url.Replace(invalidChar, '-');
                         }
                     }
                     if (name.Length == 0 || url.StartsWith(name))
                     {
                         string title = parser.Title.Trim();
                         if (title.Length > 0)
                         {
                             IBookmarkProfile profile = service.GetOwnerProfile(source);
                             string           error;
                             if (profile != null && profile.CanRename(source, out error))
                             {
                                 profile.Rename(source, title);
                                 service.SetName(source, title);
                             }
                         }
                     }
                 }
             }
         }
     }
     finally
     {
         _currentIndexedRes = null;
     }
 }
Ejemplo n.º 3
0
        /**
         * returns action flags for group of weblinks or folders (IAction.Update methods)
         */
        public static void IActionUpdateWeblinksOrFolders(
            IActionContext context, ref ActionPresentation presentation, ActionType type)
        {
            if (context.SelectedResources == null || context.SelectedResources.Count == 0)
            {
                presentation.Visible = false;
            }
            else
            {
                IBookmarkService service =
                    (IBookmarkService)Core.PluginLoader.GetPluginService(typeof(IBookmarkService));
                for (int i = 0; i < context.SelectedResources.Count; ++i)
                {
                    IResource res = context.SelectedResources[i];
                    if (res.Type != "Folder" && res.Type != "Weblink")
                    {
                        res = res.GetLinkProp("Source");
                        if (res == null || (res.Type != "Weblink" && res.Type != "Folder"))
                        {
                            presentation.Visible = false;
                            return;
                        }
                    }
                    IBookmarkProfile profile = service.GetOwnerProfile(res);
                    string           error   = null;
                    if (profile != null)
                    {
                        switch (type)
                        {
                        case ActionType.Create:
                        {
                            if (!profile.CanCreate(null, out error))
                            {
                                presentation.Visible = false;
                            }
                            break;
                        }

                        case ActionType.Update:
                        {
                            if (!profile.CanRename(res, out error))
                            {
                                presentation.Visible = false;
                            }
                            break;
                        }

                        case ActionType.Delete:
                        {
                            if (!profile.CanDelete(res, out error))
                            {
                                presentation.Visible = false;
                            }
                            break;
                        }

                        case ActionType.Edit:
                        {
                            break;
                        }
                        }
                        if (!presentation.Visible && error != null && error.Length > 0)
                        {
                            presentation.ToolTip = error;
                        }
                    }
                }
            }
        }