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(), ""); } }