/// <summary> /// Constructor /// </summary> /// <param name="queryData">Query data</param> /// <param name="filedsMap">The mapped set of Context model fields and Google Analytics fields</param> /// <param name="expression">Delegate which will be invoked to create the instance of the Result object</param> internal SelectedDataContext(QueryData queryData, FieldsMap filedsMap, Func <ContextDataModel, T> expression) { _expression = expression; _fieldsMap = filedsMap; _queryData = queryData; }
public void ExecuteAsync(QueryData queryData, Func <ContextDataModel, T> expression, FieldsMap fieldsMap, Action <IEnumerable <T> > callback) { var request = getRequest(queryData); request.FetchAsync(lazyData => { try { GaData data = lazyData.GetResult(); callback(getResult(data, expression, fieldsMap)); } catch (Exception ex) { var requestExceprion = new GoogleAnalyticsRequestException("Can't fetch data", ex); throw requestExceprion; } }); }
private IEnumerable <T> getResult(GaData data, Func <ContextDataModel, T> expression, FieldsMap fieldsMap) { var contextProperties = new Dictionary <string, PropertyInfo>(); ContextDataModel context = new ContextDataModel(); Type contextType = typeof(ContextDataModel); if (data.Rows != null) { foreach (var row in data.Rows) { for (int i = 0; i < data.ColumnHeaders.Count; i++) { string fieldName = data.ColumnHeaders[i].Name; var item = fieldsMap.FindByContextModelFieldName(fieldName); MemberInfo member = item.ContextModelMember; if (item.IsProperty) { PropertyInfo propertyInfo = member as PropertyInfo; DataType dataType = propertyInfo.GetDataTypeOfMember(); BaseField field = (BaseField)Activator.CreateInstance(propertyInfo.PropertyType); string fieldValue = row[i]; field.SetValue(fieldValue); propertyInfo.SetValue(context, field, null); } else if (item.IsMethod) { MethodInfo methodInfo = member as MethodInfo; MethodInfo setter = contextType.GetMethod("addTofieldsForMethodStorage", BindingFlags.NonPublic | BindingFlags.Instance); BaseField field = (BaseField)Activator.CreateInstance(methodInfo.ReturnType); setter.Invoke(context, new object[] { fieldName, field }); } } T res = expression(context); yield return(res); } } }
public IEnumerable <T> Execute(QueryData queryData, Func <ContextDataModel, T> expression, FieldsMap fieldsMap) { var request = getRequest(queryData); try { GaData data = request.Fetch(); return(getResult(data, expression, fieldsMap)); } catch (Exception ex) { var requestExceprion = new GoogleAnalyticsRequestException("Can't fetch data", ex); throw requestExceprion; } }