private void UpdateTitle() { string t = ""; if ((mStage.StageFileName == null || mStage.StageFileName == "") && mStage.RawFileName != null) { t = System.IO.Path.GetFileName(mStage.RawFileName) + " — " + MainClass.APP_NAME; } else if (mStage.RawFileName != null) { string ern = ReceiptsManager.ExtractReceiptName(mStage.StageFileName, mStage.RawFileName); if (ern != null && ern != "") { t = System.IO.Path.GetFileName(mStage.RawFileName) + " (" + ern + ") — " + MainClass.APP_NAME; } else { t = System.IO.Path.GetFileName(mStage.RawFileName) + " — " + MainClass.APP_NAME; } } else { t = MainClass.APP_NAME; } Title = t; }
public ChooseReceiptsViewModel(IFrameNavigationService navigationService) { _navigationService = navigationService; _receiptsManager = new ReceiptsManager(); Year = Enumerable.Range(1990, DateTime.Now.Year - 1990 + 1).ToList(); Month = Enumerable.Range(1, 12).ToList(); ReceiptsCommand = new RelayCommand(ShowReceipt); GoBackCommand = new RelayCommand(() => { _navigationService.NavigateTo("Login"); }); }
protected void OnSaveReceiptActionActivated(object sender, System.EventArgs e) { if (ReceiptsManager.DetermineReceiptType(mStage.StageFileName, mStage.RawFileName) == ReceiptsManager.ReceiptType.Default || ReceiptsManager.DetermineReceiptType(mStage.StageFileName, mStage.RawFileName) == ReceiptsManager.ReceiptType.Custom) { mStage.SaveStage(); } else { mStage.SaveStage(ReceiptsManager.MakeDefaultOrCustomReceiptFilename(mStage.RawFileName, null)); } //mStage.StageFileName }
void HandleUIChange(object sender, EventArgs e) { if (!mUIChangingInProgress) { mUIChangingInProgress = true; try { if (mDefault.Active) { mNameComboBoxEntry.Sensitive = false; mSaveButton.Sensitive = true; } else if (mCustom.Active) { mNameComboBoxEntry.Sensitive = true; mSaveButton.Sensitive = (mNameComboBoxEntry.ActiveText != ""); // Updating names list ListStore ls = (ListStore)mNameComboBoxEntry.Model; ls.Clear(); string[] customReceipts = CatEye.Core.ReceiptsManager.FindCustomReceiptsForRaw(mRawFileName); for (int i = 0; i < customReceipts.Length; i++) { ls.AppendValues(ReceiptsManager.ExtractReceiptName(customReceipts[i], mRawFileName)); } } else if (mClass.Active) { mNameComboBoxEntry.Sensitive = true; mSaveButton.Sensitive = (mNameComboBoxEntry.ActiveText != ""); // Updating names list ListStore ls = (ListStore)mNameComboBoxEntry.Model; ls.Clear(); string[] classReceipts = CatEye.Core.ReceiptsManager.FindClassReceiptsForRaw(mRawFileName); for (int i = 0; i < classReceipts.Length; i++) { ls.AppendValues(ReceiptsManager.ExtractReceiptName(classReceipts[i], mRawFileName)); } } } finally { mUIChangingInProgress = false; } } }
// ctor public ReceiptsViewModel(IFrameNavigationService navigationService) { _navigationService = navigationService; _receiptsManager = new ReceiptsManager(); Year = Enumerable.Range(1990, DateTime.Now.Year - 1990 + 1).ToList(); Month = Enumerable.Range(1, 12).ToList(); ReceiptsCommand = new RelayCommand(ShowReceipt); GoBackCommand = new RelayCommand(() => { _navigationService.NavigateTo("Login"); }); ExportCommand = new RelayCommand(ExportReceipt); Receipts = new ObservableCollection <LineReceiptDTO>() { new LineReceiptDTO() { LeftSms = 1, LeftMinutes = TimeSpan.FromSeconds(2000) } }; }
protected void OnSaveReceiptAsActionActivated(object sender, System.EventArgs e) { ReceiptSaveDialog rsd = new ReceiptSaveDialog(this, mStage.RawFileName); if (ReceiptsManager.DetermineReceiptType(mStage.StageFileName, mStage.RawFileName) == ReceiptsManager.ReceiptType.Custom) { rsd.SelectedType = ReceiptSaveDialog.ReceiptType.Custom; } else if (ReceiptsManager.DetermineReceiptType(mStage.StageFileName, mStage.RawFileName) == ReceiptsManager.ReceiptType.Class) { rsd.SelectedType = ReceiptSaveDialog.ReceiptType.Class; } else { rsd.SelectedType = ReceiptSaveDialog.ReceiptType.Default; } rsd.SelectedName = ReceiptsManager.ExtractReceiptName(mStage.StageFileName, mStage.RawFileName); if (rsd.Run() == (int)Gtk.ResponseType.Accept) { if (rsd.SelectedType == ReceiptSaveDialog.ReceiptType.Default) { mStage.SaveStage(ReceiptsManager.MakeDefaultOrCustomReceiptFilename(mStage.RawFileName, null)); } else if (rsd.SelectedType == ReceiptSaveDialog.ReceiptType.Custom) { mStage.SaveStage(ReceiptsManager.MakeDefaultOrCustomReceiptFilename(mStage.RawFileName, rsd.SelectedName)); } else if (rsd.SelectedType == ReceiptSaveDialog.ReceiptType.Class) { mStage.SaveStage(ReceiptsManager.MakeClassReceiptFilename(System.IO.Path.GetDirectoryName(mStage.RawFileName), rsd.SelectedName)); } else { throw new Exception("Invalid rsd.SelectedType value"); } } rsd.Destroy(); }
public static void Main(string[] args) { // Initializing remote control mRemoteControlService = new RemoteControlService("localhost", 21985); mRemoteControlService.RemoteCommandReceived += HandleRemoteControlServiceRemoteCommandReceived; // Parsing command line. Formulating command and it's arguments List <string> argslist = new List <string>(args); List <string> commands = new List <string>(); List <List <string> > commands_arguments = new List <List <string> >(); if (argslist.Contains("-q") || argslist.Contains("--queue")) { argslist.Remove("-q"); argslist.Remove("--queue"); // Queue launch mode // Searching for "--default" option int d_inx = -1; d_inx = argslist.IndexOf("-d") >= 0 ? argslist.IndexOf("-d") : d_inx; d_inx = argslist.IndexOf("--default") >= 0 ? argslist.IndexOf("--default") : d_inx; string d_cestage_name = ""; if (d_inx >= 0) { if (d_inx < argslist.Count - 1) { d_cestage_name = argslist[d_inx + 1]; // Removing readed "-d" argslist.RemoveRange(d_inx, 2); if (!ReceiptsManager.IsReceipt(d_cestage_name)) { Console.WriteLine("Incorrect argument: " + d_cestage_name + " is not a .cestage file."); d_cestage_name = ""; } } else if (d_inx == argslist.Count - 1) { Console.WriteLine("Incorrect argument: .cestage file name should be provided after --default or -d"); argslist.RemoveAt(d_inx); } } // Searching for "--target-type" int tt_inx = -1; tt_inx = argslist.IndexOf("-t") >= 0 ? argslist.IndexOf("-t") : tt_inx; tt_inx = argslist.IndexOf("--target-type") >= 0 ? argslist.IndexOf("--target-type") : tt_inx; string target_type = ""; if (tt_inx >= 0) { if (tt_inx < argslist.Count - 1) { target_type = argslist[tt_inx + 1]; // Removing readed "-t" argslist.RemoveRange(tt_inx, 2); if (target_type != "jpeg" && target_type != "png" && target_type != "bmp") { Console.WriteLine("Incorrect target type specified: " + target_type + ". It should be \"jpeg\", \"png\" or \"bmp\"."); target_type = ""; } } else if (tt_inx == argslist.Count - 1) { Console.WriteLine("Incorrect argument: target type should be provided after --target-type or -t"); argslist.RemoveAt(tt_inx); } } // Searching for "--prescale" int p_inx = -1; p_inx = argslist.IndexOf("-p") >= 0 ? argslist.IndexOf("-p") : p_inx; p_inx = argslist.IndexOf("--prescale") >= 0 ? argslist.IndexOf("--prescale") : p_inx; int prescale = 2; if (p_inx >= 0) { if (p_inx < argslist.Count - 1) { if (!int.TryParse(argslist[p_inx + 1], out prescale) || prescale < 1 || prescale > 8) { Console.WriteLine("Incorrect prescale value specified: " + argslist[p_inx + 1] + ". It should be an integer value from 1 to 8."); } // Removing readed "-t" argslist.RemoveRange(p_inx, 2); } else if (p_inx == argslist.Count - 1) { Console.WriteLine("Incorrect argument: prescale should be provided after --prescale or -p"); argslist.RemoveAt(p_inx); } } // Now when all the additional parameters are parsed and removed, // we're analysing, what's left. The options: if (argslist.Count == 2 && ((ReceiptsManager.IsReceipt(argslist[0]) && RawLoader.IsRaw(argslist[1])) || (ReceiptsManager.IsReceipt(argslist[1]) && RawLoader.IsRaw(argslist[0])))) { // Two file names: one cestage and one raw string cestage_filename; string raw_filename; if (ReceiptsManager.IsReceipt(argslist[0]) && RawLoader.IsRaw(argslist[1])) { cestage_filename = argslist[0]; raw_filename = argslist[1]; } else // if (IsCEStageFile(argslist[1]) && DCRawConnection.IsRaw(argslist[0])) { cestage_filename = argslist[1]; raw_filename = argslist[0]; } // Guessing target filename if (target_type == "") { target_type = "jpeg"; } string target_name = System.IO.Path.ChangeExtension(raw_filename, target_type); target_name = CheckIfFileExistsAndAddIndex(target_name); // Launching StageEditor with the cestage file and the raw file commands.Add("AddToQueue"); commands_arguments.Add(new List <string>(new string[] { cestage_filename, raw_filename, target_name, target_type, prescale.ToString() })); } else { // Searching for cestage for each raw and for raws for each cestage for (int i = 0; i < argslist.Count; i++) { if (RawLoader.IsRaw(argslist[i])) { // The current file is a raw // Guessing target filename if (target_type == "") { target_type = "jpeg"; } string target_name = System.IO.Path.ChangeExtension(argslist[i], target_type); target_name = CheckIfFileExistsAndAddIndex(target_name); string[] cestages = ReceiptsManager.FindReceiptsForRaw(argslist[i]); if (cestages.Length > 0) { // At least one found // Launching StageEditor with the cestage file and the raw file commands.Add("AddToQueue"); commands_arguments.Add(new List <string>(new string[] { cestages[0], argslist[i], target_name, target_type, prescale.ToString() })); } else if (d_cestage_name != "") { // Nothing found, but default name is present commands.Add("AddToQueue"); commands_arguments.Add(new List <string>(new string[] { d_cestage_name, argslist[i], target_name, target_type, prescale.ToString() })); } else { Console.WriteLine("Can't open " + argslist[i] + ": can't find it's .cestage file"); } } else if (ReceiptsManager.IsReceipt(argslist[i])) { // The current file is a cestage // Guessing target filename if (target_type == "") { target_type = "jpeg"; } string target_name = System.IO.Path.ChangeExtension(argslist[i], target_type); target_name = CheckIfFileExistsAndAddIndex(target_name); string[] raws = new string[] {}; try { raws = ReceiptsManager.FindRawsForReceipt(argslist[i]); } catch (System.IO.DirectoryNotFoundException dnfe) { Console.WriteLine("Error: " + dnfe.Message); } if (raws.Length > 0) { // At least one found commands.Add("AddToQueue"); commands_arguments.Add(new List <string>(new string[] { argslist[i], raws[0], target_name, target_type, prescale.ToString() })); } else { Console.WriteLine("Can't open " + argslist[i] + ": can't find it's raw file"); } } } } } else { // Not a queue launch mode // If we don't have 1 cestage and 1 raw, let's open as many windows as possible. // But, at first, trying to find "--default" option int d_inx = -1; d_inx = argslist.IndexOf("-d") >= 0 ? argslist.IndexOf("-d") : d_inx; d_inx = argslist.IndexOf("--default") >= 0 ? argslist.IndexOf("--default") : d_inx; string d_cestage_name = ""; if (d_inx >= 0) { if (d_inx < argslist.Count - 1) { d_cestage_name = argslist[d_inx + 1]; // Removing readed "-d" argslist.RemoveRange(d_inx, 2); if (!ReceiptsManager.IsReceipt(d_cestage_name)) { Console.WriteLine("Incorrect argument: " + d_cestage_name + " is not a .cestage file."); d_cestage_name = ""; } } else if (d_inx == argslist.Count - 1) { Console.WriteLine("Incorrect argument: .cestage file name should be provided after --default or -d"); argslist.RemoveAt(d_inx); } } // Searching for "--prescale" int p_inx = -1; p_inx = argslist.IndexOf("-p") >= 0 ? argslist.IndexOf("-p") : p_inx; p_inx = argslist.IndexOf("--prescale") >= 0 ? argslist.IndexOf("--prescale") : p_inx; int prescale = 2; if (p_inx >= 0) { if (p_inx < argslist.Count - 1) { if (!int.TryParse(argslist[p_inx + 1], out prescale) || prescale < 1 || prescale > 8) { Console.WriteLine("Incorrect prescale value specified: " + argslist[p_inx + 1] + ". It should be an integer value from 1 to 8."); } // Removing readed "-p" argslist.RemoveRange(p_inx, 2); } else if (p_inx == argslist.Count - 1) { Console.WriteLine("Incorrect argument: prescale should be provided after --prescale or -p"); argslist.RemoveAt(p_inx); } } if (argslist.Count == 2 && ReceiptsManager.IsReceipt(argslist[0]) && RawLoader.IsRaw(argslist[1])) { // Launching StageEditor with the cestage file and the raw file commands.Add("StageEditor_CEStage_RAW"); commands_arguments.Add(new List <string>(new string[] { argslist[0], argslist[1], prescale.ToString() })); } else if (argslist.Count == 2 && ReceiptsManager.IsReceipt(argslist[1]) && RawLoader.IsRaw(argslist[0])) { // Launching StageEditor with the cestage file and the raw file commands.Add("StageEditor_CEStage_RAW"); commands_arguments.Add(new List <string>(new string[] { argslist[1], argslist[0], prescale.ToString() })); } else { // Searching for cestage for each raw and for raws for each cestage for (int i = 0; i < argslist.Count; i++) { if (RawLoader.IsRaw(argslist[i])) { // The current file is a raw if (d_cestage_name != "") { // Nothing found, but default name is present commands.Add("StageEditor_CEStage_RAW"); commands_arguments.Add(new List <string>(new string[] { d_cestage_name, argslist[i], prescale.ToString() })); } else { commands.Add("StageEditor_RAW"); commands_arguments.Add(new List <string>(new string[] { argslist[i], prescale.ToString() })); } } else if (ReceiptsManager.IsReceipt(argslist[i])) { // The current file is a cestage string[] raws = ReceiptsManager.FindRawsForReceipt(argslist[i]); if (raws.Length > 0) { // At least one found // Launching StageEditor with the cestage file and the raw file commands.Add("StageEditor_CEStage_RAW"); commands_arguments.Add(new List <string>(new string[] { argslist[i], raws[0], prescale.ToString() })); } else if (raws.Length == 0) { Gtk.MessageDialog md = new Gtk.MessageDialog( null, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, false, "Can't find raw file for {0}", argslist[i]); md.Title = MainClass.APP_NAME; md.Run(); md.Destroy(); } else // raws.Length > 1 { Gtk.MessageDialog md = new Gtk.MessageDialog( null, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, false, "More than one raw file found for {0}", argslist[i]); md.Title = MainClass.APP_NAME; md.Run(); md.Destroy(); } } } } } bool ownServerStarted = mRemoteControlService.Start(); if (ownServerStarted) { string mylocation = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetCallingAssembly().Location); windowsGtkStyle = new WindowsGtkStyle(mylocation + Path.DirectorySeparatorChar + "res" + Path.DirectorySeparatorChar + "win-gtkrc"); Application.Init(); // Creating render queue and its window mRenderingQueue = new RenderingQueue(); mRenderingQueueWindow = new RenderingQueueWindow(mRenderingQueue); mRenderingQueue.StartThread(); } // No files asked if (commands.Count == 0) { // No command line arguments passed. // Sending the "StageEditor" command with no arguments commands.Add("StageEditor"); commands_arguments.Add(new List <string>()); } // Sending the commands List <string> packed_commands = new List <string>(); for (int i = 0; i < commands.Count; i++) { packed_commands.Add(RemoteControlService.PackCommand(commands[i], commands_arguments[i].ToArray())); } mRemoteControlService.SendCommands(packed_commands.ToArray()); if (ownServerStarted) { GLib.Idle.Add(delegate { // Checking if something is already started if (RenderingQueue.IsProcessingItem || StageEditorWindows.Count > 0) { mLoadedSomethingAlready = true; } // Removing all destroyed StageEditorWindows.RemoveAll(delegate(StageEditorWindow wnd) { return(wnd.IsDestroyed); }); // Checking is there any activity or no if (mLoadedSomethingAlready && StageEditorWindows.Count == 0 && !RenderingQueue.IsProcessingItem) { RenderingQueue.StopThread(); Application.Quit(); } return(true); }); Application.Run(); } mRemoteControlService.Stop(); }