Ejemplo n.º 1
0
        /// <summary>
        ///     Initializes the Historical data package
        /// </summary>
        /// <param name="filePath">The path to the file to load</param>
        /// <param name="factory">THe factory used to create instances of the loaded file</param>
        public static History Load(string filePath, Generated.Factory factory)
        {
            History retVal = null;

            acceptor.setFactory(factory);
            if (File.Exists(filePath))
            {
                // Do not rely on XmlBFileContext since it does not care about encoding.
                // File encoding is UTF-8
                XmlBStringContext ctxt;
                using (StreamReader file = new StreamReader(filePath))
                {
                    ctxt = new XmlBStringContext(file.ReadToEnd());
                    file.Close();
                }

                try
                {
                    retVal = acceptor.accept(ctxt) as History;
                }
                catch (XmlBException)
                {
                    Console.WriteLine(ctxt.errorMessage());
                }
            }

            return(retVal);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Duplicates the model element and avoid duplicated GUID
        /// </summary>
        /// <returns></returns>
        public ModelElement Duplicate()
        {
            ModelElement retVal = null;

            Util.DontNotify(() =>
            {
                XmlBStringContext ctxt = new XmlBStringContext(ToXMLString());
                try
                {
                    retVal = acceptor.accept(ctxt) as ModelElement;
                    RegererateGuidVisitor visitor = new RegererateGuidVisitor();
                    visitor.visit(retVal, true);
                }
                catch (Exception)
                {
                }
            });

            return(retVal);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Loads a file and locks it if required
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="enclosing"></param>
        /// <param name="lockFiles"></param>
        /// <returns></returns>
        public static T LoadFile <T>(string filePath, ModelElement enclosing, bool lockFiles)
            where T : class, IXmlBBase
        {
            T retVal = null;

            // Do not rely on XmlBFileContext since it does not care about encoding.
            // File encoding is UTF-8
            XmlBStringContext ctxt;

            using (StreamReader file = new StreamReader(filePath))
            {
                ctxt = new XmlBStringContext(file.ReadToEnd());
                file.Close();
            }

            DontNotify(() =>
            {
                try
                {
                    retVal = acceptor.accept(ctxt) as T;
                    if (retVal != null)
                    {
                        retVal.setFather(enclosing);
                        if (lockFiles)
                        {
                            LockFile(filePath);
                        }
                    }
                }
                catch (XmlBException)
                {
                    Console.WriteLine(ctxt.errorMessage());
                }
            });

            return(retVal);
        }