コード例 #1
0
 /// <summary>
 /// Success
 /// </summary>
 protected override void OnExecutionSuccess()
 {
     Log.Instance.Debug("Record updated");
     //See if there's a cache in the process. If so then we need to flush the cache.
     if (MethodReader.MethodHasAttribute(Request.method, "CacheFlush"))
     {
         cDTO = new CacheMetadata("CacheFlush", Request.method, DTO);
         foreach (Cas cas in cDTO.CasList)
         {
             MemCacheD.CasRepositoryFlush(cas.CasRepository + cas.Domain);
         }
     }
 }
コード例 #2
0
 /// <summary>
 /// On success
 /// </summary>
 protected override void OnExecutionSuccess()
 {
     Log.Instance.Debug("Record deleted");
     //See if there's a cache in the process. If so then we need to flush the cache.
     if (MethodReader.MethodHasAttribute(Request.method, Utility.GetCustomConfig("APP_CACHE_FLUSH_ATTRIBUTE")))
     {
         cDTO = new CacheMetadata(Utility.GetCustomConfig("APP_CACHE_FLUSH_ATTRIBUTE"), Request.method, DTO);
         foreach (Cas cas in cDTO.CasList)
         {
             MemCacheD.CasRepositoryFlush(cas.CasRepository + cas.Domain);
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <returns></returns>
        public BaseTemplate_Read <T, V> Read()
        {
            try
            {
                // first of all, we check if user has the right to perform this operation!
                if (HasUserToBeAuthenticated())
                {
                    if (!IsUserAuthenticated() || !HasUserPrivilege())
                    {
                        return(this);
                    }
                }
                //Run the parameters through the cleanse process
                dynamic cleansedParams = Cleanser.Cleanse(Request.parameters);

                try
                {
                    DTO = GetDTO(cleansedParams);
                }
                catch
                {
                    throw new InputFormatException();
                }

                DTO = Sanitizer.Sanitize(DTO);

                DTOValidationResult = Validator.Validate(DTO);

                if (!DTOValidationResult.IsValid)
                {
                    OnDTOValidationError();

                    return(this);
                }

                //Create the analytic data if required
                Security.Analytic_BSO_Create.Create(Ado, DTO, HttpContext.Current.Request, Request);

                //See if there's a cache in the process
                if (MethodReader.MethodHasAttribute(Request.method, "CacheRead"))
                {
                    cDTO = new CacheMetadata("CacheRead", Request.method, DTO);
                    MemCachedD_Value cache = MemCacheD.Get_BSO <dynamic>(cDTO.Namespace, cDTO.ApiName, cDTO.Method, DTO);
                    if (cache.hasData)
                    {
                        Response.data = cache.data;
                        return(this);
                    }
                }

                // The Actual Read should happen here by the specific class!
                if (!Execute())
                {
                    OnExecutionError();
                    return(this);
                }

                OnExecutionSuccess();

                return(this);
            }
            catch (UnmatchedParametersException unmatchException)
            {
                Log.Instance.Debug(unmatchException);
                OnDTOValidationError();
                return(this);
            }
            catch (FormatException formatException)
            {
                //A FormatException error has been caught, log the error and return a message to the caller
                Log.Instance.Error(formatException);
                Response.error = Label.Get("error.schema");
                return(this);
            }
            catch (Exception ex)
            {
                //An error has been caught,  log the error and return a message to the caller
                Log.Instance.Error(ex);
                Response.error = Label.Get("error.exception");

                return(this);
            }
            finally
            {
                Dispose();
            }
        }
コード例 #4
0
        /// <summary>
        /// Creates the analytic entry if one is deemed to be necessary
        /// This method relies on DeviceDetector.NET. Details at https://github.com/totpero/DeviceDetector.NET
        /// It is advisable to frequently check for updates, especially to the regexes folder (situated in the Resources folder of this project)
        /// </summary>
        /// <param name="Ado"></param>
        /// <param name="requestDTO"></param>
        /// <param name="hRequest"></param>
        /// <param name="request"></param>
        internal static void Create(ADO Ado, dynamic requestDTO, HttpRequest hRequest, JSONRPC_API request)
        {
            //If this method doesn't require analytic logging then exit the function here
            if (!MethodReader.MethodHasAttribute(request.method, "Analytic"))
            {
                return;
            }

            Analytic_DTO aDto = new Analytic_DTO();


            if (hRequest.UserLanguages != null)
            {
                if (hRequest.UserLanguages.Count() > 0)
                {
                    if (hRequest.UserLanguages[0].Length >= 2)
                    {
                        aDto.EnvironmentLngIsoCode = hRequest.UserLanguages[0].Substring(0, 2);
                    }
                }
            }

            //Get a masked version of the ip address
            aDto.NltMaskedIp = getMaskedIp(request.ipAddress);

            //Get the matrix field from the calling DTO
            if (MethodReader.DynamicHasProperty(requestDTO, "jStatQueryExtension"))
            {
                aDto.matrix = requestDTO.jStatQueryExtension.extension.Matrix;
            }

            // Get the Referer
            aDto.NltReferer = hRequest.UrlReferrer == null || String.IsNullOrEmpty(hRequest.UrlReferrer.Host) ? null : hRequest.UrlReferrer.Host;

            //The m2m parameter will not be translated into a DTO property so we just read it from the request parameters if it exists
            if (MethodReader.DynamicHasProperty(requestDTO, "m2m"))
            {
                aDto.NltM2m = requestDTO.m2m;
            }
            else
            {
                aDto.NltM2m = true;
            }

            if (MethodReader.DynamicHasProperty(requestDTO, "widget"))
            {
                aDto.NltWidget = requestDTO.widget;
            }

            if (MethodReader.DynamicHasProperty(requestDTO, "user"))
            {
                aDto.NltUser = requestDTO.user;
            }

            // Get the DateTime
            aDto.NltDate = DateTime.Now;


            //Get Format information
            if (MethodReader.DynamicHasProperty(requestDTO, "jStatQueryExtension"))
            {
                if (MethodReader.DynamicHasProperty(requestDTO.jStatQueryExtension.extension.Format, "Type") && MethodReader.DynamicHasProperty(requestDTO.jStatQueryExtension.extension.Format, "Version"))
                {
                    aDto.FrmType    = requestDTO.jStatQueryExtension.extension.Format.Type;
                    aDto.FrmVersion = requestDTO.jStatQueryExtension.extension.Format.Version;
                }
            }


            //Get the device detector and populate the dto attributes
            DeviceDetector deviceDetector = GetDeviceDetector(request.userAgent);

            aDto.NltBotFlag = deviceDetector.IsBot();


            //If it's a bot, then that overrules everything else
            if (aDto.NltBotFlag)
            {
                aDto.NltM2m    = false;
                aDto.NltUser   = false;
                aDto.NltWidget = false;
            }

            if (deviceDetector.GetBrowserClient().Match != null)
            {
                aDto.NltBrowser = deviceDetector.GetBrowserClient().Match.Name;
            }

            if (deviceDetector.GetOs().Match != null)
            {
                aDto.NltOs = deviceDetector.GetOs().Match.Name;
            }


            var valids = new Analytic_VLD().Validate(aDto);

            //validate whatever has been returned
            if (!valids.IsValid)
            {
                foreach (var fail in valids.Errors)
                {
                    Log.Instance.Debug("Analytic method failed validation:" + request.method + " :" + fail.ErrorMessage);
                }
                return;
            }

            //Create the analytic entry
            Analytic_ADO ado = new Analytic_ADO(Ado);

            if (ado.Create(aDto) == 0)
            {
                Log.Instance.Debug("Failed to create Analytic:" + request.method);
                return;
            }

            return;
        }
コード例 #5
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <returns></returns>
        public BaseTemplate_Read <T, V> Read()
        {
            try
            {
                // first of all, we check if user has the right to perform this operation!
                if (HasUserToBeAuthenticated())
                {
                    if (!IsUserAuthenticated() || !HasUserPrivilege())
                    {
                        OnAuthenticationFailed();
                        return(this);
                    }
                }
                //if we didn't attempt to authenticate and it's an external call then we still need to the the SamAccountName
                if (SamAccountName == null && Request.sessionCookie != null)
                {
                    Log.Instance.Debug("Session cookie: " + Request.sessionCookie.Value);

                    //Does the cookie correspond with a live token for a user?
                    ADO_readerOutput user;
                    using (Login_BSO lBso = new Login_BSO())
                    {
                        user = lBso.ReadBySession(Request.sessionCookie.Value);
                        if (user.hasData)
                        {
                            SamAccountName = user.data[0].CcnUsername;
                        }
                    }
                }

                //Run the parameters through the cleanse process
                dynamic cleansedParams;

                //If the API has the IndividualCleanseNoHtml attribute then parameters are cleansed individually
                //Any of these parameters whose corresponding DTO property contains the NoHtmlStrip attribute will not be cleansed of HTML tags
                if (Resources.MethodReader.MethodHasAttribute(Request.method, "IndividualCleanseNoHtml"))
                {
                    dynamic dto = GetDTO(Request.parameters);
                    cleansedParams = Cleanser.Cleanse(Request.parameters, dto);
                }
                else
                {
                    cleansedParams = Cleanser.Cleanse(Request.parameters);
                }

                try
                {
                    DTO = GetDTO(cleansedParams);
                }
                catch
                {
                    throw new InputFormatException();
                }

                DTO = Sanitizer.Sanitize(DTO);

                DTOValidationResult = Validator.Validate(DTO);

                if (!DTOValidationResult.IsValid)
                {
                    OnDTOValidationError();

                    return(this);
                }

                ////Has the user hit a limit of how many queries are allowed?
                //if (Throttle_BSO.IsThrottled(Ado, HttpContext.Current.Request, Request, SamAccountName))
                //{
                //    OnThrottle();
                //    return this;
                //}

                //Create the analytic data if required
                Security.Analytic_BSO_Create.Create(Ado, DTO, HttpContext.Current.Request, Request);

                //See if there's a cache in the process
                if (MethodReader.MethodHasAttribute(Request.method, "CacheRead"))
                {
                    cDTO = new CacheMetadata("CacheRead", Request.method, DTO);
                    MemCachedD_Value cache = MemCacheD.Get_BSO <dynamic>(cDTO.Namespace, cDTO.ApiName, cDTO.Method, DTO);
                    if (cache.hasData)
                    {
                        Response.data = cache.data;
                        return(this);
                    }
                }



                // The Actual Read should happen here by the specific class!
                if (!Execute())
                {
                    OnExecutionError();
                }
                else
                {
                    OnExecutionSuccess();
                }



                return(this);
            }
            catch (UnmatchedParametersException unmatchException)
            {
                Log.Instance.Debug(unmatchException);
                OnDTOValidationError();
                return(this);
            }
            catch (FormatException formatException)
            {
                //A FormatException error has been caught, log the error and return a message to the caller
                Log.Instance.Error(formatException);
                Response.error = Label.Get("error.schema");
                return(this);
            }
            catch (Exception ex)
            {
                //An error has been caught,  log the error and return a message to the caller
                Log.Instance.Error(ex);
                Response.error = Label.Get("error.exception");

                return(this);
            }
            finally
            {
                Dispose();
            }
        }