public void TestQueryParametersCreate(string name, string urlString, object expectedQueryParameters)
        {
            // Arrange
            var expected = (QueryParameters)expectedQueryParameters;
            var url      = String.IsNullOrWhiteSpace(urlString) == false ? new Uri(urlString) : default(Uri);

            this.Output.WriteLine("Test Name: {0}", name);
            this.Output.WriteLine(String.Empty);

            this.Output.WriteLine("URL: {0}", urlString ?? "null");
            this.Output.WriteLine(String.Empty);

            this.Output.WriteLine("Expected Query Parameters:");
            this.WriteQueryParameters(expected);
            this.Output.WriteLine(String.Empty);

            // Act
            var actual = QueryParameters.Create(url);

            this.Output.WriteLine("Actual Query Parameters:");
            this.WriteQueryParameters(actual);

            // Assert
            Assert.Equal(expected.FilterString, actual.FilterString);
            Assert.Equal(expected.SortString, actual.SortString);
            Assert.Equal(expected.FieldStrings.AsEnumerable(), actual.FieldStrings.AsEnumerable());
            Assert.Equal(expected.FieldStringsParsed.AsEnumerable(), actual.FieldStringsParsed.AsEnumerable());
            Assert.Equal(expected.PageStrings.AsEnumerable(), actual.PageStrings.AsEnumerable());
            Assert.Equal(expected.PageStringsParsed.AsEnumerable(), actual.PageStringsParsed.AsEnumerable());
            Assert.Equal(expected.IncludeString, actual.IncludeString);
            Assert.Equal(expected.IncludeParsed.AsEnumerable(), actual.IncludeParsed.AsEnumerable());
        }
Beispiel #2
0
        public static ScriptHost.Result MonthlyFinancialEmails(string date, IDictionary <object, object> args)
        {
            ScriptHost.Result result = new ScriptHost.Result();

            QueryParameters queryParams = QueryParameters.Create(args);

            DateTime d = DateTime.Parse(date);

            var opt = new FinancialManagerReportOptions
            {
                ClientID       = 0,
                ManagerOrgID   = 0,
                Period         = d,
                IncludeManager = queryParams.GetValue("IncludeManager", true),
                Message        = queryParams.GetValue("Message", string.Empty)
            };

            var processResult = Provider.Billing.Report.SendFinancialManagerReport(opt);
            var count         = processResult.TotalEmailsSent;

            result.Success = true;
            result.Message = string.Format("sent {0} emails", count);
            result.Data    = null;

            return(result);
        }
Beispiel #3
0
        public LoginResult Login(string name, string password, string token = null)
        {
            var queryProcessor = new QueryProcessor <LoginResult>(
                m_info,
                new QueryTypeProperties <LoginResult>(
                    "login", "lg", null, null, new TupleList <string, string> {
                { "action", "login" }
            }, null,
                    LoginResult.Parse));

            var parameters = QueryParameters.Create <LoginResult>();

            if (name != null)
            {
                parameters = parameters.AddSingleValue("name", name);
            }

            if (password != null)
            {
                parameters = parameters.AddSingleValue("password", password);
            }

            if (token != null)
            {
                parameters = parameters.AddSingleValue("token", token);
            }

            return(queryProcessor.ExecuteSingle(parameters));
        }
        /// <summary>
        /// Loads module names from the wiki.
        /// </summary>
        private void RetrieveModuleNames()
        {
            var module = m_processor
                         .ExecuteSingle(QueryParameters.Create <ParamInfo>().AddSingleValue("modules", "paraminfo"))
                         .Modules.Single();

            m_moduleNames      = ((EnumParameterType)module.Parameters.Single(p => p.Name == "modules").Type).Values.ToArray();
            m_queryModuleNames = ((EnumParameterType)module.Parameters.Single(p => p.Name == "querymodules").Type).Values.ToArray();
        }
        /// <summary>
        /// Loads module names from the wiki.
        /// </summary>
        private void RetrieveModuleNames()
        {
            var modules = m_processor.ExecuteSingle(
                QueryParameters.Create <ParamInfo>().AddMultipleValues("modules", new[] { "main", "paraminfo" }))
                          .Modules.ToList();

            m_moduleNames      = GetParameterValues(modules, "main", "action");
            m_queryModuleNames = GetParameterValues(modules, "paraminfo", "querymodules");
        }
Beispiel #6
0
        public WikiQuerySortable <CategoryMembersWhere, CategoryMembersOrderBy, CategoryMembersSelect> CategoryMembers(
            string title)
        {
            var parameters = QueryParameters.Create <CategoryMembersSelect>()
                             .AddSingleValue("title", title);

            return(new WikiQuerySortable <CategoryMembersWhere, CategoryMembersOrderBy, CategoryMembersSelect>(
                       new QueryProcessor <CategoryMembersSelect>(m_wiki, CategoryMembersProperties),
                       parameters));
        }
