예제 #1
0
        public void ApplyUpdates()
        {
            this.Package.Updater.Progress.ChangeStatus("Aplicando actualización de " + this.Name);

            string NewFileName = this.GetTempFileName();

            switch (this.Compression)
            {
            case CompressionFormats.None:
                using (System.IO.BinaryWriter wr = new System.IO.BinaryWriter(System.IO.File.OpenWrite(NewFileName), System.Text.Encoding.Default)) {
                    wr.Write(this.FileContents);
                    wr.Close();
                }
                break;

            case CompressionFormats.Bz2:
                System.IO.MemoryStream InStr = new System.IO.MemoryStream(this.FileContents);
                Lfx.FileFormats.Compression.Archive ArchivoComprimido = new Lfx.FileFormats.Compression.Archive(InStr, Lfx.FileFormats.Compression.ArchiveTypes.BZip2);
                ArchivoComprimido.Extract(System.IO.File.Create(NewFileName));
                break;
            }

            System.IO.File.SetLastWriteTime(NewFileName, this.NewVersion);

            this.FileContents      = null;
            this.DownloadedVersion = DateTime.MinValue;
            this.UpdatePending     = true;
        }
예제 #2
0
                public Lfx.Types.OperationResult Backup(BackupInfo backupInfo)
                {
                        string WorkFolder = backupInfo.Name + System.IO.Path.DirectorySeparatorChar;

                        Lfx.Environment.Folders.EnsurePathExists(this.BackupPath);

                        if (!System.IO.Directory.Exists(Lfx.Environment.Folders.TemporaryFolder + WorkFolder))
                                System.IO.Directory.CreateDirectory(Lfx.Environment.Folders.TemporaryFolder + WorkFolder);

                        Lfx.Types.OperationProgress Progreso = new Lfx.Types.OperationProgress("Creando copia de seguridad", "Se está creando un volcado completo del almacén de datos en una carpeta, para resguardar.");
                        Progreso.Modal = true;
                        Progreso.Advertise = true;
                        Progreso.Begin();
                        Progreso.Max = Lfx.Workspace.Master.Structure.Tables.Count + 1;

                        Progreso.ChangeStatus("Exportando estructura");
                        Progreso.ChangeStatus(Progreso.Value + 1);
                        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                        doc.AppendChild(Lfx.Workspace.Master.Structure.ToXml(doc));
                        doc.Save(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "dbstruct.xml");

                        BackupWriter Writer = new BackupWriter(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "dbdata.lbd");
                        Writer.Write(":BKP");

                        IList<string> TableList = Lfx.Data.DataBaseCache.DefaultCache.GetTableNames();
                        foreach (string Tabla in TableList) {
                                string NombreTabla = Tabla;
                                if (Lfx.Workspace.Master.Structure.Tables.ContainsKey(Tabla))
                                        NombreTabla = Lfx.Workspace.Master.Structure.Tables[Tabla].Label;

                                Progreso.ChangeStatus("Volcando " + NombreTabla);
                                Progreso.ChangeStatus(Progreso.Value + 1);
                                ExportTableBin(Tabla, Writer);

                        }
                        Writer.Close();

                        System.IO.FileStream Archivo = new System.IO.FileStream(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "info.txt", System.IO.FileMode.Append, System.IO.FileAccess.Write);
                        using (System.IO.StreamWriter Escribidor = new System.IO.StreamWriter(Archivo, System.Text.Encoding.Default)) {
                                Escribidor.WriteLine("Copia de seguridad de Lázaro");
                                Escribidor.WriteLine("");
                                Escribidor.WriteLine("Empresa=" + backupInfo.CompanyName);
                                Escribidor.WriteLine("EspacioTrabajo=" + Lfx.Workspace.Master.Name);
                                Escribidor.WriteLine("FechaYHora=" + System.DateTime.Now.ToString("dd-MM-yyyy") + " a las " + System.DateTime.Now.ToString("HH:mm:ss"));
                                Escribidor.WriteLine("Usuario=" + backupInfo.UserName);
                                Escribidor.WriteLine("Estación=" + Lfx.Environment.SystemInformation.MachineName);
                                Escribidor.WriteLine("VersiónLazaro=" + backupInfo.ProgramVersion);
                                Escribidor.WriteLine("");
                                Escribidor.WriteLine("Por favor no modifique ni elimine este archivo.");
                                Escribidor.Close();
                                Archivo.Close();
                        }

                        if (Lfx.Workspace.Master.CurrentConfig.ReadGlobalSetting<int>("Sistema.ComprimirCopiasDeSeguridad", 0) != 0) {
                                Progreso.ChangeStatus("Comprimiendo los datos");
                                Lfx.FileFormats.Compression.Archive ArchivoComprimido = new Lfx.FileFormats.Compression.Archive(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "backup.7z");
                                ArchivoComprimido.Add(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "*");
                                if (System.IO.File.Exists(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "backup.7z")) {
                                        Progreso.ChangeStatus("Eliminando archivos temporales");
                                        // Borrar los archivos que acabo de comprimir
                                        System.IO.DirectoryInfo Dir = new System.IO.DirectoryInfo(Lfx.Environment.Folders.TemporaryFolder + WorkFolder);
                                        foreach (System.IO.FileInfo DirItem in Dir.GetFiles()) {
                                                if (DirItem.Name != "backup.7z" && DirItem.Name != "info.txt") {
                                                        System.IO.File.Delete(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + DirItem.Name);
                                                }
                                        }
                                }
                        }

                        Progreso.ChangeStatus("Almacenando");
                        Progreso.ChangeStatus(Progreso.Value + 1);
                        Lfx.Environment.Folders.MoveDirectory(Lfx.Environment.Folders.TemporaryFolder + WorkFolder, this.BackupPath + WorkFolder);

                        int GuardarBackups = Lfx.Workspace.Master.CurrentConfig.ReadGlobalSetting<int>("Sisteam.Backup.CantMax", 14);
                        if (GuardarBackups > 0) {
                                List<BackupInfo> ListaDeBackups = this.GetBackups();
                                if (ListaDeBackups.Count > GuardarBackups) {
                                        Progreso.ChangeStatus("Eliminando copias de seguridad antiguas");
                                        int BorrarBackups = ListaDeBackups.Count - GuardarBackups;
                                        if (BorrarBackups < ListaDeBackups.Count) {
                                                for (int i = 1; i <= BorrarBackups; i++) {
                                                        this.Delete(this.GetOldestBackupName());
                                                }
                                        }
                                }
                        }

                        Progreso.End();

                        return new Lfx.Types.SuccessOperationResult();
                }
