Exemplo n.º 1
0
        public static async void Changed(object sender, RecordChangedEventArgs <ModelProcessedHistory> e)
        {
            var changedEntity = e.Entity;

            Console.WriteLine("DML operation: " + e.ChangeType);
            Console.WriteLine("Item ID: " + changedEntity.HistoryID);
            Console.WriteLine("ModelElementID: " + changedEntity.ModelElementID);
            Console.WriteLine("ModelJobID: " + changedEntity.ModelJobID);
            Console.WriteLine("OrderID: " + changedEntity.OrderID);
            //RecordHandler.RetransmitFailedLocalAsync(); // Debug only, delete it from here when done
            if (e.ChangeType == TableDependency.Enums.ChangeType.Insert)
            {
                //DML operation of type insert, try push this entry to logging server
                try {
                    bool transmitStatus = await RecordHandler.TransmitAsync(e);

                    if (transmitStatus)
                    {
                        Console.WriteLine($"Record ID:  {changedEntity.HistoryID} successfully transmitted");
                    }
                    else
                    {
                        // This section executed if either the transmission failed and record was logged to file OR!
                        // The UnitsCounted field was had a value Zero causing a reconcillitation action to be performed
                        Console.WriteLine($"FAILED: Record {changedEntity.HistoryID} transmition failed! Deffered processing");
                    }
                }
                catch (HttpRequestException ex)
                {
                    Console.WriteLine("A HTTP connection error was encountered, could be because of Web Server being down/unreachable");
                    Console.WriteLine($"FAILED: Record {changedEntity.HistoryID} transmition failed! It has been logged to file system for later transmittion");

                    await RecordHandler.RetransmitFailedDBAsync(); // This statement is only for debug must be DELETED when done debugging!

                    dynamic record = JSONConverter.EntityToJObject(e);

                    // If record is null then return, don't continue processing
                    if (record == null)
                    {
                        return;
                    }



                    // Log current record to File system, it was never trasmitted in the first place due to connection issues
                    RecordHandler.LogFailed(record.ToString());
                }
            }
        }
Exemplo n.º 2
0
        public static async Task <bool> TransmitAsync(RecordChangedEventArgs <ModelProcessedHistory> e)
        {
            // return true on successful transmission of a record, false otherwise

            var changedEntity = e.Entity;

            dynamic record = JSONConverter.EntityToJObject(e);

            // If record is null then return, don't continue processing
            if (record == null)
            {
                return(false);
            }

            // Here, check the record to ensure teeth isn't zero by mistake

            bool transmitStatus = await TransmitJSONRecordAsync(record.ToString());


            return(transmitStatus);
        }