private void HandleUpdatesForStopStartProgram(ProgressResponse response, ProgramViewModel program, bool start) { MainThreadUtility.InvokeOnMain(() => { if (response != null) { DataCache.AddCommandProgress(new CommandProgress(CommandType.StartPrograms, response.Body, new string[] { program.Id })); if (response.IsFinal) { Action resetProgram = () => { program.Starting = false; //ServiceContainer.DeviceService.RequestDevice(this.Device.Device); }; if (response.IsSuccessful) { //AlertUtility.ShowProgressResponse("Stop/Start Program " + program.Id, response); this.RegisterForAsyncUpdate(resetProgram, 5000); } else { this.RegisterForAsyncUpdate(resetProgram); if ((bool)!response?.IsReconnectResponse && (bool)!response?.IsServerDownResponse) { AlertUtility.ShowAppError(response?.ErrorBody); } } } } }); }
private void HandleUpdatesForPrev(ProgressResponse response) { MainThreadUtility.InvokeOnMain(() => { if (response != null) { DataCache.AddCommandProgress(new CommandProgress(CommandType.DevicePrev, response.Body)); if (response.IsFinal) { this.Device.Preving = false; this.SetButtonMode(this._prevButton, this._prevButtonSpinner, false); if (response.IsSuccessful) { } else { if ((bool)!response?.IsReconnectResponse && (bool)!response?.IsServerDownResponse) { AlertUtility.ShowAppError(response?.ErrorBody); } } } } AlertUtility.ShowProgressResponse(this._prevFeature.ProgressText, response); }); }
public async Task GetProgressTest() { ArachniApi api = new ArachniApi(Address); ProgressResponse result = await api.GetProgress(id); Assert.IsNotNull(result); string j = JsonConvert.SerializeObject(result); await File.WriteAllTextAsync("d:\\result_progress.json", j); }
public static void ShowProgressResponse(string title, ProgressResponse response) { ExceptionUtility.Try(() => { if (response != null) { if (response.IsFinal) { if (response.HasError) { //ShowAppError(response.ErrorBody); } else { string message = String.Empty; if (response.Body != null) { message = String.Empty; if (!String.IsNullOrEmpty(response.Body.Progress)) { message += "Progress: " + response.Body.Progress; } if (!String.IsNullOrEmpty(response.Body.ProgressDescription)) { message += "\nProgressDescription: " + response.Body.ProgressDescription; } if (response.Body.ProgressSpecific != null) { message += "\nProgressSpecific: " + response.Body.ProgressSpecific; } if (!String.IsNullOrEmpty(response.Body.CommandId)) { message += "\nCommandId: " + response.Body.CommandId; } } if (title == null) { title = String.Empty; } if (!response.IsSuccessful && !response.HasError) { ShowAlert(title, message); } LogUtility.LogMessage(message); } } } }); }
private void HandleUpdatesForTestStations(ProgressResponse response, string[] stationIds) { MainThreadUtility.InvokeOnMain(() => { if (response != null) { DataCache.AddCommandProgress(new CommandProgress(CommandType.TestStations, response.Body, stationIds)); if (response.IsFinal) { Action resetStations = () => { foreach (string id in stationIds) { var station = this.Device?.Device?.Stations.Values.Where((d) => d.Id == id).FirstOrDefault(); if (station != null) { station.Selected = false; station.Starting = false; } } }; if (response.IsSuccessful) { //AlertUtility.ShowAlert("Testing Stations", "Testing Stations"); this.RegisterForAsyncUpdate(resetStations, 5000); } else { this.RegisterForAsyncUpdate(resetStations); if ((bool)!response?.IsReconnectResponse && (bool)!response?.IsServerDownResponse) { AlertUtility.ShowAppError(response?.ErrorBody); } } DataCache.TriggerDeviceUpdate(this.DeviceId); int countSelected = Device.Stations.Where((s) => s.Selected).Count(); this._buttonFooterView.PermaDisabled = false; this.ShowHideButtonFooter(countSelected); this._selectionHeaderView.Enabled = true; /* * this.LoadData(); */ } } }); }
private void HandleUpdatesForStartCircuits(ProgressResponse response, string[] circuitIds, int durationMinutes) { MainThreadUtility.InvokeOnMain(() => { if (response != null) { DataCache.AddCommandProgress(new CommandProgress(CommandType.StartCircuits, response.Body, circuitIds)); if (response.IsFinal) { Action resetCircuits = () => { foreach (string id in circuitIds) { var circuit = this.Device?.Device?.Circuits.Values.Where((d) => d.Id == id).FirstOrDefault(); if (circuit != null) { circuit.Selected = false; circuit.Starting = false; } } }; if (response.IsSuccessful) { //AlertUtility.ShowAlert("Start Circuits", "Start Circuits"); this.RegisterForAsyncUpdate(resetCircuits, 5000); } else { this.RegisterForAsyncUpdate(resetCircuits); if ((bool)!response?.IsReconnectResponse && (bool)!response?.IsServerDownResponse) { AlertUtility.ShowAppError(response?.ErrorBody); } } DataCache.TriggerDeviceUpdate(this.DeviceId); int countSelected = Device.Circuits.Where((s) => s.Selected).Count(); this._buttonFooterView.PermaDisabled = false; this.ShowHideButtonFooter(countSelected > 0); this._selectionHeaderView.Enabled = true; } } AlertUtility.ShowProgressResponse("Start Circuits", response); }); }
public async Task GetByIdAsyncWhenInvalidIdReturnsProgressNotFoundResponse() { // Arrange var mockProgressRepository = GetDefaultIProgressRepositoryInstance(); var progressId = 1; mockProgressRepository.Setup(r => r.FindById(progressId)) .Returns(Task.FromResult<Progress>(null)); var mockUnitOfWork = GetDefaultIUnitOfWorkInstance(); var service = new ProgressService(mockProgressRepository.Object, mockUnitOfWork.Object); // Act ProgressResponse result = await service.GetByIdAsync(progressId); var message = result.Message; // Assert message.Should().Be("Progress not found"); }
private void HandleUpdatesForStartStations(ProgressResponse response, IEnumerable <PumpViewModel> pumps, int durationMinutes, string[] stationIds) { MainThreadUtility.InvokeOnMain(() => { if (response != null) { DataCache.AddCommandProgress(new CommandProgress(CommandType.StartStations, response.Body, stationIds)); if (response.IsFinal) { Action resetStations = () => { foreach (string id in stationIds) { var station = this.Device?.Device?.Stations.Values.Where((d) => d.Id == id).FirstOrDefault(); if (station != null) { station.Selected = false; station.Starting = false; } } }; if (response.IsSuccessful) { //AlertUtility.ShowAlert("Starting Stations", "Starting Stations"); this.RegisterForAsyncUpdate(resetStations, 5000); } else { this.RegisterForAsyncUpdate(resetStations); if ((bool)!response?.IsReconnectResponse && (bool)!response?.IsServerDownResponse) { AlertUtility.ShowAppError(response?.ErrorBody); } } DataCache.TriggerDeviceUpdate(this.DeviceId); } } }); }
public ProgressResponse GetProgress(ProgressRequest pr) { // calculate points for this round long qpa = GetQuestPoint(pr.ChipAmountBet, pr.PlayerLevel); // get player data var pp = pdm.GetOrCreatePlayer(pr.PlayerId); // add qpa to total player saved long qpe = qpa + pp.PointsEarned; pp.PointsEarned = qpe; // update total points earned // get player current quest Quest qq = qcm.GetQuest(pp.QuestIndex).Value; // calc total quest % complete double qpc = GetTotalQuestPercentCompleted(qpe, qq.PointsCompleted); // calc milestone completed var ms = GetMileStoneCompleted(qq, pp); // update & save player latest info pp.MilestoneIndex = ms == null ? pp.MilestoneIndex : ms.MilestoneIndex; pdm.Save(pp); // determine if quest leveled up to new quest! LeveledUpQuest(qq, pp); var prc = new ProgressResponse() { QuestPointsEarned = qpe, TotalQuestPercentCompleted = qpc, MilestonesCompleted = ms }; return(prc); }
/// <summary> /// Registers a callback to receive updates when ProgressResponse updates are received for a specific async command. /// </summary> /// <param name="response">The first ProgressResponse received; we're saying that we want further updates related to /// this response.</param> /// <param name="callback">The callback to call when udpates are received</param> protected void RegisterForProgressUpdates(ProgressResponse response, Action <ProgressResponse> callback) { if (response != null && callback != null) { if (response.IsFinal) { callback(response); } else { if (response.CommandId != null) { Action <ProgressResponse> superCallback = (p) => { ServiceContainer.InvalidateCache(); callback(p); }; WebSocketsClient.RegisterForProgressUpdates(response.CommandId, superCallback); } } } }
public static void Request(string url, Action <ServerImage> successCallback, Action <string> failedCallback = null, Action <ProgressResponse> progressCallback = null, string cancelKey = DEFAULT_URL_CANCEL_KEY, float cacheTimeOutInSecs = DEFAULT_CACHE_TIMEOUT, float requestTimeout = -1) { if (m_prefixURL != null && !url.Contains("http")) { url = m_prefixURL + url; } CacheImage cacheImage; bool useMemoryCache = false; bool imageOnDisk = false; ulong codedURL = GetHashCodeInt64(url); Debugger.Log("WebImage::Request key: " + cancelKey + " url: " + url, (int)SharedSystems.Systems.WEB_IMAGE); Debugger.Assert(!string.IsNullOrEmpty(cancelKey), "WebImage:;Request() called with no cancel key, ignoring request"); if (string.IsNullOrEmpty(cancelKey)) { return; } if (s_cachedImages.TryGetValue(codedURL, out cacheImage)) { useMemoryCache = ((cacheImage.weakReference.Target as Texture2D) != null); } Debugger.Log("WebImage::Request useMemoryCache: " + useMemoryCache, (int)SharedSystems.Systems.WEB_IMAGE); if (useMemoryCache) { cacheImage.isCached = true; cacheImage.timeStamp = System.DateTime.UtcNow; if (progressCallback != null) { ProgressResponse progress = new ProgressResponse(); progress.isDone = true; progress.progress = (float)1.0; progressCallback(progress); } if (successCallback != null) { ServerImage image = new ServerImage(); image.texture = cacheImage.weakReference.Target as Texture2D; image.isCached = true; Debugger.Log("WebImage::Request successCallback key: " + cancelKey + " url: " + url, (int)SharedSystems.Systems.WEB_IMAGE); successCallback(image); } } else { bool doRequest = true; string filePath = Application.temporaryCachePath + "/CACHE" + codedURL.ToString(); if (System.IO.File.Exists(filePath)) { //check how old System.DateTime written = File.GetLastWriteTimeUtc(filePath); System.DateTime now = System.DateTime.UtcNow; double totalSeconds = now.Subtract(written).TotalSeconds; if (totalSeconds < cacheTimeOutInSecs) { doRequest = false; CoroutineHelper.Instance.Run(LoadImageFromDiskInternal(filePath, codedURL, successCallback, cancelKey)); } } if (doRequest) { CoroutineHelper.Instance.Run(GetImage(url, codedURL, successCallback, progressCallback, failedCallback, cancelKey, imageOnDisk, requestTimeout)); } } }
private static IEnumerator UpdateImageProgress(UnityWebRequest webRequest, Action <ProgressResponse> progressCallback, Action <string> failCallback, bool ignoreFileSize) { bool eventSent = false; while (!webRequest.isDone) { yield return(new WaitForFixedUpdate()); int contentLength = 0; int.TryParse(webRequest.GetResponseHeader("Content-Length"), out contentLength); if (!eventSent && (contentLength > ANALYTICS_TRIGGER_SIZE_DEFAULT || (int)webRequest.downloadedBytes > ANALYTICS_TRIGGER_SIZE_DEFAULT)) { eventSent = true; Core.Analytics.Dispatcher.Param urlParam = new Core.Analytics.Dispatcher.Param() { name = "url", value = webRequest.url }; Core.Analytics.Dispatcher.Param contentLengthParam = new Core.Analytics.Dispatcher.Param() { name = "contentLength", value = contentLength }; Core.Analytics.Dispatcher.Param bytesDownloadedParam = new Core.Analytics.Dispatcher.Param() { name = "downloadedBytes", value = webRequest.downloadedBytes }; Core.Analytics.Dispatcher.Param[] paramsArray = new Core.Analytics.Dispatcher.Param[3] { urlParam, contentLengthParam, bytesDownloadedParam }; Core.Analytics.Dispatcher.SendEvent(Core.Analytics.Events.IMAGE_OVER_SIZE_LIMIT, paramsArray); } if (!ignoreFileSize && (contentLength > MAX_SIZE_BYTES || webRequest.downloadedBytes > MAX_SIZE_BYTES)) { Debugger.Log("UpdateImageProgress abort file size webRequest.url: " + webRequest.url, (int)SharedSystems.Systems.WEB_IMAGE); webRequest.Abort(); yield break; } else { if (progressCallback != null) { ProgressResponse progress = new ProgressResponse(); progress.isDone = webRequest.isDone; progress.progress = webRequest.downloadProgress; progressCallback(progress); } } } }
private static IEnumerator GetImage(string url, ulong codedURL, Action <ServerImage> successCallback, Action <ProgressResponse> progressCallback, Action <string> failedCallback, string cancelKey, bool imageOnDisk, float requestTimeout) { Debugger.Log("GetImage() key: " + cancelKey + " url: " + url, (int)SharedSystems.Systems.WEB_IMAGE); WWW www = new WWW(url); AddRequest(cancelKey, codedURL, null); Texture2D texture = null; float timer = 0f; if (www.isDone || texture != null) { Debugger.Error("GetImage() www.isDone is true before we get to the while. Forcing it through."); } bool forceEnterWhile = true; // Force into the while at least once while (forceEnterWhile || (!www.isDone && texture == null)) { forceEnterWhile = false; yield return(new WaitForFixedUpdate()); timer += Time.deltaTime; if (progressCallback != null) { ProgressResponse progress = new ProgressResponse(); progress.isDone = www.isDone; progress.progress = www.progress; progressCallback(progress); } if (!string.IsNullOrEmpty(www.error)) { Debugger.Log(www.error + "\nurl: " + url, (int)SharedSystems.Systems.WEB_IMAGE); RemoveRequest(cancelKey, codedURL); if (failedCallback != null) { failedCallback(www.error); } yield break; } if (www.isDone) { Debugger.Log("www.isDone: " + url, (int)SharedSystems.Systems.WEB_IMAGE); texture = www.texture; FinaliseTexture(url, codedURL, texture, successCallback, cancelKey); if (!imageOnDisk) { yield return(SaveImage(www.bytes, codedURL, cancelKey)); } RemoveRequest(cancelKey, codedURL); yield break; } if (requestTimeout != -1 && timer > requestTimeout) { Debugger.Log("Image download timed out", (int)SharedSystems.Systems.WEB_IMAGE); RemoveRequest(cancelKey, codedURL); if (failedCallback != null) { failedCallback("timeout"); } yield break; } } }