예제 #3
0
        public Lfx.Types.OperationResult Backup(BackupInfo backupInfo)
        {
            string WorkFolder = backupInfo.Name + System.IO.Path.DirectorySeparatorChar;

            Lfx.Environment.Folders.EnsurePathExists(this.BackupPath);

            if (!System.IO.Directory.Exists(Lfx.Environment.Folders.TemporaryFolder + WorkFolder))
            {
                System.IO.Directory.CreateDirectory(Lfx.Environment.Folders.TemporaryFolder + WorkFolder);
            }

            Lfx.Types.OperationProgress Progreso = new Lfx.Types.OperationProgress("Creando copia de seguridad", "Se está creando un volcado completo del almacén de datos en una carpeta, para resguardar.");
            Progreso.Modal     = true;
            Progreso.Advertise = true;
            Progreso.Begin();
            Progreso.Max = Lfx.Workspace.Master.Structure.Tables.Count + 1;

            Progreso.ChangeStatus("Exportando estructura");
            Progreso.ChangeStatus(Progreso.Value + 1);
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            doc.AppendChild(Lfx.Workspace.Master.Structure.ToXml(doc));
            doc.Save(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "dbstruct.xml");

            BackupWriter Writer = new BackupWriter(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "dbdata.lbd");

            Writer.Write(":BKP");

            IList <string> TableList = Lfx.Data.DatabaseCache.DefaultCache.GetTableNames();

            foreach (string Tabla in TableList)
            {
                string NombreTabla = Tabla;
                if (Lfx.Workspace.Master.Structure.Tables.ContainsKey(Tabla))
                {
                    NombreTabla = Lfx.Workspace.Master.Structure.Tables[Tabla].Label;
                }

                Progreso.ChangeStatus("Volcando " + NombreTabla);
                Progreso.ChangeStatus(Progreso.Value + 1);
                ExportTableBin(Tabla, Writer);
            }
            Writer.Close();

            System.IO.FileStream Archivo = new System.IO.FileStream(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "info.txt", System.IO.FileMode.Append, System.IO.FileAccess.Write);
            using (System.IO.StreamWriter Escribidor = new System.IO.StreamWriter(Archivo, System.Text.Encoding.Default)) {
                Escribidor.WriteLine("Copia de seguridad de Lázaro");
                Escribidor.WriteLine("");
                Escribidor.WriteLine("Empresa=" + backupInfo.CompanyName);
                Escribidor.WriteLine("EspacioTrabajo=" + Lfx.Workspace.Master.Name);
                Escribidor.WriteLine("FechaYHora=" + System.DateTime.Now.ToString("dd-MM-yyyy") + " a las " + System.DateTime.Now.ToString("HH:mm:ss"));
                Escribidor.WriteLine("Usuario=" + backupInfo.UserName);
                Escribidor.WriteLine("Estación=" + Lfx.Environment.SystemInformation.MachineName);
                Escribidor.WriteLine("VersiónLazaro=" + backupInfo.ProgramVersion);
                Escribidor.WriteLine("");
                Escribidor.WriteLine("Por favor no modifique ni elimine este archivo.");
                Escribidor.Close();
                Archivo.Close();
            }

            if (Lfx.Workspace.Master.CurrentConfig.ReadGlobalSetting <int>("Sistema.ComprimirCopiasDeSeguridad", 0) != 0)
            {
                Progreso.ChangeStatus("Comprimiendo los datos");
                Lfx.FileFormats.Compression.Archive ArchivoComprimido = new Lfx.FileFormats.Compression.Archive(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "backup.7z");
                ArchivoComprimido.Add(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "*");
                if (System.IO.File.Exists(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + "backup.7z"))
                {
                    Progreso.ChangeStatus("Eliminando archivos temporales");
                    // Borrar los archivos que acabo de comprimir
                    System.IO.DirectoryInfo Dir = new System.IO.DirectoryInfo(Lfx.Environment.Folders.TemporaryFolder + WorkFolder);
                    foreach (System.IO.FileInfo DirItem in Dir.GetFiles())
                    {
                        if (DirItem.Name != "backup.7z" && DirItem.Name != "info.txt")
                        {
                            System.IO.File.Delete(Lfx.Environment.Folders.TemporaryFolder + WorkFolder + DirItem.Name);
                        }
                    }
                }
            }

            Progreso.ChangeStatus("Almacenando");
            Progreso.ChangeStatus(Progreso.Value + 1);
            Lfx.Environment.Folders.MoveDirectory(Lfx.Environment.Folders.TemporaryFolder + WorkFolder, this.BackupPath + WorkFolder);

            int GuardarBackups = Lfx.Workspace.Master.CurrentConfig.ReadGlobalSetting <int>("Sisteam.Backup.CantMax", 14);

            if (GuardarBackups > 0)
            {
                List <BackupInfo> ListaDeBackups = this.GetBackups();
                if (ListaDeBackups.Count > GuardarBackups)
                {
                    Progreso.ChangeStatus("Eliminando copias de seguridad antiguas");
                    int BorrarBackups = ListaDeBackups.Count - GuardarBackups;
                    if (BorrarBackups < ListaDeBackups.Count)
                    {
                        for (int i = 1; i <= BorrarBackups; i++)
                        {
                            this.Delete(this.GetOldestBackupName());
                        }
                    }
                }
            }

            Progreso.End();

            return(new Lfx.Types.SuccessOperationResult());
        }
