예제 #1
0
        private async Task ProcessWSChat(AspNetWebSocketContext context)
        {
            Exception Ex = new Exception("1");

            CommonServices.ErrorLogging(Ex);

            Exception Ex1 = new Exception("2");

            CommonServices.ErrorLogging(Ex1);
            WebSocket socket = context.WebSocket;
            Exception ex     = new Exception(Convert.ToString("123"));

            CommonServices.ErrorLogging(ex);
            while (true)
            {
                ArraySegment <byte>    buffer = new ArraySegment <byte>(new byte[1024]);
                WebSocketReceiveResult result = await socket.ReceiveAsync(buffer, CancellationToken.None);

                if (socket.State == WebSocketState.Open)
                {
                    string userMessage = Encoding.UTF8.GetString(buffer.Array, 0, result.Count);
                    userMessage = "You sent: " + userMessage + " at " + DateTime.Now.ToLongTimeString();
                    buffer      = new ArraySegment <byte>(Encoding.UTF8.GetBytes(userMessage));
                    await socket.SendAsync(buffer, WebSocketMessageType.Text, true, CancellationToken.None);
                }
                else
                {
                    break;
                }
            }
        }
예제 #2
0
        public void ProcessRequest(HttpContext context)
        {
            Exception Ex = new Exception("1123123");

            CommonServices.ErrorLogging(Ex);
            if (context.IsWebSocketRequest)
            {
                context.AcceptWebSocketRequest(ProcessWSChat);
            }
        }
