예제 #1
0
파일: EpubFactory.cs 프로젝트: jflepp/Epub
 public EpubFactory(
     IZipReader zipReader,
     IEpubStructureFactory structureFactory,
     IModelBuilderFactory modelBuilderFactory,
     IBookCleaner bookCleaner)
 {
     this.zipReader           = zipReader;
     this.structureFactory    = structureFactory;
     this.modelBuilderFactory = modelBuilderFactory;
     this.bookCleaner         = bookCleaner;
 }
예제 #2
0
        /// <summary>
        /// Get the relations for the specified part.
        /// </summary>
        /// <param name="zipReader">ZipReader for reading from the OOXML package</param>
        /// <param name="forPartPath">Part for which to get relations</param>
        /// <returns>List of Relationship nodes belonging to forFile</returns>
        protected static XmlNodeList GetRelations(IZipReader zipReader, string forPartPath)
        {
            string relPath   = GetRelationPath(forPartPath);
            var    relStream = zipReader.GetEntry(relPath);

            var relDocument = new XmlDocument();

            relDocument.Load(relStream);

            var rels = relDocument["Relationships"].GetElementsByTagName("Relationship");

            return(rels);
        }
예제 #3
0
        /// <summary>
        /// Method that extracts the actual XmlElement that will be used as this XmlContainer's
        /// XmlDocumentElement based on the relations and a ZipReader for the OOXML package.
        ///
        /// The default implementation simply returns the root of the first referenced part if
        /// there is only one part.
        ///
        /// Override this in subclasses to implement behaviour for more complex cases.
        /// </summary>
        /// <param name="zipReader">ZipReader for reading from the OOXML package</param>
        /// <param name="rels">List of Relationship nodes belonging to root part</param>
        /// <returns>The XmlElement that will become this record's XmlDocumentElement</returns>
        protected virtual XmlElement ExtractDocumentElement(IZipReader zipReader, XmlNodeList rels)
        {
            if (rels.Count != 1)
            {
                throw new Exception("Expected actly one Relationship in XmlContainer OOXML doc");
            }

            string partPath   = rels[0].Attributes["Target"].Value;
            var    partStream = zipReader.GetEntry(partPath);

            var partDoc = new XmlDocument();

            partDoc.Load(partStream);

            return(partDoc.DocumentElement);
        }
예제 #4
0
        /// <summary>
        /// Method that extracts the actual XmlElement that will be used as this XmlContainer's
        /// XmlDocumentElement based on the relations and a ZipReader for the OOXML package.
        ///
        /// The default implementation simply returns the root of the first referenced part if
        /// there is only one part.
        ///
        /// Override this in subclasses to implement behaviour for more complex cases.
        /// </summary>
        /// <param name="zipReader">ZipReader for reading from the OOXML package</param>
        /// <param name="rootRels">List of Relationship nodes belonging to root part</param>
        /// <returns>The XmlElement that will become this record's XmlDocumentElement</returns>
        protected override XmlElement ExtractDocumentElement(IZipReader zipReader, XmlNodeList rootRels)
        {
            if (rootRels.Count != 1)
            {
                throw new Exception("Expected actly one Relationship in Theme OOXML doc");
            }

            string      managerPath      = rootRels[0].Attributes["Target"].Value;
            string      managerDirectory = Path.GetDirectoryName(managerPath).Replace("\\", "/");
            XmlNodeList managerRels;

            try
            {
                managerRels = GetRelations(zipReader, managerPath);
            }
            catch (Exception)
            {
                this.XmlDocumentElement = null;
                return(null);
            }

            if (managerRels.Count != 1)
            {
                throw new Exception("Expected actly one Relationship for Theme manager");
            }

            string partPath   = string.Format("{0}/{1}", managerDirectory, managerRels[0].Attributes["Target"].Value);
            var    partStream = zipReader.GetEntry(partPath);

            var partDoc = new XmlDocument();

            partDoc.Load(partStream);

            XmlNode e = partDoc.DocumentElement;

            b2xtranslator.Tools.Utils.replaceOutdatedNamespaces(ref e);

            return((XmlElement)e);
        }
