/// <summary> /// Creates a new EventDescriptor from metadata /// </summary> public EventDescriptor( string name, Type type, Type[] requiredTypes, string[] sentiments, StateCondition[] stateReqs, RelationCondition[] relationReqs, RuleCondition[] ruleReqs, StateCondition[] stateEffects, RelationCondition[] relationEffects, int[] canEqualPairs) { this.Name = name; this.Type = type; this.RequiredTypes = requiredTypes; this.Sentiments = sentiments; this.StateReqs = stateReqs; this.RelationReqs = relationReqs; this.RuleReqs = ruleReqs; this.StateEffects = stateEffects; this.RelationEffects = relationEffects; this.StateRequirements = this.CollectStateRequirements(); this.canEqual = this.PopulateCanEqual(canEqualPairs); }
internal override int GetRecurciveHashCode(ReferenceHashSet <Content> visitedContents) { int hash = base.GetHashCode(); hash = HashHelper.CombineHashCodes(hash, PreloadingMode.GetHashCode()); if (RelationCondition != null) { hash = HashHelper.CombineHashCodes(hash, RelationCondition.GetHashCode()); } if (ClonePrototypeCondition != null) { hash = HashHelper.CombineHashCodes(hash, ClonePrototypeCondition.GetHashCode()); } if (Content != null) { hash = HashHelper.CombineHashCodes(hash, Content.GetRecurciveHashCode(visitedContents)); } if (CloneDefinition != null) { hash = HashHelper.CombineHashCodes(hash, CloneDefinition.GetRecurciveHashCode(visitedContents)); } return(hash); }
public async System.Threading.Tasks.Task RequestTestAsync() { EBGetSkuRelationReqModel reqModel = new EBGetSkuRelationReqModel(); reqModel.Page = 1; reqModel.PageSize = 1000; RelationCondition condition = new RelationCondition(); condition.AddTimeStart = "2018-01-01"; condition.AddTimeEnd = "2020-03-04 17:21:07.0000000"; condition.ProductSku = "X0-Q7WK-72D0"; reqModel.Condition = condition; //var tt = new RequstInfoStruct { paramsJson = JsonConvert.SerializeObject(reqModel), service = "getSkuRelation", userName = "******", userPass = "******", url = "http://longqi-eb.eccang.com/default/svc-open/web-service-v2" }; //string st = GetRequestXML(tt); EBGetSkuRelationRequest request = new EBGetSkuRelationRequest("admin", "eccang123456", reqModel); var result = await request.Request(); //int pageNum = (int)Math.Ceiling(int.Parse(result.TotalCount) * 1.0 / 1000); //try //{ // RelationCondition condition = new RelationCondition(); // condition.AddTimeStart = "2018-01-01"; // condition.AddTimeEnd = DateTime.Now.ToString(); // reqModel.Condition = condition; // reqModel.Page = pageNum-1; // reqModel.PageSize = 1000; // request = new EBGetSkuRelationRequest("admin", "eccang123456", reqModel); // result = await request.Request(); //} //catch (Exception ex) //{ // throw ex; //} }
public RelationRequiredAttribute( int indexFrom, int indexTo, params RelationName[] tags) { this.Condition = new RelationCondition(indexFrom, indexTo, tags); }
public void BeginComplexCondition <TRelatedType>(IObjectProvider <TRelatedType> relatedObjects, RelationCondition <T, TRelatedType> relationCondition) where TRelatedType : ICanBeAnalyzed { _relatedObjectsTemp = relatedObjects; _relationConditionTemp = relationCondition; _referenceTypeTemp = typeof(TRelatedType); }
public override async Task Job(DateTime?datetime = null) { bool finish = true; int page = 1; List <ECSkuRelation> skuRelation = new List <ECSkuRelation>(); using (var uow = _uowProvider.CreateUnitOfWork()) { var repository = uow.GetRepository <ECSkuRelation>(); datetime = repository.GetPage(0, 1, x => x.OrderByDescending(c => c.CreateTime)).FirstOrDefault().CreateTime; EBGetSkuRelationReqModel reqModel = new EBGetSkuRelationReqModel(); RelationCondition condition = new RelationCondition(); condition.AddTimeStart = datetime.ToString(); condition.AddTimeEnd = DateTime.Now.ToString(); log.Info($"SKU映射信息 - 开始拉取,请求参数:{JsonConvert.SerializeObject(reqModel, new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" })}"); while (finish) { reqModel.Page = page; reqModel.PageSize = 1000; reqModel.Condition = condition; log.Info($"SKU映射信息 - 正在拉取第{page}页"); EBGetSkuRelationRequest request = new EBGetSkuRelationRequest(login.Username, login.Password, reqModel); var response = await request.Request(); if (response.Body.Count != 1000) { finish = false; } try { skuRelation = skuRelation.GroupBy(a => a.ProductSku).Select(a => a.First()).ToList(); await repository.BulkInsertAsync(skuRelation, x => x.IncludeGraph = true); uow.BulkSaveChanges(); skuRelation.Clear(); } catch (Exception ex) { log.Error($"SKU映射信息 - 写入数据库异常:{ex.Message}"); throw ex; } page++; } log.Info($"SKU映射信息 - 任务拉取完成"); } }
public void BeginComplexCondition <TRelatedType>(IObjectProvider <TRelatedType> relatedObjects, RelationCondition <TRuleType, TRelatedType> relationCondition) where TRelatedType : ICanBeAnalyzed { _conditionManager.BeginComplexCondition(relatedObjects, relationCondition); }
public override async Task Job(DateTime?datetime = null) { bool finish = true; int page = 836; List <ECSkuRelation> skuRelation = new List <ECSkuRelation>(); using (var uow = _uowProvider.CreateUnitOfWork()) { var repository = uow.GetRepository <ECSkuRelation>(); //try //{ // await repository.DeleteAll(); // await uow.SaveChangesAsync(); //} //catch (Exception ex) //{ // log.Error($"初始化Sku映射信息,删除Sku映射信息异常:{ex.Message}"); // throw ex; //} EBGetSkuRelationReqModel reqModel = new EBGetSkuRelationReqModel(); RelationCondition condition = new RelationCondition(); condition.AddTimeStart = "2018-01-01"; condition.AddTimeEnd = "2020-05-26"; while (finish) { reqModel.Page = page; reqModel.PageSize = 1000; reqModel.Condition = condition; EBGetSkuRelationRequest request = new EBGetSkuRelationRequest(login.Username, login.Password, reqModel); var response = await request.Request(); System.Diagnostics.Debug.WriteLine($"第{page}页获取成功"); if (response.Body.Count == 1000) { foreach (var item in response.Body) { try { var m = Mapper <EC_SkuRelation, ECSkuRelation> .Map(item); m.CreateTime = DateTime.Parse(reqModel.Condition.AddTimeEnd); skuRelation.Add(m); } catch (Exception ex) { RabbitMqUtils.pushMessage(new LogPushModel("Xin", "EcGetSkuRelationInit", "ERROR", "Sku映射转换实体类出现异常;" + ex.Message, reqModel)); System.Diagnostics.Debug.WriteLine($"Sku映射转换实体类出现异常:时间区间{reqModel.Condition.AddTimeStart.ToString()}TO{reqModel.Condition.AddTimeEnd.ToString()}第{reqModel.Page}页;异常信息:{ex.Message}"); throw ex; } } } else { finish = false; foreach (var item in response.Body) { try { var m = Mapper <EC_SkuRelation, ECSkuRelation> .Map(item); m.CreateTime = DateTime.Parse(reqModel.Condition.AddTimeEnd); skuRelation.Add(m); } catch (Exception ex) { RabbitMqUtils.pushMessage(new LogPushModel("Xin", "EcGetSkuRelationInit", "ERROR", "Sku映射转换实体类出现异常;" + ex.Message, reqModel)); System.Diagnostics.Debug.WriteLine($"Sku映射转换实体类出现异常:时间区间{reqModel.Condition.AddTimeStart.ToString()}TO{reqModel.Condition.AddTimeEnd.ToString()}第{reqModel.Page}页;异常信息:{ex.Message}"); throw ex; } } try { await repository.BulkInsertAsync(skuRelation, x => x.IncludeGraph = true); uow.BulkSaveChanges(); skuRelation.Clear(); } catch (Exception ex) { RabbitMqUtils.pushMessage(new LogPushModel("Xin", "EcGetSkuRelationInit", "ERROR", "入库单信息,写入数据库异常;" + ex.Message, reqModel)); System.Diagnostics.Debug.WriteLine($"入库单信息,写入数据库异常:时间区间{reqModel.Condition.AddTimeStart.ToString()}TO{reqModel.Condition.AddTimeEnd.ToString()}第{reqModel.Page}页;异常信息:{ex.Message}"); throw ex; } } if (page % 5 == 0 && skuRelation.Count > 0) { try { System.Diagnostics.Debug.WriteLine($"本次写入{skuRelation.Count}条"); await repository.BulkInsertAsync(skuRelation, x => x.IncludeGraph = true); uow.BulkSaveChanges(); skuRelation.Clear(); } catch (Exception ex) { RabbitMqUtils.pushMessage(new LogPushModel("Xin", "EcGetSkuRelationInit", "ERROR", "入库单信息,写入数据库异常;" + ex.Message, reqModel)); System.Diagnostics.Debug.WriteLine($"入库单信息,写入数据库异常:时间区间{reqModel.Condition.AddTimeStart.ToString()}TO{reqModel.Condition.AddTimeEnd.ToString()}第{reqModel.Page}页;异常信息:{ex.Message}"); throw ex; } } page++; } //response.TotalCount = response.TotalCount == null ? "1" : response.TotalCount; //int pageNum = (int)Math.Ceiling(long.Parse(response.TotalCount) * 1.0 / 1000); //for (int page = 1; page < pageNum; page++) //{ // reqModel.Page = page; // reqModel.PageSize = 1000; // try // { // System.Diagnostics.Debug.WriteLine($"Sku映射,开始拉取,开始时间:{DateTime.Now};时间区间{reqModel.Condition.AddTimeStart.ToString()}TO{reqModel.Condition.AddTimeEnd.ToString()}第{reqModel.Page}页;"); // request = new EBGetSkuRelationRequest(login.Username, login.Password, reqModel); // response =await request.Request(); // foreach (var item in response.Body) // { // try // { // var m = Mapper<EC_SkuRelation, ECSkuRelation>.Map(item); // m.CreateTime = DateTime.Parse(reqModel.Condition.AddTimeEnd); // skuRelation.Add(m); // } // catch (Exception ex) // { // System.Diagnostics.Debug.WriteLine($"Sku映射转换实体类出现异常:时间区间{reqModel.Condition.AddTimeStart.ToString()}TO{reqModel.Condition.AddTimeEnd.ToString()}第{reqModel.Page}页;异常信息:{ex.Message}"); // throw ex; // } // } // } // catch (Exception ex) // { // System.Diagnostics.Debug.WriteLine($"Sku映射接口获取出现异常:时间区间{reqModel.Condition.AddTimeStart.ToString()}TO{reqModel.Condition.AddTimeEnd.ToString()}第{reqModel.Page}页;异常信息:{ex.Message}"); // throw ex; // } // try // { // System.Diagnostics.Debug.WriteLine($"拉取结束&开始写入时间时间: { DateTime.Now}"); // await repository.BulkInsertAsync(skuRelation, x => x.IncludeGraph = true); // uow.BulkSaveChanges(); // skuRelation.Clear(); // System.Diagnostics.Debug.WriteLine($"写入完成时间: { DateTime.Now}"); // } // catch (Exception ex) // { // System.Diagnostics.Debug.WriteLine($"入库单信息,写入数据库异常:时间区间{reqModel.Condition.AddTimeStart.ToString()}TO{reqModel.Condition.AddTimeEnd.ToString()}第{reqModel.Page}页;异常信息:{ex.Message}"); // throw ex; // } //} //Parallel.ForEach(pages, new ParallelOptions { MaxDegreeOfParallelism = 1 }, page => mulitSaveAsync(reqModel,page)); } }
public void BeginComplexCondition <TRelatedType>(IObjectProvider <TRelatedType> relatedObjects, RelationCondition <TRuleType, TRelatedType> relationCondition) where TRelatedType : ICanBeAnalyzed { _currentArchRuleCreator.BeginComplexCondition(relatedObjects, relationCondition); }
private string EmitCondition(Condition condition, string trueAddr, string falseAddr) { //if falseAddr == null, then don't implement a jump for false condition //always implement a jump for true condition //TODO: This code is stolen from EmitLoopCondition below. // EmitLoopCondition should call this string r = ""; if (condition.GetType() == typeof(RelationCondition)) { RelationCondition cond = condition as RelationCondition; //Remove the "if (cond.Combined.Count>0)" stuff. //This code handles both situations RelationCondition last = cond; RelationCondition orig = cond; int conditionNumber = 0; int conditionCount = cond.Combined.Count; //Console.WriteLine("conditionCount = "+conditionCount); r += "\n"; //If we have multiple conditions, set the 1st one's AND/OR //type to be the same as the next one as it's not initally set. if (conditionCount > 0) { cond = cond.Combined[0] as RelationCondition; last.CombinedWithAnd = cond.CombinedWithAnd; last.CombinedWithOr = cond.CombinedWithOr; cond = last; } List <string> ifSegments = new List <string>(); List <bool> needsToBreakToNext = new List <bool>(); while (conditionNumber <= conditionCount) { //Console.WriteLine("conditionNumber = "+conditionNumber); //cond.CombinedWithAnd - break only on false //cond.CombinedWithOr - break only on true string s = ""; s += EmitExpression(cond.LeftExpression); s += EmitExpression(cond.RightExpression); if (cond.RelationalOperator.Relation == RelationType.EqualTo) { //true, false, breakOnTrueOnly, breakOnFalseOnly s += EmitConditionEqualTo(trueAddr, falseAddr, last.CombinedWithOr, last.CombinedWithAnd); } else if (cond.RelationalOperator.Relation == RelationType.GreaterThan) { s += EmitConditionGreaterThan(trueAddr, falseAddr, last.CombinedWithOr, last.CombinedWithAnd); } else if (cond.RelationalOperator.Relation == RelationType.LessThan) { s += EmitConditionLessThan(trueAddr, falseAddr, last.CombinedWithOr, last.CombinedWithAnd); } else if (cond.RelationalOperator.Relation == RelationType.GreaterThanOrEqualTo) { s += EmitConditionGreaterThanOrEqualTo(trueAddr, falseAddr, last.CombinedWithOr, last.CombinedWithAnd); } else if (cond.RelationalOperator.Relation == RelationType.LessThanOrEqualTo) { s += EmitConditionLessThanOrEqualTo(trueAddr, falseAddr, last.CombinedWithOr, last.CombinedWithAnd); } else if (cond.RelationalOperator.Relation == RelationType.NotEqualTo) { s += EmitConditionNotEqualTo(trueAddr, falseAddr, last.CombinedWithOr, last.CombinedWithAnd); } else { throw new CompilerException("Relation type not supported yet"); } ifSegments.Add(s); if (last.CombinedWithAnd && String.IsNullOrEmpty(falseAddr)) { needsToBreakToNext.Add(true); } else { needsToBreakToNext.Add(false); } if (conditionNumber == conditionCount) { //Console.WriteLine("Last condition"); //For the last condition in the list, we have to branch to somewhere... if (last.CombinedWithAnd) { //Jump to trueAddr s = ""; s += " //last jump trueAddr\n"; s += " " + ILAddress(5); s += "br " + trueAddr + "\n"; ifSegments.Add(s); needsToBreakToNext.Add(false); } if (last.CombinedWithOr) { //Jump to falseAddr s = ""; s += " //last jump falseAddr\n"; s += " " + ILAddress(5); s += "br " + falseAddr + "\n"; ifSegments.Add(s); if (String.IsNullOrEmpty(falseAddr)) { needsToBreakToNext.Add(true); } else { needsToBreakToNext.Add(false); } } } if (conditionNumber < conditionCount) { last = cond; cond = orig.Combined[conditionNumber] as RelationCondition; } conditionNumber++; } string nextAddr = ILAddress(); for (int n = 0; n < ifSegments.Count; n++) { string ifSegment = ifSegments[n]; if (needsToBreakToNext[n]) { ifSegment = ifSegment.Substring(0, ifSegment.Length - 1); ifSegment += nextAddr + "\n"; } r += ifSegment; } } else { //TODO: Implement this throw new CompilerException("Other condition types not supported yet"); } return(r); }