Beispiel #1
0
        private void Awake()
        {
            ConsoleLog.Initialize();
            TextureManager.Initialize();
            FileReference.Initialize();
            CacheDetails.Initialize();

            // If game directory hasn't been set, Open "Locate Outpost2" dialog to force user to select one
            if (string.IsNullOrEmpty(UserPrefs.gameDirectory))
            {
                PreferencesDialog.Create();
            }

            Debug.Log("Hub initialized.");
        }
Beispiel #2
0
        public void OnClick_Delete()
        {
            // Remove details reference
            CacheDetails.RemoveMissionData(missionData.missionID);

            // Delete mission from cache
            if (Directory.Exists(CachePath.GetMissionDirectory(missionData.missionID)))
            {
                Directory.Delete(CachePath.GetMissionDirectory(missionData.missionID), true);
            }

            // Set buttons
            m_BtnDownload.gameObject.SetActive(true);
            m_BtnDelete.gameObject.SetActive(false);
            m_BtnInstall.interactable = false;
        }
        public void Assert_That__Cheap_Payment_GateWay_Is_Called_If_Amount_Is_Less_Than_20_Pounds()
        {
            var paymentRepository       = new Mock <IPaymentRepository>();
            var autoMapper              = new Mock <IMapper>();
            var cheapPaymentGateway     = new Mock <ICheapPaymentGateway>();
            var expensivePaymentGateway = new Mock <IExpensivePaymentGateway>();
            var premiumPaymentGateway   = new Mock <IPremiumPaymentService>();
            var paymentService          = new BankingAPI.Service.Manager.PaymentService(paymentRepository.Object, autoMapper.Object, cheapPaymentGateway.Object, premiumPaymentGateway.Object, expensivePaymentGateway.Object);
            var cacheDetail             = new CacheDetails
            {
                ProcessCount = 1,
                ExpensiveGatewayAvailability = false
            };

            paymentService.ProcessPayment(new Service.RequestModel.ProcessPaymentRequest
            {
                Amount = 15
            }, cacheDetail);
            cheapPaymentGateway.Verify(m => m.ProcessPayment(It.IsAny <bool>(), It.IsAny <int>()), Times.Once);
        }
        public void Assert_That_Premium_Payment_Gateway_Is_Retried_Three_Times_If_Not_Processed()
        {
            var paymentRepository       = new Mock <IPaymentRepository>();
            var autoMapper              = new Mock <IMapper>();
            var cheapPaymentGateway     = new Mock <ICheapPaymentGateway>();
            var expensivePaymentGateway = new Mock <IExpensivePaymentGateway>();
            var premiumPaymentGateway   = new Mock <IPremiumPaymentService>(MockBehavior.Strict);
            var paymentService          = new BankingAPI.Service.Manager.PaymentService(paymentRepository.Object, autoMapper.Object, cheapPaymentGateway.Object, premiumPaymentGateway.Object, expensivePaymentGateway.Object);
            var cacheDetail             = new CacheDetails
            {
                ProcessCount = 9,
                ExpensiveGatewayAvailability = false
            };

            paymentService.ProcessPayment(new Service.RequestModel.ProcessPaymentRequest
            {
                Amount = 501
            }, cacheDetail);
            premiumPaymentGateway.Verify(m => m.ProcessPayment(It.IsAny <bool>(), It.IsAny <int>()), Times.AtMostOnce);
        }
        public string GetPaymentProcessingStatus(ProcessPaymentRequest processPaymentRequest, CacheDetails cacheDetails)
        {
            string result = "";

            if (processPaymentRequest.Amount < 20)
            {
                result = _cheapPaymentGateway.ProcessPayment(cacheDetails.ExpensiveGatewayAvailability, cacheDetails.ProcessCount);
                return(result);
            }
            else if (processPaymentRequest.Amount > 20 && processPaymentRequest.Amount < 500)
            {
                if (cacheDetails.ExpensiveGatewayAvailability) // if expensive payment gateway is available use it else switch to cheap gateway
                {
                    result = _expensivePaymentGateway.ProcessPayment(cacheDetails.ExpensiveGatewayAvailability, cacheDetails.ProcessCount);
                    return(result);
                }
                else
                {
                    result = _cheapPaymentGateway.ProcessPayment(cacheDetails.ExpensiveGatewayAvailability, cacheDetails.ProcessCount);
                    return(result);
                }
            }
            int i = 0;

            while (i < Constants.PremiumCount && result != Constants.Processed)   //retry three times if transaction not successful
            {
                result = _premiumPaymentService.ProcessPayment(cacheDetails.ExpensiveGatewayAvailability, cacheDetails.ProcessCount);
            }
            return(result);
        }
        public async Task ProcessPayment(ProcessPaymentRequest processPaymentRequest, CacheDetails cacheDetails)
        {
            var payment = _mapper.Map <Payment>(processPaymentRequest);
            var paymentProcessStatus = GetPaymentProcessingStatus(processPaymentRequest, cacheDetails);
            var tranxRef             = GenerateTransactionreference();

            payment.TransactionReference = tranxRef;
            await _paymentRepository.ProcessPayment(payment);

            await _paymentRepository.ProcessProcessPaymentState(new PaymentState {
                State = paymentProcessStatus,
                TransactionReference = tranxRef
            });
        }
