Esempio n. 1
0
        protected override void OnStartProcessingRequest(ProcessRequestArgs args)
        {
            base.OnStartProcessingRequest(args);

            HttpContext context = HttpContext.Current;

            if (null != context)
            {
                HttpCachePolicy c = context.Response.Cache;
                c.SetCacheability(HttpCacheability.ServerAndPrivate);
                c.SetExpires(context.Timestamp.AddSeconds(30));
                c.VaryByHeaders["Accept"]          = true;
                c.VaryByHeaders["Accept-Charset"]  = true;
                c.VaryByHeaders["Accept-Encoding"] = true;
                c.VaryByParams["*"] = true;
            }
        }
        protected override void OnStartProcessingRequest(ProcessRequestArgs args)
        {
            base.OnStartProcessingRequest(args);

            HttpCachePolicy c = HttpContext.Current.Response.Cache;

            c.SetCacheability(HttpCacheability.ServerAndPrivate);

            c.SetExpires(HttpContext.Current.Timestamp.AddSeconds(600));

            c.VaryByHeaders["Accept"]          = true;
            c.VaryByHeaders["Accept-Charset"]  = true;
            c.VaryByHeaders["Accept-Encoding"] = true;
            c.VaryByParams["*"] = true;

            // don't allow clients to mess with this. its valid period
            c.SetValidUntilExpires(true);
        }
        protected override void OnStartProcessingRequest(ProcessRequestArgs args)
        {
            base.OnStartProcessingRequest(args);

            if (ShouldCacheOutput(HttpContext))
            {
                var cache = HttpContext.Response.Cache;
                cache.SetCacheability(HttpCacheability.ServerAndPrivate);
                cache.SetExpires(DateTime.UtcNow.AddMinutes(5));

                cache.VaryByHeaders["Accept"]          = true;
                cache.VaryByHeaders["Accept-Charset"]  = true;
                cache.VaryByHeaders["Accept-Encoding"] = true;
                cache.VaryByParams["*"] = true;

                cache.SetValidUntilExpires(true);
            }
        }
Esempio n. 4
0
        protected override void OnStartProcessingRequest(ProcessRequestArgs args)
        {
            base.OnStartProcessingRequest(args);
            WebOperationContext context = WebOperationContext.Current;

            if (context != null)
            {
                if (!args.IsBatchOperation)
                {
                    StreamingServiceContext.AddRequestHeaders(context.IncomingRequest.Method, args.RequestUri.ToString(),
                                                              StreamingServiceHelpers.SerializeRequestHeaders(context.IncomingRequest.Headers));
                }
                if (context.IncomingRequest.Headers["Test_FailThisRequest"] == "true")
                {
                    throw new InvalidOperationException("Request failed for testing purposes.");
                }
            }
        }
