Exemplo n.º 1
0
        /// <summary>
        /// Register a hit for a function
        /// </summary>
        /// <param name="iFunctionName">The name of the function to register the hit for</param>
        /// <param name="iSource">The source of the request, for example ipaddress</param>
        /// <returns></returns>
        public Boolean RegisterHit(String iFunctionName,
                                   String iSource)
        {
            FunctionHit pFHtHit = FunctionHit.Create(iFunctionName,
                                                     iSource);

            FunctionHitsTable.CreateIfNotExists();
            TableOperation pTOnInsert = TableOperation.Insert(pFHtHit);
            TableResult    pTRtResult;

            try
            {
                pTRtResult = FunctionHitsTable.Execute(pTOnInsert);
                switch (pTRtResult.HttpStatusCode)
                {
                case 200:
                case 204:
                {
                    return(true);
                }

                default:
                {
                    return(false);
                }
                }
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get all hits for a specific function, from a specific source
        /// </summary>
        /// <param name="iFunctionName">The name of the function to get the registered hits for</param>
        /// <param name="iSource">The source of the request, for example ipaddress</param>
        /// <param name="iEarliest">The earliest registered datetime to get</param>
        /// <returns></returns>
        public List <FunctionHit> GetHits(String iFunctionName,
                                          String iSource,
                                          DateTime iEarliest)
        {
            String pStrPartitionFilter = TableQuery.GenerateFilterCondition(
                "PartitionKey",
                QueryComparisons.Equal,
                String.Format("{0}_{1}", iFunctionName, iSource));
            String pStrTimestampFilter = TableQuery.GenerateFilterConditionForDate(
                "Timestamp",
                QueryComparisons.GreaterThanOrEqual,
                iEarliest);
            String pStrFilter = TableQuery.CombineFilters(pStrPartitionFilter,
                                                          TableOperators.And,
                                                          pStrTimestampFilter);

            TableQuery <FunctionHit> pTQyQuery = new TableQuery <FunctionHit>().Where(pStrFilter);

            FunctionHitsTable.CreateIfNotExists();
            IEnumerable <FunctionHit> pIEeHits = FunctionHitsTable.ExecuteQuery <FunctionHit>(pTQyQuery);
            List <FunctionHit>        pLisHits = new List <FunctionHit>(pIEeHits);

            return(pLisHits);
        }