protected virtual void ProcessResults(WaitableTask result, TaskResult <string> serverOutput)
        {
            if (serverOutput == null || serverOutput.IsError())
            {
                result.SetError(serverOutput.Exception);
                return;
            }

            var output = serverOutput.Value.Trim();

            if (output.StartsWith("1"))
            {
                result.SetCompleted();
                return;
            }

            string errorStart = "-1|";

            if (output.StartsWith(errorStart, StringComparison.InvariantCultureIgnoreCase))
            {
                var encounterLock = parser.Deserialize(output.Substring(errorStart.Length));
                result.SetError(new EncounterAlreadyLockedException(encounterLock));
                return;
            }

            result.SetError(new Exception("Could not unlock the encounter."));
        }
示例#2
0
        private void ProcessResults(WaitableTask actionResult, TaskResult <string> serverResult, EncounterMetadata metadata)
        {
            if (serverResult.IsError())
            {
                actionResult.SetError(serverResult.Exception);
                return;
            }

            Debug.Log("Returned text from PHP: \n" + serverResult.Value);
            if (string.IsNullOrWhiteSpace(serverResult.Value))
            {
                actionResult.SetError(new Exception("No text returned from the server."));
            }
            else if (!int.TryParse(serverResult.Value, out int recordNumber))
            {
                actionResult.SetError(new Exception(serverResult.Value));
            }
            else if (recordNumber != metadata.RecordNumber)
            {
                actionResult.SetError(new Exception("Did not get the correct metadata from the server."));
            }
            else
            {
                actionResult.SetCompleted();
            }
        }
 protected virtual void AutosaveCompleted(TaskResult result)
 {
     if (!result.IsError())
     {
         MessageHandler.ShowMessage("Encounter autosaved.");
     }
 }
示例#4
0
        protected virtual void OnCustomSpriteSelected(TaskResult <string> spriteKey)
        {
            if (spriteKey.IsError())
            {
                return;
            }

            LastUploadedIcon = spriteKey != null ? new Icon(Icon.IconType.Upload, spriteKey.Value) : null;
            SetCurrentToLastUploadedIcon();
        }
 private void CopyValue(TaskResult source, WaitableTask destination)
 {
     if (source.IsError())
     {
         destination.SetError(source.Exception);
     }
     else
     {
         destination.SetCompleted();
     }
 }
示例#6
0
 protected virtual void SetFileResult(TaskResult <string> serverResult, WaitableTask <string> fileText)
 {
     if (serverResult.IsError())
     {
         fileText.SetError(serverResult.Exception);
     }
     else
     {
         fileText.SetResult(serverResult.Value);
     }
 }
        private void ProcessResults(WaitableTask <List <EncounterMetadata> > result, TaskResult <string> serverOutput)
        {
            if (serverOutput == null || serverOutput.IsError())
            {
                result.SetError(serverOutput.Exception);
                return;
            }

            var metadatas = parser.Deserialize(serverOutput.Value);

            result.SetResult(metadatas);
        }
示例#8
0
        protected void SetEncounters(TaskResult <string> serverResult)
        {
            if (demoEncounters == null || demoEncounters.IsCompleted() || serverResult.IsError())
            {
                demoEncounters.SetError(new Exception("Could not get demo encounters from file."));
                return;
            }

            var splitChars = new char[] { '\n', '\r' };
            var encounters = serverResult.Value.Split(splitChars, StringSplitOptions.RemoveEmptyEntries);

            demoEncounters.SetResult(encounters);
        }
示例#9
0
        protected virtual void EncounterLocked(
            TaskResult result,
            MenuSceneInfo sceneInfo,
            KeyValuePair <SaveType, EncounterMetadata> metadata)
        {
            if (!result.IsError())
            {
                StartWriter(sceneInfo, metadata);
                return;
            }

            MessageHandler.ShowMessage($"Cannot set lock on encounter: {result.Exception.Message}", MessageType.Error);
        }
示例#10
0
        private void ProcessResults(TaskResult <string> serverResult)
        {
            if (serverResult.IsError())
            {
                //MessageHandler.ShowMessage(serverResult.Message, true);
                return;
            }
            if (!serverResult.Value.EndsWith(errorSuffix))
            {
                //MessageHandler.ShowMessage(serverResult.Message, false);
                return;
            }

            var error = serverResult.Value.Substring(0, serverResult.Value.Length - errorSuffix.Length);
            //MessageHandler.ShowMessage(error, true);
        }
