Ejemplo n.º 1
0
    public bool CaptureScreenShot(long stationID)
    {
        try
        {
            var container = new eAdEntities();

            var station = (from s in container.Stations
                           where s.StationID == stationID
                           select s).FirstOrDefault<Station>();

            if (station != null)
            {
                station.Available = true;

                var entity = new Message
                {
                    StationID = stationID,
                    Text = "",
                    Command = "Screenshot",
                    Type = "Status",
                    UserID = 1L,
                    DateAdded = DateTime.Now
                };

                container.Messages.AddObject(entity);

                container.SaveChanges();
            }
        }

        catch (Exception)
        {
            return false;
        }

        return true;
    }
Ejemplo n.º 2
0
    public bool MakeStationUnAvailable(long stationID, string rfidCode = "")
    {
        try
        {
            var container = new eAdEntities();

            var station = (from s in container.Stations
                           where s.StationID == stationID
                           select s).FirstOrDefault<Station>();

            if (station != null)
            {
                station.Available = false;

                var entity = new Message
                {
                    StationID = stationID,
                    Text = rfidCode,
                    Command = "Make UnAvailable",
                    Type = "Status",
                    UserID = 1L,
                    DateAdded = DateTime.Now
                };

                container.Messages.AddObject(entity);

                container.SaveChanges();
            }
        }

        catch (Exception)
        {
            return false;
        }

        return true;
    }
Ejemplo n.º 3
0
    public List<PositionViewModel> GetPositionsForMosaic(long mosaicID)
    {
        var container = new eAdEntities();

        List<PositionViewModel> list = new List<PositionViewModel>();
        var firstOrDefault = (container.Mosaics.Where(m => m.MosaicID == mosaicID)).FirstOrDefault();
        if (firstOrDefault != null)
            foreach (Position p in firstOrDefault.Positions)
                list.Add(p.CreateModel());
        return list;
    }
Ejemplo n.º 4
0
    public List<MediaListModel> GetMyMedia(long stationID)
    {
        var container = new eAdEntities();

        var source = new List<MediaListModel>();

        var station = (from s in container.Stations
                       where s.StationID == stationID
                       select s).FirstOrDefault<Station>();

        if (station != null)
        {
            EntityCollection<Grouping> groupings = station.Groupings;

            foreach (Grouping grouping in groupings)
            {
                foreach (Theme theme in grouping.Themes)
                {
                    using (IEnumerator<Medium> enumerator3 = theme.Media.GetEnumerator())
                    {
                        Func<MediaListModel, bool> predicate = null;

                        Medium media;

                        while (enumerator3.MoveNext())
                        {
                            media = enumerator3.Current;

                            if (predicate == null)
                            {
                                predicate = l => l.MediaID == media.MediaID;
                            }

                            if (source.Where(predicate).Count<MediaListModel>() <= 0)
                            {
                                var item = new MediaListModel
                                {
                                    MediaID = media.MediaID,
                                    DisplayLocation = media.Location,
                                    Duration = media.Duration.Value
                                };

                                source.Add(item);
                            }
                        }
                    }
                }
            }
        }

        return source;
    }
Ejemplo n.º 5
0
        public ScheduleModel Schedule(string serverKey, string hardwareKey, string version)
        {
            var container = new eAdEntities();
            Mosaic mosaic = null;
            Mosaic profilemosaic = null;
            Station station = (from s in container.Stations
                         where s.HardwareKey == hardwareKey
                         select s).FirstOrDefault<Station>();
            if (station != null)
            {
                var grouping = (from m in station.Groupings
                                where m.Mosaic != null
                                select m).FirstOrDefault<Grouping>();

                if (grouping != null)
                {
                    mosaic = grouping.Mosaic;
                    profilemosaic = container.Mosaics.Where(mo => mo.MosaicID == grouping.ProfileMosaicID).FirstOrDefault();
                }
            }

            if (mosaic == null)
            {
                mosaic = container.Mosaics.Where(m => m.Type == "General").FirstOrDefault();
            }

            if (profilemosaic == null)
            {
                profilemosaic = container.Mosaics.Where(m => m.Type == "Profile").FirstOrDefault();
            }
            var schedule = new ScheduleModel()
            {
                Items = new List<ScheduleLayout>()
            {
                new ScheduleLayout()
                {
                    File = mosaic.MosaicID.ToString(),
                    FromDate = "2000-01-01 00:00:00",
                    ToDate = "2030-01-19 00:00:00",
                    ScheduleId = 0,
                    Priority = 0,
                    Default = true,
                    Type =mosaic.Type,
                    Hash = mosaic.Hash
                },
                 new ScheduleLayout()
                {
                    File = profilemosaic.MosaicID.ToString(),
                    FromDate = "2000-01-01 00:00:00",
                    ToDate = "2030-01-19 00:00:00",
                    ScheduleId = 0,
                    Priority = 0,
                    Default = true,
                    Type =profilemosaic.Type,
                    Hash = profilemosaic.Hash
                }
            }
            };


            return schedule;

        }
