示例#1
0
        public override void Execute(Core.Var.VariableTable table)
        {
            base.Execute(table);
            Next = LinkedBlocks[0];

            Printed?.Invoke(_control.GetValue(table));
        }
示例#2
0
        public void PrintElementWithWriter()
        {
            var builder      = new StreamBuilder();
            var stringWriter = new StringWriter();

            builder.Stream <string, string>("topic")
            .Print(Printed <string, string> .ToWriter(stringWriter).WithLabel("string"));
            // DEFAULT FORMAT => [label]: key value";

            var config = new StreamConfig <StringSerDes, StringSerDes>();

            config.ApplicationId = "test-print";

            Topology t = builder.Build();

            using (var driver = new TopologyTestDriver(t, config))
            {
                var inputTopic = driver.CreateInputTopic <string, string>("topic");
                var expected   = new StringBuilder();
                for (int i = 0; i < 5; i++)
                {
                    string key   = i.ToString();
                    string value = $"V{i}";
                    inputTopic.PipeInput(key, value);
                    expected.AppendLine($"[string]: {key} {value}");
                }

                Assert.AreEqual(expected.ToString(), stringWriter.ToString());
            }
        }
        public void Print(Printed <K, V> printed)
        {
            var name = new Named(printed.Name).OrElseGenerateWithPrefix(this.builder, PRINTING_NAME);
            ProcessorParameters <K, V> processorParameters = new ProcessorParameters <K, V>(printed.Build(this.nameNode), name);
            ProcessorGraphNode <K, V>  printNode           = new ProcessorGraphNode <K, V>(name, processorParameters);

            builder.AddGraphNode(node, printNode);
        }
示例#4
0
        static async Task Main(string[] args)
        {
            CancellationTokenSource source = new CancellationTokenSource();

            var config = new StreamConfig();

            config.ApplicationId    = "test-app";
            config.BootstrapServers = "localhost:9092";
            // NEED FOR SchemaAvroSerDes
            config.SchemaRegistryUrl   = "http://localhost:8081";
            config.AutoRegisterSchemas = true;

            StreamBuilder builder = new StreamBuilder();

            var table = builder.Table("product",
                                      new Int32SerDes(),
                                      new SchemaAvroSerDes <Product>(),
                                      InMemory <int, Product> .As("product-store"));

            var orders = builder.Stream <int, Order, Int32SerDes, SchemaAvroSerDes <Order> >("orders");

            orders.Join(table, (order, product) => new OrderProduct
            {
                order_id      = order.order_id,
                price         = order.price,
                product_id    = product.product_id,
                product_name  = product.name,
                product_price = product.price
            })
            .To <Int32SerDes, SchemaAvroSerDes <OrderProduct> >("orders-output");

            orders
            .GroupByKey()
            .Aggregate <OrderAgg, SchemaAvroSerDes <OrderAgg> >(
                () => new OrderAgg(),
                (key, order, agg) =>
            {
                agg.order_id    = order.order_id;
                agg.price       = order.price;
                agg.product_id  = order.product_id;
                agg.totalPrice += order.price;
                return(agg);
            })
            .ToStream()
            .Print(Printed <int, OrderAgg> .ToOut());

            Topology t = builder.Build();

            KafkaStream stream = new KafkaStream(t, config);

            Console.CancelKeyPress += (o, e) =>
            {
                stream.Dispose();
            };

            await stream.StartAsync();
        }
