Ejemplo n.º 1
0
        public LastActiveResult checkLastActive()
        {
            LastActiveResult lastActiveResult = new LastActiveResult()
            {
                IsLogged = false, Seconds = 0
            };

            try
            {
                HttpClient client = new HttpClient();
                string     method = "CheckLastActive?GUID=" + ClsCommon.UserId;

                client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/json"));
                HttpResponseMessage response = client.GetAsync(ClsCommon.APIBASEURL + method).Result;
                if (response.IsSuccessStatusCode)
                {
                    string responsestr = response.Content.ReadAsStringAsync().Result;
                    lastActiveResult = JsonConvert.DeserializeObject <LastActiveResult>(responsestr);
                }
                else
                {
                    ClsCommon.WriteLog(response.Content.ReadAsStringAsync().Result);
                }
                return(lastActiveResult);
            }
            catch (Exception ex)
            {
                ClsCommon.WriteLog(ex.Message + " Mthod :- CheckLastActive");
                //   ClsCommon.WriteLog(ex.Message+" Mthod :- CheckLastActive");
                return(lastActiveResult);
            }
        }
Ejemplo n.º 2
0
 public bool SaveEntry(string UserId, string URL, int LogType)
 {
     try
     {
         HttpClient client = new HttpClient();
         string     method = "";
         if (URL.Trim() == "")
         {
             method = "/SaveLogEntry?UserId=" + UserId + "&LogType=" + LogType;
         }
         else
         {
             method = "/SaveLogEntry?UserId=" + UserId + "&URL=" + URL + "&LogType=" + LogType;
         }
         // client.BaseAddress = new Uri(URL);
         client.DefaultRequestHeaders.Accept.Add(
             new MediaTypeWithQualityHeaderValue("application/json"));
         HttpResponseMessage response = client.GetAsync(ClsCommon.APIBASEURL + method).Result;
         //var dataObjects = response.Content.Result;
         return(true);
     }catch (Exception ex)
     {
         ClsCommon.WriteLog(ex.Message + " Mthod=SaveEntry");
         return(false);
     }
 }
Ejemplo n.º 3
0
        public bool exeConfig()
        {
            try
            {
                HttpClient client = new HttpClient();
                string     method = "GetEXEConfig";

                client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/json"));
                HttpResponseMessage response = client.GetAsync(ClsCommon.APIBASEURL + method).Result;
                if (response.IsSuccessStatusCode)
                {
                    string    responsestr = response.Content.ReadAsStringAsync().Result;
                    EXEConfig eXEConfig   = JsonConvert.DeserializeObject <EXEConfig>(responsestr);
                    ClsCommon.TimeToexit = eXEConfig.TimeToExit;
                    ClsCommon.Interval   = eXEConfig.TimeInterval;
                }
                else
                {
                    ClsCommon.WriteLog(response.Content.ReadAsStringAsync().Result + " Mthod :- getConfig");
                }
                return(true);
            }
            catch (Exception ex)
            {
                ClsCommon.WriteLog(ex.Message + " Mthod :- getConfigexception");
                return(false);
            }
        }
Ejemplo n.º 4
0
        private void waveSource_DataAvailable(object sender, WaveInEventArgs e)
        {
            try
            {
                //if (waveFile != null)
                // {
                //  waveFile.Write(e.Buffer, 0, e.BytesRecorded);
                //waveFile.Flush();
                if (_firstAudio)
                {
                    if (!WaitForConnection(_audioPipe, 5000))
                    {
                        throw new Exception("Cannot connect Audio pipe to FFmpeg");
                    }

                    _firstAudio = false;
                }

                _lastAudio?.Wait();

                _lastAudio = _audioPipe.WriteAsync(e.Buffer, 0, e.Buffer.Length);
                // }
            }
            catch (Exception ex)
            {
                ClsCommon.WriteLog(ex.Message + "   Method :- AUDIO Data Available.");
            }
        }
