Ejemplo n.º 1
0
        public static DnaLibrary LoadFrom(string fileName)
        {
            DnaLibrary dnaLibrary;

            if (!File.Exists(fileName))
            {
                Logger.Initialization.Error("The required .dna script file {0} does not exist.", fileName);
                return(null);
            }

            try
            {
                XmlSerializer serializer = new DnaLibrarySerializer();
                using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                {
                    dnaLibrary = (DnaLibrary)serializer.Deserialize(fileStream);
                }
            }
            catch (Exception e)
            {
                Logger.Initialization.Error("There was an error during processing of {0}:\r\n{1}\r\n{2}", fileName, e.Message, e.InnerException != null ? e.InnerException.Message : string.Empty);
                return(null);
            }
            dnaLibrary.dnaResolveRoot = Path.GetDirectoryName(fileName);
            return(dnaLibrary);
        }
Ejemplo n.º 2
0
        public static void Save(string fileName, DnaLibrary dnaLibrary)
        {
            //			XmlSerializer serializer = new XmlSerializer(typeof(DnaLibrary));
            XmlSerializer serializer = new DnaLibrarySerializer();

            using (FileStream fileStream = new FileStream(fileName, FileMode.Truncate))
            {
                serializer.Serialize(fileStream, dnaLibrary);
            }
        }
Ejemplo n.º 3
0
        public static byte[] Save(DnaLibrary dnaLibrary)
        {
            //			XmlSerializer serializer = new XmlSerializer(typeof(DnaLibrary));
            XmlSerializer serializer = new DnaLibrarySerializer();

            using (MemoryStream ms = new MemoryStream())
            {
                serializer.Serialize(ms, dnaLibrary);
                return(ms.ToArray());
            }
        }
Ejemplo n.º 4
0
        public static void LoadCommandBars(string xmlCustomUI, GetImageDelegate getImage)
        {
            string dnaLibraryWrapper = string.Format(@"<DnaLibrary><CustomUI>{0}</CustomUI></DnaLibrary>", xmlCustomUI);

            using (StringReader sr = new StringReader(dnaLibraryWrapper))
            {
                XmlSerializer serializer = new DnaLibrarySerializer();
                // TODO: Check for and display errors....
                DnaLibrary dnaLibrary = (DnaLibrary)serializer.Deserialize(sr);
                LoadCommandBars(dnaLibrary.CustomUIs[0], getImage);
            }
        }
Ejemplo n.º 5
0
        public static DnaLibrary LoadFrom(byte[] bytes, string pathResolveRoot)
        {
            DnaLibrary    dnaLibrary;
            XmlSerializer serializer = new DnaLibrarySerializer();

            try
            {
                using (MemoryStream ms = new MemoryStream(bytes))
                {
                    dnaLibrary = (DnaLibrary)serializer.Deserialize(ms);
                }
            }
            catch (Exception e)
            {
                Logger.Initialization.Error("There was an error in processing .dna file bytes:\r\n{0}\r\n{1}", e.Message, e.InnerException != null ? e.InnerException.Message : string.Empty);
                return(null);
            }
            dnaLibrary.dnaResolveRoot = pathResolveRoot;
            return(dnaLibrary);
        }
Ejemplo n.º 6
0
        public static DnaLibrary LoadFrom(Uri uri)
        {
            DnaLibrary    dnaLibrary;
            XmlSerializer serializer = new DnaLibrarySerializer();

            // The uri might be file or http.
            try
            {
                WebRequest  req = WebRequest.CreateDefault(uri);
                WebResponse res = req.GetResponse();
                Stream      s   = res.GetResponseStream();
                dnaLibrary = (DnaLibrary)serializer.Deserialize(s);
            }
            catch (Exception e)
            {
                Logger.Initialization.Error("There was an error in loading the .dna file from a Uri:\r\n{0}\r\n{1}\r\nUri:{2}", e.Message, e.InnerException != null ? e.InnerException.Message : string.Empty, uri.ToString());
                return(null);
            }

            dnaLibrary.dnaResolveRoot = null;
            return(dnaLibrary);
        }
Ejemplo n.º 7
0
        public static DnaLibrary LoadFrom(byte[] bytes, string pathResolveRoot)
        {
            DnaLibrary    dnaLibrary;
            XmlSerializer serializer = new DnaLibrarySerializer();

            try
            {
                using (MemoryStream ms = new MemoryStream(bytes))
                {
                    dnaLibrary = (DnaLibrary)serializer.Deserialize(ms);
                }
            }
            catch (Exception e)
            {
                string errorMessage = string.Format("There was an error while processing DnaFile bytes:\r\n{0}\r\n{1}", e.Message, e.InnerException != null ? e.InnerException.Message : string.Empty);
                Debug.WriteLine(errorMessage);
                //ExcelDna.Logging.LogDisplay.SetText(errorMessage);
                return(null);
            }
            dnaLibrary.dnaResolveRoot = pathResolveRoot;
            return(dnaLibrary);
        }