private async void WriteReading(bool major, DateTime time, ReadingData data)
        {
            var readingGuid = Guid.NewGuid();
            try
            {
                // Ensure the inital create have finished
                if (initalCreate != null)
                {
                    lock (initalCreateLock)
                    {
                        if (initalCreate != null)
                        {
                            Task.WaitAll(initalCreate);
                            initalCreate = null;
                        }
                    }
                }

                var reading = new Reading()
                {
                    Id = readingGuid,
                    Project = this.Id,
                    Major = major ? (byte)1 : (byte)0,
                    Time = time,
                    LAeq = data.LAeq,
                    LAMax = data.LAMax,
                    LAMin = data.LAMin,
                    LZMax = data.LZMax,
                    LZMin = data.LZMin,

                    // 1/3
                    Hz6_3 = data.LAeqOctaveBandOneThird.Hz6_3,
                    Hz8 = data.LAeqOctaveBandOneThird.Hz8,
                    Hz10 = data.LAeqOctaveBandOneThird.Hz10,
                    Hz12_5 = data.LAeqOctaveBandOneThird.Hz12_5,
                    Hz16 = data.LAeqOctaveBandOneThird.Hz16,
                    Hz20 = data.LAeqOctaveBandOneThird.Hz20,
                    Hz25 = data.LAeqOctaveBandOneThird.Hz25,
                    Hz31_5 = data.LAeqOctaveBandOneThird.Hz31_5,
                    Hz40 = data.LAeqOctaveBandOneThird.Hz40,
                    Hz50 = data.LAeqOctaveBandOneThird.Hz50,
                    Hz63 = data.LAeqOctaveBandOneThird.Hz63,
                    Hz80 = data.LAeqOctaveBandOneThird.Hz80,
                    Hz100 = data.LAeqOctaveBandOneThird.Hz100,
                    Hz125 = data.LAeqOctaveBandOneThird.Hz125,
                    Hz160 = data.LAeqOctaveBandOneThird.Hz160,
                    Hz200 = data.LAeqOctaveBandOneThird.Hz200,
                    Hz250 = data.LAeqOctaveBandOneThird.Hz250,
                    Hz315 = data.LAeqOctaveBandOneThird.Hz315,
                    Hz400 = data.LAeqOctaveBandOneThird.Hz400,
                    Hz500 = data.LAeqOctaveBandOneThird.Hz500,
                    Hz630 = data.LAeqOctaveBandOneThird.Hz630,
                    Hz800 = data.LAeqOctaveBandOneThird.Hz800,
                    Hz1000 = data.LAeqOctaveBandOneThird.Hz1000,
                    Hz1250 = data.LAeqOctaveBandOneThird.Hz1250,
                    Hz1600 = data.LAeqOctaveBandOneThird.Hz1600,
                    Hz2000 = data.LAeqOctaveBandOneThird.Hz2000,
                    Hz2500 = data.LAeqOctaveBandOneThird.Hz2500,
                    Hz3150 = data.LAeqOctaveBandOneThird.Hz3150,
                    Hz4000 = data.LAeqOctaveBandOneThird.Hz4000,
                    Hz5000 = data.LAeqOctaveBandOneThird.Hz5000,
                    Hz6300 = data.LAeqOctaveBandOneThird.Hz6300,
                    Hz8000 = data.LAeqOctaveBandOneThird.Hz8000,
                    Hz10000 = data.LAeqOctaveBandOneThird.Hz10000,
                    Hz12500 = data.LAeqOctaveBandOneThird.Hz12500,
                    Hz16000 = data.LAeqOctaveBandOneThird.Hz16000,
                    Hz20000 = data.LAeqOctaveBandOneThird.Hz20000,

                    // 1/1
                    OOHz16 = data.LAeqOctaveBandOneOne.Hz16,
                    OOHz31_5 = data.LAeqOctaveBandOneOne.Hz31_5,
                    OOHz63 = data.LAeqOctaveBandOneOne.Hz63,
                    OOHz125 = data.LAeqOctaveBandOneOne.Hz125,
                    OOHz250 = data.LAeqOctaveBandOneOne.Hz250,
                    OOHz500 = data.LAeqOctaveBandOneOne.Hz500,
                    OOHz1000 = data.LAeqOctaveBandOneOne.Hz1000,
                    OOHz2000 = data.LAeqOctaveBandOneOne.Hz2000,
                    OOHz4000 = data.LAeqOctaveBandOneOne.Hz4000,
                    OOHz8000 = data.LAeqOctaveBandOneOne.Hz8000,
                    OOHz16000 = data.LAeqOctaveBandOneOne.Hz16000
                };

                using (var audioViewEntities = new AudioViewEntities())
                {
                    audioViewEntities.Readings.Add(reading);
                    await audioViewEntities.SaveChangesAsync();
                }


                if (isServerDown && OnSQLServerStatusChanged != null)
                {
                    OnSQLServerStatusChanged(false);
                }
                isServerDown = false;

                // Reading ok, try to load offline files
                await UploadLocalFiles();
            }
            catch (Exception exp)
            {
                logger.Debug(exp, "Got database exception, starting to write offline for \"{0}\".", this.Settings.ProjectName);
                WriteOfline(major, time, data, readingGuid);

                if (!isServerDown && OnSQLServerStatusChanged != null)
                {
                    OnSQLServerStatusChanged(true);
                }
                isServerDown = true;
            }
        }
