예제 #1
0
        /// <summary>
        /// Deletes all the files within the specified folder
        /// </summary>
        /// <param name="folder">The folder from which we wish to delete all of the files</param>
        public static void ClearFolder(DirectoryInfo folder)
        {
            SAFINCALog.Debug(CommonUtilities.GetClassAndMethodName(), folder.FullName);
            // Iterate each file
            foreach (FileInfo file in folder.GetFiles())
            {
                try
                {
                    // Delete the file, ignoring any exceptions
                    file.Delete();
                }
                catch (Exception)
                {
                }
            }

            // For each folder in the specified folder
            foreach (DirectoryInfo subfolder in folder.GetDirectories())
            {
                // Clear all the files in the folder
                ClearFolder(subfolder);
            }
        }
예제 #2
0
 /// <summary>
 /// Clear the cache for Inernet Explorer
 /// </summary>
 public static void ClearIECache()
 {
     SAFINCALog.Debug(CommonUtilities.GetClassAndMethodName());
     // Clear the special cache folder
     ClearFolder(new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)));
 }
예제 #3
0
 // Function added by Rahul
 public static void writeDataToExcelFile(string pathToDir, string fileName, string key, string value)
 {
     Excel.Workbook    workbook;
     Excel.Application xlApp = new Excel.Application();
     try
     {
         //String SHEET_NAME = getSheetName(key, value);
         String SHEET_NAME = "USER_DATA_TEST";
         workbook = xlApp.Workbooks.Open(pathToDir + fileName);
         Excel.Worksheet worksheet    = (Excel.Worksheet)workbook.Worksheets[SHEET_NAME];
         Excel.Range     range        = worksheet.UsedRange;
         int             rowCount     = range.Rows.Count;
         int             rowNameIndex = 0;
         for (int r = 1; r <= rowCount; r++)
         {
             string rowNameForCell = range.Cells[r, 1].Value.ToString();
             if (rowNameForCell.Equals(key))
             {
                 rowNameIndex = r;
                 break;
             }
         }
         if (rowNameIndex == 0)
         {
             range.Cells[rowCount + 1, 1] = key;
             range.Cells[rowCount + 1, 2] = value;
         }
         else
         {
             range.Rows[rowNameIndex].EntireRow.Delete();
             range.Cells[rowCount, 1] = key;
             range.Cells[rowCount, 2] = value;
         }
         xlApp.DisplayAlerts = false;
         long maxTimeToWait = CommonUtilities.GetCurrentTimeMillis() + CommonUtilities.GLOBAL_TIMEOUT_TIME_IN_MSEC;
         xlApp.Workbooks.Application.ActiveWorkbook.Save();
         while (!xlApp.Workbooks.Application.ActiveWorkbook.Saved && maxTimeToWait > CommonUtilities.GetCurrentTimeMillis())
         {
             xlApp.Workbooks.Application.ActiveWorkbook.Save();
         }
         xlApp.Workbooks.Close();
         xlApp.Quit();
         ProcessMgn.killProcessByNames(SAFINCA.ParameterAndUserDataMgn.Parameters.EXCEL_PROCESS_NAME);
     }
     catch (Exception e)
     {
         xlApp.DisplayAlerts = false;
         xlApp.Workbooks.Close();
         xlApp.Quit();
         ProcessMgn.killProcessByNames(SAFINCA.ParameterAndUserDataMgn.Parameters.EXCEL_PROCESS_NAME);
         throw new Exception(e.ToString());
     }
 }