Esempio n. 5
0
        public static SortedDictionary <string, string> CopyRequestHeaderValues(this ProcessRequestArgs args)
        {
            if (args is null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            var requestHeaderValues = new SortedDictionary <string, string>();

            if (args.OperationContext.RequestHeaders != null && args.OperationContext.RequestHeaders.Count > 0)
            {
                for (var i = 0; i < args.OperationContext.RequestHeaders.AllKeys.Length; i++)
                {
                    var key = args.OperationContext.RequestHeaders.AllKeys[i];
                    requestHeaderValues.Add(key, args.OperationContext.RequestHeaders.Get(key));
                }
            }

            return(requestHeaderValues);
        }
        /// <summary>
        /// Configures the current <see cref="HttpContext"/> cache if it is provided.
        /// </summary>
        /// <param name="args">A <see cref="ProcessRequestArgs"/> containing the arguments to be processed.</param>
        protected override void OnStartProcessingRequest(ProcessRequestArgs args)
        {
            base.OnStartProcessingRequest(args);

            var cacheSettings = EnableOutputCacheAttribute.GetServiceOutputCacheSettings(GetType());

            if (cacheSettings == null)
            {
                return;
            }

            var context = HttpContext.Current;
            var cache   = HttpContext.Current.Response.Cache;

            cache.SetCacheability(cacheSettings.HttpCacheability);
            cache.SetExpires(context.Timestamp.AddSeconds(cacheSettings.ExpiresInSeconds));

            cache.VaryByHeaders["Accept"]          = true;
            cache.VaryByHeaders["Accept-Charset"]  = true;
            cache.VaryByHeaders["Accept-Encoding"] = true;
            cache.VaryByParams["*"] = true;
        }
Esempio n. 7
0
            protected override void OnStartProcessingRequest(ProcessRequestArgs args)
            {
                if (args.OperationContext.RequestHeaders["ReverseUriPaths"] == "true")
                {
                    var relativeRequestUri = args.ServiceUri.MakeRelativeUri(args.RequestUri);

                    if (!args.IsBatchOperation)
                    {
                        args.ServiceUri = ReversePath(args.ServiceUri);
                    }

                    args.RequestUri = new Uri(args.ServiceUri, ReversePath(relativeRequestUri));
                }
                else
                {
                    if (!args.IsBatchOperation)
                    {
                        args.ServiceUri = new Uri(args.OperationContext.RequestHeaders["MyCustomServiceUri"]);
                    }

                    args.RequestUri = new Uri(args.OperationContext.RequestHeaders["MyCustomRequestUri"]);
                }
            }
Esempio n. 8
0
 protected override void OnStartProcessingRequest(ProcessRequestArgs args)
 {
     FixUpDataServiceUrisForCuratedFeedName(args.OperationContext, GetCuratedFeedName());
 }
Esempio n. 9
0
 /// <summary>
 /// Called before processing each request. For batch requests, it is called one time for the top batch request and one time for each operation in the batch.
 /// </summary>
 /// <param name="args">System.Data.Services.ProcessRequestArgs that contains information about the request.</param>
 protected override void OnStartProcessingRequest(ProcessRequestArgs args)
 {
 }
Esempio n. 10
0
        protected override void OnStartProcessingRequest(ProcessRequestArgs args)
        {
            HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);

            // HttpContext.Current.Response.AddHeader("Cache-control", "no-cache");
        }
         protected override void OnStartProcessingRequest(ProcessRequestArgs args)
         {
             ValidarAcesso();
 
             base.OnStartProcessingRequest(args);
         }
Esempio n. 12
0
        // Place OData Interceptors here, one for each Entity type.
        // [QueryInterceptor("EntityType")]
        // public Expression<Func<EntityType, bool>> OnQuery() {
        //    return o => true;
        // }

        // This method is called on each service call and returns a token.
        public override object Authenticate(ProcessRequestArgs args)
        {
            return(base.Authenticate(args));
        }
Esempio n. 13
0
 public void TestOnStartProcessingRequest(ProcessRequestArgs args)
 {
     this.OnStartProcessingRequest(args);
 }
Esempio n. 14
0
 protected override void OnStartProcessingRequest(ProcessRequestArgs args)
 {
     Auth.ThrowDataServiceExceptionIfNotAuthenticated();
     base.OnStartProcessingRequest(args);
 }
Esempio n. 15
0
 protected override void OnStartProcessingRequest(ProcessRequestArgs args)
 {
     Log.Trace(args.RequestUri);
 }
Esempio n. 16
0
 public void InternalOnStartProcessingRequest(ProcessRequestArgs args)
 {
 }
 /// <summary>
 /// Called when processing of a request is started.
 /// </summary>
 /// <param name="args">The arguments.</param>
 protected override void OnStartProcessingRequest(ProcessRequestArgs args)
 {
     this.logger.Info(args.OperationContext.RequestHeaders.ToString());
     base.OnStartProcessingRequest(args);
 }
