public object Create(object p)
 {
     try
     {
         DadoColetado r = (context.DadoColetado.Add((DadoColetado)p)).Entity;
         context.SaveChanges();
         Program.connection.StartAsync().ContinueWith(task =>
         {
             if (task.IsFaulted)
             {
                 Console.WriteLine("There was an error opening the connection:{0}", task.Exception.GetBaseException());
             }
             else
             {
                 string valorLido  = ((DadoColetado)p).ValorLido.ToString() + DateTime.Now.Second;
                 string medidor    = ((DadoColetado)p).Hwid;
                 string tipoMedida = ((Grandeza) new GrandezaRepository(new LPTContext()).Read(((DadoColetado)p).TipoDeGrandeza)).Descricao;
                 Program.connection.InvokeAsync <string>("SendMessage", medidor, tipoMedida, valorLido).ContinueWith(task1 => {
                     if (task1.IsFaulted)
                     {
                         Console.WriteLine("There was an error calling send: {0}", task1.Exception.GetBaseException());
                     }
                 });
             }
         }).Wait();
         Program.connection.StopAsync();
         return(r);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(null);
     }
 }
示例#2
0
 public object Create(object p)
 {
     try
     {
         MedidorExperimento r = (context.MedidorExperimento.Add((MedidorExperimento)p)).Entity;
         context.SaveChanges();
         return(r);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(null);
     }
 }
 public object Create(object p)
 {
     try
     {
         Grandeza r = (context.Grandeza.Add((Grandeza)p)).Entity;
         context.SaveChanges();
         return(r);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(null);
     }
 }
示例#4
0
 public object Create(object p)
 {
     try
     {
         foreach (var item in (from t in context.Experimento where t.DataFim == null && t.DataInicio != ((Experimento)p).DataInicio select t).ToList <Experimento>())
         {
             item.DataFim = DateTime.Now;
             context.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
         }
         Experimento r = (context.Experimento.Add((Experimento)p)).Entity;
         context.SaveChanges();
         Program.experimentoAtivo = r.IdExperimento;
         return(r);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(null);
     }
 }