Managing Version-Controlled Items on a DeltaV Server
Enabling Version Control
Usually by default all items in the WebDAV repository are not under version control. The item actually behaves like a Class 2 item. To start creating versions you must call IResource.PutUnderVersionControl passing true as a parameter:
string license = "<?xml version='1.0' encoding='u...
WebDavSession session = new WebDavSession(license);
session.Credentials = new NetworkCredential("User1", "pwd");
IResource resource = session.OpenResource("http://server/sales.docx");
resource.PutUnderVersionControl(true);
During the call to PutUnderVersionControl server will create an initial version. The item will be in a checked-in state. If the item is under version control it always has at last one version in its versions list.
To disable version control call PutUnderVersionControl passing false as a parameter. Server will usually delete all item versions during this call.
Note that IT Hit WebDAV Server Engine has Engine.AutoPutUnderVersionControl property indicating if items must be put under version control explicitly. If this property is set to true the item will be automatically put under version control before the update.
Checking if Item is Being Version-Controlled
To check if item is under version control use IResource.IsVersionControlled method:
if(resource.IsVersionControlled())
MessageBox.Show("The item is being version controlled.");
else
MessageBox.Show("The item is not under version control.");
Listing Item Versions
Each file version implements IVersion interface that is inherited from IHierarchyItem and IItemContent interfaces. To get list of versions call IResource.GetVersions:
IResource resource = session.OpenResource("http://server/sales.docx");
IVersion[] versions = resource.GetVersions();
foreach (IVersion version in versions)
{
MessageBox.Show("Version Name: " + version.VersionName);
MessageBox.Show("Comment: " + version.Comment);
MessageBox.Show("Author: " + version.CreatorDisplayName);
MessageBox.Show("Created: " + version.CreationDate);
}
You can read version content and request properties as you usually do for resources but you cannot update content or properties (the only exceptions are comment and author, see example below).
IVersion version = session.OpenVersion("http://server/ sales.docx?version=2");
using (StreamReader sr = new StreamReader(version.GetReadStream()))
{
string versionContents = sr.ReadToEnd();
MessageBox.Show(versionContents);
}
Updating Version-Сontrolled Item
To allow modifications on a version-controlled item it must be first checked-out. If you would like to protect item from being modified by other users you will also lock the item:
IResource resource = session.OpenResource("http://server/sales.docx");
LockInfo lockInfo = resource.Lock(LockScope.Exclusive, false, "John Walter", TimeSpan.MaxValue);
resource.CheckOut(lockInfo.LockToken.LockToken);
resource.UpdateProperties(
new Property[] {new Property(new PropertyName("amount", "server"), "2")}, null, lockInfo.LockToken.LockToken);
IVersion version = resource.CheckIn(lockInfo.LockToken.LockToken);
resource.Unlock(lockInfo.LockToken.LockToken);
version.SetCommentAndAuthor("Props updated.", "John");
Note that IResource.CheckOut only allows modifications while new version is created during the call to IResource.CheckIn.
To find out if item is in a check-out state use IResource.IsCheckedOut property:
if (resource.IsCheckedOut())
MessageBox.Show("The item is checked-out.");
else
MessageBox.Show("The item is checked-in.");
Uncheck-out
If after making some item modifications you decide to cancel your updates you can call IResource.UnCheckOut. It will restore the pre-checkout state of the item:
IResource resource = session.OpenResource("http://server/sales.docx");
LockInfo lockInfo = resource.Lock(LockScope.Exclusive, false, "John Walter", TimeSpan.MaxValue);
resource.CheckOut(lockInfo.LockToken.LockToken);
//Modify resource content or properties here.
//....
resource.UnCheckOut(lockInfo.LockToken.LockToken);
resource.Unlock(lockInfo.LockToken.LockToken);
Reverting Item Content and Properties to a Specific Version
To revert item state to a specific version use IResource.UpdateToVersion:
IResource resource = session.OpenResource("http://server/sales.docx");
LockInfo lockInfo = resource.Lock(LockScope.Exclusive, false, "John Walter", TimeSpan.MaxValue);
IVersion version = session.OpenVersion(new Uri("http://server/ sales.docx?version=2"));
resource.UpdateToVersion(version, lockInfo.LockToken.LockToken);
resource.Unlock(lockInfo.LockToken.LockToken);
|