示例#5
0
 private void 실행RToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         Board.Run();
     }
     catch (ArgumentNullException ex)
     {
         Printed?.Invoke(ex.Message);
     }
 }
        public void Print(Printed <K, V> printed)
        {
            if (printed == null)
            {
                throw new ArgumentNullException("Print() doesn't allow null printed instance");
            }

            var name = new Named(printed.Name).OrElseGenerateWithPrefix(this.builder, PRINTING_NAME);
            ProcessorParameters <K, V> processorParameters = new ProcessorParameters <K, V>(printed.Build(this.nameNode), name);
            ProcessorGraphNode <K, V>  printNode           = new ProcessorGraphNode <K, V>(name, processorParameters);

            builder.AddGraphNode(node, printNode);
        }
        /// <summary>
        /// Print To.
        /// </summary>
        public void PrintTo()
        {
            int errCnt   = 0;
            int fromPage = -1;
            int toPage   = -1;

            System.Windows.Controls.PrintDialog pd = new System.Windows.Controls.PrintDialog();
            pd.UserPageRangeEnabled = true;
            if (true == pd.ShowDialog())
            {
                if (null != pd.PrintQueue)
                {
                    _printerName = pd.PrintQueue.FullName;
                    short noOfCopies = (!pd.PrintTicket.CopyCount.HasValue) ?
                                       (short)1 : Convert.ToInt16(pd.PrintTicket.CopyCount.Value);

                    System.Windows.Controls.PageRangeSelection sel = pd.PageRangeSelection;
                    if (sel == PageRangeSelection.UserPages)
                    {
                        // User page.
                        if (null != pd.PageRange)
                        {
                            fromPage = pd.PageRange.PageFrom;
                            toPage   = pd.PageRange.PageTo;
                        }
                    }

                    // Print but not raise event.
                    if (!this.Print(fromPage, toPage, noOfCopies, false))
                    {
                        ++errCnt;
                    }
                }
            }
            pd = null;

            // Raise event.
            if (errCnt <= 0)
            {
                if (null != Printed)
                {
                    Printed.Call(this, EventArgs.Empty);
                }
            }
            else
            {
                MessageBox.Show("Print failed.", "CKD Robbing Program");
            }
        }
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            var config = new StreamConfig <StringSerDes, StringSerDes>();

            config.ApplicationId    = "test-app";
            config.BootstrapServers = "localhost:9092";

            StreamBuilder             builder = new StreamBuilder();
            IKStream <string, string> kStream = builder.Stream <string, string>("test-topic");

            kStream.Print(Printed <string, string> .ToOut());

            Topology    t      = builder.Build();
            KafkaStream stream = new KafkaStream(t, config);

            Console.CancelKeyPress += (o, e) => stream.Dispose();

            await stream.StartAsync();
        }
示例#9
0
        public void AddBlock(Block block)
        {
            block.Parent = this.Board;

            _blocks.Add(block);

            block.OuterControl                 = new BlockControl(block);
            block.OuterControl.Location        = block.Location;
            block.OuterControl.TriedToLinkIn  += Bc_TriedToLinkIn;
            block.OuterControl.TriedToLinkOut += Bc_TriedToLinkOut;
            block.LocationChanged             += (a, b) => block.OuterControl.Location = block.Location;
            block.OuterControl.NeedInvalidate += () => Invalidate();

            if (block is PrintBlock)
            {
                ((PrintBlock)block).Printed += (s) => Printed?.Invoke(s);
            }
            this.Controls.Add(block.OuterControl);
        }
示例#10
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            var config = new StreamConfig <StringSerDes, StringSerDes>();

            config.ApplicationId    = "test-app";
            config.BootstrapServers = "localhost:9092";
            config.AutoOffsetReset  = Confluent.Kafka.AutoOffsetReset.Earliest;
            config.StateDir         = Path.Combine(".", Guid.NewGuid().ToString());

            StreamBuilder builder = new StreamBuilder();

            builder
            .Table("table", RocksDb <string, string> .As("table-store").WithLoggingEnabled())
            .ToStream()
            .Print(Printed <string, string> .ToOut());

            Topology t = builder.Build();

            KafkaStream stream = new KafkaStream(t, config);
            await stream.StartAsync(stoppingToken);
        }
