Ejemplo n.º 1
0
        Stream IWebCamService.getWebCamImage(string loginName)
        {
            int indexUser = clientUserBuffer.FindIndex(p => p.LoginName == loginName);
            DateTime dtIn = DateTime.Now;
            DateTime dt = dtIn;
            if (indexUser >= 0)
            {
                dtIn = clientUserBuffer[indexUser].DateIn;
                clientUserBuffer.RemoveAll(p => p.LoginName == loginName);
                bufferUserList mynewuser = new bufferUserList() { LoginName = loginName, DateIn = dtIn, DateStamp = dt };
                clientUserBuffer.Add(mynewuser);
            }

            MemoryStream ms = new MemoryStream();
            if (newImage != null)
            {
                lock (newImage)
                {
                    /*RectangleF rectf = new RectangleF(0, newImage.Size.Height-50, 250, 50);

                    Graphics g = Graphics.FromImage(newImage);

                    g.SmoothingMode = SmoothingMode.AntiAlias;
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                    g.DrawString("www.soheyln.com", new Font("Tahoma", 18), Brushes.Yellow, rectf);
                    g.Flush();*/

                    lock (ms)
                    {
                        newImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                        ms.Position = 0;
                    }
                }

                //WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
                return ms;

            }
            else
            {
                return null;
            }
        }
Ejemplo n.º 2
0
        public void Record(string loginName, string cValue, string cName, string lID, string cID)
        {
            //Console.WriteLine(DateTime.Now.ToShortTimeString());
            lastDevType = "camera";
            startCheckUserTimer();
            FilterInfoCollection videoDevices;
            string camDescr;
            try
            {
                videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
                if (videoDevices.Count == 0)
                {
                    throw new ApplicationException("no webcams");
                }
                else
                {
                    camName = videoDevices[Convert.ToInt32(cValue)].MonikerString;
                    camDescr = videoDevices[Convert.ToInt32(cValue)].Name;
                }
            }
            catch (ApplicationException)
            {
                throw new ApplicationException("failed web cams initialize");
            }

            if (clientUserBuffer != null)
            {
                if (clientUserBuffer.FindIndex(p => p.LoginName == loginName) >= 0)
                {
                    clientUserBuffer.RemoveAll(p => p.LoginName == loginName);
                    clientID--;
                }
            }

            clientID++;
            Console.WriteLine(string.Format("\n{0} , client : {1} , Name : {2} , webCam : {3} on {4}", DateTime.Now.ToShortTimeString(), clientID, loginName, camDescr, cName));

            lastLabID = lID;
            lastDevID = cID;

            AddUserToUserLiveLog(loginName);

            if (clientID == 1)
            {
                clientUserBuffer = new List<bufferUserList>();
                bufferUserList newuser = new bufferUserList() { LoginName = loginName, DateIn = DateTime.Now, DateStamp = DateTime.Now };
                clientUserBuffer.Add(newuser);

                if (videoSource != null)
                    return;
            }

            if (clientUserBuffer.FindIndex(p => p.LoginName == loginName) >= 0)
                clientUserBuffer.RemoveAll(p => p.LoginName == loginName);

            bufferUserList mynewuser = new bufferUserList() { LoginName = loginName, DateIn = DateTime.Now, DateStamp = DateTime.Now };
            clientUserBuffer.Add(mynewuser);

            if (videoSource != null)
                return;

            videoSource = new VideoCaptureDevice(camName);
            videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
            videoSource.DesiredFrameSize = new Size(320, 240);//new Size(480, 360);
            videoSource.DesiredFrameRate = 10;
            videoSource.Start();

            if (timerUploadImage == null)
            {
                timerUploadImage = new System.Timers.Timer(300);
                timerUploadImage.Elapsed += new ElapsedEventHandler(timerUploadImage_Tick);
                timerUploadImage.Start();
            }
        }
