Ejemplo n.º 1
0
        private async Task DoUpdateWineInventory(
            int workId,
            string sCode,
            string sBinCode,
            WineInfo wni,
            bool fCheckOnly,
            bool fErrorSoundsOnly, // we ignore this for wines -- we don't do bulk wine scanning
            Guid crids,
            FinalScanCodeReportAndCleanupDelegate del)
        {
            string sCheck = fCheckOnly ? "[CheckOnly] " : "";

            m_lp.LogEvent(crids, EventType.Verbose, "Service returned info for {0}", sCode);

            m_lp.LogEvent(crids, EventType.Verbose, "{1}Updating inventory for wine {0} ({2})", sCode, sCheck, sBinCode);

            // now update the last scan date
            bool fResult = fCheckOnly || await UpdateWineInventory(sCode, wni.Wine, sBinCode, crids);

            if (fResult)
            {
                m_lp.LogEvent(crids, EventType.Verbose, "{1}Successfully updated inventory for wine for {0}", sCode, sCheck);
                m_isr.AddMessage(fErrorSoundsOnly ? AlertType.None : AlertType.GoodInfo, "{1}{0}: Updated inventory for wine!", wni.Wine, sCheck);
            }
            else
            {
                m_lp.LogEvent(crids, EventType.Error, "Failed to update inventory for wine {0}", sCode);
                m_isr.AddMessage(AlertType.BadInfo, "{0}: Failed to update inventory for wine!", wni.Wine);
            }

            await del(workId, sCode, crids, wni.Wine, true);
        }
Ejemplo n.º 2
0
        private async Task DoDrinkWine(
            int workId,
            string sCode,
            string sNotes,
            WineInfo wni,
            bool fCheckOnly,
            bool fErrorSoundsOnly, // we ignore this for wines -- we don't do bulk wine scanning
            Guid crids,
            FinalScanCodeReportAndCleanupDelegate del)
        {
            string sCheck = fCheckOnly ? "[CheckOnly] " : "";

            m_lp.LogEvent(crids, EventType.Verbose, "Service returned info for {0}", sCode);

            m_lp.LogEvent(crids, EventType.Verbose, "{1}Drinking wine {0}", sCode, sCheck);

            // now update the last scan date
            bool fResult = fCheckOnly || await DrinkWine(sCode, wni.Wine, wni.Vintage, sNotes, crids);

            if (fResult)
            {
                m_lp.LogEvent(crids, EventType.Verbose, "{1}Successfully drank wine for {0}", sCode, sCheck);
                m_isr.AddMessage(AlertType.Drink, "{1}{0}: Drank wine!", wni.Wine, sCheck);
            }
            else
            {
                m_lp.LogEvent(crids, EventType.Error, "Failed to drink wine {0}", sCode);
                m_isr.AddMessage(AlertType.BadInfo, "{0}: Failed to drink wine!", wni.Wine);
            }

            await del(workId, sCode, crids, wni.Wine, true);
        }
Ejemplo n.º 3
0
        public async Task DoHandleWineScanCode(
            int workId,
            string sCode,
            string sNotes,
            string sBinCode,
            bool fCheckOnly,
            bool fErrorSoundsOnly,
            Guid crids,
            FinalScanCodeReportAndCleanupDelegate del)
        {
            bool fInventory = sBinCode != null;

            if (sNotes.StartsWith("!!") && !fInventory)
            {
                m_isr.AddMessage(AlertType.BadInfo, "Notes not set: {0}", sNotes);
                await del(workId, sCode, crids, null, false);

                return;
            }

            string sTitle = null;

            m_lp.LogEvent(crids, EventType.Verbose,
                          "Continuing with processing for {0}...Checking for WineInfo from service", sCode);
            WineInfo wni = await WineInfoRetrieve(sCode);

            if (wni != null)
            {
                string sOriginalCode = sCode;

                // we want to refresh the code to what we just retrieved, but first we have to capture the
                // original scancode so it can be sent to the delgate correctly
                FinalScanCodeReportAndCleanupDelegate delWrapper =
                    async(int workIdDel, string scanCodeDel, Guid cridsDel, string sFinalTitleDel, bool fResultDel) =>
                {
                    await del(workIdDel, sOriginalCode, cridsDel, sFinalTitleDel, fResultDel);
                };

                sCode = wni.Code;

                if (fInventory)
                {
                    await DoUpdateWineInventory(workId, sCode, sBinCode, wni, fCheckOnly, fErrorSoundsOnly, crids, delWrapper);
                }
                else
                {
                    await DoDrinkWine(workId, sCode, sNotes, wni, fCheckOnly, fErrorSoundsOnly, crids, delWrapper);
                }
            }
            else
            {
                m_isr.AddMessage(AlertType.BadInfo, "Could not find wine for {0}", sCode);

                sTitle = "!!WINE NOTE FOUND";

                await del(workId, sCode, crids, sTitle, false);
            }
        }
