Ejemplo n.º 1
0
 public static MusicFile GetBestMusicFile(this Track t, DeviceRuntime dr)
 {
     //TODO:: a more complicated algorithm may be required browsers
     // i.e. one that tries to decide if they are flac capable, etc
     if (dr.Type == AudioDeviceType.Browser)
     {
         var mp3versions = t.MusicFiles.Where(x => x.Encoding == EncodingType.mp3);
         if (mp3versions.Count() > 0)
         {
             return(mp3versions.OrderByDescending(x => x.AverageBitRate).First());
         }
     }
     if (dr.MaxSampleRate == 0)
     {
         return(t.MusicFiles.First());
     }
     else
     {
         var candidates = t.MusicFiles.Where(x => x.SampleRate <= dr.MaxSampleRate);
         if (candidates.Count() > 0)
         {
             var bestSampleRate = candidates.Max(x => x.SampleRate);
             var availableFiles = t.MusicFiles.Where(x => x.SampleRate == bestSampleRate).OrderBy(x => (x.AverageBitRate > 0 ? x.AverageBitRate : x.MaximumBitRate));
             return(availableFiles.First());
         }
     }
     return(null);
 }
Ejemplo n.º 2
0
 public DeviceClient(string devIDNO, IPAddress ip, int port)
 {
     DevIDNO = devIDNO;
     Ip      = ip;
     Port    = port;
     Runtime = new DeviceRuntime()
     {
         DevIDNO = devIDNO
     };
 }
Ejemplo n.º 3
0
        internal static void Create(DeviceRuntime runtime, LisconDbEntities db)
        {
            // Todo: Check Editability

            runtime.CreateUserID = -1;
            runtime.CreateTime   = DateTime.UtcNow;
            runtime.UpdateUserID = -1;
            runtime.UpdateTime   = DateTime.UtcNow;

            db.DeviceRuntime.Add(runtime);
            db.SaveChanges();
        }
Ejemplo n.º 4
0
        public static void Update(DeviceRuntime runtime, LisconDbEntities db)
        {
            var existingRuntime = db.DeviceRuntime.Single(q => q.DevIDNO == runtime.DevIDNO);

            existingRuntime.GpsTime   = runtime.GpsTime;
            existingRuntime.Latitude  = runtime.Latitude;
            existingRuntime.Longitude = runtime.Longitude;
            existingRuntime.Altitude  = runtime.Altitude;
            existingRuntime.Speed     = runtime.Speed;
            existingRuntime.Course    = runtime.Course;

            db.SaveChanges();
        }
Ejemplo n.º 5
0
        public IActionResult GetDeviceStatus(string deviceKey)
        {
            DeviceRuntime dr = this.playManager.GetDeviceRuntime(deviceKey);

            if (dr != null)
            {
                return(SuccessResult(dr.Status.ToDTO(dr)));
            }
            else
            {
                log.Error($"device with key {deviceKey} not found");
                return(ErrorResult($"device with key {deviceKey} not found"));
            }
        }
Ejemplo n.º 6
0
        public static void Register(string devIDNO, DeviceRuntime runtime, LisconDbEntities db)
        {
            using (var ts = new TransactionScope())
            {
                var device = new Device();

                device.IDNO         = devIDNO;
                device.Plate        = string.Empty;
                device.CreateUserID = -1;
                device.CreateTime   = DateTime.UtcNow;
                device.UpdateUserID = -1;
                device.UpdateTime   = DateTime.UtcNow;

                db.Device.Add(device);
                db.SaveChanges();

                DeviceRuntimeBL.Create(runtime, db);

                ts.Complete();
            }
        }