internal void OnUnsuccessfulCalibration(CalibrationContext context, PlateCalibration plateCalibration) { m_PlateToReport = null; try { string tempFilename = Path.GetTempFileName(); plateCalibration.SaveContext(tempFilename); string zippedFileName = Path.GetFullPath(tempFilename + ".zip"); ZipUnzip.Zip(tempFilename, zippedFileName); m_PlateToReport = File.ReadAllBytes(zippedFileName); File.Delete(tempFilename); File.Delete(zippedFileName); } catch (Exception ex) { Trace.WriteLine(ex); } if (m_PlateToReport != null) { double mbSize = m_PlateToReport.Length * 1.0 / (1024 * 1024); btnSendProblemFit.Text = string.Format("Report Unsolved Plate ({0} Mb)", mbSize.ToString("0.00")); btnSendProblemFit.Visible = true; } }
public static void SendOcrErrorReport(VideoController videoController, string errorMessage, ITimestampOcr timestampOCR, Dictionary <string, Tuple <uint[], int, int> > images, uint[] lastUnmodifiedImage, Bitmap ocdDebugImage, string email) { string tempDir = Path.GetFullPath(Path.GetTempPath() + @"\" + Guid.NewGuid().ToString()); string tempFile = Path.GetTempFileName(); try { Directory.CreateDirectory(tempDir); int fieldAreaWidth = timestampOCR.InitializationData.OSDFrame.Width; int fieldAreaHeight = timestampOCR.InitializationData.OSDFrame.Height; int frameWidth = timestampOCR.InitializationData.FrameWidth; int frameHeight = timestampOCR.InitializationData.FrameHeight; foreach (string key in images.Keys) { uint[] pixels = images[key].Item1; Bitmap img = null; if (pixels.Length == fieldAreaWidth * fieldAreaHeight) { img = Pixelmap.ConstructBitmapFromBitmapPixels(pixels, fieldAreaWidth, fieldAreaHeight); } else if (pixels.Length == frameWidth * frameHeight) { img = Pixelmap.ConstructBitmapFromBitmapPixels(pixels, frameWidth, frameHeight); } else if (pixels.Length == images[key].Item2 * images[key].Item3) { img = Pixelmap.ConstructBitmapFromBitmapPixels(pixels, images[key].Item2, images[key].Item3); } if (img != null) { img.Save(Path.GetFullPath(string.Format(@"{0}\{1}", tempDir, key)), ImageFormat.Bmp); } } if (lastUnmodifiedImage != null) { Bitmap fullFrame = Pixelmap.ConstructBitmapFromBitmapPixels(lastUnmodifiedImage, frameWidth, frameHeight); fullFrame.Save(Path.GetFullPath(string.Format(@"{0}\full-frame.bmp", tempDir)), ImageFormat.Bmp); } if (ocdDebugImage != null) { ocdDebugImage.Save(Path.GetFullPath(string.Format(@"{0}\ocr-debug-image.bmp", tempDir)), ImageFormat.Bmp); } ZipUnzip.Zip(tempDir, tempFile, false); byte[] attachment = File.ReadAllBytes(tempFile); var binding = new BasicHttpBinding(); var address = new EndpointAddress("http://www.tangra-observatory.org/TangraErrors/ErrorReports.asmx"); var client = new TangraService.ServiceSoapClient(binding, address); string errorReportBody = errorMessage + "\r\n\r\n" + "OCR OSD Engine: " + timestampOCR.NameAndVersion() + "\r\n" + "OSD Type: " + timestampOCR.OSDType() + "\r\n" + "Frames Range: [" + videoController.VideoFirstFrame + ", " + videoController.VideoLastFrame + "]\r\n" + "File Name: " + videoController.FileName + "\r\n" + "Video File Type:" + videoController.CurrentVideoFileType + "\r\n\r\n" + "Contact Email: " + email + "\r\n\r\n" + frmSystemInfo.GetFullVersionInfo(); List <string> errorMesages = timestampOCR.GetCalibrationErrors(); if (errorMesages != null && errorMesages.Count > 0) { errorReportBody += "\r\n\r\n" + string.Join("\r\n", errorMesages); } client.ReportErrorWithAttachment( errorReportBody, string.Format("CalibrationFrames-{0}.zip", Guid.NewGuid().ToString()), attachment); } finally { if (Directory.Exists(tempDir)) { try { Directory.Delete(tempDir, true); } catch { } } if (File.Exists(tempFile)) { try { File.Delete(tempFile); } catch { } } } }
public void RunTangra3UpdaterForWindows() { try { string currentPath = AppDomain.CurrentDomain.BaseDirectory; string updaterFileName = Path.GetFullPath(currentPath + "\\Tangra3Update.zip"); int currUpdVer = CurrentlyInstalledTangra3UpdateVersion(); int servUpdVer = int.Parse(tangra3UpdateServerVersion); if (!File.Exists(Path.GetFullPath(currentPath + "\\Tangra3Update.exe")) || /* If there is no Tangra3Update.exe*/ servUpdVer > currUpdVer /* Or it is an older version ... */ ) { if (servUpdVer > currUpdVer) { Trace.WriteLine(string.Format("Update required for 'Tangra3Update.exe': local version: {0}; server version: {1}", currUpdVer, servUpdVer)); } Uri updateUri = new Uri(UpdateLocation + "/Tangra3Update.zip"); HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(updateUri); httpRequest.Method = "GET"; httpRequest.Timeout = 1200000; //1200 sec = 20 min HttpWebResponse response = null; try { response = (HttpWebResponse)httpRequest.GetResponse(); Stream streamResponse = response.GetResponseStream(); try { try { if (File.Exists(updaterFileName)) { File.Delete(updaterFileName); } using (BinaryReader reader = new BinaryReader(streamResponse)) using (BinaryWriter writer = new BinaryWriter(new FileStream(updaterFileName, FileMode.Create))) { byte[] chunk = null; do { chunk = reader.ReadBytes(1024); writer.Write(chunk); }while (chunk != null && chunk.Length == 1024); writer.Flush(); } } catch (UnauthorizedAccessException uex) { m_VideoController.ShowMessageBox( uex.Message + "\r\n\r\nYou may need to run Tangra3 as administrator to complete the update.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (Exception ex) { Trace.WriteLine(ex); } if (File.Exists(updaterFileName)) { string tempOutputDir = Path.ChangeExtension(Path.GetTempFileName(), ""); Directory.CreateDirectory(tempOutputDir); try { string zippedFileName = updaterFileName; ZipUnzip.UnZip(updaterFileName, tempOutputDir, true); string[] files = Directory.GetFiles(tempOutputDir); updaterFileName = Path.ChangeExtension(updaterFileName, ".exe"); System.IO.File.Copy(files[0], updaterFileName, true); System.IO.File.Delete(zippedFileName); } finally { Directory.Delete(tempOutputDir, true); } } } finally { streamResponse.Close(); } } catch (WebException) { MessageBox.Show("There was an error trying to download the Tangra3Update program. Please ensure that you have an active internet connection and try again later.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { // Close response if (response != null) { response.Close(); } } } // Make sure after the update is completed a new check is done. // This will check for Add-in updates Settings.Default.LastCheckedForUpdates = DateTime.Now.AddDays(-15); Settings.Default.Save(); updaterFileName = Path.GetFullPath(currentPath + "\\Tangra3Update.exe"); if (File.Exists(updaterFileName)) { var processInfo = new ProcessStartInfo(); if (System.Environment.OSVersion.Version.Major > 5) { // UAC Elevate as Administrator for Windows Vista, Win7 and later processInfo.Verb = "runas"; } processInfo.FileName = updaterFileName; processInfo.Arguments = string.Format("{0}", TangraConfig.Settings.Generic.AcceptBetaUpdates ? "beta" : "full"); Process.Start(processInfo); } } catch (Exception ex) { Trace.WriteLine(ex, "Update"); m_MainFrom.pnlNewVersionAvailable.Enabled = true; } }
private void bgWorker_DoWork(object sender, DoWorkEventArgs e) { StartProgressBar = true; Blackbox = Visibility.Visible; #region Backup if (_inbackup == true) { string backupfolder = AppDomain.CurrentDomain.BaseDirectory + @"backup\"; string uploadfolder = AppDomain.CurrentDomain.BaseDirectory + @"upload\"; try { //System.IO.Directory.Delete(_root, true); //ZipUnzip.ProgressDelegate txt; string file = @"" + DateTime.Now.Year.ToString("0000") + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00") + "_" + DateTime.Now.Hour.ToString("00") + DateTime.Now.Minute.ToString("00") + DateTime.Now.Second.ToString("00") + ".gz"; string backupfile = uploadfolder + file; string db1file = ConnectionString + "SimDataBase1.mdb"; string db2file = ConnectionString + "SimDataBase2.mdb"; string db3file = ConnectionString + "SimDataBase3.mdb"; string db4file = ConnectionString + "SimDataBase4.mdb"; if (ConnectionString == @"|DataDirectory|\DataBase\") { db1file = AppDomain.CurrentDomain.BaseDirectory + @"DataBase\SimDataBase1.mdb"; db2file = AppDomain.CurrentDomain.BaseDirectory + @"DataBase\SimDataBase2.mdb"; db3file = AppDomain.CurrentDomain.BaseDirectory + @"DataBase\SimDataBase3.mdb"; db4file = AppDomain.CurrentDomain.BaseDirectory + @"DataBase\SimDataBase4.mdb"; } if (!System.IO.Directory.Exists(backupfolder)) { System.IO.Directory.CreateDirectory(backupfolder); } if (!System.IO.Directory.Exists(uploadfolder)) { System.IO.Directory.CreateDirectory(uploadfolder); } System.IO.File.Copy(db1file, backupfolder + "SimDataBase1.mdb", true); System.IO.File.Copy(db2file, backupfolder + "SimDataBase2.mdb", true); System.IO.File.Copy(db3file, backupfolder + "SimDataBase3.mdb", true); System.IO.File.Copy(db4file, backupfolder + "SimDataBase4.mdb", true); //MessageBox.Show(uploadfolder); ZipUnzip.CompressDirectory(backupfolder, backupfile, null); if (OnNuvem == true) { new Ftp().UploadFileFTP(backupfile, _nuvemftp + file, bgWorker); } else { System.IO.File.Copy(backupfile, BackupPath + @"\" + file, true); } } catch (Exception ex) { e.Cancel = true; System.Windows.MessageBox.Show(ex.Message, "Sim.App.DataTools", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information); } System.IO.Directory.Delete(backupfolder, true); System.IO.Directory.Delete(uploadfolder, true); } #endregion #region DeleteBackup if (_indelete == true) { LabelBalckbox = "Excluidno Backup " + SelectedItem + "!"; if (OnNuvem == true) { System.IO.File.Delete(BackupPath + @"\" + SelectedItem); } else { new Ftp().DeleteFileFTP(new Uri(_nuvemftp + SelectedItem)); } } #endregion #region RestoreBackup if (_inrestore == true) { string downloadfolder = AppDomain.CurrentDomain.BaseDirectory + @"download\"; try { string backupfile = downloadfolder + SelectedItem; if (!System.IO.Directory.Exists(downloadfolder)) { System.IO.Directory.CreateDirectory(downloadfolder); } string restorefolder = ConnectionString; if (ConnectionString == @"|DataDirectory|\DataBase\") { restorefolder = AppDomain.CurrentDomain.BaseDirectory + @"DataBase\"; } if (OnNuvem == true) { new Ftp().DownloadFileFTP(_nuvemftp + SelectedItem, downloadfolder + SelectedItem, bgWorker); ZipUnzip.DecompressDirectory(downloadfolder + SelectedItem, restorefolder, null); } else { //System.IO.File.Copy(backupfile, BackupPath + @"\" + SelectedItem, true); ZipUnzip.DecompressDirectory(BackupPath + @"\" + SelectedItem, restorefolder, null); } } catch (Exception ex) { e.Cancel = true; System.Windows.MessageBox.Show(ex.Message, "Sim.App.Publisher", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information); } System.IO.Directory.Delete(downloadfolder, true); } #endregion try { if (OnNuvem == false) { BackupList = Files.ListFiles(BackupPath, "*.*"); } else { BackupList = Ftp.GetFilesInFtpDirectory(_nuvemftp); } } catch { BackupList = null; } }