public void FindOrCreateDefaultContent( IVersionedUniqueId plugin, Func<Stream> contentAccessor, string culture = null )
 {
     string pluginHelpDirectoryPath = GetBaseHelpDirectoryForPlugin( plugin, culture );
     if( !Directory.Exists( pluginHelpDirectoryPath ) )
     {
         UnzipAndExtractStream( contentAccessor(), pluginHelpDirectoryPath );
     }
 }
Ejemplo n.º 2
0
 public void FireShowHostHelp()
 {
     if( _fakeUniqueIdForTheHost == null ) _fakeUniqueIdForTheHost = new SimpleVersionedUniqueId( Guid.Empty, AppVersion );
     if( ShowHostHelp != null )
         ShowHostHelp( this, new HostHelpEventArgs { HostUniqueId = _fakeUniqueIdForTheHost } );
 }
Ejemplo n.º 3
0
        string GetHelpLocalContentFilePath( IVersionedUniqueId pluginName, string culture = null )
        {
            if( culture == null ) culture = CultureInfo.CurrentCulture.TwoLetterISOLanguageName.ToLowerInvariant();

            // try to load the help of the plugin in the good culture (current or given)
            string localhelp = Path.Combine( GetBaseHelpDirectoryForPlugin( pluginName ), culture, "index.html" );
            if( !File.Exists( localhelp ) )
            {
                // if the help does not exists, and if the given culture is already the default, there is no help content
                if( culture == _defaultCulture )
                {
                    localhelp = NoContentFilePath;
                }
                else
                {
                    // if the given culture is still not the default, and a specialized culture, try to load the help for the base culture
                    if( culture.Contains( '-' ) ) return GetHelpLocalContentFilePath( pluginName, culture.Substring( culture.IndexOf( '-' ) ) );
                    else return GetHelpLocalContentFilePath( pluginName, _defaultCulture );
                }

            }

            return localhelp;
        }
Ejemplo n.º 4
0
 string GetBaseHelpDirectoryForPlugin( IVersionedUniqueId pluginName )
 {
     return Path.Combine( LocalHelpBaseDirectory, pluginName.UniqueId.ToString( "B" ), pluginName.Version.ToString() );
 }
Ejemplo n.º 5
0
 public bool ShowHelpFor( IVersionedUniqueId pluginName, bool force = false )
 {
     string url = GetHelpLocalContentFilePath( pluginName );
     bool found = url != NoContentFilePath;
     if( found || force )
     {
         Application.Current.Dispatcher.BeginInvoke( (Action)( () =>
         {
             HelpBrowser._browser.Navigate( url );
             HelpBrowser.Show();
         } ), null );
     }
     return found;
 }
Ejemplo n.º 6
0
 public void RegisterHelpContent( IVersionedUniqueId pluginName, Stream zipContent )
 {
     string key = pluginName.UniqueId.ToString( "B" ) + pluginName.Version.ToString();
     if( !RegisteredHelps.Contains( key ) )
     {
         UnzipAndExtractStream( zipContent, GetBaseHelpDirectoryForPlugin( pluginName ) );
         RegisteredHelps.Add( key );
     }
 }
Ejemplo n.º 7
0
        public CancellationTokenSource GetHelpContentFor( IVersionedUniqueId pluginName, Action<Task<string>> onComplete )
        {
            CancellationTokenSource cancellationToken = new CancellationTokenSource();
            Task<string> getContent = new Task<string>( () =>
            {
                using( StreamReader rdr = new StreamReader( GetHelpLocalContentFilePath( pluginName ) ) )
                {
                    return rdr.ReadToEnd();
                }
            }, cancellationToken.Token );

            getContent.ContinueWith( onComplete, cancellationToken.Token );

            getContent.Start();

            return cancellationToken;
        }
        string GetBaseHelpDirectoryForPlugin( IVersionedUniqueId pluginName, string culture = null )
        {
            string path = Path.Combine( HelpBaseDirectory, pluginName.UniqueId.ToString( "B" ), pluginName.Version == null ? "" : pluginName.Version.ToString() );
            if( !string.IsNullOrEmpty( culture ) )
            {
                path = Path.Combine( path, culture );
            }

            return path;
        }
        public void InstallDownloadedHelpContent( IVersionedUniqueId plugin, Func<Stream> contentAccessor, string culture, bool clean = false )
        {
            DirectoryInfo pluginHelpDirectory = new DirectoryInfo( GetBaseHelpDirectoryForPlugin( plugin, culture ) );
            if( clean && pluginHelpDirectory.Parent.Exists )
            {
                pluginHelpDirectory.Parent.Delete( true );
                pluginHelpDirectory.Create();
            }

            UnzipAndExtractStream( contentAccessor(), pluginHelpDirectory.FullName, "content" );
        }