Ejemplo n.º 5
0
        public void StartCamera(FilterInfo filterInfo = null, PictureBox pictureBox = null)
        {
            try
            {
                if (IsDesktopSource)
                {
                    if (File.Exists(Program.Localpath + "\\resolution.txt"))
                    {
                        var str = File.ReadAllText(Program.Localpath + "\\resolution.txt").Split('_');
                        Program.width  = int.Parse(str[0]);
                        Program.height = int.Parse(str[1]);
                        wf             = float.Parse(str[2]);
                        hf             = float.Parse(str[3]);
                    }
                    else
                    {
                        Program.width  = SystemInformation.VirtualScreen.Width;
                        Program.height = SystemInformation.VirtualScreen.Height;
                    }
                    ClsCommon.WriteLog(Environment.OSVersion.Version.Major + "   Major " + Environment.OSVersion.Version.Major + "  Minor.   METHOD :- StartCamera();");
                    var rectangle = new Rectangle(0, 0, Program.width, Program.height);
                    heigth = rectangle.Height;
                    widht  = rectangle.Width;
                    ClsCommon.WriteLog(heigth + "X" + widht + " Method :- Screen Height and width.");
                    _videoSource           = new ScreenCaptureStream(rectangle);
                    _videoSource.NewFrame += video_NewFrame;
                    _videoSource.Start();
                }
                else if (IsWebcamSource)
                {
                    _PictureBox   = pictureBox;
                    CurrentDevice = filterInfo;

                    if (CurrentDevice != null)
                    {
                        _videoSource           = new VideoCaptureDevice(CurrentDevice.MonikerString);
                        _videoSource.NewFrame += video_NewFrame;
                        _videoSource.Start();
                        var video = new VideoCaptureDevice(CurrentDevice.MonikerString).VideoCapabilities;
                        heigth = video[0].FrameSize.Height;
                        widht  = video[0].FrameSize.Width;
                        ClsCommon.WriteLog(heigth + "X" + widht + " Method :- video Height and width.");
                    }
                    else
                    {
                        MessageBox.Show("Current device can't be null");
                    }
                }
                else if (IsIpCameraSource)
                {
                    _videoSource           = new MJPEGStream(IpCameraUrl);
                    _videoSource.NewFrame += video_NewFrame;
                    _videoSource.Start();
                }
            }
            catch (Exception ex)
            {
                ClsCommon.WriteLog(ex.Message + " Method :- Start Camera");
            }
        }
