Esempio n. 1
0
        public void Connect()
        {
            try
            {
                InsertLog.AddLog("MirasysVCAInterfaceService Connect(): Start");

                if (_connection != null)
                {
                    _connection.ConnectionEvent -= new EventHandler <ConnectionEventArgs>(OnConnectionEvent);
                    _connection.Dispose();
                    _connection = null;
                }
                _connection = new GatewayConnection(MirasysHostIP, Convert.ToInt32(MirasysHostPort), MirasysHostUserName, MirasysHostPassword, TestSDKApplicationCode);
                _connection.ConnectionEvent += new EventHandler <ConnectionEventArgs>(OnConnectionEvent);
                session = _connection.SessionContext;
                session.ErrorHandler.SessionExceptionThrown += new EventHandler <Mirasys.Clients.Gateway.SDK.Events.ExceptionEventArgs>(OnExceptionThrown);;//ErrorHandler_SessionExceptionThrown;
                session.RequestValidation += new EventHandler <RequestValidationEventArgs>(OnRequestValidation);
                session.ProfileService.ProfileEventReceived += new EventHandler <ProfileEventArgs>(OnProfileEventReceived);
                session.ProfileService.UserStatusChanged    += new EventHandler <AuthenticationEventArgs>(OnUserStatusChanged);

                //session.RecorderEventService.RecorderEventReceived += new EventHandler<RecorderEventArgs>(OnRecorderEventReceived);


                _connection.Connect();
            }
            catch (Exception ex)
            {
                InsertLog.AddLog("MirasysVCAInterfaceService Connect(): Exception " + ex.Message);
            }
        }
Esempio n. 2
0
        private void OnAlarmEventReceived(System.Object aSource, AlarmEventArgs aAlarmEventArgs)
        {
            try
            {
                //UpdateAlarmEventRow(aAlarmEventArgs.AlarmEvent);
                AlarmNode alarmProfile = _aAlarmService.GetAlarmProfile(aAlarmEventArgs.AlarmEvent.AlarmProfileId);
                if (alarmProfile != null)
                {
                    String strEventCode     = "";
                    String strAlarmDateTime = "";
                    String strDevName       = "";
                    String CamGuid          = "b42d6cf5-313d-4ff8-b49d-74c2e91124cd";
                    string strEventTemp     = alarmProfile.Name;

                    strDevName = aAlarmEventArgs.AlarmEvent.AlarmConfiguration.AlarmTrigger.ChannelName;

                    InsertLog.AddLog("MirasysVCAInterfaceService CamGuid ProfileId:" + alarmProfile.ProfileId);

                    if (alarmProfile.ProfileId != null && alarmProfile.ProfileId != "")
                    {
                        CamGuid = alarmProfile.ProfileId;
                    }


                    if (strEventTemp.Contains(strDevName))
                    {
                        strEventTemp = strEventTemp.Replace("_" + strDevName, "");
                    }

                    strEventCode = strEventTemp;// aAlarmEventArgs.AlarmEvent.AlarmConfiguration.AlarmTrigger.EventName;

                    strAlarmDateTime = Helper.ToLocalDateTime(aAlarmEventArgs.AlarmEvent.StartTime).ToString();

                    DateTime _datetime   = DateTime.Parse(strAlarmDateTime);
                    string   strDateTime = _datetime.ToUniversalTime().ToString("O");
                    var      _img        = GetImage(CamGuid, strDateTime);
                    byte[]   jpegBytes   = Convert.FromBase64String(_img);

                    InsertLog.AddLog("MirasysVCAInterfaceService Connect() before CreateVaAlert: strDevName " + strDevName + "--!--strEventCode:" + strEventCode + "--!--strAlarmDateTime:" + strAlarmDateTime + "--!--strDateTime:" + strDateTime);


                    CreateVaAlert(strDevName, strEventCode, strAlarmDateTime, jpegBytes);

                    System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        string strResult = strDevName + "   " + strEventCode + "    " + strAlarmDateTime;
                        MainWindow.txtResult.AppendText(strResult + "\n");
                        if (MainWindow.txtResult.LineCount > 20)
                        {
                            MainWindow.txtResult.Clear();
                        }
                    }));
                }
            }
            catch (Exception ex)
            {
                InsertLog.AddLog("MirasysVCAInterfaceService Connect() before CreateVaAlert:Exception -- " + ex.ToString());
            }
        }
