Exemplo n.º 1
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
Exemplo n.º 2
0
 public async Task Dispose()
 {
     if (WasInitiated)
     {
         _mainDbContext.Dispose();
         _comHelper.Dispose();
         await _gammuService.Dispose();
     }
 }
Exemplo n.º 3
0
        protected void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                _context.Dispose();
            }

            _disposed = true;
        }
Exemplo n.º 4
0
        protected override void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects)
                    dbContext.Dispose();
                }

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.

                disposed = true;
                base.Dispose(disposing);
            }
        }
Exemplo n.º 5
0
        public void GenerateLocalizationFilesForTypescript(IConfiguration Configuration)
        {
            try
            {
                var localizations = _DbContext.Localizations.ToList();
                var jsonAr        = localizations.Select(x => new { x.Key, x.ValueAr }).ToList();
                var jsonEn        = localizations.Select(x => new { x.Key, x.ValueEn }).ToList();
                var stringBuilder = new StringBuilder("{");
                foreach (var item in jsonAr)
                {
                    stringBuilder.Append('"').Append(item.Key).Append('"')
                    .Append(':').Append('"').Append(item.ValueAr).Append('"').Append(",");
                }
                stringBuilder.Remove(stringBuilder.Length - 1, 1).Append("}");

                var localizationPath = Configuration.GetValue("LocalizationSettings:LocalizationRelativePath", "");

                new FileInfo(localizationPath).Directory.Create();

                File.WriteAllText(localizationPath + "\\ar.json", stringBuilder.ToString());

                stringBuilder.Clear().Append("{");
                foreach (var item in jsonEn)
                {
                    stringBuilder.Append('"').Append(item.Key).Append('"')
                    .Append(':').Append('"').Append(item.ValueEn).Append('"').Append(",");
                }
                stringBuilder.Remove(stringBuilder.Length - 1, 1).Append("}");

                File.WriteAllText(localizationPath + "\\en.json", stringBuilder.ToString());
            }

            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                _DbContext.Dispose();
            }
        }
Exemplo n.º 6
0
 public void Dispose()
 {
     _context?.Dispose();
 }
        /// <summary>To be used internaly</summary>
        /// <param name="values"></param>
        private bool CreateDevice(KeyValuePair <Guid, SensorMessage[]> values, string devicename)
        {
            var db = new MainDbContext();

            //Make sure that it is good and proper to create this device
            if (SettingsService.Instance.IsLoggedIn == false ||
                SettingsService.Instance.LastSuccessfulGeneralDbGet == default(DateTimeOffset) ||
                _dbDevices.Any(dev => dev.SerialNumber == values.Key))
            {
                return(false);
            }

            //Make sure this device is reporting valid sensor Id's
            var sensorTypes = db.SensorTypes.ToList();

            foreach (var sensor in values.Value)
            {
                if (sensorTypes.FirstOrDefault(st => st.ID == sensor.SensorTypeID) == null)
                {
                    Util.LoggingService.LogInfo($"Receieved message with sensor ID {sensor.SensorTypeID}, but it is invalid - there is no such ID", Windows.Foundation.Diagnostics.LoggingLevel.Error);
                    return(false); //If any of the sensors are invalid, then return;
                }
            }

            LoggingService.LogInfo("Adding a new Device", Windows.Foundation.Diagnostics.LoggingLevel.Information);

            var device = new Device
            {
                ID           = Guid.NewGuid(),
                SerialNumber = values.Key,
                Deleted      = false,
                CreatedAt    = DateTimeOffset.Now,
                UpdatedAt    = DateTimeOffset.Now,
                Name         = $"{devicename} {_dbDevices.Count}",
                Relays       = new List <Relay>(),
                Sensors      = new List <Sensor>(),
                Version      = new byte[32],
                Location     =
                    new Location
                {
                    ID            = Guid.NewGuid(),
                    Deleted       = false,
                    Name          = $"{devicename} {_dbDevices.Count}",
                    PersonId      = SettingsService.Instance.CredStableSid, //TODO use the thing from settings!
                    Version       = new byte[32],
                    CropCycles    = new List <CropCycle>(),
                    Devices       = new List <Device>(),
                    RelayHistory  = new List <RelayHistory>(),
                    SensorHistory = new List <SensorHistory>(),
                    CreatedAt     = DateTimeOffset.Now,
                    UpdatedAt     = DateTimeOffset.Now
                }
            };

            db.Devices.Add(device);
            db.Locations.Add(device.Location);
            //Add sensors
            foreach (var inSensors in values.Value)
            {
                //Todo check correctness of hte sensorType
                var newSensor = new Sensor
                {
                    CreatedAt    = DateTimeOffset.Now,
                    UpdatedAt    = DateTimeOffset.Now,
                    ID           = Guid.NewGuid(),
                    DeviceID     = device.ID,
                    Deleted      = false,
                    SensorTypeID = inSensors.SensorTypeID,
                    Enabled      = true,
                    Multiplier   = 1,
                    Offset       = 0,
                    Version      = new byte[32]
                };
                device.Sensors.Add(newSensor);
            }
            db.SaveChanges();

            //Add the device to the cached data?
            _dbDevices.Add(device);
            foreach (var sensor in device.Sensors)
            {
                _sensorBuffer.Add(new SensorBuffer(sensor));
            }
            db.Dispose();

            ToastService.NotifyUserOfInformation($"A new Device has been Created - {device.Name}");

            return(true);
        }
