public static string ComposeMessage(Domain.Socioboard.Enum.FbProfileType profiletype, string accessToken, string fbUserId, string message, string profileId, long userId, string imagePath, string link, Domain.Socioboard.Models.ScheduledMessage schmessage, Domain.Socioboard.Models.User _user)
        {
            string ret = "";
            var    dbr = new DatabaseRepository();

            try
            {
                var pageAccessToken = FacebookApiHelper.GetPageAccessToken(fbUserId, accessToken, string.Empty);
                var response        = FacebookApiHelper.PublishPostOnPage(pageAccessToken, fbUserId, message,
                                                                          imagePath, link);

                var isPublished = response.Contains("id");

                // if (isPublished)
                {
                    schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated;
                    dbr.Update(schmessage);
                    var notify        = new Notifications();
                    var notifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id);
                    if (notifications == null)
                    {
                        notify.MsgId            = schmessage.id;
                        notify.MsgStatus        = "Scheduled";
                        notify.notificationtime = schmessage.localscheduletime;
                        notify.NotificationType = "Schedule Successfully";
                        notify.ReadOrUnread     = "Unread";
                        notify.UserId           = userId;
                        dbr.Add(notify);
                        if (_user.scheduleSuccessUpdates)
                        {
                            var sucResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.error;
                dbr.Update(schmessage);
                apiHitsCount = MaxapiHitsCount;
                var notify        = new Notifications();
                var notifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id);
                if (notifications == null)
                {
                    notify.MsgId            = schmessage.id;
                    notify.MsgStatus        = "Failed";
                    notify.notificationtime = schmessage.localscheduletime;
                    notify.NotificationType = "Schedule Failed";
                    notify.ReadOrUnread     = "Unread";
                    notify.UserId           = userId;
                    dbr.Add(notify);
                    if (_user.scheduleFailureUpdates)
                    {
                        var falResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    }
                }
            }
            return(ret);
        }
示例#2
0
        public static string ComposeMessage(Domain.Socioboard.Enum.FbProfileType profiletype, string accessToken, string fbUserId, string message, string profileId, long userId, string imagePath, string link, Domain.Socioboard.Models.ScheduledMessage schmessage)
        {
            string             ret = "";
            DatabaseRepository dbr = new DatabaseRepository();
            FacebookClient     fb  = new FacebookClient();

            fb.AccessToken = accessToken;
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
            var args = new Dictionary <string, object>();

            if (!string.IsNullOrEmpty(message))
            {
                args["message"] = message;
            }
            if (profiletype == Domain.Socioboard.Enum.FbProfileType.FacebookProfile)
            {
                args["privacy"] = FbUser.SetPrivacy("Public", fb, profileId);
            }
            try
            {
                if (!string.IsNullOrEmpty(imagePath))
                {
                    Uri    u         = new Uri(imagePath);
                    string filename  = string.Empty;
                    string extension = string.Empty;
                    extension = System.IO.Path.GetExtension(u.AbsolutePath).Replace(".", "");
                    var media = new FacebookMediaObject
                    {
                        FileName    = "filename",
                        ContentType = "image/" + extension
                    };
                    var    webClient = new WebClient();
                    byte[] img       = webClient.DownloadData(imagePath);
                    media.SetValue(img);
                    args["source"] = media;
                    ret            = fb.Post("v2.1/" + fbUserId + "/photos", args).ToString();
                }
                else
                {
                    if (!string.IsNullOrEmpty(link))
                    {
                        args["link"] = link;
                    }
                    ret = fb.Post("v2.1/" + fbUserId + "/feed", args).ToString();
                }

                schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated;
                schmessage.url    = ret;
                dbr.Update <ScheduledMessage>(schmessage);
            }
            catch (Exception ex)
            {
                apiHitsCount = MaxapiHitsCount;
            }
            return(ret);
        }
        public static string ComposeMessage(Domain.Socioboard.Enum.FbProfileType profiletype, string accessToken, string fbUserId, string message, string profileId, long userId, string imagePath, string link, Domain.Socioboard.Enum.MediaType mediaType, string profileName, DatabaseRepository dbr, ILogger _logger)
        {
            string         ret = "";
            FacebookClient fb  = new FacebookClient();

            fb.AccessToken = accessToken;
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
            var args = new Dictionary <string, object>();

            if (!string.IsNullOrEmpty(message))
            {
                args["message"] = message;
            }
            if (profiletype == Domain.Socioboard.Enum.FbProfileType.FacebookProfile)
            {
                args["privacy"] = FbUser.SetPrivacy("Public", fb, profileId);
            }
            try
            {
                if (string.IsNullOrEmpty(link))
                {
                    if (!string.IsNullOrEmpty(imagePath))
                    {
                        if (!imagePath.Contains("mp4") && !imagePath.Contains("mov") && !imagePath.Contains("mpeg") && !imagePath.Contains("wmv") && !imagePath.Contains("avi") && !imagePath.Contains("flv") && !imagePath.Contains("3gp"))
                        {
                            Uri    u         = new Uri(imagePath);
                            string filename  = string.Empty;
                            string extension = string.Empty;
                            extension = System.IO.Path.GetExtension(u.AbsolutePath).Replace(".", "");
                            var media = new FacebookMediaObject
                            {
                                FileName    = "filename",
                                ContentType = "image/" + extension
                            };
                            var    webClient = new WebClient();
                            byte[] img       = webClient.DownloadData(imagePath);
                            media.SetValue(img);
                            args["source"] = media;
                            ret            = fb.Post("v2.7/" + fbUserId + "/photos", args).ToString();
                        }
                        else
                        {
                            Uri    u         = new Uri(imagePath);
                            string filename  = string.Empty;
                            string extension = string.Empty;
                            filename = imagePath.Substring(imagePath.IndexOf("get?id=") + 7);
                            if (!string.IsNullOrWhiteSpace(filename))
                            {
                                extension = filename.Substring(filename.IndexOf(".") + 1);
                            }
                            var media = new FacebookMediaObject
                            {
                                FileName    = filename,
                                ContentType = "video/" + extension
                            };
                            //byte[] img = System.IO.File.ReadAllBytes(imagepath);
                            var    webClient = new WebClient();
                            byte[] img       = webClient.DownloadData(imagePath);
                            media.SetValue(img);
                            args["title"]       = message;
                            args["description"] = message;
                            args["source"]      = media;
                            ret = fb.Post("v2.7/" + fbUserId + "/videos", args).ToString();//v2.1
                        }
                    }
                    else
                    {
                        args["message"] = message;
                        ret             = fb.Post("v2.7/" + fbUserId + "/feed", args).ToString();
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(link))
                    {
                        args["link"] = link;
                    }
                    if (!string.IsNullOrEmpty(imagePath))
                    {
                        args["picture"] = imagePath.Replace("&amp;", "&");
                    }
                    ret = fb.Post("v2.7/" + fbUserId + "/feed", args).ToString();//v2.1
                }
                ScheduledMessage scheduledMessage = new ScheduledMessage();
                scheduledMessage.createTime = DateTime.UtcNow;
                scheduledMessage.picUrl     = "https://graph.facebook.com/" + fbUserId + "/picture?type=small";//imagePath;
                scheduledMessage.profileId  = profileId;
                if (profiletype == Domain.Socioboard.Enum.FbProfileType.FacebookProfile)
                {
                    scheduledMessage.profileType = Domain.Socioboard.Enum.SocialProfileType.Facebook;
                }
                else
                {
                    scheduledMessage.profileType = Domain.Socioboard.Enum.SocialProfileType.FacebookFanPage;
                }
                scheduledMessage.scheduleTime      = DateTime.UtcNow;
                scheduledMessage.shareMessage      = message;
                scheduledMessage.userId            = userId;
                scheduledMessage.status            = Domain.Socioboard.Enum.ScheduleStatus.Compleated;
                scheduledMessage.url               = imagePath;//"https://graph.facebook.com/"+ fbUserId + "/picture?type=small";
                scheduledMessage.mediaType         = mediaType;
                scheduledMessage.socialprofileName = profileName;
                dbr.Add <ScheduledMessage>(scheduledMessage);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                _logger.LogError(ex.StackTrace);
            }
            return(ret);
        }
示例#4
0
        public static string ComposeMessage(Domain.Socioboard.Enum.FbProfileType profiletype, string accessToken, string fbUserId, string message, string profileId, long userId, string imagePath, string link, Domain.Socioboard.Models.ScheduledMessage schmessage, Domain.Socioboard.Models.User _user)
        {
            string             ret = "";
            DatabaseRepository dbr = new DatabaseRepository();
            FacebookClient     fb  = new FacebookClient();

            fb.AccessToken = accessToken;
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;


            var args = new Dictionary <string, object>();


            if (profiletype == Domain.Socioboard.Enum.FbProfileType.FacebookProfile)
            {
                args["privacy"] = FbUser.SetPrivacy("Public", fb, profileId);
            }
            try
            {
                if (string.IsNullOrEmpty(link))
                {
                    if (!string.IsNullOrEmpty(imagePath))
                    {
                        if (!string.IsNullOrEmpty(message))
                        {
                            args["message"] = message;
                        }

                        if (!imagePath.Contains("mp4") && !imagePath.Contains("mov") && !imagePath.Contains("mpeg") && !imagePath.Contains("wmv") && !imagePath.Contains("avi") && !imagePath.Contains("flv") && !imagePath.Contains("3gp"))
                        {
                            Uri    u         = new Uri(imagePath);
                            string filename  = string.Empty;
                            string extension = string.Empty;
                            extension = System.IO.Path.GetExtension(u.AbsolutePath).Replace(".", "");
                            var media = new FacebookMediaObject
                            {
                                FileName    = "filename",
                                ContentType = "image/" + extension
                            };
                            var    webClient = new WebClient();
                            byte[] img       = webClient.DownloadData(imagePath);
                            media.SetValue(img);
                            args["source"] = media;
                            ret            = fb.Post("v2.7/" + fbUserId + "/photos", args).ToString();
                        }
                        else
                        {
                            Uri    u         = new Uri(imagePath);
                            string filename  = string.Empty;
                            string extension = string.Empty;
                            filename = imagePath.Substring(imagePath.IndexOf("get?id=") + 7);
                            if (!string.IsNullOrWhiteSpace(filename))
                            {
                                extension = filename.Substring(filename.IndexOf(".") + 1);
                            }
                            var media = new FacebookMediaObject
                            {
                                FileName    = filename,
                                ContentType = "video/" + extension
                            };
                            //byte[] img = System.IO.File.ReadAllBytes(imagepath);
                            var    webClient = new WebClient();
                            byte[] img       = webClient.DownloadData(imagePath);
                            media.SetValue(img);
                            args["title"]       = message;
                            args["description"] = message;
                            args["source"]      = media;
                            ret = fb.Post("v2.7/" + fbUserId + "/videos", args).ToString();//v2.1
                        }
                    }
                    else
                    {
                        args["message"] = message;
                        ret             = fb.Post("v2.7/" + fbUserId + "/feed", args).ToString();
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(link))
                    {
                        if (message.Contains("https://") || message.Contains("http://"))
                        {
                            link = message;
                            if (link.Contains("https://"))
                            {
                                string links = getBetween(link + "###", "https", "###");
                                links = "https" + links;
                                try
                                {
                                    link = links.Split(' ')[0].ToString();
                                }
                                catch (Exception)
                                {
                                    link = links;
                                }
                            }
                            if (link.Contains("http://"))
                            {
                                string links = getBetween(link + "###", "http", "###");
                                links = "http" + links;
                                try
                                {
                                    link = links.Split(' ')[0].ToString();
                                }
                                catch (Exception)
                                {
                                    link = links;
                                }
                            }
                            message         = message.Replace(link, "");
                            args["message"] = message;
                        }
                        else
                        {
                            args["message"] = message;
                        }
                    }
                    else
                    {
                        args["message"] = message;
                    }
                    if (!string.IsNullOrEmpty(link))
                    {
                        args["link"] = link;
                    }
                    if (!string.IsNullOrEmpty(imagePath))
                    {
                        args["picture"] = imagePath.Replace("&amp;", "&");
                    }
                    ret = fb.Post("v2.7/" + fbUserId + "/feed", args).ToString();
                }

                schmessage.status = Domain.Socioboard.Enum.ScheduleStatus.Compleated;
                //schmessage.url = ret;
                dbr.Update <ScheduledMessage>(schmessage);
                Domain.Socioboard.Models.Notifications notify = new Notifications();
                Notifications lstnotifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id);
                if (lstnotifications == null)
                {
                    notify.MsgId            = schmessage.id;
                    notify.MsgStatus        = "Scheduled";
                    notify.notificationtime = schmessage.localscheduletime;
                    notify.NotificationType = "Schedule Successfully";
                    notify.ReadOrUnread     = "Unread";
                    notify.UserId           = userId;
                    dbr.Add <Notifications>(notify);
                    if (_user.scheduleSuccessUpdates)
                    {
                        string sucResponse = SendMailbySendGrid(AppSettings.frommail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    }
                }
                else
                {
                    if (_user.scheduleSuccessUpdates)
                    {
                        string sucResponse = SendMailbySendGrid(AppSettings.frommail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, true, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    }
                }
            }
            catch (Exception ex)
            {
                apiHitsCount = MaxapiHitsCount;
                Domain.Socioboard.Models.Notifications notify = new Notifications();
                Notifications lstnotifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id);
                if (lstnotifications == null)
                {
                    notify.MsgId            = schmessage.id;
                    notify.MsgStatus        = "Failed";
                    notify.notificationtime = schmessage.localscheduletime;
                    notify.NotificationType = "Schedule Failed";
                    notify.ReadOrUnread     = "Unread";
                    notify.UserId           = userId;
                    dbr.Add <Notifications>(notify);
                    if (_user.scheduleFailureUpdates)
                    {
                        string falResponse = SendMailbySendGrid(AppSettings.frommail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    }
                }
                else
                {
                    if (_user.scheduleFailureUpdates)
                    {
                        string falResponse = SendMailbySendGrid(AppSettings.frommail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime, false, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    }
                }
            }
            return(ret);
        }
示例#5
0
        public static string ComposeMessage(Domain.Socioboard.Enum.FbProfileType profiletype, string accessToken, string fbUserId, string message, string profileId, long userId, string imagePath, string link, Domain.Socioboard.Models.Mongo.SavedFeedsManagement schmessage, Domain.Socioboard.Models.User _user)
        {
            string             ret = "";
            DatabaseRepository dbr = new DatabaseRepository();
            FacebookClient     fb  = new FacebookClient();

            fb.AccessToken = accessToken;
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;


            var args = new Dictionary <string, object>();


            if (profiletype == Domain.Socioboard.Enum.FbProfileType.FacebookProfile)
            {
                args["privacy"] = FbUser.SetPrivacy("Public", fb, profileId);
            }
            try
            {
                if (string.IsNullOrEmpty(link))
                {
                    if (!string.IsNullOrEmpty(imagePath))
                    {
                        if (!string.IsNullOrEmpty(message))
                        {
                            args["message"] = message;
                        }

                        if (!imagePath.Contains("mp4") && !imagePath.Contains("mov") && !imagePath.Contains("mpeg") && !imagePath.Contains("wmv") && !imagePath.Contains("avi") && !imagePath.Contains("flv") && !imagePath.Contains("3gp"))
                        {
                            Uri    u         = new Uri(imagePath);
                            string filename  = string.Empty;
                            string extension = string.Empty;
                            extension = System.IO.Path.GetExtension(u.AbsolutePath).Replace(".", "");
                            var media = new FacebookMediaObject
                            {
                                FileName    = "filename",
                                ContentType = "image/" + extension
                            };
                            var    webClient = new WebClient();
                            byte[] img       = webClient.DownloadData(imagePath);
                            media.SetValue(img);
                            args["source"] = media;
                            ret            = fb.Post("v2.7/" + fbUserId + "/photos", args).ToString();
                        }
                        else
                        {
                            Uri    u         = new Uri(imagePath);
                            string filename  = string.Empty;
                            string extension = string.Empty;
                            filename = imagePath.Substring(imagePath.IndexOf("get?id=") + 7);
                            if (!string.IsNullOrWhiteSpace(filename))
                            {
                                extension = filename.Substring(filename.IndexOf(".") + 1);
                            }
                            var media = new FacebookMediaObject
                            {
                                FileName    = filename,
                                ContentType = "video/" + extension
                            };
                            //byte[] img = System.IO.File.ReadAllBytes(imagepath);
                            var    webClient = new WebClient();
                            byte[] img       = webClient.DownloadData(imagePath);
                            media.SetValue(img);
                            args["title"]       = message;
                            args["description"] = message;
                            args["source"]      = media;
                            ret = fb.Post("v2.7/" + fbUserId + "/videos", args).ToString();//v2.1
                        }
                    }
                    else
                    {
                        args["message"] = message;
                        ret             = fb.Post("v2.7/" + fbUserId + "/feed", args).ToString();
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(link))
                    {
                        if (message.Contains("https://") || message.Contains("http://"))
                        {
                            link = message;
                            if (link.Contains("https://"))
                            {
                                string links = getBetween(link + "###", "https", "###");
                                links = "https" + links;
                                try
                                {
                                    link = links.Split(' ')[0].ToString();
                                }
                                catch (Exception)
                                {
                                    link = links;
                                }
                            }
                            if (link.Contains("http://"))
                            {
                                string links = getBetween(link + "###", "http", "###");
                                links = "http" + links;
                                try
                                {
                                    link = links.Split(' ')[0].ToString();
                                }
                                catch (Exception)
                                {
                                    link = links;
                                }
                            }
                            message         = message.Replace(link, "");
                            args["message"] = message;
                        }
                        else
                        {
                            args["message"] = message;
                        }
                    }
                    else
                    {
                        args["message"] = message;
                    }
                    if (!string.IsNullOrEmpty(link))
                    {
                        args["link"] = link;
                    }
                    if (!string.IsNullOrEmpty(imagePath))
                    {
                        args["picture"] = imagePath.Replace("&amp;", "&");
                    }
                    ret = fb.Post("v2.7/" + fbUserId + "/feed", args).ToString();
                }
                MongoRepository mongorepo = new Helper.MongoRepository("SavedFeedsComments");
                schmessage.status = Domain.Socioboard.Enum.ScheduledStatusFeedsManager.Published;
                FilterDefinition <BsonDocument> filterIds = new BsonDocument("strId", schmessage.strId);
                var updatetime = Builders <BsonDocument> .Update.Set("status", schmessage.status);

                mongorepo.Update <Domain.Socioboard.Models.Mongo.SavedFeedsComments>(updatetime, filterIds);
            }
            catch (Exception ex)
            {
            }
            return(ret);
        }
        public static string DaywiseComposeMessage(Domain.Socioboard.Enum.FbProfileType profiletype, string accessToken, string fbUserId, string message, string profileId, long userId, string imagePath, string link, Domain.Socioboard.Models.DaywiseSchedule schmessage, Domain.Socioboard.Models.User _user)
        {
            string ret = "";
            var    dbr = new DatabaseRepository();

            try
            {
                var pageAccessToken = FacebookApiHelper.GetPageAccessToken(fbUserId, accessToken, string.Empty);
                var response        = FacebookApiHelper.PublishPostOnPage(pageAccessToken, fbUserId, message,
                                                                          imagePath, link);

                var isPublished = response.Contains("id");

                if (isPublished)
                {
                    var selectDayObject = JsonConvert.DeserializeObject <List <string> >(schmessage.weekdays);

                    schmessage.scheduleTime = DateTimeHelper.GetNextScheduleDate(selectDayObject, schmessage.scheduleTime);

                    if (schmessage.scheduleTime.Date == DateTime.Today)
                    {
                        schmessage.scheduleTime = schmessage.scheduleTime.AddDays(7);
                    }

                    dbr.Update(schmessage);
                    var notify        = new Notifications();
                    var notifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id);
                    if (notifications == null)
                    {
                        notify.MsgId            = schmessage.id;
                        notify.MsgStatus        = "Scheduled";
                        notify.notificationtime = schmessage.localscheduletime.ToString();
                        notify.NotificationType = "Schedule Successfully";
                        notify.ReadOrUnread     = "Unread";
                        notify.UserId           = userId;
                        dbr.Add(notify);
                        if (_user.scheduleSuccessUpdates)
                        {
                            var sucResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime.ToString(), true, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                apiHitsCount = MaxapiHitsCount;
                var notify        = new Notifications();
                var notifications = dbr.Single <Notifications>(t => t.MsgId == schmessage.id);
                if (notifications == null)
                {
                    notify.MsgId            = schmessage.id;
                    notify.MsgStatus        = "Failed";
                    notify.notificationtime = schmessage.localscheduletime.ToString();
                    notify.NotificationType = "Schedule Failed";
                    notify.ReadOrUnread     = "Unread";
                    notify.UserId           = userId;
                    dbr.Add(notify);
                    if (_user.scheduleFailureUpdates)
                    {
                        string falResponse = SendMailbySendGrid(AppSettings.from_mail, "", _user.EmailId, "", "", "", "", _user.FirstName, schmessage.localscheduletime.ToString(), false, AppSettings.sendGridUserName, AppSettings.sendGridPassword);
                    }
                }
            }
            return(ret);
        }