예제 #1
0
        public void SetBackUpFile(string nomefileBackUp)
        {
#if (!DBG_TEST)
            SetBackUpFile_old(nomefileBackUp); return;
#endif
            try
            {
                FileInfo      buf         = new FileInfo(nomefileBackUp);
                string        cartellatmp = App.TMP_FOLDER + Guid.NewGuid().ToString();
                DirectoryInfo di          = new DirectoryInfo(cartellatmp);
                if (di.Exists)
                {
                    // errore directory già esistente aspettare processo terminato da parte
                    // di altro utente
                    return;
                }
                di.Create();
                // nuove cartelle per i file necessari
                DirectoryInfo d_rdf = new DirectoryInfo(cartellatmp + "\\" + App.DataFolder);      // ex "\\RDF"
                d_rdf.Create();
                DirectoryInfo d_uuff = new DirectoryInfo(cartellatmp + "\\" + App.UserFileFolder); // ex "\\UserUF"
                d_uuff.Create();
                //----------------------------------------------------------------------------+
                //                            lettura master file                             |
                //----------------------------------------------------------------------------+
                MasterFile  mf    = new MasterFile();
                XmlDocument mfDoc = mf.GetDocument();
                if (mfDoc == null)
                {
                    return;
                }
                //----------------------------------------------------------------------------+
                //   scansione di tutti i nodi contenenti "FileData" e quindi anche "File"    |
                //----------------------------------------------------------------------------+
                string      fName;
                XmlManager  manager = new XmlManager();
                XmlDocument doc;
                string[]    attrs = { "File", "FileData" };
                foreach (XmlNode node in mfDoc.SelectNodes("//*[@FileData]"))
                {
                    foreach (string s in attrs)
                    {
                        // salvataggio albero se esiste
                        if (node.Attributes[s] != null)
                        {
                            fName = node.Attributes[s].Value;
                            doc   = manager.LoadEncodedFile(fName);
                            if (doc != null)
                            {
                                manager.SaveEncodedFile_old(
                                    cartellatmp + @"\" + App.DataFolder + @"\" + fName, doc.OuterXml);
                            }
                        }
                    }
                }
                //----------------------------------------------------------------------------+
                //                         copia di tutti i documenti                         |
                //----------------------------------------------------------------------------+
                foreach (string dir in Directory.GetDirectories(App.AppDocumentiFolder,
                                                                "*", SearchOption.AllDirectories))
                {
                    Directory.CreateDirectory(dir.Replace(App.AppDocumentiFolder, d_uuff.FullName));
                }
                foreach (string item in Directory.GetFiles(App.AppDocumentiFolder,
                                                           "*.*", SearchOption.AllDirectories))
                {
                    File.Copy(item, item.Replace(App.AppDocumentiFolder, d_uuff.FullName), true);
                }
                //----------------------------------------------------------------------------+
                //                           scrittura master file                            |
                //----------------------------------------------------------------------------+
                manager.SaveEncodedFile_old(
                    cartellatmp + @"\" + App.AppMasterDataFile.Split('\\').Last(), mfDoc.OuterXml);
                //----------------------------------------------------------------------------+
                //                          scrittura file documenti                          |
                //----------------------------------------------------------------------------+
                fName = "revisoftapp.rdocf";
                doc   = manager.LoadEncodedFile(fName);
                if (doc != null)
                {
                    manager.SaveEncodedFile_old(cartellatmp + @"\" + fName, doc.OuterXml);
                }

                //creo lo zip
                Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile();
                zip.Password = App.ZipFilePassword;
                zip.AddDirectory(di.FullName);
                zip.MaxOutputSegmentSize = MaxOutputSegmentSize;
                zip.Save(nomefileBackUp);
                // cancello i dati temporanei
                di.Delete(true);
            }
            catch (Exception ex)
            {
                string log = ex.ToString();
                System.IO.File.WriteAllText(
                    System.IO.Path.Combine(App.AppLogFolder,
                                           String.Format("{0:yyyyMMddHHmmss}_bklog.txt", DateTime.Now)), log);
                Error(WindowGestioneMessaggi.TipologieMessaggiErrore.ErroreInSalvataggioFileMaster);
            }
        }