private static void CommitMonitorData() { if (PerformanceMonitorHelper.ExistsMonitor(MonitorName)) { MonitorData md = PerformanceMonitorHelper.GetMonitor("WfServerContextInvoker"); md.Stopwatch.Stop(); if (md.EnableLogging) { md.LogWriter.WriteLine("请求{0}的结束时间: {1:yyyy-MM-dd HH:mm:ss.fff},经过{2:#,##0}毫秒", md.MonitorName, SNTPClient.AdjustedTime, md.Stopwatch.ElapsedMilliseconds); CommitLogging(md); } if (md.EnablePFCounter) { SetCountersValues(md, md.HasErrors); } PerformanceMonitorHelper.RemoveMonitor(MonitorName); PerformanceMonitorHelper.DefaultMonitorName = "DefaultMonitor"; } }
private void context_BeginRequestExecute(object sender, EventArgs e) { if (PageMonitorSettings.GetConfig().Enabled) { PageMonitorElement pme = PageMonitorSettings.GetConfig().Pages.GetMatchedElement(); if (pme != null) { MonitorData md = PerformanceMonitorHelper.StartMonitor(PageMonitorModule.MonitorDataKey); md.EnableLogging = pme.EnableLogging; md.EnablePFCounter = pme.EnablePFCounter; md.MonitorName = pme.Name; if (string.IsNullOrEmpty(pme.CounterInstanceName)) { md.InstanceName = pme.Name; } else { md.InstanceName = pme.CounterInstanceName; } PerformanceMonitorHelper.DefaultMonitorName = PageMonitorModule.MonitorDataKey; if (pme.EnableLogging) { md.LogWriter.WriteLine("请求{0}的开始时间: {1:yyyy-MM-dd HH:mm:ss.fff}", md.MonitorName, SNTPClient.AdjustedTime); } } } }
/// <summary> /// 按照条件加载对象 /// </summary> /// <param name="whereAction">筛选条件</param> /// <param name="orderByAction">排序条件</param> /// <param name="mappings"></param> /// <returns>对象集合</returns> public TCollection Load(Action <WhereSqlClauseBuilder> whereAction, Action <OrderBySqlClauseBuilder> orderByAction, ORMappingItemCollection mappings) { TCollection result = null; PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(string.Format("Load({0})", this.GetType().FullName), () => { whereAction.NullCheck("whereAction"); WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder(); whereAction(builder); builder.AppendTenantCode(typeof(T)); OrderBySqlClauseBuilder orderByBuilder = null; if (orderByAction != null) { orderByBuilder = new OrderBySqlClauseBuilder(); orderByAction(orderByBuilder); } result = InnerLoadByBuilder(builder.ToSqlString(TSqlBuilder.Instance), orderByBuilder, mappings); }); return(result); }
public System.ServiceModel.Channels.Message SerializeReply(System.ServiceModel.Channels.MessageVersion messageVersion, object[] parameters, object result) { Message returnMessage = null; PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("SerializeReply", () => { //返回值总是Raw格式的 string jsonResult = string.Empty; if (result is string) { if (this._AtlasEnabled) { //asp.net ajax 返回值格式 Dictionary <string, object> returnDict = new Dictionary <string, object>(); returnDict.Add("d", result); jsonResult = JSONSerializerExecute.Serialize(returnDict); } else { jsonResult = result.ToString(); } } else { jsonResult = JSONSerializerExecute.SerializeWithType(result); } returnMessage = WcfUtils.CreateJsonFormatReplyMessage(messageVersion, this._OperationDesc.Messages[1].Action, jsonResult); }); return(returnMessage); }
private WfProcessCollection LoadProcesses(Action <WhereSqlClauseBuilder> action) { action.NullCheck("action"); var whereBuilder = new WhereSqlClauseBuilder(); action(whereBuilder); var mapping = ORMapping.GetMappingInfo <WfProcessInstanceData>(); string[] fields = ORMapping.GetSelectFieldsName(mapping, "Data"); var sql = string.Format("SELECT {0},{1} FROM {2} WHERE {3}", string.Join(",", fields), BINARYDATA, mapping.TableName, whereBuilder.ToSqlString(TSqlBuilder.Instance)); var table = DbHelper.RunSqlReturnDS(sql, GetConnectionName()).Tables[0]; WfProcessCollection result = null; PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("DataTableToProcessCollection", () => result = DataTableToProcessCollection(table) ); return(result); }
/// <summary> /// 得到某个活动的子流程。如果缓存中存在,则使用缓存中的流程 /// </summary> /// <param name="activityID"></param> /// <param name="templateKey"></param> /// <returns></returns> public static WfProcessCollection GetProcessByOwnerActivityID(string activityID, string templateKey) { activityID.CheckStringIsNullOrEmpty("activityID"); templateKey.CheckStringIsNullOrEmpty("templateKey"); WfProcessCollection queryResult = null; PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(string.Format("LoadProcessByOwnerActivityID({0}-{1})", activityID, templateKey), () => queryResult = WorkflowSettings.GetConfig().GetPersistManager().LoadProcessByOwnerActivityID(activityID, templateKey) ); WfProcessCollection result = new WfProcessCollection(); foreach (IWfProcess process in queryResult) { //如果缓存中存在,则使用缓存的数据,如果缓存中不存在,则使用查询到的结果 IWfProcess processNeedToAdd = WfProcessContextCache.Instance.GetOrAddNewValue(process.ID, (cache, key) => { cache.Add(key, process); return(process); }); result.Add(processNeedToAdd); } return(result); }
/// <summary> /// 根据ResourceID得到流程 /// </summary> /// <param name="resourceID"></param> /// <returns></returns> public static WfProcessCollection GetProcessByResourceID(string resourceID) { resourceID.NullCheck <WfRuntimeException>("resourceID"); WfProcessCollection processes = new WfProcessCollection(); foreach (KeyValuePair <string, IWfProcess> kp in WfProcessContextCache.Instance) { if (string.Compare(kp.Value.ResourceID, resourceID, true) == 0) { processes.Add(kp.Value); break; } } WfProcessCollection persistedProcesses = null; PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(string.Format("LoadProcessByResourceID({0})", resourceID), () => persistedProcesses = WorkflowSettings.GetConfig().GetPersistManager().LoadProcessByResourceID(resourceID) ); persistedProcesses.ForEach(p => { if (processes.ContainsKey(p.ID) == false) { processes.Add(p); } WfProcessContextCache.Instance[p.ID] = p; }); return(processes); }
public virtual void Delete(Action <WhereSqlClauseBuilder> whereAction) { whereAction.NullCheck("whereAction"); PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(string.Format("Delete(whereAction-{0})", this.GetType().FullName), () => { WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder(); whereAction(builder); if (builder.Count > 0) { Dictionary <string, object> context = new Dictionary <string, object>(); ORMappingItemCollection mappings = GetMappingInfo(context); string sql = string.Format("DELETE {0} WHERE {1}", mappings.TableName, builder.ToSqlString(TSqlBuilder.Instance)); BeforeInnerDelete(builder, context); using (TransactionScope scope = TransactionScopeFactory.Create()) { DbHelper.RunSql(db => db.ExecuteNonQuery(CommandType.Text, sql), this.GetConnectionName()); AfterInnerDelete(builder, context); scope.Complete(); } } }); }
/// <summary> /// 根据已经完成系统任务创建新任务 /// </summary> /// <param name="taskID">被移动的任务的ID</param> /// <param name="status">重置任务的状态</param> public void MoveToNoRunningTask(string taskID) { var completedTask = this.Load(taskID); (completedTask != null).FalseThrow <ArgumentException>("ID为 {0} 的任务不存在", taskID); PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(string.Format("MoveNoRunning({0})", this.GetType().FullName), () => { Dictionary <string, object> context = new Dictionary <string, object>(); ORMappingItemCollection mappingsTask = ORMapping.GetMappingInfo <SysTask>(); var task = completedTask.CreateNewSystask(UuidHelper.NewUuidString());; StringBuilder sql = new StringBuilder(); sql.Append(ORMapping.GetInsertSql(task, mappingsTask, TSqlBuilder.Instance)); sql.Append(TSqlBuilder.Instance.DBStatementSeperator); using (TransactionScope scope = TransactionScopeFactory.Create()) { DbHelper.RunSql(sql.ToString(), this.GetConnectionName()); scope.Complete(); } }); }
/// <summary> /// 按照条件加载对象 /// </summary> /// <param name="loadingCondition">筛选和排序条件</param> /// <param name="mappings"></param> /// <returns>对象集合</returns> public TCollection Load(WhereLoadingCondition loadingCondition, ORMappingItemCollection mappings = null) { loadingCondition.NullCheck("loadingCondition"); if (mappings == null) { mappings = this.GetQueryMappingInfo(); } TCollection result = default(TCollection); PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(string.Format("Load({0})", this.GetType().FullName), () => { loadingCondition.BuilderAction.NullCheck("whereAction"); WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder(); loadingCondition.BuilderAction(builder); builder.AppendTenantCode(typeof(T)); OrderBySqlClauseBuilder orderByBuilder = null; if (loadingCondition.OrderByAction != null) { orderByBuilder = new OrderBySqlClauseBuilder(); loadingCondition.OrderByAction(orderByBuilder); } result = this.InnerLoadByBuilder(builder.ToSqlString(TSqlBuilder.Instance), orderByBuilder, mappings); }); return(result); }
/// <summary> /// 根据ActivityID得到流程 /// </summary> /// <param name="activityID"></param> /// <returns></returns> public static IWfProcess GetProcessByActivityID(string activityID) { activityID.NullCheck <WfRuntimeException>("activityID"); IWfProcess process = null; foreach (KeyValuePair <string, IWfProcess> kp in WfProcessContextCache.Instance) { if (kp.Value.Activities.ContainsKey(activityID)) { process = kp.Value; break; } } if (process == null) { PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(string.Format("LoadProcessByActivityID({0})", activityID), () => process = WorkflowSettings.GetConfig().GetPersistManager().LoadProcessByActivityID(activityID) ); WfProcessContextCache.Instance.Add(process.ID, process); } return(process); }
/// <summary> /// 按照条件删除 /// </summary> /// <param name="whereAction"></param> public virtual void Delete(Action <WhereSqlClauseBuilder> whereAction) { whereAction.NullCheck("whereAction"); PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(string.Format("Delete(whereAction-{0})", this.GetType().FullName), () => { WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder(); whereAction(builder); Dictionary <string, object> context = new Dictionary <string, object>(); this.BeforeInnerDelete(builder, context); string sql = this.GetDeleteSql(builder, context); if (sql.IsNotEmpty()) { using (TransactionScope scope = TransactionScopeFactory.Create()) { DbHelper.RunSql(db => db.ExecuteNonQuery(CommandType.Text, sql), this.GetConnectionName()); this.AfterInnerDelete(builder, context); scope.Complete(); } } }); }
protected internal override void DoOperation() { if (IsRelativeForm == false) { PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("CheckCurrentUserInAcl", () => CheckCurrentUserInAcl(WfClientContext.Current.OriginalActivity.Process)); } OnProcessReady(WfClientContext.Current.OriginalActivity.Process); OnPrepareCommandState(WfClientContext.Current.OriginalActivity.Process); SetLockResult lockResult = null; if (WfClientContext.Current.InMoveToMode) { if (LockConfigSetting.GetConfig().Enabled) { PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("AddLock", () => { lockResult = WfClientContext.Current.AddFormLock( WfClientContext.Current.OriginalActivity.Process.ResourceID, WfClientContext.Current.OriginalActivity.ID); }); } } PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("SetScene", () => SetScene(lockResult)); //需要导航到目标视图 TransferToTargetView(); }
private static PerformanceCounter createCounter( string COUNTER_NAME, string COUNTER_HELP, string instanceName ) { PerformanceCounter counter = null; PerformanceMonitorHelper.createCounter( PerformanceMonitorHelper.WBX_CATEGORY_NAME, PerformanceMonitorHelper.WBX_CATEGORY_NAME, PerformanceCounterCategoryType.MultiInstance, COUNTER_NAME, COUNTER_HELP, PerformanceCounterType.NumberOfItems64 ); counter = PerformanceMonitorHelper.getCounter( PerformanceMonitorHelper.WBX_CATEGORY_NAME, COUNTER_NAME, instanceName, PerformanceCounterInstanceLifetime.Process, false ); return(counter); }
private void ExecuteOpenFormControllerOperation() { IWfProcess process = WfClientContext.Current.OriginalActivity.Process; OpenFormControllerOperation operation = new OpenFormControllerOperation(); string requestTicketString = HttpContext.Current.Request.QueryString.GetValue("requestTicket", string.Empty); if (requestTicketString.IsNotEmpty()) { RelativeTicket requestTicket = RelativeTicket.DecryptFromString(requestTicketString); requestTicket.CheckIsValid(); operation.IsRelativeForm = true; } operation.Process = process; operation.NavigationCommand = CollectNavigationCommand(this.GetType()); operation.SceneInfo = CollectSceneInfo(this.GetType()); OnInitOperation(operation); PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("DoOpenFormControllerOperation", () => operation.DoOperation()); }
protected virtual void OnProcessReady(IWfProcess process) { if (ProcessReady != null) { PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("ProcessReady", () => ProcessReady(process)); } }
public void DeserializeRequest(System.ServiceModel.Channels.Message message, object[] parameters) { object bodyFormatProperty; if (!message.Properties.TryGetValue(WebBodyFormatMessageProperty.Name, out bodyFormatProperty) || (bodyFormatProperty as WebBodyFormatMessageProperty).Format != WebContentFormat.Raw) { throw new InvalidOperationException("服务行为配置错误,请将WebHttpBinding的ContentTypeMapper属性设置为WfRawWebContentTypeMapper类型"); } try { PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("DeserializeRequest", () => { string jsonStr = WcfUtils.GetMessageRawContent(message); Dictionary <string, object> paramsInfo = JSONSerializerExecute.Deserialize <Dictionary <string, object> >(jsonStr); Dictionary <string, object> headers = PopHeaderInfo(paramsInfo); PushHeaderInfoToMessageProperties(message, headers); Dictionary <string, string> connectionMappings = PopConnectionMappings(paramsInfo); PushConnectionMappingsToMessageProperties(message, connectionMappings); Dictionary <string, object> context = PopContextInfo(paramsInfo); PushContextToMessageProperties(message, context); GenericTicketTokenContainer container = PopGenericTicketTokenContainer(paramsInfo); PushGenericTicketTokenContainer(message, container); for (int i = 0; i < _OperationDesc.Messages[0].Body.Parts.Count; i++) { string paramName = _OperationDesc.Messages[0].Body.Parts[i].Name; Type targetType = this._OperationDesc.Messages[0].Body.Parts[i].Type; object val = paramsInfo[paramName]; try { parameters[i] = JSONSerializerExecute.DeserializeObject(val, targetType); } catch (System.Exception ex) { string errorMessage = string.Format("反序列化参数{0}错误,类型为{1}:{2}", paramName, targetType.ToString(), ex.Message); throw new InvalidDataException(errorMessage, ex); } } }); } catch (Exception ex) { throw new InvalidOperationException("传入的JSON格式错误:" + ex.Message, ex); } }
void IHttpHandler.ProcessRequest(HttpContext context) { context.Response.Cache.SetCacheability(HttpCacheability.NoCache); context.Response.Cache.SetNoStore(); PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("ExecuteMethodByRequest(ProcessRequest)", () => ControllerHelper.ExecuteMethodByRequest(this)); }
/// <summary> /// 重载基类加载ViewState的过程 /// </summary> /// <returns></returns> protected override object LoadPageStateFromPersistenceMedium() { object result = null; PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("LoadPageStateFromPersistenceMedium", () => result = InnerLoadPageStateFromPersistenceMedium()); return(result); }
private void context_Error(object sender, EventArgs e) { if (PerformanceMonitorHelper.ExistsMonitor(PageMonitorModule.MonitorDataKey)) { MonitorData md = PerformanceMonitorHelper.GetMonitor(PageMonitorModule.MonitorDataKey); md.HasErrors = true; } }
private object InvokeWithMonitor(object instance, object[] inputs, out object[] outputs) { ServiceMethodConfigurationElement methodElement = ServiceSettings.GetConfig().GetMethodElementByOperationContext(); object[] result = null; if (methodElement != null) { PerformanceMonitorHelper.DefaultMonitorName = MonitorName; MonitorData md = PerformanceMonitorHelper.StartMonitor(MonitorName); md.MonitorName = string.Format("{0}.{1}", OperationContext.Current.GetContractName(), OperationContext.Current.GetMethodName()); md.EnableLogging = methodElement.EnableLogging; md.EnablePFCounter = methodElement.EnablePFCounter; md.InstanceName = md.MonitorName; md.Context["GlobalInstance"] = new WebMethodServerCounters("_Total_"); md.Context["Instance"] = new WebMethodServerCounters(md.InstanceName); if (md.EnableLogging) { md.LogWriter.WriteLine("请求{0}的开始时间: {1:yyyy-MM-dd HH:mm:ss.fff}", md.MonitorName, SNTPClient.AdjustedTime); } try { PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(md.MonitorName, () => { result = this.InternalInvoke(instance, inputs); }); } catch (System.Exception ex) { md.HasErrors = true; if (md.EnableLogging) { ex.WriteToEventLog(md.MonitorName, EventLogEntryType.Error, 8010); } throw; } finally { CommitMonitorData(); } } else { result = this.InternalInvoke(instance, inputs); } outputs = (object[])result[1]; return(result[0]); }
public void PersistActions(WfActionParams actionParams) { this.ForEach(action => { PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration( string.Format("Persist Action: {0}", action.GetType().FullName), () => action.PersistAction(actionParams)); }); }
protected void TransferToTargetView() { PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("TransferToTargetView", () => { if (NavigationCommand != null) { NavigationCommand.Execute(); } }); }
/// <summary> /// 重载OnPreRender /// </summary> /// <param name="e"></param> protected override void OnPreRender(EventArgs e) { if (Scene.Current != null) { Scene.Current.RenderToControl(this); } PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("ViewBase-PreRender", () => base.OnPreRender(e)); }
/// <summary> /// 得到某个活动的子流程的状态信息,没有流程实例,只是状态信息 /// </summary> /// <param name="activityID"></param> /// <param name="templateKey"></param> /// <param name="includeAborted">是否包含已经作废的流程</param> /// <returns></returns> public static WfProcessCurrentInfoCollection GetProcessStatusByOwnerActivityID(string activityID, string templateKey, bool includeAborted) { activityID.CheckStringIsNullOrEmpty("activityID"); WfProcessCurrentInfoCollection queryResult = null; PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(string.Format("LoadProcessByOwnerActivityID({0}-{1})", activityID, templateKey), () => queryResult = WorkflowSettings.GetConfig().GetPersistManager().LoadProcessInfoOwnerActivityID(activityID, templateKey, includeAborted) ); return(queryResult); }
/// <summary> /// PreRender之后,准备保存ViewState /// </summary> /// <param name="e"></param> protected override void OnPreRenderComplete(EventArgs e) { PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("ViewBase-PreRenderComplete", () => { CommandStateHelper.SaveViewState(); if (Scene.Current != null) { Scene.Current.SaveViewState(); } base.OnPreRenderComplete(e); }); }
protected override string SaveClientState() { string result = string.Empty; if (this.initialData != null) { object[] state = new object[] { this.initialData, this.initialData.GetType().AssemblyQualifiedName }; PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(this.UniqueID + "_JSON Serializer", () => result = JSONSerializerExecute.Serialize(state)); } return(result); }
public void AfterWorkflowPersistAction(WfActionParams actionParams) { ProcessProgress.Current.MaxStep += this.Count; ProcessProgress.Current.Response(); this.ForEach(action => { PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration( string.Format("AfterWorkflowPersist Action: {0}", action.GetType().FullName), () => action.AfterWorkflowPersistAction(actionParams)); ProcessProgress.Current.Increment(); ProcessProgress.Current.Response(); }); }
public static WfClientProcessInfo ToClientProcessInfo(this IWfProcess process, IWfActivity originalActivity, WfClientUser clientUser) { process.NullCheck("process"); WfClientProcessInfo clientProcessInfo = null; PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("ToClientProcessInfo", () => { WfClientProcessInfoConverter.Instance.ServerToClient(process, ref clientProcessInfo); clientProcessInfo.AuthorizationInfo = WfClientProcessInfoBaseConverter.Instance.GetAuthorizationInfo(process, originalActivity, clientUser); }); return(clientProcessInfo); }
protected virtual void OnPrepareCommandState(IWfProcess process) { if (PrepareCommandState != null) { PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("PrepareCommandState", () => { CommandStateBase state = PrepareCommandState(process); if (state != null) { CommandStateHelper.RegisterState(state); } }); } }