Exemplo n.º 8
0
        public static void Destroy(MainDbContext context)
        {
            context.Database.EnsureDeleted();

            context.Dispose();
        }
Exemplo n.º 9
0
        /// <summary>To be used internaly</summary>
        /// <param name="values"></param>
        private bool CreateDevice(KeyValuePair <Guid, Manager.SensorMessage[]> values)
        {
            //Make sure that if fired several times, the constraints are maintained

            if (Settings.Instance.IsLoggedIn && Settings.Instance.LastSuccessfulGeneralDbGet != default(DateTimeOffset) &&
                _dbDevices.Any(dev => dev.SerialNumber == values.Key) == false)
            {
                Debug.WriteLine("addingDevice");
                var db = new MainDbContext();

                var device = new Device
                {
                    ID           = Guid.NewGuid(),
                    SerialNumber = values.Key,
                    Deleted      = false,
                    CreatedAt    = DateTimeOffset.Now,
                    UpdatedAt    = DateTimeOffset.Now,
                    Name         = string.Format("Box Number {0}", _dbDevices.Count),
                    Relays       = new List <Relay>(),
                    Sensors      = new List <Sensor>(),
                    Version      = new byte[32],
                    Location     =
                        new Location
                    {
                        ID            = Guid.NewGuid(),
                        Deleted       = false,
                        Name          = string.Format("Box Number {0}", _dbDevices.Count),
                        PersonId      = Settings.Instance.CredStableSid, //TODO use the thing from settings!
                        Version       = new byte[32],
                        CropCycles    = new List <CropCycle>(),
                        Devices       = new List <Device>(),
                        RelayHistory  = new List <RelayHistory>(),
                        SensorHistory = new List <SensorHistory>(),
                        CreatedAt     = DateTimeOffset.Now,
                        UpdatedAt     = DateTimeOffset.Now
                    }
                };

                db.Devices.Add(device);
                db.Locations.Add(device.Location);
                //Add sensors
                foreach (var inSensors in values.Value)
                {
                    //Todo check correctness of hte sensorType
                    var newSensor = new Sensor
                    {
                        CreatedAt    = DateTimeOffset.Now,
                        UpdatedAt    = DateTimeOffset.Now,
                        ID           = Guid.NewGuid(),
                        DeviceID     = device.ID,
                        Deleted      = false,
                        SensorTypeID = inSensors.SensorTypeID,
                        Enabled      = true,
                        Multiplier   = 1,
                        Offset       = 0,
                        Version      = new byte[32]
                    };
                    device.Sensors.Add(newSensor);
                }
                db.SaveChanges();

                //Add the device to the cached data?
                _dbDevices.Add(device);
                foreach (var sensor in device.Sensors)
                {
                    _sensorBuffer.Add(new SensorBuffer(sensor));
                }
                db.Dispose();

                return(true);
            }
            return(false);
        }