public static void WriteToXmlFile(object objectToSerialize, string path)
        {
            var contents = SerializeToXml(objectToSerialize);

            if (!ContentChecker.ContentsAreEqual(contents, path))
            {
                File.WriteAllText(path, contents);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Thread safe file overwriting method
        /// </summary>
        /// <param name="path">Path to the file</param>
        /// <param name="data">Data to insert</param>
        /// <param name="numBytes">Number of bytes to write</param>
        public static void WriteToFile(string path, byte[] data, int numBytes)
        {
            lock (GetLockSemaphore(path))
            {
                if (ContentChecker.ContentsAreEqual(data, numBytes, path))
                {
                    return;
                }

                using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write))
                {
                    fs.Write(data, 0, numBytes);
                }
            }
        }