Esempio n. 18
0
        protected override void OnStartProcessingRequest(ProcessRequestArgs args)
        {
            // If already logged in via Forms Auth, just return
            if (ContextProvider.CurrentUserProfile != null)
            {
                return;
            }

            if (!args.OperationContext.RequestHeaders.AllKeys.Contains("Authorization"))
            {
                CreateNotAuthorizedResponse(401, 1, "Authorization headers missing.");
                HttpContext.Current.ApplicationInstance.Response.End();
                return;
            }

            var credentials = GetCredentialsFromHeader(args.OperationContext.RequestHeaders["Authorization"]);

            if (credentials == null)
            {
                CreateNotAuthorizedResponse(403, 1, "Wrong credentials header.");
                HttpContext.Current.ApplicationInstance.Response.End();
                return;
            }

            // UserName can be in the form of just UserName, UserName\CustomerNumber or UserName\CustomerNumber\CustomerSequence
            var loginInfo        = credentials[0].Split('\\');
            var userName         = loginInfo[0];
            var customerNumber   = "";
            var customerSequence = "";

            if (loginInfo.Length > 1)
            {
                customerNumber = loginInfo[1];
            }
            if (loginInfo.Length > 2)
            {
                customerSequence = loginInfo[2];
            }

            var password = credentials[1];

            if (!AuthenticationService.ValidateUser(ContextProvider.CurrentApplicationName, userName, password))
            {
                CreateNotAuthorizedResponse(403, 1, "Wrong credentials.");
                HttpContext.Current.ApplicationInstance.Response.End();
                return;
            }
            var userProfile = UserProfile.GetByUserName(userName);

            if (userProfile == null)
            {
                CreateNotAuthorizedResponse(403, 1, "UserProfile record missing.");
                HttpContext.Current.ApplicationInstance.Response.End();
                return;
            }
            if (!string.IsNullOrEmpty(customerNumber))
            {
                if (!CustomerUserProfile.GetTable().Any(cup => cup.UserProfile.Id == userProfile.Id && cup.Customer.CustomerNumber == customerNumber))
                {
                    CreateNotAuthorizedResponse(403, 1, "The supplied CustomerNumber is not associated with the supplied UserName.");
                    HttpContext.Current.ApplicationInstance.Response.End();
                    return;
                }

                var customer = Customer.GetByNumber(customerNumber);
                ContextProvider.SetContext(customer);
                if (!string.IsNullOrEmpty(customerSequence))
                {
                    var shipTo = Customer.GetByNumberSequence(customerNumber, customerSequence);
                    if (!CustomerInfo.GetTable().Any(c => c.CustomerNumber == customerNumber && c.CustomerSequence == customerSequence))
                    {
                        CreateNotAuthorizedResponse(403, 1, "The supplied CustomerSequence is not associated with the supplied CustomerNumber.");
                        HttpContext.Current.ApplicationInstance.Response.End();
                        return;
                    }
                    ContextProvider.SetContext(customer, shipTo);
                }
            }
            FormsAuthentication.SetAuthCookie(userName, true);
            HttpContext.Current.ApplicationInstance.Context.User = new GenericPrincipal(new GenericIdentity(userName), Roles.GetRolesForUser(userName));
        }
