示例#1
0
        public static NotifyList GetUsersListByZoneCollection(AlertDTO alert, IEnumerable <long> zoneIdsCollection, bool getInherited = false)
        {
            var usersCollection = new List <UserContactInformation>();

            var extendedZoneIdCollections = new List <long>(128);

            using (var ctx = new CentralDBEntities())
            {
                if (getInherited)
                {
                    foreach (var zoneId in zoneIdsCollection)
                    {
                        extendedZoneIdCollections.AddRange(GetParentZoneId(ctx, zoneId));
                    }
                }

                foreach (var zoneId in extendedZoneIdCollections.Distinct())
                {
                    var zoneUsersCollection = ctx.ZoneUser
                                              .Where(x => x.ZoneId == zoneId)
                                              .Select(x => x.Username)
                                              .ToList()
                                              .Where(x => !usersCollection.Any(y => y.Username == x));

                    usersCollection.AddRange(
                        zoneUsersCollection.Select(x => new UserContactInformation
                    {
                        Username = x,
                        ContactMethodsCollection = GetContactMethods(x)
                    })
                        );
                }
            }

            return(new NotifyList
            {
                Alert = alert,
                UsersCollection = usersCollection.ToArray()
            });
        }
        /*public void doJob()
         * {
         *  int recv;
         *  byte[] data = new byte[1024];
         *
         *  IPEndPoint ipep = new IPEndPoint(IPAddress.Any, Convert.ToInt32(strUDPPort));
         *  mListener = new Socket(AddressFamily.InterNetwork,
         *                 SocketType.Dgram, ProtocolType.Udp);
         *  mListener.Bind(ipep);
         *
         *  IPEndPoint senderUser = new IPEndPoint(IPAddress.Any, Convert.ToInt32(strUDPPort));
         *  Remote = (EndPoint)(senderUser);
         *
         *  //StartReceive();
         *
         *  while (true)
         *  {
         *      try
         *      {
         *          data = new byte[1024];
         *          recv = mListener.ReceiveFrom(data, ref Remote);
         *          string strData = Encoding.Default.GetString(data, 0, recv);
         *          if(strData.Contains(","))
         *          {
         *              Task.Run(() => ProcessData(strData.ToString(), ((IPEndPoint)Remote).Address.ToString()));
         *          }
         *      }
         *      catch (Exception es)
         *      {
         *          Logger.Info("ACSIntegrationClass Exception" + es.Message);
         *      }
         *      finally
         *      {
         *
         *      }
         *  }
         *
         * }*/

        /* public void ProcessData(string data, string strIp)
         * {
         *   string strData = data;// "#1U,002,001,002,3782706324,162806,261114,000023,000048,002,002,00000,4B,\r";
         *   try
         *   {
         *       var strDa = strData.Split(',');
         *       if (strDa == null)
         *           return;
         *
         *       string strCheck = strDa[3];
         *       if (strCheck == "002" || strCheck == "002" || strCheck == "004" || strCheck == "005" || strCheck == "006" || strCheck == "007" || strCheck == "008"
         || strCheck == "012" || strCheck == "015" || strCheck == "017" || strCheck == "020" || strCheck == "024" || strCheck == "036" || strCheck == "038"
         || strCheck == "039" || strCheck == "040" || strCheck == "041" || strCheck == "042" || strCheck == "043" || strCheck == "062")
         ||      { }
         ||      else
         ||          return;
         ||      string deviceId = Int32.Parse(strDa[2]).ToString();
         ||      string strCardNo = strDa[4];
         ||      string errorCode = "ACS Alert " + strCardNo + "-" + SelectEvent(Int32.Parse(strDa[3]));
         ||      string errorCode1 = "ACS Alert " + strCardNo + "-" + SelectEvent(Int32.Parse(strDa[3]));
         ||      string strTemp1 = strDa[5];
         ||      string strTemp2 = strDa[6];
         ||
         ||      string dateTime = DateTime.Now.ToString();//"20" + strTemp2.Substring(4, 2) + "-" + strTemp2.Substring(2, 2) + "-" + strTemp2.Substring(0, 2) + " " + strTemp1.Substring(0, 2) + ":" + strTemp1.Substring(2, 2) + ":" + strTemp1.Substring(4, 2);
         ||
         ||      string strExtId = deviceId + "-" + strIp;
         ||      //amit 14112016
         ||      if (Storage.IsLogEnable == "1")
         ||      {
         ||          string Message = "Acs integration Service--ProcessData -- DevicID = " + deviceId + "-- DevicExtID = " + strExtId;
         ||          InsertBrokerOperationLog.AddProcessLog(Message);
         ||      }
         ||      DeviceDto deviceDto = new DeviceDto();
         ||      using (var devicecontext = new CentralDBEntities())
         ||      {
         ||          var devicetemplates = from dc in devicecontext.Device
         ||                                where dc.ExternalId == strExtId
         ||                                select dc;
         ||          var devicetemplate = devicetemplates.FirstOrDefault();
         ||          int count = devicetemplates.Count();
         ||          if (count > 0)
         ||          {
         ||              //deviceDto = Mapper.Map<DeviceDto>(devicetemplate); ;// Mapper.Map<DeviceDto>(alerttemplate);
         ||
         ||              try
         ||              {
         ||                  if (devicetemplate is NvrCamera)
         ||                  {
         ||                      var _entity1 = devicetemplate as NvrCamera;
         ||
         ||                      NvrCameraDto DevDto = new NvrCameraDto()
         ||                      {
         ||                          DeviceId = _entity1.DeviceId,
         ||                          ExternalId = _entity1.ExternalId,
         ||                          Description = _entity1.Description,
         ||                          Metadata = _entity1.Metadata,
         ||                          Type = _entity1.Type,
         ||                          Lat = _entity1.Lat,
         ||                          Long = _entity1.Long,
         ||                          Altitude = _entity1.Altitude,
         ||                          LocationDescription = _entity1.LocationDescription,
         ||                          CameraGUID = _entity1.CameraGuid,
         ||                          NvrId = _entity1.NvrId,
         ||                          SiteId = _entity1.SiteId.HasValue ? _entity1.SiteId.Value : 0,
         ||                          ActiveAlert = _entity1.ActiveAlert,
         ||                          //   HasPvAnalytics = _entity1.HasPvAnalytics,
         ||                          //   HasSzAnalytics = _entity1.HasSzAnalytics,
         ||                          //   HasAbAnalytics = _entity1.HasAbAnalytics,
         ||                          InterfaceId = _entity1.InterfaceId.HasValue ? _entity1.InterfaceId.Value : 0,
         ||                          IsMovable = _entity1.IsMovable,
         ||                          Name = _entity1.Name,
         ||
         ||                          AnalyticAlgorithmTypeId = _entity1.AnalyticAlgorithmTypeId, //None
         ||                          FPS = _entity1.FPS,
         ||                          Version = _entity1.Version,
         ||                          MaxBlobSize = _entity1.MaxBlobSize,
         ||                          MinBlobSize = _entity1.MinBlobSize,
         ||                          AlarmDelay = _entity1.AlarmDelay,
         ||                          UpdateRate = _entity1.UpdateRate,
         ||                          Width = _entity1.Width,
         ||                          Height = _entity1.Height,
         ||                          ZoneRows = _entity1.ZoneRows,
         ||                          ZoneColumns = _entity1.ZoneColumns,
         ||                          ZoneData = null,
         ||                          AnalyticsEventTemplateId = _entity1.AnalyticsEventTemplateId,
         ||                          IsPtz = _entity1.IsPtz,
         ||                          CameraIp = _entity1.CameraIp,
         ||                          LineStart = _entity1.LineStart,
         ||                          LineEnd = _entity1.LineEnd,
         ||                          DirectionFlag = _entity1.DirectionFlag,
         ||                          CameraUrl = _entity1.CameraUrl,
         ||                          CamUser = _entity1.CamUser,
         ||                          CamPassword = _entity1.CamPassword,
         ||                          CameraPort = _entity1.CameraPort,
         ||                          CameraType = _entity1.CameraType,
         ||                          MaxBlobHeight = _entity1.MaxBlobHeight,
         ||                          MaxBlobWidth = _entity1.MaxBlobWidth,
         ||                          MinBlobHeight = _entity1.MinBlobHeight,
         ||                          MinBlobWidth = _entity1.MinBlobWidth,
         ||                          AnalyticsServerIp = _entity1.AnalyticsServerIp,
         ||                          Lane1 = _entity1.Lane1,
         ||                          Lane2 = _entity1.Lane2,
         ||                          Lane3 = _entity1.Lane3,
         ||                          NoOfLens = _entity1.NoOfLens,
         ||                          ChanelNo = _entity1.ChanelNo,
         ||                          IsEdgeAnalytics = _entity1.IsEdgeAnalytics,
         ||                          IPAddress = _entity1.NVR.IPAddress
         ||                      };
         ||                      deviceDto = DevDto;
         ||                  }
         ||                  else
         ||                  {
         ||                      DeviceDto DevDto = new DeviceDto
         ||                      {
         ||                          DeviceId = devicetemplate.DeviceId,
         ||                          ExternalId = devicetemplate.ExternalId,
         ||                          Description = devicetemplate.Description,
         ||                          Metadata = devicetemplate.Metadata,
         ||                          Type = devicetemplate.Type,
         ||                          Lat = devicetemplate.Lat,
         ||                          Long = devicetemplate.Long,
         ||                          Altitude = devicetemplate.Altitude,
         ||                          LocationDescription = devicetemplate.LocationDescription,
         ||                          CameraGUID = devicetemplate.CameraGuid,
         ||                          NvrId = devicetemplate.NvrId,
         ||                          SiteId = devicetemplate.SiteId.HasValue ? devicetemplate.SiteId.Value : 0,
         ||                          ActiveAlert = devicetemplate.ActiveAlert,
         ||                          //  HasPvAnalytics = _data.Device.HasPvAnalytics,
         ||                          //  HasSzAnalytics = _data.Device.HasSzAnalytics,
         ||                          //  HasAbAnalytics = _data.Device.HasAbAnalytics,
         ||                          InterfaceId = devicetemplate.InterfaceId.HasValue ? devicetemplate.InterfaceId.Value : 0,
         ||                          IsMovable = devicetemplate.IsMovable,
         ||                          Name = devicetemplate.Name
         ||                      };
         ||                      deviceDto = DevDto;
         ||                  }
         ||              }
         ||              catch (Exception ex)
         ||              {
         ||
         ||              }
         ||          }
         ||      }
         ||
         ||      if (deviceDto.DeviceId == 0)
         ||          return;
         ||      var alert = new AlertDTO
         ||      {
         ||          DeviceId = Convert.ToInt64(Convert.ToDecimal(deviceDto.DeviceId)),//long.Parse(wcfEvent.Payload["DeviceId"].ToString()),
         ||          Sender = "Device-" + deviceDto.DeviceId.ToString(),//(string)wcfEvent.Payload["Sender"],
         ||          Source = deviceDto.Description,//(string)wcfEvent.Payload["Address"],
         ||          //SentAsString = dateTime, //wcfEvent.StartTime.ToString(),
         ||          Sent=DateTime.Now,
         ||          Identifier = Guid.NewGuid().ToString(),
         ||          StatusId = (AMS.Broker.Contracts.DTO.Status)Enum.Parse(typeof(AMS.Broker.Contracts.DTO.Status), Enum.GetName(typeof(AMS.Broker.Contracts.DTO.Status), AMS.Broker.Contracts.DTO.Status.Actual)),//(Status)Enum.Parse(typeof(Status), (string)wcfEvent.Payload["StatusId"]),
         ||          MessageTypeId = Contracts.DTO.MessageType.Alert,
         ||          ScopeId = (Contracts.DTO.Scope)Enum.Parse(typeof(Contracts.DTO.Scope), AMS.Broker.Contracts.DTO.Scope.Private.ToString()), //(Contracts.DTO.Scope)Enum.Parse(typeof(Contracts.DTO.Scope), (string)wcfEvent.Payload["ScopeId"]),
         ||          Code = errorCode,
         ||          Addresses = deviceDto.Name, //(string)wcfEvent.Payload["Address"],
         ||          Severity = (Contracts.DTO.Severity)Enum.Parse(typeof(Contracts.DTO.Severity), Contracts.DTO.Severity.Extreme.ToString()), //(Contracts.DTO.Severity)Enum.Parse(typeof(Contracts.DTO.Severity), (string)wcfEvent.Payload["SeverityId"]),
         ||          InfoCollection = new List<InfoDTO>()
         ||                          {
         ||                              new InfoDTO
         ||                                  {   SenderName=deviceId,//(string)wcfEvent.Payload["AdapterName"],
         ||                                      Headline = "ACS Alert",//"ACS Alert",//(string)wcfEvent.Payload["Headline"],
         ||                                      Description =errorCode,//"ACS Alert",//(string)wcfEvent.Payload["Description"],
         ||                                      Instruction ="",//(string)wcfEvent.Payload["Instruction"],
         ||                                      Contact ="", //(string)wcfEvent.Payload["Contact"],
         ||                                      UrgencyId = (Contracts.DTO.Urgency)Enum.Parse(typeof(Contracts.DTO.Urgency),Contracts.DTO.Urgency.Immediate.ToString()),//(Contracts.DTO.Urgency)Enum.Parse(typeof(Contracts.DTO.Urgency), (string)wcfEvent.Payload["UrgencyId"]),
         ||                                      SeverityId = (Contracts.DTO.Severity)Enum.Parse(typeof(Contracts.DTO.Severity), Contracts.DTO.Severity.Extreme.ToString()),
         ||                                      CertaintyId = (Contracts.DTO.Certainty)Enum.Parse(typeof(Contracts.DTO.Certainty),  Contracts.DTO.Certainty.Possible.ToString()),
         ||                                      Event = errorCode,
         ||                                      AreasCollection = new List<AreaDTO>()
         ||                                          {
         ||                                              new AreaDTO
         ||                                                  {
         ||                                                      SiteId = deviceDto.SiteId,
         ||                                                      Latitude = Convert.ToDouble(deviceDto.Lat),
         ||                                                      Longitude = Convert.ToDouble(deviceDto.Long),
         ||                                                      Altitude =Convert.ToDouble(deviceDto.Altitude)
         ||                                                  }
         ||                                          }
         ||                                  }
         ||                          }
         ||      };
         ||
         ||      try
         ||      {
         ||         // alert.DeviceDto = deviceDto; //amit 24102016
         ||          //_alertCreationService.SubmitNewAlert(alert);    //trupti to change calling of service because of broker distribution
         ||          try
         ||          {
         ||              string _strUrl = "https://localhost:6530/soap/AlertsCreationService";
         ||              EndpointAddress ar = new EndpointAddress(_strUrl);
         ||              AlertsCreationServiceRef.AlertsCreationServiceClient _serVice = new AlertsCreationServiceRef.AlertsCreationServiceClient("WSHttpBinding_IAlertsCreationService", ar.ToString());
         ||              if (Storage.IsCloudServer == "1")
         ||              {
         ||                  _serVice.Endpoint.Binding.OpenTimeout = TimeSpan.FromSeconds(30);
         ||                  _serVice.Endpoint.Binding.SendTimeout = TimeSpan.FromSeconds(30);
         ||              }
         ||              else
         ||              {
         ||                  _serVice.Endpoint.Binding.OpenTimeout = TimeSpan.FromSeconds(5);
         ||                  _serVice.Endpoint.Binding.SendTimeout = TimeSpan.FromSeconds(5);
         ||              }
         ||              string _alert = SerializeAlertObject(alert);
         ||              _serVice.SubmitNewAlert(_alert);
         ||              _serVice.Close();
         ||          }
         ||          catch (OutOfMemoryException ex)
         ||          {
         ||              Logger.Info("StationsServiceImpl ActivateStationInform() Exception:" + ex.Message);
         ||          }
         ||          catch (Exception ex)
         ||          {
         ||              Logger.Info("StationsServiceImpl UpdateRegistionInfoStationInformTask() Exception:" + ex.Message);
         ||              Console.WriteLine(ex.Message);
         ||          }
         ||          finally
         ||          {
         ||
         ||          }
         ||      }
         ||      catch (Exception es)
         ||      {
         ||          Logger.Info("ACSIntegrationClass process data Exception" + es.Message);
         ||      }
         ||  }
         ||  catch (Exception ex)
         ||  {
         ||      Logger.Info("ACSIntegrationClass process data Exception" + ex.Message);
         ||  }
         ||
         ||}*/

        public static string SerializeAlertObject(AlertDTO _alert)
        {
            try
            {
                var    serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(AlertDTO));
                string jsonCode;

                using (var ms = new MemoryStream())
                {
                    serializer.WriteObject(ms, _alert);
                    jsonCode = Encoding.Default.GetString(ms.ToArray());
                }

                return(jsonCode);
            }
            catch (Exception ex)
            { Logger.Info("StationsServiceImpl SerializeObject() Exception:" + ex.Message); }
            finally
            {
            }
            return(null);
        }