コード例 #1
0
 static void Main(string[] args)
 {
     if (args.Length == 2)
     {
         string arg1 = args[0].ToLower();
         string arg2 = args[1].ToLower();
         using (WebClient W = new WebClient())
         {
             W.DownloadFile("ftp://ftp.univ.kiev.ua/pub/linux/centos/build/rpmcompare5.pl.txt", @"C:\Users\maksy\OneDrive\Документы\2.2 курс\Petrovich\rpmcompare5.pl.txt");
         }
         using (StreamReader sr = new StreamReader(File.OpenRead(@"C:\Users\maksy\OneDrive\Документы\2.2 курс\Petrovich\rpmcompare5.pl.txt")))
         {
             using (StreamWriter sw = new StreamWriter(File.Open(@"C:\Users\maksy\OneDrive\Документы\2.2 курс\Petrovich\RpmCompare-LIGHT.txt", FileMode.Create)))
             {
                 string   CurLine;
                 string[] split;
                 int      counter;
                 bool     cheker1;
                 bool     cheker2;
                 string   ls;
                 while (!sr.EndOfStream)
                 {
                     cheker1 = false;
                     cheker2 = false;
                     counter = 0;
                     CurLine = sr.ReadLine();
                     split   = CurLine.Split(new String[] { "\t", " " }, StringSplitOptions.RemoveEmptyEntries);
                     foreach (string s in split)
                     {
                         ls = s.ToLower();
                         if (ls.Contains(arg1) || (counter == 0 && ls.StartsWith("#")))
                         {
                             cheker1 = true;
                         }
                         else if (ls.Contains("="))
                         {
                             cheker2 = true;
                         }
                         counter++;
                     }
                     if (cheker1)
                     {
                     }
                     else if (cheker2)
                     {
                         sw.WriteLine(arg2);
                     }
                     else
                     {
                         sw.WriteLine(CurLine);
                     }
                 }
             }
         }
     }
     else
     {
         Console.WriteLine("SYNTAX: SysProga1.exe <Arg1> <Arg2>");
     }
 }
コード例 #2
0
        public static void LoadConfig()
        {
            if (File.Exists("IRCStatistician.conf"))
            {
                AppLog.WriteLine(1, "STATUS", "Loading configuration from IRCStatistician.conf");
                string       CurLine;
                StreamReader ConfigFile = new StreamReader("IRCStatistician.conf");
                while ((CurLine = ConfigFile.ReadLine()) != null)
                {
                    if (CurLine.Substring(0, 1) != "#")
                    {
                        string[] CurLineSplit = CurLine.Split(new char[1] {
                            '='
                        }, 2);
                        AppLog.WriteLine(4, "CONFIG", "Configuration Option: " + CurLineSplit[0] + " = " + CurLineSplit[1]);
                        switch (CurLineSplit[0].ToLower())
                        {
                        case "sqlserverhost":
                            m_SQLServerHost = CurLineSplit[1];
                            break;

                        case "sqlserverport":
                            m_SQLServerPort = Convert.ToInt32(CurLineSplit[1]);
                            break;

                        case "sqlusername":
                            m_SQLUsername = CurLineSplit[1];
                            break;

                        case "sqlpassword":
                            m_SQLPassword = CurLineSplit[1];
                            break;

                        case "sqldatabase":
                            m_SQLDatabase = CurLineSplit[1];
                            break;

                        case "sqltableprefix":
                            m_SQLTablePrefix = CurLineSplit[1];
                            break;

                        case "resolution":
                            m_Resolution = Convert.ToInt32(CurLineSplit[1]);
                            break;

                        default:
                            AppLog.WriteLine(1, "ERROR", "Unknown Configuration Option: " + CurLineSplit[0] + " = " + CurLineSplit[1]);
                            break;
                        }
                    }
                }
            }
            else
            {
                AppLog.WriteLine(1, "ERROR", "No Configuration File Found. Did you copy IRCStatistician.sample.conf and change the settings?");
            }
        }
コード例 #3
0
        public void ProcessLog(string Data)
        {
            TextReader LogTextReader = new StringReader(Data);
            string     CurLine;
            int        i          = 0;
            DateTime   StartOfDay = DateTime.MinValue;
            DateTime   Timestamp  = DateTime.MinValue;

            while ((CurLine = LogTextReader.ReadLine()) != null)
            {
                if (CurLine.Substring(0, 1) == "#")
                {
                    if (CurLine.Substring(0, 15) == "# Opened (UTC):")
                    {
                        string DayStr = CurLine.Substring(16);
                        StartOfDay = Convert.ToDateTime(DayStr.Substring(0, DayStr.IndexOf(' ')));
                    }
                    // Is a comment
                }
                else
                {
                    string TimeNum = CurLine.Substring(0, CurLine.IndexOf(' '));
                    Timestamp = StartOfDay.AddMilliseconds(Convert.ToDouble(TimeNum));
                    // The will return the number of whole Config.Resolution chunks that have passed since Jan 1 2014.
                    uint TimeframeID = (uint)(((Timestamp - new DateTime(2014, 1, 1)).TotalSeconds) / Config.Resolution);
                    CurLine = CurLine.Substring(TimeNum.Length + 1);
                    if (CurLine.Substring(0, 1) == ":")
                    {
                        CurLine = CurLine.Substring(1);
                        string[] ParameterSplit = CurLine.Split(" ".ToCharArray(), 3, StringSplitOptions.RemoveEmptyEntries);
                        Sender   Sender         = IRCFunctions.ParseSender(ParameterSplit[0]);
                        string   Command        = ParameterSplit[1];
                        string   Parameters     = ParameterSplit[2];
                        Network.Parse(Timestamp, TimeframeID, Sender, Command, Parameters);
                    }
                    else if (CurLine.Substring(0, 4) == "PING")
                    {
                        // Do anything here?
                    }
                    else
                    {
                        AppLog.WriteLine(5, "DEBUG", "Unknown Line Format: " + CurLine);
                    }
                }
                i++;
            }
        }
