Example #1
0
 private void CleanupLogger()
 {
     if (_logger != null)
     {
         _logger.Dispose();
         _logger = null;
     }
     if (!string.IsNullOrEmpty(_loggerFilename))
     {
         //** remove the log file
         System.IO.File.Delete(_loggerFilename);
         _loggerFilename = null;
     }
     if (_loggerTransDetails != null)
     {
         _loggerTransDetails.Dispose();
         _loggerTransDetails = null;
     }
     if (!string.IsNullOrEmpty(_loggerTransDetailsFilename))
     {
         System.IO.File.Delete(_loggerTransDetailsFilename);
         _loggerTransDetailsFilename = null;
     }
     //** dispose the text log file
     if (_loggerTransDetailsFileStream != null)
     {
         _loggerTransDetailsFileStream.Dispose();
         _loggerTransDetailsFileStream = null;
         _loggerTransDetailsBuffer     = null;
         System.IO.File.Delete(_loggerTransDetailsLogFilename);
     }
     //if (System.IO.Directory.Exists(LogFolder))
     //    System.IO.Directory.Delete(LogFolder, true);
 }
Example #2
0
        //** rollback the action
        private static bool ProcessLines(string loggerFilename,
                                         GenericLogger logger, ObjectServer server)
        {
            //** go to 1st line in transaction log text file
            string processedLinesFilename = string.Format("{0}Processed.dat", loggerFilename);
            var    plh = new ProcessedLinesHandler(processedLinesFilename);

            /*
             *  Create Test.dta
             *  Create File.dta
             *  Create Test.dta.log
             *  Create _SystemTransactionDataBackup
             *  Remove _SystemTransactionDataBackup
             *  Create _SystemTransactionDataBackup
             *  Remove _SystemTransactionDataBackup
             */
            using (plh)
            {
                if (logger != null)
                {
                    logger.Dispose();
                }
                if (Sop.Utility.Utility.FileExists(loggerFilename))
                {
                    System.IO.StreamReader reader = new System.IO.StreamReader(loggerFilename);
                    using (reader)
                    {
                        bool   previousIsCreateToken = false;
                        string previousTokenValue    = string.Empty;
                        int    lineCtr = 0;
                        while (!reader.EndOfStream)
                        {
                            string line = reader.ReadLine();
                            //** process line...
                            if (line.StartsWith("Create "))
                            {
                                if (previousIsCreateToken)
                                {
                                    plh.ProcessedLines = lineCtr;
                                    //DisposeTransRelatedFiles(PreviousTokenValue);
                                    if (server != null &&
                                        server.Filename == previousTokenValue)
                                    {
                                        server.Transaction = null;
                                        server.dispose(true);
                                    }
                                    try
                                    {
                                        System.IO.File.Delete(previousTokenValue);
                                    }
                                    catch
                                    {
                                        return(false);
                                    }
                                    plh.MarkLineSuccess();

                                    /* * marking the file entry with "Success" token:
                                     *  Create Test.dta
                                     *  Success
                                     *  Create File.dta
                                     *  Success
                                     *  Create Test.dta.log
                                     *  Success
                                     *  Create _SystemTransactionDataBackup
                                     *  Remove _SystemTransactionDataBackup
                                     *  Create _SystemTransactionDataBackup
                                     *  Remove _SystemTransactionDataBackup
                                     */
                                }
                                previousIsCreateToken = true;
                            }
                            else if (line.StartsWith("Remove "))
                            {
                                if (previousIsCreateToken)
                                {
                                    previousIsCreateToken = false;
                                }
                            }
                            lineCtr++;
                            previousTokenValue = line.Substring(7);
                        }
                        if (previousIsCreateToken)
                        {
                            plh.ProcessedLines = lineCtr;
                            System.IO.File.Delete(previousTokenValue);
                            plh.MarkLineSuccess();
                        }
                    }
                }
            }
            return(true);
        }