public IList <IDictionary <string, object> > Execute(ExecuteChangesRequest request, IList <string> properties) { var executeResponse = Execute(request); var executeResults = new List <IDictionary <string, object> >(); if (executeResponse != null && executeResponse.Length > 0) { executeResults.AddRange ( executeResponse.Select ( o => o.Property.Where ( p => properties.Contains ( p.propertyId, StringComparer.CurrentCultureIgnoreCase ) ).ToDictionary <PropertyType, string, object> ( p => p.propertyId, Utilities.GetPropertyValue ) ) ); } return(executeResults); }
public ChangeResponseType[] Execute(ExecuteChangesRequest request, bool adminOverride = false) { InitialiseToken(adminOverride); return(Service.ExecuteChanges(request)); }
public IList <IDictionary <string, object> > Execute(ExecuteChangesRequest request, string property) => Execute(request, new List <string> { property });
public bool RemoveDocumentAccess(Guid id, IList <string> removeUsers, ObjectStore objectStore = DefaultObjectStore, DocumentClass documentClass = DefaultDocumentClass) { var permissionsList = RetrieveDocumentAccess(id, objectStore, documentClass); var accessPermissions = removeUsers.Select ( u => permissionsList.FirstOrDefault ( kvp => kvp["GranteeName"].ToString().Equals(u, StringComparison.CurrentCultureIgnoreCase) ) ).Select(permissionsList.IndexOf).Where(i => i >= 0).Select ( userIndex => new DependentObjectType { classId = "AccessPermission", dependentAction = DependentObjectTypeDependentAction.Delete, dependentActionSpecified = true, originalIndex = userIndex, originalIndexSpecified = true } ).ToArray(); if (accessPermissions.Length == 0) { return(true); } var actionProperties = new List <ModifiablePropertyType> { new ListOfObject { propertyId = "Permissions", Value = accessPermissions } }; var updateRequest = new ExecuteChangesRequest { ChangeRequest = new[] { new ChangeRequestType { id = "1", Action = new ActionType[] { new UpdateAction() }, ActionProperties = actionProperties.ToArray(), TargetSpecification = new ObjectSpecification { objectStore = objectStore.GetDescription(), classId = documentClass.GetDescription(), objectId = id.ToString(DefaultIDFormat) } } }, refresh = true, refreshSpecified = true }; return(Execute(updateRequest, true).Length > 0); }
public bool AllowDocumentAccess(Guid id, IList <string> allowUsers, ObjectStore objectStore = DefaultObjectStore, DocumentClass documentClass = DefaultDocumentClass) { var accessProperties = new List <DependentObjectType>(); if (allowUsers != null) { accessProperties.AddRange(allowUsers.Select(allowUser => new DependentObjectType { classId = "AccessPermission", dependentAction = DependentObjectTypeDependentAction.Insert, dependentActionSpecified = true, Property = new PropertyType[] { new SingletonString { propertyId = "GranteeName", Value = allowUser }, new SingletonInteger32 { propertyId = "AccessType", Value = (int)AccessType.Allow, ValueSpecified = true }, new SingletonInteger32 { propertyId = "AccessMask", Value = (int)AccessLevel.WriteDocument, ValueSpecified = true }, new SingletonInteger32 { propertyId = "InheritableDepth", Value = 0, ValueSpecified = true } } }).ToList()); } var actionProperties = new List <ModifiablePropertyType> { new ListOfObject { propertyId = "Permissions", Value = accessProperties.ToArray() } }; var updateRequest = new ExecuteChangesRequest { ChangeRequest = new[] { new ChangeRequestType { id = "1", Action = new ActionType[] { new UpdateAction() }, ActionProperties = actionProperties.ToArray(), TargetSpecification = new ObjectSpecification { objectStore = objectStore.GetDescription(), classId = documentClass.GetDescription(), objectId = id.ToString(P8ContentEngine.DefaultIDFormat) } } }, refresh = true, refreshSpecified = true }; return(Execute(updateRequest, true).Length > 0); }
public Guid?CreateDocument(string name, byte[] content, IDictionary <string, object> properties = null, ObjectStore objectStore = P8ContentEngine.DefaultObjectStore, DocumentClass documentClass = P8ContentEngine.DefaultDocumentClass) { if (name == string.Empty) { throw new ArgumentException(nameof(name)); } if (name == null) { throw new ArgumentNullException(nameof(name)); } if (content == null) { throw new ArgumentNullException(nameof(content)); } properties = ResolveTitleAndMimeType(name, properties); var mimeType = properties.ContainsKey(MIME_TYPE) ? properties[MIME_TYPE] as string : MimeTypeUtility.DefaultType; var actionProperties = new List <ModifiablePropertyType> { new ListOfObject { propertyId = "ContentElements", Value = new[] { new DependentObjectType { classId = "ContentTransfer", dependentAction = DependentObjectTypeDependentAction.Insert, dependentActionSpecified = true, Property = new PropertyType[] { new SingletonString { propertyId = "ContentType", Value = mimeType }, new SingletonString { propertyId = "RetrievalName", Value = name }, new ContentData { propertyId = "Content", Value = new InlineContent { Binary = content } } } } } } }; if (properties != null) { actionProperties.AddRange(Utilities.GetPropertyCollection(properties)); } var executeRequest = new ExecuteChangesRequest { ChangeRequest = new[] { new ChangeRequestType { id = "1", Action = new ActionType[] { new CreateAction { classId = documentClass.GetDescription() }, new CheckinAction { autoClassify = true, autoClassifySpecified = true, checkinMinorVersion = true, checkinMinorVersionSpecified = true }, new PromoteVersionAction() }, ActionProperties = actionProperties.ToArray(), TargetSpecification = new ObjectReference { classId = "ObjectStore", objectStore = objectStore.GetDescription() } } }, refresh = true, refreshSpecified = true }; var createResults = Execute(executeRequest, "ID"); var id = (from cr in createResults.FirstOrDefault() where cr.Key.Equals("ID", StringComparison.CurrentCultureIgnoreCase) select cr.Value).FirstOrDefault(); if (id != null) { return(new Guid(id.ToString())); } return(null); }
public bool DeleteDocument(Guid id, bool allVersions, ObjectStore objectStore = DefaultObjectStore, DocumentClass documentClass = DefaultDocumentClass) { if (allVersions) { var deleteInfoRequest = new[] { new ObjectRequestType { SourceSpecification = new ObjectSpecification { objectStore = objectStore.GetDescription(), classId = documentClass.GetDescription(), objectId = id.ToString(DefaultIDFormat) }, PropertyFilter = new PropertyFilterType { maxRecursion = 1, maxRecursionSpecified = true, IncludeProperties = new[] { new FilterElementType { Value = "VersionSeries" } } } } }; var deleteInfoResponse = GetObjects(deleteInfoRequest); var series = (from responseProperty in (((SingleObjectResponse)deleteInfoResponse[0]).Object).Property where responseProperty.propertyId == "VersionSeries" select((SingletonObject)responseProperty).Value as ObjectValue).FirstOrDefault(); if (series != null) { id = new Guid(series.objectId); } else { throw new ApplicationException(string.Format("Could not retrieve the version series for {0}", id.ToString(P8ContentEngine.DefaultIDFormat))); } } var deleteRequest = new ExecuteChangesRequest { ChangeRequest = new[] { new ChangeRequestType { id = "1", Action = new ActionType[] { new DeleteAction() }, TargetSpecification = new ObjectSpecification { objectStore = objectStore.GetDescription(), classId = (allVersions) ? "VersionSeries" : documentClass.GetDescription(), objectId = id.ToString(P8ContentEngine.DefaultIDFormat) } } }, refresh = true, refreshSpecified = true }; var deleteResult = Execute(deleteRequest); return((deleteResult.Length > 0) && deleteResult[0].id == "1"); }
public bool CheckinDocument(Guid id, ObjectStore objectStore = DefaultObjectStore, DocumentClass documentClass = DefaultDocumentClass) { var checkinInfoRequest = new[] { new ObjectRequestType { SourceSpecification = new ObjectSpecification { objectStore = objectStore.GetDescription(), classId = documentClass.GetDescription(), objectId = id.ToString(DefaultIDFormat) }, PropertyFilter = new PropertyFilterType { maxRecursion = 1, maxRecursionSpecified = true, IncludeProperties = new[] { new FilterElementType { Value = "Reservation" } } } } }; var checkinInfoResponse = GetObjects(checkinInfoRequest); var reservation = (from responseProperty in (((SingleObjectResponse)checkinInfoResponse[0]).Object).Property where responseProperty.propertyId == "Reservation" select((SingletonObject)responseProperty).Value as ObjectValue).FirstOrDefault(); if (reservation != null) { id = new Guid(reservation.objectId); } var checkinRequest = new ExecuteChangesRequest { ChangeRequest = new[] { new ChangeRequestType { id = "1", Action = new ActionType[] { new CheckinAction { autoClassify = true, autoClassifySpecified = true, checkinMinorVersion = true, checkinMinorVersionSpecified = true }, new PromoteVersionAction() }, TargetSpecification = new ObjectReference { objectStore = objectStore.GetDescription(), classId = documentClass.GetDescription(), objectId = id.ToString(DefaultIDFormat) }, RefreshFilter = new PropertyFilterType { maxRecursion = 1, maxRecursionSpecified = true, IncludeProperties = new[] { new FilterElementType { Value = "VersionStatus" } } } } }, refresh = true, refreshSpecified = true }; var checkinResponse = Execute(checkinRequest); var versionStatus = (from responseProperty in checkinResponse[0].Property where responseProperty.propertyId == "VersionStatus" select responseProperty as SingletonInteger32).FirstOrDefault(); return(versionStatus != null && versionStatus.Value == (int)VersionStatus.Released); }
public Guid?CheckoutDocument(Guid id, ObjectStore objectStore = DefaultObjectStore, DocumentClass documentClass = DefaultDocumentClass) { var checkoutInfoRequest = new[] { new ObjectRequestType { SourceSpecification = new ObjectSpecification { objectStore = objectStore.GetDescription(), classId = documentClass.GetDescription(), objectId = id.ToString(DefaultIDFormat) }, PropertyFilter = new PropertyFilterType { maxRecursion = 1, maxRecursionSpecified = true, IncludeProperties = new[] { new FilterElementType { Value = "CurrentVersion" }, new FilterElementType { Value = "Reservation" } } } } }; var checkoutInfoResponse = GetObjects(checkoutInfoRequest); var reservation = (from responseProperty in (((SingleObjectResponse)checkoutInfoResponse[0]).Object).Property where responseProperty.propertyId == "Reservation" select((SingletonObject)responseProperty).Value as ObjectValue).FirstOrDefault(); if (reservation != null) { return(new Guid(reservation.objectId)); } var currentVersion = (from responseProperty in (((SingleObjectResponse)checkoutInfoResponse[0]).Object).Property where responseProperty.propertyId == "CurrentVersion" select((SingletonObject)responseProperty).Value as ObjectValue).FirstOrDefault(); if (currentVersion != null) { id = new Guid(currentVersion.objectId); } var executeRequest = new ExecuteChangesRequest { ChangeRequest = new[] { new ChangeRequestType { id = "1", Action = new ActionType[] { new CheckoutAction { reservationType = ReservationType.Exclusive, reservationTypeSpecified = true } }, TargetSpecification = new ObjectReference { objectStore = objectStore.GetDescription(), classId = documentClass.GetDescription(), objectId = id.ToString(DefaultIDFormat) }, RefreshFilter = new PropertyFilterType { maxRecursion = 1, maxRecursionSpecified = true, IncludeProperties = new[] { new FilterElementType { Value = "Reservation" } } } } }, refresh = true, refreshSpecified = true }; var checkoutResponse = Execute(executeRequest); reservation = (from responseProperty in checkoutResponse[0].Property where responseProperty.propertyId == "Reservation" select((SingletonObject)responseProperty).Value as ObjectValue).FirstOrDefault(); if (reservation != null) { return(new Guid(reservation.objectId)); } return(null); }
public bool UpdateDocument(Guid id, string name, byte[] content, IDictionary <string, object> properties = null, ObjectStore objectStore = DefaultObjectStore, DocumentClass documentClass = DefaultDocumentClass) { var updateContent = name != null && content != null; var updateProperties = properties != null && properties.Count > 0; if (!updateContent && !updateProperties) { throw new ArgumentException("Insufficient arguments provided (name, content and/or properties)"); } properties = ResolveTitleAndMimeType(name, properties); var mimeType = properties.ContainsKey(MIME_TYPE) ? properties[MIME_TYPE] as string : MimeTypeUtility.DefaultType; var reservationID = updateContent ? CheckoutDocument(id, objectStore, documentClass) : Guid.Empty; if (reservationID != null && reservationID != Guid.Empty) { id = reservationID.Value; } var actionProperties = new List <ModifiablePropertyType>(); if (updateContent) { actionProperties.Add(new ListOfObject { propertyId = "ContentElements", Value = new[] { new DependentObjectType { classId = "ContentTransfer", dependentAction = DependentObjectTypeDependentAction.Insert, dependentActionSpecified = true, Property = new PropertyType[] { new SingletonString { propertyId = "ContentType", Value = mimeType }, new ContentData { propertyId = "Content", Value = new InlineContent { Binary = content } } } } } }); } if (updateProperties) { actionProperties.AddRange(Utilities.GetPropertyCollection(properties)); } var updateRequest = new ExecuteChangesRequest { ChangeRequest = new[] { new ChangeRequestType { id = "1", Action = new ActionType[] { new UpdateAction() }, ActionProperties = actionProperties.ToArray(), TargetSpecification = new ObjectSpecification { objectStore = objectStore.GetDescription(), classId = documentClass.GetDescription(), objectId = id.ToString(DefaultIDFormat) } } }, refresh = true, refreshSpecified = true }; Execute(updateRequest); return((!updateContent) || CheckinDocument(id, objectStore, documentClass)); }