Example #2
0
        private async void WriteReading(bool major, DateTime time, ReadingData data)
        {
            var readingGuid = Guid.NewGuid();

            try
            {
                // Ensure the inital create have finished
                if (initalCreate != null)
                {
                    lock (initalCreateLock)
                    {
                        if (initalCreate != null)
                        {
                            Task.WaitAll(initalCreate);
                            initalCreate = null;
                        }
                    }
                }

                var reading = new Reading()
                {
                    Id      = readingGuid,
                    Project = this.Id,
                    Major   = major ? (byte)1 : (byte)0,
                    Time    = time,
                    LAeq    = data.LAeq,
                    LAMax   = data.LAMax,
                    LAMin   = data.LAMin,
                    LZMax   = data.LZMax,
                    LZMin   = data.LZMin,

                    // 1/3
                    Hz6_3   = data.LAeqOctaveBandOneThird.Hz6_3,
                    Hz8     = data.LAeqOctaveBandOneThird.Hz8,
                    Hz10    = data.LAeqOctaveBandOneThird.Hz10,
                    Hz12_5  = data.LAeqOctaveBandOneThird.Hz12_5,
                    Hz16    = data.LAeqOctaveBandOneThird.Hz16,
                    Hz20    = data.LAeqOctaveBandOneThird.Hz20,
                    Hz25    = data.LAeqOctaveBandOneThird.Hz25,
                    Hz31_5  = data.LAeqOctaveBandOneThird.Hz31_5,
                    Hz40    = data.LAeqOctaveBandOneThird.Hz40,
                    Hz50    = data.LAeqOctaveBandOneThird.Hz50,
                    Hz63    = data.LAeqOctaveBandOneThird.Hz63,
                    Hz80    = data.LAeqOctaveBandOneThird.Hz80,
                    Hz100   = data.LAeqOctaveBandOneThird.Hz100,
                    Hz125   = data.LAeqOctaveBandOneThird.Hz125,
                    Hz160   = data.LAeqOctaveBandOneThird.Hz160,
                    Hz200   = data.LAeqOctaveBandOneThird.Hz200,
                    Hz250   = data.LAeqOctaveBandOneThird.Hz250,
                    Hz315   = data.LAeqOctaveBandOneThird.Hz315,
                    Hz400   = data.LAeqOctaveBandOneThird.Hz400,
                    Hz500   = data.LAeqOctaveBandOneThird.Hz500,
                    Hz630   = data.LAeqOctaveBandOneThird.Hz630,
                    Hz800   = data.LAeqOctaveBandOneThird.Hz800,
                    Hz1000  = data.LAeqOctaveBandOneThird.Hz1000,
                    Hz1250  = data.LAeqOctaveBandOneThird.Hz1250,
                    Hz1600  = data.LAeqOctaveBandOneThird.Hz1600,
                    Hz2000  = data.LAeqOctaveBandOneThird.Hz2000,
                    Hz2500  = data.LAeqOctaveBandOneThird.Hz2500,
                    Hz3150  = data.LAeqOctaveBandOneThird.Hz3150,
                    Hz4000  = data.LAeqOctaveBandOneThird.Hz4000,
                    Hz5000  = data.LAeqOctaveBandOneThird.Hz5000,
                    Hz6300  = data.LAeqOctaveBandOneThird.Hz6300,
                    Hz8000  = data.LAeqOctaveBandOneThird.Hz8000,
                    Hz10000 = data.LAeqOctaveBandOneThird.Hz10000,
                    Hz12500 = data.LAeqOctaveBandOneThird.Hz12500,
                    Hz16000 = data.LAeqOctaveBandOneThird.Hz16000,
                    Hz20000 = data.LAeqOctaveBandOneThird.Hz20000,

                    // 1/1
                    OOHz16    = data.LAeqOctaveBandOneOne.Hz16,
                    OOHz31_5  = data.LAeqOctaveBandOneOne.Hz31_5,
                    OOHz63    = data.LAeqOctaveBandOneOne.Hz63,
                    OOHz125   = data.LAeqOctaveBandOneOne.Hz125,
                    OOHz250   = data.LAeqOctaveBandOneOne.Hz250,
                    OOHz500   = data.LAeqOctaveBandOneOne.Hz500,
                    OOHz1000  = data.LAeqOctaveBandOneOne.Hz1000,
                    OOHz2000  = data.LAeqOctaveBandOneOne.Hz2000,
                    OOHz4000  = data.LAeqOctaveBandOneOne.Hz4000,
                    OOHz8000  = data.LAeqOctaveBandOneOne.Hz8000,
                    OOHz16000 = data.LAeqOctaveBandOneOne.Hz16000
                };

                using (var audioViewEntities = new AudioViewEntities())
                {
                    audioViewEntities.Readings.Add(reading);
                    await audioViewEntities.SaveChangesAsync();
                }


                if (isServerDown && OnSQLServerStatusChanged != null)
                {
                    OnSQLServerStatusChanged(false);
                }
                isServerDown = false;

                // Reading ok, try to load offline files
                await UploadLocalFiles();
            }
            catch (Exception exp)
            {
                logger.Debug(exp, "Got database exception, starting to write offline for \"{0}\".", this.Settings.ProjectName);
                WriteOfline(major, time, data, readingGuid);

                if (!isServerDown && OnSQLServerStatusChanged != null)
                {
                    OnSQLServerStatusChanged(true);
                }
                isServerDown = true;
            }
        }