Exemplo n.º 1
0
        private void CollectLogFiles(List <ClusterNode> nodes)
        {
            //List<string> nodes = GetNodes();

            FolderBrowserDialog fbDialog = new FolderBrowserDialog();

            //fbDialog.Description = "Select a folder for save log files from nodes :";
            if (fbDialog.ShowDialog() != DialogResult.OK || nodes.Count == 0)
            {
                return;
            }



            // clean all files except *.zip, *.rar


            // list of new files
            List <string> fileList = new List <string>();

            // copy + rename
            foreach (ClusterNode node in nodes)
            {
                string logFilename = logFile;

                string logFilenameSep = (logFilename == string.Empty) ? "" : ("_");

                string srcLogPath = GetLogFolder(node.address) + Path.GetFileNameWithoutExtension(selectedApplication) + ".log";
                string dstLogPath = fbDialog.SelectedPath + @"\" + logFilenamePrefix + node.id + logFilenameSep + logFilename;
                string logMsg     = "[" + srcLogPath + "] to [" + dstLogPath + "]";

                // add to list
                fileList.Add(dstLogPath);

                try
                {
                    File.Copy(srcLogPath, dstLogPath);
                    AppLogger.Add("Copied file from " + logMsg);
                }
                catch (Exception exception)
                {
                    AppLogger.Add("Can't copy file from " + logMsg + ". EXCEPTION: " + exception.Message);
                }
            }

            // create archive
            if (!isLogZip)
            {
                return;
            }

            string currentTime = DateTime.Now.ToString("HHmmss");
            string currentDate = DateTime.Now.ToString("yyyyMMdd");

            string zipFilename = fbDialog.SelectedPath + @"\" + logFilenamePrefix + currentDate + "_" + currentTime + ".zip";

            CreateZipLogs(zipFilename, fileList);

            // clean *.log-files
            if (isLogRemove)
            {
                RemoveListOfFiles(fileList);
            }
        }