public static void Parse(string filename, object userData, Func <XFileData, XFileData, XFile, object, bool> ParseDataObject) { XFile xfile = null; XFileEnumerationObject firstObject = null; try { xfile = new XFile(); xfile.RegisterTemplates(XFile.DefaultTemplates); //xfile.RegisterTemplates(XFile.ExtensionTemplates); xfile.RegisterTemplates(XFile.SkinTemplates); firstObject = xfile.CreateEnumerationObject(filename, System.Runtime.InteropServices.CharSet.Ansi); for (int i = 0; i < firstObject.ChildCount; i++) { if (!ParseDataObject(firstObject.GetChild(i), null, xfile, userData)) { break; } } } finally { if (firstObject != null) { firstObject.Dispose(); } if (xfile != null) { xfile.Dispose(); } } }
/// <summary> /// Read an XFile and create the objects defined in it /// </summary> /// <param name="filespec"></param> public void Load(string filespec) { Debug.WriteLine("Loading XFile: "+filespec); manager = new XFileManager(); manager.RegisterDefaultTemplates(); // register standard templates BEFORE opening file try { xfile = manager.FromFile(filespec); // create an XFile object from file } catch (GraphicsException e) { if (e.ErrorCode == (int)XFileErrorCodes.ParseError) Debug.WriteLine("ERROR in CellLoader.Load() - Couldn't parse Xfile "+filespec); else Debug.WriteLine("ERROR in CellLoader.Load() - Failed to load "+filespec); throw; } manager.RegisterXFileTemplates(xfile); // register any custom templates in the file //manager.RegisterTemplates(data); // register any templates defined in my code for (int i=0; i<xfile.NumberChildren; i++) // iterate through the root-level objects { using (XFileData rootObject = xfile.GetChild(i)) { LoadDataObject(rootObject,0,null,null); } } // Dispose of everything xfile.Dispose(); manager.Dispose(); }
public void GetAllLinksFromZip(ZipArchive AFile, ref List <string> WebexURLs, ref List <string> StreamURLs) { foreach (var Entry in AFile.Entries) { string FileName = Entry.Name; string FileExtension = FileName.Substring(FileName.LastIndexOf(".")); while (File.Exists(FileName)) { FileName = FileName.Replace(FileExtension, "_1" + FileExtension); } Entry.ExtractToFile(FileName, true); if (FileExtension == ".xlsx" | FileExtension == ".docx" | FileExtension == ".zip") { ZipArchive XFile; try { XFile = ZipFile.OpenRead(FileName); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } GetAllLinksFromZip(XFile, ref WebexURLs, ref StreamURLs); XFile.Dispose(); } else { GetAllRecordingLinks(File.ReadAllText(Entry.Name), ref WebexURLs, ref StreamURLs); } File.Delete(FileName); } }
/// <summary> /// Read an XFile and create the objects defined in it, /// i.e. the frame hierarchy and Cytoplasm meshes. /// The animationSet objects in the X file are used to set joint limits in the frames /// </summary> /// <param name="group">Group that cell belongs to (i.e. DLL and folder name)</param> /// <param name="name">Cell type (i.e. filename minus extension, and CellType-derived class name)</param> /// <param name="variantName">NAME of the variant (i.e. name of the .X file)</param> /// <returns>The root frame of the loaded hierarchy</returns> public static JointFrame Load(string group, string type, string variantName) { CellLoader.folder = "cells" + "\\" + group + "\\" + type; // store subfolder name so that textures can be found string fsp = FileResource.Fsp(CellLoader.folder, variantName + ".X"); // .X file will be ../cells/group/type/variant.x // Debug.WriteLine("Loading XFile: "+fsp); filespec = fsp; manager = new XFileManager(); manager.RegisterDefaultTemplates(); // register standard templates BEFORE opening file try { xfile = manager.FromFile(filespec); // create an XFile object from file } catch (GraphicsException e) { if (e.ErrorCode == (int)XFileErrorCodes.ParseError) throw new SDKException("ERROR in CellLoader.Load() - Couldn't parse Xfile "+filespec); else throw new SDKException("ERROR in CellLoader.Load() - Failed to load " + filespec); } manager.RegisterXFileTemplates(xfile); // register any custom templates in the file //////// RegisterCustomTemplates(); // register any templates in this code for (int i=0; i<xfile.NumberChildren; i++) // iterate through the root-level objects { using (XFileData rootObject = xfile.GetChild(i)) { LoadRootObject(rootObject); } } // Dispose of everything xfile.Dispose(); manager.Dispose(); // return the completed hierarchy return rootFrame; }