public static void AcquireXML(TextReader reader, string fileName)
        {
            string xml;

            using (reader)
            {
                xml = reader.ReadToEnd();
            }

            object enitiyBase;

            try
            {
                using (StreamReader readerDue = new StreamReader(fileName, Encoding.UTF8, true))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(PASSPORTSCAN));//, new XmlRootAttribute("EricsoftGuestData"));
                    enitiyBase = serializer.Deserialize(readerDue);
                }
            }
            catch (InvalidOperationException operationEx)
            {
                throw new ApplicationException("Il file selezionato non è corretto. " + operationEx.Message);
            }

            try
            {
                if (!GestioneMySql.OpenConnection())
                {
                    throw new Exception("Errore nell'apertura della connessione. ");
                }

                GestioneMySql.TransazioneBegin();

                PassportscanDB.Save(enitiyBase as PASSPORTSCAN);
                FileInfo fileInfo = new FileInfo(fileName);

                TemplateXml templateXml = new TemplateXml();
                templateXml.FILE_NM   = fileInfo.Name;
                templateXml.FILE_PATH = fileInfo.FullName;

                TemplateXmlDB.SaveTemplate(templateXml);

                if (!GestioneMySql.OpenConnection())
                {
                    throw new Exception("Errore nell'apertura della connessione. ");
                }

                GestioneMySql.TransazioneCommit();

                if (!GestioneMySql.CloseConnection())
                {
                    throw new Exception("Errore nella chiusura della connessione. ");
                }
            }
            catch (Exception e)
            {
                GestioneMySql.TransazioneRollback();
                throw e;
            }
        }
 internal void Load(TemplateXml xml)
 {
     this.dictionary.Clear();
     foreach (var setting in xml.settings)
     {
         this.dictionary[setting.key] = setting.value;
     }
 }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Template"/> class.
        /// Instantiate an existing <see cref="Template"/>.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        /// <param name="fileInfo">
        /// The template Xml file
        /// </param>
        internal Template(Repository repository, FileInfo fileInfo)
        {
            this.repository = repository;

            fileInfo.Refresh();
            if (!fileInfo.Exists)
            {
                throw new Exception("Template not found");
            }

            this.xml = TemplateXml.Load(fileInfo);

            this.settings.Load(this.xml);

            Repository.CheckAllorsVersion(this.xml.allors, fileInfo.Name);
        }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Template"/> class.
        /// Creates a new <see cref="Template"/>.
        /// </summary>
        /// <param name="repository">
        /// The repository.
        /// </param>
        internal Template(Repository repository)
        {
            this.repository = repository;

            var id = Guid.NewGuid().ToString().ToLower();

            var fileName = Path.Combine(repository.TemplatesDirectoryInfo.FullName, id + TemplateExtension);
            var fileInfo = new FileInfo(fileName);

            this.xml = new TemplateXml(fileInfo)
            {
                allors = Domain.Version.ToString()
            };

            this.settings.Save(this.xml);

            Repository.CheckAllorsVersion(this.xml.allors, fileInfo.Name);

            this.Save();
            this.Repository.SendChangedEvent(this);
        }
 internal void Save(TemplateXml xml)
 {
     xml.settings = new List <SettingsXml>(this.dictionary.Select(keyValuePair => new SettingsXml(keyValuePair.Key, keyValuePair.Value)));
 }
예제 #6
0
 public Template(TemplateXml template)
 {
     Name       = template.Name;
     Regions    = template.Regions.Select(r => new RegionDef(r)).ToReadOnlyList();
     MethodDefs = template.MethodDefs.Select(m => new MethodDef(m)).ToReadOnlyList();
 }