示例#11
0
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            var config = new StreamConfig <StringSerDes, StringSerDes>();

            config.ApplicationId    = "test-app";
            config.BootstrapServers = "localhost:9093";


            StreamBuilder builder = new StreamBuilder();

            builder.Stream <string, string>("evenements")
            .GroupByKey()
            .WindowedBy(TumblingWindowOptions.Of(TimeSpan.FromMinutes(1)))
            .Aggregate(() => "", (k, v, va) => va += v)
            .ToStream()
            .Print(Printed <Windowed <String>, String> .ToOut());

            Topology    t      = builder.Build();
            KafkaStream stream = new KafkaStream(t, config);

            Console.CancelKeyPress += (o, e) => stream.Dispose();

            await stream.StartAsync();
        }
        /// <summary>
        /// Print.
        /// </summary>
        /// <param name="fromPage">-1 for print all</param>
        /// <param name="toPage">-1 for print all</param>
        /// <param name="noOfCopies">The Number of Copies.</param>
        /// <param name="raiseEvent">True for raise event after print finished.</param>
        /// <returns>Returns true if success.</returns>
        public bool Print(int fromPage     = -1, int toPage     = -1,
                          short noOfCopies = 1, bool raiseEvent = true)
        {
            RdlcPrintResult result = rptViewer.PrintTo(
                _printerName, fromPage, toPage, noOfCopies);

            if (result.Success)
            {
                // Raise event.
                if (raiseEvent && null != Printed)
                {
                    Printed.Call(this, EventArgs.Empty);
                }
            }
            else
            {
                if (raiseEvent)
                {
                    MessageBox.Show(result.Message, "CKD Robbing Program");
                }
            }

            return(result.Success);
        }
示例#13
0
 public override void Print(string val)
 {
     Printed.Add(val);
 }
示例#14
0
        private async void UpdateJob()
        {
            if (_isBusy)
            {
                OnLog("上次请求还未处理");
                return;
            }

            _isBusy = true;

            try
            {
                var status = await X30Client.GetClearSendStatusAsync();

                if (status == ClearSendStatus.Ready)
                {
                    if (IsComplete)
                    {
                        _timer.Stop();
                        await X30Client.StateChangeAsync(StateChangeStatus.Ready);

                        PrintCompleted?.Invoke(this, EventArgs.Empty);
                    }
                    else
                    {
                        CurrentBatchItem.Status = BatchStatus.Printed;
                        AppContext.Instance.DB.Update(CurrentBatchItem);

                        if (IsFatalError)
                        {
                            _timer.Stop();
                            FatalError?.Invoke(this, EventArgs.Empty);
                            await X30Client.StateChangeAsync(StateChangeStatus.Ready);

                            return;
                        }
                        var jobUpdateCommand = new JobCommand();
                        var bi = _batchsToPrint[_batchIndex + 1];

                        PopulateJobCommandFields(jobUpdateCommand, bi.QRCodeContent);

                        await X30Client.UpdateJob(jobUpdateCommand);

                        _currentClearStatus = ClearSendStatus.NotReady;
                        _batchIndex++;
                        bi.Status = BatchStatus.CodeSent;
                        AppContext.Instance.DB.Update(bi);
                        var message = $"{bi.SerinalNo} - {bi.QRCodeContent} 已赋码";
                        OnLog(message);
                        Printed?.Invoke(this, EventArgs.Empty);
                    }
                }
                else
                {
                    CurrentBatchItem.Status = BatchStatus.Printing;
                }
            }
            catch (Exception e)
            {
                var message = $"错误--{e.Message}";
                OnLog(message);
            }

            _isBusy = false;
        }