Ejemplo n.º 6
0
        private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            try
            {
                if (IsWebcamSource)
                {
                    _PictureBox.Image = (Bitmap)eventArgs.Frame.Clone();
                }
                if (_recording)
                {
                    using (var bitmap = (Bitmap)eventArgs.Frame.Clone())
                    {
                        Bitmap bitmapnew;
                        bitmapnew = bitmap;
                        if (IsDesktopSource)
                        {
                            bitmapnew = CaptureScreen(true, bitmap);
                        }
                        // var _videoBuffers = ImageToByte(bitmapnew);
                        var bits = bitmapnew.LockBits(new Rectangle(System.Drawing.Point.Empty, bitmapnew.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb);

                        Parallel.For(0, heigth, Y =>
                        {
                            var absStride = Math.Abs(bits.Stride);

                            Marshal.Copy(bits.Scan0 + (Y * bits.Stride), _videoBuffer, Y * absStride, absStride);
                        });

                        bitmapnew.UnlockBits(bits);
                        if (_firstFrameTime != null)
                        {
                            _lastFrameTask?.Wait();
                            _lastFrameTask = _ffmpegIn.WriteAsync(_videoBuffer, 0, _videoBuffer.Length);
                        }
                        else
                        {
                            if (_firstFrame)
                            {
                                Thread.Sleep(300);
                                if (!WaitForConnection(_ffmpegIn, 5000))
                                {
                                    throw new Exception("Cannot connect Video pipe to FFmpeg");
                                }
                                _firstFrame = false;
                            }
                            _firstFrameTime = DateTime.Now;
                            _lastFrameTask?.Wait();
                            _lastFrameTask = _ffmpegIn.WriteAsync(_videoBuffer, 0, _videoBuffer.Length);
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                ClsCommon.WriteLog(exc.Message + "  METHOD :- New Video Frame");
                //MessageBox.Show("Error on _videoSource_NewFrame:\n" + exc.Message, "Error", MessageBoxButtons.OK,
                //    MessageBoxIcon.Error);
                //StopCamera();
            }
        }
Ejemplo n.º 7
0
 void Getresolution()
 {
     try
     {
         Process pr = new Process();
         pr.StartInfo.FileName = Application.ExecutablePath.Replace("ScreenRecorder.exe", "") + "\\resolution.exe";
         //  pr.StartInfo.Arguments = "test.dat";
         pr.Start();
         while (pr.HasExited == false)
         {
             if ((DateTime.Now.Second % 1) == 0)
             {
                 // Show a tick every five seconds.
                 Console.Write(".");
                 System.Threading.Thread.Sleep(50);
             }
         }
         //Process.Start(Application.ExecutablePath.Replace("ScreenRecorder.exe","") +"\\resolution.exe").WaitForExit();
         base.Invoke(new MethodInvoker(() =>
         {
             form1 = new Form1();
             form1.StartCamera();
         }));
         //  ClsCommon.WriteLog(Application.ExecutablePath + " Method:- GetResolution.");
     }
     catch (Exception ex)
     {
         ClsCommon.WriteLog(ex.Message + " Method:- GetResolution.");
     }
 }
Ejemplo n.º 8
0
        public void ffmpegWriter()
        {
            try
            {
                if (File.Exists(Program.Localpath + "\\output.mp4"))
                {
                    File.Delete(Program.Localpath + "\\output.mp4");
                }

                _videoBuffer = new byte[widht * heigth * 4];
                var    audioPipeName = GetPipeName();
                var    videoPipeName = GetPipeName();
                string audioInArgs = "", audioOutArgs = "";

                var    videoInArgs  = $@" -thread_queue_size 512 -use_wallclock_as_timestamps 1 -f rawvideo -pix_fmt rgb32 -video_size {widht}x{heigth} -i \\.\pipe\{videoPipeName}";
                string videoOutArgs = "";
                if (IsDesktopSource)
                {
                    videoOutArgs = $"-vcodec libx264 -crf 15 -pix_fmt yuv420p -preset ultrafast -r 10";
                }
                else
                {
                    videoOutArgs = "-vcodec libx264 -crf 25 -pix_fmt yuv420p -preset ultrafast -r 10";
                }
                if (_isAudio)
                {
                    audioInArgs = $" -thread_queue_size 512 -f s16le -acodec pcm_s16le -ar 44100 -ac 2 -i {PipePrefix}{audioPipeName}";
                    //audioOutArgs = "-c:a aac -strict -2 -b:a 256k";
                    audioOutArgs = "-c:a aac -strict -2 -b:a 256k";
                    var audioBufferSize = (int)((1000.0 / 10) * 44.1 * 2 * 2 * 2);
                    _audioPipe = new NamedPipeServerStream(audioPipeName, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 0, audioBufferSize);
                    _ffmpegIn  = new NamedPipeServerStream(videoPipeName, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 0, _videoBuffer.Length);
                    Process    = StartFFmpeg($"{videoInArgs} {audioInArgs} {videoOutArgs} {audioOutArgs} \"{Program.Localpath + "\\output.mp4"}\"", Program.Localpath + "\\output.mp4");
                }
                else
                {
                    _ffmpegIn = new NamedPipeServerStream(videoPipeName, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 0, _videoBuffer.Length);
                    Process   = StartFFmpeg($"{videoInArgs} {videoOutArgs} \"{Program.Localpath + "\\output.mp4"}\"", Program.Localpath + "\\output.mp4");
                }
            }catch (Exception ex)
            {
                ClsCommon.WriteLog(ex.Message + "  Method :- Start FFMPEG");
            }
        }
Ejemplo n.º 9
0
 private static bool CheckForProtocolMessage()
 {
     string[] arguments = Environment.GetCommandLineArgs();
     if (arguments.Length > 1)
     {
         // Format = "Owf:OpenForm?id=111"
         ClsCommon.WriteLog(arguments[0]);
         string[] args = arguments[1].Split(':');
         if (args[0].Trim().ToUpper() == "TREZLERECORDER" && args.Length > 1)
         { // Means this is a URL protocol
             string[] actionDetail = args[1].Split('?');
             if (actionDetail.Length > 1)
             {
                 switch (actionDetail[0].Trim().ToUpper())
                 {
                 case "OPENFORM":
                     string[] details = actionDetail[1].Split('=');
                     if (details.Length > 1)
                     {
                         if (details[0] == "IdRecord")
                         {
                             eRequestFor = RequestFor.VideoRecording;
                         }
                         else
                         {
                             eRequestFor = RequestFor.ScreenRecording;
                         }
                         if (actionDetail.Length > 2)
                         {
                             exestring = actionDetail[2].Split('=')[1];
                         }
                         string id = details[1].Trim();
                         ClsCommon.UserId = id;
                         return(true);
                     }
                     break;
                 }
             }
         }
     }
     return(false);
 }
Ejemplo n.º 10
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                // if(count==3)
                //{

                //    if (Program.eRequestFor == RequestFor.ScreenRecording)
                //    {
                //        form1 = new Form1();
                //        Thread thread = new Thread(Getresolution);
                //        thread.Start();
                //    }
                //}
                if (count == 1)
                {
                    lblTimer.Text = "Start";
                    // Thread threads = new Thread(GetConfig);
                    // threads.Start();
                }
                else if (count == 0)
                {
                    timer1.Stop(); this.Hide();
                    if (Program.eRequestFor == RequestFor.ScreenRecording)
                    {
                        form1.Show();
                    }
                    else
                    {
                        this.Hide();
                    }
                }
                else
                {
                    lblTimer.Text = (count - 1).ToString();
                }
                count--;
            }catch (Exception ex)
            {
                ClsCommon.WriteLog(ex.Message + " Method:- Timer Tick.");
            }
        }
Ejemplo n.º 11
0
        static void Main()
        {
            //Thread.Sleep(20000);
            ClsCommon.UserId = "test";
            //MessageBox.Show(Environment.OSVersion.ToString());
            // GetParent();

            string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\ScreenRecorder";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            Localpath = path;
            ClsCommon.WriteLog("**************************************************************************");
            ClsCommon.WriteLog("**************************************************************************");
            ClsCommon.WriteLog("Application Launched.");
            //if (!CheckForProtocolMessage())
            if (false)
            {
                MessageBox.Show("Please launch the Screen Recorder only from the Trezle coaching application.");
                Environment.Exit(1);
            }
            else
            {
                Thread threadLog = new Thread(SaveLog);
                threadLog.Start();
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                if (eRequestFor == RequestFor.ScreenRecording)
                {
                    Application.Run(new timerform());
                }
                else
                {
                    RecordVideo.IsRecordLoad = true;
                    Application.Run(new timerform());
                }
            }
        }
Ejemplo n.º 12
0
 void StartAudioRecord(int AudioDeviceIndex, int Channel)
 {
     try
     {
         waveSource            = new NAudio.Wave.WaveIn();
         waveSource.WaveFormat = new NAudio.Wave.WaveFormat(44100, Channel);
         waveSource            = new WaveIn
         {
             DeviceNumber       = AudioDeviceIndex,
             BufferMilliseconds = (int)Math.Ceiling((double)(1000 / 10)),
             NumberOfBuffers    = 3,
             WaveFormat         = new WaveFormat(44100, 16, Channel)
         };
         waveSource.DataAvailable    += new EventHandler <WaveInEventArgs>(waveSource_DataAvailable);
         waveSource.RecordingStopped += new EventHandler <StoppedEventArgs>(waveSource_RecordingStopped);
         // waveFile = new NAudio.Wave.WaveFileWriter(Program.Localpath+"\\raw.wav", waveSource.WaveFormat);
         waveSource.StartRecording();
     }
     catch (Exception ex)
     {
         ClsCommon.WriteLog(ex.Message + "  Method :-Start Audio Recording.");
     }
 }