public string StandardResponse(HttpApplication application) { IDictionary <string, object> data; if (!application.TryGetData(out data)) { return("Error: No Glimpse Data Found"); } var json = JsSerializer.Serialize(data); //serialize data to Json json = Sanitizer.Sanitize(json); //if ajax request, render glimpse data to headers if (application.IsAjax()) { application.Response.AddHeader(GlimpseConstants.HttpHeader, json); } else { var html = string.Format( @"<script type='text/javascript' id='glimpseData'>var glimpse = {0};</script>", json); html += @"<script type='text/javascript' id='glimpseClient' src='/Glimpse/glimpseClient.js'></script>"; html += @"<!--<img src='/Glimpse/glimpseSprite.png'/>-->"; application.Response.Write(html); } return(json); }
public override void Respond(HttpApplication application, GlimpseConfiguration config) { if (!application.IsValidRequest(config, false, checkPath: false)) { var data = JsSerializer.Serialize(new { Error = true, Message = "You are not configured to access history." }); JsonResponse(application, data); return; } var queue = application.Application[GlimpseConstants.JsonQueue] as Queue <GlimpseRequestMetadata>; if (queue != null) { var filteredQueue = from request in queue group request by request.ClientName into clients select new { Client = clients.Key, RequestCount = clients.Count() }; var data = JsSerializer.Serialize(filteredQueue); JsonResponse(application, data); return; } else { var data = JsSerializer.Serialize(new { Error = true, Message = "No history avalible." }); JsonResponse(application, data); return; } }
public ActionResult Index(FacebookContext context, bool?debug = false) { //var fs = new FacebookServices(); //fs.GetCurrentUser("CAAEWkqzCCHYBACFe04a09eZAUvDjBmk1CDIe4aZBTJB8tVWea8EmZCN24ETgEnrqAWoTYLpezdL0FrYJbyE0tODcrqcj57gpMqJQdCxyOZAARCcVKocVPI5lBFDtzEf0qOxBQ2sCgzSQg3VX6YBlg8BtxUuxZBZCjW03ObrHKm2NwNNKVTN6atkhH9JnTNJdIcONBFuYUmp1LQYwMPr0dD"); FacebookLayoutToken facebookPageToken = null; FbSignedRequestToken signedRequest; if (debug == null || !(bool)debug) { if (!ModelState.IsValid) { return(View("Error")); } dynamic signedRequestJson = context.Client.ParseSignedRequest(Utils.GetKeyValue("Facebook:AppSecret"), Request.Params["signed_request"]); signedRequest = JsSerializer.Deserialize <FbSignedRequestToken>(signedRequestJson.ToString()); } else { #region debug mode const string json = "{\"algorithm\": \"HMAC-SHA256\",\"issued_at\": 1404917218,\"page\": {\"id\": \"384502031623764\",\"liked\": false,\"admin\": true},\"user\": {\"country\": \"il\",\"locale\": \"en_US\",\"age\": {\"min\": 21}}}"; signedRequest = JsSerializer.Deserialize <FbSignedRequestToken>(json); #endregion } Logger.Debug("signed request::" + JsSerializer.Serialize(signedRequest)); if (signedRequest.page != null) { facebookPageToken = new FacebookLayoutToken { Liked = signedRequest.page.liked , Admin = signedRequest.page.admin , TrackingId = signedRequest.page.id , AccessToken = context != null ? context.AccessToken : string.Empty }; if (facebookPageToken.Admin) { facebookPageToken.Settings = User.Identity.IsAuthenticated ? GetSettingsViewToken(facebookPageToken.TrackingId) : facebookPageToken.TrackingId.ToDefaultSettingsToken(); } } return(facebookPageToken == null?View("Error") : View("FacebookFrames", facebookPageToken)); }
public override void Respond(HttpApplication application, GlimpseConfiguration config) { if (!application.IsValidRequest(config, false, checkPath: false)) { var data = JsSerializer.Serialize(new { Error = true, Message = "You are not configured to access history." }); JsonResponse(application, data); return; } var queue = application.Application[GlimpseConstants.JsonQueue] as Queue <GlimpseRequestMetadata>; if (queue != null) { var result = new Dictionary <string, object>(); var sortedQueue = from request in queue orderby request.ClientName select request; var lastClient = Guid.NewGuid().ToString(); foreach (var request in sortedQueue) { if (!lastClient.Equals(request.ClientName)) { result.Add(request.ClientName, new Dictionary <string, object>()); } var dictionary = result[request.ClientName] as IDictionary <string, object>; dictionary.Add(request.RequestId.ToString(), new { request.Url, request.Browser, request.RequestTime, request.IsAjax, request.Method }); lastClient = request.ClientName; } var data = JsSerializer.Serialize(new { Data = result }); JsonResponse(application, data); return; } else { var data = JsSerializer.Serialize(new { Error = true, Message = "No history avalible." }); JsonResponse(application, data); return; } }
public FbResponse GetFbUserToken(string accessToken, out string error) { error = string.Empty; try { var fbc = new FacebookClient { AppId = FB_APP_ID, AppSecret = FB_APP_SECRET, AccessToken = accessToken }; dynamic result = fbc.Get("me"); var fbToken = JsSerializer.Deserialize <FbResponse>(result.ToString()); return(fbToken); } catch (Exception ex) { error = Utils.FormatError(ex); Logger.Error(ex); return(null); } }
public JsonResult SaveCategoryItems(string data) { string error; bool result; try { var token = JsSerializer.Deserialize <AddItems2StoreCategoryToken>(data); result = _webStoreServices.AddItems2Category(token, out error); } catch (Exception ex) { result = false; error = Utils.FormatError(ex); } return(Json(new JsonResponseToken { success = result, error = error }, JsonRequestBehavior.AllowGet)); }
public override void Respond(HttpApplication application, GlimpseConfiguration config) { if (!application.IsValidRequest(config, false, checkPath: false)) { var data = JsSerializer.Serialize(new { Error = true, Message = "You are not configured to access history." }); JsonResponse(application, data); return; } var queue = application.Application[GlimpseConstants.JsonQueue] as Queue <GlimpseRequestMetadata>; if (queue != null) { var clientName = application.Request.QueryString[GlimpseConstants.ClientName]; string data; if (string.IsNullOrEmpty(clientName)) { data = JsSerializer.Serialize(queue); } else { var filteredQueue = from request in queue where request.ClientName.Equals(clientName) select request; data = JsSerializer.Serialize(filteredQueue); } JsonResponse(application, data); return; } else { var data = JsSerializer.Serialize(new { Error = true, Message = "No history avalible." }); JsonResponse(application, data); return; } }
public ActionResult SaveNewStore(BaseWebStoreDTO token, string uid, int?srcId, string callback) { string error; token.StoreId = -1; //check source var plugin = WidgetEndpointServices.GetPluginInstallationDto(uid, out error); if (plugin != null) { token.RegistrationSource = plugin.Type.PluginType2RegistrationSource(); } var saved = _pluginStoreServices.SaveStore(ref token, CurrentUserId, srcId, out error); ViewBag.result = JsSerializer.Serialize(new JsonResponseToken { success = saved, error = error }); ViewBag.callback = callback; Response.ContentType = "text/javascript"; return(View()); }
public override void Respond(HttpApplication application, GlimpseConfiguration config) { if (!application.IsValidRequest(config, false, checkPath: false)) { var data = JsSerializer.Serialize(new { Error = true, Message = "You are not configured to access history." }); JsonResponse(application, data); return; } var queue = application.Application[GlimpseConstants.JsonQueue] as Queue <GlimpseRequestMetadata>; if (queue != null) { var result = new Dictionary <string, object>(); IEnumerable <GlimpseRequestMetadata> data; var requestId = application.Request.QueryString[GlimpseConstants.ClientRequestId]; if (!string.IsNullOrEmpty(requestId)) { data = from request in queue where request.RequestId.ToString().Equals(requestId) select request; var requestResult = data.FirstOrDefault(); if (requestResult != null) { result.Add(requestResult.RequestId.ToString(), new { Data = requestResult.Json }); } } else { var clientName = application.Request.QueryString[GlimpseConstants.ClientName]; if (string.IsNullOrEmpty(clientName)) { data = queue; } else { data = from request in queue where request.ClientName.Equals(clientName) select request; } var lastClient = Guid.NewGuid().ToString(); foreach (var request in data.OrderBy(d => d.ClientName)) { if (!lastClient.Equals(request.ClientName)) { result.Add(request.ClientName, new Dictionary <string, object>()); } var dictionary = result[request.ClientName] as IDictionary <string, object>; dictionary.Add(request.RequestId.ToString(), new { Data = request.Json }); lastClient = request.ClientName; } if (!string.IsNullOrEmpty(clientName) && result.Count == 0) { result.Add(clientName, new Dictionary <string, object>()); } } var json = JsSerializer.Serialize(new { Data = result }); JsonResponse(application, json); return; } else { var data = JsSerializer.Serialize(new { Error = true, Message = "No history avalible." }); JsonResponse(application, data); return; } }
public string StandardResponse(HttpApplication application, Guid requestId) { IDictionary <string, object> data; if (!application.TryGetData(out data)) { return("Error: No Glimpse Data Found"); } var sb = new StringBuilder("{"); foreach (var item in data) { try { var dataString = JsSerializer.Serialize(item.Value); sb.Append(string.Format("\"{0}\":{1},", item.Key, dataString)); } catch (Exception ex) { var message = ex.Message; if (ex is InvalidOperationException) { sb.Append(string.Format("\"{0}\":\"{1} : {2}<br/><span style='color:red;'>Please implement an IGlimpseConverter for the type mentioned above, or one of its base types, to fix this problem. More info on a better experience for this coming soon, keep an eye on <a href='http://getGlimpse.com' target='main'>getGlimpse.com</a></span>\",", item.Key, ex.GetType().Name, message)); } else { sb.Append(string.Format("\"{0}\":\"{1} : {2}\",", item.Key, ex.GetType().Name, message)); } } } //Add exceptions tab if needed var exceptions = application.GetWarningStore(); if (exceptions.Count > 1) { var dataString = JsSerializer.Serialize(exceptions); sb.Append(string.Format("\"{0}\":{1},", "Glimpse Warnings", dataString)); } if (sb.Length > 1) { sb.Remove(sb.Length - 1, 1); } sb.Append("}"); //var json = JsSerializer.Serialize(data); //serialize data to Json var json = sb.ToString(); json = Sanitizer.Sanitize(json); //if ajax request, render glimpse data to headers if (application.IsAjax()) { application.Response.AddHeader(GlimpseConstants.HttpHeader, requestId.ToString()); } else { var html = string.Format( @"<script type='text/javascript' id='glimpseData' data-glimpse-requestID='{1}'>var glimpse = {0};</script>", json, requestId); html += @"<script type='text/javascript' id='glimpseClient' src='" + RootPath + "glimpseClient.js'></script>"; application.Response.Write(html); } return(json); }
public void RegisterConverters() { JsSerializer.RegisterConverters(JsConverters); }
public ActionResult PostMessage(FbTesterToken token) { if (String.IsNullOrEmpty(token.BaseAccessToken)) { return(ErrorResponse("base access_token required")); } var _fbClient = new FacebookClient(token.BaseAccessToken); dynamic messagePost = new ExpandoObject(); messagePost.message = String.IsNullOrEmpty(token.Message) ? "default test msg" : token.Message; messagePost.name = "some title"; messagePost.caption = "capt"; messagePost.description = "desc"; messagePost.picture = "https://s3.amazonaws.com/lfe-production/Course/5/9/2013/yMsQb5yePkC2VZpilIKkRg.jpg"; if (!String.IsNullOrEmpty(token.MessageAccessToken)) { messagePost.access_token = token.MessageAccessToken; } var from = (token.UsePageId ? "384502031623764" : "me"); Logger.Debug("post app message with at::" + token.BaseAccessToken + ", from::" + from + ", msg::" + JsSerializer.Serialize(messagePost)); var post = _fbClient.Post(from + "/feed", messagePost); return(Json(new JsonResponseToken { success = true , result = post.id }, JsonRequestBehavior.AllowGet)); }
public bool CreateOrUpdateFbAccountAndLoginWixUser(string access_token, out string error, string trackingId = null) { try { var result = VerifyFbUserAccessToken(access_token); if (!result.IsSuccessful || result.UserName == null) { Logger.Debug("wix fb login::access_token:" + access_token + "::" + JsSerializer.Serialize(result)); error = result.Error != null ? result.Error.Message : "Authentication failed"; return(false); } //check if email registered in LFE var user = _userAccountServices.FindUserByEmail(result.UserName); if (user != null) { return(CreateAuthenticationTicket(user.Email, string.Empty, trackingId, out error)); } string email; var loginResult = CreateOrUpdateExternalAccountAndLoginUser(result, out email, out error, trackingId, CommonEnums.eRegistrationSources.WIX); if (!loginResult) { return(false); } loginResult = CreateAuthenticationTicket(email, string.Empty, trackingId, out error); return(loginResult); } catch (Exception ex) { error = Utils.FormatError(ex); return(false); } }
public ActionResult UserScript(string callback, string uid) { ViewBag.linkMessage = "null"; ViewBag.linkUrl = "null"; var currencies = JsSerializer.Serialize(_geoServices.ActiveCurrenciesList); dynamic stores = new BaseWebStoreDTO[0]; var userAuthorized = false; string error; var installToken = WidgetEndpointServices.GetPluginInstallationDto(uid, out error); //Logger.Debug("Call plugin user script for " + uid); if (installToken == null) { ViewBag.linkMessage = "'Installation not registered with " + error + ". Please contact support team.'"; ViewBag.linkUrl = "'#'"; } else { if (CurrentUserId < 0) { ViewBag.linkMessage = installToken.UserId == null ? "'Oooooppss… No LFE account is connected to this plugin. Click here to connect an LFE account with this plugin'" : "'Oooooppss… You are not logged in. Click here to login with the LFE account associated with this plugin'"; ViewBag.linkUrl = "'#login'"; } else { if (installToken.UserId != null) { if (installToken.UserId == CurrentUserId) { stores = WidgetEndpointServices.GetOwnerStores(CurrentUserId).OrderBy(x => x.Name).ToArray(); userAuthorized = true; //show panel } else { ViewBag.linkMessage = "'Oooooppss… You are attempting to login with an LFE account that is not connected to this application. Click here to connect with the LFE account associated with this plugin'"; ViewBag.linkUrl = "'#'"; } } else { // Show message"Connect account" ViewBag.linkMessage = "'Oooooppss… No LFE account is connected to this application. Click here to connect your LFE account'"; ViewBag.linkUrl = "'#'"; } } } var newStore = new BaseWebStoreDTO { StoreId = -1 , TrackingID = Guid.NewGuid().ToString() , DefaultCurrencyId = Constants.DEFAULT_CURRENCY_ID }; ViewBag.currencies = string.IsNullOrEmpty(currencies) ? "[]" : currencies; ViewBag.stores = JsSerializer.Serialize(stores); ViewBag.user = CurrentUserId; ViewBag.newStore = JsSerializer.Serialize(newStore); ViewBag.callback = callback; ViewBag.uid = uid; ViewBag.status = userAuthorized ? string.Empty : HttpStatusCode.Forbidden.ToString(); Response.ContentType = "text/javascript"; return(View()); }
public bool SaveUserMessage(ref DiscussionMessageInputDTO token, int userId, out string error) { try { //var oid = FbServices.GetCourseFbObjectId(token.CourseId); token.HTMLVersion = CURRENT_MSG_HTML_VERSION; var entity = token.Dto2MessageEntity(userId); DiscussionMessageRepository.Add(entity); DiscussionMessageRepository.UnitOfWork.CommitAndRefreshChanges(); var messageId = entity.MessageId; var names = String.IsNullOrEmpty(token.NamesArrayStr) ? new string[0] : JsSerializer.Deserialize <string[]>(token.NamesArrayStr); var tags = String.IsNullOrEmpty(token.TagsArrayStr) ? new string[0] : JsSerializer.Deserialize <string[]>(token.TagsArrayStr); if (tags.Length > 0) { if (!SaveHashtags(tags, userId, out error)) { return(false); } if (!SaveMessageHashtags(tags, messageId, out error)) { return(false); } } if (names.Length > 0) { if (!SaveMessageUsers(names, messageId, out error)) { return(false); } } if (!SaveMessageHtml(messageId, FEED_LINK_V2, out error)) { return(false); } if (!SaveRoomFollower(userId, token.RoomId, out error)) { return(false); } SaveMessageNotifications(messageId, userId, out error); //token.RoomId, if (token.ParentMessageId != null) { SaveReplayMessageNotifications(messageId, (long)token.ParentMessageId, out error); } SaveMessageEmails(messageId); //UnitOfWork.CommitAndRefreshChanges(); SaveFbPostMessages(messageId, token.CourseId, userId); token.MessageId = messageId; token.Uid = entity.Uid; return(true); } catch (Exception ex) { error = Utils.FormatError(ex); Logger.Error("save user message", token.RoomId, ex, CommonEnums.LoggerObjectTypes.Discussion); return(false); } }
public string[] UpdateExceptionShift_ExceptionShiftsPage(string operationState, string ShiftID, string FirstPersonnelID, string SecondPersonnelID, string FirstWorkGroupID, string SecondWorkGroupID, string FirstDate, string SecondDate, string replacementState, string shiftViewState, string ShiftExchange) { this.InitializeCulture(); string[] retMessage = new string[6]; try { //IList<ShiftException> ExceptionShiftList = null; IList <ShiftExceptionProxy> ShiftExceptionProxyList = null; AttackDefender.CSRFDefender(this.Page); OperationState OS = (OperationState)Enum.Parse(typeof(OperationState), this.StringBuilder.CreateString(operationState)); decimal shiftID = decimal.Parse(this.StringBuilder.CreateString(ShiftID), CultureInfo.InvariantCulture); decimal firstPersonnelID = decimal.Parse(this.StringBuilder.CreateString(FirstPersonnelID), CultureInfo.InvariantCulture); decimal secondPersonnelID = decimal.Parse(this.StringBuilder.CreateString(SecondPersonnelID), CultureInfo.InvariantCulture); decimal firstWorkGroupID = decimal.Parse(this.StringBuilder.CreateString(FirstWorkGroupID), CultureInfo.InvariantCulture); decimal secondWorkGroupID = decimal.Parse(this.StringBuilder.CreateString(SecondWorkGroupID), CultureInfo.InvariantCulture); bool shiftExchange = bool.Parse(this.StringBuilder.CreateString(ShiftExchange)); FirstDate = this.StringBuilder.CreateString(FirstDate); SecondDate = this.StringBuilder.CreateString(SecondDate); ReplacementState RS = (ReplacementState)Enum.Parse(typeof(ReplacementState), this.StringBuilder.CreateString(replacementState)); ShiftViewState SVS = (ShiftViewState)Enum.Parse(typeof(ShiftViewState), this.StringBuilder.CreateString(shiftViewState)); string shift = string.Empty; string SuccessMessageBody = string.Empty; switch (OS) { case OperationState.Add: this.ExceptionShiftsBusiness.InsertExceptionShift(firstPersonnelID, shiftID, FirstDate, SecondDate); SuccessMessageBody = GetLocalResourceObject("AddComplete").ToString(); break; case OperationState.Edit: this.ExceptionShiftsBusiness.UpdateExceptionShift(firstPersonnelID, shiftID, FirstDate, SecondDate); SuccessMessageBody = GetLocalResourceObject("EditComplete").ToString(); break; case OperationState.TwoDayReplacement: switch (SVS) { case ShiftViewState.NotView: switch (RS) { case ReplacementState.NotReplacement: break; case ReplacementState.Personnel: if (!shiftExchange) { ShiftExceptionProxyList = this.ExceptionShiftsBusiness.GetShiftExceptionProxy(firstPersonnelID, FirstDate, SecondDate); } if (ShiftExceptionProxyList == null) { this.ExceptionShiftsBusiness.ExchangeDayByPerson(firstPersonnelID, FirstDate, SecondDate); } break; case ReplacementState.WorkGroup: this.ExceptionShiftsBusiness.ExchangeDayByWorkGroup(firstWorkGroupID, FirstDate, SecondDate); break; } if (ShiftExceptionProxyList == null) { SuccessMessageBody = GetLocalResourceObject("TwoDayReplacementComplete").ToString(); } break; case ShiftViewState.First: switch (RS) { case ReplacementState.NotReplacement: break; case ReplacementState.Personnel: shift = this.ExceptionShiftsBusiness.GetDayShiftByPersonId(firstPersonnelID, FirstDate); break; case ReplacementState.WorkGroup: shift = this.ExceptionShiftsBusiness.GetDayShiftByWorkGroup(firstWorkGroupID, FirstDate); break; } break; case ShiftViewState.Second: switch (RS) { case ReplacementState.NotReplacement: break; case ReplacementState.Personnel: shift = this.ExceptionShiftsBusiness.GetDayShiftByPersonId(firstPersonnelID, SecondDate); break; case ReplacementState.WorkGroup: shift = this.ExceptionShiftsBusiness.GetDayShiftByWorkGroup(firstWorkGroupID, SecondDate); break; } break; } break; case OperationState.TwoPersonnelReplacement: switch (SVS) { case ShiftViewState.NotView: switch (RS) { case ReplacementState.NotReplacement: break; case ReplacementState.Personnel: this.ExceptionShiftsBusiness.ExchangePerson(firstPersonnelID, secondPersonnelID, FirstDate, SecondDate); break; case ReplacementState.WorkGroup: this.ExceptionShiftsBusiness.ExchangeWorkGroup(firstWorkGroupID, secondWorkGroupID, FirstDate, SecondDate); break; } SuccessMessageBody = GetLocalResourceObject("TwoPersonnelReplacementComplete").ToString(); break; case ShiftViewState.First: switch (RS) { case ReplacementState.NotReplacement: break; case ReplacementState.Personnel: shift = this.ExceptionShiftsBusiness.GetDayShiftByPersonId(firstPersonnelID, FirstDate); break; case ReplacementState.WorkGroup: shift = this.ExceptionShiftsBusiness.GetDayShiftByWorkGroup(firstWorkGroupID, FirstDate); break; } break; case ShiftViewState.Second: switch (RS) { case ReplacementState.NotReplacement: break; case ReplacementState.Personnel: shift = this.ExceptionShiftsBusiness.GetDayShiftByPersonId(secondPersonnelID, SecondDate); break; case ReplacementState.WorkGroup: shift = this.ExceptionShiftsBusiness.GetDayShiftByWorkGroup(secondWorkGroupID, SecondDate); break; } break; } break; } retMessage[1] = SuccessMessageBody; retMessage[2] = "success"; if (ShiftExceptionProxyList != null) { retMessage[4] = JsSerializer.Serialize(ShiftExceptionProxyList.Where(x => x.Date == FirstDate).FirstOrDefault()); retMessage[5] = JsSerializer.Serialize(ShiftExceptionProxyList.Where(x => x.Date == SecondDate).FirstOrDefault()); } if (SVS != ShiftViewState.NotView) { retMessage[3] = shift != string.Empty ? shift : GetLocalResourceObject("NoShift").ToString(); } return(retMessage); } catch (UIValidationExceptions ex) { retMessage = this.exceptionHandler.HandleException(this.Page, ExceptionTypes.UIValidationExceptions, ex, retMessage); return(retMessage); } catch (UIBaseException ex) { retMessage = this.exceptionHandler.HandleException(this.Page, ExceptionTypes.UIBaseException, ex, retMessage); return(retMessage); } catch (Exception ex) { retMessage = this.exceptionHandler.HandleException(this.Page, ExceptionTypes.Exception, ex, retMessage); return(retMessage); } }