コード例 #1
0
ファイル: PostService.cs プロジェクト: ziadkasmani/sample
        public void SchedulePost(string postIds)
        {
            PostManager mgr = new PostManager();
            mgr.SchedulePost(Convert.ToInt64(postIds), null);

            var obj = Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext<HeyVoteHub>();
            new PostManager().GetNotificationUserList(postIds).ForEach(x =>
            {
                var signalR = HeyVoteHub.MyUsers.Where(y => y.Value.Equals(x.NotifyUserIdf)).FirstOrDefault();
                if (!signalR.Equals(default(KeyValuePair<string, string>)))
                    obj.Clients.Client(signalR.Key).notifyUsers(new
                    {
                        Id = x.Id,
                        Title = x.Title,
                        UserIdf = x.UserIdf,
                        ImageIdf = x.ImageIdf,
                        Image1Idf = x.Image1Idf,
                        FolderPath = x.FolderPath,
                        CreatedOn = x.CreatedOn,
                        Caption1 = x.Caption1,
                        Caption2 = x.Caption2,
                        DisplayName = x.DisplayName,
                        PostId = x.PostId,
                        EndDate = x.EndDate
                    });
            });
        }
コード例 #2
0
ファイル: PostService.cs プロジェクト: ziadkasmani/sample
        public string AddPost(PostInfo info, ResourceInfo resource1Info, ResourceInfo resource2Info, List<ContactInfo> lstContacts, bool isPicture, bool isVideo, bool isAudio, bool isWeb)
        {
            try
            {
                if (!String.IsNullOrWhiteSpace(info.Title) && !String.IsNullOrWhiteSpace(info.Caption1) && !String.IsNullOrWhiteSpace(info.Caption2)
                     && !String.IsNullOrWhiteSpace(resource1Info.DataUrl) && info.Duration >= 5 && info.Duration <= 60
                     && (info.IsPublic == true || info.ToContacts == true || (info.ToSelectedContacts == true && lstContacts.Count > 0))
                     && (info.TerritoryId != null || info.IsGlobal == true) && (isPicture || isVideo || isAudio) && (info.CategoryId == 1 || info.CategoryId == 2 || info.CategoryId == 3))
                {
                    PostManager mgr = new PostManager();

                    TokenInfo tokenInfo = new HelperMethods().GetUserToken<TokenInfo>(isWeb, HttpContext.Current);

                    resource1Info.Data = JsonWebToken.Base64UrlDecode(resource1Info.DataUrl);

                    if (resource2Info != null && !String.IsNullOrWhiteSpace(resource2Info.DataUrl))
                        resource2Info.Data = JsonWebToken.Base64UrlDecode(resource2Info.DataUrl);

                    // Sets user token from cookie
                    info.UserIdf = tokenInfo.Idf;
                    info.EndDate = DateTime.UtcNow.AddMinutes(info.Duration);

                    if (info.IsPublic)
                    {
                        info.ToContacts = false;
                        info.ToSelectedContacts = false;
                    }
                    else if (info.ToContacts)
                    {
                        info.ToSelectedContacts = false;
                        info.IsPublic = false;
                    }
                    else if (info.ToSelectedContacts)
                    {
                        info.IsPublic = false;
                        info.ToContacts = false;
                    }

                    if (isPicture)
                    {
                        isVideo = false;
                        isAudio = false;
                    }
                    else if (isVideo)
                    {
                        isPicture = false;
                        isAudio = false;
                    }
                    else if (isAudio)
                    {
                        isVideo = false;
                        isPicture = false;
                    }

                    EnumPostType postType = isPicture ? EnumPostType.Picture : (isVideo ? EnumPostType.Video : (isAudio ? EnumPostType.Audio : EnumPostType.Picture));

                    var guids = mgr.AddPostImages(resource1Info, resource2Info, tokenInfo.FolderPath, postType);
                    long postId = mgr.AddPost(info, guids[0], guids[1], postType, tokenInfo.FolderPath);
                    if (info.ToSelectedContacts)
                    {
                        List<ContactInfo> lstFilteredContacts = new List<ContactInfo>();
                        ContactManager conMgr = new ContactManager();
                        lstContacts.ForEach(x =>
                        {
                            if (!String.IsNullOrWhiteSpace(x.ContactToken))
                            {
                                try
                                {
                                    TokenInfo contactToken = JsonWebToken.DecodeToken<TokenInfo>(x.ContactToken, CodeHelper.SecretAccessKey, true, false);
                                    x.ContactIdf = contactToken.Idf;
                                    lstFilteredContacts.Add(x);
                                }
                                catch (Exception)
                                {
                                    // if contact does not have all details, ignore it
                                }
                            }

                        });
                        conMgr.SavePostContacts(info.UserIdf, info.TerritoryId, info.IsGlobal, postId, lstFilteredContacts);
                    }

                    // schedule job
                    mgr.SchedulePost(postId, info.EndDate);

                    // send notification to all users either GCM or SignalR stating your contact has posted something
                    var obj = GlobalHost.ConnectionManager.GetHubContext<HeyVoteHub>();
                    new PostManager().GetNotificationUserList(postId.ToString()).ForEach(x =>
                    {
                        var signalR = HeyVoteHub.MyUsers.Where(y => y.Value.Equals(x.NotifyUserIdf)).FirstOrDefault();
                        if (!signalR.Equals(default(KeyValuePair<string, string>)))
                            obj.Clients.Client(signalR.Key).notifyUsers(new
                            {
                                Id = x.Id,
                                Title = x.Title,
                                UserIdf = x.UserIdf,
                                ImageIdf = x.ImageIdf,
                                Image1Idf = x.Image1Idf,
                                FolderPath = x.FolderPath,
                                CreatedOn = x.CreatedOn,
                                Caption1 = x.Caption1,
                                Caption2 = x.Caption2,
                                DisplayName = x.DisplayName,
                                PostId = x.PostId,
                                EndDate = x.EndDate,
                                isPost = x.isPost,
                                isFollow = x.isFollow,
                                isContact = x.isContact,
                                hasRead = false,
                                isViewed = false
                            });
                    });

                    return true.ToString();
                }
                return false.ToString();
            }
            catch (Exception ex)
            {
                throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError);
            }
        }