Example #1
0
        /// <summary>
        /// Initiates a synchronous request to the Salesforce API.
        /// </summary>
        /// <param name="request">An IRestRequest.</param>
        /// <typeparam name="T">The type of the IRestRequest.</typeparam>
        public Response Process <T>(IAuthenticatedRequest request) where T : class, IAuthenticatedRequest
        {
            Task <Response> task = null;

            try
            {
                task = ProcessAsync(request);
                task.Wait(TimeSpan.FromSeconds(DefaultNetworkTimeout));
                if (!task.IsFaulted)
                {
                    return(task.Result);
                }

                Debug.WriteLine("Process rethrowing exception: " + task.Exception);
                throw task.Exception.InnerException;
            }
            catch (AggregateException)
            {
                // We're hiding the fact that this method
                // is using the async version. That means
                // we need to remove the aggregate exception
                // wrapper and retrow the actual exception.
                throw task.Exception.InnerException;
            }
        }
Example #2
0
        private static FormInfo GetFormInfoByRequest(IAuthenticatedRequest request, bool get)
        {
            var siteId    = get ? request.GetQueryInt("siteId") : request.GetPostInt("siteId");
            var channelId = get ? request.GetQueryInt("channelId") : request.GetPostInt("channelId");
            var contentId = get ? request.GetQueryInt("contentId") : request.GetPostInt("contentId");
            var formId    = get ? request.GetQueryInt("formId") : request.GetPostInt("formId");

            return(formId > 0 ? GetFormInfo(siteId, formId) : GetFormInfoOrCreateIfNotExists(siteId, channelId, contentId));
        }
Example #3
0
        public static PollInfo GetPollInfo(IAuthenticatedRequest request)
        {
            var siteId    = request.GetQueryInt("siteId");
            var channelId = request.GetQueryInt("channelId");
            var contentId = request.GetQueryInt("contentId");
            var pollId    = request.GetQueryInt("pollId");

            return(pollId > 0 ? GetPollInfo(siteId, pollId) : GetPollInfo(siteId, channelId, contentId));
        }
        public static DynamicInfo GetDynamicInfo(IAuthenticatedRequest request, UserInfo userInfo)
        {
            var dynamicInfo = TranslateUtils.JsonDeserialize <DynamicInfo>(TranslateUtils.DecryptStringBySecretKey(request.GetPostString("value")));

            if (dynamicInfo.ChannelId == 0)
            {
                dynamicInfo.ChannelId = dynamicInfo.SiteId;
            }
            dynamicInfo.UserInfo    = userInfo;
            dynamicInfo.QueryString =
                PageUtils.GetQueryStringFilterXss(PageUtils.UrlDecode(HttpContext.Current.Request.RawUrl));
            dynamicInfo.QueryString.Remove("siteId");

            dynamicInfo.Page = request.GetPostInt("page");

            return(dynamicInfo);
        }
        private void ValidateAuthentication(IAuthenticatedRequest <IProtocolResponse> request)
        {
            var response = Execute(new ValidateAuthenticationRequest
            {
                AuthenticationToken = request.AuthenticationToken
            });

            if (!response.IsSuccessful)
            {
                throw new AuthenticationException();
            }

            AuthenticationContext ctx = new AuthenticationContext
            {
                Claims = response.Claims
            };

            AuthenticationContext.Insert(request, ctx);
            // TODO Authorization
        }
Example #6
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            AuthRequest = SiteServer.Plugin.Context.AuthenticatedRequest;
            SiteId      = AuthRequest.GetQueryInt("siteId");

            if (!AuthRequest.AdminPermissions.HasSitePermissions(SiteId, Utils.PluginId))
            {
                HttpContext.Current.Response.Write("<h1>未授权访问</h1>");
                HttpContext.Current.Response.End();
            }

            ChannelInfoList = PublicManager.GetPublicChannelInfoList(SiteId);

            if (ChannelInfoList.Count == 0)
            {
                HttpContext.Current.Response.Redirect(PageInit.GetRedirectUrl(SiteId, Request.RawUrl));
                HttpContext.Current.Response.End();
            }
        }
Example #7
0
 public AppUser Get(IAuthenticatedRequest request)
 {
     return(Context.Users.First(user => user.Id == request.UserId));
 }
Example #8
0
 public static FormInfo GetFormInfoByPost(IAuthenticatedRequest request)
 {
     return(GetFormInfoByRequest(request, false));
 }
Example #9
0
 public static FormInfo GetFormInfoByGet(IAuthenticatedRequest request)
 {
     return(GetFormInfoByRequest(request, true));
 }
        /// <summary>
        /// Requests changes to all SObjects of the specified type in the given time frame.
        /// </summary>
        /// <remarks>
        /// Returns updates if passed ChangeTypes.Default.
        /// 
        /// Start date must not exceed 30 days prior.
        /// 
        /// Salesforce limits the result set size to 200,000 id's.
        /// If your request matches more than that, the service will
        /// return an EXCEEDED_ID_LIMIT error. To resolve this, either narrow
        /// down your time interval or sub-divide the internal into
        /// multiple requests.
        /// </remarks>
        /// <returns>The async.</returns>
        /// <param name="self">Self.</param>
        /// <param name = "request"></param>
        public static async Task<JsonObject> ChangesAsync (this SalesforceClient self, IAuthenticatedRequest request)
        {
            Response response;

            try {
                response = await self.ProcessAsync (request);
            } catch (AggregateException ex) {
                throw ex.Flatten ().InnerException;
            }

            var result = response.GetResponseText ();
            var jsonValue = JsonValue.Parse (result);

            if (jsonValue == null)
                throw new Exception ("Could not parse Json data");

            return (JsonObject)jsonValue;
        }
Example #11
0
 public static UnauthorizedException From(IAuthenticatedRequest authenticatedRequest)
 {
     return(new UnauthorizedException(
                $"Failed to authorize {authenticatedRequest.GetType().Name} with given {nameof(authenticatedRequest.Token)}"));
 }
Example #12
0
        /// <summary>
        /// Requests changes to all SObjects of the specified type in the given time frame.
        /// </summary>
        /// <remarks>
        /// Returns updates if passed ChangeTypes.Default.
        ///
        /// Start date must not exceed 30 days prior.
        ///
        /// Salesforce limits the result set size to 200,000 id's.
        /// If your request matches more than that, the service will
        /// return an EXCEEDED_ID_LIMIT error. To resolve this, either narrow
        /// down your time interval or sub-divide the internal into
        /// multiple requests.
        /// </remarks>
        /// <returns>The async.</returns>
        /// <param name="self">Self.</param>
        /// <param name = "request"></param>
        public static async Task <JsonObject> ChangesAsync(this SalesforceClient self, IAuthenticatedRequest request)
        {
            Response response;

            try {
                response = await self.ProcessAsync(request);
            } catch (AggregateException ex) {
                throw ex.Flatten().InnerException;
            }

            var result    = response.GetResponseText();
            var jsonValue = JsonValue.Parse(result);

            if (jsonValue == null)
            {
                throw new Exception("Could not parse Json data");
            }

            return((JsonObject)jsonValue);
        }