Ejemplo n.º 3
0
        public string getNewSerialData(string loginName, ref DateTime lastDate)
        {
            string NewLine = "Null";

            int indexUser = clientUserBuffer.FindIndex(p => p.LoginName == loginName);
            DateTime dtIn = DateTime.Now;
            DateTime dt = dtIn;
            string userPermission = "";
            if (indexUser >= 0)
            {
                dtIn = clientUserBuffer[indexUser].DateIn;
                userPermission = clientUserBuffer[indexUser].Permission;
                clientUserBuffer.RemoveAll(p => p.LoginName == loginName);
            }
            bufferUserList mynewuser = new bufferUserList() { LoginName = loginName, DateIn = dtIn, Permission = userPermission, DateStamp = dt };
            clientUserBuffer.Add(mynewuser);

            if (arduinoSerialDataBuffer.Count == 0)
            {
                lastDate = DateTime.Now;
                return NewLine;
            }

            string serialDataLines = "";
            int listCount = arduinoSerialDataBuffer.Count;
            dt = DateTime.Now;

            for (int i = (listCount - 1); i >= 0; i--)
            {
                if (arduinoSerialDataBuffer[i].DateIn >= lastDate)
                {
                    serialDataLines = string.Format("[{0}]@@@{1}@@@{2}§§§",
                                                    arduinoSerialDataBuffer[i].DateIn,
                                                    arduinoSerialDataBuffer[i].LoginName,
                                                    arduinoSerialDataBuffer[i].Content) +
                                                    serialDataLines;
                    dt = arduinoSerialDataBuffer[i].DateIn;
                }
                else
                    break;
            }
            if (serialDataLines != "")
                NewLine = serialDataLines;

            lastDate = dt.AddMilliseconds(10);//DateTime.Now;
            /*
                        var json = new JavaScriptSerializer().Serialize(chatTextBuffer);
                        NewLine = json.ToString();
            */
            if (arduinoSerialDataBuffer.Count > 200)
                arduinoSerialDataBuffer.RemoveRange(0, 100);

            return NewLine;
        }
Ejemplo n.º 4
0
        public string getNewChatLine(string loginName, ref DateTime lastDate)
        {
            string NewLine = "Null";

            int indexUser = clientUserBuffer.FindIndex(p => p.LoginName == loginName);
            DateTime dtIn = DateTime.Now;
            DateTime dt = dtIn;
            if (indexUser >= 0)
            {
                dtIn = clientUserBuffer[indexUser].DateIn;
                clientUserBuffer.RemoveAll(p => p.LoginName == loginName);
            }
            bufferUserList mynewuser = new bufferUserList() { LoginName = loginName, DateIn = dtIn, DateStamp = dt };
            clientUserBuffer.Add(mynewuser);

            if (chatTextBuffer.Count == 0)
            {
                lastDate = DateTime.Now;
                return NewLine;
            }

            string chatLines = "";
            int listCount = chatTextBuffer.Count;

            for (int i = (listCount - 1); i >= 0; i--)
            {
                if (chatTextBuffer[i].DateIn >= lastDate)
                {
                    //chatLines = chatTextBuffer[i].LoginName + ": " + chatTextBuffer[i].Text + "\r\n" + chatLines;
                    chatLines = string.Format("[{0}]@@@{1}@@@{2}§§§", chatTextBuffer[i].DateIn, chatTextBuffer[i].LoginName, chatTextBuffer[i].Content) + chatLines;
                }
                else
                    break;
            }
            if (chatLines != "")
                NewLine = chatLines;

            lastDate = DateTime.Now;
            /*
                        var json = new JavaScriptSerializer().Serialize(chatTextBuffer);
                        NewLine = json.ToString();
            */
            if (chatTextBuffer.Count > 100)
                chatTextBuffer.RemoveRange(0, 50);

            return NewLine;
        }
