Esempio n. 1
0
        public async Task <NodeEntry> UploadNewVersionComponent(string nodeId, string componentId, byte[] component, string componentName, string mimeType)
        {
            var componentEntryBeforeUpload = await _alfrescoHttpClient.GetNodeInfo(componentId);

            string newName = $"{IdGenerator.GenerateId()}{ System.IO.Path.GetExtension(componentName) }";

            var body = new NodeBodyUpdate();

            if (System.IO.Path.GetExtension(componentEntryBeforeUpload?.Entry?.Name) != System.IO.Path.GetExtension(componentName))
            {
                try
                {
                    var nameSplit = componentEntryBeforeUpload?.Entry?.Name?.Split(".");
                    newName = $"{nameSplit[0]}{System.IO.Path.GetExtension(componentName)}";
                }
                catch
                {
                    newName = $"{IdGenerator.GenerateId()}{ System.IO.Path.GetExtension(componentName) }"; // Default name if chanhing extension fails
                }
            }

            // Name must be included in uploading the content. Otherwise Alfresco will not update content properties
            await _alfrescoHttpClient.UploadContent(new FormDataParam(component, newName, "filedata", mimeType), ImmutableList <Parameter> .Empty
                                                    .Add(new Parameter("filename", newName, ParameterType.GetOrPost))
                                                    .Add(new Parameter("destination", "null", ParameterType.GetOrPost))
                                                    .Add(new Parameter("uploaddirectory", "", ParameterType.GetOrPost))
                                                    .Add(new Parameter("createdirectory", "true", ParameterType.GetOrPost))
                                                    .Add(new Parameter("majorVersion", "true", ParameterType.GetOrPost))
                                                    .Add(new Parameter("username", "null", ParameterType.GetOrPost))
                                                    .Add(new Parameter("overwrite", "true", ParameterType.GetOrPost))
                                                    .Add(new Parameter("thumbnails", "null", ParameterType.GetOrPost))
                                                    .Add(new Parameter("updatenameandmimetype", "true", ParameterType.GetOrPost))
                                                    .Add(new Parameter("updateNodeRef", $"workspace://SpacesStore/{componentId}", ParameterType.GetOrPost)));

            var componentPID = await GenerateComponentPID(nodeId, "/", GeneratePIDComponentType.Component);

            await _alfrescoHttpClient.UpdateNode(componentId, body
                                                 .AddProperty(SpisumNames.Properties.Pid, componentPID)
                                                 .AddProperty(SpisumNames.Properties.FileName, componentName)
                                                 );

            return(await UpdateMainFileComponentVersionProperties(nodeId, componentId, SpisumNames.VersionOperation.Update));
        }
Esempio n. 2
0
 public static NodeBodyUpdate AddPropertyIfNotNull(this NodeBodyUpdate nodeBodyUpdate, string key, object value)
 {
     return(value == null ? nodeBodyUpdate : nodeBodyUpdate.AddProperty(key, value));
 }