コード例 #1
0
ファイル: Notifier.cs プロジェクト: jefrisibarani/tobasaqueue
        protected virtual void OnNotifyLog(string source, string message, string summary = "Info")
        {
            NotifyEventArgs args = new NotifyEventArgs();

            args.Summary   = summary;
            args.Source    = source;
            args.Message   = message;
            args.Exception = null;
            args.Type      = NotifyType.NOTIFY_LOG;

            OnNotify(args);
        }
コード例 #2
0
ファイル: Notifier.cs プロジェクト: jefrisibarani/tobasaqueue
        protected virtual void OnNotifyError(string source, Exception ex)
        {
            NotifyEventArgs args = new NotifyEventArgs();

            args.Summary   = ex.GetType().Name;
            args.Source    = source;
            args.Message   = ex.Message;
            args.Exception = ex;
            args.Type      = NotifyType.NOTIFY_ERR;

            OnNotify(args);
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: jhrendon/tobasaqueue
 public void ProcessError(NotifyEventArgs e)
 {
     if (this.InvokeRequired)
     {
         ProcessErrorCallBack d = new ProcessErrorCallBack(ProcessError);
         this.Invoke(d, new object[] { e });
     }
     else
     {
         MessageBox.Show(this, e.Message, e.Summary, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #4
0
ファイル: Notifier.cs プロジェクト: jsibarani/tobasaqueue
 protected virtual void OnNotify(NotifyEventArgs e)
 {
     /*
      * EventHandler<NotifyEventArgs> handler = Notified;
      * if (handler != null)
      * {
      *  handler(this, e);
      * }
      */
     if (Notified != null)
     {
         Notified(e);
     }
 }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: jefrisibarani/tobasaqueue
        private void TCPClientNotified(NotifyEventArgs arg)
        {
            if (this.InvokeRequired)
            {
                TCPClientNotifiedCb dlg = new TCPClientNotifiedCb(TCPClientNotified);
                this.Invoke(dlg, new object[] { arg });
            }
            else
            {
                if (arg.Type == NotifyType.NOTIFY_ERR)
                {
                    MessageBox.Show(arg.Message, arg.Summary, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                Logger.Log(arg);
            }
        }
コード例 #6
0
ファイル: Notifier.cs プロジェクト: jefrisibarani/tobasaqueue
 protected virtual void OnNotifyMessage(NotifyEventArgs e)
 {
     e.Type = NotifyType.NOTIFY_MSG;
     OnNotify(e);
 }
コード例 #7
0
 public static void Log(NotifyEventArgs arg)
 {
     Logger.Log(string.Format("[{0}] {1} : {2}", arg.Source, arg.Summary, arg.Message));
 }
コード例 #8
0
ファイル: Notifier.cs プロジェクト: jefrisibarani/tobasaqueue
 protected virtual void OnNotifyError(NotifyEventArgs e)
 {
     e.Type = NotifyType.NOTIFY_ERR;
     OnNotify(e);
 }
コード例 #9
0
ファイル: Notifier.cs プロジェクト: jefrisibarani/tobasaqueue
 protected virtual void OnNotify(NotifyEventArgs e)
 {
     Notified?.Invoke(e);
 }
コード例 #10
0
ファイル: TCPServer.cs プロジェクト: jsibarani/tobasaqueue
        public bool Start()
        {
            IPEndPoint localEndPoint = GetLocalEndPoint();

            if (localEndPoint == null)
            {
                return(false);
            }

            try
            {
                // Create a TCP/IP socket.
                sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            }
            catch (SocketException e)
            {
                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "SocketException";
                args.Source    = "TCPServer";
                args.Message   = e.Message;
                args.Exception = e;

                OnNotifyError(args);
            }

            // Connect our local client accepted event handler
            // before calling sock.BeginAccept()
            //this.ClientAccepted += new ClientAccepted(this.TCPServer_ClientAccepted);

            // Bind the socket to the local endpoint and listen for incoming connections.
            try
            {
                sock.Bind(localEndPoint);
                sock.Listen(10);

                if (ServerStarted != null)
                {
                    ServerStarted(this);
                }

                while (shuttingDown == false)
                {
                    // Set the event to nonsignaled state.
                    allDone.Reset();

                    // Start an asynchronous socket to listen for connections.
                    sock.BeginAccept(new AsyncCallback(AcceptCallback), sock);

                    // Wait until a connection is made before continuing.
                    allDone.WaitOne();
                }
            }
            catch (SocketException e)
            {
                Close();

                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "SocketException";
                args.Source    = "TCPServer";
                args.Message   = e.Message;
                args.Exception = e;

                OnNotifyError(args);
            }
            catch (ArgumentNullException e)
            {
                Close();

                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "ArgumentNullException";
                args.Source    = "TCPServer";
                args.Message   = e.Message;
                args.Exception = e;

                OnNotifyError(args);
            }
            catch (NullReferenceException e)
            {
                Close();

                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "NullReferenceException";
                args.Source    = "TCPServer";
                args.Message   = e.Message;
                args.Exception = e;

                OnNotifyError(args);
            }
            catch (Exception e)
            {
                Close();

                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "Exception";
                args.Source    = "TCPServer";
                args.Message   = e.Message;
                args.Exception = e;

                OnNotifyError(args);
            }

            return(true);
        }
コード例 #11
0
 private void TCPServer_Notified(NotifyEventArgs arg)
 {
     Logger.Log(arg);
 }
コード例 #12
0
        public void StartDisplay(Panel panel, IntPtr notifyWindow, DisplaySource dispSource, string filename)
        {
            int hr = 0;

            displaySource = dispSource;

            if (dispSource == DisplaySource.Clip)
            {
                if (filename == String.Empty)
                {
                    return;
                }
            }

            try
            {
                graphBuilder = (IGraphBuilder) new FilterGraph();
                // QueryInterface for DirectShow interfaces
                mediaControl  = (IMediaControl)graphBuilder;
                mediaEventEx  = (IMediaEventEx)graphBuilder;
                mediaSeeking  = (IMediaSeeking)graphBuilder;
                mediaPosition = (IMediaPosition)graphBuilder;
                // Query for video interfaces, which may not be relevant for audio files
                videoWindow = graphBuilder as IVideoWindow;
                basicVideo  = graphBuilder as IBasicVideo;
                // Query for audio interfaces, which may not be relevant for video-only files
                basicAudio = graphBuilder as IBasicAudio;

                if (displaySource == DisplaySource.Stream)
                {
                    /// Find source filter ///

                    string     possibleTvTunerName = "Video Capture";
                    DsDevice[] vidInputDevices     = GetVideoInputDevices();

                    for (int i = 0; i < vidInputDevices.Length; i++)
                    {
                        DsDevice possibleTvTuner = vidInputDevices[i];

                        // use first device if none defined
                        if (videoInputDevicePath == "")
                        {
                            videoInputDevicePath = possibleTvTuner.DevicePath;
                        }

                        if (possibleTvTuner.DevicePath != videoInputDevicePath)
                        {
                            continue;
                        }
                        try
                        {
                            if (sourceFilter != null)
                            {
                                Marshal.ReleaseComObject(sourceFilter);
                                sourceFilter = null;
                            }
                            //Create the filter for the selected video input device
                            sourceFilter         = CreateFilterFromPath(FilterCategory.VideoInputDevice, possibleTvTuner.DevicePath);
                            possibleTvTunerName  = possibleTvTuner.Name;
                            videoInputDeviceName = possibleTvTuner.Name;

                            if (sourceFilter == null)
                            {
                                return;
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                            //System.Diagnostics.Debug.WriteLine(ex.ToString());
                        }
                    }
                    ///////////////////////////////////////////////////////////////////////////////////////////
                    captureGraphBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

                    // Attach the filter graph to the capture graph
                    hr = captureGraphBuilder.SetFiltergraph(graphBuilder);
                    DsError.ThrowExceptionForHR(hr);

                    // Add Capture filter to our graph.
                    hr = graphBuilder.AddFilter(sourceFilter, possibleTvTunerName /*"Video Capture"*/);
                    DsError.ThrowExceptionForHR(hr);

                    //// Init tuner/crossbar //////////////////////////////////////////////////////////////////
                    object o;
                    tuner    = null;
                    crossbar = null;

                    hr = captureGraphBuilder.FindInterface(FindDirection.UpstreamOnly, null, sourceFilter, typeof(IAMTVTuner).GUID, out o);
                    //DsError.ThrowExceptionForHR(hr);
                    if (hr >= 0)
                    {
                        tuner = (IAMTVTuner)o;
                        o     = null;

                        hr = captureGraphBuilder.FindInterface(null, null, sourceFilter, typeof(IAMCrossbar).GUID, out o);
                        DsError.ThrowExceptionForHR(hr);
                        if (hr >= 0)
                        {
                            crossbar = (IAMCrossbar)o;
                            //crossbar = (IBaseFilter)o;
                            o = null;
                        }
                        usingCrossBar = true;
                    }
                    else
                    {
                        usingCrossBar = false;
                    }
                    ///////////////////////////////////////////////////////////////////////////////////////////

                    // Render the preview pin on the video capture filter
                    // Use this instead of this.graphBuilder.RenderFile
                    hr = captureGraphBuilder.RenderStream(PinCategory.Preview, DirectShowLib.MediaType.Video, sourceFilter, null, null);
                    DsError.ThrowExceptionForHR(hr);

                    // If we are using tv tuner, force audio on..and set device input from tuner
                    if (tuner != null)
                    {
                        if (videoInputDeviceSource == PhysicalConnectorType.Video_Tuner)
                        {
                            ChangeVideoInputSource(PhysicalConnectorType.Video_Tuner);
                            ChangeAudioInputSource(PhysicalConnectorType.Audio_Tuner);
                        }
                    }

                    // Now that the filter has been added to the graph and we have
                    // rendered its stream, we can release this reference to the filter.
                    // temp
                    //Marshal.ReleaseComObject(sourceFilter);

                    isAudioOnly = false;
                }
                else
                {
                    // Have the graph builder construct its the appropriate graph automatically
                    hr = graphBuilder.RenderFile(filename, null);
                    DsError.ThrowExceptionForHR(hr);

                    // Is this an audio-only file (no video component)?
                    CheckVisibility();
                }

                if (!isAudioOnly)
                {
                    RenderToPanel(panel, notifyWindow);
                    GetFrameStepInterface();
                }
                else
                {
                    /// Initialize the default player size and enable playback menu items
                    /// <jefri> hr = InitPlayerWindow();
                    /// <jefri> DsError.ThrowExceptionForHR(hr);
                    /// <jefri> EnablePlaybackMenu(true, MediaType.Audio);
                }

                currentPlaybackRate = 1.0;

                #if DEBUG
                rot = new DsROTEntry(this.graphBuilder);
                #endif

                // Run the graph to play the media
                hr = mediaControl.Run();
                DsError.ThrowExceptionForHR(hr);

                currentState = PlayState.Running;

                // Every call to this method,volume level will be 0,
                // so inform client to adjust volume level
                // Raise event, so our client can take action for it
                if (PlayerStarted != null)
                {
                    PlayerStarted(new EventArgs());
                }
            }
            catch (COMException ce)
            {
                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "DirectShow Exception";
                args.Source    = ce.Source;
                args.Message   = ce.Message;
                args.Exception = ce;

                OnNotifyError(args);
            }
            catch
            {
                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "DirectShow Exception";
                args.Source    = "";
                args.Message   = "An unrecoverable error has occurred.";
                args.Exception = null;

                OnNotifyError(args);
            }
        }
コード例 #13
0
 private void NetSession_Notified(NotifyEventArgs e)
 {
     OnNotify(e);
 }
コード例 #14
0
 private void NetSession_Notified(NotifyEventArgs arg)
 {
     OnNotify(arg);
 }
コード例 #15
0
 private void NetSession_Notified(NotifyEventArgs e)
 {
     Logger.Log(e.Source + " : " + e.Summary + " : " + e.Message);
     OnNotify(e);
 }
コード例 #16
0
        private void SendCallback(IAsyncResult ar)
        {
            if (socketClosed)
            {
                return;
            }

            try
            {
                // Complete sending the data to the remote device.
                int bytesSent = sock.EndSend(ar);
                Logger.Log(String.Format("NetSession : ID " + Id.ToString() + " Sent {0} bytes data to {1}", bytesSent, RemoteInfo));
            }
            catch (SocketException e)
            {
                Close();

                string msg = "NetSession : ID " + Id.ToString() + " : SocketException : " + e.Message;

                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "SocketException";
                args.Source    = e.Source;
                args.Message   = msg;
                args.Exception = e;

                OnNotifyError(args);
            }
            catch (ArgumentNullException e)
            {
                Close();

                string msg = "NetSession : ID " + Id.ToString() + " : ArgumentNullException : " + e.Message;

                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "ArgumentNullException";
                args.Source    = e.Source;
                args.Message   = msg;
                args.Exception = e;

                OnNotifyError(args);
            }
            catch (ArgumentException e)
            {
                Close();

                string msg = "NetSession : ID " + Id.ToString() + " : ArgumentException : " + e.Message;

                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "ArgumentException";
                args.Source    = e.Source;
                args.Message   = msg;
                args.Exception = e;

                OnNotifyError(args);
            }
            catch (InvalidOperationException e)
            {
                Close();

                string msg = "NetSession : ID " + Id.ToString() + " : InvalidOperationException : " + e.Message;

                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "InvalidOperationException";
                args.Source    = e.Source;
                args.Message   = msg;
                args.Exception = e;

                OnNotifyError(args);
            }
            catch (Exception e)
            {
                Close();

                string msg = "NetSession : ID " + Id.ToString() + " : Exception : " + e.Message;

                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "Exception";
                args.Source    = e.Source;
                args.Message   = msg;
                args.Exception = e;

                OnNotifyError(args);
            }
        }
コード例 #17
0
        public void Send(byte[] data, bool keepalivemsg = false)
        {
            if (socketClosed)
            {
                return;
            }
            try
            {
                // Begin sending the data to the remote device.
                lock (sock)
                {
                    if (keepalivemsg)
                    {
                        sock.BeginSend(data, 0, data.Length, 0, null, this);
                    }
                    else
                    {
                        // convert string length value to network order
                        int dataLengthNBO = IPAddress.HostToNetworkOrder(data.Length);

                        // Get the length prefix for the message
                        byte[] lengthPrefix = BitConverter.GetBytes(dataLengthNBO);

                        // no callback here
                        sock.BeginSend(lengthPrefix, 0, lengthPrefix.Length, 0, null, this);
                        // Send the actual message, this time enabling the normal callback.
                        sock.BeginSend(data, 0, data.Length, 0, new AsyncCallback(SendCallback), this);
                    }
                }
            }
            catch (SocketException e)
            {
                Close();

                string msg = "NetSession : ID " + Id.ToString() + " : SocketException : " + e.Message;

                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "SocketException";
                args.Source    = e.Source;
                args.Message   = msg;
                args.Exception = e;

                OnNotifyError(args);
            }
            catch (ArgumentNullException e)
            {
                Close();

                string msg = "NetSession : ID " + Id.ToString() + " : ArgumentNullException : " + e.Message;

                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "ArgumentNullException";
                args.Source    = e.Source;
                args.Message   = msg;
                args.Exception = e;

                OnNotifyError(args);
            }
            catch (ArgumentOutOfRangeException e)
            {
                Close();

                string msg = "NetSession : ID " + Id.ToString() + " : ArgumentOutOfRangeException : " + e.Message;

                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "ArgumentOutOfRangeException";
                args.Source    = e.Source;
                args.Message   = msg;
                args.Exception = e;

                OnNotifyError(args);
            }
            catch (ObjectDisposedException e)
            {
                Close();

                string msg = "NetSession : ID " + Id.ToString() + " : ObjectDisposedException : " + e.Message;

                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "ObjectDisposed";
                args.Source    = e.Source;
                args.Message   = msg;
                args.Exception = e;

                OnNotifyError(args);
            }
            catch (Exception e)
            {
                Close();

                string msg = "NetSession : ID " + Id.ToString() + " : Exception : " + e.Message;

                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "Exception";
                args.Source    = e.Source;
                args.Message   = msg;
                args.Exception = e;

                OnNotifyError(args);
            }
        }
コード例 #18
0
        private void ReceiveCallback(IAsyncResult ar)
        {
            if (socketClosed)
            {
                return;
            }

            try
            {
                int read = sock.EndReceive(ar);
                ReadData(read);
            }
            catch (SocketException e)
            {
                Close();

                string msg = "NetSession : ID " + Id.ToString() + " : SocketExceptions Code: " + Convert.ToString(e.ErrorCode) + "  " + e.Message;

                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "SocketException";
                args.Source    = e.Source;
                args.Message   = msg;
                args.Exception = e;
                // Notify disconected event - ErrorCode 10054 - SocketErrorCode.ConnectionReset
                //if (e.ErrorCode == 10054)
                //    socketDisconnected = true;
                OnNotifyError(args);
            }
            catch (ArgumentNullException e)
            {
                Close();

                string msg = "NetSession : ID " + Id.ToString() + " : ArgumentNullException : " + e.Message;

                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "ArgumentNullException";
                args.Source    = e.Source;
                args.Message   = msg;
                args.Exception = e;

                OnNotifyError(args);
            }
            catch (InvalidOperationException e)
            {
                Close();

                string msg = "NetSession : ID " + Id.ToString() + " : InvalidOperationException : " + e.Message;

                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "InvalidOperationException";
                args.Source    = e.Source;
                args.Message   = msg;
                args.Exception = e;

                OnNotifyError(args);
            }
            catch (Exception e)
            {
                // Exception throwed by ReadData(), will be handled here

                Close();

                string msg = "NetSession : ID " + Id.ToString() + " : Exception : " + e.Message;

                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "Exception";
                args.Source    = e.Source;
                args.Message   = msg;
                args.Exception = e;

                OnNotifyError(args);
            }
        }
コード例 #19
0
ファイル: MainForm.cs プロジェクト: jhrendon/tobasaqueue
 void TCPClient_Notified(NotifyEventArgs e)
 {
     ProcessError(e);
 }
コード例 #20
0
 private void Database_Notified(NotifyEventArgs arg)
 {
     Logger.Log(arg);
 }
コード例 #21
0
        private Socket GetSocket(string server, int port)
        {
            /// Create socket and connect to a remote device.
            try
            {
                IPAddress ipAddress = null;

                /*
                 * IPHostEntry ipHostInfo = Dns.GetHostEntry(server);
                 *
                 * // Get only IPv4 Address
                 * foreach (IPAddress a in ipHostInfo.AddressList)
                 * {
                 *  if (a.AddressFamily == AddressFamily.InterNetwork)
                 *  {
                 *      ipAddress = a;
                 *      break;
                 *  }
                 * }
                 */

                /// resolv ip dengan GetHostAddresses, karena GetHostEntry
                /// meresolv 192.169.1.1 menjadi 36.22.22.180, bila dns
                /// bukan local lan dns

                IPAddress[] ips;
                ips = Dns.GetHostAddresses(server);

                foreach (IPAddress a in ips)
                {
                    if (a.AddressFamily == AddressFamily.InterNetwork)
                    {
                        ipAddress = a;
                        break;
                    }
                }


                IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);

                /// Create a TCP/IP socket.
                Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                /// Connect to the remote endpoint.
                sock.Connect(remoteEP);

                return(sock);
            }
            catch (SocketException e)
            {
                Logger.Log("TCPClient : SocketException : " + e.Message);

                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "SocketException";
                args.Source    = "TCPClient";
                args.Message   = e.Message;
                args.Exception = e;

                OnNotifyError(args);
            }
            catch (ArgumentNullException e)
            {
                Logger.Log("TCPClient : ArgumentNullException : " + e.Message);

                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "ArgumentNullException";
                args.Source    = "TCPClient";
                args.Message   = e.Message;
                args.Exception = e;

                OnNotifyError(args);
            }
            catch (NullReferenceException e)
            {
                Logger.Log("TCPClient : NullReferenceException : " + e.Message);

                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "NullReferenceException";
                args.Source    = "TCPClient";
                args.Message   = e.Message;
                args.Exception = e;

                OnNotifyError(args);
            }
            catch (Exception e)
            {
                Logger.Log("TCPClient : Exception : " + e.Message);

                NotifyEventArgs args = new NotifyEventArgs();
                args.Summary   = "Exception";
                args.Source    = "TCPClient";
                args.Message   = e.Message;
                args.Exception = e;

                OnNotifyError(args);
            }

            return(null);
        }
コード例 #22
0
ファイル: MainForm.cs プロジェクト: jhrendon/tobasaqueue
 private void DSEngine_Notified(NotifyEventArgs e)
 {
     MessageBox.Show(this, e.Message, e.Summary, MessageBoxButtons.OK, MessageBoxIcon.Error);
 }