예제 #5
0
파일: AppShellImpl.cs 프로젝트: weeble/ohos
 public AppShellImpl(
     IAppServices aFullPrivilegeAppServices,
     IConfigFileCollection aConfiguration,
     IAddinManager aAddinManager,
     IAppsDirectory aAppsDirectory,
     IStoreDirectory aStoreDirectory,
     Func<DvDevice, string, string, string, IDvProviderOpenhomeOrgApp1> aAppProviderConstructor,
     IZipReader aZipReader,
     IAppMetadataStore aMetadataStore,
     IZipVerifier aZipVerifier,
     ISystemAppsConfiguration aSystemAppsConfiguration,
     IXappServer aXappServer,
     bool aAutoStart)
 {
     iFullPrivilegeAppServices = aFullPrivilegeAppServices;
     iZipVerifier = aZipVerifier;
     iXappServer = aXappServer;
     //iZipReader = aZipReader;
     iMetadataStore = aMetadataStore;
     iConfiguration = aConfiguration;
     iAddinManager = aAddinManager;
     iAppsDirectory = aAppsDirectory;
     iStoreDirectory = aStoreDirectory;
     iAppProviderConstructor = aAppProviderConstructor;
     iNodeRebooter = iFullPrivilegeAppServices.NodeRebooter;
     //iApps = new Dictionary<string, PublishedApp>();
     iHistory = new List<HistoryItem>();
     // !!!! restore previous history from disk
     iKnownApps = new Dictionary<string, KnownApp>();
     foreach (var app in iMetadataStore.LoadAppsFromStore())
     {
         GetOrCreateKnownApp(app.AppName);
     }
     foreach (string dirname in iAppsDirectory.GetAppSubdirectories())
     {
         GetOrCreateKnownApp(dirname);
     }
     MarkSystemApps(aSystemAppsConfiguration);
     if (aAutoStart)
     {
         Start();
     }
 }
예제 #6
0
파일: ZipVerifier.cs 프로젝트: weeble/ohos
 public ZipVerifier(IZipReader aZipReader)
 {
     iZipReader = aZipReader;
 }
예제 #7
0
파일: AppShell.cs 프로젝트: weeble/ohos
 /// <summary>
 /// Create an app shell. Hosted apps are not automatically started.
 /// </summary>
 /// <param name="aFullPrivilegeAppServices">
 /// Services that will be provided to apps granted permissions.
 /// (If we implement restricted permissions, such apps would
 /// receive only a subset of these services.)
 /// </param>
 /// <param name="aConfiguration">
 /// Parsed config files. Some pre-installed apps need to read
 /// configuration  information (such as location of serial devices)
 /// from these files.
 /// </param>
 /// <param name="aAddinManager">
 /// Interface to the addin manager that handles actual loading of
 /// plugins. (Currently we use MEF.)
 /// </param>
 /// <param name="aAppsDirectory">
 /// Interface to inspect and manipulate the apps directory, where
 /// we put app binaries and their static data.
 /// </param>
 /// <param name="aStoreDirectory">
 /// Interface to inspect and manipulate the store directory, where
 /// apps store their dynamic, persistent data.
 /// </param>
 /// <param name="aAppProviderConstructor">
 /// Constructor to create an AppProvider. The AppShell is responsible
 /// for creating a device for each app and publishing the app service
 /// on that device on behalf of the app, and it uses this to construct
 /// such a provider. (Unit tests need to be able to pass in a
 /// substitute here.
 /// </param>
 /// <param name="aZipReader">
 /// Reads entries from a zip file.
 /// </param>
 /// <param name="aAppMetadataStore">
 /// Stores persistent data about apps, such as deferred deletions or
 /// upgrades.
 /// </param>
 /// <param name="aZipVerifier">
 /// Verifies that a zip file contains a valid OpenHome app.
 /// </param>
 /// <param name="aAutoStart">
 /// If true, start the AppShell immediately. Otherwise, caller needs
 /// to call Start() when they want to start apps.
 /// </param>
 public AppShell(
     IAppServices aFullPrivilegeAppServices,
     IConfigFileCollection aConfiguration,
     IAddinManager aAddinManager,
     IAppsDirectory aAppsDirectory,
     IStoreDirectory aStoreDirectory,
     Func<DvDevice, string, string, string, IDvProviderOpenhomeOrgApp1> aAppProviderConstructor,
     IZipReader aZipReader,
     IAppMetadataStore aAppMetadataStore, IZipVerifier aZipVerifier,
     ISystemAppsConfiguration aSystemAppsConfiguration,
     IXappServer aXappServer,
     bool aAutoStart)
 {
     lock (iLock)
     {
         iImpl = new AppShellImpl(
             aFullPrivilegeAppServices,
             aConfiguration,
             aAddinManager,
             aAppsDirectory,
             aStoreDirectory,
             aAppProviderConstructor,
             aZipReader,
             aAppMetadataStore,
             aZipVerifier,
             aSystemAppsConfiguration,
             aXappServer,
             aAutoStart);
         iImpl.AppStatusChanged += OnAppStatusChanged;
     }
 }