Ejemplo n.º 5
0
        public string getArduinoUserList(string loginName)
        {
            int indexUser = clientUserBuffer.FindIndex(p => p.LoginName == loginName);
            DateTime dtIn = DateTime.Now;
            DateTime dt = dtIn;
            string userPermission = "";
            if (indexUser >= 0)
            {
                dtIn = clientUserBuffer[indexUser].DateIn;
                userPermission = clientUserBuffer[indexUser].Permission;
                clientUserBuffer.RemoveAll(p => p.LoginName == loginName);
            }
            bufferUserList mynewuser = new bufferUserList() { LoginName = loginName, DateIn = dtIn, Permission = userPermission, DateStamp = dt };
            clientUserBuffer.Add(mynewuser);

            if (clientUserBuffer.Count == 0)
            {
                return "Null";
            }

            var t = Task<string>.Factory.StartNew(() =>
            {
                return new JavaScriptSerializer().Serialize(clientUserBuffer);
            });

            return t.Result;
        }
Ejemplo n.º 6
0
        public void chatStart(string loginName, ref DateTime date)
        {
            lastDevType = "chat";

            startCheckUserTimer();

            if (clientUserBuffer != null)
            {
                if (clientUserBuffer.FindIndex(p => p.LoginName == loginName) >= 0)
                {
                    clientUserBuffer.RemoveAll(p => p.LoginName == loginName);
                    clientID--;
                }
            }

            clientID++;

            Console.WriteLine(string.Format("\n{0} , client : {1} , Name : {2}", DateTime.Now.ToShortTimeString(), clientID, loginName));
            date = DateTime.Now;

            if (clientID == 1)
            {
                chatTextBuffer = new List<bufferTextList>();
                clientUserBuffer = new List<bufferUserList>();
                bufferUserList newuser = new bufferUserList() { LoginName = loginName, DateIn = date, DateStamp = date };
                clientUserBuffer.Add(newuser);

                return;
            }

            if (clientUserBuffer.FindIndex(p => p.LoginName == loginName) >= 0)
                clientUserBuffer.RemoveAll(p => p.LoginName == loginName);

            bufferUserList mynewuser = new bufferUserList() { LoginName = loginName, DateIn = date, DateStamp = date };
            clientUserBuffer.Add(mynewuser);
        }
Ejemplo n.º 7
0
        public void arduinoStart(string loginName, string aPort, string lID, string cID, string userPermission, ref DateTime date)
        {
            lastDevType = "arduino";

            startCheckUserTimer();

            if (clientUserBuffer != null)
            {
                if (clientUserBuffer.FindIndex(p => p.LoginName == loginName) >= 0)
                {
                    clientUserBuffer.RemoveAll(p => p.LoginName == loginName);
                    clientID--;
                }
            }

            clientID++;

            lastLabID = lID;
            lastDevID = cID;

            AddUserToUserLiveLog(loginName);

            Console.WriteLine(string.Format("\n{0} , client : {1} , Name : {2}", DateTime.Now.ToShortTimeString(), clientID, loginName));
            date = DateTime.Now;

            if (clientID == 1)
            {
                arduinoSourceCodeBuffer = new List<bufferTextList>();
                arduinoSerialDataBuffer = new List<bufferTextList>();
                clientUserBuffer = new List<bufferUserList>();
                bufferUserList newuser = new bufferUserList() { LoginName = loginName, Permission = userPermission, DateIn = date, DateStamp = date };
                clientUserBuffer.Add(newuser);

                if (userPermission == "rw")
                {
                    arduinoPort = aPort;
                    arduinoSourceFile = getArduinoTempFile(loginName);
                    batchFilePath = createBatchFiles(arduinoSourceFile, aPort);
                }
                arduinoBoardInterface = new ArduinoBoard(arduinoPort);
                arduinoBoardInterface.OpenArduinoConnection();
                arduinoBoardInterface.arduinoDataReceived += serialData_NewarduinoDataReceived;

                return;
            }

            if (clientUserBuffer.FindIndex(p => p.LoginName == loginName) >= 0)
                clientUserBuffer.RemoveAll(p => p.LoginName == loginName);

            bufferUserList mynewuser = new bufferUserList() { LoginName = loginName, DateIn = date, Permission = userPermission, DateStamp = date };
            clientUserBuffer.Add(mynewuser);
            if (userPermission == "rw")
            {
                arduinoPort = aPort;
                arduinoSourceFile = getArduinoTempFile(loginName);
                batchFilePath = createBatchFiles(arduinoSourceFile, aPort);
            }
        }