示例#1
0
        public static TimerSyncAction CreateInstance(float seconds)
        {
            TimerSyncAction instance = CreateInstance <TimerSyncAction>();

            instance.duration = seconds;
            return(instance);
        }
        void HandleSuccessCallback(IBM.Watson.DeveloperCloud.Services.SpeechToText.v1.Customization response, Dictionary <string, object> customData)
        {
            if (response != null)
            {
                string status = response.status;
                if (status.Length > 0)
                {
                    status = status.Substring(0, 1).ToUpper() + status.Substring(1);
                }

                workspace.WatsonSpeechToTextManager.SyncStatus = status;

                Debug.Log("Response progress: " + response.progress);

                // TODO: Use retry here.
                if (response.progress < 100)
                {
                    queue.Insert(TimerSyncAction.CreateInstance(5), 0);
                    queue.Insert(WatsonCustomModelStatus.CreateInstance(workspace), 1);
                }

                succeeded = true;
                isDone    = true;
                return;
            }

            succeeded = false;
            isDone    = true;
        }
        public void SyncWatsonSpeechToText(LexiconWorkspace workspace, WorkspaceSyncData syncData)
        {
            workspace.WatsonSpeechToTextManager.IsSyncing  = true;
            workspace.WatsonSpeechToTextManager.SyncStatus = "Syncing";

            WatsonSyncQueue syncQueue = ScriptableObject.CreateInstance <WatsonSyncQueue>();

            syncQueue.workspace = workspace;
            syncQueue.syncData  = syncData;

            if (string.IsNullOrEmpty(workspace.WatsonSpeechToTextManager.CustomizationId))
            {
                syncQueue.Enqueue(WatsonCustomModelCreate.CreateInstance(workspace));
            }
            else
            {
                syncQueue.Enqueue(WatsonCustomWordsUpdate.CreateInstance(workspace));
                syncQueue.Enqueue(TimerSyncAction.CreateInstance(10));
            }

            syncQueue.Enqueue(WatsonCorpusAddIntents.CreateInstance(workspace));
            syncQueue.Enqueue(TimerSyncAction.CreateInstance(10));
            syncQueue.Enqueue(WatsonCorpusAddEntities.CreateInstance(workspace));
            syncQueue.Enqueue(TimerSyncAction.CreateInstance(10));
            syncQueue.Enqueue(WatsonCustomModelTrain.CreateInstance(workspace));
            syncQueue.Enqueue(TimerSyncAction.CreateInstance(10));

            syncQueue.OnCompleteAction = WatsonCompleteSpeechToTextSync.CreateInstance(workspace);
            syncQueue.OnQueueFinished += CleanUp;

            syncQueue.Process();

            watsonSpeechToTextSyncQueues.Add(syncQueue);
        }
        void HandleSuccessCallback(Workspace watsonWorkspace, Dictionary <string, object> customData)
        {
            if (watsonWorkspace != null)
            {
                workspace.WatsonConversationManager.SyncStatus = watsonWorkspace.status;

                if (!string.Equals(watsonWorkspace.status, "Available", StringComparison.OrdinalIgnoreCase))
                {
                    // TODO: Use retry here.
                    queue.Insert(TimerSyncAction.CreateInstance(10), 0);
                    queue.Insert(WatsonWorkspaceStatus.CreateInstance(workspace), 1);
                }

                succeeded = true;
                isDone    = true;
                return;
            }

            succeeded = false;
            isDone    = true;
        }
示例#5
0
        private IEnumerator ProcessQueue()
        {
            if (finished)
            {
                // Already finished, exit the coroutine.
                yield break;
            }

            processing = true;
            bool failed = false;

            SyncAction action = Dequeue();

            while (action != null)
            {
                Debug.Log("Processing Action: " + action.GetType().Name);

                yield return(null);

                // Reset all fields in case this is a retry.
                action.isDone     = false;
                action.succeeded  = false;
                action.retry      = false;
                action.retryDelay = 0.0f;

                action.Process(this);

                while (!action.isDone)
                {
                    yield return(null);
                }

                Debug.Log("Action " + action.GetType().Name + " " + (action.succeeded ? "Succeeded" : (action.retry ? "Retry" : "Failed")));

                if (!action.succeeded)
                {
                    RequeueCurrentAction();

                    if (!action.retry)
                    {
                        // Fatal error, stop the queue.
                        failed = true;
                        DestroyImmediate(action);
                        break;
                    }
                    else if (action.retryDelay > 0)
                    {
                        // Wait delay seconds and try again.
                        Insert(TimerSyncAction.CreateInstance(action.retryDelay), 0);
                    }
                }
                else
                {
                    DestroyImmediate(action);
                }

                yield return(null);

                action = Dequeue();
            }

            if (onCompleteAction != null)
            {
                onCompleteAction.succeeded = !failed;
                onCompleteAction.Process(this);
                DestroyImmediate(onCompleteAction);
            }

            processing = false;
            finished   = true;

            if (OnQueueFinished != null)
            {
                OnQueueFinished();
            }
        }