示例#1
0
        public async Task <string> StartTaskDb(string nameMethod, string optionalParameter, string token)
        {
            Driver  driver  = context.Drivers.First(d => d.Token == token);
            LogTask logTask = context.LogTasks
                              .Include(l => l.TaskLoads)
                              .FirstOrDefault();

            if (logTask == null)
            {
                context.LogTasks.Add(new LogTask()
                {
                    TaskLoads = new List <TaskLoad>()
                });
                context.SaveChanges();
                logTask = context.LogTasks
                          .Include(l => l.TaskLoads)
                          .FirstOrDefault();
            }
            TaskLoad taskLoad = new TaskLoad()
            {
                Array             = new byte[0],
                NameMethod        = nameMethod,
                OptionalParameter = optionalParameter,
                IdDriver          = driver.Id.ToString()
            };

            logTask.TaskLoads.Add(taskLoad);
            context.SaveChanges();
            return(taskLoad.Id.ToString());
        }
示例#2
0
        public async Task <string> LoadTaskDb(string idTask, byte[] buffer)
        {
            TaskLoad taskLoad = await context.TaskLoads
                                .FirstOrDefaultAsync(l => l.Id.ToString() == idTask);

            if (taskLoad == null)
            {
                return("No");
            }
            string str  = Encoding.Default.GetString(taskLoad.Array);
            string str1 = Encoding.Default.GetString(buffer);

            taskLoad.Array = Encoding.Default.GetBytes(str + str1);
            await context.SaveChangesAsync();

            return(taskLoad.Id.ToString());
        }
示例#3
0
        public async Task <string[]> EndTaskDb(string idTask)
        {
            LogTask logTask = await context.LogTasks
                              .Include(l => l.TaskLoads)
                              .FirstOrDefaultAsync();

            if (logTask == null)
            {
                return(null);
            }
            TaskLoad taskLoad = logTask.TaskLoads.FirstOrDefault(l => l.Id.ToString() == idTask);

            if (taskLoad == null)
            {
                return(null);
            }
            string str = Encoding.Default.GetString(taskLoad.Array);

            context.TaskLoads.Remove(taskLoad);
            await context.SaveChangesAsync();

            return(new string[] { str, taskLoad.OptionalParameter });
        }