Update a file on a serverside extension
Hi all!
I'm trying to update the content of a file using server api. I've read the thread link to the discussion I found that they use IFIleContentManager and FileSystemCore to store the content in the file. But these classes are from client api. It is possibile to use them on the serverside? Or, are there any server version of these classes? In my code I've tried to do this but it doesn't work serverVersionedContentService.fetchContent(file, hash, out); byte[] bytes = out.toByteArray(); //some modifics occurs on bytes IFileItem modifiedFile = (IFileItem) file.getWorkingCopy(); contentHashCode = ContentHash.valueOf(new ByteArrayInputStream(bytes)); ByteArrayInputStream inStream = new ByteArrayInputStream(bytes); serverVersionedContentService.storeContentNoProperties(contentHashCode, bytes.length, null, inStream); VersionedContent vc = ScmFactory.eINSTANCE.createVersionedContent(); vc.setHash(contentHashCode); vc.setPredecessorHint((ContentHash)null); vc.setSize(bytes.length); modifiedFile.setContent(vc); ICommitParameter parm = ICommitParameter.FACTORY.create(singleChangeSet); parm.addItemToSave(file); this.getScmService().batchCommit(workspaceHandle, new ICommitParameter[]{parm}, null, null, null); this give me the errore that a fileItem cannot get the content from a VersionedContent but just from a FileContent what can I do? Any suggestion? Thanks in advance |
Accepted answer
If the server won't take a VersionedContent and wants a FileContent, couldn't you just create one?
FileContent content = FilesystemFactory.eINSTANCE.createFileContent(); Marco Gianfico selected this answer as the correct answer
Comments
Marco Gianfico
commented Sep 16 '14, 3:44 a.m.
That's right, but how can I fill it if I cannot use IFileContentManager on the server side?
Marco Gianfico
commented Sep 16 '14, 6:02 a.m.
Thanks Remy,
|
2 other answers
For whom is interested in on server api does not provide the method setContent for a FileContent that on the client side is provided by FileContentManager.setContent().
So you have manually to set hash, predecessorhint, size, characterencoding, ld count and ldsetting through FileContent set methods. A snippet of code that can be useful: VersionedContent newContent = ..//createcontent through ServerVersionedContentService.storeContent(...) FileContent c = FilesystemFactory.eINSTANCE.createFileContent(); c.setHash(newContent.getHash()); c.setPredecessorHint(newContent.getPredecessorHint()); c.setSize(b.length);//oppure fileContent.getSize() c.setCharacterEncoding(fileContent.getCharacterEncoding()); FileContentProperties context = new FileContentProperties(fileContent); c.setLineDelimiterCount(context.getLineDelimiterCount()); c.setLineDelimiterSetting(ld.dbValue()) IFileItem modifiedFile = (IFileItem) file.getWorkingCopy(); modifiedFile.setContent((IFileContent) c); |
Marco,
my colleague Kevin Eifinger describes a very elegant solution to modifying files directly on a stream with server side code. You can find the links in Ralph Schoons Blog. Is this what you are looking for? Then please mark the answer as accepted. - Arne Comments
Marco Gianfico
commented Sep 15 '14, 5:42 a.m.
The fact is the he uses IFileContentManager, FileSystemCore and ScmPlatform that are from the client api. In my little experience in rtc development i never figured out how to import client classes in a server side environment.
|
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.
Comments
the real problem is to set the content of the file on the serverside.
with the help of the class IServerSideVersionedContentService we are able to get a VersionedContent or also an IVersionedContent (the superclass) but we aren't able to put this IVersionedContent in a IFileContent (it's a sublcass of IVersionedContent), and the poor IFileItem can just take a IFileContent through the method setContent