コード例 #1
0
ファイル: WebHookSession.cs プロジェクト: Mavtak/roomie
 public WebHookSession(Computer computer, int id, DateTime? lastPing, string token)
 {
     Computer = computer;
     Id = id;
     LastPing = lastPing;
     Token = token;
 }
コード例 #2
0
ファイル: ComputerController.cs プロジェクト: Mavtak/roomie
        private static Computer GetSerializableVersion(Computer computer)
        {
            User owner = null;
            if (computer.Owner != null)
            {
                owner = new User(
                    alias: computer.Owner.Alias,
                    email: null,
                    id: computer.Owner.Id,
                    registeredTimestamp: null,
                    secret: null,
                    token: null
                );
            }

            var result = new Computer(
                accessKey: computer.AccessKey,
                address: computer.Address,
                encryptionKey: computer.EncryptionKey,
                id: computer.Id,
                lastPing: computer.LastPing,
                lastScript: computer.LastScript,
                name: computer.Name,
                owner: owner
            );

            return result;
        }
コード例 #3
0
ファイル: Task.cs プロジェクト: Mavtak/roomie
 public Task(DateTime? expiration, int id, string origin, User owner, DateTime? receivedTimestamp, Script script, Computer target)
 {
     Expiration = expiration;
     Id = id;
     Origin = origin;
     Owner = owner;
     ReceivedTimestamp = receivedTimestamp;
     Script = script;
     Target = target;
 }
コード例 #4
0
ファイル: ComputerRepository.cs プロジェクト: Mavtak/roomie
        public void Add(Computer computer)
        {
            var model = ComputerModel.FromRepositoryType(computer, _scripts, _users);

            _computers.Add(model);

            _save();

            computer.SetId(model.Id);
        }
コード例 #5
0
ファイル: WebHookSession.cs プロジェクト: Mavtak/roomie
        public static WebHookSession Create(Computer computer)
        {
            var result = new WebHookSession
            {
                Computer = computer,
                LastPing = DateTime.UtcNow,
                Token = Guid.NewGuid().ToString()
            };

            return result;
        }
コード例 #6
0
        public static void AddTask(this IRoomieController controller, Computer computer, string origin, string scriptText)
        {
            var database = controller.Database;
            var user = controller.User;

            var script = Script.Create(false, scriptText);
            database.Scripts.Add(script);

            var task = Task.Create(user, origin, computer, script);

            database.Tasks.Add(task);
        }
コード例 #7
0
ファイル: TaskRepository.cs プロジェクト: Mavtak/roomie
        public Task[] ForComputer(Computer computer, DateTime now)
        {
            var results = (from t in _tasks
                          where t.Target.Id == computer.Id
                                && t.ReceivedTimestamp == null
                                && t.Expiration.Value > now
                          select t)
                          .ToArray()
                          .Select(x => x.ToRepositoryType())
                              .ToArray();

            return results;
        }
コード例 #8
0
ファイル: Network.cs プロジェクト: Mavtak/roomie
        public Network(string address, Computer attatchedComputer, IEnumerable<Device> devices, int id, DateTime? lastPing, string name, User owner)
        {
            Address = address;
            AttatchedComputer = attatchedComputer;

            if (devices != null)
            {
                Devices = SortDevices(devices);
            }

            Id = id;
            LastPing = lastPing;
            Name = name;
            Owner = owner;
        }
コード例 #9
0
ファイル: ComputerModel.cs プロジェクト: Mavtak/roomie
        public static ComputerModel FromRepositoryType(Computer model, DbSet<ScriptModel> scripts, DbSet<UserModel> users)
        {
            var result = new ComputerModel
            {
                AccessKey = model.AccessKey,
                Address = model.Address,
                EncryptionKey = model.EncryptionKey,
                Id = model.Id,
                LastPing = model.LastPing,
                LastScript = model.LastScript == null ? null : scripts.Find(model.LastScript.Id),
                Name = model.Name,
                Owner = users.Find(model.Owner.Id)
            };

            return result;
        }
