Пример #1
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;
    }
Пример #2
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;
    }
Пример #3
0
    private void ProcessStatusMessage(MessageViewModel message)
    {

        string command = message.Command;

        if (command != null)
        {

            if (!(command == "Make UnAvailable"))
            {

                if (command == "Make Available")
                {

                    CustomerPage.Instance.Update(0x4e20);

                    Switcher.Switch(CustomerPage.Instance);

                    goto Label_014E;

                }

                if (command == "Added Theme")
                {

                    ServiceClient client = new ServiceClient("BasicHttpBinding_IService", Constants.ServerAddress);

                    long mosaicIDForStation = client.GetMosaicIDForStation(Constants.MyStationID);

                    Positions = client.GetPositionsForMosaic(mosaicIDForStation);

                    MainWindow.Instance.LoadPositions(null);

                    goto Label_014E;

                }

                if (command == "Removed Theme")
                {

                    ServiceClient client2 = new ServiceClient("BasicHttpBinding_IService", Constants.ServerAddress);

                    long mosaicID = client2.GetMosaicIDForStation(Constants.MyStationID);

                    Positions = client2.GetPositionsForMosaic(mosaicID);

                    MainWindow.Instance.LoadPositions(null);

                    goto Label_014E;

                }

                if (command == "Screenshot")
                {

                    try
                    {

                        ThreadPool.QueueUserWorkItem(delegate(object hjhj)
                        {

                            string filename = string.Concat(new object[]
                            { "Screenshot#", Constants.MyStationID, "#", string.Format("{0:yyyy-MM-dd_hh-mm-ss-tt}", DateTime.Now), ".jpg"
                            });

                            new ScreenCapture().CaptureScreenToFile(filename, ImageFormat.Jpeg);

                            NameValueCollection nvc = new NameValueCollection();

                            nvc.Add("StationID", Constants.MyStationID.ToString());

                            nvc.Add("btn-submit-photo", "Upload");

                            WebUpload.HttpUploadFile(Constants.ServerUrl + "/Stations/UploadScreenshot", filename, "file", "image/jpeg", nvc);

                        });

                    }

                    catch (Exception)
                    {

                    }

                    goto Label_014E;

                }

            }

            else
            {

                CustomerPage.CurrentRFID = message.Text;

                CustomerPage.Instance.Update(0xea60);

                Switcher.Switch(CustomerPage.Instance);

                goto Label_014E;

            }

        }

        MessageBox.Show(this, message.Text, message.Type, MessageBoxButton.OKCancel, MessageBoxImage.Exclamation);

        Label_014E:

        SendMessageReceipt(message, true);

    }
Пример #4
0
        public ActionResult MosaicUpdated(long id)
        {
            var mosaic = db.Mosaics.Single(g => g.MosaicID == id);
            var groupings = mosaic.Groupings;
            if (groupings != null)
            {

                var message = new MessageViewModel();
                message.Command = "Updated Mosaic";
                message.Type = "Media";
                //   message.UserID =
                message.Text = mosaic.Name;

                foreach (var grouping in groupings)
                {
                    Service.SendMessageToGroup(grouping.GroupingID, message);
                }



                return Json(new { message = "Mosaic Updated" }, JsonRequestBehavior.AllowGet);
            }
            return null;
        }
Пример #5
0
    private static void LoadMosaic(MessageViewModel message)
    {

        ThreadPool.QueueUserWorkItem(delegate(object state)
        {

            try
            {

                ServiceClient client = new ServiceClient("BasicHttpBinding_IService", Constants.ServerAddress);

                long mosaicID = client.GetMosaicIDForStation(Constants.MyStationID);

                Constants.CurrentClientConfiguration.CurrentMosaic=mosaicID;

                Constants.SaveDefaults();

                Positions = client.GetPositionsForMosaic(mosaicID);

                SavePositions(new List<PositionViewModel>(Positions));

                MainWindow.Instance.LoadPositions(null);

                client.SetStationStatus(Constants.MyStationID, "Positions Loaded, Now Playing");

            }

            catch (Exception)
            {

            }

            ServiceClient client2 = new ServiceClient();

            try
            {

                if (message != null)
                {

                    client2.MessageRead(message.ID);

                }

            }

            catch (TimeoutException exception)
            {

                Console.WriteLine("Got {0}", exception.GetType());

                client2.Abort();

            }

            catch (CommunicationException exception2)
            {

                Console.WriteLine("Got {0}", exception2.GetType());

                client2.Abort();

            }

        });

    }
Пример #6
0
    private void ProcessInformationMessage(MessageViewModel message)
    {

        MessageBox.Show(this, message.Text, message.Type, MessageBoxButton.OKCancel, MessageBoxImage.Exclamation);

        ServiceClient client = new ServiceClient();

        try
        {

            client.MessageRead(message.ID);

        }

        catch (TimeoutException exception)
        {

            Console.WriteLine("Got {0}", exception.GetType());

            client.Abort();

        }

        catch (CommunicationException exception2)
        {

            Console.WriteLine("Got {0}", exception2.GetType());

            client.Abort();

        }

        finally
        {

            if (client != null)
            {

                //  client.Dispose();

            }

        }

    }
Пример #7
0
    private static bool CheckMessage(MessageViewModel message)
    {

        bool flag = false;

        if ((from m in UnProcessedMessages

                where (m.Command == message.Command) && (m.Text == message.Text)

                select m).Count<MessageViewModel>() > 0)
        {

            SendMessageReceipt(message, false);

            return false;

        }

        flag = true;

        UnProcessedMessages.Add(message);

        return flag;

    }