示例#11
0
        private void ProcessResults(TaskResult <string> serverResults)
        {
            if (serverResults.IsError())
            {
                //MessageHandler.ShowMessage(serverResults.Message, true);
                return;
            }
            if (serverResults.Value.StartsWith("Connection Granted"))
            {
                //MessageHandler.ShowMessage("Success. Please check email (or spam folder) for verification", false);
                return;
            }

            var error = serverResults.Value.Split(new string[] { "--" }, System.StringSplitOptions.None)[0];
            //MessageHandler.ShowMessage(error, true);
        }
示例#12
0
        private void ProcessResults(TaskResult <string> serverResult)
        {
            if (serverResult.IsError())
            {
                //MessageHandler.ShowMessage(serverResult.Message, true);
                return;
            }
            if (!serverResult.Value.EndsWith(errorSuffix))
            {
                //MessageHandler.ShowMessage("Success. Please check email for verification", false);
                return;
            }

            var error = serverResult.Value.Substring(0, serverResult.Value.Length - errorSuffix.Length);
            //MessageHandler.ShowMessage("Unable to send email", true);
        }
示例#13
0
        private void ProcessResults(WaitableTask <User> result, TaskResult <string> serverResult)
        {
            if (serverResult.IsError() || string.IsNullOrWhiteSpace(serverResult.Value))
            {
                result.SetError(serverResult.Exception);
                return;
            }

            var user = UserDeserializer.Deserialize(serverResult.Value);

            if (user == null)
            {
                result.SetError(new Exception($"Could not parse user: {serverResult.Value}"));
            }
            else
            {
                result.SetResult(user);
            }
        }
        protected virtual void CompleteMenuEncountersInfoTask(WaitableTask <IMenuEncountersInfo> task,
                                                              TaskResult <IMenuEncountersInfo> result, UserEncounter userEncounter)
        {
            if (userEncounter?.Status != null)
            {
                userEncounter.Status.BasicStatus.Completed = userEncounter.Status.ContentStatus.Read;
            }

            if (result.IsError())
            {
                task.SetError(result.Exception);
                return;
            }

            if (result.Value == null)
            {
                task.SetResult(null);
                return;
            }

            foreach (var encounter in result.Value.GetEncounters())
            {
                if (encounter.GetLatestMetadata().RecordNumber != userEncounter.Data.Metadata.RecordNumber)
                {
                    continue;
                }

                if (userEncounter.Status != null)
                {
                    encounter.Status = userEncounter.Status.BasicStatus;
                }
                else
                {
                    encounter.Status = new EncounterBasicStatus();
                }
                break;
            }

            task.SetResult(result.Value);
        }
        protected virtual void ProcessResults(
            WaitableTask <Dictionary <int, EncounterEditLock> > result,
            TaskResult <string> serverOutput)
        {
            if (serverOutput == null || serverOutput.IsError())
            {
                result.SetError(serverOutput.Exception);
                return;
            }

            var locks          = parser.Deserialize(serverOutput.Value);
            var lockDictionary = new Dictionary <int, EncounterEditLock>();

            foreach (var encounterLock in locks)
            {
                if (!lockDictionary.ContainsKey(encounterLock.RecordNumber))
                {
                    lockDictionary.Add(encounterLock.RecordNumber, encounterLock);
                }
            }
            result.SetResult(lockDictionary);
        }
示例#16
0
        protected virtual void ProcessResults(WaitableTask actionResult, TaskResult <string> serverResult, EncounterMetadata metadata)
        {
            if (serverResult.IsError())
            {
                actionResult.SetError(serverResult.Exception);
                return;
            }

            Debug.Log("Returned text from PHP: \n" + serverResult.Value);
            if (string.IsNullOrWhiteSpace(serverResult.Value))
            {
                actionResult.SetError(new Exception("No text returned from the server."));
                return;
            }

            var splitStr = serverResult.Value.Split('|');

            if (int.TryParse(splitStr[0], out var recordNumber))
            {
                metadata.RecordNumber = recordNumber;
            }

            actionResult.SetCompleted();
        }
        protected virtual void SetUserEncounter(WaitableTask <UserEncounter> result, User user, TaskResult <IMenuEncountersInfo> encounters, int recordNumber)
        {
            if (encounters.IsError())
            {
                result.SetError(encounters.Exception);
                return;
            }

            foreach (var encounter in encounters.Value.GetEncounters())
            {
                var typedMetadata = encounter.GetLatestTypedMetada();
                if (typedMetadata.Value.RecordNumber != recordNumber)
                {
                    continue;
                }

                ImageHolder.HoldImage(typedMetadata.Value.Sprite);
                var userEncounter = EncounterReader.GetUserEncounter(user, typedMetadata.Value, encounter.Status, typedMetadata.Key);
                userEncounter.CopyValueWhenCompleted(result);
                return;
            }

            result.SetError(new Exception("Could not find an encounter with the given record number."));
        }