Ejemplo n.º 6
0
    public bool DoIHaveUpdates(long stationID)
    {
        var container = new eAdEntities();

        return ((from s in container.Messages
                 where (s.StationID == stationID) && !s.Sent
                 select s).Count<Message>() > 0);
    }
Ejemplo n.º 7
0
    public bool SendMessageToStation(long stationID, MessageViewModel message)
    {
        try
        {
            var container = new eAdEntities();

            var station = (from s in container.Stations
                           where s.StationID == stationID
                           select s).FirstOrDefault<Station>();

            if (station != null)
            {
                station.Available = false;

                var entity = new Message
                {
                    StationID = station.StationID,
                    DateAdded = DateTime.Now,
                    Text = message.Text,
                    Command = message.Command,
                    Type = message.Type,
                    UserID = message.UserID
                };

                container.Messages.AddObject(entity);
            }

            container.SaveChanges();
        }

        catch (Exception)
        {
            return false;
        }

        return true;
    }
Ejemplo n.º 8
0
    public string SayHiKey(string hardwareKey)
    {
        var container = new eAdEntities();

        var station = (from s in container.Stations
                       where s.HardwareKey == hardwareKey
                       select s).FirstOrDefault<Station>();

        if (station != null)
        {
            station.Available = false;

            station.LastCheckIn = DateTime.Now;

            container.SaveChanges();

            return "Hi there";
        }

        return "Invalid";
    }
Ejemplo n.º 9
0
    public CustomerViewModel GetCustomerByRFID(string tag)
    {
        var container = new eAdEntities();

        var car = (from e in container.Cars
                   where e.RFID == tag
                   select e).FirstOrDefault<Car>();

        if (car != null)
        {
            Customer customer = car.Customer;

            if (customer != null)
            {
                return customer.CreateModel();
            }
        }

        return CustomerViewModel.Empty;
    }
Ejemplo n.º 10
0
    public List<StationViewModel> GetAllStations()
    {
        var container = new eAdEntities();

        return (from c in container.Stations.ToList() select c.CreateModel()).ToList<StationViewModel>();
    }
Ejemplo n.º 11
0
    public List<MessageViewModel> GetAllMyMessagesKey(string hardwareKey)
    {
        var container = new eAdEntities();

        var thisStation = (from s in container.Stations
                           where s.HardwareKey == hardwareKey
                           select s).FirstOrDefault<Station>();

        //Compress up messages

        //TODO:

        return (container.Messages.Where(s => (s.StationID == thisStation.StationID) && !s.Sent)).ToList<Message>().Select(c => c.CreateModel()).ToList();
    }
Ejemplo n.º 12
0
    public List<MessageViewModel> GetAllMyMessages(long clientID)
    {
        var container = new eAdEntities();

        return (from c in
                (from s in container.Messages
                 where (s.StationID == clientID) && !s.Sent
                 select s).ToList<Message>()
                select c.CreateModel()).ToList<MessageViewModel>();
    }
Ejemplo n.º 13
0
    public List<CustomerViewModel> GetAllCustomers()
    {
        var container = new eAdEntities();

        return (from c in container.Customers.ToList() select c.CreateModel()).ToList<CustomerViewModel>();
    }
