SysTray() { InitializeComponent(); CreateHandle(); Icon = AssemblyRoutines.GetAppIcon(); Service.StateChanged += delegate { this.Invoke(() => { StartStop.Checked = Service.Running; string title = "Cistera Screen Capture"; if (Service.Running) { notifyIcon.Icon = Icon; title += " started"; } else { //notifyIcon.Icon = Icon.FromHandle(ImageRoutines.GetGreyScale(Icon.ToBitmap()).GetHicon()); notifyIcon.Icon = Icon.FromHandle(ImageRoutines.GetInverted(Icon.ToBitmap()).GetHicon()); title += " stopped"; } notifyIcon.Text = title; }); }; }
public static void Main(string[] args) { try { //Wpf.Message.ResourceDictionaryPath = "assembly=" + System.Reflection.Assembly.GetEntryAssembly().EscapedCodeBase + ";resources/style.xaml"; //Uri u = new System.Uri("/" + PathRoutines.GetFileNameFromPath(System.Reflection.Assembly.GetEntryAssembly().EscapedCodeBase) + ";component/resources/style.xaml", System.UriKind.Relative); //System.Windows.ResourceDictionary rd = new System.Windows.ResourceDictionary(); //System.Windows.Application.LoadComponent(rd, u); //Wpf.Message.ResourceDictionary = rd; //System.Windows.Resources.StreamResourceInfo info = System.Windows.Application.GetContentStream(u); //System.Windows.Markup.XamlReader reader = new System.Windows.Markup.XamlReader(); //Wpf.Message.ResourceDictionary = (System.Windows.ResourceDictionary)reader.LoadAsync(info.Stream); Log.Main.Inform("Version: " + AssemblyRoutines.GetAppVersion()); string user = ProcessRoutines.GetProcessUserName(); string m = "User: "******" (as administrator)"; } Log.Main.Inform(m); ProcessRoutines.RunSingleProcessOnly(); if (ProgramRoutines.IsParameterSet <CommandLineParameters>(CommandLineParameters.INITIAL_CONFIGURATION)) { Message.Inform("Please configure service in the next window."); SettingsWindow.OpenDialog(); return; } #if !test Application.Run(SysTray.This); #else UiApiClient.testCreateInstanceContext(); SettingsWindow.Open(); Application.Run(SysTray.This); //UiApiClient.testSubscribe(); //UiApiClient.testSubscribe(); //Thread.Sleep(1000); //UiApiClient.testCloseInstanceContext(); //UiApiClient.testCreateInstanceContext(); //UiApiClient.testSubscribe(); //UiApiClient.testSubscribe(); //for (; ; ) //{ // System.Threading.Thread.Sleep(10000); //} #endif } catch (Exception e) { LogMessage.Error(e); } finally { Exit(); } }
static void Main() { try { Log.Main.Inform("Application version: " + AssemblyRoutines.GetAppVersion()); string m = "Appication user: "******" ("; if (WindowsUserRoutines.CurrentUserIsAdministrator()) { m += "administrator"; if (WindowsUserRoutines.CurrentUserHasElevatedPrivileges()) { m += ", elevated privileges"; } else { m += ", not elevated privileges"; } } else { m += "not administrator"; } Log.Main.Inform(m + ")"); ServiceBase.Run(new Service()); } catch (Exception e) { Log.Main.Error(e); } }
public SettingsForm() { InitializeComponent(); this.Icon = AssemblyRoutines.GetAppIcon(); Text = Program.Name + ": Settings"; load_settings(); }
//static public void OpenDialog() //{ // if (SettingsForm.This.Visible) // SettingsForm.This.Activate(); // else // SettingsForm.This.ShowDialog(); //} //public static SettingsForm This //{ // get // { // if (_This == null || _This.IsDisposed) // _This = new SettingsForm(); // return _This; // } //} //static SettingsForm _This = null; public SettingsForm() { InitializeComponent(); this.Icon = AssemblyRoutines.GetAppIcon(); Text = Application.ProductName; //important.Text = "Important! Letting folder '" + Config.StorageDir + "' be synchronized by a remote drive application may bring to malfunction."; load_settings(); }
public AboutBox() { InitializeComponent(); this.Icon = AssemblyRoutines.GetAppIcon(); this.Text = String.Format("About {0}", AssemblyTitle); this.labelProductName.Text = AssemblyProduct; this.labelVersion.Text = "Version: " + Program.Version;// AssemblyRoutines.GetAssemblyCompiledTime(Assembly.GetEntryAssembly()).ToString("yyMMdd-HHmmss"); //String.Format("Version {0}", AssemblyVersion); this.labelCopyright.Text = AssemblyCopyright; this.labelCompanyName.Text = AssemblyCompany; this.textBoxDescription.Text = AssemblyDescription; }
public TextForm(string caption, string t, bool html) { InitializeComponent(); this.Icon = AssemblyRoutines.GetAppIcon(); Text = AboutBox.AssemblyProduct + ": " + caption;// Application.ProductName; if (html) { browser.DocumentText = t; browser.BringToFront(); } else { textBox.Text = t; textBox.BringToFront(); } }
AboutWindow() { InitializeComponent(); System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(this); Icon = AssemblyRoutines.GetAppIconImageSource(); ContentRendered += delegate { //this.MinHeight = this.ActualHeight; //this.MaxHeight = this.ActualHeight; //this.MinWidth = this.ActualWidth; //FormattedText formattedText = new FormattedText(AssemblyProduct, System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight); //var pagePadding = text.Document.PagePadding; //var borderThickness = text.BorderThickness; //text.Width = formattedText.Width // + pagePadding.Left + pagePadding.Right // + borderThickness.Left + borderThickness.Right; }; WpfRoutines.AddFadeEffect(this, 300); Title = "Cistera Screen Capture"; try { set(new AssemblyRoutines.AssemblyInfo(Log.AppDir + "\\CisteraScreenCaptureService.exe")); } catch (Exception e) { Message.Error(e); } TextRange tr = new TextRange(text.Document.ContentEnd, text.Document.ContentEnd); tr.Text = "\r\n\r\n"; set(new AssemblyRoutines.AssemblyInfo()); WindowStartupLocation = WindowStartupLocation.CenterScreen; //WindowStartupLocation = WindowStartupLocation.CenterScreen; //DefaultServerIp.ValueDataType = typeof(IPAddress); }
public FileFilterForm(string folder, Regex r) { InitializeComponent(); this.Icon = AssemblyRoutines.GetAppIcon(); Text = "Filtered Files"; files.ReadOnly = true; Load += delegate { foreach (string f in FileSystemRoutines.GetFiles(folder)) { int i = files.Items.Add(f); if (r.IsMatch(f)) { files.SelectedIndex = i; } } }; }
SettingsWindow() { InitializeComponent(); System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(this); Icon = AssemblyRoutines.GetAppIconImageSource(); ContentRendered += delegate { this.MinHeight = this.ActualHeight; this.MaxHeight = this.ActualHeight; this.MinWidth = this.ActualWidth; }; IsVisibleChanged += (object sender, DependencyPropertyChangedEventArgs e) => { if (Visibility == Visibility.Visible) { DoubleAnimation da = new DoubleAnimation(0, 1, TimeSpan.FromMilliseconds(300)); this.BeginAnimation(UIElement.OpacityProperty, da); } }; Closing += (object sender, System.ComponentModel.CancelEventArgs e) => { if (Opacity > 0) { e.Cancel = true; DoubleAnimation da = new DoubleAnimation(1, 0, TimeSpan.FromMilliseconds(200)); da.Completed += delegate { Close(); }; this.BeginAnimation(UIElement.OpacityProperty, da); } }; WindowStartupLocation = WindowStartupLocation.CenterScreen; //WindowStartupLocation = WindowStartupLocation.CenterScreen; //DefaultServerIp.ValueDataType = typeof(IPAddress); set(); }
SettingsWindow() { InitializeComponent(); System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(this); Icon = AssemblyRoutines.GetAppIconImageSource(); ContentRendered += delegate { //this.MinHeight = this.ActualHeight; //this.MaxHeight = this.ActualHeight; //this.MinWidth = this.ActualWidth; }; WpfRoutines.AddFadeEffect(this, 300); WindowStartupLocation = WindowStartupLocation.CenterScreen; //WindowStartupLocation = WindowStartupLocation.CenterScreen; //DefaultServerIp.ValueDataType = typeof(IPAddress); general = UiApiClient.GetServiceSettings(); if (general == null) { ok.IsEnabled = false; reset.IsEnabled = false; Message.Error("The service is unavailable."); return; } set(); if (!ProcessRoutines.ProcessHasElevatedPrivileges() && !ProcessRoutines.ProcessIsSystem() /*used for configuration during installing*/) { ok.IsEnabled = false; reset.IsEnabled = false; if (Message.YesNo("Settings modification requires elevated privileges. Would you like to restart this application 'As Administrator'?")) { ProcessRoutines.Restart(true); } } }
public Template2Form(Template2 t) { InitializeComponent(); this.Icon = AssemblyRoutines.GetAppIcon(); Text = Application.ProductName + ": additional properties of '" + t.Template.Name + "'"; template2 = t; Active.Checked = t.Active; Comment.Text = t.Comment; OrderWeight.Value = (decimal)t.OrderWeight; if (t.FileFilterRegex != null) { FileFilterRegex.Text = Serialization.Json.Serialize(t.FileFilterRegex, false); } else { FileFilterRegex.Text = ""; } }
static Program() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); AppDomain.CurrentDomain.UnhandledException += delegate(object sender, UnhandledExceptionEventArgs args) { Exception e = (Exception)args.ExceptionObject; Log.Message.Error(e); Environment.Exit(0); }; Version = AssemblyRoutines.GetAssemblyCompiledTime(Assembly.GetEntryAssembly()).ToString("yyMMdd-HHmmss"); //String.Format("Version {0}", AssemblyVersion); Name = Application.ProductName; Message.TopMost = true; Config.Reload(); Log.Message.DisableStumblingDialogs = false; Log.ShowDeleteOldLogsDialog = false; Log.Initialize(Log.Mode.ONLY_LOG, Log.CompanyCommonDataDir, true); }
SysTray() { InitializeComponent(); CreateHandle(); Load += delegate { Icon = AssemblyRoutines.GetAppIcon(); ServiceStateChanged(UiApiClient.GetServiceStatus()); silentlyToolStripMenuItem.Checked = !Settings.View.DisplayNotifications; //string __file; //Cliver.CisteraScreenCaptureService.Settings.GeneralSettings general = UiApiClient.GetServiceSettings(out __file); //if(general.CapturedMonitorRectangle == null) //{ // if(string.IsNullOrWhiteSpace( general.CapturedMonitorDeviceName)) // general.CapturedMonitorDeviceName = Cliver.CisteraScreenCaptureService.MonitorRoutines.GetDefaultMonitorName(); // if (string.IsNullOrWhiteSpace(general.CapturedMonitorDeviceName)) // LogMessage.Error("Could not detect default monitor."); // else // { // WinApi.User32.RECT? a = Cliver.CisteraScreenCaptureService.MonitorRoutines.GetMonitorAreaByMonitorName(general.CapturedMonitorDeviceName); // if (a == null) // { // string defaultMonitorName = Cliver.CisteraScreenCaptureService.MonitorRoutines.GetDefaultMonitorName(); // LogMessage.Warning("Monitor '" + general.CapturedMonitorDeviceName + "' was not found. Using default one '" + defaultMonitorName + "'"); // general.CapturedMonitorDeviceName = defaultMonitorName; // a = Cliver.CisteraScreenCaptureService.MonitorRoutines.GetMonitorAreaByMonitorName(general.CapturedMonitorDeviceName); // if (a == null) // LogMessage.Error("Monitor '" + general.CapturedMonitorDeviceName + "' was not found."); // } // general.CapturedMonitorRectangle = a; // } // general.Save(__file); //} }; }
static void Main() { try { Log.Main.Inform("Version: " + AssemblyRoutines.GetAppVersion()); string user = ProcessRoutines.GetProcessUserName(); string m = "User: "******" (as administrator)"; } Log.Main.Inform(m); #if !test ServiceBase.Run(new Service()); #else MpegStream.Start(1, "-f gdigrab -framerate 10 -f rtp_mpegts -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params aMg7BqN047lFN72szkezmPyN1qSMilYCXbqP/sCt srtp://127.0.0.1:5920"); //Service.sessionChanged(1, true); //System.Threading.Thread.Sleep(1000000); //s.Stop //MpegStream.Start(1, ""); UserSessionApi.OpenApi(); UiApi.OpenApi(); ServiceControllerStatus scs = ServiceControllerStatus.Running; for (; ;) { System.Threading.Thread.Sleep(10000); UiApi.Message(MessageType.INFORM, "test"); scs = scs == ServiceControllerStatus.Running ? ServiceControllerStatus.Stopped : ServiceControllerStatus.Running; } #endif } catch (Exception e) { Log.Main.Error(e); } }
public static void Main(string[] args) { try { uint dwSessionId = WinApi.Wts.WTSGetActiveConsoleSessionId(); MpegStream.Start(dwSessionId, "-f gdigrab -framerate 10 -f rtp_mpegts -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params aMg7BqN047lFN72szkezmPyN1qSMilYCXbqP/sCt srtp://127.0.0.1:5920"); //Process mpeg_stream_process; //var processId = Win32Process.CreateProcessInConsoleSession("cmd"); //mpeg_stream_process = Process.GetProcessById((int)processId); //ProcessRoutines.AntiZombieTracker.Track(mpeg_stream_process); // try // { // var p = new Process(); // p.StartInfo.UseShellExecute = false; // //const string file = "cmd.exe"; // const string file = @"psexec.exe"; // p.StartInfo.WorkingDirectory = Path.GetDirectoryName(file); // p.StartInfo.FileName = Path.GetFileName(file); // //proc.StartInfo.Domain = "WIN08"; // p.StartInfo.Arguments = "-i -d -s cmd"; // //p.StartInfo.UserName = "******"; // //var password = new System.Security.SecureString(); // //foreach (var c in "123") // // password.AppendChar(c); // //p.StartInfo.Password = password; // p.StartInfo.LoadUserProfile = false; // p.Start(); // } // catch (Exception e) // { // Console.WriteLine(e); // } //MpegStream.Start("-f gdigrab -framerate 10 -f rtp_mpegts -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params aMg7BqN047lFN72szkezmPyN1qSMilYCXbqP/sCt srtp://127.0.0.1:5920"); //Thread.Sleep(2000); //MpegStream.Stop(); Log.Main.Inform("Version: " + AssemblyRoutines.GetAppVersion()); string m = "User: "******"("; if (WindowsUserRoutines.CurrentUserIsAdministrator()) { m += "administrator"; if (WindowsUserRoutines.CurrentUserHasElevatedPrivileges()) { m += ", elevated privileges"; } else { m += ", not elevated privileges"; } } else { m += "not administrator"; } Log.Main.Inform(m + ")"); ProcessRoutines.RunSingleProcessOnly(); Service.Running = true; Application.Run(SysTray.This); } catch (Exception e) { Message.Error(e); } finally { Environment.Exit(0); } }
public TemplateForm(TemplateManager templateManager) { InitializeComponent(); Icon = AssemblyRoutines.GetAppIcon(); Text = Program.Name + ": Template Editor"; this.templateManager = templateManager; initializeAnchorsTable(); initializeConditionsTable(); initializeFieldsTable(); picture.MouseDown += delegate(object sender, MouseEventArgs e) { if (pages == null) { return; } Point p = new Point((int)(e.X / (float)pictureScale.Value), (int)(e.Y / (float)pictureScale.Value)); ResizebleBox rb = findResizebleBox(p, out ResizebleBoxSides resizebleBoxSide); if (rb != null) { drawingMode = resizebleBoxSide == ResizebleBoxSides.Left || resizebleBoxSide == ResizebleBoxSides.Right ? DrawingModes.resizingSelectionBoxV : DrawingModes.resizingSelectionBoxH; Cursor.Current = drawingMode == DrawingModes.resizingSelectionBoxV ? Cursors.VSplit : Cursors.HSplit; selectionBoxPoint0 = rb.R.Location; selectionBoxPoint1 = rb.R.Location; selectionBoxPoint2 = new Point(rb.R.Right, rb.R.Bottom); } else { drawingMode = DrawingModes.drawingSelectionBox; selectionBoxPoint0 = p; selectionBoxPoint1 = p; selectionBoxPoint2 = p; } selectionCoordinates.Text = selectionBoxPoint1.ToString(); }; picture.MouseMove += delegate(object sender, MouseEventArgs e) { if (pages == null) { return; } Point p = new Point((int)(e.X / (float)pictureScale.Value), (int)(e.Y / (float)pictureScale.Value)); switch (drawingMode) { case DrawingModes.NULL: selectionCoordinates.Text = p.ToString(); if (findResizebleBox(p, out ResizebleBoxSides resizebleBoxSide) != null) { Cursor.Current = resizebleBoxSide == ResizebleBoxSides.Left || resizebleBoxSide == ResizebleBoxSides.Right ? Cursors.VSplit : Cursors.HSplit; } else { Cursor.Current = Cursors.Default; } return; case DrawingModes.drawingSelectionBox: if (selectionBoxPoint0.X < p.X) { selectionBoxPoint1.X = selectionBoxPoint0.X; selectionBoxPoint2.X = p.X; } else { selectionBoxPoint1.X = p.X; selectionBoxPoint2.X = selectionBoxPoint0.X; } if (selectionBoxPoint0.Y < p.Y) { selectionBoxPoint1.Y = selectionBoxPoint0.Y; selectionBoxPoint2.Y = p.Y; } else { selectionBoxPoint1.Y = p.Y; selectionBoxPoint2.Y = selectionBoxPoint0.Y; } break; case DrawingModes.resizingSelectionBoxV: if (Math.Abs(selectionBoxPoint2.X - p.X) < Math.Abs(p.X - selectionBoxPoint1.X)) { selectionBoxPoint2.X = p.X; } else { selectionBoxPoint1.X = p.X; } break; case DrawingModes.resizingSelectionBoxH: if (Math.Abs(selectionBoxPoint2.Y - p.Y) < Math.Abs(p.Y - selectionBoxPoint1.Y)) { selectionBoxPoint2.Y = p.Y; } else { selectionBoxPoint1.Y = p.Y; } break; } selectionCoordinates.Text = selectionBoxPoint1.ToString() + ":" + selectionBoxPoint2.ToString(); RectangleF r = new RectangleF(selectionBoxPoint1.X, selectionBoxPoint1.Y, selectionBoxPoint2.X - selectionBoxPoint1.X, selectionBoxPoint2.Y - selectionBoxPoint1.Y); clearImageFromBoxes(); drawBoxes(Settings.Appearance.SelectionBoxColor, Settings.Appearance.SelectionBoxBorderWidth, new List <System.Drawing.RectangleF> { r }); }; picture.MouseUp += delegate(object sender, MouseEventArgs e) { try { if (pages == null) { return; } if (drawingMode == DrawingModes.NULL) { return; } drawingMode = DrawingModes.NULL; Template.RectangleF r = new Template.RectangleF(selectionBoxPoint1.X, selectionBoxPoint1.Y, selectionBoxPoint2.X - selectionBoxPoint1.X, selectionBoxPoint2.Y - selectionBoxPoint1.Y); if (r.Width == 0 || r.Y == 0)//accidental tap { return; } switch (settingMode) { case SettingModes.SetAnchor: { if (currentAnchorControl == null) { break; } currentAnchorControl.SetTagFromControl(); Template.Anchor a = (Template.Anchor)currentAnchorControl.Row.Tag; a.Position = new Template.PointF { X = r.X, Y = r.Y }; try { switch (a.Type) { case Template.Anchor.Types.PdfText: { Template.Anchor.PdfText pt = (Template.Anchor.PdfText)a; pt.CharBoxs = new List <Template.Anchor.PdfText.CharBox>(); List <Pdf.Line> lines = Pdf.RemoveDuplicatesAndGetLines(Pdf.GetCharBoxsSurroundedByRectangle(pages[currentPageI].PdfCharBoxs, r.GetSystemRectangleF(), true), null); foreach (Pdf.Line l in lines) { foreach (Pdf.CharBox cb in l.CharBoxs) { pt.CharBoxs.Add(new Template.Anchor.PdfText.CharBox { Char = cb.Char, Rectangle = new Template.RectangleF(cb.R.X, cb.R.Y, cb.R.Width, cb.R.Height), }); } } pt.Size = new Template.SizeF { Width = r.Width, Height = r.Height }; } break; case Template.Anchor.Types.OcrText: { Template.Anchor.OcrText ot = (Template.Anchor.OcrText)a; ot.CharBoxs = new List <Template.Anchor.OcrText.CharBox>(); var selectedOcrCharBoxs = new List <Ocr.CharBox>(); if (ot.OcrEntirePage) { selectedOcrCharBoxs.AddRange(Ocr.GetCharBoxsSurroundedByRectangle(pages[currentPageI].ActiveTemplateOcrCharBoxs, r.GetSystemRectangleF())); } else { foreach (Ocr.CharBox cb in Ocr.This.GetCharBoxs(pages[currentPageI].GetRectangleFromActiveTemplateBitmap(r.X / Settings.Constants.Image2PdfResolutionRatio, r.Y / Settings.Constants.Image2PdfResolutionRatio, r.Width / Settings.Constants.Image2PdfResolutionRatio, r.Height / Settings.Constants.Image2PdfResolutionRatio))) { cb.R.X += r.X; cb.R.Y += r.Y; selectedOcrCharBoxs.Add(cb); } } foreach (Ocr.Line l in Ocr.GetLines(selectedOcrCharBoxs, null)) { foreach (Ocr.CharBox cb in l.CharBoxs) { ot.CharBoxs.Add(new Template.Anchor.OcrText.CharBox { Char = cb.Char, Rectangle = new Template.RectangleF(cb.R.X, cb.R.Y, cb.R.Width, cb.R.Height), }); } } ot.Size = new Template.SizeF { Width = r.Width, Height = r.Height }; } break; case Template.Anchor.Types.ImageData: { Template.Anchor.ImageData id = (Template.Anchor.ImageData)a; using (Bitmap rb = pages[currentPageI].GetRectangleFromActiveTemplateBitmap(r.X / Settings.Constants.Image2PdfResolutionRatio, r.Y / Settings.Constants.Image2PdfResolutionRatio, r.Width / Settings.Constants.Image2PdfResolutionRatio, r.Height / Settings.Constants.Image2PdfResolutionRatio)) { using (Bitmap b = ImageData.GetScaled(rb, Settings.Constants.Image2PdfResolutionRatio)) id.Image = new ImageData(b, false); } } break; default: throw new Exception("Unknown option: " + a.Type); } setAnchorRow(currentAnchorControl.Row, a); clearImageFromBoxes(); findAndDrawAnchor(a.Id); } finally { anchors.EndEdit(); } } break; case SettingModes.SetField: { if (fields.SelectedRows.Count < 1) { break; } var row = fields.SelectedRows[0]; Template.Field f = (Template.Field)row.Tag; f.Rectangle = r; if (f.LeftAnchor != null) { Page.AnchorActualInfo aai = pages[currentPageI].GetAnchorActualInfo(f.LeftAnchor.Id); f.LeftAnchor.Shift = aai.Shift.Width; } if (f.TopAnchor != null) { Page.AnchorActualInfo aai = pages[currentPageI].GetAnchorActualInfo(f.TopAnchor.Id); f.TopAnchor.Shift = aai.Shift.Height; } if (f.RightAnchor != null) { Page.AnchorActualInfo aai = pages[currentPageI].GetAnchorActualInfo(f.RightAnchor.Id); f.RightAnchor.Shift = aai.Shift.Width; } if (f.BottomAnchor != null) { Page.AnchorActualInfo aai = pages[currentPageI].GetAnchorActualInfo(f.BottomAnchor.Id); f.BottomAnchor.Shift = aai.Shift.Height; } setFieldRow(row, f); extractFieldAndDrawSelectionBox(f); //owners2resizebleBox[f] = new ResizebleBox(f, f.Rectangle.GetSystemRectangleF(), Settings.Appearance.SelectionBoxBorderWidth); } break; case SettingModes.NULL: break; default: throw new Exception("Unknown option: " + settingMode); } } catch (Exception ex) { Message.Error2(ex); } }; Shown += delegate { Application.DoEvents();//make form be drawn completely setUIFromTemplate(templateManager.Template); }; FormClosed += delegate { if (scaledCurrentPageBitmap != null) { scaledCurrentPageBitmap.Dispose(); scaledCurrentPageBitmap = null; } if (pages != null) { pages.Dispose(); pages = null; } templateManager.LastTestFile = testFile.Text; }; this.EnumControls((Control c) => { if (c is SplitContainer s) { s.BackColor = Color.FromArgb(80, 70, 0); s.SplitterWidth = 2; s.Panel1.BackColor = SystemColors.Control; s.Panel2.BackColor = SystemColors.Control; } }, true); testFile.TextChanged += delegate { try { if (picture.Image != null) { picture.Image.Dispose(); picture.Image = null; } if (scaledCurrentPageBitmap != null) { scaledCurrentPageBitmap.Dispose(); scaledCurrentPageBitmap = null; } if (pages != null) { pages.Dispose(); pages = null; } if (string.IsNullOrWhiteSpace(testFile.Text)) { return; } testFile.SelectionStart = testFile.Text.Length; testFile.ScrollToCaret(); if (!File.Exists(testFile.Text)) { Log.Message.Error("File '" + testFile.Text + "' does not exist!"); return; } pages = new PageCollection(testFile.Text); totalPageNumber = pages.PdfReader.NumberOfPages; lTotalPages.Text = " / " + totalPageNumber; showPage(1); } catch (Exception ex) { Log.Message.Error(ex); } }; pictureScale.ValueChanged += delegate { if (!loadingTemplate) { setScaledImage(); } }; pageRotation.SelectedIndexChanged += delegate { reloadPageBitmaps(); //showPage(currentPageI); }; autoDeskew.CheckedChanged += delegate { reloadPageBitmaps(); //showPage(currentPageI); }; Load += delegate { }; save.Click += Save_Click; cancel.Click += delegate { Close(); }; Help.LinkClicked += Help_LinkClicked; Configure.LinkClicked += Configure_LinkClicked; About.LinkClicked += About_LinkClicked; bTestFile.Click += delegate(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); if (!string.IsNullOrWhiteSpace(testFile.Text)) { d.InitialDirectory = PathRoutines.GetDirFromPath(testFile.Text); } else if (!string.IsNullOrWhiteSpace(templateManager.TestFileDefaultFolder)) { d.InitialDirectory = templateManager.TestFileDefaultFolder; } d.Filter = "PDF|*.pdf|" + "All files (*.*)|*.*"; if (d.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } testFile.Text = d.FileName; }; ShowPdfText.LinkClicked += ShowPdfText_LinkClicked; ShowOcrText.LinkClicked += ShowOcrText_LinkClicked; ShowAsJson.LinkClicked += showAsJson_LinkClicked; tCurrentPage.Leave += delegate { changeCurrentPage(); }; tCurrentPage.KeyDown += delegate(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { changeCurrentPage(); } }; }
public MainForm() { InitializeComponent(); this.Icon = AssemblyRoutines.GetAppIcon(); Text = Program.Name + " [" + Program.Version + "] / " + PdfDocumentParser.Program.Name + " [" + PdfDocumentParser.Program.Version.ToString(2) + "]"; Message.Owner = this; InputFolder.Text = Settings.General.InputFolder; LoadTemplates(); Active.ValueType = typeof(bool); Selected.ValueType = typeof(bool); OrderWeight.ValueType = typeof(float); FileFilterRegex.ValueType = typeof(Regex); Settings.Template2s.TouchedChanged += delegate { this.BeginInvoke(() => { saveTemplates.Enabled = Settings.Template2s.IsTouched(); }); }; saveTemplates.Enabled = false; saveTemplates.Click += delegate { saveTemplatesFromTableIfTouched(false); }; FormClosing += delegate(object sender, FormClosingEventArgs e) { Settings.TemplateLocalInfo.Clear_Save(); if (!saveTemplatesFromTableIfTouched(true)) { e.Cancel = true; } }; template2s.CellValidating += delegate(object sender, DataGridViewCellValidatingEventArgs e) { try { DataGridViewRow r = template2s.Rows[e.RowIndex]; Template2 t = (Template2)r.Tag; switch (template2s.Columns[e.ColumnIndex].Name) { case "Name_": { if (string.IsNullOrWhiteSpace((string)e.FormattedValue)) { if (t != null) { throw new Exception("Name cannot be empty!"); } return; } string name2 = ((string)e.FormattedValue).Trim(); foreach (DataGridViewRow rr in template2s.Rows) { if (rr.Index != e.RowIndex && name2 == (string)rr.Cells["Name_"].Value) { throw new Exception("Name '" + name2 + "' is duplicated!"); } } if ((string)r.Cells["Name_"].Value != name2) { r.Cells["Name_"].Value = name2; } } return; } } catch (Exception ex) { e.Cancel = true; Message.Error2(ex); } }; template2s.DataError += delegate(object sender, DataGridViewDataErrorEventArgs e) { try { DataGridViewRow r = template2s.Rows[e.RowIndex]; Template2 t = (Template2)r.Tag; switch (template2s.Columns[e.ColumnIndex].Name) { case "OrderWeight": throw new Exception("Order must be a float number:\r\n" + e.Exception.Message); case "FileFilterRegex": throw new Exception("FileFilterRegex must be a regex."); } } catch (Exception ex) { Message.Error2(ex); } }; template2s.CellValueChanged += delegate(object sender, DataGridViewCellEventArgs e) { try { DataGridViewRow r = template2s.Rows[e.RowIndex]; Template2 t = (Template2)r.Tag; if (t == null) { return; } if (e.ColumnIndex < 0)//row's header { return; } switch (template2s.Columns[e.ColumnIndex].Name) { case "Name_": t.Template.Name = (string)r.Cells["Name_"].Value; Settings.Template2s.Touch(); return; case "Active": t.Active = (bool)r.Cells["Active"].Value; Settings.Template2s.Touch(); return; case "Comment": t.Comment = (string)r.Cells["Comment"].Value; Settings.Template2s.Touch(); return; case "OrderWeight": t.OrderWeight = (float)r.Cells["OrderWeight"].Value; Settings.Template2s.Touch(); return; case "FileFilterRegex": t.FileFilterRegex = (Regex)r.Cells["FileFilterRegex"].Value; Settings.Template2s.Touch(); return; return; } } catch (Exception ex) { Message.Error2(ex); } }; template2s.UserDeletingRow += delegate(object sender, DataGridViewRowCancelEventArgs e) { try { if (e.Row == null || e.Row.Tag == null) { return; } if (!Message.YesNo("Template '" + e.Row.Cells["Name_"].Value + "' will be deleted! Proceed?")) { e.Cancel = true; return; } } catch (Exception ex) { Log.Message.Error(ex); } }; template2s.UserDeletedRow += delegate(object sender, DataGridViewRowEventArgs e) { Settings.Template2s.Touch(); }; TemplateManager.Templates = template2s; template2s.SelectionChanged += delegate(object sender, EventArgs e) { //if (templates.SelectedRows.Count < 1) // return; //var r = templates.SelectedRows[templates.SelectedRows.Count - 1]; //if (r.IsNewRow)//hacky forcing commit a newly added row and display the blank row //{ // try // { // int i = templates.Rows.Add(); // templates.Rows[i].Selected = true; // templates.Rows[i].Cells["Active"].Value = true; // } // catch { } //} }; template2s.CellClick += delegate(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } DataGridViewRow r = template2s.Rows[e.RowIndex]; if (e.ColumnIndex < 0)//row's header { return; } if (r.IsNewRow)//hacky forcing commit a newly added row and display the blank row { try { int i = template2s.Rows.Add(); r = template2s.Rows[i]; Template2 t = Settings.Template2s.CreateInitialTemplate(); r.Tag = t; r.Cells["Active"].Value = t.Active; r.Cells["OrderWeight"].Value = t.OrderWeight; r.Cells["FileFilterRegex"].Value = t.FileFilterRegex; r.Selected = true; } catch { } } switch (template2s.Columns[e.ColumnIndex].Name) { case "Edit": editTemplate(r); break; case "Copy": Template2 t = (Template2)r.Tag; if (t == null) { return; } Template2 t2 = Serialization.Json.Deserialize <Template2>(Serialization.Json.Serialize(t)); t2.Template.Name = ""; t2.Template.Editor.TestFile = null; int i = template2s.Rows.Add(new DataGridViewRow()); DataGridViewRow r2 = template2s.Rows[i]; r2.Tag = t2; r2.Cells["Name_"].Value = t2.Template.Name.Trim(); r2.Cells["Active"].Value = t2.Active; r2.Cells["OrderWeight"].Value = t2.OrderWeight; r2.Cells["FileFilterRegex"].Value = t2.FileFilterRegex; editTemplate(r2); break; case "Edit2": edit2Template(r); break; } }; progress.Maximum = 10000; }