public Value AdicionarVEntidade(String WorkId, String Entidade, String Valor) { CreateValue value = new CreateValue() { Value = Valor }; var result = _assistant.CreateValue(WorkId, Entidade, value); return(result); }
public TValue GetOrCreateAndSave(TKey key, int hashForValidityOfValue, CreateValue <TValue> createValue) { if (this.ContainsKey(key, hashForValidityOfValue)) { CachedValue <TValue> cacheResult = this.internalStore[key]; return(cacheResult.Value); } TValue value = createValue(); this.Save(key, value, hashForValidityOfValue); return(value); }
public TValue GetOrCreateValue(TKey key, CreateValue create) { lock (data) { PublishInfo <TValue> pubValue; if (data.TryGetValue(key, out pubValue)) { if (pubValue.Value == null && pubValue.Exception == null) { pubValue.PrepareForWait(); Monitor.Exit(data); try { pubValue.WaitForPublish(); } finally { Monitor.Enter(data); pubValue.FinishWait(); } } if (pubValue.Exception != null) { throw new Exception("Error", pubValue.Exception); } return(pubValue.Value); } TValue ret; // publish the empty PublishInfo data[key] = pubValue = new PublishInfo <TValue>(); // release our lock while we create the new value // then re-acquire the lock and publish the info. Monitor.Exit(data); try{ try { ret = create(); Debug.Assert(ret != null, "Can't publish a null value"); } finally { Monitor.Enter(data); } } catch (Exception e) { pubValue.PublishError(e); throw; } pubValue.PublishValue(ret); return(ret); } }
public Value CreateValue(string workspaceId, string entity, CreateValue body) { try { var result = AssistantRepository.CreateValue(workspaceId, entity, body); return(result); } catch (Exception ex) { Logger.Error("AssistantService.CreateValue failed", this, ex); } return(null); }
private void btnCreateNewDefinition_Click(object sender, RoutedEventArgs e) { var dialog = new CreateValue(); if (dialog.ShowDialog() == true) { if (!string.IsNullOrWhiteSpace(dialog.ResponseText)) { DataFac.AddProperty(new Property(dialog.ResponseText)); } else { MessageBox.Show("Du mangler at udfylde feltet"); } } FillOutProperty(); }
private void btnCreateValue(object sender, RoutedEventArgs e) { string content = (sender as Button).Tag.ToString(); var dialog = new CreateValue(); if (dialog.ShowDialog() == true) { if (!string.IsNullOrWhiteSpace(dialog.ResponseText)) { Property prop = PropRep.GetByName(content); DataFac.AddValueToProp(dialog.ResponseText, prop._id); KeepSelectedValues(); } else { MessageBox.Show("Du mangler at udfylde feltet"); } } }
private void CreateValue() { Console.WriteLine(string.Format("\nCalling CreateValue({0}, {1}, {2})...", _createdWorkspaceId, _createdEntity, _createdValue)); CreateValue value = new CreateValue() { Value = _createdValue }; var result = _conversation.CreateValue(_createdWorkspaceId, _createdEntity, value); if (result != null) { Console.WriteLine(string.Format("value: {0}", result.ValueText)); } else { Console.WriteLine("Result is null."); } }
public void CreateValue_Success() { Console.WriteLine(string.Format("\nCalling CreateValue({0}, {1}, {2})...", _createdWorkspaceId, _createdEntity, _createdValue)); CreateValue value = new CreateValue() { Value = _createdValue }; var result = conversation.CreateValue(_createdWorkspaceId, _createdEntity, value); Assert.IsNotNull(result); if (result != null) { Console.WriteLine(string.Format("value: {0}", result.Value)); } else { Console.WriteLine("Result is null."); } }
public override void Process(SyncQueue queue) { if (CreateConversation()) { List <CreateValue> createValues = new List <CreateValue>(); foreach (EntityValueData valueData in localEntity.values) { CreateValue createValue = new CreateValue(); createValue.value = valueData.name; createValue.synonyms = valueData.synonyms.ToArray(); createValues.Add(createValue); } conversation.CreateEntity(HandleSuccessCallback, HandleFailCallback, workspace.WatsonConversationManager.WorkspaceId, localEntity.name, null, createValues.ToArray()); } }
public ValueResponse CreateValue(string workspaceId, string entity, CreateValue body) { if (string.IsNullOrEmpty(workspaceId)) { throw new ArgumentNullException(nameof(workspaceId)); } if (string.IsNullOrEmpty(entity)) { throw new ArgumentNullException(nameof(entity)); } if (body == null) { throw new ArgumentNullException(nameof(body)); } if (string.IsNullOrEmpty(VersionDate)) { throw new ArgumentNullException("versionDate cannot be null. Use 'CONVERSATION_VERSION_DATE_2017_05_26'"); } ValueResponse result = null; try { result = this.Client.WithAuthentication(this.UserName, this.Password) .PostAsync($"{this.Endpoint}/v1/workspaces/{workspaceId}/entities/{entity}/values") .WithArgument("version", VersionDate) .WithBody <CreateValue>(body) .As <ValueResponse>() .Result; } catch (AggregateException ae) { throw ae.Flatten(); } return(result); }
public override void Process(SyncQueue queue) { if (CreateConversation()) { // TODO: Would be better to update values individually instead of replacing all List <CreateValue> createValues = new List <CreateValue>(); foreach (EntityValueData valueData in localEntity.values) { CreateValue createValue = new CreateValue(); createValue.value = valueData.name; createValue.synonyms = valueData.synonyms.ToArray(); createValues.Add(createValue); } conversation.UpdateEntity(HandleSuccessCallback, HandleFailCallback, workspace.WatsonConversationManager.WorkspaceId, localEntity.name, null, createValues.ToArray()); } }
public override IEnumerator RunTest() { LogSystem.InstallDefaultReactors(); VcapCredentials vcapCredentials = new VcapCredentials(); fsData data = null; string result = null; string credentialsFilepath = "../sdk-credentials/credentials.json"; // Load credentials file if it exists. If it doesn't exist, don't run the tests. if (File.Exists(credentialsFilepath)) { result = File.ReadAllText(credentialsFilepath); } else { yield break; } // Add in a parent object because Unity does not like to deserialize root level collection types. result = Utility.AddTopLevelObjectToJson(result, "VCAP_SERVICES"); // Convert json to fsResult fsResult r = fsJsonParser.Parse(result, out data); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Convert fsResult to VcapCredentials object obj = vcapCredentials; r = _serializer.TryDeserialize(data, obj.GetType(), ref obj); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Set credentials from imported credntials Credential credential = vcapCredentials.GetCredentialByname("assistant-sdk")[0].Credentials; _username = credential.Username.ToString(); _password = credential.Password.ToString(); _url = credential.Url.ToString(); _workspaceId = credential.WorkspaceId.ToString(); // Create credential and instantiate service Credentials credentials = new Credentials(_username, _password, _url); _service = new Assistant(credentials); _service.VersionDate = _assistantVersionDate; // List Workspaces _service.ListWorkspaces(OnListWorkspaces, OnFail); while (!_listWorkspacesTested) { yield return(null); } // Create Workspace CreateWorkspace workspace = new CreateWorkspace() { Name = _createdWorkspaceName, Description = _createdWorkspaceDescription, Language = _createdWorkspaceLanguage, LearningOptOut = true }; _service.CreateWorkspace(OnCreateWorkspace, OnFail, workspace); while (!_createWorkspaceTested) { yield return(null); } // Get Workspace _service.GetWorkspace(OnGetWorkspace, OnFail, _createdWorkspaceId); while (!_getWorkspaceTested) { yield return(null); } // Update Workspace UpdateWorkspace updateWorkspace = new UpdateWorkspace() { Name = _createdWorkspaceName + "-updated", Description = _createdWorkspaceDescription + "-updated", Language = _createdWorkspaceLanguage }; _service.UpdateWorkspace(OnUpdateWorkspace, OnFail, _createdWorkspaceId, updateWorkspace); while (!_updateWorkspaceTested) { yield return(null); } // Message with customerID // Create customData object Dictionary <string, object> customData = new Dictionary <string, object>(); // Create a dictionary of custom headers Dictionary <string, string> customHeaders = new Dictionary <string, string>(); // Add to the header dictionary customHeaders.Add("X-Watson-Metadata", "customer_id=" + _unitySdkTestCustomerID); // Add the header dictionary to the custom data object customData.Add(Constants.String.CUSTOM_REQUEST_HEADERS, customHeaders); Dictionary <string, object> input = new Dictionary <string, object>(); input.Add("text", _inputString); MessageRequest messageRequest = new MessageRequest() { Input = input }; _service.Message(OnMessage, OnFail, _workspaceId, messageRequest, null, customData); while (!_messageTested) { yield return(null); } _messageTested = false; input["text"] = _conversationString0; MessageRequest messageRequest0 = new MessageRequest() { Input = input, Context = _context }; _service.Message(OnMessage, OnFail, _workspaceId, messageRequest0); while (!_messageTested) { yield return(null); } _messageTested = false; input["text"] = _conversationString1; MessageRequest messageRequest1 = new MessageRequest() { Input = input, Context = _context }; _service.Message(OnMessage, OnFail, _workspaceId, messageRequest1); while (!_messageTested) { yield return(null); } _messageTested = false; input["text"] = _conversationString2; MessageRequest messageRequest2 = new MessageRequest() { Input = input, Context = _context }; _service.Message(OnMessage, OnFail, _workspaceId, messageRequest2); while (!_messageTested) { yield return(null); } // List Intents _service.ListIntents(OnListIntents, OnFail, _createdWorkspaceId); while (!_listIntentsTested) { yield return(null); } // Create Intent CreateIntent createIntent = new CreateIntent() { Intent = _createdIntent, Description = _createdIntentDescription }; _service.CreateIntent(OnCreateIntent, OnFail, _createdWorkspaceId, createIntent); while (!_createIntentTested) { yield return(null); } // Get Intent _service.GetIntent(OnGetIntent, OnFail, _createdWorkspaceId, _createdIntent); while (!_getIntentTested) { yield return(null); } // Update Intents string updatedIntent = _createdIntent + "-updated"; string updatedIntentDescription = _createdIntentDescription + "-updated"; UpdateIntent updateIntent = new UpdateIntent() { Intent = updatedIntent, Description = updatedIntentDescription }; _service.UpdateIntent(OnUpdateIntent, OnFail, _createdWorkspaceId, _createdIntent, updateIntent); while (!_updateIntentTested) { yield return(null); } // List Examples _service.ListExamples(OnListExamples, OnFail, _createdWorkspaceId, updatedIntent); while (!_listExamplesTested) { yield return(null); } // Create Examples CreateExample createExample = new CreateExample() { Text = _createdExample }; _service.CreateExample(OnCreateExample, OnFail, _createdWorkspaceId, updatedIntent, createExample); while (!_createExampleTested) { yield return(null); } // Get Example _service.GetExample(OnGetExample, OnFail, _createdWorkspaceId, updatedIntent, _createdExample); while (!_getExampleTested) { yield return(null); } // Update Examples string updatedExample = _createdExample + "-updated"; UpdateExample updateExample = new UpdateExample() { Text = updatedExample }; _service.UpdateExample(OnUpdateExample, OnFail, _createdWorkspaceId, updatedIntent, _createdExample, updateExample); while (!_updateExampleTested) { yield return(null); } // List Entities _service.ListEntities(OnListEntities, OnFail, _createdWorkspaceId); while (!_listEntitiesTested) { yield return(null); } // Create Entities CreateEntity entity = new CreateEntity() { Entity = _createdEntity, Description = _createdEntityDescription }; _service.CreateEntity(OnCreateEntity, OnFail, _createdWorkspaceId, entity); while (!_createEntityTested) { yield return(null); } // Get Entity _service.GetEntity(OnGetEntity, OnFail, _createdWorkspaceId, _createdEntity); while (!_getEntityTested) { yield return(null); } // Update Entities string updatedEntity = _createdEntity + "-updated"; string updatedEntityDescription = _createdEntityDescription + "-updated"; UpdateEntity updateEntity = new UpdateEntity() { Entity = updatedEntity, Description = updatedEntityDescription }; _service.UpdateEntity(OnUpdateEntity, OnFail, _createdWorkspaceId, _createdEntity, updateEntity); while (!_updateEntityTested) { yield return(null); } // List Values _service.ListValues(OnListValues, OnFail, _createdWorkspaceId, updatedEntity); while (!_listValuesTested) { yield return(null); } // Create Values CreateValue value = new CreateValue() { Value = _createdValue }; _service.CreateValue(OnCreateValue, OnFail, _createdWorkspaceId, updatedEntity, value); while (!_createValueTested) { yield return(null); } // Get Value _service.GetValue(OnGetValue, OnFail, _createdWorkspaceId, updatedEntity, _createdValue); while (!_getValueTested) { yield return(null); } // Update Values string updatedValue = _createdValue + "-updated"; UpdateValue updateValue = new UpdateValue() { Value = updatedValue }; _service.UpdateValue(OnUpdateValue, OnFail, _createdWorkspaceId, updatedEntity, _createdValue, updateValue); while (!_updateValueTested) { yield return(null); } // List Synonyms _service.ListSynonyms(OnListSynonyms, OnFail, _createdWorkspaceId, updatedEntity, updatedValue); while (!_listSynonymsTested) { yield return(null); } // Create Synonyms CreateSynonym synonym = new CreateSynonym() { Synonym = _createdSynonym }; _service.CreateSynonym(OnCreateSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, synonym); while (!_createSynonymTested) { yield return(null); } // Get Synonym _service.GetSynonym(OnGetSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, _createdSynonym); while (!_getSynonymTested) { yield return(null); } // Update Synonyms string updatedSynonym = _createdSynonym + "-updated"; UpdateSynonym updateSynonym = new UpdateSynonym() { Synonym = updatedSynonym }; _service.UpdateSynonym(OnUpdateSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, _createdSynonym, updateSynonym); while (!_updateSynonymTested) { yield return(null); } // List Dialog Nodes _service.ListDialogNodes(OnListDialogNodes, OnFail, _createdWorkspaceId); while (!_listDialogNodesTested) { yield return(null); } // Create Dialog Nodes CreateDialogNode createDialogNode = new CreateDialogNode() { DialogNode = _dialogNodeName, Description = _dialogNodeDesc }; _service.CreateDialogNode(OnCreateDialogNode, OnFail, _createdWorkspaceId, createDialogNode); while (!_createDialogNodeTested) { yield return(null); } // Get Dialog Node _service.GetDialogNode(OnGetDialogNode, OnFail, _createdWorkspaceId, _dialogNodeName); while (!_getDialogNodeTested) { yield return(null); } // Update Dialog Nodes string updatedDialogNodeName = _dialogNodeName + "_updated"; string updatedDialogNodeDescription = _dialogNodeDesc + "_updated"; UpdateDialogNode updateDialogNode = new UpdateDialogNode() { DialogNode = updatedDialogNodeName, Description = updatedDialogNodeDescription }; _service.UpdateDialogNode(OnUpdateDialogNode, OnFail, _createdWorkspaceId, _dialogNodeName, updateDialogNode); while (!_updateDialogNodeTested) { yield return(null); } // List Logs In Workspace _service.ListLogs(OnListLogs, OnFail, _createdWorkspaceId); while (!_listLogsInWorkspaceTested) { yield return(null); } // List All Logs var filter = "(language::en,request.context.metadata.deployment::deployment_1)"; _service.ListAllLogs(OnListAllLogs, OnFail, filter); while (!_listAllLogsTested) { yield return(null); } // List Counterexamples _service.ListCounterexamples(OnListCounterexamples, OnFail, _createdWorkspaceId); while (!_listCounterexamplesTested) { yield return(null); } // Create Counterexamples CreateCounterexample example = new CreateCounterexample() { Text = _createdCounterExampleText }; _service.CreateCounterexample(OnCreateCounterexample, OnFail, _createdWorkspaceId, example); while (!_createCounterexampleTested) { yield return(null); } // Get Counterexample _service.GetCounterexample(OnGetCounterexample, OnFail, _createdWorkspaceId, _createdCounterExampleText); while (!_getCounterexampleTested) { yield return(null); } // Update Counterexamples string updatedCounterExampleText = _createdCounterExampleText + "-updated"; UpdateCounterexample updateCounterExample = new UpdateCounterexample() { Text = updatedCounterExampleText }; _service.UpdateCounterexample(OnUpdateCounterexample, OnFail, _createdWorkspaceId, _createdCounterExampleText, updateCounterExample); while (!_updateCounterexampleTested) { yield return(null); } // Delete Counterexample _service.DeleteCounterexample(OnDeleteCounterexample, OnFail, _createdWorkspaceId, updatedCounterExampleText); while (!_deleteCounterexampleTested) { yield return(null); } // Delete Dialog Node _service.DeleteDialogNode(OnDeleteDialogNode, OnFail, _createdWorkspaceId, updatedDialogNodeName); while (!_deleteDialogNodeTested) { yield return(null); } // Delete Synonym _service.DeleteSynonym(OnDeleteSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, updatedSynonym); while (!_deleteSynonymTested) { yield return(null); } // Delete Value _service.DeleteValue(OnDeleteValue, OnFail, _createdWorkspaceId, updatedEntity, updatedValue); while (!_deleteValueTested) { yield return(null); } // Delete Entity _service.DeleteEntity(OnDeleteEntity, OnFail, _createdWorkspaceId, updatedEntity); while (!_deleteEntityTested) { yield return(null); } // Delete Example _service.DeleteExample(OnDeleteExample, OnFail, _createdWorkspaceId, updatedIntent, updatedExample); while (!_deleteExampleTested) { yield return(null); } // Delete Intent _service.DeleteIntent(OnDeleteIntent, OnFail, _createdWorkspaceId, updatedIntent); while (!_deleteIntentTested) { yield return(null); } // Delete Workspace _service.DeleteWorkspace(OnDeleteWorkspace, OnFail, _createdWorkspaceId); while (!_deleteWorkspaceTested) { yield return(null); } // Delete User Data _service.DeleteUserData(OnDeleteUserData, OnFail, _unitySdkTestCustomerID); while (!_deleteUserDataTested) { yield return(null); } Log.Debug("TestAssistant.RunTest()", "Assistant examples complete."); yield break; }
private IEnumerator Examples() { // List Workspaces _service.ListWorkspaces(OnListWorkspaces, OnFail); while (!_listWorkspacesTested) { yield return(null); } // Create Workspace CreateWorkspace workspace = new CreateWorkspace() { Name = _createdWorkspaceName, Description = _createdWorkspaceDescription, Language = _createdWorkspaceLanguage, LearningOptOut = true }; _service.CreateWorkspace(OnCreateWorkspace, OnFail, workspace); while (!_createWorkspaceTested) { yield return(null); } // Get Workspace _service.GetWorkspace(OnGetWorkspace, OnFail, _createdWorkspaceId); while (!_getWorkspaceTested) { yield return(null); } // Update Workspace UpdateWorkspace updateWorkspace = new UpdateWorkspace() { Name = _createdWorkspaceName + "-updated", Description = _createdWorkspaceDescription + "-updated", Language = _createdWorkspaceLanguage }; _service.UpdateWorkspace(OnUpdateWorkspace, OnFail, _createdWorkspaceId, updateWorkspace); while (!_updateWorkspaceTested) { yield return(null); } // Message Dictionary <string, object> input = new Dictionary <string, object>(); input.Add("text", _inputString); MessageRequest messageRequest = new MessageRequest() { Input = input }; _service.Message(OnMessage, OnFail, _workspaceId, messageRequest); while (!_messageTested) { yield return(null); } _messageTested = false; input["text"] = _conversationString0; MessageRequest messageRequest0 = new MessageRequest() { Input = input, Context = _context }; _service.Message(OnMessage, OnFail, _workspaceId, messageRequest0); while (!_messageTested) { yield return(null); } _messageTested = false; input["text"] = _conversationString1; MessageRequest messageRequest1 = new MessageRequest() { Input = input, Context = _context }; _service.Message(OnMessage, OnFail, _workspaceId, messageRequest1); while (!_messageTested) { yield return(null); } _messageTested = false; input["text"] = _conversationString2; MessageRequest messageRequest2 = new MessageRequest() { Input = input, Context = _context }; _service.Message(OnMessage, OnFail, _workspaceId, messageRequest2); while (!_messageTested) { yield return(null); } // List Intents _service.ListIntents(OnListIntents, OnFail, _createdWorkspaceId); while (!_listIntentsTested) { yield return(null); } // Create Intent CreateIntent createIntent = new CreateIntent() { Intent = _createdIntent, Description = _createdIntentDescription }; _service.CreateIntent(OnCreateIntent, OnFail, _createdWorkspaceId, createIntent); while (!_createIntentTested) { yield return(null); } // Get Intent _service.GetIntent(OnGetIntent, OnFail, _createdWorkspaceId, _createdIntent); while (!_getIntentTested) { yield return(null); } // Update Intents string updatedIntent = _createdIntent + "-updated"; string updatedIntentDescription = _createdIntentDescription + "-updated"; UpdateIntent updateIntent = new UpdateIntent() { Intent = updatedIntent, Description = updatedIntentDescription }; _service.UpdateIntent(OnUpdateIntent, OnFail, _createdWorkspaceId, _createdIntent, updateIntent); while (!_updateIntentTested) { yield return(null); } // List Examples _service.ListExamples(OnListExamples, OnFail, _createdWorkspaceId, updatedIntent); while (!_listExamplesTested) { yield return(null); } // Create Examples CreateExample createExample = new CreateExample() { Text = _createdExample }; _service.CreateExample(OnCreateExample, OnFail, _createdWorkspaceId, updatedIntent, createExample); while (!_createExampleTested) { yield return(null); } // Get Example _service.GetExample(OnGetExample, OnFail, _createdWorkspaceId, updatedIntent, _createdExample); while (!_getExampleTested) { yield return(null); } // Update Examples string updatedExample = _createdExample + "-updated"; UpdateExample updateExample = new UpdateExample() { Text = updatedExample }; _service.UpdateExample(OnUpdateExample, OnFail, _createdWorkspaceId, updatedIntent, _createdExample, updateExample); while (!_updateExampleTested) { yield return(null); } // List Entities _service.ListEntities(OnListEntities, OnFail, _createdWorkspaceId); while (!_listEntitiesTested) { yield return(null); } // Create Entities CreateEntity entity = new CreateEntity() { Entity = _createdEntity, Description = _createdEntityDescription }; _service.CreateEntity(OnCreateEntity, OnFail, _createdWorkspaceId, entity); while (!_createEntityTested) { yield return(null); } // Get Entity _service.GetEntity(OnGetEntity, OnFail, _createdWorkspaceId, _createdEntity); while (!_getEntityTested) { yield return(null); } // Update Entities string updatedEntity = _createdEntity + "-updated"; string updatedEntityDescription = _createdEntityDescription + "-updated"; UpdateEntity updateEntity = new UpdateEntity() { Entity = updatedEntity, Description = updatedEntityDescription }; _service.UpdateEntity(OnUpdateEntity, OnFail, _createdWorkspaceId, _createdEntity, updateEntity); while (!_updateEntityTested) { yield return(null); } // List Values _service.ListValues(OnListValues, OnFail, _createdWorkspaceId, updatedEntity); while (!_listValuesTested) { yield return(null); } // Create Values CreateValue value = new CreateValue() { Value = _createdValue }; _service.CreateValue(OnCreateValue, OnFail, _createdWorkspaceId, updatedEntity, value); while (!_createValueTested) { yield return(null); } // Get Value _service.GetValue(OnGetValue, OnFail, _createdWorkspaceId, updatedEntity, _createdValue); while (!_getValueTested) { yield return(null); } // Update Values string updatedValue = _createdValue + "-updated"; UpdateValue updateValue = new UpdateValue() { Value = updatedValue }; _service.UpdateValue(OnUpdateValue, OnFail, _createdWorkspaceId, updatedEntity, _createdValue, updateValue); while (!_updateValueTested) { yield return(null); } // List Synonyms _service.ListSynonyms(OnListSynonyms, OnFail, _createdWorkspaceId, updatedEntity, updatedValue); while (!_listSynonymsTested) { yield return(null); } // Create Synonyms CreateSynonym synonym = new CreateSynonym() { Synonym = _createdSynonym }; _service.CreateSynonym(OnCreateSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, synonym); while (!_createSynonymTested) { yield return(null); } // Get Synonym _service.GetSynonym(OnGetSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, _createdSynonym); while (!_getSynonymTested) { yield return(null); } // Update Synonyms string updatedSynonym = _createdSynonym + "-updated"; UpdateSynonym updateSynonym = new UpdateSynonym() { Synonym = updatedSynonym }; _service.UpdateSynonym(OnUpdateSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, _createdSynonym, updateSynonym); while (!_updateSynonymTested) { yield return(null); } // List Dialog Nodes _service.ListDialogNodes(OnListDialogNodes, OnFail, _createdWorkspaceId); while (!_listDialogNodesTested) { yield return(null); } // Create Dialog Nodes CreateDialogNode createDialogNode = new CreateDialogNode() { DialogNode = _dialogNodeName, Description = _dialogNodeDesc }; _service.CreateDialogNode(OnCreateDialogNode, OnFail, _createdWorkspaceId, createDialogNode); while (!_createDialogNodeTested) { yield return(null); } // Get Dialog Node _service.GetDialogNode(OnGetDialogNode, OnFail, _createdWorkspaceId, _dialogNodeName); while (!_getDialogNodeTested) { yield return(null); } // Update Dialog Nodes string updatedDialogNodeName = _dialogNodeName + "_updated"; string updatedDialogNodeDescription = _dialogNodeDesc + "_updated"; UpdateDialogNode updateDialogNode = new UpdateDialogNode() { DialogNode = updatedDialogNodeName, Description = updatedDialogNodeDescription }; _service.UpdateDialogNode(OnUpdateDialogNode, OnFail, _createdWorkspaceId, _dialogNodeName, updateDialogNode); while (!_updateDialogNodeTested) { yield return(null); } // List Logs In Workspace _service.ListLogs(OnListLogs, OnFail, _createdWorkspaceId); while (!_listLogsInWorkspaceTested) { yield return(null); } // List All Logs var filter = "(language::en,request.context.metadata.deployment::deployment_1)"; _service.ListAllLogs(OnListAllLogs, OnFail, filter); while (!_listAllLogsTested) { yield return(null); } // List Counterexamples _service.ListCounterexamples(OnListCounterexamples, OnFail, _createdWorkspaceId); while (!_listCounterexamplesTested) { yield return(null); } // Create Counterexamples CreateCounterexample example = new CreateCounterexample() { Text = _createdCounterExampleText }; _service.CreateCounterexample(OnCreateCounterexample, OnFail, _createdWorkspaceId, example); while (!_createCounterexampleTested) { yield return(null); } // Get Counterexample _service.GetCounterexample(OnGetCounterexample, OnFail, _createdWorkspaceId, _createdCounterExampleText); while (!_getCounterexampleTested) { yield return(null); } // Update Counterexamples string updatedCounterExampleText = _createdCounterExampleText + "-updated"; UpdateCounterexample updateCounterExample = new UpdateCounterexample() { Text = updatedCounterExampleText }; _service.UpdateCounterexample(OnUpdateCounterexample, OnFail, _createdWorkspaceId, _createdCounterExampleText, updateCounterExample); while (!_updateCounterexampleTested) { yield return(null); } // Delete Counterexample _service.DeleteCounterexample(OnDeleteCounterexample, OnFail, _createdWorkspaceId, updatedCounterExampleText); while (!_deleteCounterexampleTested) { yield return(null); } // Delete Dialog Node _service.DeleteDialogNode(OnDeleteDialogNode, OnFail, _createdWorkspaceId, updatedDialogNodeName); while (!_deleteDialogNodeTested) { yield return(null); } // Delete Synonym _service.DeleteSynonym(OnDeleteSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, updatedSynonym); while (!_deleteSynonymTested) { yield return(null); } // Delete Value _service.DeleteValue(OnDeleteValue, OnFail, _createdWorkspaceId, updatedEntity, updatedValue); while (!_deleteValueTested) { yield return(null); } // Delete Entity _service.DeleteEntity(OnDeleteEntity, OnFail, _createdWorkspaceId, updatedEntity); while (!_deleteEntityTested) { yield return(null); } // Delete Example _service.DeleteExample(OnDeleteExample, OnFail, _createdWorkspaceId, updatedIntent, updatedExample); while (!_deleteExampleTested) { yield return(null); } // Delete Intent _service.DeleteIntent(OnDeleteIntent, OnFail, _createdWorkspaceId, updatedIntent); while (!_deleteIntentTested) { yield return(null); } // Delete Workspace _service.DeleteWorkspace(OnDeleteWorkspace, OnFail, _createdWorkspaceId); while (!_deleteWorkspaceTested) { yield return(null); } Log.Debug("TestAssistant.RunTest()", "Assistant examples complete."); yield break; }
public DataSource(bool buffor, BuiltInType type, string name, Simulator queue, TimeSpan cycle) : base(queue, cycle) { m_name = name; m_CanonicalType = TypeInfo.GetSystemType(type, ValueRanks.OneDimension); m_LastValue = null;//TODO TypeInfo.GetDefaultValue( type ); m_BuiltInType = type; if (buffor) { m_ValueGenerator = new CreateValue(GetFromBuffer); } else { switch (type) { case BuiltInType.Boolean: m_ValueGenerator = new CreateValue(CreateBoolean); break; case BuiltInType.Double: m_ValueGenerator = new CreateValue(CreateDouble); break; case BuiltInType.Int32: m_ValueGenerator = new CreateValue(CreateInt32); break; case BuiltInType.Byte: m_ValueGenerator = new CreateValue(CreateByte); break; case BuiltInType.ByteString: m_ValueGenerator = new CreateValue(CreateByteString); break;//TODO it must be implemented //case BuiltInType.DataValue: // m_ValueGenerator = new CreateValue( CreateDataValue ); // break; case BuiltInType.DateTime: m_ValueGenerator = new CreateValue(CreateDateTime); break;//TODO it must be implemented //case BuiltInType.DiagnosticInfo: // m_ValueGenerator = new CreateValue( CreateDiagnosticInfo ); // break; case BuiltInType.Enumeration: m_ValueGenerator = new CreateValue(CreateEnumeration); break;//TODO it must be implemented //case BuiltInType.ExpandedNodeId: // m_ValueGenerator = new CreateValue( CreateExpandedNodeId ); // break; case BuiltInType.ExtensionObject: m_ValueGenerator = new CreateValue(CreateExtensionObject); break; case BuiltInType.Float: m_ValueGenerator = new CreateValue(CreateFloat); break; case BuiltInType.Guid: m_ValueGenerator = new CreateValue(CreateGuid); break; case BuiltInType.Int16: m_ValueGenerator = new CreateValue(CreateInt16); break; case BuiltInType.Int64: m_ValueGenerator = new CreateValue(CreateInt64); break; case BuiltInType.Integer: m_ValueGenerator = new CreateValue(CreateInteger); break; case BuiltInType.LocalizedText: m_ValueGenerator = new CreateValue(CreateLocalizedText); break;//TODO it must be implemented //case BuiltInType.NodeId: // m_ValueGenerator = new CreateValue( CreateNodeId ); // break; case BuiltInType.Null: m_ValueGenerator = new CreateValue(CreateDouble); //TODO Should be proper value break; case BuiltInType.Number: m_ValueGenerator = new CreateValue(CreateNumber); break; case BuiltInType.QualifiedName: m_ValueGenerator = new CreateValue(CreateQualifiedName); break; case BuiltInType.SByte: m_ValueGenerator = new CreateValue(CreateSByte); break;//TODO it must be implemented //case BuiltInType.StatusCode: // m_ValueGenerator = new CreateValue( CreateStatusCode ); // break; case BuiltInType.String: m_ValueGenerator = new CreateValue(CreateString); break; case BuiltInType.UInt16: m_ValueGenerator = new CreateValue(CreateUInt16); break; case BuiltInType.UInt32: m_ValueGenerator = new CreateValue(CreateUInt32); break; case BuiltInType.UInt64: m_ValueGenerator = new CreateValue(CreateUInt64); break; case BuiltInType.UInteger: m_ValueGenerator = new CreateValue(CreateUInteger); break; case BuiltInType.Variant: m_ValueGenerator = new CreateValue(CreateVariant); break; case BuiltInType.XmlElement: m_ValueGenerator = new CreateValue(CreateXmlElement); break; default: // switch off for unknown types; this.Cycle = TimeSpan.MaxValue; break; } } }
public override IEnumerator RunTest() { LogSystem.InstallDefaultReactors(); VcapCredentials vcapCredentials = new VcapCredentials(); fsData data = null; string result = null; var vcapUrl = Environment.GetEnvironmentVariable("VCAP_URL"); var vcapUsername = Environment.GetEnvironmentVariable("VCAP_USERNAME"); var vcapPassword = Environment.GetEnvironmentVariable("VCAP_PASSWORD"); using (SimpleGet simpleGet = new SimpleGet(vcapUrl, vcapUsername, vcapPassword)) { while (!simpleGet.IsComplete) { yield return(null); } result = simpleGet.Result; } // Add in a parent object because Unity does not like to deserialize root level collection types. result = Utility.AddTopLevelObjectToJson(result, "VCAP_SERVICES"); // Convert json to fsResult fsResult r = fsJsonParser.Parse(result, out data); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Convert fsResult to VcapCredentials object obj = vcapCredentials; r = _serializer.TryDeserialize(data, obj.GetType(), ref obj); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Set credentials from imported credntials Credential credential = vcapCredentials.VCAP_SERVICES["conversation"]; _username = credential.Username.ToString(); _password = credential.Password.ToString(); _url = credential.Url.ToString(); //_workspaceId = credential.WorkspaceId.ToString(); // Create credential and instantiate service Credentials credentials = new Credentials(_username, _password, _url); _service = new Assistant(credentials); _service.VersionDate = _assistantVersionDate; // List Workspaces _service.ListWorkspaces(OnListWorkspaces, OnFail); while (!_listWorkspacesTested) { yield return(null); } // Create Workspace CreateWorkspace workspace = new CreateWorkspace() { Name = _createdWorkspaceName, Description = _createdWorkspaceDescription, Language = _createdWorkspaceLanguage, LearningOptOut = true }; _service.CreateWorkspace(OnCreateWorkspace, OnFail, workspace); while (!_createWorkspaceTested) { yield return(null); } // Get Workspace _service.GetWorkspace(OnGetWorkspace, OnFail, _createdWorkspaceId); while (!_getWorkspaceTested) { yield return(null); } // Update Workspace UpdateWorkspace updateWorkspace = new UpdateWorkspace() { Name = _createdWorkspaceName + "-updated", Description = _createdWorkspaceDescription + "-updated", Language = _createdWorkspaceLanguage }; _service.UpdateWorkspace(OnUpdateWorkspace, OnFail, _createdWorkspaceId, updateWorkspace); while (!_updateWorkspaceTested) { yield return(null); } // Message Dictionary <string, object> input = new Dictionary <string, object>(); input.Add("text", _inputString); MessageRequest messageRequest = new MessageRequest() { Input = input, AlternateIntents = true }; _service.Message(OnMessage, OnFail, _workspaceId, messageRequest); while (!_messageTested) { yield return(null); } // List Intents _service.ListIntents(OnListIntents, OnFail, _createdWorkspaceId); while (!_listIntentsTested) { yield return(null); } // Create Intent CreateIntent createIntent = new CreateIntent() { Intent = _createdIntent, Description = _createdIntentDescription }; _service.CreateIntent(OnCreateIntent, OnFail, _createdWorkspaceId, createIntent); while (!_createIntentTested) { yield return(null); } // Get Intent _service.GetIntent(OnGetIntent, OnFail, _createdWorkspaceId, _createdIntent); while (!_getIntentTested) { yield return(null); } // Update Intents string updatedIntent = _createdIntent + "-updated"; string updatedIntentDescription = _createdIntentDescription + "-updated"; UpdateIntent updateIntent = new UpdateIntent() { Intent = updatedIntent, Description = updatedIntentDescription }; _service.UpdateIntent(OnUpdateIntent, OnFail, _createdWorkspaceId, _createdIntent, updateIntent); while (!_updateIntentTested) { yield return(null); } // List Examples _service.ListExamples(OnListExamples, OnFail, _createdWorkspaceId, updatedIntent); while (!_listExamplesTested) { yield return(null); } // Create Examples CreateExample createExample = new CreateExample() { Text = _createdExample }; _service.CreateExample(OnCreateExample, OnFail, _createdWorkspaceId, updatedIntent, createExample); while (!_createExampleTested) { yield return(null); } // Get Example _service.GetExample(OnGetExample, OnFail, _createdWorkspaceId, updatedIntent, _createdExample); while (!_getExampleTested) { yield return(null); } // Update Examples string updatedExample = _createdExample + "-updated"; UpdateExample updateExample = new UpdateExample() { Text = updatedExample }; _service.UpdateExample(OnUpdateExample, OnFail, _createdWorkspaceId, updatedIntent, _createdExample, updateExample); while (!_updateExampleTested) { yield return(null); } // List Entities _service.ListEntities(OnListEntities, OnFail, _createdWorkspaceId); while (!_listEntitiesTested) { yield return(null); } // Create Entities CreateEntity entity = new CreateEntity() { Entity = _createdEntity, Description = _createdEntityDescription }; _service.CreateEntity(OnCreateEntity, OnFail, _createdWorkspaceId, entity); while (!_createEntityTested) { yield return(null); } // Get Entity _service.GetEntity(OnGetEntity, OnFail, _createdWorkspaceId, _createdEntity); while (!_getEntityTested) { yield return(null); } // Update Entities string updatedEntity = _createdEntity + "-updated"; string updatedEntityDescription = _createdEntityDescription + "-updated"; UpdateEntity updateEntity = new UpdateEntity() { Entity = updatedEntity, Description = updatedEntityDescription }; _service.UpdateEntity(OnUpdateEntity, OnFail, _createdWorkspaceId, _createdEntity, updateEntity); while (!_updateEntityTested) { yield return(null); } // List Values _service.ListValues(OnListValues, OnFail, _createdWorkspaceId, updatedEntity); while (!_listValuesTested) { yield return(null); } // Create Values CreateValue value = new CreateValue() { Value = _createdValue }; _service.CreateValue(OnCreateValue, OnFail, _createdWorkspaceId, updatedEntity, value); while (!_createValueTested) { yield return(null); } // Get Value _service.GetValue(OnGetValue, OnFail, _createdWorkspaceId, updatedEntity, _createdValue); while (!_getValueTested) { yield return(null); } // Update Values string updatedValue = _createdValue + "-updated"; UpdateValue updateValue = new UpdateValue() { Value = updatedValue }; _service.UpdateValue(OnUpdateValue, OnFail, _createdWorkspaceId, updatedEntity, _createdValue, updateValue); while (!_updateValueTested) { yield return(null); } // List Synonyms _service.ListSynonyms(OnListSynonyms, OnFail, _createdWorkspaceId, updatedEntity, updatedValue); while (!_listSynonymsTested) { yield return(null); } // Create Synonyms CreateSynonym synonym = new CreateSynonym() { Synonym = _createdSynonym }; _service.CreateSynonym(OnCreateSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, synonym); while (!_createSynonymTested) { yield return(null); } // Get Synonym _service.GetSynonym(OnGetSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, _createdSynonym); while (!_getSynonymTested) { yield return(null); } // Update Synonyms string updatedSynonym = _createdSynonym + "-updated"; UpdateSynonym updateSynonym = new UpdateSynonym() { Synonym = updatedSynonym }; _service.UpdateSynonym(OnUpdateSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, _createdSynonym, updateSynonym); while (!_updateSynonymTested) { yield return(null); } // List Dialog Nodes _service.ListDialogNodes(OnListDialogNodes, OnFail, _createdWorkspaceId); while (!_listDialogNodesTested) { yield return(null); } // Create Dialog Nodes CreateDialogNode createDialogNode = new CreateDialogNode() { DialogNode = _dialogNodeName, Description = _dialogNodeDesc }; _service.CreateDialogNode(OnCreateDialogNode, OnFail, _createdWorkspaceId, createDialogNode); while (!_createDialogNodeTested) { yield return(null); } // Get Dialog Node _service.GetDialogNode(OnGetDialogNode, OnFail, _createdWorkspaceId, _dialogNodeName); while (!_getDialogNodeTested) { yield return(null); } // Update Dialog Nodes string updatedDialogNodeName = _dialogNodeName + "_updated"; string updatedDialogNodeDescription = _dialogNodeDesc + "_updated"; UpdateDialogNode updateDialogNode = new UpdateDialogNode() { DialogNode = updatedDialogNodeName, Description = updatedDialogNodeDescription }; _service.UpdateDialogNode(OnUpdateDialogNode, OnFail, _createdWorkspaceId, _dialogNodeName, updateDialogNode); while (!_updateDialogNodeTested) { yield return(null); } // List Logs In Workspace _service.ListLogs(OnListLogs, OnFail, _createdWorkspaceId); while (!_listLogsInWorkspaceTested) { yield return(null); } // List All Logs var filter = "(language::en,request.context.metadata.deployment::deployment_1)"; _service.ListAllLogs(OnListAllLogs, OnFail, filter); while (!_listAllLogsTested) { yield return(null); } // List Counterexamples _service.ListCounterexamples(OnListCounterexamples, OnFail, _createdWorkspaceId); while (!_listCounterexamplesTested) { yield return(null); } // Create Counterexamples CreateCounterexample example = new CreateCounterexample() { Text = _createdCounterExampleText }; _service.CreateCounterexample(OnCreateCounterexample, OnFail, _createdWorkspaceId, example); while (!_createCounterexampleTested) { yield return(null); } // Get Counterexample _service.GetCounterexample(OnGetCounterexample, OnFail, _createdWorkspaceId, _createdCounterExampleText); while (!_getCounterexampleTested) { yield return(null); } // Update Counterexamples string updatedCounterExampleText = _createdCounterExampleText + "-updated"; UpdateCounterexample updateCounterExample = new UpdateCounterexample() { Text = updatedCounterExampleText }; _service.UpdateCounterexample(OnUpdateCounterexample, OnFail, _createdWorkspaceId, _createdCounterExampleText, updateCounterExample); while (!_updateCounterexampleTested) { yield return(null); } // Delete Counterexample _service.DeleteCounterexample(OnDeleteCounterexample, OnFail, _createdWorkspaceId, updatedCounterExampleText); while (!_deleteCounterexampleTested) { yield return(null); } // Delete Dialog Node _service.DeleteDialogNode(OnDeleteDialogNode, OnFail, _createdWorkspaceId, updatedDialogNodeName); while (!_deleteDialogNodeTested) { yield return(null); } // Delete Synonym _service.DeleteSynonym(OnDeleteSynonym, OnFail, _createdWorkspaceId, updatedEntity, updatedValue, updatedSynonym); while (!_deleteSynonymTested) { yield return(null); } // Delete Value _service.DeleteValue(OnDeleteValue, OnFail, _createdWorkspaceId, updatedEntity, updatedValue); while (!_deleteValueTested) { yield return(null); } // Delete Entity _service.DeleteEntity(OnDeleteEntity, OnFail, _createdWorkspaceId, updatedEntity); while (!_deleteEntityTested) { yield return(null); } // Delete Example _service.DeleteExample(OnDeleteExample, OnFail, _createdWorkspaceId, updatedIntent, updatedExample); while (!_deleteExampleTested) { yield return(null); } // Delete Intent _service.DeleteIntent(OnDeleteIntent, OnFail, _createdWorkspaceId, updatedIntent); while (!_deleteIntentTested) { yield return(null); } // Delete Workspace _service.DeleteWorkspace(OnDeleteWorkspace, OnFail, _createdWorkspaceId); while (!_deleteWorkspaceTested) { yield return(null); } Log.Debug("TestAssistant.RunTest()", "Assistant examples complete."); yield break; }
public TValue GetOrCreateAndSave(TKey key, CreateValue <TValue> createValue) { return(this.GetOrCreateAndSave(key, 0, createValue)); }