Ejemplo n.º 1
0
        internal void AskForSelectedBackupVersion(MainWindow.RecoveringQuery_st recQuery)
        {
            int version = recQuery.versionToRecover;
            MyLogger.print("Ripristino della versione " + recQuery.versionToRecover +"... ");
            sendToServer(commRecoverBackup);
            waitForAck(commCmdAckFromServer);
            //seleziono versione
            sendToServer(version.ToString());

            int fileCount = recQuery.recInfos.getVersionSpecificCount(version);

            try
            {
                for (int i = 0; i < fileCount; i++)
                {

                    //legge nome del file
                    string fileName = socketReadline();
                    string newPathAndName;
                    //definisce percorso dove salvare il file
                    if (recQuery.recoveringFolderPath != "")
                    {
                        //path da usare: quello specificato da utente
                        System.Diagnostics.Debug.Assert(fileName.Contains(mainWindow.settings.getRootFolder()));
                        //elimina la rootFolder. lascia // iniziale
                        string localPath = fileName.Substring(mainWindow.settings.getRootFolder().Length);
                        newPathAndName = recQuery.recoveringFolderPath.TrimEnd(Path.AltDirectorySeparatorChar) + localPath;
                    }
                    else
                    {
                        //path da usare: quello originale del file
                        newPathAndName = fileName;
                    }

                    //apro il file
                    FileStream fout;
                    Directory.CreateDirectory(System.IO.Path.GetDirectoryName(newPathAndName));
                    try
                    {
                        fout = new FileStream(newPathAndName, FileMode.Create);
                    }
                    catch (Exception e) when (e is IOException || e is UnauthorizedAccessException)
                    {
                        //se file è protetto ne crea una copia a fianco
                        newPathAndName += "-restoredCopy";
                        fout = new FileStream(newPathAndName, FileMode.Create);
                        MyLogger.print("Impossibile ripristinare il file " + newPathAndName + ", salvo con suffisso \"restoredCopy\"\n");
                    }

                    System.DateTime LastModifyDate;
                    try
                    {
                        LastModifyDate = RecFileContent(newPathAndName, fout);
                        fout.Close();
                        FileInfo fi = new FileInfo(newPathAndName);
                        fi.LastWriteTime = LastModifyDate;

                    }
                    catch (CancelFileRequestException)
                    {
                        MyLogger.print("Operazione Annullata\n");
                        fout.Close();
                        deleteFile(newPathAndName);
                        return;
                    }
                    catch(IOException)
                    {
                        MyLogger.popup("Impossibile accedere al file " + newPathAndName + " Operazione interrotta.", MessageBoxImage.Error);
                        fout.Close();
                        deleteFile(newPathAndName);
                        return;
                    }

                }

                //mainWindow.Dispatcher.Invoke(mainWindow.DelShowOkMsg, "Ripristino versione completato!", MessageBoxImage.Information);
                //MyLogger.print("Ripristino versione " + recQuery.versionToRecover.ToString() + " riuscito");
                MyLogger.popup("Ripristino versione " + recQuery.versionToRecover.ToString() + " riuscito", MessageBoxImage.Information);
            }
            catch (Exception e)
            {
                MyLogger.print("ripristino fallito");
                mainWindow.Dispatcher.Invoke(mainWindow.DelShowOkMsg, "Ripristino versione fallita", MessageBoxImage.Error);
                MyLogger.debug(e.ToString());
                return;
            }
        }
Ejemplo n.º 2
0
        int versionToDisplay; //-1 se display di file da tutte le versioni

        #endregion Fields

        #region Constructors

        public RecoverWindow(MainWindow mainW)
        {
            InitializeComponent();
            this.mainW = mainW;
            DelYesNoQuestion = AskYesNoQuestion;
            DelCloseWindow = () => { this.Close(); return; };
            DelSetRecProgressValues = SetRecProgressValues;

            RecoverEntryList = new List<recoverListEntry>();
            RecoverEntryList.Add( new recoverListEntry() { Name = "Caricamento in corso...", lastMod = ""});
            recoverListView.ItemsSource = RecoverEntryList;

            recInfos = new RecoverInfos();
            RecoverViewModeList = new List<string> { "file da tutte le versioni" };
            comboRecoverViewMode.ItemsSource = RecoverViewModeList;
            //seleziono prima stringa (file da tutte le versioni)
            comboRecoverViewMode.SelectedIndex = 0;
            versionToDisplay = -1;
            this.buttRecover.IsEnabled = false;
        }
Ejemplo n.º 3
0
        public SessionManager(string serverIP, int serverPort, MainWindow mainWindow)
        {
            this.serverIP = serverIP;
            this.serverPort = serverPort;
            this.mainWindow = mainWindow;

            utf8 = new UTF8Encoding();
            separator_r_n = utf8.GetBytes("\r\n");
        }
Ejemplo n.º 4
0
 internal static void init(MainWindow mainWindowp)
 {
     MyLogger.mainWindow = mainWindowp;
 }