Beispiel #1
0
    public void DeleteSelectedTraceFiles()
    {
        for (int i = 0; i < traceFileListView.SelectedItems.Count; i++)
        {
            string fileName = string.Format(@"{0}\{1}", _traceFileDir, traceFileListView.SelectedItems[i].SubItems[2].Text);

            try
            {
                GenericHelper.DeleteFile(fileName);
            }
            catch (Exception ex)
            {
                string text = "Error deleting Trace File.\r\n\r\n{0}";

                if (ConfigHandler.UseTranslation)
                {
                    text = Translator.GetText("errorDeletingTrace");
                }

                OutputHandler.Show(string.Format(text, ex.Message), GenericHelper.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        RefreshTraceFileListView();
    }
Beispiel #2
0
    private static bool SendLogtoWebService(int returnCode)
    {
        bool success = false;

        string machineName = Environment.MachineName;
        string userName    = Environment.UserName;
        string domainName  = Environment.UserDomainName;

        try
        {
            ServiceHandler service = new ServiceHandler(new Uri(_sendLogToWebService));

            if (ConfigHandler.StatisticsArchive == null)
            {
                object[] args = { "SQL Event Analyzer", GenericHelper.Version, machineName, userName, domainName, returnCode, OutputHandler.GetLog() };
                success = service.InvokeMethod <bool>("LogService", "RegisterLogEvent", args);
            }
            else
            {
                byte[]   attachment = GetDocument(ConfigHandler.StatisticsArchive);
                object[] args       = { "SQL Event Analyzer", GenericHelper.Version, machineName, userName, domainName, returnCode, OutputHandler.GetLog(), attachment };
                success = service.InvokeMethod <bool>("LogService", "RegisterLogEventWithAttachment", args);

                GenericHelper.DeleteFile(ConfigHandler.StatisticsArchive);
            }
        }
        catch
        {
        }

        return(success);
    }
Beispiel #3
0
    public bool DeleteCheckedTraceFiles()
    {
        bool success = true;

        OutputHandler.WriteToLog(string.Format("Deleting Trace Files after import. Number of Trace Files to delete: {0}", traceFileListView.CheckedItems.Count));

        for (int i = 0; i < traceFileListView.CheckedItems.Count; i++)
        {
            string fileName = string.Format(@"{0}\{1}", _traceFileDir, traceFileListView.CheckedItems[i].SubItems[2].Text);

            try
            {
                GenericHelper.DeleteFile(fileName);
            }
            catch (Exception ex)
            {
                success = false;

                string text = "Error deleting Trace File.\r\n\r\n{0}";

                if (ConfigHandler.UseTranslation)
                {
                    text = Translator.GetText("errorDeletingTrace");
                }

                OutputHandler.Show(string.Format(text, ex.Message), GenericHelper.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        return(success);
    }
Beispiel #4
0
    public static bool WriteXmlToFile(string xml, string fileName)
    {
        try
        {
            if (File.Exists(fileName))
            {
                GenericHelper.DeleteFile(fileName);
            }

            XmlDocument xmlDocument = FormatXml(xml);
            xmlDocument.LoadXml(xml);

            XmlTextWriter xmlTextWriter = new XmlTextWriter(fileName, Encoding.UTF8);
            xmlTextWriter.IndentChar  = '\t';
            xmlTextWriter.Indentation = 1;
            xmlTextWriter.Formatting  = Formatting.Indented;
            xmlDocument.WriteContentTo(xmlTextWriter);

            xmlTextWriter.Flush();
            xmlTextWriter.Close();

            return(true);
        }
        catch (Exception ex)
        {
            MessageBox.Show(string.Format("Error writing Xml to file.\r\n\r\n{0}", ex.Message), GenericHelper.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return(false);
        }
    }
Beispiel #5
0
    public bool CompressCheckedTraceFiles(int filesToKeep, string sevenZipFileName)
    {
        bool success = true;

        OutputHandler.WriteToLog(string.Format("Compressing Trace Files after import. Number of Trace Files to compress: {0}", traceFileListView.CheckedItems.Count));

        try
        {
            GenericHelper.WriteFile(sevenZipFileName, SQLEventAnalyzer.Properties.Resources._7za);
        }
        catch (Exception ex)
        {
            OutputHandler.WriteToLog(string.Format("Error writing 7za.exe in CompressCheckedTraceFiles: \"{0}\"", ex.Message));
            success = false;
        }

        if (success)
        {
            for (int i = 0; i < traceFileListView.CheckedItems.Count; i++)
            {
                string fileName = string.Format(@"{0}\{1}", _traceFileDir, traceFileListView.CheckedItems[i].SubItems[2].Text);

                try
                {
                    CompressionHandler.CompressFile(fileName, string.Format(@"{0}\{1}.7z", _traceFileDir, Path.GetFileNameWithoutExtension(fileName)), sevenZipFileName);
                }
                catch (Exception ex)
                {
                    success = false;

                    string text = "Error compressing Trace File.\r\n\r\n{0}";

                    if (ConfigHandler.UseTranslation)
                    {
                        text = Translator.GetText("errorCompressingTrace");
                    }

                    OutputHandler.Show(string.Format(text, ex.Message), GenericHelper.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }

            if (filesToKeep > 0)
            {
                DeleteOldCompressedFiles(filesToKeep, _traceFileDir);
            }

            try
            {
                GenericHelper.DeleteFile(sevenZipFileName);
            }
            catch
            {
            }
        }

        return(success);
    }
    public static bool DeleteTraceFile(bool showError, DatabaseOperation databaseOperation)
    {
        databaseOperation.DropEventSession();

        if (Directory.Exists(ConfigHandler.RecordTraceFileDir))
        {
            foreach (string file in Directory.GetFiles(ConfigHandler.RecordTraceFileDir, string.Format("{0}*.*", ConfigHandler.TraceFileName)))
            {
                try
                {
                    GenericHelper.DeleteFile(file);
                }
                catch (Exception ex)
                {
                    if (showError)
                    {
                        string text = "Error deleting Trace File.\r\n\r\n{0}";

                        if (ConfigHandler.UseTranslation)
                        {
                            text = Translator.GetText("errorDeletingTrace");
                        }

                        OutputHandler.Show(string.Format(text, ex.Message), GenericHelper.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }

                    return(false);
                }
            }
        }
        else
        {
            if (showError)
            {
                string text = "The Trace File Directory \"{0}\" does not exist.\r\n\r\nPlease create the directory manually.";

                if (ConfigHandler.UseTranslation)
                {
                    text = Translator.GetText("createTraceDirManually");
                }

                OutputHandler.Show(string.Format(text, ConfigHandler.RecordTraceFileDir), GenericHelper.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            return(false);
        }

        return(true);
    }
Beispiel #7
0
    private static void DeleteOldCompressedFiles(int filesToKeep, string traceFileDir)
    {
        DirectoryInfo di = new DirectoryInfo(traceFileDir);

        FileInfo[] zipFiles = di.GetFiles(@"*.7z");

        GenericHelper.DateCompareFileInfo dayCompareFileInfo = new GenericHelper.DateCompareFileInfo();

        Array.Sort(zipFiles, dayCompareFileInfo);

        for (int i = filesToKeep; i < zipFiles.Length; i++)
        {
            try
            {
                GenericHelper.DeleteFile(zipFiles[i].FullName);
            }
            catch
            {
            }
        }
    }
Beispiel #8
0
    private static bool CompressStatisticsDirectory(string tempPath, string archiveName, string sevenZipFileName)
    {
        bool success = true;

        try
        {
            GenericHelper.WriteFile(sevenZipFileName, SQLEventAnalyzer.Properties.Resources._7za);
        }
        catch (Exception ex)
        {
            OutputHandler.WriteToLog(string.Format("Error writing 7za.exe in CompressStatisticsDirectory: \"{0}\"", ex.Message));
            success = false;
        }

        if (success)
        {
            try
            {
                CompressionHandler.CompressDirectory(tempPath, archiveName, sevenZipFileName);
            }
            catch (Exception ex)
            {
                OutputHandler.WriteToLog(string.Format("Error creating statistics archive: \"{0}\"", ex.Message));
                success = false;
            }
        }

        if (success)
        {
            try
            {
                GenericHelper.DeleteFile(sevenZipFileName);
            }
            catch
            {
            }
        }

        return(success);
    }
Beispiel #9
0
    private static string ApplyCustomColumnsUpdate(string fileName)
    {
        string updatedXml          = null;
        string tempFilenameAndPath = string.Format(@"{0}\{1}", GenericHelper.TempPath, Path.GetFileName(fileName));

        try
        {
            string           oldXml     = File.ReadAllText(fileName, Encoding.UTF8);
            ColumnCollection oldColumns = ColumnHelper.XmlToColumnCollection(oldXml);

            string           newXml     = File.ReadAllText(tempFilenameAndPath, Encoding.UTF8);
            ColumnCollection newColumns = ColumnHelper.XmlToColumnCollection(newXml);

            foreach (Parameter oldParameter in oldColumns.Parameters)
            {
                foreach (Parameter newParameter in newColumns.Parameters)
                {
                    if (oldParameter.Name == newParameter.Name)
                    {
                        newParameter.Value = oldParameter.Value;
                        break;
                    }
                }
            }

            updatedXml = ColumnHelper.ColumnCollectionToXml(newColumns);

            WriteXmlToFile(ColumnHelper.ColumnCollectionToXml(newColumns), fileName);
            GenericHelper.DeleteFile(tempFilenameAndPath);
        }
        catch (Exception ex)
        {
            OutputHandler.Show(string.Format("Error applying Custom Column update.\r\n\r\n{0}", ex.Message), GenericHelper.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

        return(updatedXml);
    }
    public static void InitializeLog()
    {
        DirectoryInfo di = new DirectoryInfo(GenericHelper.ExecPath);

        FileInfo[] logFiles = di.GetFiles(string.Format(@"{0}*.log", GenericHelper.ApplicationName));

        GenericHelper.DateCompareFileInfo dateCompareFileInfo = new GenericHelper.DateCompareFileInfo();

        Array.Sort(logFiles, dateCompareFileInfo);

        for (int i = ConfigHandler.NumberOfServiceContextLogFiles - 1; i < logFiles.Length; i++)
        {
            try
            {
                GenericHelper.DeleteFile(logFiles[i].FullName);
            }
            catch
            {
            }
        }

        _fileNameDate = GenericHelper.FormatFileNameDate(DateTime.Now);
        _log          = new StringBuilder();
    }
Beispiel #11
0
    private static bool CompressStatistics(string saveToPath, string tempPath, string tempPathSendToWebService, List <string> sendToWebServiceNames, string sevenZipFileName)
    {
        string archiveName = string.Format(@"{0}\Statistics.zip", GenericHelper.TempPath);

        bool success = CompressStatisticsDirectory(tempPath, archiveName, sevenZipFileName);

        if (saveToPath != null)
        {
            if (Directory.Exists(saveToPath))
            {
                try
                {
                    File.Copy(archiveName, string.Format(@"{0}\Statistics.zip", saveToPath), true);
                }
                catch (Exception ex)
                {
                    OutputHandler.WriteToLog(string.Format("Error copying Statistics.zip to \"{0}\". Error: {1}", saveToPath, ex.Message));
                    success = false;
                }
            }
            else
            {
                OutputHandler.WriteToLog(string.Format("Error: Directory \"{0}\" does not exist", saveToPath));
                success = false;
            }
        }

        if (success)
        {
            try
            {
                foreach (string file in Directory.GetFiles(tempPath))
                {
                    GenericHelper.DeleteFile(file);
                }

                Directory.Delete(tempPath);
            }
            catch
            {
            }
        }

        if (success)
        {
            try
            {
                GenericHelper.DeleteFile(archiveName);
            }
            catch
            {
            }
        }

        if (sendToWebServiceNames.Count > 0)
        {
            if (success)
            {
                success = CompressStatisticsDirectory(tempPathSendToWebService, archiveName, sevenZipFileName);
            }

            if (success)
            {
                try
                {
                    foreach (string file in Directory.GetFiles(tempPathSendToWebService))
                    {
                        GenericHelper.DeleteFile(file);
                    }

                    Directory.Delete(tempPathSendToWebService);
                }
                catch
                {
                }
            }

            if (success)
            {
                ConfigHandler.StatisticsArchive = archiveName;
            }
        }

        return(success);
    }