Esempio n. 1
0
 private void Client_OnReadMessage(ClientInfo ci, uint code, byte[] bytes, int len)
 {
     if (code == 0) //String
     {
         Console.WriteLine("Received msg from Client[" + ci.ID + "]: " + Encoding.UTF8.GetString(bytes));
         if (ReceiveMessage != null)
         {
             ReceiveMessage.Invoke(Encoding.UTF8.GetString(bytes), EventArgs.Empty);
         }
     }
     else if (code == 1) //File
     {
         File.WriteAllBytes("file.txt", bytes);
     }
     else if (code == 2) //Projection
     {
         string        ret        = string.Empty;
         ProjectionObj projection = ProjectionObj.Deserialize(bytes);
         ReceiveProjection.Invoke(projection, EventArgs.Empty);
     }
     else if (code == 3) //ProjectionManger
     {
         ProjectionManager recManager = ProjectionManager.Deserialize(bytes);
         ReceiveProjectionManager.Invoke(recManager, EventArgs.Empty);
     }
     else
     {
         Console.WriteLine("Unknown msg from server, disregarding...");
     }
 }
Esempio n. 2
0
        private void btnCreateProjection_Click(object sender, EventArgs e)
        {
            if (grid.RowCount == 0)
            {
                MessageBox.Show(this, "Please add a screen first using 'Add Screen'!", "Projection", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            ProjectionCreator pc = new ProjectionCreator();

            pc.ShowDialog(this);
            ProjectionObj projection = (ProjectionObj)pc.Tag;

            if (projection == null)
            {
                return;
            }
            //Ret: Name,Resolution,IP
            string data = ShowSelector();

            if (data == null)
            {
                return;
            }
            string[] splData = data.Split(',');
            string   ip      = splData[2];

            DisplayClient client = new DisplayClient();

            client.Connect(ip);
            client.SendProjection(projection);
            client.Disconnect();
            client = null;
        }
 public void DeleteProjection(ProjectionObj projection)
 {
     if (projection.isDefault)
     {
         return;
     }
     projections.Remove(projection);
 }
 public ProjectionManager(Image img)
 {
     name              = Environment.MachineName;
     projections       = new List <ProjectionObj>();
     defaultProjection = new ProjectionObj(DateTime.Now, DateTime.MinValue, DateTime.MaxValue)
     {
         isDefault = true
     };
     defaultProjection.AddSlide(img);
 }
 public bool HasOverlappingProjection(ProjectionObj projection)
 {
     foreach (ProjectionObj proj in projections)
     {
         if (projection.scheduledDateTimes.First().Intersects(proj.scheduledDateTimes.First()))
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 6
0
 public void SendProjection(ProjectionObj projection)
 {
     byte[] data = projection.Serialize();
     if (data == null || data.Length < 1)
     {
         Console.WriteLine("Serialization failed, unable to send projection.");
     }
     else
     {
         client.SendMessage(2, data);
     }
 }
 public void AddProjection(ProjectionObj projection)
 {
     if (projection.isDefault)
     {
         defaultProjection = projection;
         Console.WriteLine("Default projection replaced");
     }
     else
     {
         projections.Add(projection);
     }
 }
        private void btnOK_Click(object sender, EventArgs e)
        {
            ProjectionObj proj = new ProjectionObj(dtpStart.Value, dtpEnd.Value);

            for (int i = 0; i < gridContent.RowCount; i++)
            {
                string file = (string)gridContent.Rows[i].Cells[0].Value;
                proj.AddSlide(file);
            }
            proj.title = Constants.DEFAULT_TITLE;
            Tag        = proj;
            Close();
        }
        /// <summary>
        /// When a projection is received from client add it to the Projection Manger
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ReceiveProjection(object sender, EventArgs e)
        {
            ProjectionObj projection = (ProjectionObj)sender;

            projectionManager.AddProjection(projection);
            //Switch
            if (currentProjection.isDefault && projection.isDefault)
            {
                //currentProjection = projection;
                //DisplaySlide(projection.GetImages().First());
            }
            Save();
        }
Esempio n. 10
0
        private void Client_OnReadMessage(ClientInfo clientInfo, uint code, byte[] bytes, int length)
        {
            if (code == 0) //String
            {
                string msg = Encoding.UTF8.GetString(bytes);
                if (msg.Equals("RequestName"))
                {
                    string name = projectionManager.GetName();
                    clientInfo.SendMessage(0, Encoding.UTF8.GetBytes(name));
                    return;
                }
                else if (msg.Equals("RequestPM"))
                {
                    clientInfo.SendMessage(3, projectionManager.Serialize());
                    return;
                }
                else if (msg.Equals("RequestRES"))
                {
                    //Screen[] screens = Screen.AllScreens;

                    int width  = Screen.PrimaryScreen.WorkingArea.Width;
                    int height = Screen.PrimaryScreen.WorkingArea.Height;

                    clientInfo.SendMessage(0, Encoding.UTF8.GetBytes(width + "x" + height));
                    return;
                }
                Console.WriteLine("Received msg from Client[" + clientInfo.ID + "]: " + Encoding.UTF8.GetString(bytes));
            }
            else if (code == 1) //File
            {
                File.WriteAllBytes("file.txt", bytes);
            }
            else if (code == 2) //Projection
            {
                ProjectionObj data = ProjectionObj.Deserialize(bytes);
                if (ReceivedProjection != null)
                {
                    ReceivedProjection.Invoke(data, EventArgs.Empty);
                }
                Console.WriteLine("Received projection from client: " + data.scheduledDateTimes.First().Start.ToString("yyyy/MM/dd hh:mm:ss tt"));
            }
            else
            {
                Console.WriteLine("Unknown msg from Client[" + clientInfo.ID + "]");
            }
            clientInfo.SendMessage(0, Encoding.UTF8.GetBytes("Acknowledged"));
        }
Esempio n. 11
0
 private void SendImageToIP(string ip, Image img)
 {
     try
     {
         DisplayClient sender = new DisplayClient();
         sender.Connect(IPAddress.Parse(ip));
         ProjectionObj proj = new ProjectionObj(DateTime.Now, DateTime.Now.AddHours(1))
         {
             isDefault = true
         };
         proj.AddSlide(img);
         sender.SendProjection(proj);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
     }
 }
        private void tmrUpdate_Tick(object sender, EventArgs e)
        {
            if (warmup && --warmup_time_left <= 0)
            {
                warmup = false;
                lblIP.Hide();
            }

            if (currentProjection != null)
            {
                if (currentProjection.isDefault) //Check if scheduled projection is available
                {
                    ProjectionObj schedProj = projectionManager.GetCurrentProjection();
                    if (schedProj != null) //Scheduled Projection is Available
                    {
                        currentProjection = schedProj;
                        intervalWatch.Restart();
                        DisplaySlide(currentProjection.GetImages().First());
                    }
                    else if (!projectionManager.GetDefaultProjection().Equals(currentProjection))
                    {
                        currentProjection = projectionManager.GetDefaultProjection();
                        intervalWatch.Restart();
                        DisplaySlide(currentProjection.GetImages().First());
                    }
                }
                else //non-default projection
                {
                    DateTimeRange currentRange  = new DateTimeRange(DateTime.Now, DateTime.Now.AddSeconds(1));
                    bool          isProjCurrent = currentProjection.scheduledDateTimes.Any(range => range.Intersects(currentRange));
                    if (!isProjCurrent)
                    {
                        //Cleanup
                        //TODO_LATER make sure this won't collide with 'Save' being called when projection is being received
                        projectionManager.DeleteProjection(currentProjection);
                        Save();
                        currentProjection = null;
                        GC.Collect();
                    }
                }

                if (currentProjection != null && currentProjection.GetImages().Count > 1)
                {
                    if (intervalWatch.Elapsed.Seconds >= currentProjection.changeInterval.Seconds)
                    {
                        Console.WriteLine(DateTime.Now.ToString("HH:mm:ss"));
                        intervalWatch.Restart();
                        ++iterator;
                        if (iterator >= currentProjection.GetImages().Count)
                        {
                            iterator = 0;
                        }
                        DisplaySlide(currentProjection.GetImages()[iterator]);
                    }
                }
            }
            //Current projection marked for removal, or initialization
            if (currentProjection == null)
            {
                //Display default image or retrieve current

                currentProjection = projectionManager.GetDefaultProjection();
                intervalWatch.Restart();

                //Add dummy image so fade will be executed
                if (pbProject.Image == null)
                {
                    Bitmap   bmp = new Bitmap(pbProject.Width, pbProject.Height);
                    Graphics g   = Graphics.FromImage(bmp);
                    g.FillRectangle(Brushes.LightGray, 0, 0, pbProject.Width, pbProject.Height);
                    pbProject.Image = bmp;
                }
                DisplaySlide(currentProjection.GetImages().First());
            }
        }
 public ProjectionManager(ProjectionObj proj)
 {
     projections       = new List <ProjectionObj>();
     defaultProjection = proj;
 }