/// <summary> /// Before rendering the SME into a list of new elements, process the SME. /// If <c>Touched</c>, <c>sourceSme</c> and <c>editSource</c> is set, /// this function shall write back the new values instead of /// producing a new element. Returns True, if a new element shall be rendered. /// </summary> public override bool ProcessSmeForRender( AdminShellPackageEnv packageEnv = null, bool addFilesToPackage = false, bool editSource = false) { // refer to base (SME) function, but not caring about result base.ProcessSmeForRender(packageEnv, addFilesToPackage, editSource); // access var file = this.sme as AdminShell.File; var fileSource = this.sourceSme as AdminShell.File; // need to do more than the base implementation! if (file != null) { if (packageEnv != null) { // source path as given by the user var sourcePath = this.FileToLoad?.Trim(); if (sourcePath != null && sourcePath.Length > 0) { // target path challenge: shall be unqiue try { var onlyFn = System.IO.Path.GetFileNameWithoutExtension(sourcePath); var onlyExt = System.IO.Path.GetExtension(sourcePath); var salt = Guid.NewGuid().ToString().Substring(0, 8); var targetPath = "/aasx/files/"; var targetFn = String.Format("{0}_{1}{2}", onlyFn, salt, onlyExt); // have package to adopt the file name packageEnv.PrepareSupplementaryFileParameters(ref targetPath, ref targetFn); // save file.value = targetPath + targetFn; if (addFilesToPackage) { packageEnv.AddSupplementaryFileToStore( sourcePath, targetPath, targetFn, embedAsThumb: false); } } catch (Exception ex) { throw new Exception( $"FormInstanceFile.RenderAasSmeCollection failed while " + $"writing package for {sourcePath}", ex); } } } } // now, may be edit instead of new if (file != null && Touched && fileSource != null && editSource) { fileSource.value = file.value; return(false); } return(true); }