public bool Check(Network network, User user) { var entry = Get(network, user); var result = entry != null; return result; }
public void Remove(Network network, User user) { var entry = Get(network, user); _entries.Remove(entry); _save(); }
public void Add(Network network) { var model = NetworkModel.FromRepositoryType(network, _computers, _users); _networks.Add(model); _save(); network.SetId(model.Id); }
public User[] Get(Network network) { var result = _entries .Where(x => x.Network.Id == network.Id) .Select(x => x.User) .ToArray() .Select(x => x.ToRepositoryType()) .ToArray(); return result; }
public void Add(Network network, User user) { var entry = new NetworkGuestModel { Network = _networks.Find(network.Id), User = _users.Find(user.Id), }; _entries.Add(entry); _save(); }
public static void Copy(this INetworkGuestRepository repository, Network source, Network destination) { var users = repository.Get(source); foreach (var user in users) { if (!repository.Check(destination, user)) { repository.Add(destination, user); } } }
public static NetworkModel FromRepositoryType(Network network, DbSet<ComputerModel> computers, DbSet<UserModel> users) { var result = new NetworkModel { Address = network.Address, AttatchedComputer = network.AttatchedComputer == null ? null : computers.Find(network.AttatchedComputer.Id), //TODO: include devices?, Id = network.Id, LastPing = network.LastPing, Name = network.Name, Owner = users.Find(network.Owner.Id) }; return result; }
public Device(string address, DateTime? lastPing, int id, string name, Network network, IScriptRepository scripts, IDeviceState state, ITaskRepository tasks, DeviceType type) : this() { Address = address; LastPing = lastPing; Id = id; Name = name; Network = network; ScriptRepository = scripts; TaskRepository = tasks; Type = type; if (state != null) { Update(state, false); } }
private void NetworkAction(Network network, string action) { this.AddTask( computer: network.AttatchedComputer, origin: "RoomieBot", scriptText: $"<HomeAutomation.{action} Network=\"{network.Address}\" />\n<HomeAutomation.SyncWithCloud />" ); }
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; }
public Device[] Get(Network network) { var models = _devices .Where(x => x.Network.Id == network.Id) .ToArray(); var result = models .Select(x => x.ToRepositoryType(_scripts, _tasks)) .ToArray(); return result; }
public Network ToRepositoryType() { var result = new Network( address: Address, attatchedComputer: AttatchedComputer.ToRepositoryType(), devices: null, //TODO: remove this property completely id: Id, lastPing: LastPing, name: Name, owner: Owner.ToRepositoryType() ); return result; }
public static Device Create(string address, bool? isConnected, string name, Network network, ILocation location, DeviceType type, string currentAction = null) { var result = new Device( address: address, lastPing: null, id: 0, name: name, network: network, scripts: null, state: null, tasks: null, type: type ); result.CurrentAction = currentAction; return result; }
public void Add(Network network) { _networks.Add(network); }
private static IEnumerable<IDeviceState> ProcessSentDevices(Message request, Message response, User user, Network network, IRoomieDatabaseContext database) { var sentDevices = request.Payload.Select(x => x.ToDeviceState()); sentDevices = sentDevices.Select(x => x.NewWithNetwork(network)); return sentDevices; }
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 Remove(Network network) { //TODO: improve this method _networks.Remove(network); foreach (var guest in _guests.Get(network)) { _guests.Remove(network, guest); } }
public void Update(Network network) { var model = _networks.Find(network.Id); model.Address = network.Address; model.AttatchedComputer = _computers.Find(network.AttatchedComputer.Id); model.LastPing = network.LastPing; model.Name = network.Name; _save(); }
public void Remove(Network network) { var model = _networks.Find(network.Id); _networks.Remove(model); _save(); }
private static void UpdateDevices(IEnumerable<IDeviceState> sentDevices, IEnumerable<Device> registeredDevices, Network network, IRoomieDatabaseContext database) { // go through the devices from the client and update the entries in the database foreach (var sentDevice in sentDevices) { var registeredDevice = registeredDevices.FirstOrDefault(x => x.Address == sentDevice.Address && x.Network.Address == sentDevice.NetworkState.Address); if (registeredDevice == null) { var newDevice = Device.Create( address: sentDevice.Address, isConnected: sentDevice.IsConnected, name: sentDevice.Name, network: network, location: sentDevice.Location, type: sentDevice.Type ); newDevice.Update(sentDevice); database.Devices.Add(newDevice); } else { database.Devices.Update(registeredDevice.Id, sentDevice); } } }
private NetworkGuestModel Get(Network network, User user) { var result = _entries .Where(x => x.User.Id == user.Id) .Where(x => x.Network.Id == network.Id) .FirstOrDefault(); return result; }
public Device[] Get(Network network) { var result = _devices.Get(network); return result; }
public void Update(Network network) { _networks.Update(network); }