コード例 #10
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;
        }
コード例 #11
0
ファイル: ComputerRepository.cs プロジェクト: Mavtak/roomie
        public void Remove(Computer computer)
        {
            var model = _computers.Find(computer.Id);

            _computers.Remove(model);
        }
コード例 #12
0
ファイル: NetworkController.cs プロジェクト: Mavtak/roomie
        private static Network GetSerializableVersion(Network network)
        {
            Computer computer = null;

            if (network.AttatchedComputer != null)
            {
                computer = new Computer(
                    accessKey: null,
                    address: null,
                    encryptionKey: null,
                    id: network.AttatchedComputer.Id,
                    lastPing: network.AttatchedComputer.LastPing,
                    lastScript: null,
                    name: network.AttatchedComputer.Name,
                    owner: null
                );
            }

            Device[] devices = null;

            if(network.Devices != null)
            {
                devices = network.Devices
                    .Select(x => new Device(
                        address: x.Address,
                        id: x.Id,
                        lastPing: null,
                        name: x.Name,
                        network: null,
                        scripts: null,
                        state: null,
                        tasks: null,
                        type: x.Type
                    ))
                    .ToArray();
            }

            User owner = null;

            if (network.Owner != null)
            {
                owner = new User(
                    alias: network.Owner.Alias,
                    email: null,
                    id: network.Owner.Id,
                    registeredTimestamp: null,
                    secret: null,
                    token: null
                );
            }

            return new Network(
                address: network.Address,
                attatchedComputer: computer,
                devices: devices,
                id: network.Id,
                lastPing: network.LastPing,
                name: network.Name,
                owner: owner
            );
        }
コード例 #13
0
ファイル: Network.cs プロジェクト: Mavtak/roomie
 public void UpdatePing(Computer computer)
 {
     AttatchedComputer = computer;
     LastPing = DateTime.UtcNow;
 }
コード例 #14
0
ファイル: Network.cs プロジェクト: Mavtak/roomie
        public static Network Create(string address, User owner, string name, DateTime? lastPing = null, Computer attachedComputer = null, IEnumerable<Device> devices = null)
        {
            var result = new Network
            {
                Address = address,
                AttatchedComputer = attachedComputer,
                Devices = (devices == null) ? null : devices.ToArray(),
                LastPing = lastPing,
                Name = name,
                Owner = owner
            };

            return result;
        }
コード例 #15
0
ファイル: TaskController.cs プロジェクト: Mavtak/roomie
        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;
        }
コード例 #16
0
ファイル: ComputerRepository.cs プロジェクト: Mavtak/roomie
        public void Update(Computer computer)
        {
            var model = _computers.Find(computer.Id);

            model.AccessKey = computer.AccessKey;
            model.Address = computer.Address;
            model.EncryptionKey = computer.EncryptionKey;
            model.LastPing = computer.LastPing;
            model.LastScript = (computer.LastScript == null) ? null : _scripts.Find(computer.LastScript.Id);
            model.Name = computer.Name;
            model.Owner = (computer.Owner == null) ? null : _users.Find(computer.Owner.Id);

            _save();
        }
コード例 #17
0
ファイル: Computer.cs プロジェクト: Mavtak/roomie
        public static Computer Create(string name, User owner, DateTime? lastPing = null)
        {
            var result = new Computer
            {
                Name = name,
                LastPing = lastPing,
                Owner = owner
            };

            return result;
        }
コード例 #18
0
ファイル: ComputerModel.cs プロジェクト: Mavtak/roomie
        public Computer ToRepositoryType()
        {
            var result = new Computer(
                accessKey: AccessKey,
                address: Address,
                encryptionKey: EncryptionKey,
                id: Id,
                lastPing: LastPing,
                lastScript: (LastScript == null) ? null : LastScript.ToRepositoryType(),
                name: Name,
                owner: Owner.ToRepositoryType()
            );

            return result;
        }