Example #1
0
 /// <summary>
 /// 消息输出到文本框
 /// </summary>
 /// <param name="msg"></param>
 void Output(string msg)
 {
     OutputField.Dispatcher.Invoke(new sysAct(() =>
     {
         OutputField.AppendText("\n" + msg);
         OutputField.ScrollToEnd();
     }));
 }
Example #2
0
        void ConcatToBody(string code)
        {
            OutputField f = GetOutputField("Body");

            if (f.Code.Length != 0)
            {
                f.Code.Append(" + ");
            }
            f.Code.Append(code);
        }
Example #3
0
        OutputField GetOutputField(string name)
        {
            OutputField ret;

            if (!outputFields.TryGetValue(name, out ret))
            {
                outputFields[name] = ret = new OutputField();
            }
            return(ret);
        }
Example #4
0
        void MakeSureThereIsTimeField()
        {
            if (outputFields.ContainsKey("Time"))
            {
                return;
            }
            OutputField f = new OutputField();

            f.Code.Append("DateTime.Now");
            outputFields["Time"] = f;
        }
Example #5
0
 private void Append(string message)
 {
     OutputField.Dispatcher.Invoke(new del(() =>
     {
         OutputField.AppendText(message + "\n");
         if (!IsActive)
         {
             sp.Play();
         }
     }));
 }
Example #6
0
        private async void Submit(object sender, EventArgs e)
        {
            var otp      = OtpInput.Text;
            var clientId = ClientIdInput.Text;
            var apiKey   = ApiKeyInput.Text;
            var sync     = SyncInput.Text;
            var nonce    = NonceInput.Text;

            OutputField.Clear();

            var client = new YubicoClient(clientId);

            if (!string.IsNullOrEmpty(apiKey))
            {
                client.SetApiKey(apiKey);
            }
            if (!string.IsNullOrEmpty(sync))
            {
                client.SetSync(sync);
            }
            if (!string.IsNullOrEmpty(nonce))
            {
                client.SetNonce(nonce);
            }
            try
            {
                var sw       = Stopwatch.StartNew();
                var response = await client.VerifyAsync(otp);

                sw.Stop();
                if (response != null)
                {
                    OutputField.AppendText(string.Format("response in: {0}{1}", sw.ElapsedMilliseconds, Environment.NewLine));
                    OutputField.AppendText(string.Format("Status: {0}{1}", response.Status, Environment.NewLine));
                    OutputField.AppendText(string.Format("Public ID: {0}{1}", response.PublicId, Environment.NewLine));
                    OutputField.AppendText(string.Format("Use/Session Counter: {0} {1}{2}", response.UseCounter, response.SessionCounter, Environment.NewLine));
                    OutputField.AppendText(string.Format("Url: {0}", response.Url));
                }
                else
                {
                    OutputField.Text = "Null result returned, error in call";
                }
            }
            catch (YubicoValidationFailure yvf)
            {
                OutputField.Text = string.Format("Failure in validation: {0}{1}", yvf.Message, Environment.NewLine);
            }
        }
Example #7
0
        private void StartIterations()
        {
            LiveCellsOfField countLiveCells = new LiveCellsOfField();

            for (int j = 0; !(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape); j++)
            {
                if (mut.WaitOne(1000))
                {
                    if (StopAllGamesOutput == false)
                    {
                        IterationNumber++;
                        int idThread = Thread.CurrentThread.ManagedThreadId;
                        currentGames.LifeCellsNumber = 0;
                        Thread.Sleep(1000);
                        //Console.Clear();
                        Console.SetCursorPosition(0, 0);    //new way, more clear
                        Console.WriteLine("Iteration {0}", IterationNumber);

                        for (int i = 0; i < currentGames.GameCount; i++)
                        {
                            if (mut.WaitOne() && idThread == Thread.CurrentThread.ManagedThreadId)
                            {
                                OutputField.ShowField(currentGames.AllCurrentGames[i], currentField.FieldSize);
                                currentGames.LifeCellsNumber += countLiveCells.CountLiveCells(currentGames.AllCurrentGames[i], currentField.FieldSize);
                                Console.WriteLine("Live cells count: {0}", countLiveCells.CountLiveCells(currentGames.AllCurrentGames[i], currentField.FieldSize));
                                currentGames.AllCurrentGames[i] = FieldNextGeneration.NextIterationOfLife(currentGames.AllCurrentGames[i], currentField.FieldSize);
                            }
                        }
                        Console.WriteLine("\nTotal life cell count {0}", currentGames.LifeCellsNumber);
                        Console.WriteLine("Total games count {0}", currentGames.GameCount);
                    }
                    else
                    {
                        SavedGame gameToSave = new SavedGame();
                        gameToSave.gameUniverse = currentGames.AllCurrentGames;
                        gameToSave.Iteration    = IterationNumber;
                        gameToSave.GameCount    = currentGames.GameCount;
                        gameToSave.FieldSize    = currentField.FieldSize;
                        SaveRestoreGame.SaveDataToFile(gameToSave);
                        Console.WriteLine("Pause. Press c to continue");
                        Environment.Exit(0);
                    }
                    mut.ReleaseMutex();
                }
            }
        }
 private void ClearBtn_Click(object sender, EventArgs e)
 {
     OutputField.Clear();
 }
