private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { o.CleanUp(); if (mesaj != null) { mesaj.Close(); mesaj = null; } }
public void btnSync_Click(object sender, RoutedEventArgs e) { //VwService.SerSettings.dirLocal = textBox2.Text; // TODO: ver ca e path valabil //VwService.FileStructClass.RunSync(); btnSync.IsEnabled = false; //return; bool mapNetwork = false; if (mesaj != null) { mesaj = null; } if (e == null) // call din mesaj, cu username si password, cu de toate { // user, pass disponibile mapNetwork = RemoteConnect(); } else // synchronize button press call { pathProviderRemote = atextBox2.Text; if (!string.IsNullOrEmpty(textBox2.Text) && !textBox2.Text.Equals(pathProviderLocal)) { pathProviderLocal = textBox2.Text; SerSettings.dirLocal = pathProviderLocal; SerSettings.UpdateFileLocations(Settings.backSlash, Settings.serLogFile, Settings.serPasswFile); } Settings.SearchPasswordFile( SerSettings.passwFilePath, Settings.GetDirLocalName(pathProviderRemote), ref user, ref pass); if (!string.IsNullOrEmpty(user)) { mapNetwork = RemoteConnect(); } } bool serviceWasRunning = Exec.SerIsOn(); //Exec.SerStop(); SerSettings.run = false; Exec.SerDelete(serviceWasRunning); SetServiceGui(false); /* * // directorul local modificat -> restart serviciul * string s1 = RegistryLocal.GetLocalPath(), * s2 = textBox2.Text; * if(s1.length==(s2.length+1)) * if(!hh.Equals()) * { * MessageBox.Show(hh+Environment.NewLine+ textBox2.Text); * Exec.SerDelete(); * }*/ //if (Exec.SerIsOn()) System.Threading.Thread.Sleep(100); SyncOperationStatistics stats = null; try { stats = o.Sync(false, pathProviderLocal, pathProviderRemote); } catch// (Exception ex) { } if (stats == null) // => show why sync result was null { if (e != null) { infoLbl.Content = "Synchronization failed"; if (o.set.directoryStructureIsOk && !o.set.remotePathIsOk) { infoLbl.Content += string.Format("Remote path should not contain the '{0}' character", Settings.chSlash); } else if (!o.set.directoryStructureIsOk) { infoLbl.Content += (Utils.DirectoryExists(o.set.dirRemote) ? "Directory exists, but without rights." : "Directory does not exist."); } else if (Utils.IsValidPath(o.set.dirRemote)) { mesaj = new ConnectionMessage(); mesaj.OkClick += Mesaj_OkClick; mesaj.lblInfo.Content = string.Format("Connection solutions:{0}{0}" + " - update username and password and click Ok{0}" + " - or before synchronization make sure you can{0} reach the path from Windows Explorer", Environment.NewLine); if (e != null) { mesaj.Show(); } } } if (o.set != null && o.set.directoryCleanupRequired) { o.set.CleanupLocalDir(); } } else { infoLbl.Content = //MessageBox.Show( string.Format( " Task done in {0}ms. Download changes total:{1} Download changes applied:{2} Download changes failed:{3}", // UploadChangesTotal: {6} stats.SyncEndTime.Subtract(stats.SyncStartTime).Milliseconds, //Environment.NewLine, stats.DownloadChangesTotal, stats.DownloadChangesApplied, stats.DownloadChangesFailed //stats.UploadChangesTotal ); UpdateSyncPathGui(o.set); } if (mapNetwork) { RemoteDisconnect(); Settings.UpdatePasswordFile(SerSettings.passwFilePath, Settings.GetDirLocalName(pathProviderRemote), user, pass); } // restart service if (stats != null && serviceWasRunning && !Exec.SerIsOn()) { btnService_Click(null, null); } btnSync.IsEnabled = true; }