Esempio n. 1
0
        public void CmFileFinder_NoPreExistingCmFile()
        {
            // Setup
            string sNewFile = Path.DirectorySeparatorChar + Path.GetRandomFileName();

            m_fileOs.AddFile(sNewFile, "456", Encoding.Default);

            ICmFolder folder = DomainObjectServices.FindOrCreateFolder(Cache,
                                                                       LangProjectTags.kflidPictures, CmFolderTags.LocalPictures);

            // Test
            ICmFile file = DomainObjectServices.FindOrCreateFile(folder, sNewFile);

            Assert.IsNotNull(file, "null CmFile returned");
            Assert.AreEqual(sNewFile, file.InternalPath, "Internal path not set correctly");
            Assert.AreEqual(sNewFile, file.AbsoluteInternalPath, "Files outside LangProject.LinkedFilesRootDir are stored as absolute paths");
            Assert.AreNotEqual(m_pict.PictureFileRA, file);
            FileUtils.Delete(sNewFile);
        }
Esempio n. 2
0
        /// -------------------------------------------------------------------------------------
        /// <summary>
        /// Create a CmPicture from a dummy file.
        /// </summary>
        /// -------------------------------------------------------------------------------------
        protected override void CreateTestData()
        {
            base.CreateTestData();

            m_fileOs = new MockFileOS();
            FileUtils.Manager.SetFileAdapter(m_fileOs);

            m_fileOs.AddFile(m_internalPath, "123", Encoding.Default);

            m_pictureFactory = Cache.ServiceLocator.GetInstance <ICmPictureFactory>();
            m_pict           = m_pictureFactory.Create(m_internalPath,
                                                       Cache.TsStrFactory.MakeString("Test picture", Cache.DefaultVernWs),
                                                       CmFolderTags.LocalPictures);

            Assert.IsNotNull(m_pict);
            Assert.AreEqual("Test picture", m_pict.Caption.VernacularDefaultWritingSystem.Text);
            Assert.AreEqual(m_internalPath, m_pict.PictureFileRA.InternalPath, "Internal path not set correctly");
            Assert.AreEqual(m_internalPath, m_pict.PictureFileRA.AbsoluteInternalPath, "Files outside LangProject.LinkedFilesRootDir are stored as absolute paths");
        }
Esempio n. 3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a temp file containing a single book
        /// </summary>
        /// <param name="sSILBookId">Three-letter SIL code for the book represented by the file
        /// being created</param>
        /// <param name="dataLines">Array of lines of SF text to write following the ID line.
        /// This text should not include line-break characters.</param>
        /// <param name="encoding">The character encoding</param>
        /// <param name="fWriteByteOrderMark">Pass <c>true</c> to have the BOM written at the
        /// beginning of a Unicode file (ignored if encoding is ASCII).</param>
        /// <returns>Name of file that was created</returns>
        /// ------------------------------------------------------------------------------------
        public string CreateFile(string sSILBookId, string[] dataLines, Encoding encoding, bool fWriteByteOrderMark)
        {
            if (sSILBookId == null)
            {
                throw new ArgumentNullException("sSILBookId");
            }

            // Create a temporary file.
            string fileName = FileUtils.GetTempFile("tmp");

            if (!FileUtils.FileExists(fileName))
            {
                s_fileOs.AddFile(fileName, string.Empty, encoding);
            }

            using (var file = FileUtils.OpenFileForBinaryWrite(fileName, encoding))
            {
                // write the byte order marker
                if (fWriteByteOrderMark && encoding != Encoding.ASCII)
                {
                    file.Write('\ufeff');
                }

                // Write the id line to the file, IF it's length is > 0
                if (sSILBookId.Length > 0)
                {
                    file.Write(EncodeLine(@"\id " + sSILBookId, encoding));
                }

                // write out the file contents
                if (dataLines != null)
                {
                    foreach (string sLine in dataLines)
                    {
                        file.Write(EncodeLine(sLine, encoding));
                    }
                }
                file.Close();

                return(fileName);
            }
        }