Пример #1
0
 /// <summary>
 /// Deserializes workflow markup into an ResourcePackageManifest object
 /// </summary>
 /// <param name="xml">string workflow markup to deserialize</param>
 /// <param name="obj">Output ResourcePackageManifest object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string xml, out ResourcePackageManifest obj, out System.Exception exception)
 {
     exception = null;
     obj       = default(ResourcePackageManifest);
     try {
         obj = Deserialize(xml);
         return(true);
     }
     catch (System.Exception ex) {
         exception = ex;
         return(false);
     }
 }
Пример #2
0
 /// <summary>
 /// Deserializes xml markup from file into an ResourcePackageManifest object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output ResourcePackageManifest object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, out ResourcePackageManifest obj, out System.Exception exception)
 {
     exception = null;
     obj       = default(ResourcePackageManifest);
     try {
         obj = LoadFromFile(fileName);
         return(true);
     }
     catch (System.Exception ex) {
         exception = ex;
         return(false);
     }
 }
Пример #3
0
 public static bool LoadFromFile(string fileName, out ResourcePackageManifest obj)
 {
     System.Exception exception = null;
     return(LoadFromFile(fileName, out obj, out exception));
 }
Пример #4
0
 public static bool Deserialize(string xml, out ResourcePackageManifest obj)
 {
     System.Exception exception = null;
     return(Deserialize(xml, out obj, out exception));
 }
