예제 #1
0
        /// <summary>
        /// </summary>
        public void ForEachWithOverwritingTempFile <T>(IEnumerable <T> coll, string fileNamePrefix, Action <T, TempFile, TempFile> actionF)
        {
            if (coll == null || !coll.Any())
            {
                return;
            }

            string permFilename = fileNamePrefix;
            string tempFilename = fileNamePrefix + ".tmp";

            foreach (T elem in coll)
            {
                TempFile permFile = NewPermaFile(permFilename);
                TempFile tempFile = NewTempFile(tempFilename);

                try
                {
                    actionF(elem, permFile, tempFile);
                }
                finally
                {
                    if (File.Exists(tempFile.FilePath))
                    {
                        tempFile.MoveTo(permFile);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        ///   Creates 1 perma file and 1 temp file, using the fileNameTemplate, and applies an action to the
        ///   both TempFile objects, overwriting the perma file with the temp file.
        /// </summary>
        public void WithOverwritingTempFile(string fileNameTemplate, Action <TempFile, TempFile> actionF)
        {
            string permFilename = fileNameTemplate;
            string tempFilename = fileNameTemplate + ".tmp";

            TempFile permFile = NewPermaFile(permFilename);
            TempFile tempFile = NewTempFile(tempFilename);

            try
            {
                actionF(permFile, tempFile);
            }
            finally
            {
                if (File.Exists(tempFile.FilePath))
                {
                    tempFile.MoveTo(permFile);
                }
            }
        }