Esempio n. 3
0
        private void OnConnectionEvent(System.Object aSource, ConnectionEventArgs aArgs)
        {
            try
            {
                InsertLog.AddLog("MirasysVCAInterfaceService OnConnectionEvent(): start");

                GatewayConnection connection = (GatewayConnection)aSource;
                // ConsoleWriteLine("Connection event: " + connection.Status.ToString());

                var connStatus = connection.Status;

                if (connection.Status == ConnectionStatus.Connected)
                {
                    //Log Connected
                    try
                    {
                        InsertLog.AddLog("MirasysVCAInterfaceService OnConnectionEvent(): Connected ");
                        System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            string strResult = "Connected";
                            MainWindow.txtResult.AppendText(strResult + "\n");
                            if (MainWindow.txtResult.LineCount > 20)
                            {
                                MainWindow.txtResult.Clear();
                            }
                        }));
                        //_connection.SessionContext.AlarmService
                        //_AlarmEvents = new AlarmEvents(_connection.SessionContext.AlarmService);
                        InsertLog.AddLog("MirasysVCAInterfaceService OnConnectionEvent(): Connected 1 ");// + _connection.SessionContext.);
                    }
                    catch (Exception ex)
                    {
                        InsertLog.AddLog("MirasysVCAInterfaceService OnConnectionEvent(): Exception " + ex.Message);
                    }
                }
                else
                {
                    if (connection.Status == ConnectionStatus.ConnectionFailed)
                    {
                        InsertLog.AddLog("MirasysVCAInterfaceService OnConnectionEvent(): ConnectionFailed ");
                        System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            string strResult = "ConnectionFailed";
                            MainWindow.txtResult.AppendText(strResult + "\n");
                            if (MainWindow.txtResult.LineCount > 20)
                            {
                                MainWindow.txtResult.Clear();
                            }
                        }));
                        //Program.ShowErrorMessageBox(this, "Error occured when connection to Gateway was attempted.", "Connection failed");
                    }
                }
            }
            catch (Exception ex)
            {
                InsertLog.AddLog("MirasysVCAInterfaceService OnConnectionEvent(): Exception 1 " + ex.Message);
            }
        }
