public IHttpActionResult GetByProjectId(string projectID) { var entity = ClosureExecutiveSummary.FirstOrDefault(e => e.ProjectId == projectID && e.IsHistory == false); if (entity == null) { entity = new ClosureExecutiveSummary(); entity.ProjectId = projectID; entity.IsHistory = false; } bool enableEdit = false; bool enableRecall = false; var closureInfo = ClosureInfo.FirstOrDefault(e => e.ProjectId == projectID); var projectInfo = ProjectInfo.FirstOrDefault(e => e.ProjectId == projectID && e.FlowCode == FlowCode.Closure_ExecutiveSummary); if (projectInfo != null) { if (ClientCookie.UserCode.Equals(closureInfo.AssetActorAccount)) { var isExistTask = TaskWork.Any(e => e.RefID == projectID && e.TypeCode == FlowCode.Closure_ExecutiveSummary && e.Status == TaskWorkStatus.UnFinish && e.ReceiverAccount == ClientCookie.UserCode && e.ActivityName == "Originator"); var isPackgeStarted = ProjectInfo.IsFlowStarted(projectID, FlowCode.Closure_ClosurePackage); var isESStarted = ProjectInfo.IsFlowStarted(projectID, FlowCode.Closure_ExecutiveSummary); enableEdit = ProjectInfo.IsFlowEditable(projectID, FlowCode.Closure_ExecutiveSummary); enableRecall = ProjectInfo.IsFlowRecallable(projectID, FlowCode.Closure_ExecutiveSummary); } } return(Ok(new { entity = entity, enableEdit = enableEdit, enableReCall = enableRecall })); }
private static object TryCompile(ref ClosureInfo closureInfo, Type delegateType, Type[] paramTypes, Type returnType, Expression bodyExpr, IList <ParameterExpression> paramExprs) { if (!TryCollectBoundConstants(ref closureInfo, bodyExpr, paramExprs)) { return(null); } if (closureInfo != null) { closureInfo.ConstructClosure(); } var method = GetDynamicMethod(paramTypes, returnType, closureInfo); var il = method.GetILGenerator(); if (!EmittingVisitor.TryEmit(bodyExpr, paramExprs, il, closureInfo)) { return(null); } il.Emit(OpCodes.Ret); // emits return from generated method // create open delegate with closure object if (closureInfo == null) { return(method.CreateDelegate(delegateType)); } return(method.CreateDelegate(delegateType, closureInfo.ClosureObject)); }
private static void LoadClosureFieldOrItem(ILGenerator il, ClosureInfo closure, int constantIndex, Type constantType) { // load closure argument: Closure object or Closure array il.Emit(OpCodes.Ldarg_0); if (!closure.IsArray) { // load closure field il.Emit(OpCodes.Ldfld, closure.Fields[constantIndex]); } else { // load array field il.Emit(OpCodes.Ldfld, ArrayClosure.ArrayField); // load array item index EmitLoadConstantInt(il, constantIndex); // load item from index il.Emit(OpCodes.Ldelem_Ref); // cast if needed if (constantType != typeof(object)) { il.Emit(OpCodes.Castclass, constantType); } } }
public IHttpActionResult GetByProjectId(string projectId) { var entity = ClosureConsInvtChecking.FirstOrDefault(e => e.ProjectId == projectId && e.IsHistory == false); if (entity != null) { var closureInfo = ClosureInfo.GetByProjectId(projectId); entity.USCode = closureInfo.USCode; ProjectCommentCondition condition = new ProjectCommentCondition(); condition.RefTableId = entity.Id; condition.RefTableName = ClosureWOCheckList.TableName; condition.UserAccount = ClientCookie.UserCode; condition.Status = ProjectCommentStatus.Save; var commentList = ProjectComment.SearchList(condition); if (commentList != null && commentList.Count > 0) { entity.Comments = commentList[0].Content; } if (string.IsNullOrEmpty(entity.PMSupervisor)) { var puser = ProjectUsers.FirstOrDefault(i => i.ProjectId == entity.ProjectId && i.RoleCode == ProjectUserRoleCode.CM); if (puser != null) { entity.PMSupervisor = puser.UserAccount; } } } return(Ok(entity)); }
public IHttpActionResult GetCreateFlowInfo(string projectId, string flowCode) { Object entity = null; if (flowCode.ToLower() == "rebuild") { entity = new RebuildInfo().GetRebuildInfo(projectId); } else if (flowCode.ToLower() == "reimage") { entity = ReimageInfo.GetReimageInfo(projectId); } else if (flowCode.ToLower() == "renewal") { entity = RenewalInfo.Get(projectId); } else if (flowCode.ToLower() == "tempclosure") { entity = TempClosureInfo.Get(projectId); } else if (flowCode.ToLower() == "closure") { entity = ClosureInfo.GetByProjectId(projectId); } else if (flowCode.ToLower() == "majorlease") { entity = new MajorLeaseInfo().GetMajorLeaseInfo(projectId); } return(Ok(entity)); }
public IHttpActionResult UpdateClosureInfo(ClosureInfo entity) { var closureTypeCode = Dictionary.FirstOrDefault(i => i.Code == entity.ClosureTypeCode); if (closureTypeCode != null) { entity.ClosureTypeNameENUS = closureTypeCode.NameENUS; entity.ClosureTypeNameZHCN = closureTypeCode.NameZHCN; } var riskStatus = Dictionary.FirstOrDefault(i => i.Code == entity.RiskStatusCode); if (riskStatus != null) { entity.RiskStatusNameENUS = riskStatus.NameENUS; entity.RiskStatusNameZHCN = riskStatus.NameZHCN; } var closureReason = Dictionary.FirstOrDefault(i => i.Code == entity.ClosureReasonCode); if (closureReason != null) { entity.ClosureReasonNameENUS = closureReason.NameENUS; entity.ClosureReasonNameZHCN = closureReason.NameZHCN; if (closureReason.Code != "Others") { entity.ClosureReasonRemark = ""; } } entity.Update(); return(Ok()); }
public IHttpActionResult GetById(string Id) { Guid _Id; if (!Guid.TryParse(Id, out _Id)) { return(Ok()); } var entity = ClosureWOCheckList.Get(_Id); if (entity != null) { ProjectCommentCondition condition = new ProjectCommentCondition(); condition.RefTableId = entity.Id; condition.RefTableName = ClosureWOCheckList.TableName; condition.UserAccount = ClientCookie.UserCode; condition.Status = ProjectCommentStatus.Save; var commentList = ProjectComment.SearchList(condition); if (commentList != null && commentList.Count > 0) { entity.Comments = commentList[0].Content; } var closureEntity = ClosureInfo.GetByProjectId(entity.ProjectId); entity.USCode = closureEntity.USCode; entity.UserAccount = ClientCookie.UserCode; } return(Ok(entity)); }
public IHttpActionResult PostClosureConsInvtChecking(ClosureConsInvtChecking entity) { //ClosureInfo closure = new ClosureInfo(); //closure = closure.GetByProjectId(entity.ProjectId.Value); var task = TaskWork.FirstOrDefault( e => e.ReceiverAccount == ClientCookie.UserCode && e.Status == 0 && e.SourceCode == FlowCode.Closure && e.TypeCode == FlowCode.Closure_ConsInvtChecking && e.RefID == entity.ProjectId); task.Finish(); // Start K2 Process string _procCode = WFConsInvtChecking.ProcessCode; List <ProcessDataField> _listDataFields = new List <ProcessDataField>(); var _diff = CalDiff(entity);; /* * Total Variance <= +-5% : 1 +-5% < Total Variance <= +- 10% : 2 * Total Variance > +- 10% : 3 */ var closureEntity = ClosureInfo.GetByProjectId(entity.ProjectId); _listDataFields.Add(new ProcessDataField("flag_DiffRangeType", _diff)); //传偏差值范围 1, 2, 3 //_listDataFields.Add(new ProcessDataField("dest_Creator", ClientCookie.UserCode)); _listDataFields.Add(new ProcessDataField("dest_Creator", entity.CreateUserAccount)); // 发起人也变成工程PM,不是actor _listDataFields.Add(new ProcessDataField("dest_EngPM", entity.PMSupervisor)); _listDataFields.Add(new ProcessDataField("dest_Fin", entity.FinControllerAccount)); _listDataFields.Add(new ProcessDataField("dest_VPGM", entity.VPGMAccount)); _listDataFields.Add(new ProcessDataField("dest_Group1", entity.FinanceAccount + ";" + entity.PMSupervisor)); _listDataFields.Add(new ProcessDataField("ProcessCode", _procCode)); //_listDataFields.Add(new ProcessDataField("dest_Receiver", "")); 知会人 //将 WFConsInvtChecking 的任务传给K2 var taskJson = Newtonsoft.Json.JsonConvert.SerializeObject(task); _listDataFields.Add(new ProcessDataField("ProjectTaskInfo", taskJson)); int _procInstID = K2FxContext.Current.StartProcess(_procCode, ClientCookie.UserCode, _listDataFields); if (_procInstID > 0) { // 更新 ConsInvtChecking 表的ProcInstId entity.ProcInstID = _procInstID; ClosureConsInvtChecking.Update(entity); SaveCommers(entity, ProjectAction.Submit, ProjectCommentStatus.Submit); ProjectInfo.FinishNode(entity.ProjectId, FlowCode.Closure_ConsInvtChecking, NodeCode.Closure_ConsInvtChecking_ResultUpload); } return(Ok()); }
// ReSharper disable once RedundantAssignment /// <summary>Compiles expression to delegate by emitting the IL. /// If sub-expressions are not supported by emitter, then the method returns null. /// The usage should be calling the method, if result is null then calling the Expression.Compile. /// Making it partial makes possibly to coditionally rely FastExpressionCompiler availability on different platforms.</summary> /// <param name="compiledDelegate">Result delegate or null,if unable to compile.</param> /// <param name="bodyExpr">Lambda body.</param> /// <param name="paramExprs">Lambda parameter expressions.</param> /// <param name="paramTypes">The types of parameters.</param> /// <param name="returnType">The return type.</param> static partial void TryCompile <TDelegate>(ref TDelegate compiledDelegate, Expression bodyExpr, ParameterExpression[] paramExprs, Type[] paramTypes, Type returnType) where TDelegate : class { ClosureInfo ignored = null; compiledDelegate = (TDelegate)TryCompile(ref ignored, typeof(TDelegate), paramTypes, returnType, bodyExpr, paramExprs); }
/// <summary>Compiles expression to delegate by emitting the IL. /// If sub-expressions are not supported by emitter, then the method returns null. /// The usage should be calling the method, if result is null then calling the Expression.Compile.</summary> /// <param name="bodyExpr">Lambda body.</param> /// <param name="paramExprs">Lambda parameter expressions.</param> /// <param name="paramTypes">The types of parameters.</param> /// <param name="returnType">The return type.</param> /// <returns>Result delegate or null, if unable to compile.</returns> public static TDelegate TryCompile <TDelegate>( Expression bodyExpr, IList <ParameterExpression> paramExprs, Type[] paramTypes, Type returnType) where TDelegate : class { ClosureInfo ignored = null; return((TDelegate)TryCompile(ref ignored, typeof(TDelegate), paramTypes, returnType, bodyExpr, paramExprs)); }
/// <summary> /// 获取单个 /// </summary> /// <param name="code"></param> /// <returns></returns> public IHttpActionResult Get(Guid id) { var dic = ClosureInfo.Get(id); if (dic == null) { return(NotFound()); } return(Ok(dic)); }
public IHttpActionResult GetOnline(string projectID) { var closure = ClosureInfo.GetByProjectId(projectID); var store = StoreBasicInfo.GetStore(closure.USCode); var toolEntity = ClosureTool.Get(closure.ProjectId); var woEntity = ClosureWOCheckList.Get(closure.ProjectId); List <StoreBEInfo> remoteBeList = new List <StoreBEInfo>(); List <StoreBEInfo> attachedBeList = new List <StoreBEInfo>(); StoreBEInfo mds = null; StoreBEInfo mcCafe = null; StoreBEInfo hour24 = null; if (store.StoreBEInfoList.Count > 0) { foreach (var beInfo in store.StoreBEInfoList) { switch (beInfo.BETypeName) { case "Remote Kiosk": remoteBeList.Add(beInfo); break; case "Attach Kiosk": attachedBeList.Add(beInfo); break; case "MDS": mds = beInfo; break; case "McCafe": mcCafe = beInfo; break; case "24 Hour": hour24 = beInfo; break; } } } return(Ok(new { Store = store, ClosureTool = toolEntity, WOCheckList = woEntity, RemoteBeList = remoteBeList, AttachedBeList = attachedBeList, MDS = mds, McCafe = mcCafe, Hour24 = hour24 })); }
internal MSAst.MethodCallExpression CreateLocalContext(MSAst.Expression parentContext) { var closureVariables = _closureVariables; if (_closureVariables == null) { closureVariables = new ClosureInfo[0]; } return Ast.Call( AstMethods.CreateLocalContext, parentContext, MutableTuple.Create(ArrayUtils.ConvertAll(closureVariables, x => GetClosureCell(x))), Ast.Constant(ArrayUtils.ConvertAll(closureVariables, x => x.AccessedInScope ? x.Variable.Name : null)) ); }
public IHttpActionResult DownLoadTemplate(string projectID) { var current = System.Web.HttpContext.Current; string path = SiteFilePath.Template_DIRECTORY + "\\" + SiteFilePath.FAWrite_offTool_Template; Excel excel = new Excel(); string templatePath = path; string tempFilePath = current.Server.MapPath("~/") + "Temp\\" + Guid.NewGuid() + ".xlsx"; var closure = ClosureInfo.GetByProjectId(projectID); excel.Open(path); excel.Save(tempFilePath); var store = _db.StoreBasicInfo.First(e => e.StoreCode == closure.USCode); Excel tempExcel = new Excel(); tempExcel.Open(tempFilePath); var sheet = tempExcel.Sheets["PMT"]; sheet.Cells[1, 1].StrValue = store.RegionENUS; sheet.Cells[2, 1].StrValue = store.MarketENUS; sheet.Cells[3, 1].StrValue = store.NameENUS; sheet.Cells[4, 1].StrValue = store.StoreCode; sheet.Cells[5, 1].StrValue = store.StoreTypeName; if (closure.ActualCloseDate != null) { sheet.Cells[6, 1].StrValue = closure.ActualCloseDate.Value.ToString("yyyy-MM-dd"); } sheet.Cells[7, 1].StrValue = closure.PMNameZHCN; tempExcel.Save(tempFilePath); var currentNode = NodeInfo.GetCurrentNode(projectID, FlowCode.Closure_WOCheckList); var newNode = NodeInfo.GetNodeInfo(NodeCode.Closure_WOCheckList_DownLoadTemplate); if (newNode.Sequence > currentNode.Sequence) { ProjectInfo.FinishNode(projectID, FlowCode.Closure_WOCheckList, NodeCode.Closure_WOCheckList_DownLoadTemplate); } current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + SiteFilePath.GetTemplateFileName(closure.USCode, FlowCode.Closure_WOCheckList, SiteFilePath.FAWrite_offTool_Template)); current.Response.ContentType = "application/octet-stream"; current.Response.WriteFile("" + tempFilePath + ""); current.Response.End(); return(Ok()); }
private static bool TryCollectBoundConstants(ref ClosureInfo closure, IList <Expression> exprs, IList <ParameterExpression> paramExprs) { var count = exprs.Count; for (var i = 0; i < count; i++) { if (!TryCollectBoundConstants(ref closure, exprs[i], paramExprs)) { return(false); } } return(true); }
public ActionResult StoreProjectRowsCount(string _USCode) { var resultData = new { ClosureRowsCount = ClosureInfo.Search(o => o.USCode == _USCode).ToList <ClosureInfo>().Count, RenewalRowsCount = RenewalInfo.Search(o => o.USCode == _USCode).ToList <RenewalInfo>().Count, RebuildRowsCount = RebuildInfo.Search(o => o.USCode == _USCode).ToList <RebuildInfo>().Count, MajorLeaseRowsCount = MajorLeaseInfo.Search(o => o.USCode == _USCode).ToList <MajorLeaseInfo>().Count, ReimageRowsCount = ReimageInfo.Search(o => o.USCode == _USCode).ToList <ReimageInfo>().Count, TempClosureRowsCount = TempClosureInfo.Search(o => o.USCode == _USCode).ToList <TempClosureInfo>().Count }; string result = Newtonsoft.Json.JsonConvert.SerializeObject(resultData); return(Content(result)); }
public IHttpActionResult SearchPosition(string storeCode) { var sql = string.Format(@"SELECT tb_employee.Code,tb_employee.NameZHCN,tb_employee.NameENUS,tb_position.NameENUS as PositionName,tb_position.PositionCode FROM dbo.Store tb_store INNER JOIN dbo.UserMiniMarket tb_mini ON tb_mini.MiniMarketCode = tb_store.MiniMarketCode INNER JOIN dbo.UserPosition tb_position ON tb_position.Id = tb_mini.PositionId INNER JOIN dbo.Employee tb_employee ON tb_employee.Id = tb_position.UserId WHERE tb_store.code = '{0}' AND tb_position.PositionCode in ('suoya303051','suoya303055','suoya303057','suoya450007','suoya303050','suoya303054') AND tb_employee.Status = 1 ORDER BY PositionCode", storeCode); //AND tb_employee.Status = 1 var list = ClosureInfo.SqlQuery <SPosition>(sql, null).ToList(); return(Ok(list)); }
public IHttpActionResult SummaryClosure(JObject entity) { dynamic main = entity; JObject model = main.ClosureInfo; bool push = Convert.ToBoolean(main.push); var closure = model.ToObject <ClosureInfo>(); using (TransactionScope tranScope = new TransactionScope()) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (closure.ClosureReasonCode != "Others") { closure.ClosureReasonRemark = string.Empty; } if (closure.Id == new Guid()) { closure.Id = Guid.NewGuid(); closure.CreateDate = DateTime.Now; closure.ProjectId = ProjectInfo.CreateSummaryProject(FlowCode.Closure, closure.USCode, closure.CreateUserAccount); ClosureInfo.Add(closure); } else { ClosureInfo.Update(closure); } try { tranScope.Complete(); } catch (DbEntityValidationException dbEx) { tranScope.Dispose(); } return(Ok(entity)); } }
public IHttpActionResult GetByProjectId(string projectId) { var entity = ClosureWOCheckList.Get(projectId); if (entity != null) { ProjectCommentCondition condition = new ProjectCommentCondition(); condition.RefTableId = entity.Id; condition.RefTableName = ClosureWOCheckList.TableName; condition.UserAccount = ClientCookie.UserCode; condition.Status = ProjectCommentStatus.Save; var commentList = ProjectComment.SearchList(condition); if (commentList != null && commentList.Count > 0) { entity.Comments = commentList[0].Content; } var closureEntity = ClosureInfo.GetByProjectId(entity.ProjectId); entity.USCode = closureEntity.USCode; entity.UserAccount = ClientCookie.UserCode; if (string.IsNullOrEmpty(entity.PMSupervisorAccount)) { var puser = ProjectUsers.FirstOrDefault(i => i.ProjectId == entity.ProjectId && i.RoleCode == ProjectUserRoleCode.CM); if (puser != null) { entity.PMSupervisorAccount = puser.UserAccount; } } // entity.Comments = GetCommers(entity); //string pmAccount = closureEntity.PMAccount; //entity.PMSupervisorAccount = userPositionHandler.GetReportToAccounts(pmAccount); //string[] accounts = {UserPositionHandler.IT,UserPositionHandler.MCCL_Construction_Mgr}; //var positionlist = userPositionHandler.SearchUserPosition(closureEntity.USCode,accounts); //string mcclApprover = userPositionHandler.GetAccounts(positionlist); //entity.MCCLApproverAccount = mcclApprover; } return(Ok(entity)); }
public IHttpActionResult Save(ClosureMemo entity) { using (TransactionScope tranScope = new TransactionScope()) { if (entity.Id != Guid.Empty) { ClosureMemo.Update(entity); } else { entity.Id = Guid.NewGuid(); entity.CreateTime = DateTime.Now; entity.Creator = ClientCookie.UserCode; ClosureMemo.Add(entity); } ClosureInfo closure = ClosureInfo.GetByProjectId(entity.ProjectId); closure.ActualCloseDate = entity.ClosureDate; closure.Update(); ProjectInfo.FinishNode(entity.ProjectId, FlowCode.Closure_Memo, NodeCode.Closure_ClosureMemo_Input); tranScope.Complete(); } return(Ok()); }
private static bool EmitNew(NewExpression n, IList <ParameterExpression> ps, ILGenerator il, ClosureInfo closure) { var ok = EmitMany(n.Arguments, ps, il, closure); if (ok) { il.Emit(OpCodes.Newobj, n.Constructor); } return(ok); }
private ClosureInfo ProcessClosure(AssemblyProcessorContext context, TypeDefinition closureType, TypeReference[] genericParameters) { ClosureInfo closure; if (closures.TryGetValue(closureType, out closure)) return closure; var closureTypeConstructor = closureType.Methods.FirstOrDefault(x => x.Name == ".ctor"); var closureGenericType = closureType.MakeGenericType(genericParameters); // Create factory method for pool items var factoryMethod = new MethodDefinition("<Factory>", MethodAttributes.HideBySig | MethodAttributes.Private | MethodAttributes.Static, closureGenericType); closureType.Methods.Add(factoryMethod); factoryMethod.Body.InitLocals = true; factoryMethod.Body.Variables.Add(new VariableDefinition(closureGenericType)); var factoryMethodProcessor = factoryMethod.Body.GetILProcessor(); // Create and store closure factoryMethodProcessor.Emit(OpCodes.Newobj, closureTypeConstructor.MakeGeneric(genericParameters)); factoryMethodProcessor.Emit(OpCodes.Stloc_0); //// Return closure factoryMethodProcessor.Emit(OpCodes.Ldloc_0); factoryMethodProcessor.Emit(OpCodes.Ret); // Create pool field var poolField = new FieldDefinition("<pool>", FieldAttributes.Public | FieldAttributes.Static, poolType.MakeGenericType(closureGenericType)); closureType.Fields.Add(poolField); var poolFieldReference = poolField.MakeGeneric(genericParameters); // Initialize pool var cctor = GetOrCreateClassConstructor(closureType); var ilProcessor2 = cctor.Body.GetILProcessor(); var retInstruction = cctor.Body.Instructions.FirstOrDefault(x => x.OpCode == OpCodes.Ret); ilProcessor2.InsertBefore(retInstruction, ilProcessor2.Create(OpCodes.Ldnull)); ilProcessor2.InsertBefore(retInstruction, ilProcessor2.Create(OpCodes.Ldftn, factoryMethod.MakeGeneric(genericParameters))); ilProcessor2.InsertBefore(retInstruction, ilProcessor2.Create(OpCodes.Newobj, funcConstructor.MakeGeneric(closureGenericType))); ilProcessor2.InsertBefore(retInstruction, ilProcessor2.Create(OpCodes.Newobj, poolConstructor.MakeGeneric(closureGenericType))); ilProcessor2.InsertBefore(retInstruction, ilProcessor2.Create(OpCodes.Stsfld, poolFieldReference)); // Implement IPooledClosure closureType.Interfaces.Add(pooledClosureType); // Create reference count field var countField = new FieldDefinition("<referenceCount>", FieldAttributes.Public, context.Assembly.MainModule.TypeSystem.Int32); closureType.Fields.Add(countField); var oountFieldReference = countField.MakeGeneric(genericParameters); // Create AddReference method var addReferenceMethod = new MethodDefinition("AddReference", MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Final | MethodAttributes.Virtual | MethodAttributes.NewSlot, context.Assembly.MainModule.TypeSystem.Void); var ilProcessor4 = addReferenceMethod.Body.GetILProcessor(); ilProcessor4.Emit(OpCodes.Ldarg_0); ilProcessor4.Emit(OpCodes.Ldflda, oountFieldReference); ilProcessor4.Emit(OpCodes.Call, interlockedIncrementMethod); ilProcessor4.Emit(OpCodes.Pop); ilProcessor4.Emit(OpCodes.Ret); closureType.Methods.Add(addReferenceMethod); // Create Release method var releaseMethod = new MethodDefinition("Release", MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Final | MethodAttributes.Virtual | MethodAttributes.NewSlot, context.Assembly.MainModule.TypeSystem.Void); ilProcessor4 = releaseMethod.Body.GetILProcessor(); retInstruction = ilProcessor4.Create(OpCodes.Ret); // Check decremented reference count ilProcessor4.Emit(OpCodes.Ldarg_0); ilProcessor4.Emit(OpCodes.Ldflda, oountFieldReference); ilProcessor4.Emit(OpCodes.Call, interlockedDecrementMethod); ilProcessor4.Emit(OpCodes.Ldc_I4_0); ilProcessor4.Emit(OpCodes.Ceq); ilProcessor4.Emit(OpCodes.Brfalse_S, retInstruction); // Release this to pool ilProcessor4.Emit(OpCodes.Ldsfld, poolFieldReference); ilProcessor4.Emit(OpCodes.Ldarg_0); ilProcessor4.Emit(OpCodes.Callvirt, poolReleaseMethod.MakeGeneric(closureGenericType)); ilProcessor4.Append(retInstruction); closureType.Methods.Add(releaseMethod); closures.Add(closureType, closure = new ClosureInfo { FactoryMethod = factoryMethod, AddReferenceMethod = addReferenceMethod, ReleaseMethod = releaseMethod, PoolField = poolField }); return closure; }
private static bool EmitComparison(BinaryExpression c, IList <ParameterExpression> ps, ILGenerator il, ClosureInfo closure) { var ok = EmitBinary(c, ps, il, closure); if (ok) { switch (c.NodeType) { case ExpressionType.Equal: il.Emit(OpCodes.Ceq); break; case ExpressionType.LessThan: il.Emit(OpCodes.Clt); break; case ExpressionType.GreaterThan: il.Emit(OpCodes.Cgt); break; case ExpressionType.NotEqual: il.Emit(OpCodes.Ceq); il.Emit(OpCodes.Ldc_I4_0); il.Emit(OpCodes.Ceq); break; case ExpressionType.LessThanOrEqual: il.Emit(OpCodes.Cgt); il.Emit(OpCodes.Ldc_I4_0); il.Emit(OpCodes.Ceq); break; case ExpressionType.GreaterThanOrEqual: il.Emit(OpCodes.Clt); il.Emit(OpCodes.Ldc_I4_0); il.Emit(OpCodes.Ceq); break; } } return(ok); }
private static bool EmitMemberAccess(MemberExpression m, IList <ParameterExpression> ps, ILGenerator il, ClosureInfo closure) { if (m.Expression != null) { var ok = TryEmit(m.Expression, ps, il, closure); if (!ok) { return(false); } } var field = m.Member as FieldInfo; if (field != null) { il.Emit(field.IsStatic ? OpCodes.Ldsfld : OpCodes.Ldfld, field); return(true); } var property = m.Member as PropertyInfo; if (property != null) { var getMethod = property.GetGetMethod(); if (getMethod == null) { return(false); } EmitMethodCall(getMethod, il); } return(true); }
private static bool EmitMethodCall(MethodCallExpression m, IList <ParameterExpression> ps, ILGenerator il, ClosureInfo closure) { var ok = true; if (m.Object != null) { ok = TryEmit(m.Object, ps, il, closure); } if (ok && m.Arguments.Count != 0) { ok = EmitMany(m.Arguments, ps, il, closure); } if (ok) { EmitMethodCall(m.Method, il); } return(ok); }
private static bool EmitMemberInit(MemberInitExpression mi, IList <ParameterExpression> ps, ILGenerator il, ClosureInfo closure) { var ok = EmitNew(mi.NewExpression, ps, il, closure); if (!ok) { return(false); } var obj = il.DeclareLocal(mi.Type); il.Emit(OpCodes.Stloc, obj); var bindings = mi.Bindings; for (int i = 0, n = bindings.Count; i < n; i++) { var binding = bindings[i]; if (binding.BindingType != MemberBindingType.Assignment) { return(false); } il.Emit(OpCodes.Ldloc, obj); ok = TryEmit(((MemberAssignment)binding).Expression, ps, il, closure); if (!ok) { return(false); } var prop = binding.Member as PropertyInfo; if (prop != null) { var setMethod = prop.GetSetMethod(); if (setMethod == null) { return(false); } EmitMethodCall(setMethod, il); } else { var field = binding.Member as FieldInfo; if (field == null) { return(false); } il.Emit(OpCodes.Stfld, field); } } il.Emit(OpCodes.Ldloc, obj); return(true); }
private static bool EmitArrayIndex(BinaryExpression ai, IList <ParameterExpression> ps, ILGenerator il, ClosureInfo closure) { var ok = EmitBinary(ai, ps, il, closure); if (ok) { il.Emit(OpCodes.Ldelem_Ref); } return(ok); }
private MSAst.Expression GetClosureCell(ClosureInfo variable) { return ((ClosureExpression)GetVariableExpression(variable.Variable)).ClosureCell; }
private static bool EmitConstant(ConstantExpression constantExpr, ILGenerator il, ClosureInfo closure) { var constant = constantExpr.Value; if (constant == null) { il.Emit(OpCodes.Ldnull); } else if (constant is int || constant.GetType().IsEnum) { EmitLoadConstantInt(il, (int)constant); } else if (constant is double) { il.Emit(OpCodes.Ldc_R8, (double)constant); } else if (constant is bool) { il.Emit((bool)constant ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0); } else if (constant is string) { il.Emit(OpCodes.Ldstr, (string)constant); } else if (constant is Type) { il.Emit(OpCodes.Ldtoken, (Type)constant); var getTypeFromHandle = typeof(Type).GetMethod("GetTypeFromHandle"); il.Emit(OpCodes.Call, getTypeFromHandle); } else if (closure != null) { var constantIndex = closure.ConstantExpressions.IndexOf(constantExpr); if (constantIndex == -1) { return(false); } // load closure argument: Closure or Closure Array il.Emit(OpCodes.Ldarg_0); if (!closure.IsClosureArray) { // load closure field il.Emit(OpCodes.Ldfld, closure.ConstantClosureFields[constantIndex]); } else { // load array field il.Emit(OpCodes.Ldfld, ArrayClosure.ArrayField); // load array item index EmitLoadConstantInt(il, constantIndex); // load item from index il.Emit(OpCodes.Ldelem_Ref); // case if needed var castType = constantExpr.Type; if (castType != typeof(object)) { il.Emit(OpCodes.Castclass, castType); } } } else { return(false); } // boxing the value type, otherwise we can get a strange result when 0 is treated as Null. if (constantExpr.Type == typeof(object) && constant != null && constant.GetType().IsValueType()) { il.Emit(OpCodes.Box, constant.GetType()); } return(true); }
private static bool EmitConvert(UnaryExpression node, IList <ParameterExpression> ps, ILGenerator il, ClosureInfo closure) { var ok = TryEmit(node.Operand, ps, il, closure); if (ok) { var convertTargetType = node.Type; if (convertTargetType == typeof(object)) { return(false); } il.Emit(OpCodes.Castclass, convertTargetType); } return(ok); }
private MSAst.Expression GetClosureCell(ClosureInfo variable) { return(((ClosureExpression)GetVariableExpression(variable.Variable)).ClosureCell); }
private static bool EmitNewArray(NewArrayExpression na, IList <ParameterExpression> ps, ILGenerator il, ClosureInfo closure) { var elems = na.Expressions; var arrType = na.Type; var elemType = arrType.GetElementType(); var isElemOfValueType = elemType.IsValueType; var arrVar = il.DeclareLocal(arrType); EmitLoadConstantInt(il, elems.Count); il.Emit(OpCodes.Newarr, elemType); il.Emit(OpCodes.Stloc, arrVar); var ok = true; for (int i = 0, n = elems.Count; i < n && ok; i++) { il.Emit(OpCodes.Ldloc, arrVar); EmitLoadConstantInt(il, i); // loading element address for later copying of value into it. if (isElemOfValueType) { il.Emit(OpCodes.Ldelema, elemType); } ok = TryEmit(elems[i], ps, il, closure); if (ok) { if (isElemOfValueType) { il.Emit(OpCodes.Stobj, elemType); // store element of value type by array element address } else { il.Emit(OpCodes.Stelem_Ref); } } } il.Emit(OpCodes.Ldloc, arrVar); return(ok); }