public WebHookSession(Computer computer, int id, DateTime? lastPing, string token) { Computer = computer; Id = id; LastPing = lastPing; Token = token; }
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; }
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; }
public void Add(Computer computer) { var model = ComputerModel.FromRepositoryType(computer, _scripts, _users); _computers.Add(model); _save(); computer.SetId(model.Id); }
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); }
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; }
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; }
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; }
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; }
public void Remove(Computer computer) { var model = _computers.Find(computer.Id); _computers.Remove(model); }
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 ); }
public void UpdatePing(Computer computer) { AttatchedComputer = computer; LastPing = DateTime.UtcNow; }
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; }
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; }
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(); }
public static Computer Create(string name, User owner, DateTime? lastPing = null) { var result = new Computer { Name = name, LastPing = lastPing, Owner = owner }; return result; }
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; }