예제 #3
0
        public override void OnMessage(string message)
        {
            try
            {
                if (message != null && message != "")
                {
                    var UserId  = message.Split(',')[0].Split(':')[1];
                    var IsLogin = message.Split(',')[1].Split(':')[1];

                    if (IsLogin == "1")
                    {
                        var TimeZone = message.Split(',')[2].Split(':')[1];

                        using (LystenEntities db = new LystenEntities())
                        {
                            if (UserId != "" && TimeZone != "")
                            {
                                int uid = Convert.ToInt32(UserId);

                                var obj = db.User_Master.Where(x => x.Id == uid).FirstOrDefault();

                                if (obj != null)
                                {
                                    obj.TimeZone        = TimeZone;
                                    obj.IsLogin         = true;
                                    db.Entry(obj).State = EntityState.Modified;
                                    db.SaveChanges();
                                }
                            }
                        }
                    }
                    else
                    {
                        using (LystenEntities db = new LystenEntities())
                        {
                            int uid = Convert.ToInt32(UserId);

                            var obj = db.User_Master.Where(x => x.Id == uid).FirstOrDefault();
                            if (obj != null)
                            {
                                obj.IsLogin = false;
                                //obj.TimeZone = "";
                                //obj.DeviceToken = null;
                                db.Entry(obj).State = EntityState.Modified;
                                db.SaveChanges();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CommonServices.ErrorLogging(ex);
            }
        }
예제 #4
0
 public override void OnOpen()
 {
     try
     {
         clients.Add(this);
     }
     catch (Exception ex)
     {
         CommonServices.ErrorLogging(ex);
     }
 }
예제 #5
0
 public JsonResult EditCallPrice(int Id)
 {
     try
     {
         return(Json(MS.EditCallPrice(Id), JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         CommonServices.ErrorLogging(ex);
         throw ex;
     }
 }
예제 #6
0
 public JsonResult SaveCallPrice(CallingPriceMaster CM)
 {
     try
     {
         return(Json(MS.SaveCallingPriceMaster(CM), JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         CommonServices.ErrorLogging(ex);
         throw ex;
     }
 }
예제 #7
0
 public JsonResult ActiveDeActiveUser(int Id)
 {
     try
     {
         return(Json(MS.ActiveDeActiveUser(Id), JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         CommonServices.ErrorLogging(ex);
         throw ex;
     }
 }
예제 #8
0
 public JsonResult MarkasVerified(int Id)
 {
     try
     {
         return(Json(MS.MarkAsVerified(Id), JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         CommonServices.ErrorLogging(ex);
         throw ex;
     }
 }
예제 #9
0
 public JsonResult SaveEvent(Event CM)
 {
     try
     {
         return(Json(MS.SaveEvent(CM), JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         CommonServices.ErrorLogging(ex);
         throw ex;
     }
 }
예제 #10
0
 public JsonResult EditEmailTempData(int TemplateId)
 {
     try
     {
         var user = MS.EditEmailTemplateData(TemplateId);
         return(Json(user, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         CommonServices.ErrorLogging(ex);
         throw ex;
     }
 }
예제 #11
0
 public JsonResult SaveEmailTemplateData(EmailTemplate UM)
 {
     try
     {
         var user = MS.SaveEmailTemplateData(UM);
         return(Json(user, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         CommonServices.ErrorLogging(ex);
         throw ex;
     }
 }
예제 #12
0
 public JsonResult ForgotPassword(string EmailId)
 {
     try
     {
         var i = cs.GetforgotPassword(EmailId);
         return(Json(i, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         CommonServices.ErrorLogging(ex);
         throw ex;
     }
 }
예제 #13
0
 public void ProcessRequest(HttpContext context)
 {
     try
     {
         if (context.IsWebSocketRequest)
         {
             context.AcceptWebSocketRequest(new SetOnlineHandler());
         }
         context = null;
     }
     catch (Exception ex)
     {
         CommonServices.ErrorLogging(ex);
     }
 }
예제 #14
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register); // NEW way

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            try
            {
                schedule_Timer();
            }
            catch (Exception ex)
            {
                CommonServices.ErrorLogging(ex);
            }
        }
예제 #15
0
 public JsonResult SaveEventCategoryimage(CategoryImageEvent CM)
 {
     try
     {
         var dd = MS.SaveEventCategoryimage(CM);
         TempData["Id"]  = dd.Id;
         TempData["CId"] = CM.CategoryId;
         TempData.Keep("Id");
         TempData.Keep("CId");
         return(Json(dd, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         CommonServices.ErrorLogging(ex);
         throw ex;
     }
 }
예제 #16
0
        public JsonResult GetAllCalling(jQueryDataTableParamModel param)
        {
            try
            {
                var allRecords = new List <Calling_Request>();
                allRecords = MS.GetAllCalling();
                List <Calling_Request> filteredRecords = null;

                if (!string.IsNullOrWhiteSpace(param.sSearch))
                {
                    allRecords      = allRecords.Where(t => t.Id.ToString().Contains(param.sSearch.ToLower()) || t.User_Master1.FullName.ToString().Contains(param.sSearch.ToLower()) || t.User_Master1.FullName.ToLower().ToString().Contains(param.sSearch.ToLower())).OrderBy(t => t.Id).ToList();
                    filteredRecords = allRecords.Skip(param.iDisplayStart).Take(param.iDisplayLength).ToList();
                }
                else
                {
                    filteredRecords = allRecords
                                      .Skip(param.iDisplayStart)
                                      .Take(param.iDisplayLength).OrderBy(t => t.Id).ToList();
                }
                int totalRecords = allRecords.Count();

                var result = from c in filteredRecords select new[] { "", c.Id.ToString(), c.User_Master.FullName, c.User_Master1.FullName, c.TotalAmount.Value.ToString("0.00"), Convert.ToDateTime(c.CallingDateTime1).ToString("dd-MM-yyy HH:mm"), c.CallingDateTime2 != null?Convert.ToDateTime(c.CallingDateTime2).ToString("dd-MM-yyyy HH:mm") : "", c.CallingDateTime3 == null ? "" : Convert.ToDateTime(c.CallingDateTime3).ToString("dd-MM-yyyy HH:mm"), c.AcceptDatetime == null ? "" : Convert.ToDateTime(c.AcceptDatetime).ToString("dd-MM-yyyy HH:mm"), c.IsAccept.ToString(), c.IsReject.ToString(), c.RejectedNote };
                return(Json(new
                {
                    sEcho = param.sEcho,
                    iTotalRecords = totalRecords,
                    iTotalDisplayRecords = totalRecords,
                    aaData = result
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                CommonServices.ErrorLogging(ex);
                return(Json(new
                {
                    sEcho = 1,
                    iTotalRecords = 0,
                    iTotalDisplayRecords = 0,
                    aaData = new List <string[]> {
                    }
                }, JsonRequestBehavior.AllowGet));
            }
        }
예제 #17
0
        public JsonResult GetEmailAccount(jQueryDataTableParamModel param)
        {
            try
            {
                var allRecords = new List <EmailAccount>();
                allRecords = MS.GetAllEmailAccount(param);
                List <EmailAccount> filteredRecords = null;

                if (!string.IsNullOrWhiteSpace(param.sSearch))
                {
                    allRecords      = allRecords.Where(t => t.Id.ToString().Contains(param.sSearch.ToLower()) || t.EmailId.ToLower().ToString().Contains(param.sSearch.ToLower()) || t.Password.ToLower().ToString().Contains(param.sSearch.ToLower()) || t.SMTPRelay.ToLower().ToString().Contains(param.sSearch.ToLower()) || t.Port.ToLower().ToString().Contains(param.sSearch.ToLower()) || t.EnableSSL.ToString().Contains(param.sSearch.ToLower())).OrderBy(t => t.EmailId).ToList();
                    filteredRecords = allRecords.Skip(param.iDisplayStart).Take(param.iDisplayLength).ToList();
                }
                else
                {
                    filteredRecords = allRecords
                                      .Skip(param.iDisplayStart)
                                      .Take(param.iDisplayLength).OrderBy(t => t.EmailId).ToList();
                }
                int totalRecords = allRecords.Count();
                var result       = from c in filteredRecords select new[] { "", c.Id.ToString(), c.EmailId, c.Password, c.SMTPRelay, c.Port, c.EnableSSL.ToString(), "" };
                return(Json(new
                {
                    sEcho = param.sEcho,
                    iTotalRecords = totalRecords,
                    iTotalDisplayRecords = totalRecords,
                    aaData = result
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                CommonServices.ErrorLogging(ex);
                return(Json(new
                {
                    sEcho = 1,
                    iTotalRecords = 0,
                    iTotalDisplayRecords = 0,
                    aaData = new List <string[]> {
                    }
                }, JsonRequestBehavior.AllowGet));
            }
        }
예제 #18
0
        public JsonResult GetAllUser(jQueryDataTableParamModel param)
        {
            try
            {
                List <User_Master> allRecords = new List <User_Master>();
                allRecords = MS.GetAllUser();
                List <User_Master> filteredRecords = null;

                if (!string.IsNullOrWhiteSpace(param.sSearch))
                {
                    allRecords      = allRecords.Where(t => t.Email.Contains(param.sSearch) || t.UserName != null ? t.UserName.Contains(param.sSearch) : t.UserName == null).ToList();
                    filteredRecords = allRecords.Skip(param.iDisplayStart).Take(param.iDisplayLength).ToList();
                }
                else
                {
                    filteredRecords = allRecords
                                      .Skip(param.iDisplayStart)
                                      .Take(param.iDisplayLength).OrderBy(t => t.Email).ToList();
                }
                int totalRecords = allRecords.Count();
                var result       = from c in filteredRecords select new[] { "", c.Id.ToString(), c.Email, c.UserName, c.IsActive == true ? "Active" : "InActive", c.IsVerified == null || c.IsVerified == false ? "Not Verified" : "IsVerified", MS.GetRoleName(c.RoleId.Value), "" };
                return(Json(new
                {
                    sEcho = param.sEcho,
                    iTotalRecords = totalRecords,
                    iTotalDisplayRecords = totalRecords,
                    aaData = result
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                CommonServices.ErrorLogging(ex);
                return(Json(new
                {
                    sEcho = 1,
                    iTotalRecords = 0,
                    iTotalDisplayRecords = 0,
                    aaData = new List <string[]> {
                    }
                }, JsonRequestBehavior.AllowGet));
            }
        }
예제 #19
0
        public JsonResult GetAllEventCategoryimage(jQueryDataTableParamModel param)
        {
            try
            {
                var allRecords = new List <CategoryImageEvent>();
                allRecords = MS.GetAllEventCategoryimage();
                List <CategoryImageEvent> filteredRecords = null;

                if (!string.IsNullOrWhiteSpace(param.sSearch))
                {
                    allRecords      = allRecords.Where(t => t.Id.ToString().Contains(param.sSearch.ToLower()) || t.Category.Name.ToLower().ToString().Contains(param.sSearch.ToLower()) || t.Image.ToString().ToLower().Contains(param.sSearch.ToLower())).OrderBy(t => t.Category.Name).ToList();
                    filteredRecords = allRecords.Skip(param.iDisplayStart).Take(param.iDisplayLength).ToList();
                }
                else
                {
                    filteredRecords = allRecords
                                      .Skip(param.iDisplayStart)
                                      .Take(param.iDisplayLength).OrderBy(t => t.Category.Name).ToList();
                }
                int totalRecords = allRecords.Count();
                var result       = from c in filteredRecords select new[] { "", c.Id.ToString(), c.Category.Name, "/Images/categoryeventimage/" + c.Image, "" };
                return(Json(new
                {
                    sEcho = param.sEcho,
                    iTotalRecords = totalRecords,
                    iTotalDisplayRecords = totalRecords,
                    aaData = result
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                CommonServices.ErrorLogging(ex);
                return(Json(new
                {
                    sEcho = 1,
                    iTotalRecords = 0,
                    iTotalDisplayRecords = 0,
                    aaData = new List <string[]> {
                    }
                }, JsonRequestBehavior.AllowGet));
            }
        }
예제 #20
0
        public JsonResult GetAllCallingPrice(jQueryDataTableParamModel param)
        {
            try
            {
                var allRecords = new List <CallingPriceMaster>();
                allRecords = MS.GetAllCallingPrices();
                List <CallingPriceMaster> filteredRecords = null;

                if (!string.IsNullOrWhiteSpace(param.sSearch))
                {
                    allRecords      = allRecords.Where(t => t.Name.Contains(param.sSearch) || t.Price.Value.ToString().Contains(param.sSearch)).OrderBy(t => t.Name).ToList();
                    filteredRecords = allRecords.Skip(param.iDisplayStart).Take(param.iDisplayLength).ToList();
                }
                else
                {
                    filteredRecords = allRecords
                                      .Skip(param.iDisplayStart)
                                      .Take(param.iDisplayLength).OrderBy(t => t.Name).ToList();
                }
                int totalRecords = allRecords.Count();
                var result       = from c in filteredRecords select new[] { "", c.Id.ToString(), c.Name.ToString(), Convert.ToString(c.Time), Convert.ToString(c.Price.Value), c.IsActive == true ? "Active" : "InActive", "" };
                return(Json(new
                {
                    sEcho = param.sEcho,
                    iTotalRecords = totalRecords,
                    iTotalDisplayRecords = totalRecords,
                    aaData = result
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                CommonServices.ErrorLogging(ex);
                return(Json(new
                {
                    sEcho = 1,
                    iTotalRecords = 0,
                    iTotalDisplayRecords = 0,
                    aaData = new List <string[]> {
                    }
                }, JsonRequestBehavior.AllowGet));
            }
        }
예제 #21
0
        public JsonResult GetAllEvent(jQueryDataTableParamModel param)
        {
            try
            {
                var allRecords = new List <Event>();
                allRecords = MS.GetAllEvent();
                List <Event> filteredRecords = null;

                if (!string.IsNullOrWhiteSpace(param.sSearch))
                {
                    allRecords      = allRecords.Where(t => t.Id.ToString().Contains(param.sSearch.ToLower()) || t.Category.Name.ToLower().ToString().Contains(param.sSearch.ToLower()) || t.Title.ToLower().ToString().Contains(param.sSearch.ToLower()) || t.IsActive.ToString().ToLower().Contains(param.sSearch.ToLower())).OrderBy(t => t.Title).ToList();
                    filteredRecords = allRecords.Skip(param.iDisplayStart).Take(param.iDisplayLength).ToList();
                }
                else
                {
                    filteredRecords = allRecords
                                      .Skip(param.iDisplayStart)
                                      .Take(param.iDisplayLength).OrderBy(t => t.Title).ToList();
                }
                int totalRecords = allRecords.Count();
                var result       = from c in filteredRecords select new[] { "", c.Id.ToString(), c.Title, c.Category.Name, c.Description, c.Image, Convert.ToDateTime(c.CreatedDate).ToString("dd/MM/yyyy HH:mm"), c.IsActive == true ? "Active" : "InActive", "" };
                return(Json(new
                {
                    sEcho = param.sEcho,
                    iTotalRecords = totalRecords,
                    iTotalDisplayRecords = totalRecords,
                    aaData = result
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                CommonServices.ErrorLogging(ex);
                return(Json(new
                {
                    sEcho = 1,
                    iTotalRecords = 0,
                    iTotalDisplayRecords = 0,
                    aaData = new List <string[]> {
                    }
                }, JsonRequestBehavior.AllowGet));
            }
        }
예제 #22
0
        public void sendMsgPreCalling(int Id, string devicetocken, string Status, string Fullname)
        {
            string ImagePath       = "";
            string name            = "";
            var    certificatePath = HostingEnvironment.MapPath("~/Lysten-DevB.p12");


            int    port     = 2195;
            String hostname = (WebConfigurationManager.AppSettings["ApnsEnvironment"]);
            //String hostname = "gateway.push.apple.com";

            string certificatePassword = "";

            X509Certificate2           clientCertificate      = new X509Certificate2(certificatePath, certificatePassword, X509KeyStorageFlags.MachineKeySet);
            X509Certificate2Collection certificatesCollection = new X509Certificate2Collection(clientCertificate);


            TcpClient client = new TcpClient(hostname, port);

            SslStream sslStream = new SslStream(
                client.GetStream(),
                false,
                new RemoteCertificateValidationCallback(ValidateServerCertificate),
                null
                );

            try
            {
                sslStream.AuthenticateAsClient(hostname, certificatesCollection, SslProtocols.Tls, false);
            }
            catch (AuthenticationException ex)
            {
                client.Close();
                Exception Eccsssas12 = new Exception("Athentication Failed");
                CommonServices.ErrorLogging(Eccsssas12);
                System.Web.HttpContext.Current.Server.MapPath("~/Authenticationfailed.txt");
                return;
            }

            //// Encode a test message into a byte array.
            MemoryStream memoryStream = new MemoryStream();
            BinaryWriter writer       = new BinaryWriter(memoryStream);

            writer.Write((byte)0);  //The command
            writer.Write((byte)0);  //The first byte of the deviceId length (big-endian first byte)
            writer.Write((byte)32); //The deviceId length (big-endian second byte)
            byte[] b0 = HexString2Bytes(devicetocken);
            WriteMultiLineByteArray(b0);
            writer.Write(b0);
            String payload;
            string strmsgbody   = "";
            int    totunreadmsg = 20;

            if (Status == "TO")
            {
                strmsgbody = "You have a call from " + Fullname + " in 15 minutes.be ready!";
            }
            else
            {
                strmsgbody = "Your calling time is in 15 minutes.be ready!";
            }
            payload = "{\"aps\":{\"alert\":\"" + strmsgbody + "\",\"badge\":" + totunreadmsg.ToString() + ",\"sound\":\"mailsent.wav\"},\"acme1\":\"bar\",\"acme2\":42}";
            writer.Write((byte)0);              //First byte of payload length; (big-endian first byte)
            writer.Write((byte)payload.Length); //payload length (big-endian second byte)
            byte[] b1 = System.Text.Encoding.UTF8.GetBytes(payload);
            writer.Write(b1);
            writer.Flush();

            byte[] array = memoryStream.ToArray();
            try
            {
                sslStream.Write(array);
                sslStream.Flush();
            }
            catch
            {
            }
            client.Close();
        }
예제 #23
0
        public override void OnMessage(string message)
        {
            try
            {
                ResultClassForNonAuth result = new ResultClassForNonAuth();
                string baseURL = (WebConfigurationManager.AppSettings["WebSiteUrl"]);
                baseURL += (WebConfigurationManager.AppSettings["userimagepath"]).Replace("~", "");
                if (message.Split(',')[1].Split(':').Contains("GroupId"))
                {
                    var Message = message.Split(',')[2].Split(':')[1];
                    var UserId  = message.Split(',')[0].Split(':')[1];
                    var GroupId = message.Split(',')[1].Split(':')[1];

                    int GId       = Convert.ToInt32(GroupId);
                    int Uid       = Convert.ToInt32(UserId);
                    var groupname = "";

                    List <WebSocketSessionDb> list = new List <WebSocketSessionDb>();
                    MessageModel MessagesModel     = new MessageModel();
                    using (LystenEntities db = new LystenEntities())
                    {
                        groupname = db.Groups.Where(x => x.Id == GId).Select(x => x.Name).FirstOrDefault();
                        Message ms = new Message()
                        {
                            Body            = Message,
                            CreatedDate     = DateTime.UtcNow,
                            ParentMessageId = 0,
                            CreatorId       = Uid
                        };
                        db.Messages.Add(ms);
                        db.SaveChanges();

                        MessageRecipient MR = new MessageRecipient()
                        {
                            RecipientGroupId = GId,
                            RecipientId      = null,
                            MessageId        = ms.Id,
                            IsRead           = false
                        };
                        db.MessageRecipients.Add(MR);
                        db.SaveChanges();


                        int gid = Convert.ToInt32(GroupId);
                        list = db.WebSocketSessionDbs.Where(x => x.GroupID == gid).ToList();



                        var userdataTimeZone = db.User_Master.Where(x => x.Id == Uid).Select(x => x.TimeZone).FirstOrDefault();
                        var ddd = DateTime.UtcNow;
                        if (userdataTimeZone != null && userdataTimeZone != "")
                        {
                            Instant instant = Instant.FromDateTimeUtc(ms.CreatedDate.Value);
                            IDateTimeZoneProvider timeZoneProvider = DateTimeZoneProviders.Tzdb;
                            var usersTimezoneId    = userdataTimeZone; //just an example
                            var usersTimezone      = timeZoneProvider[usersTimezoneId];
                            var usersZonedDateTime = instant.InZone(usersTimezone);
                            ddd = usersZonedDateTime.ToDateTimeUnspecified();
                        }



                        MessagesModel = new MessageModel()
                        {
                            MessageId        = ms.Id,
                            Body             = ms.Body,
                            RecipientGroupId = GId,
                            CreatorId        = Uid,
                            IsRead           = false,
                            CreatedDate      = ddd.Date == DateTime.UtcNow.Date ? "Today " + Convert.ToDateTime((ddd)).ToString("HH:mm") : Convert.ToDateTime(ddd).ToString("dd MM yyyy HH:mm"),

                            //CreatedDate = Convert.ToDateTime(ms.CreatedDate).ToString("dd MM yyyy HH:MM"),
                            Image           = US.GetFavouriteImage(baseURL, Uid),
                            CreatorName     = db.User_Master.Where(y => y.Id == Uid).Select(y => y.FullName).FirstOrDefault() == null ? "" : db.User_Master.Where(y => y.Id == Uid).Select(y => y.FullName).FirstOrDefault(),
                            ParentMessageId = 0,
                            ExpiryDate      = System.DateTime.Now,
                            RecipientId     = 0
                        };
                        result.Code = (int)HttpStatusCode.OK;
                        result.Msg  = ap.Success;
                        result.Data = MessagesModel;
                    }
                    var json = new JavaScriptSerializer().Serialize(result);
                    foreach (var item in list)
                    {
                        foreach (var data in clients.Where(x => x.WebSocketContext.SecWebSocketKey == item.SessionId))
                        {
                            clients.SingleOrDefault(r => ((WebSocketHandler)r).WebSocketContext.SecWebSocketKey == item.SessionId).Send(json);
                        }
                        using (LystenEntities db = new LystenEntities())
                        {
                            var obj        = db.User_Master.Where(x => x.Id == item.UserId.Value).FirstOrDefault();
                            var sendername = db.User_Master.Where(x => x.Id == Uid).Select(x => x.FullName).FirstOrDefault();

                            if (obj != null)
                            {
                                if (obj.DeviceToken != null)
                                {
                                    try
                                    {
                                        sendMsgUser(GId, true, obj.DeviceToken, Message, groupname, sendername);
                                    }
                                    catch
                                    {
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    var Message      = message.Split(',')[2].Split(':')[1];
                    var UserId       = message.Split(',')[0].Split(':')[1];
                    var ReceiptionId = message.Split(',')[1].Split(':')[1];

                    int RId = Convert.ToInt32(ReceiptionId);
                    int Uid = Convert.ToInt32(UserId);


                    List <WebSocketSessionDb> list = new List <WebSocketSessionDb>();
                    MessageModel MessagesModel     = new MessageModel();
                    var          SenderFullName    = "";

                    using (LystenEntities db = new LystenEntities())
                    {
                        SenderFullName = db.User_Master.Where(x => x.Id == Uid).Select(x => x.FullName).FirstOrDefault();

                        if (!db.MessageRequests.Any(x => x.ToUserId == RId && x.FromUserId == Uid || x.FromUserId == RId && x.ToUserId == Uid))
                        {
                            MessageRequest M1R = new MessageRequest();
                            M1R.ToUserId    = Convert.ToInt32(RId);
                            M1R.FromUserId  = Convert.ToInt32(Uid);
                            M1R.IsAccept    = false;
                            M1R.IsReject    = false;
                            M1R.IsRequested = true;
                            db.MessageRequests.Add(M1R);
                            db.SaveChanges();
                            var obj = db.User_Master.Where(x => x.Id == M1R.ToUserId).FirstOrDefault();


                            if (obj.DeviceToken != null || obj.DeviceToken != "")
                            {
                                try
                                {
                                    if (obj.DeviceType == "Android")
                                    {
                                        Helpers.NotificationHelper.sendMsgUserRequest(obj.Id, obj.DeviceToken, 0, SenderFullName);
                                    }
                                    else
                                    {
                                        sendMsgUserRequest(obj.Id, obj.DeviceToken, 0, SenderFullName);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    CommonServices.ErrorLogging(ex);
                                }
                            }
                        }
                        Message ms = new Message()
                        {
                            Body            = Message,
                            CreatedDate     = DateTime.UtcNow,
                            ParentMessageId = 0,
                            CreatorId       = Uid
                        };
                        db.Messages.Add(ms);
                        db.SaveChanges();
                        MessageRecipient MR = new MessageRecipient()
                        {
                            RecipientGroupId = null,
                            RecipientId      = RId,
                            MessageId        = ms.Id,
                            IsRead           = false
                        };
                        db.MessageRecipients.Add(MR);
                        db.SaveChanges();
                        list = db.WebSocketSessionDbs.Where(x => x.RecipientId == RId && x.UserId == Uid || (x.RecipientId == Uid && x.UserId == RId)).ToList();


                        var userdataTimeZone = db.User_Master.Where(x => x.Id == Uid).Select(x => x.TimeZone).FirstOrDefault();
                        var ddd = DateTime.UtcNow;
                        if (userdataTimeZone != null && userdataTimeZone != "")
                        {
                            Instant instant = Instant.FromDateTimeUtc(ms.CreatedDate.Value);
                            IDateTimeZoneProvider timeZoneProvider = DateTimeZoneProviders.Tzdb;
                            var usersTimezoneId    = userdataTimeZone; //just an example
                            var usersTimezone      = timeZoneProvider[usersTimezoneId];
                            var usersZonedDateTime = instant.InZone(usersTimezone);
                            ddd = usersZonedDateTime.ToDateTimeUnspecified();
                        }
                        try
                        {
                            MessagesModel = new MessageModel()
                            {
                                MessageId        = ms.Id,
                                Body             = ms.Body,
                                RecipientGroupId = 0,
                                CreatorId        = Uid,
                                IsRead           = false,

                                CreatedDate = ddd.Date == DateTime.UtcNow.Date ? "Today " + Convert.ToDateTime((ddd)).ToString("HH:mm") : Convert.ToDateTime(ddd).ToString("dd MM yyyy HH:mm"),


                                //CreatedDate = ms.CreatedDate.Value.Date == DateTime.Now.Date ? "Today " + Convert.ToDateTime((ms.CreatedDate.Value)).ToString("HH:mm") : Convert.ToDateTime(ms.CreatedDate.Value).ToString("dd MM yyyy HH:mm"),

                                //CreatedDate = Convert.ToDateTime(ms.CreatedDate).ToString("dd MM yyyy HH:MM"),
                                Image           = US.GetFavouriteImage(baseURL, Uid),
                                CreatorName     = db.User_Master.Where(y => y.Id == Uid).Select(y => y.FullName).FirstOrDefault() == null ? "" : db.User_Master.Where(y => y.Id == Uid).Select(y => y.FullName).FirstOrDefault(),
                                ParentMessageId = 0,
                                ExpiryDate      = System.DateTime.Now,
                                RecipientId     = RId
                            };
                        }
                        catch (Exception ex)
                        {
                            CommonServices.ErrorLogging(ex);
                        }
                        result.Code = (int)HttpStatusCode.OK;
                        result.Msg  = ap.Success;
                        result.Data = MessagesModel;
                    }
                    try
                    {
                        var json = new JavaScriptSerializer().Serialize(result);
                        foreach (var item in list)
                        {
                            foreach (var data in clients.Where(x => x.WebSocketContext.SecWebSocketKey == item.SessionId))
                            {
                                clients.SingleOrDefault(r => ((WebSocketHandler)r).WebSocketContext.SecWebSocketKey == item.SessionId).Send(json);
                            }
                            using (LystenEntities db = new LystenEntities())
                            {
                                var obj = db.User_Master.Where(x => x.Id == item.RecipientId.Value).FirstOrDefault();


                                if (obj != null)
                                {
                                    //if (obj.DeviceToken != null)
                                    //{
                                    //    sendMsgEventsssss(item.UserId.Value, obj.DeviceToken, Message, SenderFullName);
                                    //}

                                    try
                                    {
                                        if (obj.DeviceToken != null)
                                        {
                                            if (obj.DeviceType == "Android")
                                            {
                                                Helpers.NotificationHelper.sendMsgEventsssss(item.UserId.Value, obj.DeviceToken, Message, SenderFullName, MessagesModel.MessageId);
                                            }
                                            else
                                            {
                                                sendMsgEventsssss(item.UserId.Value, obj.DeviceToken, Message, SenderFullName);
                                                //sendMsgUserRequest(obj.Id, obj.DeviceToken, 0, SenderFullName);
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        CommonServices.ErrorLogging(ex);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        CommonServices.ErrorLogging(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                CommonServices.ErrorLogging(ex);
            }
        }
예제 #24
0
        public override void OnOpen()
        {
            try
            {
                clients.Add(this);
                if (this.WebSocketContext.RequestUri.Query.Split(',')[1].Split(':').Contains("GroupId"))
                {
                    var GroupId = this.WebSocketContext.RequestUri.Query.Split(',')[1].Split(':')[1];
                    var UserId  = this.WebSocketContext.RequestUri.Query.Split(',')[0].Split(':')[1];
                    using (LystenEntities db = new LystenEntities())
                    {
                        int gid = Convert.ToInt32(GroupId);
                        int uid = Convert.ToInt32(UserId);

                        //var obj = db.Groups.Where(x => x.Id == gid).FirstOrDefault();
                        //if (obj.GroupTypeId == 1)
                        //{
                        //    if (!db.Groups.Any(x => x.CreatorId == uid && x.Id == gid))
                        //    {
                        //        if (!db.UserGroupMappings.Any(x => x.UserId == uid && x.GroupId == gid))
                        //        {
                        //            UserGroupMapping ugm = new UserGroupMapping()
                        //            {
                        //                GroupId = gid,
                        //                UserId = uid
                        //            };
                        //            db.UserGroupMappings.Add(ugm);
                        //            db.SaveChanges();
                        //        }
                        //    }
                        //}
                        WebSocketSessionDb webs = new WebSocketSessionDb();

                        if (db.WebSocketSessionDbs.Any(x => x.GroupID == gid && x.UserId == uid))
                        {
                            webs                 = db.WebSocketSessionDbs.Where(x => x.GroupID == gid && x.UserId == uid).FirstOrDefault();
                            webs.GroupID         = Convert.ToInt32(GroupId);
                            webs.UserId          = Convert.ToInt32(UserId);
                            webs.SessionId       = this.WebSocketContext.SecWebSocketKey;
                            db.Entry(webs).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                        else
                        {
                            webs.GroupID   = Convert.ToInt32(GroupId);
                            webs.UserId    = Convert.ToInt32(UserId);
                            webs.SessionId = this.WebSocketContext.SecWebSocketKey;
                            db.WebSocketSessionDbs.Add(webs);
                            db.SaveChanges();
                        }
                    }
                }
                else
                {
                    var ReceiptionId = this.WebSocketContext.RequestUri.Query.Split(',')[1].Split(':')[1];
                    var UserId       = this.WebSocketContext.RequestUri.Query.Split(',')[0].Split(':')[1];
                    using (LystenEntities db = new LystenEntities())
                    {
                        int rid = Convert.ToInt32(ReceiptionId);
                        int uid = Convert.ToInt32(UserId);


                        WebSocketSessionDb webs = new WebSocketSessionDb();

                        if (db.WebSocketSessionDbs.Any(x => x.RecipientId == rid && x.UserId == uid))
                        {
                            webs                 = db.WebSocketSessionDbs.Where(x => x.RecipientId == rid && x.UserId == uid).FirstOrDefault();
                            webs.RecipientId     = Convert.ToInt32(rid);
                            webs.UserId          = Convert.ToInt32(UserId);
                            webs.SessionId       = this.WebSocketContext.SecWebSocketKey;
                            db.Entry(webs).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                        else
                        {
                            webs.RecipientId = Convert.ToInt32(rid);
                            webs.UserId      = Convert.ToInt32(UserId);
                            webs.SessionId   = this.WebSocketContext.SecWebSocketKey;
                            db.WebSocketSessionDbs.Add(webs);
                            db.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CommonServices.ErrorLogging(ex);
            }
        }
예제 #25
0
        public void sendMsgCallAccept(int IsAccept, int Id, string devicetocken)
        {
            string ImagePath = "";
            string name      = "";
            string baseURL   = HttpContext.Current.Request.Url.Authority;

            baseURL += (WebConfigurationManager.AppSettings["userimagepath"]).Replace("~", "");
            using (LystenEntities db = new LystenEntities())
            {
                ImagePath = US.GetFavouriteImage(baseURL, Id);
                name      = db.User_Master.Where(x => x.Id == Id).Select(x => x.FullName).FirstOrDefault() == null ? "" : db.User_Master.Where(x => x.Id == Id).Select(x => x.FullName).FirstOrDefault();
            }

            int    port     = 2195;
            String hostname = (WebConfigurationManager.AppSettings["ApnsEnvironment"]);
            //String hostname = "gateway.push.apple.com";

            string certificatePath = System.Web.HttpContext.Current.Server.MapPath("~/Lysten-DevB.p12");

            string certificatePassword = "";

            X509Certificate2           clientCertificate      = new X509Certificate2(certificatePath, certificatePassword, X509KeyStorageFlags.MachineKeySet);
            X509Certificate2Collection certificatesCollection = new X509Certificate2Collection(clientCertificate);


            TcpClient client = new TcpClient(hostname, port);

            SslStream sslStream = new SslStream(
                client.GetStream(),
                false,
                new RemoteCertificateValidationCallback(ValidateServerCertificate),
                null
                );

            try
            {
                sslStream.AuthenticateAsClient(hostname, certificatesCollection, SslProtocols.Tls, false);
            }
            catch (AuthenticationException ex)
            {
                client.Close();
                Exception Eccsssas12 = new Exception("Athentication Failed");
                CommonServices.ErrorLogging(Eccsssas12);
                System.Web.HttpContext.Current.Server.MapPath("~/Authenticationfailed.txt");
                return;
            }

            //// Encode a test message into a byte array.
            MemoryStream memoryStream = new MemoryStream();
            BinaryWriter writer       = new BinaryWriter(memoryStream);

            writer.Write((byte)0);  //The command
            writer.Write((byte)0);  //The first byte of the deviceId length (big-endian first byte)
            writer.Write((byte)32); //The deviceId length (big-endian second byte)
            byte[] b0 = HexString2Bytes(devicetocken);
            WriteMultiLineByteArray(b0);
            writer.Write(b0);
            String payload;
            string strmsgbody   = "";
            int    totunreadmsg = 20;

            string Checkbool = "";

            //if (IsAccept==1)
            //{
            //    Checkbool = "Accrpted";
            //}
            //else
            //{
            //    Checkbool = "Rejected";
            //}
            //strmsgbody = "Call request has been" + Checkbool;
            //payload = "{\"aps\":{\"alert\":\"" + strmsgbody + "\",\"badge\":" + totunreadmsg.ToString() + ",\"sound\":\"mailsent.wav\"},\"call\":{\"CallType\":\"" + IsAccept.ToString() == "1" ? "1" : "2" + "\",\"name\":\"" + name + "\"},\"acme1\":\"bar\",\"acme2\":42}";

            if (IsAccept == 1)
            {
                Checkbool = "Accepted";
            }
            else
            {
                Checkbool = "Rejected";
            }
            strmsgbody = "Message request has been " + Checkbool;

            payload = "{\"aps\":{\"alert\":\"" + strmsgbody + "\",\"badge\":" + totunreadmsg.ToString() + ",\"sound\":\"mailsent.wav\"},\"inbox\":{},\"acme1\":\"bar\",\"acme2\":42}";
            writer.Write((byte)0);              //First byte of payload length; (big-endian first byte)
            writer.Write((byte)payload.Length); //payload length (big-endian second byte)
            byte[] b1 = System.Text.Encoding.UTF8.GetBytes(payload);
            writer.Write(b1);
            writer.Flush();

            byte[] array = memoryStream.ToArray();
            try
            {
                sslStream.Write(array);
                sslStream.Flush();
            }
            catch
            {
            }
            client.Close();
        }
예제 #26
0
        public ActionResult Login(FormCollection FC, string ReturnUrl)
        {
            try
            {
                UserMasterModel UM = new UserMasterModel();
                UM.Email    = Request.Form["Email"];
                UM.Password = Request.Form["Password"];
                if (Convert.ToString(Request.Form["RememberMe"]) == "on")
                {
                    UM.RememberMe = true;
                }
                else
                {
                    UM.RememberMe = false;
                }
                var result = cs.PostLoginAuthentication(UM);
                if (result.Code == 200)
                {
                    if (UM.RememberMe)
                    {
                        Response.Cookies["UserName"].Expires = DateTime.Now.AddYears(1);
                        Response.Cookies["Password"].Expires = DateTime.Now.AddYears(1);
                        Response.Cookies["UserName"].Value   = UM.Email;
                        Response.Cookies["Password"].Value   = UM.Password;
                    }
                    else
                    {
                        Response.Cookies["UserName"].Expires = DateTime.Now.AddYears(-1);
                        Response.Cookies["Password"].Expires = DateTime.Now.AddYears(-1);
                        Response.Cookies["UserName"].Value   = "0";
                        Response.Cookies["Password"].Value   = "0";
                    }

                    var objuser = (result.Data[0]);
                    objuser.SessionId = System.Web.HttpContext.Current.Session.SessionID;
                    MS.updatesession(objuser);

                    HttpCookie UserCookies = new HttpCookie("Userid");
                    UserCookies.Value   = Convert.ToString(objuser.Id);
                    UserCookies.Expires = DateTime.Now.AddDays(1);
                    Response.Cookies.Add(UserCookies);



                    HttpCookie SessionIDCookies = new HttpCookie("SessionID");
                    SessionIDCookies.Value   = System.Web.HttpContext.Current.Session.SessionID;
                    SessionIDCookies.Expires = DateTime.Now.AddDays(1);
                    Response.Cookies.Add(SessionIDCookies);

                    //HttpContext.Application["usr_" + objuser.Id] = HttpContext.Session.SessionID;

                    // FormsAuthentication.SetAuthCookie(objuser.um.Username, false);
                    FormsAuthentication.SetAuthCookie(objuser.Email, false);
                    if (ReturnUrl != null)
                    {
                        ReturnUrl = ReturnUrl.Remove(0, 1);
                        return(RedirectToRoute(ReturnUrl));
                    }
                    if (objuser.RoleId == 1)
                    {
                        return(RedirectToRoute("dashboard"));
                    }
                    else
                    {
                        return(View());
                    }
                }
                else
                {
                    ViewBag.Errormsg = "Invalid Email Or Password!";
                    return(View());
                }
            }
            catch (Exception ex)
            {
                CommonServices.ErrorLogging(ex);
                throw ex;
            }
        }