Exemple #1
0
        }         // GetInferenceIfExists

        private Inference DownloadAndSave(int customerID, decimal explicitMonthlyPayment, bool isTryOut)
        {
            ModuleConfiguration cfg = Keeper.LoadModuleConfiguration();

            if (!cfg.RemoteRequestsEnabled)
            {
                Log.Debug(
                    "Engine.DownloadAndSave({0}, {1}, {2}): not calling remote API - calls are disabled.",
                    customerID,
                    explicitMonthlyPayment,
                    isTryOut
                    );

                return(null);
            }             // if

            var action = new DownloadAndSaveAction(
                Harvester,
                Keeper,
                customerID,
                explicitMonthlyPayment,
                isTryOut,
                Now,
                Log
                );

            action.Execute();

            return(action.Result);
        } // DownloadAndSave
Exemple #2
0
        public Inference GetInference(int customerID, decimal monthlyPayment, bool isTryout, GetInferenceMode mode)
        {
            Log.Debug("Engine.GetInference({0}, {1}) started...", customerID, mode);

            Inference result = null;

            switch (mode)
            {
            case GetInferenceMode.CacheOnly:
                result = GetInference(customerID, Now, isTryout, monthlyPayment);
                break;

            case GetInferenceMode.DownloadIfOld:
                Inference           cachedInference = GetInference(customerID, Now, isTryout, monthlyPayment);
                ModuleConfiguration cfg             = Keeper.LoadModuleConfiguration();

                if (cachedInference.IsUpToDate(Now, cfg.CacheAcceptanceDays))
                {
                    Log.Debug(
                        "Engine.GetInference({0}, {1}): returning cached inference with ResponseID = {2}.",
                        customerID,
                        mode,
                        cachedInference.ResponseID
                        );

                    result = cachedInference;
                    break;
                }                                         // if

                goto case GetInferenceMode.ForceDownload; // !!! fall through !!!

            case GetInferenceMode.ForceDownload:
                result = DownloadAndSave(customerID, monthlyPayment, isTryout);
                break;

            default:
                throw new EngineAlert(
                          Log,
                          new ArgumentOutOfRangeException("mode"),
                          "Failed to get customer {0} inference at mode {1}.",
                          customerID,
                          mode
                          );
            }             // switch

            Log.Debug("Engine.GetInference({0}, {1}) complete.", customerID, mode);

            return(result);
        }         // GetInference (standard, by actual data)