public bool UpdateStatus(string token, string SecretKey) { try { var consumerKey = ConfigurationManager.AppSettings["TwitterConsumerKey"]; var consumerSecret = ConfigurationManager.AppSettings["TwitterConsumerSecret"]; string ADID = Request.QueryString["ADID"]; OAuthTokens accessToken = new OAuthTokens(); accessToken.AccessToken = token; accessToken.AccessTokenSecret = SecretKey; accessToken.ConsumerKey = consumerKey; accessToken.ConsumerSecret = consumerSecret; string postcontent = "Tweeted via " + ofbBiz.GetAppPath(Convert.ToString(Request.QueryString["app_id"])); // string postcontent = "Tweeted via " + ofbBiz.GetAppPath(Convert.ToString(Request.QueryString["app_id"])); TwitterResponse<TwitterStatus> tweetResponse = TwitterStatus.Update(accessToken, postcontent); if (tweetResponse.Result == RequestResult.Success) { //Tweeted Successfully SonetPie osonetpie = new SonetPie(); AppLeadData oAppLeadData = new AppLeadData(); AppProduct dAppproduct = new AppProduct(); dAppproduct = ofbBiz.GetAppProduct(ADID); string PDID = dAppproduct.DID; string _sNotifierDID = new AppNotifier().GetNewDIDWithPrefix(); string NDID = _sNotifierDID; //Load app settings oDCAppUser = ofbBiz.GetAppUser(osonetpie, ADID, SessionData.TwitterData.CachedUserId1); oAppProduct = ofbBiz.GetAppProductDetails(osonetpie, PDID); ofbBiz.RaiseAppNotifier(oDCAppUser, "TWEET", oDCAppUser.DID, PDID, NDID, oAppLeadData, string.Empty); } else { // Something bad happened } return true; } catch (Exception ex) { } return false; }
protected override void OnPreLoad(EventArgs e) { try { base.OnPreLoad(e); FacebookBizProcess fbBiz = new FacebookBizProcess(); FaceBook oFBUtility = new FaceBook(); SonetPieBizProcess sonetpiebiz = new SonetPieBizProcess(); SonetPie sonetpie = new SonetPie(); NotifyURL = ConfigurationSettings.AppSettings["NotifyURL"]; pageRefreshed = false; if (QSVars.Contains("user_id")) { Session["facebook_user_id"] = QSVars["user_id"].ToString(); } if (QSVars.Contains("UDID")) { Session["sr_user_did"] = QSVars["UDID"].ToString(); } if (QSVars.Contains("PDID")) { Session["sr_product_did"] = QSVars["PDID"].ToString(); } if (Request.Url.Query.Contains("request") && !(Request.Url.Query.Contains("fb_source"))) //AppRequest callback, now save to notifiers { for (int i = 0; i < Request.QueryString.Count - 2; i++) { //every Request["to[i]"] has a userID for AppNotifier string fbUID = Request["to[" + i + "]"].ToString(); string _sNotifierDID = new AppNotifier().GetNewDIDWithPrefix(); string facebook_user_id = Convert.ToString(Session["facebook_user_id"]); string UDID = Convert.ToString(Session["sr_user_did"]); if (QSVars.Contains("NDID")) QSVars["NDID"] = _sNotifierDID; else QSVars.Add("NDID", _sNotifierDID); //Build DCAppWallPost for each user AppUser oDCAppUser = new AppUser(); string ConfigDID = fbBiz.GetConfigDEED(Convert.ToString(QSVars["app_id"])); if (!QSVars.Contains("ADID")) { QSVars.Add("ADID", ConfigDID); } if (!QSVars.Contains("PDID")) { QSVars.Add("PDID", Convert.ToString(Session["sr_product_did"])); } oDCAppUser = ofbBiz.GetAppUser(osonetpie, QSVars["ADID"].ToString(), facebook_user_id); _oDCAppWallPost.FromUserID = Convert.ToString(QSVars["user_id"]); _oDCAppWallPost.ToUserID = fbUID; _oDCAppWallPost.Name = ofbBiz.GetCustomTabName(QSVars["app_id"].ToString()); _oDCAppWallPost.Source = Convert.ToString(QSVars["user_id"]); AppLeadData oAppLead = new AppLeadData(); if (Request.Browser.IsMobileDevice == true || Request.UserAgent.ToLower().Contains("iphone") || Request.UserAgent.ToLower().Contains("android")) { if (fbBiz.RaiseAppNotifier(oDCAppUser, "MPOST", UDID, Convert.ToString(QSVars["PDID"]), "", fbUID)) { } } else { if (fbBiz.RaiseAppNotifier(oDCAppUser, "POST", UDID, Convert.ToString(QSVars["PDID"]), "", fbUID)) { } } } Page.ClientScript.RegisterStartupScript(this.GetType(), "myCloseScript", "window.close();", true); } if (Request["code"] == null) { if ((Request.QueryString.Count > 0) && !(Request["LIKED"] != null)) { //ParseRequest & set values to qsvars if (!(Request.QueryString).AllKeys[0].ToString().Contains("tabs_added")) { //REVISIT sonetpie.QSvarsString = GetQsVarsCollection(); sonetpie.FormvarsString = GetFormVarsCollection(); sonetpie.AbsolutePath = AbsolutePagePath; if (Request.Form.ToString() != string.Empty) { FormVars.Add("signed_request", Request.Form.Get(0).ToString()); } //Init Biz //SonetPieBizProcess sonetpiebiz = new SonetPieBizProcess(); if (QSVars.Contains("app_id")) { if (EnableAppServices) _oDCAppConfiguration = sonetpiebiz.GetAppConfiguration("", QSVars["app_id"].ToString()); SessionData.Config.DID = _oDCAppConfiguration.DID; //DigiMa.Common.FaceBook oFBUtility1 = new DigiMa.Common.FaceBook(); //check AppConfig got loaded if (AppConfig != null) { //Add CDID to Load customer if (QSVars.Contains("CDID")) QSVars["CDID"] = AppConfig.AppCustomerDID; else QSVars.Add("CDID", AppConfig.AppCustomerDID); //Add ADID to Load customer if (QSVars.Contains("ADID")) QSVars["ADID"] = AppConfig.DID; else QSVars.Add("ADID", AppConfig.DID); //Reset KOKO QSVars sonetpie.QSvarsString = GetQsVarsCollection(); _oDCAppCustomer = fbBiz.GetAppCustomer(Convert.ToString(QSVars["CDID"])); //ParseSigned Request if ((!QSVars.Contains("oauth_token"))) { oFBUtility.ParseSignedRequest(ref _qsVars, ref _frmVars, AppConfig); } if (QSVars.Contains("oauth_token")) { Session["oauth_token"] = Convert.ToString(QSVars["oauth_token"]); } if (QSVars.Contains("user_id")) { Session["user_id"] = Convert.ToString(QSVars["user_id"]); } //call graph to get page_Acc_tok if (QSVars.Contains("oauth_token") && (_oDCAppConfiguration.SAppCustomNameAdded == null || _oDCAppConfiguration.SAppCustomNameAdded == "")) { page_access_token = facebook.GetPageAccessToken(QSVars["oauth_token"].ToString()); System.Web.Script.Serialization.JavaScriptSerializer _oJavaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer(); JObject obj = JObject.Parse(page_access_token); IEnumerable<string> query = from res in (Newtonsoft.Json.Linq.JArray)obj["data"] let reso = res as JObject where ((string)reso["id"]).ToLower() == _oDCAppConfiguration.SPageID select (string)reso["access_token"]; //fetch the logo of this Campaign from AppProduct and pass to CallPages if (facebook.CallPages(_oDCAppConfiguration.SPageID, query.ToList()[0].ToString(), "app_" + QSVars["app_id"].ToString(), _oDCAppConfiguration.SCustomtTabName, fbBiz.FetchAppLogo(QSVars["app_id"].ToString()))) { //update custom_updated to Y fbBiz.UpdateCustomTabNAme(_oDCAppConfiguration.DID); ClientScript.RegisterStartupScript(this.GetType(), "scriptid", "window.parent.location.href='" + _oDCAppConfiguration.SAppPagePath + "'", true); } } //parse the JSON if (HasAuthorization) { if (!QSVars.Contains("oauth_token")) { //Set Authorization stamp on redirect url AppConfig.AppPath += "?soNETSrc="; if (QSVars.Contains("NDID")) AppConfig.AppPath += Convert.ToString(QSVars["NDID"]); else AppConfig.AppPath += "NULL"; //oFBUtility.GetAccessToken(QSVars["code"].ToString(), "user_location,email,friends_location,publish_stream",AppConfig.AppPath,AppConfig); // CHeck if Request is coming from Mobile device, then open Standalone if (Request.Browser.IsMobileDevice == true || Request.UserAgent.ToLower().Contains("iphone") || Request.UserAgent.ToLower().Contains("android")) { //oFBUtility.AuthorizeMob(this, "user_location,email,friends_location,user_birthday", AppConfig); } else { oFBUtility.Authorize(this, "user_location,email,friends_location,user_birthday", AppConfig); } } else { //Insert user into DB if (true) { //Call service to store into DB AppUser oDCAppUser = new AppUser(); oDCAppUser.AppConfigDID = AppConfig.DID; oDCAppUser.EmailID = "NULL"; oDCAppUser.SonetID = Convert.ToString(QSVars["user_id"]); oDCAppUser.SonetSRC = Convert.ToString(QSVars["soNETSrc"]); oDCAppUser.UserStatus = "Active"; oDCAppUser.SMType = "FB"; oDCAppUser = oFBUtility.GetUserDetail(Convert.ToString(QSVars["user_id"]), Convert.ToString(QSVars["oauth_token"]), oDCAppUser); //Save to DB if (!fbBiz.IsUserCreatedForFacebook(oDCAppUser.SonetID, oDCAppUser.AppConfigDID)) { if (fbBiz.SetAppUserAuthorize(oDCAppUser, Convert.ToString(QSVars["ADID"]))) _oDCAppUser = oDCAppUser; } } } } } //refrsh to get tab name //fbBiz.UpdateCustomTabNAme(_oDCAppConfiguration.DID); //ClientScript.RegisterStartupScript(this.GetType(), "scriptid", "window.parent.location.href='" + _oDCAppConfiguration.SAppPagePath + "'", true); //Load AppUser based on property if (_bEnableAppUser && _qsVars.Contains("user_id")) { sonetpie.QSvarsString = GetQsVarsCollection(); _oDCAppUser = fbBiz.GetAppUser(sonetpie, Convert.ToString(QSVars["ADID"]), Convert.ToString(QSVars["user_id"])); if (_oDCAppUser != null) { if (!_qsVars.Contains("UDID")) _qsVars.Add("UDID", _oDCAppUser.DID); else _qsVars["UDID"] = _oDCAppUser.DID; if (QSVars.Count < 8) { ClientScript.RegisterStartupScript(this.GetType(), "scriptid", "window.parent.location.href='" + _oDCAppConfiguration.SAppPagePath + "'", true);//To ensure all QSVARS are loaded from facebook } } } //Update Notifier count based on NDID or soNETSrc if (QSVars.Contains("soNETSrc") || QSVars.Contains("NDID")) { AppNotifier oAppNotifier = new AppNotifier(); if (QSVars.Contains("soNETSrc")) oAppNotifier.DID = Convert.ToString(QSVars["soNETSrc"]); if (QSVars.Contains("NDID")) oAppNotifier.DID = Convert.ToString(QSVars["NDID"]); if (!string.IsNullOrEmpty(oAppNotifier.DID)) fbBiz.EditAppNotifierDetails(oAppNotifier); } } } } else { // } } else { //Here redirect user to Page path if (QSVars.Contains("app_id") && QSVars.Contains("soNETSrc")) { //string pageToRedirect = fbBiz.GetAppPagePath(Convert.ToString(QSVars["app_id"])); //Response.Redirect(pageToRedirect,true); } } } catch (Exception ex) { CommonUtility commUtil = new CommonUtility(); commUtil.SendErrorMail(ex.Message, ex.StackTrace, System.Reflection.MethodBase.GetCurrentMethod().Name.ToString(), System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), SessionData.Customer.CustomerID); } }
protected override void OnPreLoad(EventArgs e) { string PDID = string.Empty; string NDID = string.Empty; string ADID = string.Empty; string UDID = string.Empty; string NTYP = string.Empty; string user_id = string.Empty; string TO_id = string.Empty; try { base.OnPreLoad(e); //Initialize KOKO SonetPie osonetpie = new SonetPie(); osonetpie.QSvarsString = GetQsVarsCollection(); osonetpie.AbsolutePath = AbsolutePagePath; //Call Service to load app settings AppUser oAppUser = new AppUser(); AppLeadData oAppLead = new AppLeadData(); FacebookBizProcess ofbBiz = new FacebookBizProcess(); SonetPieBizProcess sonetpiebiz = new SonetPieBizProcess(); //CHeck if User has Liked. Using Jquery AJAX we will get Params in Request.Form if (Request.HttpMethod == "POST") { PDID = Request.Form["PDID"]; NDID = Request.Form["NDID"]; ADID = Request.Form["ADID"]; UDID = Request.Form["UDID"]; NTYP = Request.Form["NTYP"]; user_id = Request.Form["user_id"]; oAppUser = ofbBiz.GetAppUser(osonetpie, ADID, user_id); if (NTYP != null && UDID != null && PDID != null) { if (ofbBiz.RaiseAppNotifier(oAppUser, NTYP, UDID, PDID, NDID, oAppLead, string.Empty)) litRunTimeHTMLContent.Text = "Successfully raised notifier."; else litRunTimeHTMLContent.Text = "Unable to raise notifier."; } else litRunTimeHTMLContent.Text = "In-Complete information."; } else { if (QSVars["NTYP"].ToString().Equals("MPOST")) { if (!QSVars.Contains("UDID")) { UDID = ofbBiz.GetUserDID(QSVars["ADID"].ToString(), Request["userID"].ToString()); if (Request.Cookies.AllKeys[0] != null) { TO_id = Request.Cookies.AllKeys[0]; if (TO_id.Contains(",")) { string[] allFriends = TO_id.Split(','); for (int i = 0; i < allFriends.Length; i++) { if (ofbBiz.RaiseAppNotifier(oAppUser, Convert.ToString(QSVars["NTYP"]), UDID, Convert.ToString(QSVars["PDID"]), "", oAppLead, allFriends[i])) litRunTimeHTMLContent.Text = "Successfully raised notifier."; else litRunTimeHTMLContent.Text = "Unable to raise notifier."; } } else { if (ofbBiz.RaiseAppNotifier(oAppUser, Convert.ToString(QSVars["NTYP"]), UDID, Convert.ToString(QSVars["PDID"]), "", oAppLead, TO_id)) litRunTimeHTMLContent.Text = "Successfully raised notifier."; else litRunTimeHTMLContent.Text = "Unable to raise notifier."; } } } if (ofbBiz.RaiseAppNotifier(oAppUser, Convert.ToString(QSVars["NTYP"]), UDID, Convert.ToString(QSVars["PDID"]), "", oAppLead, TO_id)) litRunTimeHTMLContent.Text = "Successfully raised notifier."; else litRunTimeHTMLContent.Text = "Unable to raise notifier."; } else { bool CheckLikeNotify = ofbBiz.CheckLikeNotify(QSVars["UDID"].ToString()); if (CheckLikeNotify != true) { oAppUser = ofbBiz.GetAppUser(osonetpie, QSVars["ADID"].ToString(), QSVars["user_id"].ToString()); //Load AppUser from DB Based on user_id if (QSVars.Contains("NTYP") && QSVars.Contains("UDID") && QSVars.Contains("PDID")) { if (ofbBiz.RaiseAppNotifier(oAppUser, Convert.ToString(QSVars["NTYP"]), Convert.ToString(QSVars["UDID"]), Convert.ToString(QSVars["PDID"]), Convert.ToString(QSVars["NDID"]), oAppLead, string.Empty)) litRunTimeHTMLContent.Text = "Successfully raised notifier."; else litRunTimeHTMLContent.Text = "Unable to raise notifier."; } else litRunTimeHTMLContent.Text = "In-Complete information."; } } } } catch (Exception ex) { DigiMa.Common.CommonUtility objCommon = new CommonUtility(); objCommon.SendErrorMail(ex.Message, ex.StackTrace, System.Reflection.MethodBase.GetCurrentMethod().Name.ToString(), System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), ""); } }
//For Share, Like, Lead public bool RaiseAppNotifier(AppUser oDCAppUser, string NTYP, string UDID, string PDID, string NDID, AppLeadData oAppLeadData, string TO_id) { //Check Event is sucess or not bool _bSetAppNotifierSuccess = false; try { //Validate NTYP before switching to respective notifier if (string.IsNullOrEmpty(NTYP)) return _bSetAppNotifierSuccess; //Build Post DCAppNotifier AppNotifier _oDCAppNotifier = new AppNotifier(); _oDCAppNotifier.AppUserDID = UDID; _oDCAppNotifier.AppProductDID = PDID; //Check if NDID already defined if so use it if (!string.IsNullOrEmpty(NDID)) _oDCAppNotifier.DID = NDID; else _oDCAppNotifier.DID = _oDCAppNotifier.GetNewDIDWithPrefix(); _oDCAppNotifier.NoOfVisits = 0; //Check which notifier to call based on NTYP switch (NTYP.ToUpper()) { case "SHARE": _oDCAppNotifier.NotifierType = "SHARE"; _bSetAppNotifierSuccess = fbDALC.AddAppNotifierDetails(GetSonetPie, _oDCAppNotifier); break; case "LEAD": _oDCAppNotifier.NotifierType = "LEAD"; _oDCAppNotifier.SoNetEmailID = oAppLeadData.EmailID; _oDCAppNotifier.SoNetEmailContext = oAppLeadData.Subject; _oDCAppNotifier.SoNetEmailContent = oAppLeadData.Body; _bSetAppNotifierSuccess = fbDALC.AddAppNotifierDetails(GetSonetPie, _oDCAppNotifier); break; case "LIKE": _oDCAppNotifier.NotifierType = "LIKE"; _bSetAppNotifierSuccess = fbDALC.AddAppNotifierDetails(GetSonetPie, _oDCAppNotifier); break; case "MSHARE": _oDCAppNotifier.NotifierType = "MSHARE"; _bSetAppNotifierSuccess = fbDALC.AddAppNotifierDetails(GetSonetPie, _oDCAppNotifier); break; case "TWEET": _oDCAppNotifier.NotifierType = "TWEET"; _bSetAppNotifierSuccess = fbDALC.AddAppNotifierDetails(GetSonetPie, _oDCAppNotifier); break; case "MPOST": _oDCAppNotifier.NotifierType = "MPOST"; _oDCAppNotifier.SoNetFriendID = TO_id; if (!TO_id.Contains(",")) { _bSetAppNotifierSuccess = fbDALC.AddAppNotifierDetails(GetSonetPie, _oDCAppNotifier); } break; case "MLIKE": _oDCAppNotifier.NotifierType = "MLIKE"; _bSetAppNotifierSuccess = fbDALC.AddAppNotifierDetails(GetSonetPie, _oDCAppNotifier); break; case "CLICK": _oDCAppNotifier.NotifierType = "CLICK"; _bSetAppNotifierSuccess = fbDALC.AddAppNotifierDetails(GetSonetPie, _oDCAppNotifier); break; case "LISHARE": _oDCAppNotifier.NotifierType = "LISHARE"; _bSetAppNotifierSuccess = fbDALC.AddAppNotifierDetails(GetSonetPie, _oDCAppNotifier); break; default: _bSetAppNotifierSuccess = false; break; } return _bSetAppNotifierSuccess; } catch (Exception ex) { //Log4NetUtility.ErrorDebug(this.GetType().FullName, "Error in DCAppConfiguration GetAppConfiguration()", ex); throw ex; } }
protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); //Initialize API Core FaceBook oFacebook = new FaceBook(); //Initialize KOKO SonetPie osonetpie = new SonetPie(); QSVars.Add("NTYP", "LEAD"); osonetpie.QSvarsString = GetQsVarsCollection(); osonetpie.AbsolutePath = AbsolutePagePath; //Load app settings oDCAppUser = fbBizProc.GetAppUser(osonetpie, QSVars["ADID"].ToString(), QSVars["user_id"].ToString()); oAppProduct = fbBizProc.GetAppProductDetails(osonetpie, QSVars["PDID"].ToString()); //get Inquiry Email if exists //fetch Inmquiry EMAIL data string inquiryEmail; inquiryEmail = fbBizProc.GetInquiryEmail(Convert.ToString(QSVars["ADID"])); //Bind Post content at runtime if (oAppProduct.DID.Equals("AP006KV63YSPT0ZDHTMD")) { txtLeadContent.Text = "I am interested to know more on this event."; } else if (oAppProduct.DID.Equals("AP000CH69W22X9KDGZTT") || oAppProduct.DID.Equals("AP001CS762FRSC4BPCV3") || oAppProduct.DID.Equals("AP005S976CL8C85Y2HV5") || oAppProduct.DID.Equals("AP002PX605GMMMG9MQ59")) { txtLeadContent.Text = "I am interested to know more on this product."; } lblProductSummary.Text = GetProductSummary(); //Prefill product context if (oAppProduct != null) { if (oAppProduct.DID.Equals("AP006KV63YSPT0ZDHTMD")) { txtLeadContext.Text = oAppProduct.ProductName + " event inquiry"; } else if (oAppProduct.DID.Equals("AP000CH69W22X9KDGZTT") || oAppProduct.DID.Equals("AP001CS762FRSC4BPCV3") || oAppProduct.DID.Equals("AP005S976CL8C85Y2HV5") || oAppProduct.DID.Equals("AP002PX605GMMMG9MQ59")) { txtLeadContext.Text = oAppProduct.ProductName + " product inquiry"; } } else txtLeadContext.Text = "product inquiry"; //Prefill Email id if (!string.IsNullOrEmpty(inquiryEmail)) txtLeadEmailID.Text = oDCAppUser.EmailID; //Clear Error text lblValidationSummary.Text = string.Empty; //Perform Post to wall friends & Store notifierDID stat if (this.IsPostBack && oAppProduct != null && AppCustomer != null && AppConfig != null) { if (FormVars.Contains("BtnSubmit")) { if (Convert.ToString(FormVars["txtLeadEmailID"]).Trim().Length <= 0) Page.ClientScript.RegisterStartupScript(this.GetType(), "myCloseScript", "alert(\"Specify email id.\")", true); else if (Convert.ToString(FormVars["txtLeadContext"]).Trim().Length <= 0) lblValidationSummary.Text = "Specify email subject."; else if (Convert.ToString(FormVars["txtLeadContent"]).Trim().Length <= 0) lblValidationSummary.Text = "Specify email content."; else { AppLeadData oAppLeadData = new AppLeadData(); oAppLeadData.EmailID = Convert.ToString(FormVars["txtLeadEmailID"]); oAppLeadData.Subject = Convert.ToString(FormVars["txtLeadContext"]); oAppLeadData.Body = Convert.ToString(FormVars["txtLeadContent"]); string _sNotifierDID = new AppNotifier().GetNewDIDWithPrefix(); if (QSVars.Contains("NDID")) QSVars["NDID"] = _sNotifierDID; else QSVars.Add("NDID", _sNotifierDID); if (fbBizProc.RaiseAppNotifier(oDCAppUser, "LEAD", QSVars["UDID"].ToString(), QSVars["PDID"].ToString(), QSVars["NDID"].ToString(), oAppLeadData, string.Empty)) { //Now send email CommonUtility comUtil = new CommonUtility(); custTabName = fbBizProc.GetCustomTabName(Convert.ToString(QSVars["app_id"])); comUtil.SendEnquiryMail(inquiryEmail, oAppLeadData.Subject, oAppLeadData.Body, custTabName, oAppProduct,oDCAppUser.EmailID); Page.ClientScript.RegisterStartupScript(this.GetType(), "myCloseScript", "window.close()", true); } } } } //Set error message section if (!string.IsNullOrEmpty(lblValidationSummary.Text)) trErrorMsg.Visible = true; else trErrorMsg.Visible = false; }