private void initializeContext() { ContextFactory contextFactory = ContextFactory.Instance; serviceContext = contextFactory.NewContext(); RepositoryIdentity repoId = new RepositoryIdentity(); RepositoryIdentity repositoryIdentity = new RepositoryIdentity(DefaultRepository, UserName, Password, ""); serviceContext.AddIdentity(repositoryIdentity); ContentTransferProfile contentTransferProfile = new ContentTransferProfile(); contentTransferProfile.TransferMode = ContentTransferMode.MTOM; contentTransferProfile.Geolocation = "Pleasanton"; serviceContext.SetProfile(contentTransferProfile); PropertyProfile propertyProfile = new PropertyProfile(); propertyProfile.FilterMode = PropertyFilterMode.ALL_NON_SYSTEM; serviceContext.SetProfile(propertyProfile); if (SecondaryRepository != null) { RepositoryIdentity repoId1 = new RepositoryIdentity(); repoId1.RepositoryName = SecondaryRepository; repoId1.UserName = UserName; repoId1.Password = Password; serviceContext.AddIdentity(repoId1); } }
public DataPackage CreateWithContentModifyContext(String filePath) { if (!File.Exists(filePath)) { throw new Exception("Test file: " + filePath + " does not exist"); } ContentTransferProfile transferProfile = new ContentTransferProfile(); transferProfile.TransferMode = ContentTransferMode.BASE64; Console.WriteLine("Modified service context: changed content transfer mode to BASE64 and Geolocation to 'Pleasanton'"); transferProfile.Geolocation = "Pleasanton"; DemoServiceContext.SetProfile(transferProfile); ObjectIdentity objIdentity = new ObjectIdentity(DefaultRepository); DataObject dataObject = new DataObject(objIdentity, "dm_document"); PropertySet properties = dataObject.Properties; properties.Set("object_name", "MyImage"); properties.Set("title", "MyImage"); properties.Set("a_content_type", "gif"); dataObject.Contents.Add(new FileContent(Path.GetFullPath(filePath), "gif")); OperationOptions operationOptions = null; return(objectService.Create(new DataPackage(dataObject), operationOptions)); }
public DfsContext(IDfsConfiguration dfsConfiguration) { this.dfsConfiguration = dfsConfiguration; serviceFactory = ServiceFactory.Instance; var contextFactory = ContextFactory.Instance; serviceContext = contextFactory.NewContext(); var repositoryIdentity = new RepositoryIdentity(dfsConfiguration.Repository, dfsConfiguration.UserName, dfsConfiguration.Password, string.Empty); serviceContext.AddIdentity(repositoryIdentity); var contentTransferProfile = new ContentTransferProfile { TransferMode = ContentTransferMode.MTOM }; serviceContext.SetProfile(contentTransferProfile); // Setting the filter to ALL can cause errors if the DataObject // passed to the operation contains system properties, so to be safe // set the filter to ALL_NON_SYSTEM unless you explicitly want to update // a system property var propertyProfile = new PropertyProfile { FilterMode = PropertyFilterMode.ALL_NON_SYSTEM }; serviceContext.SetProfile(propertyProfile); serviceContext.SetRuntimeProperty("USER_TRANSACTION_HINT", "TRANSACTION_REQUIRED"); }
private static IServiceContext createContext(String repository, String userName, String password) { Console.Out.WriteLine("Creating new empty IServiceContext instance..."); //build context factory and an empty context ContextFactory cf = ContextFactory.Instance; IServiceContext context = cf.NewContext(); Console.Out.WriteLine("Creating new repository identity..."); //create a repository ID and seed it with the login credentials RepositoryIdentity repoIdent = new RepositoryIdentity(repository, userName, password, ""); Console.Out.WriteLine("Adding repository ID into IServiceContext object..."); //seed the IServiceContext with the Repository ID context.AddIdentity(repoIdent); ContentTransferProfile ctp = new ContentTransferProfile(); ctp.TransferMode = ContentTransferMode.BASE64; context.SetProfile(ctp); return(context); }
public FileInfo GetWithContent(ObjectIdentity objectIdentity, String geoLoc, ContentTransferMode transferMode, String objectID) { try { // Console.WriteLine("GetWithContent"); //ObjectId objectId = new ObjectId(objectID); //ObjectIdentity objectIdent = new ObjectIdentity(objectId, objectIdentity.RepositoryName); //ObjectIdentitySet objectIdentitySet = new ObjectIdentitySet(objectIdent); //DataPackage dataPackageas = objectService.Get(objectIdentitySet, null); ContentTransferProfile transferProfile = new ContentTransferProfile(); transferProfile.Geolocation = geoLoc; transferProfile.TransferMode = transferMode; DemoServiceContext.SetProfile(transferProfile); ContentProfile contentProfile = new ContentProfile(); contentProfile.FormatFilter = FormatFilter.ANY; contentProfile.UrlReturnPolicy = UrlReturnPolicy.PREFER; OperationOptions operationOptions = new OperationOptions(); operationOptions.ContentProfile = contentProfile; operationOptions.SetProfile(contentProfile); ObjectIdentitySet objectIdSet = new ObjectIdentitySet(objectIdentity); List <ObjectIdentity> objIdList = objectIdSet.Identities; objIdList.Add(objectIdentity); DataPackage dataPackage = objectService.Get(objectIdSet, operationOptions); DataObject dataObject = dataPackage.DataObjects[0]; Content resultContent = dataObject.Contents[0]; String contentClassName = resultContent.GetType().FullName; //Console.WriteLine("Returned content as type " + contentClassName); if (contentClassName.Equals("Emc.Documentum.FS.DataModel.Core.Content.UrlContent")) { UrlContent urlContent = (UrlContent)resultContent; // Console.WriteLine("Content ACS URL is: " + (urlContent.Url)); } if (resultContent.CanGetAsFile()) { FileInfo fileInfo = resultContent.GetAsFile(); return(fileInfo); //Console.WriteLine("Got content as file " + fileInfo.FullName); } else if (contentClassName.Equals("Emc.Documentum.FS.DataModel.Core.Content.UcfContent")) { UcfContent ucfContent = (UcfContent)resultContent; // Console.WriteLine("Got content as file " + ucfContent.LocalFilePath); } return(null); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); throw ex; } }
public DataObject GetWithContent(ObjectIdentity objectIdentity, String geoLoc, ContentTransferMode transferMode) { ContentTransferProfile transferProfile = new ContentTransferProfile(); transferProfile.Geolocation = geoLoc; transferProfile.TransferMode = transferMode; DemoServiceContext.SetProfile(transferProfile); ContentProfile contentProfile = new ContentProfile(); contentProfile.FormatFilter = FormatFilter.ANY; contentProfile.UrlReturnPolicy = UrlReturnPolicy.PREFER; OperationOptions operationOptions = new OperationOptions(); operationOptions.ContentProfile = contentProfile; operationOptions.SetProfile(contentProfile); ObjectIdentitySet objectIdSet = new ObjectIdentitySet(); List<ObjectIdentity> objIdList = objectIdSet.Identities; objIdList.Add(objectIdentity); DataPackage dataPackage = objectService.Get(objectIdSet, operationOptions); DataObject dataObject = dataPackage.DataObjects[0]; Content resultContent = dataObject.Contents[0]; String contentClassName = resultContent.GetType().FullName; Console.WriteLine("Returned content as type " + contentClassName); if (contentClassName.Equals("Emc.Documentum.FS.DataModel.Core.Content.UrlContent")) { UrlContent urlContent = (UrlContent)resultContent; Console.WriteLine("Content ACS URL is: " + (urlContent.Url)); } if (resultContent.CanGetAsFile()) { FileInfo fileInfo = resultContent.GetAsFile(); Console.WriteLine("Got content as file " + fileInfo.FullName); } else if (contentClassName.Equals("Emc.Documentum.FS.DataModel.Core.Content.UcfContent")) { UcfContent ucfContent = (UcfContent)resultContent; Console.WriteLine("Got content as file " + ucfContent.LocalFilePath); } return dataObject; }
public DataPackage CreateWithContentModifyContext(String filePath) { if (!File.Exists(filePath)) { throw new Exception("Test file: " + filePath + " does not exist"); } ContentTransferProfile transferProfile = new ContentTransferProfile(); transferProfile.TransferMode = ContentTransferMode.BASE64; Console.WriteLine("Modified service context: changed content transfer mode to BASE64 and Geolocation to 'Pleasanton'"); transferProfile.Geolocation = "Pleasanton"; DemoServiceContext.SetProfile(transferProfile); ObjectIdentity objIdentity = new ObjectIdentity(DefaultRepository); DataObject dataObject = new DataObject(objIdentity, "dm_document"); PropertySet properties = dataObject.Properties; properties.Set("object_name", "MyImage"); properties.Set("title", "MyImage"); properties.Set("a_content_type", "gif"); dataObject.Contents.Add(new FileContent(Path.GetFullPath(filePath), "gif")); OperationOptions operationOptions = null; return objectService.Create(new DataPackage(dataObject), operationOptions); }