Example #1
0
        private async Task RunAsync(CancellationToken cancellationToken)
        {
            // TODO: Replace the following with your own logic.
            while (!cancellationToken.IsCancellationRequested)
            {
                Trace.WriteLine("----------------------------------------------");
                if (id == "0")
                {
                    string msg = queueHelper.GetFromQueue();

                    if (msg != null)
                    {
                        try
                        {
                            string[] parts = msg.Split('_');
                            Proizvod a     = tableHelper.GetOneProizvod(parts[0]);
                            if (a.Kolicina >= int.Parse(parts[1]))
                            {
                                Trace.WriteLine($"OK\n{a.Naziv}\n{a.Kolicina}\n{parts[1]}");
                                a.Kolicina -= int.Parse(parts[1]);
                                tableHelper.AddOrReplaceProizvod(a);
                                proxy.Notify(msg + "_OK");
                                Trace.WriteLine($"OK\n{a.Naziv}\n{a.Kolicina}\n{parts[1]}");
                            }
                            else
                            {
                                proxy.Notify(msg + "_NOTOK");
                                Trace.WriteLine("Nema dovoljno proizvoda.");
                            }
                        }
                        catch
                        {
                            proxy.Notify(msg + "_NOTOK");
                            Trace.WriteLine($"NOT OK");
                        }
                    }
                    else
                    {
                        Trace.WriteLine("Nema poruke");
                    }
                }
                Trace.TraceInformation("Working");
                Trace.WriteLine("----------------------------------------------");
                await Task.Delay(3000);
            }
        }