Esempio n. 1
0
        /// <summary>
        /// Adds/update file info on processed files log.
        /// </summary>
        /// <param name="m_filePath"></param>
        public static void RecordProcessedFile(string m_filePath)
        {
            Support.CreateFile(ProcessedFilesLog); // if file already exists, nothing is done.
            string[] ProcessedFiles = Support.getFileLines(ProcessedFilesLog);
            FileInfo FileInfo       = new FileInfo(m_filePath);

            for (int i = 0; i < ProcessedFiles.Length; i++)
            {
                if (ProcessedFiles[i].Split(';')[0] == m_filePath && ProcessedFiles[i].Split().Length > 1)
                {
                    //update existing record for that file
                    ProcessedFiles[i] = m_filePath + ";" + FileInfo.LastWriteTime.ToString();// + ";" + BuildMd5Checksum(m_filePath);
                    //rewrite file
                    WriteAllLines(ProcessedFilesLog, ProcessedFiles, true);
                    return;
                }
            }
            //add new record to end of file
            Support.WriteOneLine(ProcessedFilesLog, m_filePath + ";" + FileInfo.LastWriteTime.ToString(), true);// + ";" + BuildMd5Checksum(m_filePath),true);
        }
Esempio n. 2
0
        private void button_PIConfig_GetAllTagList_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(this, "Are you sure you want to extract tag list from PI? \r\nThis operation may take a while...", "Fetching PI tag list", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                //fetch pitags from pi
                System.Diagnostics.Process process = new System.Diagnostics.Process();

                string configName = listBox_ConfigList.GetItemText(listBox_ConfigList.SelectedItem);

                process.StartInfo.FileName               = Support.InstalPath + "\\resources\\piconfig.exe";
                process.StartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
                process.StartInfo.RedirectStandardInput  = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.UseShellExecute        = false;
                process.Start();
                string input = "";
                input = input + "@logi " + ConfigFile.read_attribute(configName, ConfigFile.AttribPIConfig_Host) + "," + ConfigFile.read_attribute(configName, ConfigFile.AttribPIConfig_User)
                        + "," + ConfigFile.read_attribute(configName, ConfigFile.AttribPIConfig_Pass) + "," + ConfigFile.read_attribute(configName, ConfigFile.AttribPIConfig_Port) + "\r\n";
                input = input + "@maxerr 65535" + "\r\n";
                input = input + "@table pipoint" + "\r\n";
                input = input + "@mode list" + "\r\n";
                input = input + "@ostr tag,pointtype" + "\r\n";
                input = input + "@ostr ..." + "\r\n";
                input = input + "@select tag=*" + "\r\n";
                input = input + "@endsection" + "\r\n";
                input = input + "@bye";

                process.StandardInput.Write(input);
                process.StandardInput.Flush();

                process.StandardInput.Close();

                string result = (process.StandardOutput.ReadToEnd());

                string[] results     = result.Split(new string[] { "\r\n" }, StringSplitOptions.None);
                string   finalresult = "";
                for (int i = 0; i < results.Length; i++)
                {
                    //test to see if line is valid information or not (alert, error, etc)
                    if (results[i].Contains(",") == true)
                    {
                        finalresult = finalresult + results[i].Split(',')[0] + "\r\n";
                    }
                }


                process.WaitForExit();
                //save on the alltags file
                Support.CreateFile(Support.AllTagFilePrefix + configName + ".txt");
                try
                {
                    Support.WriteOneLine(Support.AllTagFilePrefix + configName + ".txt", finalresult, false);
                }
                catch (Exception exc)
                {
                    LogFile.write_LogFile("Error trying to save list of all PI tags: " + exc.Message);
                }
                //DateTime time = DateTime.Now;             // Use current time.
                //string format = "dd/mm/yyyy hh:mm";   // Use this format.
            }
        }