private void Dispatch(IEnumerable <Message> posts) { foreach (var message in posts) { s_logger.LogInformation("Decoupled invocation of message: Topic:{Topic} Id:{Id}", message.Header.Topic, message.Id.ToString()); var producer = ProducerRegistry.LookupByOrDefault(message.Header.Topic); if (producer is IAmAMessageProducerSync producerSync) { if (producer is ISupportPublishConfirmation) { //mark dispatch handled by a callback - set in constructor Retry(() => { producerSync.Send(message); }); } else { var sent = Retry(() => { producerSync.Send(message); }); if (sent) { Retry(() => OutBox.MarkDispatched(message.Id, DateTime.UtcNow)); } } } else { throw new InvalidOperationException("No sync message producer defined."); } } }
private async Task BackgroundDispatchUsingSync(int amountToClear, int minimumAge) { if (await _backgroundClearSemaphoreToken.WaitAsync(TimeSpan.Zero)) { await _clearSemaphoreToken.WaitAsync(CancellationToken.None); try { var messages = OutBox.OutstandingMessages(minimumAge, amountToClear); s_logger.LogInformation("Found {NumberOfMessages} to clear out of amount {AmountToClear}", messages.Count(), amountToClear); Dispatch(messages); s_logger.LogInformation("Messages have been cleared"); } catch (Exception e) { s_logger.LogError(e, "Error while dispatching from outbox"); } finally { _clearSemaphoreToken.Release(); _backgroundClearSemaphoreToken.Release(); } CheckOutstandingMessages(); } else { s_logger.LogInformation("Skipping dispatch of messages as another thread is running"); } }
internal void ClearOutbox(params Guid[] posts) { if (!HasOutbox()) { throw new InvalidOperationException("No outbox defined."); } // Only allow a single Clear to happen at a time _clearSemaphoreToken.Wait(); try { foreach (var messageId in posts) { var message = OutBox.Get(messageId); if (message == null || message.Header.MessageType == MessageType.MT_NONE) { throw new NullReferenceException($"Message with Id {messageId} not found in the Outbox"); } Dispatch(new[] { message }); } } finally { _clearSemaphoreToken.Release(); } CheckOutstandingMessages(); }
private void InBox_KeyPress(object sender, KeyPressEventArgs e) { //数値およびバックスぺースのみを受け入れる if ((e.KeyChar < '0' || e.KeyChar > '9') && (e.KeyChar != '\b')) { if (e.KeyChar != '-' && InBox.TextLength == 0) { e.Handled = true; } } if ((e.KeyChar == (char)Keys.Enter) && InBox.Text != "" && InBox.Text != "-") { Console.WriteLine(InBox.Text); OutBox.AppendText(InBox.Text + "\r\n"); Kotaeawase(); InBox.Text = ""; if (mondaiCnt < mondaiMax) { Mondaisakusei(); } else { Seiseki(); } } }
private void Seiseki() { InBox.Enabled = false; mondaiLbl2.Text = "";//問題の表示をクリア OutBox.AppendText("正解数は" + seikaiCnt + "です。"); PercentageOfCorrectAnswers = seikaiCnt / mondaiMax * 100; OutBox.AppendText("正答率は" + PercentageOfCorrectAnswers + " % です。"); StartButton.Text = "開 始"; }
private void button2_Click(object sender, EventArgs e) { for (int i = 0; i < drawWindowsList.Count; i++) { drawWindowsList[i].Close(); } drawWindowsList.Clear(); OutBox.Clear(); }
}//Kotaeawase // 成績処理 private void Seiseki() { mondaiCnt++; // Timer1_Tick を終了するためのプラス1 InBox.Enabled = false; // InBox を無効に MondaiLbl.Text = ""; // 問題の表示のクリア OutBox.AppendText("正解数は " + seikaiCnt + " です"); // 正解率の表示 ansRate = 1.0 * seikaiCnt / mondaiMax * 100; // C#の場合、整数同士ではなく実数同士の割り算であることを示すために、1.0 を最初にかける必要がある。 OutBoxCorrectAnsRate.Text = ansRate + " %"; }//Seiseki
internal void AddToOutbox <T>(T request, Message message, IAmABoxTransactionConnectionProvider overridingTransactionConnectionProvider = null) where T : class, IRequest { CheckOutboxOutstandingLimit(); var written = Retry(() => { OutBox.Add(message, OutboxTimeout, overridingTransactionConnectionProvider); }); if (!written) { throw new ChannelFailureException($"Could not write request {request.Id} to the outbox"); } }
private void Kotaeawase() { if (noC == Int64.Parse(InBox.Text)) { OutBox.AppendText("○ "); seikaiCnt++; } else { OutBox.AppendText("× "); } OutBox.AppendText(mondaiLbl2.Text + InBox.Text + "\r\n"); }
private void CauchyButton_Click(object sender, EventArgs e) { leftBorder = Convert.ToDouble(LeftBorderBox.Text); rightBorder = Convert.ToDouble(RightBorderBox.Text); double[] x = new Double[2]; x.SetValue(Convert.ToDouble(x0Box.Text), 0); x.SetValue(Convert.ToDouble(x1Box.Text), 1); double eps = Convert.ToDouble(EpsilonBox.Text); double h = Convert.ToDouble(StepBox.Text); OutBox.Clear(); OutBox.AppendText(Grad(x, eps, h)); }
}//InBox_KeyPress // 答え合わせ private void Kotaeawase() { // Inr64.parse() = ()内の取得した値を数値型に変換する if (sumAB == Int64.Parse(InBox.Text)) { OutBox.AppendText("〇 "); // ここで \r\n を入力しないのがポイント seikaiCnt++; // 正解数を+1 } else { // ここで \r\n を入力しないのがポイント OutBox.AppendText("× "); } // 問題 + 入力 + 改行 OutBox.AppendText(MondaiLbl.Text + InBox.Text + "\r\n"); }//Kotaeawase
internal bool ConfigurePublisherCallbackMaybe(IAmAMessageProducer producer) { if (producer is ISupportPublishConfirmation producerSync) { producerSync.OnMessagePublished += delegate(bool success, Guid id) { if (success) { s_logger.LogInformation("Sent message: Id:{Id}", id.ToString()); if (OutBox != null) { Retry(() => OutBox.MarkDispatched(id, DateTime.UtcNow)); } } }; return(true); } return(false); }
public TestingWindow(bool terminateOnExit) { CheckForIllegalCrossThreadCalls = false; Application.EnableVisualStyles(); var resources = new System.ComponentModel.ComponentResourceManager(typeof(TestingWindow)); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); Size = new Size(900, 500); BackColor = Color.Black; Text = nameof(TestingWindow); OutB = new OutBox(this); if (terminateOnExit) { FormClosed += (s, e) => Environment.Exit(2); } }
private void OutstandingMessagesCheck() { if (Monitor.TryEnter(_checkOutStandingMessagesObject)) { s_logger.LogDebug("Begin count of outstanding messages"); try { if (OutBox != null) { _outStandingCount = OutBox .OutstandingMessages(ProducerRegistry.GetDefaultProducer() .MaxOutStandingCheckIntervalMilliSeconds) .Count(); return; } // else if(AsyncOutbox != null) // { // //TODO: There is no async version of this call at present; the thread here means that won't hurt if implemented // _outStandingCount = AsyncOutbox // .OutstandingMessages(ProducerRegistry.GetDefaultProducer().MaxOutStandingCheckIntervalMilliSeconds) // .Count(); // return; // } _outStandingCount = 0; } catch (Exception ex) { //if we can't talk to the outbox, we would swallow the exception on this thread //by setting the _outstandingCount to -1, we force an exception s_logger.LogError(ex, "Error getting outstanding message count, reset count"); _outStandingCount = 0; } finally { s_logger.LogDebug("Current outstanding count is {OutStandingCount}", _outStandingCount); Monitor.Exit(_checkOutStandingMessagesObject); } } }
public void Listener() { if (!queueExist) { this.Create(); queueExist = true; } var outB = new OutBox(); var product = new Product(); var rep = new MongoRepository(); { var factory = new ConnectionFactory() { HostName = "localhost" }; using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { var consumer = new EventingBasicConsumer(channel); consumer.Received += (model, ea) => { var body = ea.Body.ToArray(); var message = Encoding.UTF8.GetString(body); //Console.WriteLine(" [x] Received {0}", message); product = JsonConvert.DeserializeObject <Product>(message); rep.Insert(product).Wait(); }; channel.BasicConsume(queue: this.queueName, autoAck: true, consumer: consumer); Console.WriteLine(" Press [enter] to exit."); Console.ReadLine(); } } }
private void StartButton_Click(object sender, EventArgs e) { OutBox.Clear(); List <Attribute> matrixAttr = new List <Attribute>(); int x = 0; int y = 0; double min = 0; double[,] A1; x = int.Parse(Xbox.Text); y = int.Parse(Ybox.Text); A1 = new double[x, y]; for (int i = 0, index = 0; i < x; i++) { for (int j = 0; j < y; j++, index++) { A1[i, j] = parseElement(index); } } for (int i = y - x, count = 0; i < y; count++, i++) { matrixAttr.Add(new Attribute() { value = A1[count, y - 1] }); if (i == y - 1) { matrixAttr[count].name = "P"; } else { matrixAttr[count].name = "x" + i; } } do { min = 0; int colPosition = 0; // Find min element in last line and set colPosition for (int i = 0; i < y; i++) { if (A1[x - 1, i] < 0 && min > A1[x - 1, i]) { min = A1[x - 1, i]; colPosition = i; } } double[] tempArray = new double[x - 1]; // A1[Last col] / A1[colPosition] for (int i = 0; i < tempArray.Length; i++) { tempArray[i] = A1[i, y - 1] / A1[i, colPosition]; } min = tempArray[0]; int rawPosition = 0; // Find min element and set rawPosition for (int i = 0; i < tempArray.Length; i++) { if (min > tempArray[i]) { min = tempArray[i]; rawPosition = i; } } double num = A1[rawPosition, colPosition]; // A1[rawPosition] / A1[rawPosition, colPosition] for (int i = 0; i < y; i++) { A1[rawPosition, i] = A1[rawPosition, i] / num; } // A1[raws] - A1[rawPosition] * A1[colPosition] for (int i = 0; i < x - 1; i++) { if (i != rawPosition) { num = A1[i, colPosition]; for (int j = 0; j < y; j++) { A1[i, j] = A1[i, j] - A1[rawPosition, j] * Math.Abs(num); } } } num = A1[x - 1, colPosition]; // A1[Last raw] + A1[rawPosition] * A1[colPosition] for (int i = 0; i < y; i++) { A1[x - 1, i] = A1[x - 1, i] + A1[rawPosition, i] * Math.Abs(num); } // Change values and rawPosition.name beacause of new basic solution for (int i = 0; i < x; i++) { matrixAttr[i].value = A1[i, y - 1]; if (i == rawPosition) { matrixAttr[i].name = "x" + i; } } // Repeat? min = 0; for (int i = 0; i < y; i++) { if (A1[x - 1, i] < 0 && min > A1[x - 1, i]) { min = A1[x - 1, i]; } } } while (min < 0); // Sort by Name column matrixAttr.Sort((a, b) => { if (a.name != "P" && b.name != "P") { return(a.name.CompareTo(b.name)); } return(0); }); // And print out for (int i = 0; i < x; i++) { OutBox.AppendText(matrixAttr[i].name + " = " + matrixAttr[i].value + "\n"); } }
public async Task Remove(OutBox outbox) { this._repo.OutBox.Remove(outbox); await this._repo.SaveChangesAsync(); }
private void Seiseki() { InBox.Enabled = false; MondaiLbl.Text = ""; OutBox.AppendText("正解数は " + seikaiCnt + " です"); }