コード例 #1
0
        /// <summary>
        /// Tests the API by loading the input file, saving it to memory and comparing it to the wished result file.
        /// </summary>
        /// <param name="inFile">The file to load and save.</param>
        /// <param name="resultFile">The file to compare to.</param>
        private static void DoLoadSaveTest(string inFile, string resultFile)
        {
            MadCatzProfile profile = ProfileFactory.Load(inFile);

            byte[] data = null;
            using (var stream = new MemoryStream())
            {
                ProfileFactory.Save(stream, profile);
                data = stream.GetBuffer();
            }

            StreamReader writtenReader = null;
            MemoryStream memStream     = null;
            string       written       = null;

            try
            {
                memStream     = new MemoryStream(data);
                writtenReader = new StreamReader(memStream);
                written       = writtenReader.ReadToEnd().Trim().Replace("\0", string.Empty);
                writtenReader.Close();
                writtenReader = null;
                memStream     = null;
            }
            finally
            {
                if (writtenReader != null)
                {
                    writtenReader.Close();
                    writtenReader = null;
                    memStream     = null;
                }
                if (memStream != null)
                {
                    memStream.Close();
                }
            }

            StreamReader originalReader = null;
            string       original       = null;

            try
            {
                originalReader = new StreamReader(resultFile);
                original       = originalReader.ReadToEnd().Trim();
                originalReader.Close();
                originalReader = null;
            }
            finally
            {
                if (originalReader != null)
                {
                    originalReader.Close();
                }
            }

            Assert.AreEqual(original, written);
        }
コード例 #2
0
        public void SaveProfile(MadCatzProfile profile)
        {
            if (!HasSaveFile(profile))
            {
                throw new InvalidOperationException("Can't save the profile: there is no save location available.");
            }

            ProfileFactory.Save(profileInfos[profile].ProfileFile, profile);
            profileInfos[profile].Edited = false;
        }
コード例 #3
0
 public void SaveProfile(MadCatzProfile profile, FileInfo saveFile)
 {
     ProfileFactory.Save(saveFile, profile);
     profileInfos[profile].Edited      = false;
     profileInfos[profile].ProfileFile = saveFile;
 }