Пример #1
0
 public void ShowErrorMessage(string message)
 {
     lblGeneralError.Text = message;
     modalExtenderError.Show();
     SetFocus(btnOkError.ClientID);
     logFiles.ErrorMessageLog("show error message text " + message);
 }
Пример #2
0
    public static void DeleteRunFile(string userdirPath, string username, bool logSuccess)
    {
        string   pathToRunFile = userdirPath + CalcClass.RUN_FILE;
        LogFiles logFiles      = new LogFiles(username);

        if (FileOperations.WaitForFile(pathToRunFile, 500, 3))
        {
            try {
                File.Delete(pathToRunFile);
                if (logSuccess)
                {
                    logFiles.ErrorMessageLog("Run file deleted successfully.");
                }
            } catch (Exception ex) {
                logFiles.ErrorLog(ex);
            }
        }
        else if (logSuccess)
        {
            logFiles.ErrorMessageLog("Run file '" + pathToRunFile + "' not found for user " + username + ".");
        }
    }
Пример #3
0
    public static void CreateDllInProcessFile(string username)
    {
        LogFiles logFiles = new LogFiles();
        string   fullPath = GetMainDirectory() + "Bin\\" + COMMON_RUN_FILE;

        try {
            using (StreamWriter runFile = new StreamWriter(fullPath, false)) {
                runFile.WriteLine(DateTime.Now.Ticks);
                runFile.Close();
            }
            logFiles.ErrorMessageLog("Created common fun file '" + fullPath + "'.");
        } catch (Exception ex) {
            logFiles.ErrorLog(ex);
            throw ex;
        }
    }
    public static bool WaitForFile(string fullPath, int milliseconds, int maxTries)
    {
        int numTries = 0;

        while (true)
        {
            ++numTries;
            try {
                // Attempt to open the file exclusively.
                using (FileStream fs = new FileStream(fullPath,
                                                      FileMode.Open, FileAccess.ReadWrite, FileShare.None, 100)) {
                    fs.ReadByte();

                    // If we got this far the file is ready
                    break;
                }
            } catch (Exception ex) {
                //logFiles.ErrorMessageLog("WaitForFile " + fullPath + "failed to get an exclusive lock: " + ex.ToString());

                if (numTries > maxTries)
                {
                    LogFiles logFiles = new LogFiles();
                    logFiles.ErrorMessageLog(
                        "WaitForFile " + fullPath + " failed to get an exclusive lock: " + ex.ToString() + ". Giving up after " + maxTries + " tries.");

                    return(false);
                }

                // Wait for the lock to be released
                System.Threading.Thread.Sleep(milliseconds);
            }
        }

        LogFiles lFiles = new LogFiles();

        lFiles.ErrorMessageLog("WaitForFile " + fullPath + " returning true after " + numTries + " tries.");
        return(true);
    }