public bool GetPluginEnabledState(ContentSourceInfo contentSourceInfo)
 {
     if (_enabledStateChanges.Contains(contentSourceInfo))
         return (bool)_enabledStateChanges[contentSourceInfo];
     else
         return contentSourceInfo.Enabled;
 }
        public LiveClipboardFormatHandler(LiveClipboardContentSourceAttribute lcAttribute, ContentSourceInfo contentSource)
        {
            ResourceManager resMan = new ResourceManager(contentSource.GetType());
            string resourceNamePrefix = "LiveClipboardContentSource." + lcAttribute.Name + ".";

            _format = new LiveClipboardFormat(lcAttribute.ContentType, lcAttribute.Type);
            _formatName = LoadResourcedString(resMan, resourceNamePrefix + "Name", lcAttribute.Name);
            _formatDescription = LoadResourcedString(resMan, resourceNamePrefix + "Description", lcAttribute.Description);
            _formatImagePath = lcAttribute.ImagePath;
            _contentSource = contentSource;
        }
        public static bool ExecuteSimpleContentRetreival(
            IWin32Window dialogOwner, ContentSourceInfo contentSourceInfo, string url, ref string title, ref string newContent)
        {
            try
            {
                // if there is progress requested then just do it on the main UI thread
                if (contentSourceInfo.UrlContentSourceRequiresProgress)
                {
                    // create the progress dialog and the async operation
                    UrlContentRetreivalWithProgressDialog progressDialog = new UrlContentRetreivalWithProgressDialog(contentSourceInfo);
                    progressDialog.CreateControl();
                    SimpleUrlContentRetreivalAsyncOperation asyncOperation = new SimpleUrlContentRetreivalAsyncOperation(progressDialog, contentSourceInfo.Instance as ContentSource, url, title);

                    // execute and retreive results
                    if (ExecuteWithProgress(dialogOwner, progressDialog, asyncOperation, contentSourceInfo))
                    {
                        title = asyncOperation.Title;
                        newContent = asyncOperation.NewContent;
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    try
                    {
                        (contentSourceInfo.Instance as ContentSource).CreateContentFromUrl(url, ref title, ref newContent);
                        return true;
                    }
                    catch (Exception ex)
                    {
                        ContentSourceManager.DisplayContentRetreivalError(dialogOwner, ex, contentSourceInfo);
                        return false;
                    }
                }

            }
            catch (Exception ex)
            {
                Trace.Fail("Unexpected exception executing network operation for content source: " + ex.ToString());
                return false;
            }
        }
        public UrlContentRetreivalWithProgressDialog(ContentSourceInfo contentSourceInfo)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            this.buttonCancel.Text = Res.Get(StringId.CancelButton);

            this.labelCaption.Font = Res.GetFont(FontSize.Normal, FontStyle.Bold);
            // initialize text
            Text = contentSourceInfo.Name;
            labelCaption.Text = contentSourceInfo.UrlContentSourceProgressCaption != String.Empty ? contentSourceInfo.UrlContentSourceProgressCaption : Res.Get(StringId.UrlRetrieveProgressCaption);
            labelDetails.Text = contentSourceInfo.UrlContentSourceProgressMessage != String.Empty ? contentSourceInfo.UrlContentSourceProgressMessage : Res.Get(StringId.UrlRetrieveProgressMessage);

            // initialize animated bitmap
            _animatedBitmapControl.Bitmaps = AnimationBitmaps;
            _animatedBitmapControl.Interval = 75;

            Icon = ApplicationEnvironment.ProductIcon;
        }
        private static bool ExecuteWithProgress(
            IWin32Window dialogOwner,
            UrlContentRetreivalWithProgressDialog progressDialog,
            UrlContentRetreivalAsyncOperation asyncOperation,
            ContentSourceInfo contentSourceInfo)
        {
            try
            {
                // show the progress dialog
                using (progressDialog)
                {
                    asyncOperation.Start();
                    progressDialog.ShowProgress(dialogOwner, asyncOperation);
                }

                //  handle the result
                if (asyncOperation.Error != null)
                {
                    ContentSourceManager.DisplayContentRetreivalError(dialogOwner, asyncOperation.Error, contentSourceInfo);
                    return false;
                }
                else if (asyncOperation.WasCancelled)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                Trace.Fail("Unexpected exception executing network operation for content source: " + ex.ToString());
                return false;
            }
        }
 private static void DisplayPluginException(IWin32Window owner, ContentSourceInfo csi, Exception e)
 {
     Trace.Fail(e.ToString());
     DisplayableException ex = new DisplayableException(
         Res.Get(StringId.UnexpectedErrorPluginTitle),
         string.Format(CultureInfo.CurrentCulture, Res.Get(StringId.UnexpectedErrorPluginDescription), csi.Name, e.Message));
     DisplayableExceptionDisplayForm.Show(owner, ex);
 }
        private bool InsertSmartContentFromUrl(ContentSourceInfo contentSource, string url)
        {
            SmartContentSource smartSource = contentSource.Instance as SmartContentSource;
            string title = String.Empty;
            IExtensionData extensionData = _contentSourceSite.CreateExtensionData(Guid.NewGuid().ToString());
            ISmartContent smartContent = new SmartContent(extensionData);

            if (UrlContentRetreivalWithProgress.ExecuteSmartContentRetreival(
                EditorContext.FrameWindow, contentSource, url, ref title, smartContent))
            {
                string content = smartSource.GenerateEditorHtml(smartContent, _contentSourceSite);
                if (content != null)
                {
                    _contentSourceSite.InsertContent(contentSource.Id, content, extensionData);
                }
                return true;
            }
            else
            {
                return false;
            }
        }
        private bool InsertSimpleContentFromUrl(ContentSourceInfo contentSource, string url)
        {
            string title = String.Empty;
            string content = String.Empty;

            if (UrlContentRetreivalWithProgress.ExecuteSimpleContentRetreival(
                EditorContext.FrameWindow, contentSource, url, ref title, ref content))
            {
                _contentSourceSite.InsertContent(content, false);
                return true;
            }
            else
            {
                return false;
            }
        }
        private bool InsertSmartContentFromLiveClipboard(ContentSourceInfo contentSource, XmlDocument lcDocument)
        {
            SmartContentSource smartSource = contentSource.Instance as SmartContentSource;
            if (smartSource == null)
            {
                Trace.Fail("Unexpected failure to get live clipboard content-source!");
                return false;
            }

            // create the smart content
            IExtensionData extensionData = _contentSourceSite.CreateExtensionData(Guid.NewGuid().ToString());
            ISmartContent smartContent = new SmartContent(extensionData);
            if (smartSource.CreateContentFromLiveClipboard(EditorContext.FrameWindow, lcDocument, smartContent) == DialogResult.OK)
            {
                // generate html and insert it
                string content = smartSource.GenerateEditorHtml(smartContent, _contentSourceSite);
                if (content != null)
                {
                    _contentSourceSite.InsertContent(contentSource.Id, content, extensionData);
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        private bool InsertSimpleContentFromLiveClipboard(ContentSourceInfo contentSource, XmlDocument lcDocument)
        {
            ContentSource lcContentSource = contentSource.Instance as ContentSource;
            if (lcContentSource == null)
            {
                Trace.Fail("Unexpected failure to get live clipboard content-source!");
                return false;
            }

            // create the content
            string content = String.Empty;
            if (lcContentSource.CreateContentFromLiveClipboard(EditorContext.FrameWindow, lcDocument, ref content) == DialogResult.OK)
            {
                _contentSourceSite.InsertContent(content, false);
                return true;
            }
            else
            {
                return false;
            }
        }
 public LiveClipboardComponentDisplay(ContentSourceInfo contentSource)
 {
     // if this format handler is "built-in" then override the content-source to
     // list it as "windows-live writer"
     if (ContentSourceManager.ContentSourceIsPlugin(contentSource.Id))
     {
         _icon = contentSource.Image;
         _name = contentSource.Name;
     }
     else
     {
         _icon = _writerLogoBitmap;
         _name = ApplicationEnvironment.ProductName;
     }
 }
 public static void DisplayContentRetreivalError(IWin32Window dialogOwner, Exception ex, ContentSourceInfo info)
 {
     if (ex is ContentCreationException)
     {
         ContentCreationException ccEx = ex as ContentCreationException;
         DisplayableExceptionDisplayForm.Show(dialogOwner, new DisplayableException(ccEx.Title, ccEx.Description));
     }
     else if (ex is NotImplementedException)
     {
         DisplayableExceptionDisplayForm.Show(dialogOwner, new DisplayableException(
             Res.Get(StringId.MethodNotImplemented), String.Format(CultureInfo.InvariantCulture, Res.Get(StringId.MethodNotImplementedDetail), info.Name, info.WriterPluginPublisherUrl, ex.Message)));
     }
     else
     {
         DisplayableExceptionDisplayForm.Show(dialogOwner, ex);
     }
 }
        public static void PerformInsertion(IContentSourceSite sourceSite, ContentSourceInfo contentSource)
        {
            // record use of content-source (used to list source in MRU order on the sidebar)
            RecordContentSourceUsage(contentSource.Id);

            try
            {
                if (contentSource.Instance is SmartContentSource)
                {
                    SmartContentSource scSource = (SmartContentSource)contentSource.Instance;

                    IExtensionData extensionData = sourceSite.CreateExtensionData(Guid.NewGuid().ToString());

                    // SmartContentSource implementations *must* be stateless (see WinLive 126969), so we wrap up the
                    // internal smart content context and pass it in as a parameter to the CreateContent call.
                    ISmartContent sContent;
                    if (scSource is IInternalSmartContentSource)
                    {
                        sContent = new InternalSmartContent(extensionData, sourceSite as IInternalSmartContentContextSource, contentSource.Id);
                    }
                    else
                    {
                        sContent = new SmartContent(extensionData);
                    }

                    if (scSource.CreateContent(sourceSite.DialogOwner, sContent) == DialogResult.OK)
                    {
                        string content = scSource.GenerateEditorHtml(sContent, sourceSite);
                        if (content != null)
                        {
                            sourceSite.InsertContent(contentSource.Id, content, extensionData);
                            sourceSite.Focus();

                            if (ApplicationPerformance.ContainsEvent(MediaInsertForm.EventName))
                                ApplicationPerformance.EndEvent(MediaInsertForm.EventName);
                        }
                    }
                }
                else if (contentSource.Instance is ContentSource)
                {
                    ContentSource sSource = (ContentSource)contentSource.Instance;
                    string newContent = String.Empty; // default
                    try { if (sourceSite.SelectedHtml != null) newContent = sourceSite.SelectedHtml; }
                    catch { } // safely try to provide selected html
                    if (sSource.CreateContent(sourceSite.DialogOwner, ref newContent) == DialogResult.OK)
                    {
                        sourceSite.InsertContent(newContent, contentSource.Id == WebImageContentSource.ID);
                        sourceSite.Focus();
                    }
                }
            }
            catch (Exception ex)
            {
                DisplayContentRetreivalError(sourceSite.DialogOwner, ex, contentSource);
            }
        }
        // TODO: Instead of prompting for each one, show one consolidated dialog
        private static bool PluginIsEnabled(IWin32Window owner, BlogPublishingPluginSettings settings, ContentSourceInfo plugin, bool defaultEnabled)
        {
            bool? alreadyEnabled = settings.IsEnabled(plugin.Id);
            if (alreadyEnabled != null)
                return alreadyEnabled.Value;

            // Got here? then we haven't seen this plugin before

            if (owner == null)
                return defaultEnabled;

            bool enabled = DisplayMessage.Show(MessageId.ShouldUsePlugin, owner, plugin.Name) == DialogResult.Yes;
            settings.Set(plugin.Id, enabled, settings.KnownPluginIds.Length);
            return enabled;
        }
        public ContentSourceCommand(IContentSourceSite sourceSite, ContentSourceInfo contentSourceInfo, bool isBuiltInPlugin)
        {
            // copy references
            _insertionSite = sourceSite;
            _contentSourceInfo = contentSourceInfo;

            // tie this command to the content-source for execution
            // (we don't initialize other properties b/c this Command
            // is only use for decoupled lookup & execution not for
            // UI display. If we actually want to display this command
            // on a command bar, etc. we should fill in the other properties.
            this.Identifier = contentSourceInfo.Id;

            // For built in plugins, we will get these values from the ribbon
            if (contentSourceInfo.CanCreateNew && !isBuiltInPlugin)
            {
                this.MenuText = ((IMenuCommandObject)this).Caption;
                this.CommandBarButtonBitmapEnabled = contentSourceInfo.Image;
            }
        }
 private static bool CanHandleUrl(ContentSourceInfo contentSource, string url)
 {
     try
     {
         if (typeof(IHandlesMultipleUrls).IsAssignableFrom(contentSource.Type))
         {
             IHandlesMultipleUrls plugin = (IHandlesMultipleUrls)Activator.CreateInstance(contentSource.Type);
             return plugin.HasUrlMatch(url);
         }
         Regex regex = new Regex(contentSource.UrlContentSourceUrlPattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
         return regex.IsMatch(url);
     }
     catch
     {
         return false;
     }
 }
Esempio n. 17
0
        private ISmartContent GetSmartContentForPublishHook(ContentSourceInfo csi)
        {
            // Use the plugin ID as content ID because there can only be
            // one per post anyway

            Debug.Assert(typeof(HeaderFooterSource).IsAssignableFrom(csi.Type));

            string contentId = csi.Id;
            ISmartContent smartContent =
                ((IContentSourceSidebarContext)this).FindSmartContent(contentId);
            if (smartContent == null)
                smartContent = new SmartContent(((IContentSourceSite)this).CreateExtensionData(contentId));
            return smartContent;
        }
 public void SetPluginEnabledState(ContentSourceInfo contentSourceInfo, bool enabled)
 {
     _enabledStateChanges[contentSourceInfo] = enabled;
     Modified();
 }