예제 #1
0
        public AggregationResultItem(AggregationResult <T> result, T model, AggregationLevel level, Func <T, string> label, IEnumerable <AggregationResultItem <T> > subItems)
        {
            Result = result ?? throw new ArgumentNullException(nameof(result));
            Model  = model;
            Level  = level;
            Label  = label?.Invoke(Model);

            if (subItems != null)
            {
                List <AggregationResultItem <T> > list = new List <AggregationResultItem <T> >();

                foreach (var subitem in subItems)
                {
                    if (subitem.Parent != null)
                    {
                        throw new InvalidOperationException("Sub item belongs to another item.");
                    }

                    subitem.Parent = this;
                    Depth          = subitem.IncreaseDepth();
                    list.Add(subitem);
                }

                SubItems = list;
            }
            else
            {
                SubItems = new List <AggregationResultItem <T> >(5);
            }
        }
예제 #2
0
        private void Lift(GroupingKey[] keys, AggregationLevel level, Func <T, string> label)
        {
            if (keys != null)
            {
                for (int i = 0; i < keys.Length; i++)
                {
                    var key = keys[i];
                    LambdaExpression source = key.SourceSelector, result = key.ResultSelector;

                    if (source != null && LiftModelToViewItem(ref source) ||
                        result != null && LiftModelToViewItem(ref result))
                    {
                        keys[i] = new GroupingKey(source, result);
                    }
                }
            }
            else
            {
                keys = new GroupingKey[] { GroupingKey.NoGroupingKey }
            };

            LambdaExpression groupBy = AggregationHelper <AggregationResultItem <T> > .MakeGroupByExpression(keys);

            var temp = TypicalLinqMethods.EnumerableGroupBy
                       .MakeGenericMethod(typeof(AggregationResultItem <T>), groupBy.ReturnType)
                       .Invoke(null, new object[] { Items, groupBy.Compile() });

            var selectItem = MakeSelectExpression(groupBy, keys, level, label);

            MethodInfo method = TypicalLinqMethods.EnumerableSelect
                                .MakeGenericMethod(selectItem.Parameters[0].Type, typeof(AggregationResultItem <T>));

            var coll = (IEnumerable <AggregationResultItem <T> >)method.Invoke(null, new object[] { temp, selectItem.Compile() });

            _items.Clear();
            _items.AddRange(coll);

            AppendGeneration();
        }
예제 #3
0
        /// <summary>
        /// Retrieves the current order book of a specific pair.
        /// Implements end point https://api.huobi.pro/market/depth
        /// </summary>
        /// <param name="symbol">The trading symbol to query</param>
        /// <param name="level">Market depth aggregation level.
        /// <para>step0: No market depth aggregation</para>
        /// <para>step1: Aggregation level = precision*10</para>
        /// <para>step2: Aggregation level = precision*100</para>
        /// <para>step3: Aggregation level = precision*1000</para>
        /// <para>step4: Aggregation level = precision*10000</para>
        /// <para>step5: Aggregation level = precision*100000</para>
        /// </param>
        /// <param name="depth">The number of market depth to return on each side</param>
        /// <returns>MarketDepth object</returns>
        /// <exception cref="System.ArgumentException">Thrown when symbol is empty or null</exception>
        public async Task <MarketDepth> GetMarketDepth(string symbol, AggregationLevel level, Depth?depth = null)
        {
            if (string.IsNullOrEmpty(symbol))
            {
                throw new ArgumentException("symbol parameter is required", "symbol");
            }

            SortedDictionary <string, string> parameters = new SortedDictionary <string, string>()
            {
                { "symbol", symbol }, { "type", level.ToParamValue() }
            };

            if (depth != null)
            {
                parameters.Add("depth", depth.ToParamValue());
            }

            string json = await HttpGetRequest(FormatUri(url_market_data + "depth", HttpMethod.Get, parameters, read_access_key, read_secret_key));

            var res = JsonParse <MarketDepth>(json, "$.tick");

            return(await res);
        }
예제 #4
0
 public AppAcquisitionsRequest(string applicationId)
 {
     this.ApplicationId    = applicationId;
     this.AggregationLevel = AggregationLevel.Day;
 }
