Beispiel #1
0
        public async Task CheckForLdbSales(PerformContext hangfireContext)
        {
            IDynamicsClient dynamicsClient = null;

            if (!string.IsNullOrEmpty(Configuration["DYNAMICS_ODATA_URI"]))
            {
                dynamicsClient = DynamicsSetupUtil.SetupDynamics(Configuration);
            }

            if (hangfireContext != null)
            {
                hangfireContext.WriteLine("Starting check for LDB sales");
            }

            byte[] data = TestGetFile(); //ScpGetData(hangfireContext);

            // parse the data.

            List <LdbOrderCsv> rows = GetOrderCsvs(data);

            foreach (var row in rows)
            {
                if (_debugMode && hangfireContext != null)
                {
                    hangfireContext.WriteLine($"Licence {row.Licence} DateStart {row.DateStart} DateEnd {row.DateEnd} OrderTotal {row.OrderAmount}");
                }
                // lookup the licence.
                if (dynamicsClient != null)
                {
                    var licence = dynamicsClient.GetLicenceByNumber(row.Licence.ToString());
                    if (licence != null)
                    {
                        // create a row for the ldb orders.
                        MicrosoftDynamicsCRMadoxioLdborder ldbOrder = new MicrosoftDynamicsCRMadoxioLdborder()
                        {
                            LicenceIdODataBind = dynamicsClient.GetEntityURI("adoxio_licenceses", licence.AdoxioLicencesid),
                            AdoxioMonthstart   = row.DateStart,
                            AdoxioMonthend     = row.DateEnd,
                            AdoxioMonth        = row.DateStart.Month,
                            AdoxioYeartext     = row.DateStart.Year.ToString(),
                            AdoxioTotalsales   = row.OrderAmount
                        };
                        try
                        {
                            dynamicsClient.Ldborders.Create(ldbOrder);
                            if (hangfireContext != null)
                            {
                                hangfireContext.WriteLine($"Added Order data for Licence {row.Licence} DateStart {row.DateStart} DateEnd {row.DateEnd}");
                            }
                        }
                        catch (Exception e)
                        {
                            if (hangfireContext != null)
                            {
                                hangfireContext.WriteLine($"Error adding Order data for Licence {row.Licence} DateStart {row.DateStart} DateEnd {row.DateEnd}");
                            }

                            Log.Error(e,
                                      $"Error adding Order data for Licence {row.Licence} DateStart {row.DateStart} DateEnd {row.DateEnd}");
                        }
                    }
                }
            }

            hangfireContext.WriteLine("End of check for new OneStop queue items");
        }