Example #9
0
        void HandleSpecifier(PatternToken t)
        {
            string captureName;
            string re;
            string outputFieldName     = null;
            string outputFieldCode     = null;
            string outputFieldCodeType = null;

            switch (t.Value)
            {
            case "a":
            case "appdomain":
                captureName = "AppDomain";
                re          = @".*";
                break;

            case "c":
            case "logger":
                captureName = "Logger";
                re          = @"[\w\.]+";
                break;

            case "aspnet-cache":
            case "aspnet-context":
            case "aspnet-request":
            case "aspnet-session":
                var m = Regex.Match(t.Value, @"(\w+)-(\w+)");
                captureName =
                    CapitalizeFirstLetter(m.Groups[1].Value) +
                    CapitalizeFirstLetter(m.Groups[2].Value) +
                    CapitalizeFirstLetter(t.Argument);
                re = @".*";
                break;

            case "C":
            case "class":
            case "type":
                captureName = "Class";
                re          = @".*";                // * because caller location might not be accessible
                break;

            case "d":
            case "date":
            case "utcdate":
                captureName = "Time";
                string fmt;
                switch (t.Argument)
                {
                case "ABSOLUTE":
                    fmt = "HH:mm:ss,fff";
                    break;

                case "DATE":
                    fmt = "dd MMM yyyy HH:mm:ss,fff";
                    break;

                case "ISO8601":
                case "":
                    fmt = "yyyy-MM-dd HH:mm:ss,fff";
                    break;

                default:
                    fmt = t.Argument;
                    break;
                }
                re = GetDateRe(fmt);
                outputFieldName = "Time";
                outputFieldCode = string.Format("TO_DATETIME(Time, {0})", GetCSharpStringLiteral(fmt));
                break;

            case "newline":
            case "n":
                captureName = "NL";
                re          = @"\n|\r\n";
                break;

            case "exception":
                captureName = "Exception";
                re          = @".*";
                inHeader    = false;
                break;

            case "file":
            case "F":
                captureName = "File";
                // insert " with Format() because otherwise I would have to remove @ and escape the re heavily
                re = string.Format(@"[^\*\?\{0}\<\>\|]*", '"');                         // [...]* because caller location might not be accessible
                break;

            case "identity":
            case "u":
                captureName = "Identity";
                re          = @"[\w\\\.]*";
                break;

            case "location":
            case "l":
                captureName = "Location";
                re          = @".*";                // * because caller location might not be accessible
                break;

            case "line":
            case "L":
                captureName = "Line";
                re          = @"\d*";                // * because caller location might not be accessible
                break;

            case "p":
            case "level":
                captureName         = "Level";
                re                  = @"DEBUG|INFO|WARN|ERROR|FATAL";
                outputFieldName     = "Severity";
                outputFieldCode     = @"
switch (Level)
{
case ""WARN"":
	return Severity.Warning;
case ""ERROR"":
case ""FATAL"":
	return Severity.Error;
default:
	return Severity.Info;
}";
                outputFieldCodeType = "function";
                break;

            case "message":
            case "m":
                captureName = "Message";
                inHeader    = false;
                re          = ".*";
                break;

            case "method":
            case "M":
                captureName = "Method";
                re          = ".*";
                break;

            case "mdc":
            case "property":
            case "P":
            case "X":
            case "properties":
                captureName = "Prop";
                re          = ".*";
                break;

            case "r":
            case "timestamp":
                captureName = "Timestamp";
                re          = @"\d+";
                break;

            case "thread":
            case "t":
                captureName     = "Thread";
                re              = ".+";
                outputFieldName = "Thread";
                outputFieldCode = "Thread";
                break;

            case "username":
            case "w":
                captureName = "User";
                re          = @"[\w\\\.]+";
                break;

            case "x":
            case "ndc":
                captureName = "NDC";
                re          = @".+";
                break;

            case "stacktrace":
            case "stacktracedetail":
                captureName = "Stacktrace";
                re          = @".+";
                break;

            default:
                return;
            }

            captureName = RegisterCaptureName(captureName);

            StringBuilder reToAppend = inHeader ? headerRe : bodyRe;

            string paddingString = null;

            if (t.Padding != 0)
            {
                paddingString = string.Format(@"\ {{0,{0}}}", t.Padding);
            }

            if (paddingString != null && !t.RightPaddingFlag)
            {
                reToAppend.Append(paddingString);
            }

            reToAppend.AppendFormat("(?<{0}>{1})", captureName, re);

            if (paddingString != null && t.RightPaddingFlag)
            {
                reToAppend.Append(paddingString);
            }

            reToAppend.AppendFormat(" # field '{0}'{1}", t.Value, Environment.NewLine);

            if (outputFieldName != null)
            {
                OutputField f = GetOutputField(outputFieldName);

                // First, check if the code is empty yet.
                // The code may have already been initialized. That may happen if
                // there are several specifiers with the same name and that produce
                // an output field. We want to take in use only the first such specifier.
                if (f.Code.Length == 0)
                {
                    f.Code.Append(outputFieldCode);
                    f.CodeType = outputFieldCodeType;

                    // Time field souldn't go to the body because
                    // it can be displayed later in the log view (Show Time... in content menu)
                    if (outputFieldName == "Time")
                    {
                        return;
                    }
                }
            }
            if (captureName == "Message")
            {
                ConcatToBody(captureName);
            }
        }
Example #10
0
 private void OutputField_TextChanged(object sender, TextChangedEventArgs e)
 {
     OutputField.ScrollToEnd();
 }