/// <summary> /// 序列化 /// </summary> /// <param name="data"></param> /// <param name="ty"></param> static void SerializeResultToDisk(QueryResponseType data, QueryableTypes ty) { if (data.Status.code == StatusTypeCode.OK) { #region 输出成功 foreach (var s in data.Status.Status) { #region 访问所有的状态 if (s.code == StatusTypeCode.OK) { // use LINQ to match successful status result with matching dataset DataType d = data.Data.Where(q => q.itemIDRef == s.@ref).FirstOrDefault(); if (d != null) { XmlSerializer sr = new XmlSerializer(typeof(DataType)); XmlWriterSettings settings = new XmlWriterSettings() { Indent = true, NewLineHandling = NewLineHandling.Entitize }; // Simply dump dataset to xml file on disk... using (XmlWriter wr = XmlWriter.Create(ty + "-" + d.itemIDRef.ToString() + ".xml", settings)) { sr.Serialize(wr, d); } } } else { JLog.Instance.AppInfo(string.Format("code: {0}, comment: {1}", s.code, s.comment)); } #endregion } #endregion } else { foreach (var stat in data.Status.Status) { System.Diagnostics.Debug.WriteLine(string.Format("code: {0}, comment: {1}", stat.code, stat.comment)); } } }
/// <summary> /// Creates a fully formed QueryItemType wrapper /// </summary> /// <param name="sEDSQuery">EDS query string</param> /// <param name="type">EDS object type</param> /// <param name="PageSize">Number of records EDS needs to fetch</param> /// <param name="offset">Starting row within dataset</param> /// <returns></returns> private static QueryItemType ConstructQueryItem(string sEDSQuery, QueryableTypes type, int PageSize, int offset) { return(new QueryItemType() { itemID = Guid.NewGuid(), objectType = type, Select = new QrySelectType() { Item = new QrySimpleTextType() { // Place our query expression here... Query = string.Format(sEDSQuery) } }, count = PageSize, offset = offset }); }
public void AnalyzeInvocationExpression(SyntaxNodeAnalysisContext context) { var invocationExpression = (InvocationExpressionSyntax)context.Node; if (!(invocationExpression.Expression is MemberAccessExpressionSyntax memberAccessExpression)) { return; } var methodName = memberAccessExpression.Name.Identifier; if (!queryMethodNames.Contains(methodName.ValueText)) { return; } var methodInfo = context.SemanticModel.GetSymbolInfo(memberAccessExpression, context.CancellationToken); if (methodInfo.Symbol is IMethodSymbol methodSymbol && QueryableTypes.Contains(methodSymbol.ContainingType) && methodSymbol.Parameters.Length >= 1 && invocationExpression.ArgumentList.Arguments.Count >= 1) { foreach (var argument in invocationExpression.ArgumentList.Arguments) { if (argument.Expression is LambdaExpressionSyntax lambdaExpression) { var typeInfo = context.SemanticModel.GetTypeInfo(argument.Expression); if (typeInfo.ConvertedType != null && IsPredicate(typeInfo.ConvertedType)) { AnalyzePredicate(context, methodName, lambdaExpression); } } } } }
public void HandleQuery(string sEDSQuery, QueryableTypes type, EDS client, int PageSize, Action <int, int, int> Progress) { try { int recordsRemaining = 0; int offset = 0; bool bFirstTime = true; int iTotalRecords = 0; do { QueryRequestType req = null; if (bFirstTime) { req = new QueryRequestType() { QueryItems = new QueryItemType[] { ConstructQueryItem(sEDSQuery, type, PageSize, offset) }, itemID = Guid.NewGuid(), TimeoutOverride = m_edsRequestTimeout }; } else { List <QueryItemType> qItems = new List <QueryItemType>(); req = new QueryRequestType() { itemID = Guid.NewGuid(), TimeoutOverride = m_edsRequestTimeout }; for (int i = 0; i < m_iBatchSize; i++) { qItems.Add(ConstructQueryItem(sEDSQuery, type, PageSize, offset + (PageSize * i))); } req.QueryItems = qItems.ToArray(); } DateTime start = DateTime.Now; var EDSResponse = client.Query(req); TimeSpan timespan = DateTime.Now.Subtract(start); string sError = ""; bool bError = ValidateResponse(EDSResponse, sEDSQuery, type, req.QueryItems, out sError); if (!bError && EDSResponse != null && EDSResponse.Data != null) { if (bFirstTime) { DataType d = EDSResponse.Data.First(); iTotalRecords = d.remaining + d.nextOffset; bFirstTime = false; } HandleData(EDSResponse); var data = EDSResponse.Data.AsQueryable(); recordsRemaining = data.Min(d => d.remaining); offset = data.Max(d => d.nextOffset); if (Progress != null) { int iTotal = recordsRemaining + offset; if (iTotal == 0) { Progress(100, iTotalRecords, iTotalRecords); } else { float percentage = ((float)offset / (float)iTotal) * 100; Progress((int)percentage, offset, iTotal); } } } else { if (bError && Progress != null) { throw new Exception(sError); } break; } } while (recordsRemaining > 0); } catch (Exception _ex) { Log.Exception(_ex, LogSource); throw; } }
private bool ValidateResponse(QueryResponseType EDSResponse, string sEDSQuery, QueryableTypes type, QueryItemType[] queryItemType, out string sError) { if (EDSResponse == null || EDSResponse.Status == null || EDSResponse.Status.Status == null) { sError = "Either response, response.Status, or response.Status.Status was null"; return(true); } bool error = false; StringBuilder str = new StringBuilder(); ValidateStatus(new StatusType[] { EDSResponse.Status }, str, ref error, queryItemType); if (error == true) { Log.Error(str.ToString(), LogSource); } sError = str.ToString(); return(error); }