Esempio n. 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Update the properties of a CmPicture with the given file, caption, and folder.
        /// </summary>
        /// <param name="srcFilename">The full path to the original filename (an internal copy
        /// will be made in this method)</param>
        /// <param name="captionTss">The caption</param>
        /// <param name="sFolder">The name of the CmFolder where picture should be stored</param>
        /// <param name="ws">The WS for the location in the caption MultiUnicode to put the
        /// caption</param>
        /// ------------------------------------------------------------------------------------
        public void UpdatePicture(string srcFilename, ITsString captionTss, string sFolder, int ws)
        {
            // Locate CmFolder with given name or create it, if neccessary
            ICmFolder folder = CmFolder.FindOrCreateFolder(m_cache, (int)LangProject.LangProjectTags.kflidPictures, sFolder);
            ICmFile   file   = PictureFileRA;

            if (file == null)
            {
                file          = folder.FilesOC.Add(new CmFile());
                PictureFileRA = file;
            }
            // (The case-independent comparison is valid only for Microsoft Windows.)
            string sInternalAbsPath = file.AbsoluteInternalPath;

            if (srcFilename != null &&
                !srcFilename.Equals(sInternalAbsPath, StringComparison.InvariantCultureIgnoreCase))
            {
                ((CmFile)file).SetInternalPath(srcFilename);
            }
            Caption.SetAlternative(captionTss, ws);
            m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, Hvo,
                                (int)CmPicture.CmPictureTags.kflidCaption, ws, 0, 0);
            m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, file.Hvo,
                                (int)CmFile.CmFileTags.kflidInternalPath, 0, 1, 1);
        }
Esempio n. 2
0
        public void CmFileFinder_OrigFilesMatch()
        {
            CheckDisposed();

            // Setup
            ICmFolder folder = CmFolder.FindOrCreateFolder(Cache, (int)LangProject.LangProjectTags.kflidPictures,
                                                           StringUtils.LocalPictures);

            using (DummyFileMaker maker = new DummyFileMaker("garbage.jpg", true))
            {
                ICmFile fileOrig = new CmFile();
                folder.FilesOC.Add(fileOrig);
                fileOrig.InternalPath = maker.Filename;

                ICmFile file = CmFile.FindOrCreateFile(folder, maker.Filename);
                Assert.AreEqual(fileOrig, file);
            }
        }
Esempio n. 3
0
        public void CmFileFinder_NoPreExistingCmFile()
        {
            CheckDisposed();

            // Setup
            ICmFolder folder = CmFolder.FindOrCreateFolder(Cache, (int)LangProject.LangProjectTags.kflidPictures,
                                                           StringUtils.LocalPictures);

            using (DummyFileMaker maker = new DummyFileMaker("junk56.jpg", true))
            {
                ICmFile file = CmFile.FindOrCreateFile(folder, maker.Filename);
                Assert.IsNotNull(file, "null CmFile returned");
                Assert.IsNotNull(file.InternalPath, "Internal path not set correctly");
                Assert.IsTrue(file.AbsoluteInternalPath == file.InternalPath, "Files outside LangProject.ExtLinkRootDir are stored as absolute paths");
                m_internalFilesToDelete.Add(file.AbsoluteInternalPath);
                Assert.IsTrue(m_pict.PictureFileRAHvo != file.Hvo);
            }
        }
Esempio n. 4
0
        public void CmFileFinder_OrigFileMissing()
        {
            CheckDisposed();

            // Setup
            ICmFolder folder = CmFolder.FindOrCreateFolder(Cache, (int)LangProject.LangProjectTags.kflidPictures,
                                                           StringUtils.LocalPictures);
            string origFile = m_pict.PictureFileRA.AbsoluteInternalPath;

            try
            {
                File.Delete(origFile);
            }
            catch
            {
            }
            Assert.IsFalse(File.Exists(origFile),
                           "Test cannot proceed. Unable to delete Original file.");

            // Test
            ICmFile file = CmFile.FindOrCreateFile(folder, origFile);
        }
Esempio n. 5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initialize a new CmPicture by creating a copy of the file in the given folder and
        /// hooking everything up.
        /// </summary>
        /// <param name="srcFilename">The path to the original filename (an internal copy will
        /// be made in this method)</param>
        /// <param name="captionTss">The caption (in the given Writing System)</param>
        /// <param name="description">Illustration description in English. This is not
        /// published.</param>
        /// <param name="layoutPos">Indication of where in the column/page the picture is to be
        /// laid out.</param>
        /// <param name="scaleFactor">Integral percentage by which picture is grown or shrunk.</param>
        /// <param name="locationRangeType">Indicates the type of data contained in LocationMin
        /// and LocationMax.</param>
        /// <param name="locationMin">The minimum Scripture reference at which this picture can
        /// be laid out.</param>
        /// <param name="locationMax">The maximum Scripture reference at which this picture can
        /// be laid out.</param>
        /// <param name="copyright">Publishable information about the copyright that should
        /// appear on the copyright page of the publication.</param>
        /// <param name="sFolder">The name of the CmFolder where picture should be stored
        /// </param>
        /// <param name="ws">The WS of the caption and copyright</param>
        /// ------------------------------------------------------------------------------------
        public void InitializeNewPicture(string srcFilename, ITsString captionTss,
                                         string description, PictureLayoutPosition layoutPos, int scaleFactor,
                                         PictureLocationRangeType locationRangeType, int locationMin, int locationMax,
                                         string copyright, string sFolder, int ws)
        {
            // Set the caption first since creating the CmFile will throw if srcFilename is empty.
            if (captionTss != null)
            {
                Caption.SetAlternative(captionTss, ws);
            }
            // Locate CmFolder with given name or create it, if neccessary
            ICmFolder folder = CmFolder.FindOrCreateFolder(m_cache, (int)LangProject.LangProjectTags.kflidPictures, sFolder);

            PictureFileRA = CmFile.FindOrCreateFile(folder, srcFilename);
            int wsEn = Cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr("en");

            if (!String.IsNullOrEmpty(description) && wsEn > 0)
            {
                Description.SetAlternative(description, wsEn);
            }
            LayoutPos         = layoutPos;
            ScaleFactor       = scaleFactor;
            LocationRangeType = locationRangeType;
            LocationMin       = locationMin;
            LocationMax       = locationMax;
            if (!string.IsNullOrEmpty(copyright))
            {
                string sExistingCopyright = PictureFileRA.Copyright.GetAlternative(ws).Text;
                if (sExistingCopyright != null && sExistingCopyright != copyright)
                {
                    Logger.WriteEvent("Could not update copyright for picture " +
                                      PictureFileRA.AbsoluteInternalPath + " to '" + copyright + "'");
                    return;
                }
                PictureFileRA.Copyright.SetAlternative(copyright, ws);
            }
        }