Esempio n. 19
0
        private void ProcessRequests(object aRgUmEnT)
        {
            ProcessRequestArgs arg = aRgUmEnT as ProcessRequestArgs;

            if (arg == null)
            {
                return;
            }
            if (!processRequestsMutex.WaitOne(3000))
            {
                return;
            }
            try
            {
                //Обработаем все запросы, связанные с таймером
                using (SqlConnection cn = new SqlConnection(arg.ConnectionString))
                {
                    cn.Open();
                    List <Pair <ClimbingTimerCommand, string> > listParams = new List <Pair <ClimbingTimerCommand, string> >();
                    SqlTransaction tran = cn.BeginTransaction();
                    try
                    {
                        SqlCommand cmd = new SqlCommand("SELECT REQUEST, PARAM, sys_date, GetDate() curDate" +
                                                        "  FROM prg_Qs(NOLOCK)" +
                                                        " WHERE MACHINE <> " + MACHINE_PARAM_ID, cn);
                        AddMachineID(cmd);
                        cmd.Transaction = tran;
                        using (SqlDataReader rdr = cmd.ExecuteReader())
                        {
                            while (rdr.Read())
                            {
                                try
                                {
                                    ClimbingTimerCommand c = StaticClass.GetEnumValueFromStringNumeric <ClimbingTimerCommand>(rdr[0] as string);
                                    if (ContainsTimerData(c))
                                    {
                                        listParams.Add(new Pair <ClimbingTimerCommand, string>(c, rdr[1] as string, (DateTime)rdr[2], (DateTime)rdr[3]));
                                    }
                                }
                                catch (FormatException) { }
                            }
                        }
                        bool dataInserted = false;
                        foreach (var v in listParams)
                        {
                            #region ForEachParam
                            //Если мы запрашивали синхронизацию, то обновим значение
                            bool synchroNeeded = endPoints.Count < 1 && !arg.IsMain && (arg.Parent.autoSynchro || !arg.Parent.firstSynchroCompleted);
                            if (synchroNeeded && ((v.Value1 & ClimbingTimerCommand.Timer_SynchroCompleted) == ClimbingTimerCommand.Timer_SynchroCompleted))
                            {
                                int[]    vals = new int[4];
                                string[] s    = v.Value2.Split(new char[] { ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);
                                if (s.Length < 4)
                                {
                                    continue;
                                }
                                try
                                {
                                    for (int i = 0; i < vals.Length; i++)
                                    {
                                        vals[i] = int.Parse(s[i]);
                                    }
                                }
                                catch (FormatException) { continue; }
                                /*обновим остаток*/
                                if (Monitor.TryEnter(arg.Locker, 2000))
                                {
                                    try
                                    {
                                        TimeSpan oldBase = new TimeSpan(0, vals[0], vals[1]);
                                        oldBase -= (v.DateSelected - v.DateUpdated);
                                        arg.Parent.remainingInterval     = oldBase;
                                        arg.Parent.rotationInterval      = new TimeSpan(0, vals[2], vals[3]);
                                        arg.Parent.lastSignal            = v.DateSelected;
                                        arg.Parent.firstSynchroCompleted = true;
                                    }
                                    finally { Monitor.Exit(arg.Locker); }
                                    arg.Parent.Start();
                                }
                            }
                            if (arg.IsMain && ((v.Value1 & ClimbingTimerCommand.Timer_SynchroRequest) == ClimbingTimerCommand.Timer_SynchroRequest))
                            {
                                //Если кто-то запрашивает синхронизацию
                                //Ответ поставим только один раз
                                if (!dataInserted)
                                {
                                    cmd.Parameters.Clear();
                                    cmd.CommandText = "DELETE FROM prg_Qs WHERE REQUEST IN(@sr, @sc)";
                                    cmd.Parameters.Add("@sr", SqlDbType.VarChar, 255).Value =
                                        StaticClass.GetEnumStringNumericValue(ClimbingTimerCommand.Timer_SynchroRequest);
                                    cmd.Parameters.Add("@sc", SqlDbType.VarChar, 255).Value =
                                        StaticClass.GetEnumStringNumericValue(ClimbingTimerCommand.Timer_SynchroCompleted);
                                    cmd.ExecuteNonQuery();
                                    cmd.CommandText = "INSERT INTO prg_Qs (REQUEST, PARAM, MACHINE) VALUES (@sc,@p," + MACHINE_PARAM_ID + ")";
                                    AddMachineID(cmd);
                                    if (Monitor.TryEnter(arg.Locker, 5000))
                                    {
                                        try
                                        {
                                            cmd.Parameters.Add("@p", SqlDbType.VarChar, 255).Value =
                                                Math.Truncate(arg.Parent.remainingInterval.TotalMinutes).ToString("0") + ";" +
                                                arg.Parent.remainingInterval.Seconds.ToString() + ";" +
                                                Math.Truncate(arg.Parent.rotationInterval.TotalMinutes).ToString("0") + ";" +
                                                arg.Parent.rotationInterval.Seconds.ToString();
                                            cmd.ExecuteNonQuery();
                                            dataInserted = true;
                                        }
                                        finally { Monitor.Exit(arg.Locker); }
                                    }
                                }
                            }
                            #endregion
                        }
                        if (!arg.IsMain && endPoints.Count < 1)
                        {
                            if (Monitor.TryEnter(arg.Locker, 1000))
                            {
                                try
                                {
                                    cmd.Parameters.Clear();
                                    cmd.CommandText = "INSERT INTO prg_Qs (REQUEST, MACHINE, PARAM) VALUES(@sr," + MACHINE_PARAM_ID + ", '-')";
                                    cmd.Parameters.Add("@sr", SqlDbType.VarChar, 255).Value =
                                        StaticClass.GetEnumStringNumericValue(ClimbingTimerCommand.Timer_SynchroRequest);
                                    AddMachineID(cmd);
                                    cmd.ExecuteNonQuery();
                                }
                                finally { Monitor.Exit(arg.Locker); }
                            }
                        }
                        tran.Commit();
                    }
                    catch (Exception ex)
                    {
                        try { tran.Rollback(); }
                        catch { }
                        throw ex;
                    }
                }
            }
            catch (ThreadAbortException) { return; }
            catch { }
            finally { processRequestsMutex.ReleaseMutex(); }
        }
Esempio n. 20
0
 public void OnStartProcessingRequest(ProcessRequestArgs args)
 {
 }
    protected override void OnStartProcessingRequest(ProcessRequestArgs args)
    {
        base.OnStartProcessingRequest(args);

        CurrentDataSource.Ponderation.Include("TypePonderation").ToList();
    }