/// <summary> /// Creates marker for package. /// </summary> /// <param name="session">The session.</param> /// <param name="package">The package.</param> /// <returns>Package marker</returns> public static PackageMarker CreateForPackage(Session session, Package package) { var result = new PackageMarker(session) { ApplicationName = package.ApplicationName, SenderNodeId = package.SenderNodeId, RecipientNodeId = package.RecipientNodeId, PackageId = package.PackageId, PackageType = package.PackageType, PackageDateTime = package.PackageDateTime.ToUniversalTime(), UserName = package.UserName }; if (package.PackageType == PackageType.Snapshot) { var recipient = ReplicationNode.FindNode(package.Session, result.RecipientNodeId); var sender = ReplicationNode.GetCurrentNode(package.Session); var num = XafDeltaModule.Instance.RoutingType == RoutingType.BroadcastRouting ? sender.LastSavedPackageNumber : recipient.LastSavedPackageNumber; if (recipient != null) { result.LastSavedPackageNumber = num; } } return(result); }
/// <summary> /// Builds the error text. /// </summary> /// <param name="propertyName">Name of the property.</param> /// <param name="marker">The marker.</param> /// <returns>Error text</returns> private string buildErrorText(string propertyName, PackageMarker marker) { var actual = GetType().GetProperty(propertyName).GetValue(this, null); var expected = marker.GetType().GetProperty(propertyName).GetValue(marker, null); var result = (expected.Equals(actual) ? "" : string.Format(Localizer.InvalidPackageProp, actual, expected, propertyName)); return(result); }
/// <summary> /// Verifies the marker. /// </summary> /// <param name="session">The session.</param> /// <param name="errorText">The error text.</param> /// <returns><c>true</c> if marker is valid; otherwise <c>false</c></returns> private bool verifyMarker(Session session, out string errorText) { // create new marker var marker = PackageMarker.GetInstance(session, this); var exceptionText = ""; var propNames = new[] { "ApplicationName", "SenderNodeId", "RecipientNodeId", "PackageId" }; propNames.ToList().ForEach(x => exceptionText += buildErrorText(x, marker)); errorText = exceptionText; return(string.IsNullOrEmpty(errorText)); }
/// <summary> /// Imports from bytes. /// </summary> /// <param name="objectSpace">The package storage object space.</param> /// <param name="fileName">Name of the file.</param> /// <param name="data">The data.</param> /// <returns>Imported package</returns> public static Package ImportFromMdbBytes(IObjectSpace objectSpace, string fileName, byte[] data) { var result = Parse(objectSpace, fileName); result.PackageData = data; // restore package attributes from marker using (result.UnitOfWork) { var marker = PackageMarker.GetInstance(result.unitOfWork, result); if (marker != null) { result.PackageDateTime = marker.PackageDateTime; result.UserName = marker.UserName; } result.CloseUnitOfWork(false); } return(result); }
/// <summary> /// Imports from bytes. /// </summary> /// <param name="objectSpace">The package storage object space.</param> /// <param name="fileName">Name of the file.</param> /// <param name="data">The data.</param> /// <returns>Imported package</returns> public static Package ImportFromBytes(IObjectSpace objectSpace, string fileName, byte[] data) { var result = Parse(objectSpace, fileName); var packer = XafDeltaModule.Instance.PackService; result.PackageData = packer.UnpackBytes(data, result.SenderNodeId); // restore package attributes from marker using (result.UnitOfWork) { var marker = PackageMarker.GetInstance(result.unitOfWork, result); if (marker != null) { result.PackageDateTime = marker.PackageDateTime; result.UserName = marker.UserName; } result.CloseUnitOfWork(false); } return(result); }
/// <summary> /// Creates marker for package. /// </summary> /// <param name="session">The session.</param> /// <param name="package">The package.</param> /// <returns>Package marker</returns> public static PackageMarker CreateForPackage(Session session, Package package) { var result = new PackageMarker(session) { ApplicationName = package.ApplicationName, SenderNodeId = package.SenderNodeId, RecipientNodeId = package.RecipientNodeId, PackageId = package.PackageId, PackageType = package.PackageType, PackageDateTime = package.PackageDateTime.ToUniversalTime(), UserName = package.UserName }; if(package.PackageType == PackageType.Snapshot) { var recipient = ReplicationNode.FindNode(package.Session, result.RecipientNodeId); var sender = ReplicationNode.GetCurrentNode(package.Session); var num = XafDeltaModule.Instance.RoutingType == RoutingType.BroadcastRouting ? sender.LastSavedPackageNumber : recipient.LastSavedPackageNumber; if (recipient != null) result.LastSavedPackageNumber = num; } return result; }
/// <summary> /// Builds the error text. /// </summary> /// <param name="propertyName">Name of the property.</param> /// <param name="marker">The marker.</param> /// <returns>Error text</returns> private string buildErrorText(string propertyName, PackageMarker marker) { var actual = GetType().GetProperty(propertyName).GetValue(this, null); var expected = marker.GetType().GetProperty(propertyName).GetValue(marker, null); var result = (expected.Equals(actual) ? "" : string.Format(Localizer.InvalidPackageProp, actual, expected, propertyName)); return result; }