Пример #1
0
        private void Open()
        {
#if (!DBG_TEST)
            Open_old(); return;
#endif
            if (Check())
            {
                try
                {
                    document = x.LoadEncodedFile_old(filebackup);
                    Utilities u = new Utilities();
                    if (!u.CheckXmlDocument(document, App.TipoFile.BackUp))
                    {
                        throw new Exception("Documento non valido. ID diverso da standard TipoFile");
                    }
                }
                catch (Exception ex)
                {
                    string log = ex.Message;
                    Error(WindowGestioneMessaggi.TipologieMessaggiErrore.ErroreInCaricamentoFileBackUp);
                }
            }
        }
Пример #2
0
        public bool RestoreFile_decoded(string nomefileBackUp)
        {
#if (!DBG_TEST)
            return(RestoreFile_old(nomefileBackUp));
#endif
            string      str, cartellatmp;
            XmlDocument doc = new XmlDocument();

            // controlli file
            cartellatmp = App.TMP_FOLDER;
            if (!cartellatmp.EndsWith(@"\"))
            {
                cartellatmp += @"\";
            }
            str = cartellatmp + Guid.NewGuid().ToString();
            DirectoryInfo di = new DirectoryInfo(str);
            if (di.Exists)
            {
                // errore directory già esistente aspettare processo terminato da parte
                // di altro utente
                return(false);
            }
            cartellatmp = str;
            di.Create();
            // verifico il contenuto
            try
            {
                Ionic.Zip.ZipFile z = new Ionic.Zip.ZipFile(nomefileBackUp);
                z.ExtractAll(
                    cartellatmp, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently);
                z.Dispose();
                z = null;
            }
            catch (Exception e)
            {
                di.Delete(true);
                MessageBox.Show(e.Message);
                return(false);
            }
            // contenuto corretto, elimino cartelle vecchie
            DirectoryInfo rdf = new DirectoryInfo(App.AppDataDataFolder);
            if (rdf.Exists)
            {
                rdf.Delete(true);
            }
            DirectoryInfo uuf = new DirectoryInfo(App.AppDocumentiFolder);
            if (uuf.Exists)
            {
                uuf.Delete(true);
            }
            // rimuovo master file
            FileInfo fi = new FileInfo(App.AppMasterDataFile);
            if (fi.Exists)
            {
                fi.Delete();
            }
            // rimuovo indice documenti
            fi = new FileInfo(App.AppDocumentiDataFile);
            if (fi.Exists)
            {
                fi.Delete();
            }
            // decodifica di tutti i files

            // RevisoftApp.rmdf e RevisoftApp.rdocf
            XmlManager x = new XmlManager {
                TipoCodifica = XmlManager.TipologiaCodifica.Nessuna
            };
            string[] files = Directory.GetFiles(
                cartellatmp, @"*.*", SearchOption.TopDirectoryOnly);
            foreach (string s in files)
            {
                doc          = x.LoadEncodedFile_old(s);
                str          = doc.InnerXml.Replace("", "");
                doc.InnerXml = str;
                doc.Save(s);
            }

            // dati in DataFile
            files = Directory.GetFiles(
                cartellatmp + @"\" + App.DataFolder, @"*.*", SearchOption.TopDirectoryOnly);
            foreach (string s in files)
            {
                doc          = x.LoadEncodedFile_old(s);
                str          = doc.InnerXml.Replace("", "");
                doc.InnerXml = str;
                doc.Save(s);
            }
            // importazione in SQL
            using (SqlConnection conn = new SqlConnection(App.connString))
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand("dbo.impMasterFile", conn);
                cmd.Parameters.AddWithValue("@masterFileFolder", cartellatmp);
                cmd.Parameters.AddWithValue("@dataFolder", cartellatmp + @"\" + App.DataFolder);
                cmd.Parameters.AddWithValue("@docFolder", cartellatmp);
                cmd.CommandType    = CommandType.StoredProcedure;
                cmd.CommandTimeout = App.m_CommandTimeout;
                try { cmd.ExecuteNonQuery(); }
                catch (Exception ex)
                {
                    str = ex.Message;
                    if (!App.m_bNoExceptionMsg)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            // ripristino cartelle
            DirectoryInfo d_rdf = new DirectoryInfo(App.AppDataDataFolder); // ex "\\RDF"
            if (!d_rdf.Exists)
            {
                d_rdf.Create();
            }
            str = App.AppDataDataFolder; if (!str.EndsWith(@"\"))
            {
                str = str + @"\";
            }
            str = str + "XAML";
            DirectoryInfo d_xaml = new DirectoryInfo(str);
            if (!d_xaml.Exists)
            {
                d_xaml.Create();
            }
            DirectoryInfo d_uuff = new DirectoryInfo(App.AppDocumentiFolder); // ex "\\UserUF"
            if (!d_uuff.Exists)
            {
                d_uuff.Create();
            }
            DirectoryInfo d_ufl = new DirectoryInfo(App.AppDocumentiFlussiFolder); // ex "\\UserUF"
            if (!d_ufl.Exists)
            {
                d_ufl.Create();
            }
            // copia contenuto
            foreach (string item in Directory.GetFiles(cartellatmp,
                                                       "*.*", SearchOption.AllDirectories))
            {
                File.Copy(item, item.Replace(cartellatmp, App.AppDataFolder), true);
            }
            Directory.Delete(cartellatmp, true);
            App.m_xmlCache.Clear();
            return(true);
        }