示例#15
0
        public async Task process(IConfiguration config)
        {
            // creando AvroSchemas from clases
            AvroSerializerSettings settings = new AvroSerializerSettings();

            settings.Resolver = new AvroPublicMemberContractResolver();
            var endpontSchema = AvroSerializer.Create <Endpoint> (settings).WriterSchema.ToString();

            var messageDSchema = AvroSerializer.Create <MessageDestination> (settings).WriterSchema.ToString();

            Console.WriteLine("Endpoint Schema: " + endpontSchema);
            Console.WriteLine("Message Destination Schema: " + messageDSchema);

            Console.WriteLine("RouterProcess");
            var sConfig = new StreamConfig <StringSerDes, StringSerDes> ();

            sConfig.ApplicationId       = config["SPRING_CLOUD_APPLICATION_GROUP"];
            sConfig.BootstrapServers    = config["SPRING_CLOUD_STREAM_KAFKA_BINDER_BROKERS"];
            sConfig.AutoOffsetReset     = AutoOffsetReset.Earliest;
            sConfig.SchemaRegistryUrl   = config["SchemaRegistryUrl"];
            sConfig.AutoRegisterSchemas = true;
            sConfig.NumStreamThreads    = 1;
            sConfig.Acks = Acks.All;
            //sConfig.Debug = "consumer,cgrp,topic,fetch";
            sConfig.AddConsumerConfig("allow.auto.create.topics", "true");
            sConfig.MaxTaskIdleMs         = 50;
            sConfig.InnerExceptionHandler = (e) => ExceptionHandlerResponse.CONTINUE;

            var      timeout = TimeSpan.FromSeconds(10);
            DateTime dt      = DateTime.Now;

            MessageDestination op = new MessageDestination();

            var           serializer = new SchemaAvroSerDes <OrderProduct>();
            StreamBuilder builder    = new StreamBuilder();

            var table = builder.Table(config["endpoints"],
                                      new Int32SerDes(),
                                      new SchemaAvroSerDes <Endpoint> (),
                                      InMemory <int, Endpoint> .As(config["endpoints-table"]));

            builder.Stream <int, OrderProduct, Int32SerDes, SchemaAvroSerDes <OrderProduct> >(config["spring.cloud.stream.bindings.input.destination"])
            .Map <int, OrderProduct>((k, v) =>
            {
                return(KeyValuePair.Create(v.product_id, v));
            })
            .Peek((k, v) =>
            {
                Console.WriteLine($"Sending message {k}  to endpoint {v.product_id}");
                //calcular metrica
            })
            .Join(table, (orderProduct, endpoint) => {
                Console.WriteLine("OrderProduct: " + orderProduct?.order_id);
                Console.WriteLine("Endpoint: " + endpoint?.endpoint_id);

                op = new MessageDestination {
                    messageId = orderProduct.order_id,
                    endpoint  = endpoint,
                    payload   = orderProduct
                };
                return(op);
            })
            .Peek((k, v) =>
            {
                Console.WriteLine($"Sending message {k}  to endpoint {v.endpoint.endpoint_url}");
                // crear metricas
                if (_messageCounterList != null)
                {
                    var counterMessage = Metrics
                                         .CreateCounter($"router_{v.endpoint.endpoint_id}_processed_total", $"Number of messages sent to {v.endpoint.endpoint_url}");

                    counterMessage.Inc();

                    _messageCounterList.Add(counterMessage);
                }
            })
            .Print(Printed <int, MessageDestination> .ToOut());

            Topology t = builder.Build();

            Console.WriteLine(t.Describe());

            KafkaStream stream = new KafkaStream(t, sConfig);

            bool isRunningState = false;

            stream.StateChanged += (old, @new) => {
                if (@new.Equals(KafkaStream.State.RUNNING))
                {
                    isRunningState = true;
                }
            };

            await stream.StartAsync();

            while (!isRunningState)
            {
                Thread.Sleep(250);
                if (DateTime.Now > dt + timeout)
                {
                    break;
                }
            }

            if (isRunningState)
            {
                Console.WriteLine("Stream running state is " + isRunningState.ToString());
            }
        }
示例#16
0
 /// <summary>
 /// Printing the item
 /// </summary>
 private void Print()
 {
     Printed?.Invoke(this);
 }
示例#17
0
 public string Value()
 {
     return(string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8}", Region, Site, Building, Floor, Room, Code, GLN, Date.ToString(), Printed.ToString()));
 }
 protected virtual void OnPrinted(string arg)
 {
     Printed?.Invoke(arg);
 }