Beispiel #7
0
        private IEnumerator RequestDownloadMission()
        {
            ProgressDialog progressDialog = ProgressDialog.Create("Downloading Mission");

            foreach (string fileName in missionData.fileNames)
            {
                // Perform request
                string url      = WebConfig.webHost + "download/" + missionData.missionID + "/" + fileName;
                string destPath = Path.Combine(CachePath.GetMissionDirectory(missionData.missionID), fileName);

                using (UnityWebRequest request = UnityWebRequest.Get(url))
                {
                    progressDialog.SetTitle("Downloading " + fileName);
                    progressDialog.SetWebRequest(request);

                    yield return(request.SendWebRequest());

                    if (!DidDownloadSucceed(request, true))
                    {
                        progressDialog.Close();
                        OnClick_Delete();
                        yield break;
                    }

                    WriteFile(destPath, request.downloadHandler.data);
                }
            }

            // Get SDK path
            if (!string.IsNullOrEmpty(sdkVersion))
            {
                // Download SDK if it does not exist
                if (!File.Exists(CachePath.GetSDKFilePath(sdkVersion)))
                {
                    string url      = "https://github.com/TechCor8/OP2DotNetMissionSDK/releases/download/" + sdkVersion + "/" + CachePath.GetSDKFileName(sdkVersion);
                    string destPath = CachePath.GetSDKFilePath(sdkVersion);

                    using (UnityWebRequest request = UnityWebRequest.Get(url))
                    {
                        progressDialog.SetTitle("Downloading " + CachePath.GetSDKFileName(sdkVersion));
                        progressDialog.SetWebRequest(request);

                        yield return(request.SendWebRequest());

                        if (!DidDownloadSucceed(request, true))
                        {
                            progressDialog.Close();
                            OnClick_Delete();
                            yield break;
                        }

                        WriteFile(destPath, request.downloadHandler.data);
                    }
                }

                // Download SDK Interop if it does not exist or is from an older SDK
                if (!File.Exists(CachePath.GetInteropFilePath()) || CachePath.IsNewerVersion(sdkVersion, CacheDetails.interopVersion))
                {
                    string url      = "https://github.com/TechCor8/OP2DotNetMissionSDK/releases/download/" + sdkVersion + "/" + CachePath.DotNetInteropFileName;
                    string destPath = CachePath.GetInteropFilePath();

                    using (UnityWebRequest request = UnityWebRequest.Get(url))
                    {
                        progressDialog.SetTitle("Downloading " + CachePath.DotNetInteropFileName);
                        progressDialog.SetWebRequest(request);

                        yield return(request.SendWebRequest());

                        if (!DidDownloadSucceed(request, true))
                        {
                            progressDialog.Close();
                            OnClick_Delete();
                            yield break;
                        }

                        WriteFile(destPath, request.downloadHandler.data);
                    }
                }
            }

            progressDialog.Close();

            // Mission fully downloaded.
            // Write mission details
            string detailsJson = JsonUtility.ToJson(missionData);

            File.WriteAllText(CachePath.GetMissionDetailsFilePath(missionData.missionID), detailsJson);

            // Add mission details reference
            CacheDetails.AddMissionData(missionData);

            // Set buttons
            m_BtnDownload.gameObject.SetActive(false);
            m_BtnDelete.gameObject.SetActive(true);
            m_BtnInstall.interactable = true;
        }