Пример #5
0
        private void CreatePackageInternal(string folderResourceId, string zipfilename, IEnumerable<ResourceTypes> allowedExtensions, bool removeExistingFiles, string alternateTargetResourceId, IEnumerable<string> resourceIds)
        {
            ResourcePackageManifest manifest = new ResourcePackageManifest();
            manifest.Description = "MapGuide Package created with Maestro"; //NOXLATE
            manifest.Operations = new ResourcePackageManifestOperations();
            manifest.Operations.Operation = new System.ComponentModel.BindingList<ResourcePackageManifestOperationsOperation>();

            var allowed = new List<ResourceTypes>(allowedExtensions);
            var files = new List<string>();
            var folders = new List<string>();
            var resourceData = new Dictionary<string, List<ResourceDataListResourceData>>();

            foreach (var resId in resourceIds)
            {
                if (!ResourceIdentifier.Validate(resId))
                    continue;

                var r = new ResourceIdentifier(resId);
                if (r.IsFolder)
                {
                    folders.Add(resId);
                }
                else
                {
                    var extension = r.ResourceType;
                    if (allowedExtensions == null || allowed.Count == 0)
                        files.Add(resId);
                    else if (m_connection.Capabilities.IsSupportedResourceType(extension) && allowed.Contains(extension))
                        files.Add(resId);
                }
            }

            if (Progress != null)
            {
                Progress(ProgressType.ReadingFileList, folderResourceId, 100, 100);
                Progress(ProgressType.PreparingFolder, string.Empty, files.Count + folders.Count + 1, 0);
            }

            string temppath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetRandomFileName());

            //All files have random names on disk, but a full path in the zip file
            List<KeyValuePair<string, string>> filemap = new List<KeyValuePair<string, string>>();

            try
            {
                System.IO.Directory.CreateDirectory(temppath);
                int opno = 1;

                foreach (var folder in folders)
                {

                    if (Progress != null)
                        Progress(ProgressType.PreparingFolder, folder, files.Count + folders.Count + 1, opno);
                    AddFolderResource(manifest, temppath, folder, removeExistingFiles, m_connection, filemap);
                    if (Progress != null)
                        Progress(ProgressType.PreparingFolder, folder, files.Count + folders.Count + 1, opno++);
                }

                foreach (var doc in files)
                {
                    if (Progress != null)
                        Progress(ProgressType.PreparingFolder, doc, files.Count + folders.Count + 1, opno);
                    string filebase = CreateFolderForResource(doc, temppath);

                    resourceData[doc] = new List<ResourceDataListResourceData>();
                    ResourceDataList rdl = m_connection.ResourceService.EnumerateResourceData(doc);
                    foreach (ResourceDataListResourceData rd in rdl.ResourceData)
                        resourceData[doc].Add(rd);

                    int itemCount = resourceData[doc].Count + 1;

                    filemap.Add(new KeyValuePair<string, string>(filebase + "_CONTENT.xml", System.IO.Path.Combine(temppath, Guid.NewGuid().ToString()))); //NOXLATE
                    using (System.IO.FileStream fs = new System.IO.FileStream(filemap[filemap.Count - 1].Value, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None))
                    {
                        using (var s = m_connection.ResourceService.GetResourceXmlData(doc))
                        {
                            var data = Utility.StreamAsArray(s);
                            fs.Write(data, 0, data.Length);
                        }
                    }

                    AddFileResource(manifest, temppath, doc, filemap[filemap.Count - 1].Key, removeExistingFiles, m_connection, filemap);

                    foreach (ResourceDataListResourceData rd in rdl.ResourceData)
                    {
                        filemap.Add(new KeyValuePair<string, string>(filebase + "_DATA_" + EncodeFilename(rd.Name), System.IO.Path.Combine(temppath, Guid.NewGuid().ToString())));
                        System.IO.FileInfo fi = new System.IO.FileInfo(filemap[filemap.Count - 1].Value);
                        using (System.IO.FileStream fs = new System.IO.FileStream(fi.FullName, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None))
                        {
                            Utility.CopyStream(m_connection.ResourceService.GetResourceData(doc, rd.Name), fs);
                        }

                        AddResourceData(manifest, temppath, doc, fi, filemap[filemap.Count - 1].Key, rd, m_connection);
                    }

                    if (Progress != null)
                        Progress(ProgressType.PreparingFolder, doc, files.Count + folders.Count + 1, opno++);
                }

                if (Progress != null)
                    Progress(ProgressType.PreparingFolder, Strings.ProgressDone, files.Count + folders.Count + 1, files.Count + folders.Count + 1);

                if (!string.IsNullOrEmpty(alternateTargetResourceId))
                {
                    if (Progress != null)
                        Progress(ProgressType.MovingResources, Strings.ProgressUpdatingReferences, 100, 0);
                    RemapFiles(m_connection, manifest, temppath, folderResourceId, alternateTargetResourceId, filemap);
                    if (Progress != null)
                        Progress(ProgressType.MovingResources, Strings.ProgressUpdatedReferences, 100, 100);
                }

                filemap.Add(new KeyValuePair<string, string>(System.IO.Path.Combine(temppath, "MgResourcePackageManifest.xml"), System.IO.Path.Combine(temppath, Guid.NewGuid().ToString()))); //NOXLATE
                using (System.IO.FileStream fs = new System.IO.FileStream(filemap[filemap.Count - 1].Value, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write, System.IO.FileShare.None))
                    m_connection.ResourceService.SerializeObject(manifest, fs);

                if (Progress != null)
                    Progress(ProgressType.MovingResources, zipfilename, filemap.Count, 0);

                ZipDirectory(zipfilename, temppath, "MapGuide Package created by Maestro", filemap); //NOXLATE

                if (Progress != null)
                {
                    Progress(ProgressType.MovingResources, zipfilename, filemap.Count, filemap.Count);
                    Progress(ProgressType.Done, "", filemap.Count, filemap.Count);
                }

            }
            finally
            {
                try
                {
                    if (System.IO.Directory.Exists(temppath))
                        System.IO.Directory.Delete(temppath, true);
                }
                catch
                { }
            }
        }
Пример #6
0
        private void AddResourceData(ResourcePackageManifest manifest, string temppath, string docResourceId, System.IO.FileInfo fi, string resourcePath, ResourceDataListResourceData rd, IServerConnection connection)
        {
            string contentType = "application/octet-stream"; //NOXLATE

            string name = rd.Name;
            string type = rd.Type.ToString();
            string resourceId = docResourceId;
            string filename = RelativeName(resourcePath, temppath).Replace('\\', '/'); //NOXLATE
            long size = fi.Length;

            AddResourceData(manifest, resourceId, contentType, type, name, filename, size);
        }
