public ColorManager() { Properties.Settings setting = new Properties.Settings(); _sundayForegroundColor = (ConsoleColor)Enum.Parse(_sundayForegroundColor.GetType(), setting.SundayForegroundColor); _saturdayForegroundColor = (ConsoleColor)Enum.Parse(_saturdayForegroundColor.GetType(), setting.SaturdayForegroundColor); _holidayForegroundColor = (ConsoleColor)Enum.Parse(_holidayForegroundColor.GetType(), setting.HolidayForegroundColor); _todayBackgroundColor = (ConsoleColor)Enum.Parse(_todayBackgroundColor.GetType(), setting.ToDayBackgroundColor); }
public TimedWaitTestCase ( ) { } // public TimedWaitTestCase (1 of 2) /// <summary> /// Use this constructor to create fully populated objects from a string /// read from a file of delimited text records. /// </summary> /// <param name="pstrRecord"> /// Pass in the record. /// </param> /// <param name="pchrDelimiter"> /// Identify the delimiter, so that I can change my mind about my choice /// of field delimiter. /// </param> public TimedWaitTestCase ( string pstrRecord ) { string [ ] astrFields = pstrRecord.Split ( s_achrFieldDelimiter ); if ( astrFields.Length == s_astrTimedWaitTestCaseInfo.Length ) { // Input contains the expected number of fields. int intPosition = ArrayInfo.ARRAY_INVALID_INDEX; foreach ( string strField in astrFields ) { intPosition++; if ( intPosition == s_intPos_puintWaitSeconds ) { uint.TryParse ( strField , out _twtc_puintWaitSeconds ); } else if ( intPosition == s_intPos_pstrCountdownWaitingFor ) { _twtc_pstrCountdownWaitingFor = strField; } else if ( intPosition == s_intPos_pclrTextColor ) { _twtc_pclrTextColor = ( ConsoleColor ) System.Enum.Parse ( _twtc_pclrTextColor.GetType ( ) , strField ); } else if ( intPosition == s_intPos_pclrTextBackgroundColor ) { _twtc_pclrTextBackgroundColor = ( ConsoleColor ) System.Enum.Parse ( _twtc_pclrTextBackgroundColor.GetType ( ) , strField ); } else if ( intPosition == s_intPos_penmInterruptCriterion ) { _twtc_penmInterruptCriterion = ( DisplayAids.InterruptCriterion ) System.Enum.Parse ( _twtc_penmInterruptCriterion.GetType ( ) , strField ); } } // foreach ( string strField in astrFields ) } // TRUE (expected outcome) block, if ( astrFields.Length == s_astrTimedWaitTestCaseInfo.Length ) else { // The input didn't split into the expected number of fields. string strMsg = string.Format ( Properties.Resources.TIMED_WAIT_TEST_CTOR_ERROR_3 , new object [ ] { pstrRecord , s_astrTimedWaitTestCaseInfo.Length , astrFields.Length , Environment.NewLine } ); throw new ArgumentException ( strMsg , Properties.Resources.TIMED_WAIT_TEST_CTOR_ARGNAME ); } // FALSE (exception) block, if ( astrFields.Length == s_astrTimedWaitTestCaseInfo.Length ) } // public TimedWaitTestCase (2 of 2)
static int Main(string[] args) { if (args.Length < 1) { Console.WriteLine("パラメータが見つかりません。マニュアルを確認してください。"); return(1); } if (args[0].ToUpper() == "SHOW") { ShowCommand show = new ShowCommand(Console.Out); if (args.Length == 1) { return(show.ShowAll()); } else { return(show.Show(args[1])); } } if (args[0].ToUpper() == "CLEAR") { Console.Clear(); return(0); } /* * これはあきらめます。理由はプロセス間の値の保持を環境変数ではできないためです。 * if (args[0].ToUpper() == "SW") * { * if (args[1].ToUpper() == "START") * { * Environment.SetEnvironmentVariable("SW", DateTime.Now.ToString(), EnvironmentVariableTarget.User); * return 0; * } * else if (args[1].ToUpper() == "STOP") * { * string v = Environment.GetEnvironmentVariable("SW", EnvironmentVariableTarget.User); * Console.Out.WriteLine(v); * return 0; * } * * } */ if (args[0].ToUpper() == "BEEP") { BeepCommand beep = new BeepCommand(); if (args.Length == 1) { Console.Beep(); } else { beep.Beep(args[1]); } return(0); } if (args[0].ToUpper() == "SET") { string[] kv = args[1].Split(new char[] { '=' }); Type con = typeof(Console); PropertyInfo propertyInfo = con.GetProperty(kv[0]); if (propertyInfo == null) { Console.Out.WriteLine("指定されたキー情報は存在しません。Key=" + kv[0]); return(1); } Debug.WriteLine(propertyInfo.Name); object o = null; if (propertyInfo.PropertyType.FullName == "System.Int32") { o = Convert.ToInt32(kv[1]); } else if (propertyInfo.PropertyType.FullName == "System.Boolean") { o = Convert.ToBoolean(kv[1]); } else if (propertyInfo.PropertyType.FullName == "System.ConsoleColor") { ConsoleColor color = ConsoleColor.Red; color = (ConsoleColor)Enum.Parse(color.GetType(), kv[1]); o = color; } else if (propertyInfo.PropertyType.FullName == "System.Text.Encoding") { Encoding encoding = null; try { int codePage; if (int.TryParse(kv[1], out codePage) == true) { encoding = Encoding.GetEncoding(codePage); } else { encoding = Encoding.GetEncoding(kv[1]); } } catch (Exception ex) { throw new SystemException("指定されているコードページが不正です。コードページ=" + kv[1], ex); } o = encoding; //Console.OutputEncoding = System.Text.Encoding.UTF8; //Console.OutputEncoding = System.Text.Encoding.Unicode; //Console.InputEncoding = System.Text.Encoding.UTF8; //return 0; } else if (propertyInfo.PropertyType.FullName == "System.String") { o = Convert.ToString(kv[1]); } else { //erorr o = kv[1]; } // propertyInfo.SetValue(null, o, null); //con.InvokeMember(kv[0], BindingFlags.SetField, null, null, new object[]{kv[1]}); return(0); } Console.WriteLine("パラメータが間違っています。マニュアルを確認してください。"); return(1); }