Beispiel #7
0
        public IHttpActionResult Get(SearchFilter filter, int pageNumber = 1, int pageSize = 2,
                                     string searchInput = null)
        {
            var queryString = QueryParameters.Create(pageNumber, pageSize, searchInput);

            var productsList = _productService.GetAllAsync(filter, queryString);

            if (productsList == null)
            {
                return(BadRequest());
            }

            return(Ok(productsList));
        }
Beispiel #8
0
        /// <summary>
        /// Downloads the namespaces for a wiki.
        /// </summary>
        private static IEnumerable <Namespace> GetNamespaces(WikiInfo wiki)
        {
            var queryProcessor = new QueryProcessor <IEnumerable <Namespace> >(
                wiki,
                new QueryTypeProperties <IEnumerable <Namespace> >(
                    "siteinfo", "", QueryType.Meta, null,
                    new TupleList <string, string>
            {
                { "action", "query" }, { "meta", "siteinfo" }, { "siprop", "namespaces" }
            },
                    null, Namespace.Parse));

            return(queryProcessor.ExecuteSingle(QueryParameters.Create <IEnumerable <Namespace> >()));
        }
        /// <summary>
        /// Returns information about the given modules
        /// (query or non-query, based on the <see cref="modulesSelector"/> and <see cref="parameterName"/>).
        /// </summary>
        private IEnumerable <Module> GetModulesInternal(
            IEnumerable <string> moduleNames, string parameterName, Func <ParamInfo, IEnumerable <Module> > modulesSelector)
        {
            const int pageSize         = 50;
            var       moduleNamesArray = moduleNames.ToArray();

            for (int i = 0; i < moduleNamesArray.Length; i += pageSize)
            {
                var result = m_processor
                             .ExecuteSingle(
                    QueryParameters.Create <ParamInfo>().AddMultipleValues(
                        parameterName, moduleNames.Skip(i).Take(pageSize)));

                foreach (var module in modulesSelector(result))
                {
                    yield return(module);
                }
            }
        }
Beispiel #10
0
        // PRIVATE METHODS //////////////////////////////////////////////////
        #region Methods
        private IDocumentBuilder CreateDocumentBuilder(Uri currentRequestUrl)
        {
            Contract.Requires(currentRequestUrl != null);

            this.Implementation.CreateNewDocument();

            var domDocument    = this.Implementation.GetDomDocument();
            var serviceModel   = this.Implementation.GetServiceModel();
            var documentWriter = this.Implementation.GetDocumentWriter();
            var hypermediaAssemblerRegistry = this.Implementation.GetHypermediaAssemblerRegistry();
            var hypermediaContext           = this.Implementation.GetHypermediaContext();
            var queryParameters             = QueryParameters.Create(currentRequestUrl);
            var sparseFieldsetsEnabled      = this.Implementation.IsSparseFieldsetsEnabled();

            var documentBuilderContext = new DocumentBuilderContext(currentRequestUrl, queryParameters, sparseFieldsetsEnabled);
            var documentBuilder        = new DocumentBuilder(domDocument, serviceModel, documentWriter, hypermediaAssemblerRegistry, hypermediaContext, documentBuilderContext);

            return(documentBuilder);
        }
        public async Task <ActionResult <ResponseData> > Get([FromQuery] Dictionary <string, string> currencyCodes, DateTime startDate, DateTime endDate)
        {
            var now = DateTime.Now;

            if (now < startDate || now < endDate)
            {
                _logger.LogWarning("Future start or end date.");
                return(new NotFoundResult());
            }

            var queryParams = QueryParameters.Create(currencyCodes, startDate, endDate);

            if (queryParams.FromCurrency == null || queryParams.ToCurrency == null)
            {
                _logger.LogWarning("No currency specified.");
                return(new NotFoundResult());
            }

            if (_memoryCache.TryGetValue(queryParams.CacheKey, out var cacheEntry))
            {
                _logger.LogInformation($"[MEMORY CACHE] Successfully retrieved data for given parameters: {currencyCodes}, {startDate}, {endDate}");
                return(new JsonResult(cacheEntry));
            }

            var result = await _currencyDataService.GetCurrencies(queryParams);

            if (result == null)
            {
                _logger.LogWarning($"No results found for given parameters: {currencyCodes}, {startDate}, {endDate}");
                return(new NotFoundResult());
            }

            _memoryCache.Set(queryParams.CacheKey, result, new MemoryCacheEntryOptions()
                             .SetSlidingExpiration(TimeSpan.FromSeconds(30)));
            _logger.LogInformation($"Added entry to in-memory cache: {queryParams.CacheKey}");
            _logger.LogInformation($"Successfully retrieved data for given parameters: {currencyCodes}, {startDate}, {endDate}");

            return(new JsonResult(result));
        }