예제 #5
0
 /// <summary>
 /// Represent the equivalence of AggregationLevel enumeration used solely when communicating with exchange server.
 /// </summary>
 public static string ToParamValue(this AggregationLevel level)
 {
     return(level.ToString().ToLower());
 }
        private async Task <string> CallAPIAsync(string appID, DateTime startDate, DateTime endDate, string verb, int top, int skip, AggregationLevel aggregationLevel, List <OrderBy> orderBy)
        {
            string result = string.Empty;
            string scope  = "https://manage.devcenter.microsoft.com";

            if (string.IsNullOrEmpty(accessToken))
            {
                accessToken = await GetClientCredentialAccessToken(
                    this.TenantId,
                    this.ClientId,
                    this.ClientSecret,
                    scope);
            }

            // Get app acquisitions
            string requestURI = BuildRequest(verb, appID, startDate, endDate, top, skip, aggregationLevel, orderBy);

            HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, requestURI);

            requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

            HttpClient          httpClient = new HttpClient();
            HttpResponseMessage response   = await httpClient.SendAsync(requestMessage);

            result = await response.Content.ReadAsStringAsync();

            response.Dispose();

            return(result);
        }
        private string BuildRequest(string verb, string appID, DateTime startDate, DateTime endDate, int top, int skip, AggregationLevel aggregationLevel, List <OrderBy> orderBy)
        {
            // Get app acquisitions
            //string requestURI = string.Format(
            //    "https://manage.devcenter.microsoft.com/v1.0/my/analytics/{5}?applicationId={0}&startDate={1}&endDate={2}&top={3}&skip={4}",
            //    appID, startDate, endDate, 1000, 0, verb);

            string requestURI = string.Format("https://manage.devcenter.microsoft.com/v1.0/my/analytics/{0}?applicationId={1}&startDate={2}&endDate={3}&top={4}&skip={5}",
                                              verb, appID, startDate, endDate, top, skip);

            if (aggregationLevel != AggregationLevel.None && aggregationLevel != AggregationLevel.Day)
            {
                requestURI += "&aggregationLevel=" + aggregationLevel.ToString().ToLower();
            }

            if (orderBy.Any())
            {
                requestURI += "&orderby=";
                foreach (OrderBy ob in orderBy)
                {
                    requestURI += ob.ToString().ToLower() + ",";
                }

                requestURI = requestURI.Remove(requestURI.Length - 1);
            }

            return(requestURI);
        }
 public AppFailuresRequest(string applicationId)
 {
     this.ApplicationId    = applicationId;
     this.AggregationLevel = AggregationLevel.Day;
 }
예제 #9
0
        private LambdaExpression MakeSelectExpression(LambdaExpression groupBy, GroupingKey[] keys, AggregationLevel level, Func <T, string> label)
        {
            var groupingType              = typeof(IGrouping <,>).MakeGenericType(groupBy.ReturnType, typeof(AggregationResultItem <T>));
            ParameterExpression  param1   = Expression.Parameter(groupingType, "grouping");
            List <MemberBinding> bindings = new List <MemberBinding>();

            foreach (var mapping in keys.Cast <Mapping>().Union(_functions))
            {
                if (mapping != GroupingKey.NoGroupingKey)
                {
                    var member = ExpressionHelper.ExtractMember(mapping.ResultSelector ?? mapping.SourceSelector);
                    var expr   = mapping.GetSourceMapping(param1);
                    var type   = member.GetPropertyOrFieldType();

                    if (expr.Type != type)
                    {
                        expr = Expression.Convert(expr, type);
                    }

                    var binding = Expression.Bind(member, expr);

                    bindings.Add(binding);
                }
            }

            var initModel = Expression.MemberInit(Expression.New(typeof(T)), bindings);

            var body = Expression.New(ViewItemConstructor,
                                      Expression.Constant(this),
                                      initModel,
                                      Expression.Constant(level),
                                      Expression.Constant(label, typeof(Func <T, string>)),
                                      param1);

            return(Expression.Lambda(body, param1));
        }
예제 #10
0
 public CodeMetric(string name, AggregationLevel level) => (Name, Level) = (name, level);