public void Save(User user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            _mongo.EnsureIdentity(user);
            _mongo.Users.Save(user);
        }
Beispiel #2
0
        public void Save(DeviceClass deviceClass)
        {
            if (deviceClass == null)
            {
                throw new ArgumentNullException("deviceClass");
            }

            _mongo.EnsureIdentity(deviceClass);

            if (deviceClass.Equipment == null)
            {
                deviceClass.Equipment = new List <Equipment>();
            }
            deviceClass.Equipment.ForEach(e => _mongo.EnsureIdentity(e));

            _mongo.DeviceClasses.Save(deviceClass);

            _mongo.Devices.Update(Query <Device> .EQ(e => e.DeviceClassID, deviceClass.ID),
                                  Update <Device> .Set(d => d.DeviceClass, deviceClass), new MongoUpdateOptions {
                Flags = UpdateFlags.Multi
            });
        }
        public void Save(AccessKey accessKey)
        {
            if (accessKey == null)
            {
                throw new ArgumentNullException("accessKey");
            }

            _mongo.EnsureIdentity(accessKey);

            if (accessKey.Permissions == null)
            {
                accessKey.Permissions = new List <AccessKeyPermission>();
            }
            accessKey.Permissions.ForEach(e => _mongo.EnsureIdentity(e));

            _mongo.AccessKeys.Save(accessKey);

            _mongo.OAuthGrants.Update(Query <OAuthGrant> .EQ(e => e.AccessKeyID, accessKey.ID),
                                      Update <OAuthGrant> .Set(e => e.AccessKey, accessKey), new MongoUpdateOptions {
                Flags = UpdateFlags.Multi
            });
        }
Beispiel #4
0
        public void Save(OAuthClient oauthClient)
        {
            if (oauthClient == null)
            {
                throw new ArgumentNullException("oauthClient");
            }

            _mongo.EnsureIdentity(oauthClient);
            _mongo.OAuthClients.Save(oauthClient);

            _mongo.OAuthGrants.Update(Query <OAuthGrant> .EQ(e => e.ClientID, oauthClient.ID),
                                      Update <OAuthGrant> .Set(e => e.Client, oauthClient), new MongoUpdateOptions {
                Flags = UpdateFlags.Multi
            });
        }
Beispiel #5
0
        public void Save(Network network)
        {
            if (network == null)
            {
                throw new ArgumentNullException("network");
            }

            _mongo.EnsureIdentity(network);
            _mongo.Networks.Save(network);

            _mongo.Devices.Update(Query <Device> .EQ(e => e.NetworkID, network.ID),
                                  Update <Device> .Set(d => d.Network, network), new MongoUpdateOptions {
                Flags = UpdateFlags.Multi
            });
        }
Beispiel #6
0
        public void Save(DeviceEquipment equipment)
        {
            if (equipment == null)
            {
                throw new ArgumentNullException("equipment");
            }

            if (equipment.Device != null)
            {
                equipment.DeviceID = equipment.Device.ID;
            }

            _mongo.EnsureIdentity(equipment);
            _mongo.DeviceEquipment.Save(equipment);
        }
        public void Save(UserNetwork userNetwork)
        {
            if (userNetwork == null)
            {
                throw new ArgumentNullException("userNetwork");
            }

            if (userNetwork.User != null)
            {
                userNetwork.UserID = userNetwork.User.ID;
            }
            if (userNetwork.Network != null)
            {
                userNetwork.NetworkID = userNetwork.Network.ID;
            }

            _mongo.EnsureIdentity(userNetwork);
            _mongo.UserNetworks.Save(userNetwork);
        }
Beispiel #8
0
        public void Save(Device device)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }
            if (string.IsNullOrEmpty(device.GUID))
            {
                throw new ArgumentException("Device.GUID must have a valid value!", "device.GUID");
            }

            if (device.Network != null)
            {
                device.NetworkID = device.Network.ID;
            }
            else if (device.NetworkID != null)
            {
                device.Network = _mongo.Networks.FindOneById(device.NetworkID.Value);
                if (device.Network == null)
                {
                    throw new ArgumentException("Specified NetworkID does not exist!", "device.NetworkID");
                }
            }

            if (device.DeviceClass != null)
            {
                device.DeviceClassID = device.DeviceClass.ID;
            }
            else
            {
                device.DeviceClass = _mongo.DeviceClasses.FindOneById(device.DeviceClassID);
                if (device.DeviceClass == null)
                {
                    throw new ArgumentException("Specified DeviceClassID does not exist!", "device.DeviceClassID");
                }
            }

            _mongo.EnsureIdentity(device);
            _mongo.Devices.Save(device);
        }
        public void Save(OAuthGrant oauthGrant)
        {
            if (oauthGrant == null)
            {
                throw new ArgumentNullException("oauthGrant");
            }

            if (oauthGrant.Client != null)
            {
                oauthGrant.ClientID = oauthGrant.Client.ID;
            }
            else
            {
                oauthGrant.Client = _mongo.OAuthClients.FindOneById(oauthGrant.ClientID);
                if (oauthGrant.Client == null)
                {
                    throw new ArgumentException("Specified ClientID does not exist!", "oauthGrant.ClientID");
                }
            }

            if (oauthGrant.AccessKey != null)
            {
                oauthGrant.AccessKeyID = oauthGrant.AccessKey.ID;
            }
            else
            {
                oauthGrant.AccessKey = _mongo.AccessKeys.FindOneById(oauthGrant.AccessKeyID);
                if (oauthGrant.AccessKey == null)
                {
                    throw new ArgumentException("Specified AccessKeyID does not exist!", "oauthGrant.AccessKeyID");
                }
            }

            _mongo.EnsureIdentity(oauthGrant);
            _mongo.OAuthGrants.Save(oauthGrant);
        }