コード例 #4
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Please supply input file");
                return;
            }

            StreamReader InputFile   = new StreamReader(args[0]);
            StreamWriter OutputFile1 = new StreamWriter(@"Output1.txt");
            StreamWriter OutputFile2 = new StreamWriter(@"Output2.txt");

            string CurLine;

            while ((CurLine = InputFile.ReadLine()) != null)
            {
                string[] b = { "a", "a" };
                if (CurLine.Contains(':'))
                {
                    b = CurLine.Split(':');
                }
                else if (CurLine.Contains(';'))
                {
                    b = CurLine.Split(';');
                }
                try
                {
                    OutputFile1.WriteLine(b[1]);
                    OutputFile2.WriteLine(b[0]);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(CurLine);
                    Console.WriteLine(ex);
                }
            }
            OutputFile1.Close();
            OutputFile2.Close();
            InputFile.Close();

            Console.WriteLine("Done Splitting!");
            Console.ReadKey();
        }
コード例 #5
0
    //-----------------------------------------------------------
    //	запись Tsv-текста в файл
    public bool    SaveToFile(string FileName)
    {
        int    I;
        bool   ContainsEmpty;
        string CurLine;

        string[] Columns;
        if (FileName == null)
        {
            return(false);
        }
        if ((Tsv == null) || (Tsv.Length == 0))
        {
            return(false);
        }
        string[] Lines = Tsv.ToString().Split(CCommon.Chr(13));
        if (Lines == null)
        {
            return(false);
        }
        if (Lines.Length == 0)
        {
            return(false);
        }
        bool        Result     = false;
        CTextWriter TextWriter = new   CTextWriter();

        if (!TextWriter.Create(FileName, CAbc.CHARSET_WINDOWS))
        {
            return(false);
        }

        for (I = 0; I < Lines.Length; I++)
        {
            Result  = true;
            CurLine = Lines[I].Replace(CAbc.BIG_UKR_I, "I").Replace(CAbc.SMALL_UKR_I, "i").Trim();
            if (CurLine.Trim().Length == 0)
            {
                continue;
            }
            ContainsEmpty = true;
            Columns       = CurLine.Split(CCommon.Chr(9));
            if (Columns == null)
            {
                ContainsEmpty = true;                                           // есть пустые ячейки ?
            }
            else if (Columns.Length < 2)
            {
                ContainsEmpty = true;
            }
            else
            {
                foreach (string Item in Columns)
                {
                    if (Item.Trim().Length != 0)
                    {
                        ContainsEmpty = false;
                    }
                }
            }
            if (!ContainsEmpty)
            {
                if (!TextWriter.Add(CurLine + CAbc.CRLF))
                {
                    Result = false;
                }
            }
        }
        TextWriter.Close();
        return(Result);
    }
コード例 #6
0
ファイル: Form1.cs プロジェクト: toddrjen/EarLab
        private void RunModel()
        {
            string CurLine;

            string[] Fields;
            int      Frame  = 0;
            string   Delims = " ";

            char[] FieldDelims = Delims.ToCharArray();
            bool   Once        = true;

            btnRun.Enabled       = false;
            btnStop.Enabled      = true;
            udFrameCount.Enabled = false;
            menuModelRun.Enabled = false;

            mRunning         = false;
            sbTextPanel.Text = "Running";
            Log("Starting simulation");
            Log("Current path is: " + Directory.GetCurrentDirectory());

            Log("Module directory: \"" + ModuleDirectory + "\"");
            Log("Input directory: \"" + InputDirectory + "\"");
            Log("Output directory: \"" + OutputDirectory + "\"");
            Log("Model configuration: \"" + DiagramFile + "\"");
            Log("Module parameters: \"" + ParameterFile + "\"");
            Log("Beginning simulation\n");
            while (true)
            {
                CurLine = mExecutionProcess.StandardOutput.ReadLine();
                if ((CurLine != null) && (CurLine.IndexOf("Error") > 0))
                {
                    Log(CurLine);
                }
                else
                {
                    if ((CurLine != null) && (CurLine.StartsWith("  Starting Frame ")))
                    {
                        Fields            = CurLine.Split(FieldDelims);
                        Frame             = Int32.Parse(Fields[Fields.Length - 1]);
                        progressBar.Value = Frame;
                        sbTextPanel.Text  = "Running: Frame " + Frame.ToString() + "/" + mFrameCount.Value.ToString();
                    }
                }
                if (Frame < 2)
                {
                    Log(CurLine);
                }
                else
                {
                    if (Once)
                    {
                        Once = false;
                        Log("Simulation running, please wait");
                    }
                }
                if (mExecutionProcess.HasExited)
                {
                    break;
                }
            }
            progressBar.Value   = progressBar.Maximum;
            progressBar.Visible = false;
            if (mExecutionProcess.ExitCode != 0)
            {
                Log("Simulation completed with errors");
            }
            else
            {
                Log("Simulation complete");
            }
            Log("Ready");

            btnRun.Enabled       = true;
            btnStop.Enabled      = false;
            btnAbort.Enabled     = false;
            udFrameCount.Enabled = true;
            UpdateStatusDisplay();
            udFrameCount.Focus();
            mRunning             = false;
            menuModelRun.Enabled = true;
            if (RunningFromCommandLineInput)
            {
                Application.Exit();
            }
        }