public static WatsonIntentCreate CreateInstance(LexiconWorkspace workspace, IntentData intentData) { WatsonIntentCreate instance = CreateInstance <WatsonIntentCreate>(); instance.workspace = workspace; instance.localIntent = intentData; return(instance); }
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; }