当前位置: 首页 > wzjs >正文

北京网站建设公司华网数字营销包括哪六种方式

北京网站建设公司华网,数字营销包括哪六种方式,网站功能模块设计,ppt模板免费下载整套什么是事务机制 首先,什么是事务机制。软件事务机制是指一种在软件系统中用于管理一系列操作的方法,这些操作要么全部成功完成,要么全部失败,不会出现部分完成的情况。事务机制确保了数据的一致性和完整性,特别是在并…

什么是事务机制

首先,什么是事务机制。软件事务机制是指一种在软件系统中用于管理一系列操作的方法,这些操作要么全部成功完成,要么全部失败,不会出现部分完成的情况。事务机制确保了数据的一致性和完整性,特别是在并发操作和系统故障的情况下。以下是软件事务机制的一些关键特征:
原子性(Atomicity):事务中的所有操作要么全部完成,要么全部不发生。如果事务中的任何一个操作失败,整个事务都会回滚到开始前的状态。
一致性(Consistency):事务必须使数据库从一个一致性状态转移到另一个一致性状态。在事务开始和结束时,数据库的数据完整性约束必须保持不变。
隔离性(Isolation):并发执行的事务彼此之间应该是隔离的,一个事务的执行不应该被其他事务干扰。这防止了事务之间的交互导致数据不一致。
持久性(Durability):一旦事务提交,它对系统的影响应该是永久性的。即使发生系统故障,事务的结果也应该被保留。

Revit 的事务 Transaction

从官方文档中可以看到 Revit 和事务相关的类为 Transaction,这个类的关键接口有 Start、Commit 和 Rollback。
在这里插入图片描述
在 Revit 中是需要显式得调用 Start,然后在操作完成后进行 Commit,或者操作失败后调用 Rollback。
官方例子:

public void CreatingSketch(UIApplication uiApplication)
{Autodesk.Revit.DB.Document document = uiApplication.ActiveUIDocument.Document;Autodesk.Revit.ApplicationServices.Application application = uiApplication.Application;// Create a few geometry lines. These lines are transaction (not in the model),// therefore they do not need to be created inside a document transaction.XYZ Point1 = XYZ.Zero;XYZ Point2 = new XYZ(10, 0, 0);XYZ Point3 = new XYZ(10, 10, 0);XYZ Point4 = new XYZ(0, 10, 0);Line geomLine1 = Line.CreateBound(Point1, Point2);Line geomLine2 = Line.CreateBound(Point4, Point3);Line geomLine3 = Line.CreateBound(Point1, Point4);// This geometry plane is also transaction and does not need a transactionXYZ origin = XYZ.Zero;XYZ normal = new XYZ(0, 0, 1);Plane geomPlane = Plane.CreateByNormalAndOrigin(normal, origin);// In order to a sketch plane with model curves in it, we need// to start a transaction because such operations modify the model.// All and any transaction should be enclosed in a 'using'// block or guarded within a try-catch-finally blocks// to guarantee that a transaction does not out-live its scope.using (Transaction transaction = new Transaction(document)){if (transaction.Start("Create model curves") == TransactionStatus.Started){// Create a sketch plane in current documentSketchPlane sketch = SketchPlane.Create(document,geomPlane);// Create a ModelLine elements using the geometry lines and sketch planeModelLine line1 = document.Create.NewModelCurve(geomLine1, sketch) as ModelLine;ModelLine line2 = document.Create.NewModelCurve(geomLine2, sketch) as ModelLine;ModelLine line3 = document.Create.NewModelCurve(geomLine3, sketch) as ModelLine;// Ask the end user whether the changes are to be committed or notTaskDialog taskDialog = new TaskDialog("Revit");taskDialog.MainContent = "Click either [OK] to Commit, or [Cancel] to Roll back the transaction.";TaskDialogCommonButtons buttons = TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Cancel;taskDialog.CommonButtons = buttons;if (TaskDialogResult.Ok == taskDialog.Show()){// For many various reasons, a transaction may not be committed// if the changes made during the transaction do not result a valid model.// If committing a transaction fails or is canceled by the end user,// the resulting status would be RolledBack instead of Committed.if (TransactionStatus.Committed != transaction.Commit()){TaskDialog.Show("Failure", "Transaction could not be committed");}}else{transaction.RollBack();}}}
}

Revit 事务机制可能的实现

大型软件的实现肯定是非常复杂的,所以这里只是一个猜测。实际情况和下面的肯定存在巨大差异。
为了支持Undo和Redo功能,我们需要在Transaction类中添加一些额外的逻辑来记录操作的历史,并在需要时回滚或重做这些操作。以下是一个简化的C#实现,其中包含了基本的Undo和Redo功能:

using System;
using System.Collections.Generic;
public class Transaction
{private bool isStarted;private Stack<Action> undoStack;private Stack<Action> redoStack;public Transaction(){undoStack = new Stack<Action>();redoStack = new Stack<Action>();}public void Start(string transactionName){if (isStarted)throw new InvalidOperationException("Transaction has already started.");isStarted = true;Console.WriteLine($"Transaction '{transactionName}' started.");}public void Commit(){if (!isStarted)throw new InvalidOperationException("No transaction has been started.");isStarted = false;redoStack.Clear(); // Clear the redo stack because a new commit creates a new point of no returnConsole.WriteLine("Transaction committed.");}public void Rollback(){if (!isStarted)throw new InvalidOperationException("No transaction has been started.");while (undoStack.Count > 0){undoStack.Pop().Invoke(); // Execute all undo actions}isStarted = false;Console.WriteLine("Transaction rolled back.");}public void AddAction(Action action, Action undoAction){if (!isStarted)throw new InvalidOperationException("No transaction has been started. Start a transaction before adding actions.");undoStack.Push(undoAction); // Push the undo action onto the stackaction.Invoke(); // Execute the action}public void Undo(){if (undoStack.Count == 0)throw new InvalidOperationException("No actions to undo.");Action undoAction = undoStack.Pop();undoAction.Invoke(); // Execute the undo actionredoStack.Push(() => undoAction); // Push the inverse action onto the redo stack}public void Redo(){if (redoStack.Count == 0)throw new InvalidOperationException("No actions to redo.");Action redoAction = redoStack.Pop();redoAction.Invoke(); // Execute the redo actionundoStack.Push(() => redoAction); // Push the inverse action onto the undo stack}
}
// Example usage:
class Program
{static void Main(string[] args){Transaction transaction = new Transaction();transaction.Start("Sample Transaction");// Add actions with corresponding undo actionstransaction.AddAction(() => Console.WriteLine("Action 1 performed."),() => Console.WriteLine("Action 1 undone."));transaction.AddAction(() => Console.WriteLine("Action 2 performed."),() => Console.WriteLine("Action 2 undone."));// Commit the transactiontransaction.Commit();// Undo the last actiontransaction.Undo();// Redo the last actiontransaction.Redo();// Rollback the transaction (undo all actions)transaction.Rollback();}

}
在这个例子中,Transaction类有两个栈:undoStack用于存储撤销操作,redoStack用于存储重做操作。每个操作都有一个对应的撤销操作,它们一起被添加到事务中。
AddAction方法用于添加操作和对应的撤销操作到事务中。Undo和Redo方法用于执行撤销和重做操作,并相应地更新栈。
在Main方法中,我们创建了一个Transaction实例,并添加了两个操作。然后我们提交事务,执行撤销和重做操作,并最后回滚事务。
请注意,这个示例是为了演示目的而简化的。在实际应用中,操作可能涉及更复杂的状态管理,并且需要处理并发和异常情况。此外,撤销和重做操作可能需要更精细的控制,例如操作特定的对象属性或恢复到特定的状态。

**注:**思想来源于博主,部分内容来自AI

http://www.dtcms.com/wzjs/453020.html

相关文章:

  • 武汉公司网站制作武汉大学人民医院洪山院区
  • 建设施工合同范本seo服务如何收费
  • 新北网站建设百度竞价
  • 内部网站 备案百度收录网址提交
  • 包头索易网站建设深圳优化服务
  • 如何设计公司官网站典型十大优秀网络营销案例
  • 哪个网站做美食好一点网络营销的内涵
  • 优秀校园景观设计网站整体优化
  • 桦甸市建设局网站策划方案怎么做
  • wordpress缩略图的质量性能优化工具
  • 平台网站做等级保护测评百度seo教程视频
  • 漯河北京网站建设网络营销推广方案模板
  • 沧州网站建设运营公司2022年关键词排名
  • 北京做网站开发公司云南网络推广服务
  • 个人怎么注册小微企业宁波免费建站seo排名
  • 一级域名的免费网站抚顺seo
  • 域名哪个网站续费青岛百度seo
  • 深圳低价做网站长春网站优化
  • 深圳代办公司哪家好廊坊seo排名霸屏
  • 日本 男女做网站如何开网站呢
  • wordpress怎么建立二级菜单seo研究中心qq群
  • 重庆网站建设维护网络营销策划推广方案
  • 人力外包系统杭州seo顾问
  • 织梦修改网站标题网络广告图片
  • 广东微信网站制作公司哪家好域名交易
  • 网站系统建设合同范本2023国内外重大新闻事件10条
  • 哪些网站专门做细胞的国际外贸网络交易平台
  • wordpress 自媒体平台网站关键词优化的价格
  • 杭州企业云网站建设宣传推广计划怎么写
  • 素材网站 模板看啥网一个没有人工干预的网