Ejemplo n.º 14
0
        public FilesModel RequiredFiles(string serverKey, string hardwareKey, string version)
        {
            lock (RequiredFilesLock)
            {


                // Get Mosaic For station
                var container = new eAdEntities();

                var thisStation = (from s in container.Stations
                                   where s.HardwareKey == hardwareKey
                                   select s).FirstOrDefault<Station>();

                if (thisStation == null)
                {
                    thisStation = new Station();
                    thisStation.HardwareKey = hardwareKey;
                    thisStation.Name = hardwareKey;
                    thisStation.LastCheckIn = DateTime.Now;
                    thisStation.Status = "Registered";
                    container.Stations.AddObject(thisStation);
                    container.SaveChanges();
                }
                else
                {
                    thisStation.LastCheckIn = DateTime.Now;
                    thisStation.Status = "Online";
                    container.SaveChanges();
                }

                Mosaic mosaic = null;
                Mosaic profilemosaic = null;
                if (thisStation != null)
                {
                    var grouping = (from m in container.Groupings
                                    where m.Mosaic != null
                                    select m).FirstOrDefault<Grouping>();

                    if (grouping != null)
                    {
                        mosaic = grouping.Mosaic;
                        profilemosaic = container.Mosaics.Where(mo => mo.MosaicID == grouping.ProfileMosaicID).FirstOrDefault();
                    }
                }

                if (mosaic == null)
                {
                    mosaic = (from m in container.Mosaics
                              where m.Name.Contains("as")
                              select m).FirstOrDefault();
                }

                if (profilemosaic == null)
                {
                    profilemosaic = container.Mosaics.Where(m => m.Type == "Profile").FirstOrDefault();
                }

                var mosaicCache = AppPath + "Layouts\\" + mosaic.MosaicID + ".mosaic";
                var profilemosaicCache = AppPath + "Layouts\\" + profilemosaic.MosaicID + ".mosaic";

                if (File.Exists(mosaicCache))
                {
                    if (new FileInfo(mosaicCache).CreationTime < mosaic.Updated)
                    {
                        UpdateMosaicCache(mosaic, mosaicCache);

                    }


                }
                else
                {
                    UpdateMosaicCache(mosaic, mosaicCache);

                }

                if (File.Exists(profilemosaicCache))
                {
                    if (new FileInfo(profilemosaicCache).CreationTime < mosaic.Updated)
                    {
                        UpdateMosaicCache(profilemosaic, profilemosaicCache);

                    }


                }
                else
                {
                    UpdateMosaicCache(profilemosaic, profilemosaicCache);

                }


                container.SaveChanges();
                var files = CreateFileModel(new List<Mosaic> { mosaic, profilemosaic });
                container.SaveChanges();
                return files;
            }
        }
Ejemplo n.º 15
0
    public bool MessageRead(long messageID)
    {
        var container = new eAdEntities();

        IQueryable<Message> queryable = from s in container.Messages
                                        where (s.MessageID == messageID) && !s.Sent
                                        select s;

        foreach (Message message in queryable)
        {
            message.Sent = true;

            message.DateReceived = DateTime.Now;
        }

        container.SaveChanges();

        return true;
    }
Ejemplo n.º 16
0
    public TimeSpan GetMediaDuration(long mediaID)
    {
        var container = new eAdEntities();

        return (from s in container.Media
                where s.MediaID == mediaID
                select s).FirstOrDefault<Medium>().Duration.Value;
    }
Ejemplo n.º 17
0
    public string GetMediaLocation(long mediaID)
    {
        var container = new eAdEntities();

        return (from s in container.Media
                where s.MediaID == mediaID
                select s).FirstOrDefault<Medium>().Location;
    }
Ejemplo n.º 18
0
    public bool SendMessageToGroup(long groupID, MessageViewModel message)
    {
        try
        {
            var container = new eAdEntities();

            var grouping = (from s in container.Groupings
                            where s.GroupingID == groupID
                            select s).FirstOrDefault<Grouping>();

            if (grouping != null)
            {
                foreach (Station station in grouping.Stations)
                {
                    station.Available = false;

                    var entity = new Message
                    {
                        DateAdded = DateTime.Now,
                        StationID = station.StationID,
                        Text = message.Text,
                        Command = message.Command,
                        Type = message.Type,
                        UserID = message.UserID
                    };

                    container.Messages.AddObject(entity);
                }
            }

            container.SaveChanges();
        }

        catch (Exception)
        {
            return false;
        }

        return true;
    }
Ejemplo n.º 19
0
    public long GetMosaicIDForStation(long stationID)
    {
        var container = new eAdEntities();

        if ((from s in container.Stations
                where s.StationID == stationID
                select s).FirstOrDefault<Station>() != null)
        {
            var grouping = (from m in container.Groupings
                            where m.Mosaic != null
                            select m).FirstOrDefault<Grouping>();

            if (grouping != null)
            {
                return grouping.MosaicID;
            }
        }

        return (from m in container.Mosaics
                where m.Name.Contains("as")
                select m).FirstOrDefault<Mosaic>().MosaicID;
    }
Ejemplo n.º 20
0
    public void SetStationStatus(long stationID, string status)
    {
        var container = new eAdEntities();

        foreach (Station station in from s in container.Stations
                 where s.StationID == stationID
                 select s)
        {
            station.Status = status;
        }

        container.SaveChanges();
    }
Ejemplo n.º 21
0
    public long GetMosaicIDForStationKey(string hardwareKey)
    {
        // Get Mosaic For station
        var container = new eAdEntities();

        var thisStation = (from s in container.Stations
                           where s.HardwareKey == hardwareKey
                           select s).FirstOrDefault<Station>();

        if (thisStation != null)
        {
            var grouping = (from m in container.Groupings
                            where m.Mosaic != null && m.Stations.Contains(thisStation)
                            select m).FirstOrDefault<Grouping>();

            if (grouping != null)
            {
                return grouping.MosaicID;
            }
        }

        return (from m in container.Mosaics
                where m.Name.Contains("as")
                select m).FirstOrDefault<Mosaic>().MosaicID;

    }