Пример #8
0
    private void GetMedia(MessageViewModel message = null)
    {

        ServiceClient client = new ServiceClient("BasicHttpBinding_IService", Constants.ServerAddress);

        try
        {

            MediaListModel[] mediaList = client.GetMyMedia(Constants.MyStationID);

            if (message != null)
            {

                client.MessageRead(message.ID);

            }

            ThreadPool.QueueUserWorkItem(delegate(object e4)
            {

                MediaListModel[] modelArray1 = mediaList;

                for (int j = 0; j < modelArray1.Length; j++)
                {

                    MediaListModel model1 = modelArray1[j];

                }

            });

        }

        catch (TimeoutException exception)
        {

            Console.WriteLine("Got {0}", exception.GetType());

            client.Abort();

        }

        catch (CommunicationException exception2)
        {

            Console.WriteLine("Got {0}", exception2.GetType());

            client.Abort();

        }

        finally
        {

            if (client != null)
            {

                //   client.Dispose();

            }

        }

    }
Пример #9
0
    private static void SendMessageReceipt(MessageViewModel message, bool updateList = true)
    {

        ServiceClient client = new ServiceClient();

        try
        {

            client.MessageRead(message.ID);

        }

        catch (TimeoutException exception)
        {

            Console.WriteLine("Got {0}", exception.GetType());

            client.Abort();

        }

        catch (CommunicationException exception2)
        {

            Console.WriteLine("Got {0}", exception2.GetType());

            client.Abort();

        }

        if (updateList)
        {

            UnProcessedMessages.Remove(message);

        }

    }
Пример #10
0
 public ActionResult RemoveTheme(long stationID, long groupID)
 {
     Grouping grouping = db.Groupings.Single(g => g.GroupingID == groupID);
     var theme = grouping.Themes.Where(s => s.ThemeID == stationID).FirstOrDefault();
     if (theme != null)
     {
         grouping.Themes.Remove(theme);
         db.SaveChanges();
         var message = new MessageViewModel();
         message.Command = "Removed Theme";
         message.Type = "Media";
         //   message.UserID =
         message.Text = theme.ThemeID.ToString();
         Service.SendMessageToGroup(groupID, message);
         return Json(new { message = "Station Removed" }, JsonRequestBehavior.AllowGet);
     }
     else
     {
         return Json(new { message = "Station Does Not Exist" }, JsonRequestBehavior.AllowGet);
     }
 }
Пример #11
0
    public ActionResult Edit(Grouping grouping)
    {
        if (ModelState.IsValid)
        {
            db.Groupings.Attach(grouping);
            db.ObjectStateManager.ChangeObjectState(grouping, EntityState.Modified);
            db.SaveChanges();


            var message = new MessageViewModel();
            message.Command = "Updated Mosaic";
            message.Type = "Media";

            message.Text = grouping.Name;
            Service.SendMessageToGroup(grouping.GroupingID, message);

            return RedirectToAction("Index");
        }
        ViewBag.MosaicID = new SelectList(db.Mosaics, "MosaicID", "Name", grouping.MosaicID);
        return View(grouping);
    }
Пример #12
0
    public JsonResult RemoveStation(long stationID, long groupID)
    {
        Grouping grouping = db.Groupings.Single(g => g.GroupingID == groupID);
        var station = grouping.Stations.Where(s => s.StationID == stationID).FirstOrDefault();
        if (station != null)
        {
            grouping.Stations.Remove(station);
            db.SaveChanges();

            var message = new MessageViewModel();
            message.Command = "Left Group";
            message.Type = "Group";
            //   message.UserID =
            message.Text = groupID.ToString();
            Service.SendMessageToStation(stationID, message);
            return Json(new { message = "Station Removed" }, JsonRequestBehavior.AllowGet);
        }
        else
        {
            return Json(new { message = "Station Does Not Exist" }, JsonRequestBehavior.AllowGet);
        }

    }
Пример #13
0
        private void ProcessStatusMessage(MessageViewModel message)
        {
            string command = message.Command;
            switch (command)
            {
                case null:
                    break;

                case "Make UnAvailable":
                    Charging.CurrentRFID = message.Text;
                    Switcher.Switch(LoadingProfile.Instance);
                    Charging.Instance.Update(60000);
                    goto Label_011C;

                default:
                    if (command == "Make Available")
                    {
                        Charging.Instance.Update(20000);
                        Switcher.Switch(LoadingProfile.Instance);
                    }
                    else if (command == "Added Theme")
                    {
                        new ServiceClient("BasicHttpBinding_IService", Constants.ServerAddress).GetMosaicIDForStationKey(new HardwareKey().Key);
                    }
                    else if (command == "Removed Theme")
                    {
                        new ServiceClient("BasicHttpBinding_IService", Constants.ServerAddress).GetMosaicIDForStationKey(new HardwareKey().Key);
                    }
                    else
                    {
                        if (!(command == "Screenshot"))
                        {
                            break;
                        }
                        try
                        {
                            ThreadPool.QueueUserWorkItem(delegate(object k)
                            {
                                string filename = string.Concat(new object[] { "Screenshot#", new HardwareKey().Key, "#", string.Format("{0:yyyy-MM-dd_hh-mm-ss-tt}", DateTime.Now), ".jpg" });
                                new ScreenCapture().CaptureScreenToFile(filename, ImageFormat.Jpeg);
                                NameValueCollection values = new NameValueCollection();
                                values.Add("StationID", new HardwareKey().Key);
                                values.Add("btn-submit-photo", "Upload");
                            });
                        }
                        catch (Exception)
                        {
                        }
                    }
                    goto Label_011C;
            }
            MessageBox.Show(this, message.Text, message.Type, MessageBoxButton.OKCancel, MessageBoxImage.Exclamation);
        Label_011C:
            SendMessageReceipt(message, true);
        }