Пример #7
0
        private void AddResourceData(ResourcePackageManifest manifest, string resourceId, string contentType, string type, string name, string filename, long size)
        {
            ResourcePackageManifestOperationsOperation op = new ResourcePackageManifestOperationsOperation();
            op.Name = "SETRESOURCEDATA"; //NOXLATE
            op.Version = "1.0.0"; //NOXLATE
            op.Parameters = new ResourcePackageManifestOperationsOperationParameters();
            op.Parameters.Parameter = new System.ComponentModel.BindingList<ResourcePackageManifestOperationsOperationParametersParameter>();

            ResourcePackageManifestOperationsOperationParametersParameter param = new ResourcePackageManifestOperationsOperationParametersParameter();

            param.Name = "DATA"; //NOXLATE
            param.Value = filename;
            param.ContentType = contentType;
            op.Parameters.Parameter.Add(param);

            param = new ResourcePackageManifestOperationsOperationParametersParameter();
            param.Name = "DATALENGTH"; //NOXLATE
            param.Value = size.ToString();
            op.Parameters.Parameter.Add(param);

            param = new ResourcePackageManifestOperationsOperationParametersParameter();
            param.Name = "DATANAME"; //NOXLATE
            param.Value = name;
            op.Parameters.Parameter.Add(param);

            param = new ResourcePackageManifestOperationsOperationParametersParameter();
            param.Name = "DATATYPE";
            param.Value = type;
            op.Parameters.Parameter.Add(param);

            param = new ResourcePackageManifestOperationsOperationParametersParameter();
            param.Name = "RESOURCEID"; //NOXLATE
            param.Value = resourceId;
            op.Parameters.Parameter.Add(param);

            manifest.Operations.Operation.Add(op);
        }
