Example #1
0
 public WebHookSession(Computer computer, int id, DateTime? lastPing, string token)
 {
     Computer = computer;
     Id = id;
     LastPing = lastPing;
     Token = token;
 }
Example #2
0
        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;
        }
Example #3
0
 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;
 }
Example #4
0
        public void Add(Computer computer)
        {
            var model = ComputerModel.FromRepositoryType(computer, _scripts, _users);

            _computers.Add(model);

            _save();

            computer.SetId(model.Id);
        }
Example #5
0
        public static WebHookSession Create(Computer computer)
        {
            var result = new WebHookSession
            {
                Computer = computer,
                LastPing = DateTime.UtcNow,
                Token = Guid.NewGuid().ToString()
            };

            return result;
        }
        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);
        }
Example #7
0
        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;
        }
Example #8
0
        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;
        }
Example #9
0
        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;
        }
Example #10
0
        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;
        }
Example #11
0
        public void Remove(Computer computer)
        {
            var model = _computers.Find(computer.Id);

            _computers.Remove(model);
        }
Example #12
0
        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
            );
        }
Example #13
0
 public void UpdatePing(Computer computer)
 {
     AttatchedComputer = computer;
     LastPing = DateTime.UtcNow;
 }
Example #14
0
        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;
        }
Example #15
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;
        }
Example #16
0
        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();
        }
Example #17
0
        public static Computer Create(string name, User owner, DateTime? lastPing = null)
        {
            var result = new Computer
            {
                Name = name,
                LastPing = lastPing,
                Owner = owner
            };

            return result;
        }
Example #18
0
        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;
        }