private void Sync() { TransactWithCentralOptions transact = new TransactWithCentralOptions(); SynchLockCallback transCallBack = new SynchLockCallback(); transact.SetLockCallback(transCallBack); SynchronizeWithCentralOptions syncset = new SynchronizeWithCentralOptions(); RelinquishOptions relinquishoptions = new RelinquishOptions(true) { CheckedOutElements = true }; syncset.SetRelinquishOptions(relinquishoptions); OpenDocument.SynchronizeWithCentral(transact, syncset); }
//与中心模型同步操作代码展示 #region public void SyncWithRelinquishing(Document doc) { TransactWithCentralOptions transOpts = new TransactWithCentralOptions(); SynchLockCallback transCallBack = new SynchLockCallback(); transOpts.SetLockCallback(transCallBack); SynchronizeWithCentralOptions syncOpts = new SynchronizeWithCentralOptions(); RelinquishOptions relinquishOpts = new RelinquishOptions(true); syncOpts.SetRelinquishOptions(relinquishOpts); syncOpts.SaveLocalAfter = false; syncOpts.Comment = "User has already done something"; try { doc.SynchronizeWithCentral(transOpts, syncOpts); } catch (Exception e) { TaskDialog.Show("Synchronize Failed", e.Message); } }
public void Execute(UIApplication app) { if (App.docdict.Keys.Count == 0) { return; } TransactWithCentralOptions transact = new TransactWithCentralOptions(); SynchLockCallback transCallBack = new SynchLockCallback(); transact.SetLockCallback(transCallBack); SynchronizeWithCentralOptions syncset = new SynchronizeWithCentralOptions(); RelinquishOptions relinquishoptions = new RelinquishOptions(true) { CheckedOutElements = true }; syncset.SetRelinquishOptions(relinquishoptions); App.running = true; if (relinquish) { foreach (Document doc in App.docdict.Keys) { try { WorksharingUtils.RelinquishOwnership(doc, relinquishoptions, transact); } catch { } } relinquish = false; } if (sync) { if (App.Dismiss()) { sync = false; App.running = false; return; } app.Application.FailuresProcessing += FailureProcessor; bool syncfailed = false; foreach (Document doc in App.docdict.Keys) { try { if (docdict[doc]) { doc.SynchronizeWithCentral(transact, syncset); app.Application.WriteJournalComment("AutoSync", true); } } catch { syncfailed = true; } } app.Application.FailuresProcessing -= FailureProcessor; if (syncfailed) { countdown -= retrysync; } sync = false; } if (close) { if (App.Dismiss()) { App.running = false; close = false; return; } bool closelast = false; string activepathname = app.ActiveUIDocument.Document.PathName; List <Document> docsdeletelist = new List <Document>(); foreach (Document doc in App.docdict.Keys) { if (activepathname == doc.PathName) { closelast = true; } else { docsdeletelist.Add(doc); } } foreach (Document doc in docsdeletelist) { try { doc.Close(false); } catch { } } if (closelast) { RevitCommandId closeDoc = RevitCommandId.LookupPostableCommandId(PostableCommand.Close); app.PostCommand(closeDoc); } close = false; countdown = 0; } App.running = false; transact.Dispose(); syncset.Dispose(); relinquishoptions.Dispose(); }