예제 #4
0
파일: File.cs 프로젝트: solutema/ultralight
                public void ApplyUpdates()
                {
                        this.Package.Updater.Progress.ChangeStatus("Aplicando actualización de " + this.Name);

                        string NewFileName = this.GetTempFileName();

                        switch (this.Compression) {
                                case CompressionFormats.None:
                                        using (System.IO.BinaryWriter wr = new System.IO.BinaryWriter(System.IO.File.OpenWrite(NewFileName), System.Text.Encoding.Default)) {
                                                wr.Write(this.FileContents);
                                                wr.Close();
                                        }
                                        break;
                                case CompressionFormats.Bz2:
                                        System.IO.MemoryStream InStr = new System.IO.MemoryStream(this.FileContents);
                                        Lfx.FileFormats.Compression.Archive ArchivoComprimido = new Lfx.FileFormats.Compression.Archive(InStr, Lfx.FileFormats.Compression.ArchiveTypes.BZip2);
                                        ArchivoComprimido.Extract(System.IO.File.Create(NewFileName));
                                        break;
                        }

                        System.IO.File.SetLastWriteTime(NewFileName, this.NewVersion);

                        this.FileContents = null;
                        this.DownloadedVersion = DateTime.MinValue;
                        this.UpdatePending = true;
                }