Пример #8
0
        private void AddFolderResource(ResourcePackageManifest manifest, string temppath, string folderResId, bool eraseFirst, IServerConnection connection, List<KeyValuePair<string, string>> filemap)
        {
            string filebase = System.IO.Path.GetDirectoryName(CreateFolderForResource(folderResId + "dummy.xml", temppath)); //NOXLATE

            filemap.Add(new KeyValuePair<string, string>(System.IO.Path.Combine(filebase, "_HEADER.xml"), System.IO.Path.Combine(temppath, Guid.NewGuid().ToString()))); //NOXLATE
            using (System.IO.FileStream fs = new System.IO.FileStream(filemap[filemap.Count - 1].Value, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None))
                connection.ResourceService.SerializeObject(connection.ResourceService.GetFolderHeader(folderResId), fs);

            if (!filebase.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
                filebase += System.IO.Path.DirectorySeparatorChar;

            string headerpath = RelativeName(filebase + "_HEADER.xml", temppath).Replace('\\', '/'); //NOXLATE

            AddFolderResource(manifest, folderResId, headerpath, eraseFirst);
        }
Пример #9
0
        private void AddFolderResource(ResourcePackageManifest manifest, string resourceId, string headerpath, bool eraseFirst)
        {
            if (eraseFirst)
            {
                ResourcePackageManifestOperationsOperation delop = new ResourcePackageManifestOperationsOperation();
                delop.Name = "DELETERESOURCE"; //NOXLATE
                delop.Version = "1.0.0"; //NOXLATE
                delop.Parameters = new ResourcePackageManifestOperationsOperationParameters();
                delop.Parameters.Parameter = new System.ComponentModel.BindingList<ResourcePackageManifestOperationsOperationParametersParameter>();

                ResourcePackageManifestOperationsOperationParametersParameter delparam = new ResourcePackageManifestOperationsOperationParametersParameter();

                delparam.Name = "RESOURCEID"; //NOXLATE
                delparam.Value = resourceId;
                delop.Parameters.Parameter.Add(delparam);
                manifest.Operations.Operation.Add(delop);
            }

            ResourcePackageManifestOperationsOperation op = new ResourcePackageManifestOperationsOperation();
            if (resourceId.EndsWith("//")) //NOXLATE
                op.Name = "UPDATEREPOSITORY"; //NOXLATE
            else
                op.Name = "SETRESOURCE"; //NOXLATE
            op.Version = "1.0.0"; //NOXLATE
            op.Parameters = new ResourcePackageManifestOperationsOperationParameters();
            op.Parameters.Parameter = new System.ComponentModel.BindingList<ResourcePackageManifestOperationsOperationParametersParameter>();

            ResourcePackageManifestOperationsOperationParametersParameter param = new ResourcePackageManifestOperationsOperationParametersParameter();

            param.Name = "HEADER"; //NOXLATE
            param.Value = headerpath;
            param.ContentType = "text/xml"; //NOXLATE
            op.Parameters.Parameter.Add(param);

            param = new ResourcePackageManifestOperationsOperationParametersParameter();
            param.Name = "RESOURCEID"; //NOXLATE
            param.Value = resourceId;
            op.Parameters.Parameter.Add(param);

            manifest.Operations.Operation.Add(op);
        }
Пример #10
0
        /// <summary>
        /// Builds a package with the specified content
        /// </summary>
        /// <param name="sourcePackageFile">The MGP file to read existing items from</param>
        /// <param name="items">The list of items that should be present in the new package</param>
        /// <param name="insertEraseCommands">True if each resource should have a delete operation inserted before the actual operation, false otherwise</param>
        /// <param name="targetfile">The output package filename</param>
        public void RebuildPackage(string sourcePackageFile, List<ResourceItem> items, string targetfile, bool insertEraseCommands)
        {
            string tempfolder = System.IO.Path.GetTempPath();
            int opno = 1;
            try
            {
                if (Progress != null)
                    Progress(ProgressType.ReadingFileList, sourcePackageFile, 100, 0);

                //Step 1: Create the file system layout
                if (!System.IO.Directory.Exists(tempfolder))
                    System.IO.Directory.CreateDirectory(tempfolder);

                string zipfilecomment;

                List<KeyValuePair<string, string>> filemap = new List<KeyValuePair<string, string>>();

                ICSharpCode.SharpZipLib.Zip.ZipConstants.DefaultCodePage = System.Text.Encoding.UTF8.CodePage;
                using (ICSharpCode.SharpZipLib.Zip.ZipFile zipfile = new ICSharpCode.SharpZipLib.Zip.ZipFile(sourcePackageFile))
                {
                    zipfilecomment = zipfile.ZipFileComment;

                    if (Progress != null)
                        Progress(ProgressType.ReadingFileList, sourcePackageFile, 100, 100);

                    if (Progress != null)
                        Progress(ProgressType.PreparingFolder, string.Empty, items.Count, 0);

                    foreach (ResourceItem ri in items)
                    {
                        if (Progress != null)
                            Progress(ProgressType.PreparingFolder, ri.ResourcePath, items.Count, opno);

                        string filebase;
                        if (ri.IsFolder)
                        {
                            filebase = System.IO.Path.GetDirectoryName(MapResourcePathToFolder(tempfolder, ri.ResourcePath + "dummy.xml")); //NOXLATE
                            if (!filebase.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
                                filebase += System.IO.Path.DirectorySeparatorChar;
                        }
                        else
                            filebase = MapResourcePathToFolder(tempfolder, ri.ResourcePath);

                        string headerpath = filebase + "_HEADER.xml"; //NOXLATE
                        string contentpath = filebase + "_CONTENT.xml"; //NOXLATE

                        if (ri.EntryType == EntryTypeEnum.Added)
                        {
                            if (string.IsNullOrEmpty(ri.Headerpath))
                            {
                                filemap.Add(new KeyValuePair<string, string>(headerpath, System.IO.Path.Combine(tempfolder, ri.GenerateUniqueName())));
                                using (System.IO.FileStream fs = new System.IO.FileStream(filemap[filemap.Count - 1].Value, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write, System.IO.FileShare.None))
                                {
                                    byte[] data = System.Text.Encoding.UTF8.GetBytes(DEFAULT_HEADER);
                                    fs.Write(data, 0, data.Length);
                                }
                            }
                            else if (!ri.IsFolder)
                            {
                                filemap.Add(new KeyValuePair<string, string>(headerpath, ri.Headerpath));
                                System.IO.File.Copy(ri.Headerpath, headerpath);
                            }

                            if (!string.IsNullOrEmpty(ri.Contentpath))
                                filemap.Add(new KeyValuePair<string, string>(contentpath, ri.Contentpath));
                        }
                        else if (ri.EntryType == EntryTypeEnum.Regular)
                        {
                            if (string.IsNullOrEmpty(ri.Headerpath))
                            {
                                filemap.Add(new KeyValuePair<string, string>(headerpath, System.IO.Path.Combine(tempfolder, ri.GenerateUniqueName())));
                                using (System.IO.FileStream fs = new System.IO.FileStream(filemap[filemap.Count - 1].Value, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write, System.IO.FileShare.None))
                                {
                                    byte[] data = System.Text.Encoding.UTF8.GetBytes(DEFAULT_HEADER);
                                    fs.Write(data, 0, data.Length);
                                }
                            }
                            else
                            {
                                int index = FindZipEntry(zipfile, ri.Headerpath);
                                if (index < 0)
                                    throw new Exception(string.Format(Strings.FileMissingError, ri.Headerpath));

                                filemap.Add(new KeyValuePair<string, string>(headerpath, System.IO.Path.Combine(tempfolder, ri.GenerateUniqueName())));
                                using (System.IO.FileStream fs = new System.IO.FileStream(filemap[filemap.Count - 1].Value, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write, System.IO.FileShare.None))
                                    Utility.CopyStream(zipfile.GetInputStream(index), fs);
                            }

                            if (!ri.IsFolder)
                            {
                                int index = FindZipEntry(zipfile, ri.Contentpath);
                                if (index < 0)
                                    throw new Exception(string.Format(Strings.FileMissingError, ri.Contentpath));

                                filemap.Add(new KeyValuePair<string, string>(contentpath, System.IO.Path.Combine(tempfolder, ri.GenerateUniqueName())));
                                using (System.IO.FileStream fs = new System.IO.FileStream(filemap[filemap.Count - 1].Value, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write, System.IO.FileShare.None))
                                    Utility.CopyStream(zipfile.GetInputStream(index), fs);
                            }

                        }

                        ri.Headerpath = headerpath;
                        ri.Contentpath = contentpath;

                        foreach (ResourceDataItem rdi in ri.Items)
                        {
                            string targetpath = filebase + "_DATA_" + EncodeFilename(rdi.ResourceName); //NOXLATE
                            if (rdi.EntryType == EntryTypeEnum.Added)
                            {
                                var tempFilePath = System.IO.Path.Combine(tempfolder, ri.GenerateUniqueName());
                                filemap.Add(new KeyValuePair<string, string>(targetpath, tempFilePath));
                                if (File.Exists(rdi.Filename))
                                    File.Copy(rdi.Filename, tempFilePath);
                            }
                            else
                            {
                                int index = FindZipEntry(zipfile, rdi.Filename);
                                if (index < 0)
                                    throw new Exception(string.Format(Strings.FileMissingError, rdi.Filename));

                                filemap.Add(new KeyValuePair<string, string>(targetpath, System.IO.Path.Combine(tempfolder, ri.GenerateUniqueName())));
                                using (System.IO.FileStream fs = new System.IO.FileStream(filemap[filemap.Count - 1].Value, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write, System.IO.FileShare.None))
                                    Utility.CopyStream(zipfile.GetInputStream(index), fs);
                            }
                            rdi.Filename = targetpath;
                        }

                        if (Progress != null)
                            Progress(ProgressType.PreparingFolder, ri.ResourcePath, items.Count, opno++);
                    }
                }

                int i = 0;

                Dictionary<string, string> filemap_lookup = new Dictionary<string, string>();
                foreach (KeyValuePair<string, string> kv in filemap)
                    filemap_lookup[kv.Key] = kv.Value;

                //Step 2: Repoint all resources with respect to the update
                foreach (ResourceItem ri in items)
                {
                    if (Progress != null)
                        Progress(ProgressType.MovingResources, Strings.ProgressUpdatingResources, items.Count, i);

                    if (ri.OriginalResourcePath != ri.ResourcePath)
                    {
                        foreach (ResourceItem rix in items)
                        {
                            if (!rix.IsFolder)
                            {
                                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                                doc.Load(filemap_lookup[rix.Contentpath]);
                                ((PlatformConnectionBase)m_connection).UpdateResourceReferences(doc, ri.OriginalResourcePath, ri.ResourcePath, ri.IsFolder);
                                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                                doc.Save(ms);
                                System.IO.MemoryStream ms2 = Utility.RemoveUTF8BOM(ms);
                                if (ms2 != ms)
                                    ms.Dispose();

                                ms2.Position = 0;
                                using (System.IO.FileStream fs = new System.IO.FileStream(filemap_lookup[rix.Contentpath], System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None))
                                {
                                    Utility.CopyStream(ms2, fs);
                                }
                                ms2.Dispose();
                            }
                        }
                    }
                    if (Progress != null)
                        Progress(ProgressType.MovingResources, Strings.ProgressUpdatingResources, items.Count, i++);
                }

                if (Progress != null)
                    Progress(ProgressType.MovingResources, Strings.ProgressUpdatedResources, items.Count, items.Count);

                //Step 3: Create an updated definition file
                ResourcePackageManifest manifest = new ResourcePackageManifest();
                manifest.Description = "MapGuide Package created by Maestro"; //NOXLATE
                manifest.Operations = new ResourcePackageManifestOperations();
                manifest.Operations.Operation = new System.ComponentModel.BindingList<ResourcePackageManifestOperationsOperation>();

                foreach (ResourceItem ri in items)
                {
                    if (ri.IsFolder)
                    {
                        AddFolderResource(
                            manifest,
                            ri.ResourcePath,
                            RelativeName(ri.Headerpath, tempfolder).Replace('\\', '/'), //NOXLATE
                            insertEraseCommands);
                    }
                    else
                    {
                        AddFileResource(
                            manifest,
                            ri.ResourcePath,
                            RelativeName(ri.Headerpath, tempfolder).Replace('\\', '/'), //NOXLATE
                            RelativeName(ri.Contentpath, tempfolder).Replace('\\', '/'), //NOXLATE
                            insertEraseCommands);

                        foreach (ResourceDataItem rdi in ri.Items)
                        {
                            AddResourceData(
                                manifest,
                                ri.ResourcePath,
                                rdi.ContentType,
                                rdi.DataType,
                                rdi.ResourceName,
                                RelativeName(rdi.Filename, tempfolder).Replace('\\', '/'), //NOXLATE
                                new System.IO.FileInfo(filemap_lookup[rdi.Filename]).Length);
                        }
                    }
                }

                filemap.Add(new KeyValuePair<string, string>(System.IO.Path.Combine(tempfolder, "MgResourcePackageManifest.xml"), System.IO.Path.Combine(tempfolder, Guid.NewGuid().ToString()))); //NOXLATE
                using (System.IO.FileStream fs = new System.IO.FileStream(filemap[filemap.Count - 1].Value, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write, System.IO.FileShare.None))
                    m_connection.ResourceService.SerializeObject(manifest, fs);

                if (Progress != null)
                    Progress(ProgressType.Compressing, Strings.ProgressCompressing, 100, 0);

                //Step 4: Create the zip file
                ZipDirectory(targetfile, tempfolder, zipfilecomment, filemap);

                if (Progress != null)
                    Progress(ProgressType.Compressing, Strings.ProgressCompressed, 100, 100);
            }
            finally
            {
                try { System.IO.Directory.Delete(tempfolder, true); }
                catch { }
            }
        }
Пример #11
0
        private void AddFileResource(ResourcePackageManifest manifest, string temppath, string docResourceId, string contentfilename, bool eraseFirst, IServerConnection connection, List<KeyValuePair<string, string>> filemap)
        {
            string filebase = CreateFolderForResource(docResourceId, temppath);

            filemap.Add(new KeyValuePair<string, string>(filebase + "_HEADER.xml", System.IO.Path.Combine(temppath, Guid.NewGuid().ToString()))); //NOXLATE
            using (System.IO.FileStream fs = new System.IO.FileStream(filemap[filemap.Count - 1].Value, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None))
                connection.ResourceService.SerializeObject(connection.ResourceService.GetResourceHeader(docResourceId), fs);

            string headerpath = RelativeName(filemap[filemap.Count - 1].Key, temppath).Replace('\\', '/'); //NOXLATE
            string contentpath = RelativeName(contentfilename, temppath).Replace('\\', '/'); //NOXLATE
            AddFileResource(manifest, docResourceId, headerpath, contentpath, eraseFirst);
        }
Пример #12
0
        private void RemapFiles(IServerConnection connection, ResourcePackageManifest manifest, string tempdir, string origpath, string newpath, List<KeyValuePair<string, string>> filemap)
        {
            if (!newpath.EndsWith("/")) //NOXLATE
                newpath += "/"; //NOXLATE
            if (!origpath.EndsWith("/")) //NOXLATE
                origpath += "/"; //NOXLATE

            Dictionary<string, string> lookup = new Dictionary<string, string>();
            foreach (KeyValuePair<string, string> p in filemap)
                lookup.Add(p.Key, p.Value);

            foreach (ResourcePackageManifestOperationsOperation op in manifest.Operations.Operation)
            {
                op.Parameters.SetParameterValue("RESOURCEID", newpath + op.Parameters.GetParameterValue("RESOURCEID").Substring(origpath.Length)); //NOXLATE
                if (op.Parameters.GetParameterValue("CONTENT") != null) //NOXLATE
                {
                    string path = System.IO.Path.Combine(tempdir, op.Parameters.GetParameterValue("CONTENT").Replace('/', System.IO.Path.DirectorySeparatorChar)); //NOXLATE
                    System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                    doc.Load(lookup[path]);
                    ((PlatformConnectionBase)connection).UpdateResourceReferences(doc, origpath, newpath, true);
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();
                    doc.Save(ms);
                    System.IO.MemoryStream ms2 = Utility.RemoveUTF8BOM(ms);
                    if (ms2 != ms)
                        ms.Dispose();

                    ms2.Position = 0;
                    using (System.IO.FileStream fs = new System.IO.FileStream(lookup[path], System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None))
                    {
                        Utility.CopyStream(ms2, fs);
                    }
                    ms2.Dispose();
                }
            }
        }
 public static bool LoadFromFile(string fileName, out ResourcePackageManifest obj) {
     System.Exception exception = null;
     return LoadFromFile(fileName, out obj, out exception);
 }
 /// <summary>
 /// Deserializes xml markup from file into an ResourcePackageManifest object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output ResourcePackageManifest object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, out ResourcePackageManifest obj, out System.Exception exception) {
     exception = null;
     obj = default(ResourcePackageManifest);
     try {
         obj = LoadFromFile(fileName);
         return true;
     }
     catch (System.Exception ex) {
         exception = ex;
         return false;
     }
 }
 public static bool Deserialize(string xml, out ResourcePackageManifest obj) {
     System.Exception exception = null;
     return Deserialize(xml, out obj, out exception);
 }
 /// <summary>
 /// Deserializes workflow markup into an ResourcePackageManifest object
 /// </summary>
 /// <param name="xml">string workflow markup to deserialize</param>
 /// <param name="obj">Output ResourcePackageManifest object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string xml, out ResourcePackageManifest obj, out System.Exception exception) {
     exception = null;
     obj = default(ResourcePackageManifest);
     try {
         obj = Deserialize(xml);
         return true;
     }
     catch (System.Exception ex) {
         exception = ex;
         return false;
     }
 }