public void Success() { Console.WriteLine("Success Start"); var JsonString = File.ReadAllText("../../../Files/TrainSuccess.txt"); var Client = MockGenerator.MockRestClient <ModelResponse>(HttpStatusCode.OK, JsonString); HacarusVisualInspection VisualInspection = new HacarusVisualInspection(Client); ModelResponse Response = VisualInspection.Train("OC", "6/11/19 10:26:07 AM", new string[] { "iItemID" }, new AlgorithmParameter[] { }); Assert.IsNotNull(Response); Assert.IsNotNull(Response.HttpResponse); Assert.IsNotNull(Response.Data); Assert.IsNull(Response.Errors); Assert.IsTrue(Response.HttpResponse.StatusCode.Equals(HttpStatusCode.OK)); Assert.IsFalse(Response.Data.Active); Assert.IsTrue(Response.Data.AlgorithmId.Equals("OC")); Assert.IsFalse(Response.Data.ContextDefault); Assert.IsTrue(Response.Data.ContextId.Equals(1000)); Assert.IsTrue(Response.Data.CreatedAt.Equals(DateTime.Parse("2019-06-11T01:26:08Z").ToUniversalTime())); Assert.IsTrue(Response.Data.ModelId.Equals(270)); Assert.IsTrue(Response.Data.Name.Equals("6/11/19 10:26:07 AM")); Assert.IsTrue(Response.Data.Status.Equals("creating")); Assert.IsTrue(Response.Data.UpdatedAt.Equals(DateTime.Parse("2019-06-11T10:26:07Z").ToUniversalTime())); Assert.IsTrue(Response.Data.Version.Equals("model-2019061101:26:07")); Console.WriteLine("Success End"); }
/// <summary> /// Downloads the specified resource as a byte array /// object /// </summary> /// <param name="urlBase">Main resource address</param> /// <param name="method">Method resource address part</param> /// <returns>DownloadFile</returns> public async Task <ModelResponse <RawBytes> > Download(string urlBase, string method) { //Verify http request integrity if (!urlBase.IsWebDirectory(out Uri uri) || method.IsNotValid()) { return(new ModelResponse <RawBytes>(false, @"The supplied address is not valid for request operation.")); } ModelResponse <RawBytes> response; try { using (WebClient client = new WebClient()) { Uri url = new Uri(urlBase + method); AddHeaders(client); response = new ModelResponse <RawBytes>(new RawBytes(await client.DownloadDataTaskAsync(url))); client.Dispose(); } } catch (Exception ex) { response = new ModelResponse <RawBytes>(ex); } return(response); }
public async Task GetFirstWithColumns() { ModelResponse <TestingEntity> result = await DataProvider.GetFirst(11, new string[1] { @"Id" }); Assert.True(result.Correct); }
public async Task ResultTableHtmlTable() { SqlServerCommand command = new SqlServerCommand(ConnectionString); ModelResponse <List <ResultTable> > result = await command.Query(@"SELECT Name = 'Israel', Age=27;"); string table = GridBuilder.HtmlTable(result.Model.ElementAt(0)); Assert.True(result.Correct && !table.IsNotValid()); }
public void ApplyModelDiff(SimulationModel model, ModelResponse diff) { if (!DiffsApplied.ContainsKey(model)) { DiffsApplied[model] = 0; } DiffsApplied[model]++; }
private static VectorOffset?BuildRemovedRegions(IList <RegionModel> removedRegions, FlatBufferBuilder builder) { if (removedRegions == null) { return(null); } return(ModelResponse.CreateRemovedRegionsVector(builder, removedRegions.Select(region => region.Index).ToArray())); }
public async Task Download() { string url = @"https://www.google.com"; string method = @"/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"; HttpRequest http = new HttpRequest(); ModelResponse <RawBytes> content = await http.Download(url, method); Assert.True(content.Correct); }
private void ApplyModelDiff(ModelResponse diff) { if (diff.IsFull) { m_model = new SimulationModel(); } m_modelDiffApplier.ApplyModelDiff(m_model, diff); }
public async Task GetFirstByConditions() { List <QueryCondition <TestingEntity> > conditions = new List <QueryCondition <TestingEntity> >(1) { new QueryCondition <TestingEntity>(e => e.Id, QueryOperator.Equal, 1052) }; ModelResponse <TestingEntity> result = await DataProvider.GetFirst(conditions); Assert.True(result.Correct); }
public static object ServiceResponse(string pageCode, ModelResponse mr, object resources = null) { object response = null; switch (mr.Status) { case ResponseStatus.Success: //HTTP Status Code: 200 HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.OK; response = resources == null ? mr.Data : new { data = mr.Data, res = resources }; break; case ResponseStatus.ValidationError: //HTTP Status Code: 400 (will be simulated client-side in [lmis.js] due to production environment issues) HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.OK; var prefix = (mr.ErrorId < 100) ? pageCode : "X"; response = new { mr.ErrorId, Message = (String)HttpContext.GetGlobalResourceObject("MessagesResource", prefix + "_Error" + mr.ErrorId) }; break; case ResponseStatus.InRelation: response = new { mr.ErrorId, Message = (String)HttpContext.GetGlobalResourceObject("MessagesResource", "X_Error103_InRelation") }; break; case ResponseStatus.Exist: response = new { mr.ErrorId, Message = (string)HttpContext.GetGlobalResourceObject("MessagesResource", "W001_RegisteredEmail") }; break; case ResponseStatus.Exception: //HTTP Status Code: 500 #if DEBUG //ExceptionDispatchInfo.Capture(mr.Exception.GetBaseException()).Throw(); #else // ExceptionDispatchInfo.Capture(mr.Exception).Throw(); #endif break; } return(response); }
private static VectorOffset?BuildRemovedSynapses(IList <SynapseModel> removedSynapses, FlatBufferBuilder builder) { Offset <Synapse>[] removedSynapsesOffsets = BuildSynapseOffsets(removedSynapses, builder); if (removedSynapsesOffsets == null) { return(null); } return(ModelResponse.CreateRemovedSynapsesVector(builder, removedSynapsesOffsets)); }
private static VectorOffset?BuildAddedRegions(IList <RegionModel> addedRegions, FlatBufferBuilder builder) { var addedRegionsOffsets = BuildRegionsOffsets(addedRegions, builder); if (addedRegionsOffsets == null) { return(null); } return(ModelResponse.CreateAddedRegionsVector(builder, addedRegionsOffsets)); }
/// <summary> /// Retrieves the first entity that /// compels to the supplied conditions and /// includes the specified columns during /// selection /// </summary> /// <param name="conditions">Query Conditions</param> /// <param name="columns">Columns to include</param> /// <returns>ComplexReponse T</returns> public async Task <ModelResponse <T> > GetFirst(List <QueryCondition <T> > conditions, string[] columns = null) { //Verify select columns if (columns.IsNotValid()) { columns = Columns; } //Verify integrity Columns (All the supplied columns must exists inside the current entity) if (!columns.ToList().TrueForAll(Columns.Contains)) { return(new ModelResponse <T>(false, @"The supplied columns does not exist in the current entity.")); } //Inicialize query conditions if (conditions.IsNotValid()) { conditions = new List <QueryCondition <T> >(); } else { //Validate query conditions integrity (All the supplied property-column query condition reference must exists inside the current entity) if (!conditions.Select(c => c.Property).ToList().TrueForAll(columns.Contains)) { return(new ModelResponse <T>(false, @"The supplied columns does not exist in the current entity.")); } } ModelResponse <T> response; try { SqlServerCommand command = new SqlServerCommand(ConnectionString); //Get the user supplied conditions string userSqlConditions = conditions.ToSqlQuery(out SqlParameter[] parameters); string sql = $@"Select Top 1 [{string.Join(@"], [", columns)}] From [dbo].[{TableName}] Where {userSqlConditions} And ([Deleted] Is Null);"; ModelResponse <List <ResultTable> > commandResult = await command.Query(sql, parameters); if (commandResult.Correct) { T model = commandResult.Model .FirstOrDefault() .Rows.ElementAt(0) .ToEntity <T>(); response = new ModelResponse <T>(model); } else { response = new ModelResponse <T>(false, commandResult.Message); } } catch (Exception ex) { response = new ModelResponse <T>(ex); } return(response); }
private static VectorOffset?BuildObservers(IList <ObserverDataContainer> observers, FlatBufferBuilder builder) { Offset <ObserverResult>[] observersOffsets = BuildOffsets(observers, observer => BuildObserverOffset(builder, observer)); if (observersOffsets == null) { return(null); } return(ModelResponse.CreateObserverResultsVector(builder, observersOffsets)); }
private static VectorOffset?BuildSpikedSynapses(IList <SynapseModel> spikedSynapses, FlatBufferBuilder builder) { Offset <Synapse>[] spikedSynapsesOffsets = BuildSynapseOffsets(spikedSynapses, builder); if (spikedSynapsesOffsets == null) { return(null); } return(ModelResponse.CreateSpikedSynapsesVector(builder, spikedSynapsesOffsets)); }
private static VectorOffset?BuildRemovedNeurons(IList <NeuronModel> removedNeurons, FlatBufferBuilder builder) { Offset <NeuronId>[] removedNeuronsOffsets = BuildOffsets(removedNeurons, neuron => NeuronId.CreateNeuronId(builder, neuron.Index, neuron.RegionModel.Index)); if (removedNeuronsOffsets == null) { return(null); } return(ModelResponse.CreateRemovedNeuronsVector(builder, removedNeuronsOffsets)); }
private static VectorOffset?BuildRepositionedNeurons(IList <NeuronModel> repositionedNeurons, FlatBufferBuilder builder) { Offset <Neuron>[] repositionedNeuronsOffsets = BuildNeuronOffsets(repositionedNeurons, builder); if (repositionedNeuronsOffsets == null) { return(null); } return(ModelResponse.CreateRepositionedNeuronsVector(builder, repositionedNeuronsOffsets)); }
private Task ApplyModelDiffAsync(ModelResponse diff) { return(Task.Factory.StartNew(() => { if (diff.IsFull) { m_currentModel = new SimulationModel(); } m_modelDiffApplier.ApplyModelDiff(m_currentModel, diff); })); }
public static bool RemoveOnlyFromModelPayload(string id) { bool result = false; ModelResponse _data = new ModelResponse(); foreach (var item in GlobalStorage.DataStorage) { GlobalStorage.ModelStorage.TryRemove(id, out _data); result = true; } return(result); }
public async Task GetRecordsByConditions() { List <QueryCondition <TestingEntity> > conditions = new List <QueryCondition <TestingEntity> >() { new QueryCondition <TestingEntity>(e => e.Id, QueryOperator.In, new long[2] { 1052, 1053 }), }; Pagination page = new Pagination(); ModelResponse <PaginatedCollection <TestingEntity> > result = await DataProvider.GetRecords(page, conditions : conditions); Assert.True(result.Correct); }
public static object PostUpdates(IndividualVM individualObject) { try { individualObject.UserID = Utils.LoggedUser.UserId; var mr = individualManager.UpdatePersonalInfo(individualObject); return(Utils.ServiceResponse(pageCode, mr)); } catch (Exception ex) { ModelResponse mr = new ModelResponse(new Exception(ex.Message)); return(Utils.ServiceResponse(pageCode, mr)); } }
public void ModelResponse_WhenCreated_CreateBody() { // Create a test model var model = new User { Name = "Test" }; // Create the new response var response = new ModelResponse <User>("User created", model); // Check the result Assert.That(response.Response.Message, Is.EqualTo("User created")); Assert.That(response.Response.Data, Is.EqualTo(model)); }
private void ApplyAddedSynapses(SimulationModel model, ModelResponse diff) { for (int i = 0; i < diff.AddedSynapsesLength; i++) { Synapse addedSynapse = diff.GetAddedSynapses(i); ProcessSynapse(model, addedSynapse, "add", (fromRegion, fromNeuron, toRegion, toNeuron) => { var synapseModel = new SynapseModel(fromRegion, fromNeuron, toRegion, toNeuron); fromNeuron.Outputs[synapseModel.ToNeuron.Index] = synapseModel; fromRegion.AddSynapse(synapseModel); toNeuron.Inputs[synapseModel.FromNeuron.Index] = synapseModel; }); } }
private void ApplyAddedConnections(SimulationModel model, ModelResponse diff) { for (int i = 0; i < diff.AddedConnectionsLength; i++) { Connection addedConnection = diff.GetAddedConnections(i); ProcessConnection(model, addedConnection, "add", (fromConnector, toConnector) => { var connectionModel = new ConnectionModel(fromConnector, toConnector); model.Connections.AddChild(connectionModel); }); } }
private void ApplyRemovedSynapses(SimulationModel model, ModelResponse diff) { for (int i = 0; i < diff.RemovedSynapsesLength; i++) { var synapse = diff.GetRemovedSynapses(i); ProcessSynapse(model, synapse, "remove", (fromRegion, fromNeuron, toRegion, toNeuron) => { var synapseModel = fromNeuron.Outputs[toNeuron.Index]; fromNeuron.Outputs.Remove(toNeuron.Index); fromRegion.Synapses.Remove(synapseModel); toNeuron.Inputs.Remove(fromNeuron.Index); }); } }
public async Task <ModelResponse> UserAuthenticationAsync(string UserLoginId, string UserPassword) { ModelResponse objModelResponse = new ModelResponse(); await Task.Delay(100); var objUser = _userList.Where(rec => rec.UserLoginId == UserLoginId && rec.UserPassword == UserPassword).FirstOrDefault(); if (objUser != null) { objModelResponse.Status = true; objModelResponse.ReturnObj = objUser; } return(objModelResponse); }
private void ApplyRemovedRegions(SimulationModel model, ModelResponse diff) { for (int i = 0; i < diff.RemovedRegionsLength; i++) { uint regionIndex = diff.GetRemovedRegions(i); if (!model.Regions.ContainsKey(regionIndex)) { Log.Warn("Cannot remove region with index {regionIndex}, region not found", regionIndex); continue; } model.Regions.Remove(regionIndex); } }
private static void ApplyAddedRegions(SimulationModel model, ModelResponse diff) { for (int i = 0; i < diff.AddedRegionsLength; i++) { Region addedRegion = diff.GetAddedRegions(i); Vector3 lower = addedRegion.Position.ToVector3(); Vector3 size = addedRegion.Size.ToVector3(); Vector3 position = lower + size / 2; model.Regions[addedRegion.Index] = new RegionModel(addedRegion.Index, addedRegion.Name, addedRegion.Type, position, size); } }
private void ApplyObservers(SimulationModel model, ModelResponse diff) { for (int i = 0; i < diff.ObserverResultsLength; i++) { ObserverResult observerData = diff.GetObserverResults(i); NeuronId neuronId = observerData.Observer.NeuronId; var definition = new ObserverDefinition(neuronId.Neuron, neuronId.Region, observerData.Observer.Type); model.Observers[definition] = new ObserverData( CopyObserverArrayData(observerData.MetadataLength, (n => observerData.GetMetadata(n))), observerData.GetPlainDataBytes()?.ToArray(), CopyObserverArrayData(observerData.FloatDataLength, (n => observerData.GetFloatData(n)))); } }
/// <summary> /// Retrieves the first entity that /// belongs to the specified key and /// includes the specified columns during /// selection /// </summary> /// <param name="id">Primary key</param> /// <param name="columns">Columns to include</param> /// <returns>ComplexReponse T</returns> public async Task <ModelResponse <T> > GetFirst(long id, string[] columns) { //Verify entity primary key if (id <= 0) { return(new ModelResponse <T>(false, @"The specified primary key is not valid.")); } //Verify select columns if (columns.IsNotValid()) { columns = Columns; } //Verify integrity Columns (All the supplied columns must exists inside the current entity) if (!columns.ToList().TrueForAll(Columns.Contains)) { return(new ModelResponse <T>(false, @"The supplied columns does not exist in the current entity.")); } ModelResponse <T> response; try { SqlServerCommand command = new SqlServerCommand(ConnectionString); string sql = $@"Select Top 1 [{string.Join(@"], [", columns)}] From [dbo].[{TableName}] Where [Id] = @Id And [Deleted] Is Null;"; SqlParameter[] parameters = new SqlParameter[1] { new SqlParameter(@"@Id", id) }; ModelResponse <List <ResultTable> > commandResult = await command.Query(sql, parameters); if (commandResult.Correct) { T model = commandResult.Model .FirstOrDefault() .Rows.ElementAt(0) .ToEntity <T>(); response = new ModelResponse <T>(model); } else { response = new ModelResponse <T>(false, commandResult.Message); } } catch (Exception ex) { response = new ModelResponse <T>(ex); } return(response); }