Esempio n. 4
0
        public void Dispose()
        {
            try
            {
                Disconnect();
                InsertLog.AddLog("MirasysVCAInterfaceService Dispose()");

                try
                {
                    if (_comboBoxProfileNames != null)
                    {
                        myhost.Child = null;
                        _comboBoxProfileNames.Dispose();
                        myhost.Dispose();
                        myhost = null;
                    }

                    _boxCameraStateEvent.Dispose();
                    _boxCameraStateEvent = null;

                    _boxIoStateEvent.Dispose();
                    _boxIoStateEvent = null;

                    _boxVideoMotionEvent.Dispose();
                    _boxVideoMotionEvent = null;

                    _boxAlarmEvent.Dispose();
                    _boxAlarmEvent = null;
                }
                catch (Exception ex)
                {
                }
                // NativeMethods.FreeConsole();
                //if(ControlFactory.Instance!=null)

                //ControlFactory.Instance.Dispose();
                if (_connection != null)
                {
                    _connection.Dispose();
                }

                session.ErrorHandler.SessionExceptionThrown -= new EventHandler <Mirasys.Clients.Gateway.SDK.Events.ExceptionEventArgs>(OnExceptionThrown);
                session.ProfileService.ProfileEventReceived -= new EventHandler <ProfileEventArgs>(OnProfileEventReceived);
                session.ProfileService.UserStatusChanged    -= new EventHandler <AuthenticationEventArgs>(OnUserStatusChanged);

                _aAlarmService.AlarmEventReceived -= new EventHandler <AlarmEventArgs>(OnAlarmEventReceived);
                _aAlarmService.AlarmException     -= new EventHandler <Mirasys.Clients.Gateway.SDK.Events.ExceptionEventArgs>(OnAlarmException);
                //base.Dispose(disposing);
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 5
0
        void aCamera_StateChanged(object sender, EventArgs e)
        {
            try
            {
                var DeviceNode = sender as DeviceNode;
                if (DeviceNode != null)
                {
                    if (DeviceNode.State != DeviceStatus.NotConfigured)
                    {
                        if (DeviceNode.State == DeviceStatus.Disconnected || DeviceNode.State == DeviceStatus.NoSignal || DeviceNode.State == DeviceStatus.Off || DeviceNode.State == DeviceStatus.Unknown)
                        {
                            //offline call broker method to update
                            var    strStatus  = "Offline"; //DeviceNode.State.ToString();
                            string DeviceName = DeviceNode.Name;
                            string StrGuid    = DeviceNode.ProfileId;

                            Task t = Task.Factory.StartNew(delegate
                            {
                                InsertLog.AddLog("MirasysInterface aCamera_StateChanged() DeviceName:" + DeviceName + "--!--StrGuid:" + StrGuid + "--!--strStatus:" + DeviceNode.State.ToString());

                                var json = JsonServicesHelper.GetJsonResponse("ControllerSetOperation", "UpdateMiracysDeviceStatus", "DeviceName=" + DeviceName, "StrGuid=" + StrGuid, "Status=" + strStatus);
                            })
                                     .ContinueWith((MyResult) =>
                            {
                            });
                        }
                        if (DeviceNode.State == DeviceStatus.OK || DeviceNode.State == DeviceStatus.On)
                        {
                            //online
                            var    strStatus  = "Online";
                            string DeviceName = DeviceNode.Name;
                            string StrGuid    = DeviceNode.ProfileId;

                            Task t = Task.Factory.StartNew(delegate
                            {
                                InsertLog.AddLog("MirasysInterface aCamera_StateChanged() DeviceName:" + DeviceName + "--!--StrGuid:" + StrGuid + "--!--strStatus:" + DeviceNode.State.ToString());

                                var json = JsonServicesHelper.GetJsonResponse("ControllerSetOperation", "UpdateMiracysDeviceStatus", "DeviceName=" + DeviceName, "StrGuid=" + StrGuid, "Status=" + strStatus);
                            })
                                     .ContinueWith((MyResult) =>
                            {
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                InsertLog.AddLog("MirasysInterface aCamera_StateChanged() Exception:" + ex.Message);
            }
        }
Esempio n. 6
0
        private static bool OnValidateCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            bool result = false;

            if (certificate.Subject.Contains("2020ImagingLtd") || certificate.Subject.Contains("cloudinary.com") || certificate.Subject.Contains("smtp.gmail.com") || certificate.Subject.Contains("outlook.com") || certificate.Subject.Contains("2020imaging.com") || certificate.Subject.Contains("pparke.in") || certificate.Subject.Contains("*.googleapis.com, O=Google Inc, L=Mountain View, S=California, C=US") || certificate.Subject.Contains("*.googleapis.com, O=Google LLC, L=Mountain View, S=California, C=US"))
            {
                return(true);
            }
            else
            {
                InsertLog.AddLog("MirasysVCAInterfaceService OnValidateCertificate() new certificate.Subject :" + certificate.Subject);//jatin
                return(true);
                // MessageBox.Show("Kindly install valid certificate from 2020Imaging!");
                // Environment.Exit(1);
            }
            return(result);
        }
Esempio n. 7
0
        public void Disconnect()
        {
            try
            {
                InsertLog.AddLog("MirasysVCAInterfaceService Disconnect(): start ");

                if (_connection != null)
                {
                    _connection.ConnectionEvent -= new EventHandler <ConnectionEventArgs>(OnConnectionEvent);
                    _connection.Disconnect();
                    _connection.Dispose();
                    _connection = null;
                }
            }
            catch (Exception ex)
            {
                InsertLog.AddLog("MirasysVCAInterfaceService Disconnect(): Exception " + ex.Message);
            }
        }
Esempio n. 8
0
        public void CreateVaAlert(string strDevName, string strEventCode, string strAlarmDateTime, byte[] image)
        {
            try
            {
                //create alert here on channael name
                Task t = Task.Factory.StartNew(delegate
                {
                    InsertLog.AddLog("MirasysInterface CreateVaAlert() DeviceName:" + strDevName + "--!--strEventCode:" + strEventCode + "--!--strAlarmDateTime:" + strAlarmDateTime.ToString());

                    // var json = JsonServicesHelper.GetJsonResponse("MirasysVideoAnalyticsService", "ConsumVideoAnalytics", "strDevName=" + strDevName, "strEventCode=" + strEventCode, "strAlarmDateTime=" + strAlarmDateTime);
                    MirasysAlertData _MirasysAlertData = new MirasysAlertData();
                    _MirasysAlertData.AlertDateTime    = strAlarmDateTime;
                    _MirasysAlertData.DeviceName       = strDevName;
                    _MirasysAlertData.Eventcode        = strEventCode;
                    _MirasysAlertData.Imagedata        = image;


                    var json = JsonServicesHelper.GetJsonResponsePost("MirasysVideoAnalyticsService", "ConsumVideoAnalytics", _MirasysAlertData);

                    // var json = JsonServicesHelper.GetJsonResponsePost("MirasysVideoAnalyticsService", "ConsumVideoAnalytics", "strDevName=" + strDevName, "strEventCode=" + strEventCode, "strAlarmDateTime=" + strAlarmDateTime);


                    if (json == null)
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                })
                         .ContinueWith((MyResult) =>
                {
                });
            }
            catch (Exception ex)
            {
            }
            return;
        }
Esempio n. 9
0
        private void OnUserStatusChanged(System.Object aSource, AuthenticationEventArgs aArgs)
        {
            ExecuteSecure(() =>
            {
                ProfileService profileService = (ProfileService)aSource;

                /*ConsoleWriteLine("User status changed: " + profileService.UserStatus.ToString() + " (" + aArgs.AuthenticationStatus.ToString() + ")");
                 * foreach (IApplicationState control in ApplicationControls)
                 * {
                 *  control.OnUserStatusEvent(profileService.UserStatus);
                 * }*/
                if (profileService.UserStatus == UserStatus.LoggedIn)
                {
                    StreamingService streamingService = _connection.SessionContext.StreamingService;

                    //session.ProfileService.GetProfile("Service");

                    //_toolStripLabelMaximumRealtimeStreams.Text = "Maximum real-time streams: " + streamingService.MaximumRealtimeDataStreams.ToString();
                    //_toolStripLabelMaximumPlaybackStreams.Text = "Maximum playback streams: " + streamingService.MaximumPlaybackDataStreams.ToString();
                    _connection.SessionContext.RecorderEventService.SubscribeRecorderEvents(RecorderEventsOn);
                }
                else
                {
                    var strtest = aArgs.AuthenticationStatus.ToString();
                    //Program.ShowErrorMessageBox(this, "You have been logged out - " + aArgs.AuthenticationStatus.ToString(), "Session terminated by host");
                    InsertLog.AddLog("MirasysVCAInterfaceService OnUserStatusChanged(): logged out : " + strtest);

                    System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        new ManualResetEvent(false).WaitOne(5000);

                        Disconnect();
                        Connect();
                    }));

                    InsertLog.AddLog("MirasysVCAInterfaceService OnUserStatusChanged():After Connect");
                }
            });
        }
Esempio n. 10
0
        //public string getCamDeviceList()
        //{
        //    string strResponce = "";
        //    try
        //    {
        //        //foreach (var _mirasys in MirasysVaInterface)
        //        //{
        //        //    try
        //        //    {
        //        //        strResponce = _mirasys.Value.getCamDeviceList();
        //        //    }
        //        //    catch (Exception ex)
        //        //    {
        //        //    }
        //        //}
        //    }
        //    catch (Exception ex)
        //    {
        //    }
        //    return string.Empty;
        //}

        public void Dispose()
        {
            try
            {
                InsertLog.AddLog("MirasysVCAInterfaceService Dispose()");

                try
                {
                    foreach (var _Obj in _MirsyssInterface)
                    {
                        _Obj.Value.Dispose();
                    }
                }
                catch (Exception ex)
                {
                }
                _MirsyssInterface.Clear();
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 11
0
 private void OnExceptionThrown(System.Object aSource, Mirasys.Clients.Gateway.SDK.Events.ExceptionEventArgs aArgs)
 {
     //ConsoleWriteLine("Session exception: " + aArgs.Exception.Message);
     InsertLog.AddLog("MirasysVCAInterfaceService OnExceptionThrown() : " + aArgs.Exception.Message);
 }
Esempio n. 12
0
        public IList <MirasysDeviceDetails> getCamDeviceList()
        {
            string strResponce = "";

            InsertLog.AddLog("MirasysInterface getCamDeviceList() Start:");

            List <MirasysDeviceDetails> MirasysDeviceDetailsList = new List <MirasysDeviceDetails>();

            try
            {
                ProfileNode _aProfileNode = session.ProfileService.CurrentProfile;
                var         _SiteNode     = (SiteNode)_aProfileNode;

                if (_SiteNode != null)
                {
                    var _Count = _SiteNode.Children.Count();
                    if (_Count > 0)
                    {
                        var _CamerasNodelist = _SiteNode.Children.Where(X => X.Name == "Cameras" || X.Name.Contains("Recorder"));// NodeType.Camera || X.NodeType == NodeType.PtzCamera);//"Cameras"
                        foreach (var _CamerasNoderecval in _CamerasNodelist)
                        {
                            var _CamerasNoderec = (SiteNode)_CamerasNoderecval;
                            foreach (var _CamerasNodelocval in _CamerasNoderec.Children)
                            {
                                //var _CamerasNodeloc = (SiteNode)_CamerasNodelocval;
                                // foreach (var _CamerasNode in _CamerasNodeloc.Children)
                                //{

                                InsertLog.AddLog("MirasysInterface getCamDeviceList() Location name:  " + _CamerasNodelocval.Name);

                                var _SiteNodeCameras = (SiteNode)_CamerasNodelocval;
                                if (_SiteNodeCameras.Children.Count() == 0)
                                {
                                }
                                else
                                {
                                    var streamingService = _connection.SessionContext.StreamingService;
                                    var playbackGroup    = streamingService.CreatePlaybackStreamingGroup();
                                    var RealtimeGroup    = session.StreamingService.CreateRealtimeStreamingGroup();

                                    foreach (var _DeviceNode in _SiteNodeCameras.Children)
                                    {
                                        try
                                        {
                                            CameraNode aCamera = _DeviceNode as CameraNode;
                                            if (aCamera.State != DeviceStatus.NotConfigured)
                                            {
                                                MirasysDeviceDetails _MirasysDeviceDetails = new MirasysDeviceDetails();
                                                string strCmName           = "";
                                                string strCamGuid          = "";
                                                string strCamType          = "";//1- camera 2- PTZ Camera
                                                string strCamChannelNumber = "";
                                                string strCamIp            = "";
                                                string strCamUserName      = "";
                                                string strCamPass          = "";
                                                string strCamPortNum       = "";
                                                string strCamWidth         = "";
                                                string strCamHeight        = "";

                                                //
                                                InsertLog.AddLog("MirasysInterface getCamDeviceList() Camera name:  " + aCamera.Name);

                                                strCmName  = aCamera.Name;
                                                strCamGuid = aCamera.ProfileId;
                                                strCamType = aCamera.NodeType.ToString();    //1- camera 2- PTZ Camera

                                                strCamChannelNumber = "";
                                                strCamIp            = "";
                                                strCamUserName      = "";
                                                strCamPass          = "";
                                                strCamPortNum       = "";
                                                strCamWidth         = "";
                                                strCamHeight        = "";

                                                if (strCmName != "" && _MirasysDeviceDetails != null)
                                                {
                                                    _MirasysDeviceDetails.CameraName = strCmName;
                                                }

                                                if (strCamGuid != "" && strCamGuid != null)
                                                {
                                                    _MirasysDeviceDetails.CameraGuid = strCamGuid;
                                                }

                                                if (strCamType != "" && strCamType != null)
                                                {
                                                    _MirasysDeviceDetails.CameraType = strCamType;
                                                }

                                                MirasysDeviceDetailsList.Add(_MirasysDeviceDetails);

                                                //
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            InsertLog.AddLog("MirasysInterface getCamDeviceList() Exception:" + ex.ToString());
                                        }
                                    }
                                }
                                //    }
                            }
                        }
                        //
                    }
                }
                //
            }
            catch (Exception ex)
            {
                InsertLog.AddLog("MirasysInterface getCamDeviceList() Exception Final:" + ex.ToString());
            }
            return(MirasysDeviceDetailsList);
        }
Esempio n. 13
0
        public void CameraStateChangeEventListen()
        {
            try
            {
                ProfileNode _aProfileNode = session.ProfileService.CurrentProfile;
                var         _SiteNode     = (SiteNode)_aProfileNode;

                if (_SiteNode != null)
                {
                    var _Count = _SiteNode.Children.Count();
                    if (_Count > 0)
                    {
                        var _CamerasNodelist = _SiteNode.Children.Where(X => X.Name == "Cameras" || X.Name.Contains("Recorder"));// NodeType.Camera || X.NodeType == NodeType.PtzCamera);//"Cameras"
                        foreach (var _CamerasNoderecval in _CamerasNodelist)
                        {
                            var _CamerasNoderec = (SiteNode)_CamerasNoderecval;
                            foreach (var _CamerasNodelocval in _CamerasNoderec.Children)
                            {
                                //var _CamerasNodeloc = (SiteNode)_CamerasNodelocval;
                                // foreach (var _CamerasNode in _CamerasNodeloc.Children)
                                //{

                                InsertLog.AddLog("MirasysInterface getCamDeviceList() Location name:  " + _CamerasNodelocval.Name);

                                var _SiteNodeCameras = (SiteNode)_CamerasNodelocval;
                                if (_SiteNodeCameras.Children.Count() == 0)
                                {
                                }
                                else
                                {
                                    var streamingService = _connection.SessionContext.StreamingService;
                                    var playbackGroup    = streamingService.CreatePlaybackStreamingGroup();
                                    var RealtimeGroup    = session.StreamingService.CreateRealtimeStreamingGroup();

                                    foreach (var _DeviceNode in _SiteNodeCameras.Children)
                                    {
                                        try
                                        {
                                            CameraNode aCamera = _DeviceNode as CameraNode;

                                            aCamera.StateChanged += aCamera_StateChanged;
                                        }
                                        catch (Exception ex)
                                        {
                                            InsertLog.AddLog("MirasysInterface getCamDeviceList() Exception:" + ex.ToString());
                                        }
                                    }
                                }
                                //    }
                            }
                        }

                        //var _CamerasNodelist = _SiteNode.Children.Where(X => X.Name == "Cameras" || X.Name.Contains("Recorder"));// NodeType.Camera || X.NodeType == NodeType.PtzCamera);//"Cameras"
                        //foreach (var _CamerasNoderecval in _CamerasNodelist)
                        //{
                        //    var _CamerasNoderec = (SiteNode)_CamerasNoderecval;
                        //    foreach (var _CamerasNodelocval in _CamerasNoderec.Children)
                        //    {
                        //        //at office
                        //        try
                        //        {
                        //            CameraNode aCamera = _CamerasNodelocval as CameraNode;
                        //            aCamera.StateChanged += aCamera_StateChanged;

                        //        }
                        //        catch (Exception ex)
                        //        {
                        //            InsertLog.AddLog("MirasysInterface getCamDeviceList() Exception:" + ex.ToString());
                        //        }

                        //    }
                        //}
                        //
                    }
                }
                //
            }
            catch (Exception ex)
            {
            }
        }