public static object ExecuteScalar(object sender, IDbCommand command) { try { BeforeExecute?.Invoke(sender, new BeforeExecuteEventArgs() { Command = command }); var now = DateTime.Now; var result = command.ExecuteReader(); string message = $"Sql:{command.CommandText}\n" + $"用时:{(DateTime.Now - now).TotalMilliseconds}毫秒。\n" + $"返回结果:{result.ToString()}"; #if DEBUG Debug.Print(message); #endif AfterExecute?.Invoke(sender, new AfterExecuteEventArgs() { Command = command, Message = message }); return(result); } catch (Exception ex) { Error?.Invoke(sender, new ErrorExecuteEventArgs() { Command = command, Message = ex.Message }); throw; } }
/// <summary> /// 获取更新文件信息 /// </summary> /// <param name="size">文件大小</param> /// <param name="description">更新描述信息</param> /// < private void GetUpdateFileInfo(out long size, out string description, out BeforeExecute befExecute, out AfterExecute aftExecute) { XDocument versionDoc = XDocument.Load(string.Format("{0}\\{1}.xml", _downloadDir, _downloadingVersion)); XElement root = versionDoc.Root; string strSize = root.Element("FileList").Element("File").Attribute("Size").Value; size = long.Parse(strSize); description = root.Element("Main").Element("Description").Value; //获取扩展操作 //升级前操作 befExecute = null; XElement beforeElement = root.Element("Expansion").Element("BeforeExecute"); string commandName = beforeElement.Attribute("Name").Value; if (!string.IsNullOrEmpty(commandName)) { string commandArgs = beforeElement.Attribute("Args").Value; befExecute = new BeforeExecute { Name = commandName, Args = commandArgs }; } //升级后操作 aftExecute = null; XElement afterElement = root.Element("Expansion").Element("AfterExecute"); commandName = afterElement.Attribute("Name").Value; if (!string.IsNullOrEmpty(commandName)) { string commandArgs = afterElement.Attribute("Args").Value; aftExecute = new AfterExecute { Name = commandName, Args = commandArgs }; } }
public static int ExecuteNonQuery(object sender, CommandCollections commandCollections) { var command = commandCollections.Command; try { if (command.Connection.State != ConnectionState.Open) { command.Connection.Open(); } BeforeExecute?.Invoke(sender, new BeforeExecuteEventArgs() { Command = commandCollections.Command }); var now = DateTime.Now; int result = 0; foreach (var param in commandCollections.DataParameters) { command.Parameters.Clear(); foreach (var item in param) { var p = command.CreateParameter(); p.ParameterName = item.Key; p.Value = item.Value; command.Parameters.Add(p); } result += command.ExecuteNonQuery(); } string message = $"Sql:{command.CommandText}\n" + $"用时:{(DateTime.Now - now).TotalMilliseconds}毫秒。\n" + $"受影响行数:{result}"; #if DEBUG Debug.Print(message); #endif AfterExecute?.Invoke(sender, new AfterExecuteEventArgs() { Command = command, Message = message }); return(result); } catch (Exception ex) { Error?.Invoke(sender, new ErrorExecuteEventArgs() { Command = command, Message = ex.Message }); throw; } finally { if (command.Connection.State == ConnectionState.Open) { command.Connection.Close(); } } }
public override int Execute(DocumentsOperationContext context) { var count = _command.Execute(context); if (_retrieveDetails) { AfterExecute?.Invoke(_getDetails(_command)); } return(count); }
public override int Execute(DocumentsOperationContext context, TransactionOperationsMerger.RecordingState recording) { var count = _command.Execute(context, recording); if (_retrieveDetails) { AfterExecute?.Invoke(_getDetails(_command)); } return(count); }
public void Execute(EtlPipelineContext context) { BeforeExecute?.Invoke(); Waiter?.Wait(); foreach (var item in Input) { _receivedItems.Add(item); } AfterExecute?.Invoke(); }
public void Execute(XmlReader reader, XmlWriter writer, XsltTransformationArguments arguments) { if (_executed) { throw new InvalidOperationException("XsltPipelineStage has already been executed!"); } if (BeforeExecute != null) { BeforeExecute.Invoke(this, new XsltPipelineStageEventArgs(reader, writer, arguments)); } _Transformer.Transform(reader, writer, arguments); _executed = true; if (AfterExecute != null) { AfterExecute.Invoke(this, new XsltPipelineStageEventArgs(reader, writer, arguments)); } }
public static IEnumerable <T> Query <T>(object sender, IDbCommand command) { try { BeforeExecute?.Invoke(sender, new BeforeExecuteEventArgs() { Command = command }); var now = DateTime.Now; if (command.Connection.State != ConnectionState.Open) { command.Connection.Open(); } using (var reader = command.ExecuteReader()) { var result = reader.ToList_Expression <T>(); string message = $"Sql:{command.CommandText}\n" + $"用时:{(DateTime.Now - now).TotalMilliseconds}毫秒。"; #if DEBUG Debug.Print(message); #endif AfterExecute?.Invoke(sender, new AfterExecuteEventArgs() { Command = command, Message = message }); return(result); } } catch (Exception ex) { Error?.Invoke(sender, new ErrorExecuteEventArgs() { Command = command, Message = ex.Message }); throw; } }
/// <summary> /// Raises the <see cref="E:AfterSetup" /> event. /// </summary> /// <param name="args">The <see cref="EventArgs"/> instance containing the event data.</param> protected virtual void OnAfterExecute(AfterExecuteEventArgs args) => AfterExecute?.Invoke(this, args);
/// <summary> /// 添加版本信息到XML文件 /// </summary> /// <param name="xmlDoc">xml文档</param> /// <param name="downloadVersion">已下载版本节点</param> /// <param name="isMust">是否强制更新</param> /// <param name="description">更新描述信息</param> /// <param name="befExe">升级前操作</param> /// <param name="aftExe">升级后操作</param> private void AddVersionInfoToXML(XDocument xmlDoc, XElement downloadVersion, bool isMust, string description, BeforeExecute befExe, AfterExecute aftExe) { //添加版本节点 XElement versionElement = new XElement("Version", _downloadingVersion); versionElement.SetAttributeValue("IsMust", isMust); //添加描述信息 versionElement.SetAttributeValue("Description", description); downloadVersion.Add(versionElement); //添加扩展操作 if (befExe != null) { var befElement = xmlDoc.Root.Element("Expansion").Element("BeforeExecute"); befElement.Attribute("Name").Value = befExe.Name; befElement.Attribute("Args").Value = befExe.Args; } if (aftExe != null) { var afterElement = xmlDoc.Root.Element("Expansion").Element("AfterExecute"); afterElement.Attribute("Name").Value = aftExe.Name; afterElement.Attribute("Args").Value = aftExe.Args; } xmlDoc.Save(_xmlPath); }
private ExecutionResult Execute(InstructionPackage package) { BeforeExecute?.Invoke(this, package); _executingInstructionPackage = package; // check for breakpoints if (_breakpoints.Contains(package.InstructionAddress)) { _onBreakpoint?.Invoke(this, package); } // set the internal WZ register to an initial value based on whether this is an indexed instruction or not; // the instruction that runs may alter/set WZ itself. // (the value in WZ [sometimes known as MEMPTR in Z80 enthusiast circles] is only ever used to control the behavior of the BIT instruction) ushort wz = package.Instruction switch { var i when i.Source.IsAddressFromIndexAndOffset() => Registers[i.Source.AsWordRegister()], var i when i.Target.IsAddressFromIndexAndOffset() => Registers[i.Target.AsWordRegister()], _ => 0 }; wz = (ushort)(wz + package.Data.Argument1); Registers.WZ = wz; ExecutionResult result = package.Instruction.Microcode.Execute(this, package); if (result.Flags != null) { Registers.F = result.Flags.Value; } result.WaitStatesAdded = _previousWaitCycles; AfterExecute?.Invoke(this, result); return(result); } // execute an instruction directly (without the processor loop running), for example for directly testing instructions ExecutionResult IDebugProcessor.ExecuteDirect(byte[] opcode) { Memory.Untimed.WriteBytesAt(Registers.PC, opcode); InstructionPackage package = DecodeInstructionAtProgramCounter(); if (package == null) { throw new InstructionDecoderException("Supplied opcode sequence does not decode to a valid instruction."); } return(Execute(package)); } // execute an instruction directly (specified by mnemonic, so no decoding necessary) ExecutionResult IDebugProcessor.ExecuteDirect(string mnemonic, byte?arg1, byte?arg2) { if (!InstructionSet.InstructionsByMnemonic.TryGetValue(mnemonic, out Instruction instruction)) { throw new InstructionDecoderException("Supplied mnemonic does not correspond to a valid instruction"); } InstructionData data = new InstructionData() { Argument1 = arg1 ?? 0, Argument2 = arg2 ?? 0 }; InstructionPackage package = new InstructionPackage(instruction, data, Registers.PC); Registers.PC += package.Instruction.SizeInBytes; // simulate the decode cycle effect on PC return(Execute(package)); }
/// <summary> /// Executes the <see cref="RelayCommand"/> on the current command target. /// </summary> /// <param name="parameter"> /// Data used by the command. If the command does not require data to be passed, this object can be set to null. /// </param> public void Execute(object?parameter) { _execute !(parameter); AfterExecute?.Invoke(parameter); }
public void execute(SqlQuery aQuery, OnExecute onExecute, BeforeExecute onBefore, AfterExecute onAfterExecute) { using (SqlCommand Command = new SqlCommand(aQuery.Query, Connection)) { Command.Parameters.AddRange(aQuery.Parameters.ToArray()); Command.Transaction = Transaction.SqlTransaction; onBefore(Command); DateTime beforequery = DateTime.Now;; logger.Debug(String.Format(EXECUTING_QUERY, aQuery)); using (SqlDataReader aReader = Command.ExecuteReader()) { DateTime afterquery = DateTime.Now; logger.Debug(String.Format(QUERY, aQuery, (afterquery - beforequery).Milliseconds)); while (aReader.Read()) { onExecute(aReader); } } } onAfterExecute(); }
protected void OnAfterExecute(IMethodCallMessage methodCallMessage, object result) { AfterExecute?.Invoke(this, new AfterExecutionEventArgs(methodCallMessage, result)); }
public void execute(QueryEngine.Query.SqlQuery aQuery, OnExecute onExecute, BeforeExecute onBefore, AfterExecute onAfterExecute) { }
/// <summary> /// 下载新版本 /// </summary> /// <param name="repMessage">服务端返回的下载信息</param> public void DownloadVersion(ResponseMessage repMessage) { //写下载状态文件 using (StreamWriter sw = new StreamWriter(_downloadDir + "\\DownloadStatus.txt", false)) { sw.AutoFlush = true; sw.WriteLine("Downloading"); } //获取版本管理文件 XDocument xmlDoc = GetVersionXml(); XElement downloadVersion = xmlDoc.Root.Element("DownloadedVersions"); //如果在指定的时间内,下载未完成,向服务端发送消息 _downloadStatus = DownLoadStaus.Downloading; int period = (repMessage.heartTime - 1) * 60 * 1000;//间隔时间(毫秒) Timer timer = new Timer(new TimerCallback(SendDownloadingMessage), _downloadingVersion, period, period); //执行下载 string ip = repMessage.downloadIP; VersionInfo[] versions = repMessage.allVersion; int curBag = 0; int bagNum = versions.Length; NamedPipeServerHelper.Start(); NamedPipeServerHelper.Status = "Start"; try { //如果是采用ftp方式下载 if (ip.ToLower().Contains("ftp:")) { //按照服务端配置的格式解析下载地址 string[] ipAddress = Regex.Split(ip, "##", RegexOptions.IgnoreCase); ip = ipAddress[0]; string userName = null; string pw = null; if (ipAddress.Length > 1) { userName = ipAddress[1]; pw = ipAddress[2]; } FTPHelper ftp = new FTPHelper(userName, pw); foreach (VersionInfo v in versions) { NamedPipeServerHelper.BagInfo = string.Format("总共{0}个包,正在下载第{1}个包...", bagNum, ++curBag); _downloadingVersion = v.versionName; //下载更新文件配置信息 ftp.Download(ip, _downloadDir, _downloadingVersion + ".xml"); //获取文件信息 long size = 0; string description = ""; BeforeExecute befExe = null; AfterExecute aftExe = null; GetUpdateFileInfo(out size, out description, out befExe, out aftExe); //下载资源包 ftp.Download(ip, _downloadDir, _downloadingVersion + ".zip", size); //添加下载的版本信息到XML文件 AddVersionInfoToXML(xmlDoc, downloadVersion, v.isMust, description, befExe, aftExe); //解压文件 GenerateZip.ZipHelper.UnZip(_downloadDir + "\\" + _downloadingVersion + ".zip", _downloadDir + "\\TempDir\\" + _downloadingVersion); } } //如果是采用Http方式下载 else { foreach (VersionInfo v in versions) { NamedPipeServerHelper.BagInfo = string.Format("总共{0}个包,正在下载第{1}个包...", bagNum, ++curBag); _downloadingVersion = v.versionName; //下载更新文件配置信息 HttpHelper.Download(ip, _downloadDir, _downloadingVersion + ".xml"); //获取文件信息 long size = 0; string description = ""; BeforeExecute befExe = null; AfterExecute aftExe = null; GetUpdateFileInfo(out size, out description, out befExe, out aftExe); //下载资源包 HttpHelper.Download(ip, _downloadDir, _downloadingVersion + ".zip", size); //添加下载的版本信息到XML文件 AddVersionInfoToXML(xmlDoc, downloadVersion, v.isMust, description, befExe, aftExe); //解压文件 GenerateZip.ZipHelper.UnZip(_downloadDir + "\\" + _downloadingVersion + ".zip", _downloadDir + "\\TempDir\\" + _downloadingVersion); } } using (StreamWriter sw = new StreamWriter(_downloadDir + "\\DownloadStatus.txt", false)) { sw.AutoFlush = true; sw.WriteLine("Downloaded"); } NamedPipeServerHelper.Status = "End"; _downloadStatus = DownLoadStaus.Downloaded; OnDownloadCompleted(repMessage.maxVersion); //提示用户更新 UpdatePrompt(); } catch (Exception ex) { _loger.Error("DownloadVersion(ResponseMessage)方法:" + ex.Message); throw ex; } finally { if (timer != null) { timer.Dispose(); } NamedPipeServerHelper.Close(); } }
private void OnAfterExecute(IInvocation methodCall) { AfterExecute?.Invoke(this, methodCall); }
public ThreadManager <TAction> SetAfterExecuteAction(AfterExecute <TAction> afterExecuteAction) { _afterExecuteAction = afterExecuteAction; return(this); }
private void OnAfterExecute(MethodInfo methodCall) => AfterExecute?.Invoke(this, methodCall);