Exemple #1
0
        public static WatsonIntentDelete CreateInstance(LexiconWorkspace workspace, string intentName)
        {
            WatsonIntentDelete instance = CreateInstance <WatsonIntentDelete>();

            instance.workspace  = workspace;
            instance.intentName = intentName;
            return(instance);
        }
Exemple #2
0
        void HandleSuccessCallback(ListIntentsResp intentsResp, Dictionary <string, object> customData)
        {
            if (intentsResp == null)
            {
                succeeded = false;
                isDone    = true;
                return;
            }

            WorkspaceSyncData syncData = queue.syncData;

            HashSet <string> watsonIntentNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (Intent watsonIntent in intentsResp.intents)
            {
                string     intentName = watsonIntent.intent;
                IntentData localIntent;

                if (syncData.intentData.TryGetValue(intentName, out localIntent))
                {
                    string localTimestamp = workspace.WatsonConversationManager.Timestamps.GetIntentTimestamp(intentName);
                    bool   needsUpdate    = true;

                    if (watsonIntent.updated.Equals(localTimestamp, StringComparison.OrdinalIgnoreCase))
                    {
                        // No remote changes

                        if (workspace.WatsonConversationManager.LastSyncData != null)
                        {
                            IntentData lastSync;
                            if (workspace.WatsonConversationManager.LastSyncData.intentData.TryGetValue(intentName, out lastSync))
                            {
                                if (WorkspaceSyncData.CompareIntentData(localIntent, lastSync))
                                {
                                    // No local changes
                                    needsUpdate = false;
                                }
                            }
                        }
                    }

                    if (needsUpdate)
                    {
                        queue.Enqueue(WatsonIntentUpdate.CreateInstance(workspace, localIntent));
                    }
                }
                else
                {
                    // Intent deleted locally
                    queue.Enqueue(WatsonIntentDelete.CreateInstance(workspace, intentName));
                }

                watsonIntentNames.Add(intentName);
            }

            foreach (IntentData localIntent in syncData.intentData.Values)
            {
                if (!watsonIntentNames.Contains(localIntent.name))
                {
                    // Intent does not exist on server
                    queue.Enqueue(WatsonIntentCreate.CreateInstance(workspace, localIntent));
                }
            }

            succeeded = true;
            isDone    = true;
        }