Ejemplo n.º 22
0
    public bool DoIHaveUpdatesKey(string hardwareKey)
    {
        var container = new eAdEntities();

        var thisStation = (from s in container.Stations
                           where s.HardwareKey == hardwareKey
                           select s).FirstOrDefault<Station>();

        return ((from s in container.Messages
                 where (thisStation.StationID == s.StationID) && !s.Sent
                 select s).Count<Message>() > 0);
    }
Ejemplo n.º 23
0
        private static FilesModel CreateFileModel(List<Mosaic> mosaics)
        {


            FilesModel files = new FilesModel();

            var list = new List<RequiredFileModel>();

            // Get Mosaic For station
            var container = new eAdEntities();



            foreach (var mosaic in mosaics)
            {

                var mosaicCache = AppPath + "Layouts\\" + mosaic.MosaicID + ".mosaic";
                var allPositions = mosaic.Positions.SelectMany(p => p.PositionMediums);

                foreach (var positionMedium in allPositions)
                {

                    var medium = positionMedium.Medium;

                    //  foreach (var medium in allMedia)
                    {

                        if (list.Where(l => l.Id == medium.MediaID).Count() <= 0)
                        {
                            bool shouldCalculatenewHash = false;
                            if (String.IsNullOrEmpty(positionMedium.Location))
                            {


                                if (medium.Hash == null || medium.Size == 0)
                                {
                                    shouldCalculatenewHash = true;
                                }

                                // Calculate new hash/size
                                if (shouldCalculatenewHash)
                                {
                                    try
                                    {

                                        using (
                                            var fs =
                                                new FileStream(
                                                    System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath +
                                                    ServerPath +
                                                    medium.Location, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
                                            )
                                        {
                                            medium.Hash = Hashes.MD5(fs);
                                            medium.Size =
                                                new FileInfo(
                                                    System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath +
                                                    ServerPath + medium.Location).Length;
                                        }
                                    }
                                    catch (Exception)
                                    {


                                    }
                                }
                                list.Add(new RequiredFileModel()
                                {
                                    FileType = "media",
                                    Path = medium.Location,
                                    Id = medium.MediaID,
                                    Size = (long)medium.Size,
                                    MD5 = medium.Hash
                                });
                            }
                            else
                            {
                                if (positionMedium.Hash == null || medium.Size == 0)
                                {
                                    shouldCalculatenewHash = true;
                                }

                                // Calculate new hash/size
                                if (shouldCalculatenewHash)
                                {
                                    try
                                    {

                                        using (
                                            var fs =
                                                new FileStream(
                                                    System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath +
                                                    ServerPath +
                                                    positionMedium.Location, FileMode.Open, FileAccess.Read,
                                                    FileShare.ReadWrite)
                                            )
                                        {
                                            positionMedium.Hash = Hashes.MD5(fs);
                                            positionMedium.Size =
                                                new FileInfo(
                                                    System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath +
                                                    ServerPath + medium.Location).Length;
                                        }
                                    }
                                    catch (Exception)
                                    {


                                    }
                                }
                                list.Add(new RequiredFileModel()
                                {
                                    FileType = "media",
                                    Path = positionMedium.Location,
                                    Id = medium.MediaID,
                                    Size = (long)positionMedium.Size,
                                    MD5 = positionMedium.Hash
                                });
                              
                            }
                        }
                        
                    }
                }
                if (!String.IsNullOrEmpty(mosaic.Background))
                    if (list.Where(l => l.Path == mosaic.Background).Count() <= 0)
                    // Add Background to list if not already there
                    {
                        var allmedia = (from s in container.Media
                                        where s.Location == mosaic.Background
                                        select s).FirstOrDefault();

                        if (allmedia != null)
                            list.Add(new RequiredFileModel
                            {
                                FileType = "media",
                                Path = mosaic.Background,
                                Id = mosaic.MosaicID,
                                Size = allmedia.Size,
                                //    (long)
                                //    new FileInfo(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath +
                                //               ServerPath + mosaic.Background).Length,
                                MD5 = allmedia.Hash
                                //    Hashes.MD5(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath +
                                //    ServerPath + mosaic.Background)
                            });
                    }
                list.Add(new RequiredFileModel
                {
                    FileType = "layout",
                    Path = "Layouts\\" + Path.GetFileName(mosaicCache),
                    Id = mosaic.MosaicID,
                    Size = (long)mosaic.Size,
                    MD5 = mosaic.Hash
                });
            }
            files.Items = new List<RequiredFileModel>(list.ToArray());
            return files;

        }