예제 #1
0
        public void Add(Task task)
        {
            var model = TaskModel.FromRepositoryType(task, _computers, _scripts, _users);

            _tasks.Add(model);

            _save();

            task.SetId(model.Id);
        }
예제 #2
0
파일: TaskModel.cs 프로젝트: Mavtak/roomie
        public Task ToRepositoryType()
        {
            var result = new Task(
                expiration: Expiration,
                id: Id,
                origin: Origin,
                owner: Owner.ToRepositoryType(),
                receivedTimestamp: ReceivedTimestamp,
                script: Script.ToRepositoryType(),
                target: Target.ToRepositoryType()
            );

            return result;
        }
예제 #3
0
파일: TaskModel.cs 프로젝트: Mavtak/roomie
        public static TaskModel FromRepositoryType(Task model, DbSet<ComputerModel> computers,DbSet<ScriptModel> scripts, DbSet<UserModel> users)
        {
            var result = new TaskModel
            {
                Expiration = model.Expiration,
                Id = model.Id,
                Origin = model.Origin,
                Owner = users.Find(model.Owner.Id),
                ReceivedTimestamp = model.ReceivedTimestamp,
                Script = scripts.Find(model.Script.Id),
                Target = computers.Find(model.Target.Id)
            };

            return result;
        }
예제 #4
0
        private Task GetSerializableVersion(Task task)
        {
            User owner = null;
            if (task.Owner != null)
            {
                owner = new User(
                    alias: task.Owner.Alias,
                    email: null,
                    id: task.Owner.Id,
                    registeredTimestamp: null,
                    secret: null,
                    token: null
                );
            }

            Computer target = null;
            if (task.Target != null)
            {
                target = new Computer(
                    accessKey: null,
                    address: null,
                    encryptionKey: null,
                    id: task.Target.Id,
                    lastPing: null,
                    lastScript: null,
                    name: task.Target.Name,
                    owner: null
                );
            }

            var result = new Task(
                expiration: task.Expiration,
                id: task.Id,
                origin: task.Origin,
                owner: owner,
                receivedTimestamp: task.ReceivedTimestamp,
                script: task.Script,
                target: target
            );

            return result;
        }
예제 #5
0
파일: Task.cs 프로젝트: Mavtak/roomie
        public static Task Create(User owner, string origin, Computer target, Script script)
        {
            var result = new Task
            {
                Expiration = DateTime.UtcNow.AddSeconds(30),
                Origin = origin,
                Owner = owner,
                Script = script,
                Target = target
            };

            return result;
        }
예제 #6
0
        public void Update(Task task)
        {
            var model = _tasks.Find(task.Id);

            model.ReceivedTimestamp = task.ReceivedTimestamp;

            _save();
        }
예제 #7
0
        public void Remove(Task task)
        {
            var model = _tasks.Find(task.Id);

            _tasks.Remove(model);

            _save();
        }