Ejemplo n.º 4
0
        /*----------------------------------------------------------------------------
        *       %%Function: DoHandleBookScanCode
        *       %%Qualified: UniversalUpc.UpcInvCore.DoHandleBookScanCode
        *       %%Contact: rlittle
        *
        *   Handle the dispatch of a DVD scan code.  Update the scan date,
        *   lookup a title, and create a title if necessary.
        *  ----------------------------------------------------------------------------*/
        public async Task DoHandleBookScanCode(
            int workId,
            string sCode,
            string sLocation,
            string sUnused2,
            bool fCheckOnly,
            bool fErrorSoundsOnly,
            Guid crids,
            FinalScanCodeReportAndCleanupDelegate del)
        {
            if (sLocation.StartsWith("!!"))
            {
                m_isr.AddMessage(AlertType.BadInfo, "Location not set: {0}", sLocation);
                await del(workId, sCode, crids, null, false);

                return;
            }

            string sTitle  = null;
            bool   fResult = false;

            m_lp.LogEvent(crids, EventType.Verbose, "Continuing with processing for {0}...Checking for BookInfo from service", sCode);
            BookInfo bki = await BookInfoRetrieve(sCode);

            if (bki != null)
            {
                DoUpdateBookScanDate(workId, sCode, sLocation, bki, fCheckOnly, fErrorSoundsOnly, crids, del);
            }
            else
            {
                try
                {
                    sTitle = await DoLookupBookTitle(sCode, crids);

                    if (sTitle != null)
                    {
                        fResult = await DoCreateBookTitle(sCode, sTitle, sLocation, fCheckOnly, fErrorSoundsOnly, crids);
                    }
                }
                catch (Exception exc)
                {
                    m_isr.AddMessage(AlertType.Halt, "Exception Caught: {0}", exc.Message);
                    sTitle  = "!!Exception";
                    fResult = false;
                }
                finally
                {
                    await del(workId, sCode, crids, sTitle, fResult);
                }
            }
        }
Ejemplo n.º 5
0
        /*----------------------------------------------------------------------------
        *       %%Function: DoHandleDvdScanCode
        *       %%Qualified: UniversalUpc.UpcInvCore.DoHandleDvdScanCode
        *       %%Contact: rlittle
        *
        *   Handle the dispatch of a DVD scan code.  Update the scan date,
        *   lookup a title, and create a title if necessary.
        *  ----------------------------------------------------------------------------*/
        public async Task DoHandleDvdScanCode(
            int workId,
            string sCode,
            string sUnused,
            string sUnused2,
            bool fCheckOnly,
            bool fErrorSoundsOnly,
            Guid crids,
            FinalScanCodeReportAndCleanupDelegate del)
        {
            string sTitle  = null;
            bool   fResult = false;

            m_lp.LogEvent(crids, EventType.Verbose,
                          "Continuing with processing for {0}...Checking for DvdInfo from service", sCode);

            m_isr.AddMessage(AlertType.None, $"Checking inventory for code: {sCode}...");

            DvdInfo dvdi = await DvdInfoRetrieve(sCode);

            if (dvdi != null)
            {
                DoUpdateDvdScanDate(workId, sCode, dvdi, fCheckOnly, fErrorSoundsOnly, crids, del);
            }
            else
            {
                try
                {
                    sTitle = await DoLookupDvdTitle(sCode, crids);

                    if (sTitle != null)
                    {
                        fResult = await DoCreateDvdTitle(sCode, sTitle, fCheckOnly, fErrorSoundsOnly, crids);
                    }
                }
                catch (Exception exc)
                {
                    m_isr.AddMessage(AlertType.Halt, "Exception Caught: {0}", exc.Message);

                    sTitle  = "!!Exception";
                    fResult = false;
                }
                finally
                {
                    await del(workId, sCode, crids, sTitle, fResult);
                }
            }
        }
Ejemplo n.º 6
0
        /*----------------------------------------------------------------------------
        *       %%Function: DoUpdateDvdScanDate
        *       %%Qualified: UniversalUpc.UpcInvCore.DoUpdateDvdScanDate
        *       %%Contact: rlittle
        *
        *  ----------------------------------------------------------------------------*/
        private async void DoUpdateBookScanDate(
            int workId,
            string sCode,
            string sLocation,
            BookInfo bki,
            bool fCheckOnly,
            bool fErrorSoundsOnly,
            Guid crids,
            FinalScanCodeReportAndCleanupDelegate del)
        {
            string sCheck = fCheckOnly ? "[CheckOnly] " : "";

            m_lp.LogEvent(crids, EventType.Verbose, "Service returned info for {0}", sCode);

            // check for a dupe/too soon last scan (within 1 hour)
            if (bki.LastScan > DateTime.Now.AddHours(-1))
            {
                m_lp.LogEvent(crids, EventType.Verbose, "{1}Avoiding duplicate scan for {0}", sCode, sCheck);
                m_isr.AddMessage(AlertType.Duplicate, "{2}{0}: Duplicate?! LastScan was {1}", bki.Title,
                                 bki.LastScan.ToString(), sCheck);
                await del(workId, sCode, crids, bki.Title, true);

                return;
            }

            m_lp.LogEvent(crids, EventType.Verbose, "Calling service to update scan date for {0}", sCode);

            // now update the last scan date
            bool fResult = fCheckOnly || await UpdateBookScan(sCode, bki.Title, sLocation, crids);

            if (fResult)
            {
                m_lp.LogEvent(crids, EventType.Verbose, "{1}Successfully updated last scan for {0}", sCode, sCheck);
                m_isr.AddMessage(fErrorSoundsOnly ? AlertType.None : AlertType.GoodInfo, "{2}{0}: Updated LastScan (was {1})", bki.Title,
                                 bki.LastScan.ToString(), sCheck);
            }
            else
            {
                m_lp.LogEvent(crids, EventType.Error, "Failed to update last scan for {0}", sCode);
                m_isr.AddMessage(AlertType.BadInfo, "{0}: Failed to update last scan!", bki.Title);
            }

            await del(workId, sCode, crids, bki.Title, true);
        }