Advertisement
GlobalAccessSoftware

SearchForm2.cs

Oct 3rd, 2019
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.32 KB | None | 0 0
  1.  
  2. #region Top Part
  3. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  4. // MyCustomLibrary.SearchForm2.cs
  5. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  6. // v5.2.7.12 05-May-2019 Created and Roughed
  7. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  8. // v5.2.7.14 12-May-2019 Great Design Stage.
  9. // v5.2.8.15 15-May-2019 Comin along nicely!
  10. // v5.2.8.16 16-May-2019 EyeOutBug Fixed ++
  11. // v5.2.8.17 18-May Split out from SF1 for
  12. // Buttons & getting ready for InterObjects
  13. // v5.2.8.18 25-May-2019 Worked into SF3:
  14. // v5.2.8.19 31-May Minor Revision, Setups.
  15. // v5.2.8.19 31-May Mechanisms such as the
  16. // PropertyChanged Events & App Detect plus
  17. // Tie-ins to Both MyEditor & PrintBlaster.
  18. // v5.2.9.19 June 2019, Ready Mods ++
  19. // v5.2.9.20 07-June Integration w/MyEditor!
  20. // v5.3.0.21 10-June Brought MySearchType &
  21. // SearchCom into SearchForm Class, but now
  22. // it's MST for the Mutexes AND MySearchType
  23. // and SearchForm Class for what was MSC
  24. // v5.3.0.21 15-June Getting Serious Now!
  25. // v5.3.1.23 25-Jun Coming Together! Rev-1;
  26. // v5.3.1.24 02-Jul Integrating Search mods.
  27. // v5.3.1.25 10-July SearchForm Features++
  28. // v5.3.2.26 14-Jul-2019 Design Rev to FSWs.
  29. // v5.3.3.27 19-July-2019 Design Revisions3.
  30. // v5.3.3.28 21-July SmesaSearch.cs rockin'
  31. // -=[ Design Revision 4 ]=- My Custom Type.
  32. // v5.3.4.29 25-Jul-2019 Spelling things out
  33. // Class{in-Class{in-Class}}; Custom Types:
  34. // v5.3.5.31 03-Aug ReCoded4 WorkList2
  35. // v5.4.5.32 07-Aug-2019 Search & Replace.
  36. // v5.4.5.35 21-Aug-2019 Design finished!
  37. // v5.4.6.36 29-31 " " Work down testwells
  38. // & BreakPoints, Clean and Polish++ 06-Sept
  39. // v5.4.7.40 24-Sep-2019 Settling down after
  40. // some evolution during tracing & testing.
  41. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  42.  
  43. using System;
  44. using System.Collections.ObjectModel;
  45. using System.IO;
  46. using System.Threading;
  47. using System.Windows.Forms;
  48.  
  49. using MCD = MyCustomLibrary.Dialogs;
  50. using MMF = MyCustomLibrary.MemoryMapper;
  51. using MCT = MyCustomLibrary.MyToolbox;
  52.  
  53. using MCR = MyCustomLibrary
  54.   .Properties.Resources;
  55. using MCS = MyCustomLibrary
  56.   .Properties.Settings;
  57.  
  58. #endregion Pop Tart
  59.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  60.  
  61.  
  62. namespace MyCustomLibrary
  63. {
  64.   // This is the Primary Class & Form.
  65.   public partial class SearchForm
  66.   {
  67. #region SF3 Design Documentation:
  68.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  69.     /*//\\//Scope items Doc [w/Legend]//\\//
  70.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  71.     \\ Indice | Design said PB Scopes://\\//
  72.     // [0] Find Files by Name.  //\\//\\//\\
  73.     \\ [1] Content of Selected Files. //\\//
  74.     // [2] Content of All Managed Files.//\\
  75.     \\ *********************************\\//
  76.     // Indice | Design said ME Scopes:\\//\\
  77.     \\ [0] Current File  Content\\//\\//\\//
  78.     // [1] Opened  Files Content//\\//\\//\\
  79.     \\ [2] Managed Files Content\\//\\//\\//
  80.     // [3] Find Files by Name.\\//\\//\\//\\
  81.     //  \\//\\//\\//\\//\\//\\//\\//\\//\\//
  82.  
  83.     // Rev9: Content goes to ME,
  84.     // Rev9: Name goes to PB.
  85.     // if (scope.List > 3) it's ME;
  86.  
  87.     /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
  88.     /*    Important Design Elements:
  89.      * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  90.      *
  91.      *      caseCheckBox.Checked;
  92.      *      wordCheckBox.Checked;
  93.      *      scopeBox.SelectedIndex;
  94.      *
  95.      * searchBox .Text; // to search for.
  96.      * replaceBox.Text  // to replace with.
  97.      *
  98.      * Selected List:   MCD.Selected;
  99.      * Whole Mngd List: MCD.WholeList;
  100.      *
  101.      * See Notes:  MMMF_Doc & Analysis.  */
  102.     /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
  103. #endregion SF3 Original Design Doc:
  104.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  105.  
  106.  
  107. #region Find-Button Subgroup of methods.
  108.     // v5.2.8.16-17 : 18-20th May-2019
  109.     // (shown/called by ME and PB)
  110.     void FindButtonClicked(
  111.       object sender, EventArgs e)
  112.     {
  113.       if (CheckFindNext()) return;
  114.  
  115.       UpdateSearchList();
  116.  
  117.       if (Application.ExecutablePath
  118.           .Contains(MCR.MyApp))
  119.         EditorCalling();
  120.       else
  121.         BlasterCalling();
  122.  
  123.       if (AnyMatches()) FoundMatches();
  124.     }
  125.  
  126.     void FoundMatches()
  127.     {
  128.       if (SearchAll) ExtractUnOpened();
  129.       var t = 0;
  130.       if (!MCT.MeRunning) t = RunMyEditor();
  131.       if (t < 9)
  132.       {
  133.         // v Event Trigger when assigned to.
  134.         MatchesFound = Info;
  135.         Info = GetNewInfo;
  136.         Validate();
  137.       }
  138.       else
  139.       {
  140.         if (!MCT.Testing
  141.           || MCT.Skip) return;
  142.         #region Permanent TestCode
  143.         MessageBox.Show(
  144.           string.Format(
  145.             "{0}{1}{2}{3}{4}",
  146.             MCR.TimeOut1,
  147.             Path.GetFileName(
  148.               Application.ExecutablePath),
  149.             MCR.TimeOut2,
  150.             MCR.FindButton,
  151.             "\n\nCycles == " + t));
  152.         #endregion
  153.       }
  154.     }
  155.  
  156.     bool AnyMatches()
  157.     {
  158.       return Info != null
  159.         && Info.File != null
  160.         && Info.File.Count > 0
  161.         && !string.IsNullOrEmpty(
  162.            Info.FindThis)
  163.         && !string.IsNullOrEmpty(
  164.            Info.Change2);
  165.     }
  166.  
  167.     // FindNext, MatchesFound if
  168.     // True Search already underway.
  169.     private bool CheckFindNext()
  170.     {
  171.       return
  172.         MatchesFound != null
  173.         && MatchesFound.File != null
  174.         && MatchesFound.File.Count > 0
  175.         && searchBox.Text.Equals(MCS.Default
  176.           .SearchBoxCollection[0])
  177.         && (FindNext = true);
  178.       // Remote ^ Trigger or NOT
  179.     }
  180. #endregion Find-Button Subgroup of Methods.
  181.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  182.  
  183.  
  184. #region Replace & Replace-ALL Methods.
  185.  
  186.     // shown/called by ME only
  187.     void ReplaceButtonClicked(
  188.       object sender, EventArgs e)
  189.     {
  190.       if (MatchesFound != null &&
  191.         searchBox.Text.Equals(MCS.Default
  192.           .SearchBoxCollection[0]) &&
  193.         replaceBox.Text.Equals(MCS.Default
  194.           .ReplaceBoxCollection[0]))
  195.       {
  196.         Replace = true;
  197.         // ^ EventTrigger! Writes Remote.sme
  198.         return;
  199.       }
  200.       // else
  201.       UpdateReplaceList();
  202.       FindButtonClicked(sender, e);
  203.     }
  204.  
  205.     // Shown / Called by ME only)
  206.     // NOTE: Cancel is Changed on Closing.
  207.     void ReplaceAllButtonClicked(
  208.       object sender, EventArgs e)
  209.     {
  210.       // breakpoint SF2.RABC
  211.       if (MatchesFound != null &&
  212.         searchBox.Text.Equals(MCS.Default
  213.           .SearchBoxCollection[0]))
  214.       {
  215.         ReplaceAll = true;
  216.         // ^ EventTrigger! Writes Remote.sme
  217.         return;
  218.       }
  219.       // else
  220.       UpdateReplaceList();
  221.       FindButtonClicked(sender, e);
  222.     }
  223.  
  224. #endregion Replace & Replace-ALL Methods.
  225.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  226.  
  227.  
  228. #region Outgoing Messaging
  229.  
  230.     /**************************************
  231.     / IndexFound Property Members for PB:
  232.     /**************************************/
  233.  
  234.     // REM: SearchForm is Signaling caller,
  235.     // either MyEditor OR PrintBlaster Apps.
  236.  
  237.     Collection<int> IndexesFound
  238.     {
  239.       get { return _indexes; }
  240.  
  241.       set
  242.       {
  243.         _indexes  = value;
  244.         if ( value == null
  245.           || value.Count < 1) return;
  246.         // Think of it as a PropertyChanged
  247.         SendSelected(); // EventHandler.
  248.       }
  249.     }
  250.     Collection<int> _indexes;
  251.  
  252.     // This 1 is Separate until Assigned.
  253.     Collection<int> Indexes { get; set; }
  254.  
  255.  
  256.     // REM: SearchForm is Signaling MyEditor
  257.     //**************************************
  258.     //    MatchesFound Property Members
  259.     //**************************************/
  260.     WorkList2 MatchesFound
  261.     {
  262.       get { return _skinny; }
  263.       set
  264.       {
  265.         _skinny = value;
  266.         if ( value == null
  267.           || value.File == null
  268.           || value.File.Count < 1) return;
  269.         SendMatches();
  270.       }
  271.     }
  272.     WorkList2 _skinny;
  273.  
  274.     // This 1 is Separate until Assigned.
  275.     WorkList2 Info { get; set; }
  276.    
  277.     /*********[Events 4 ME 2 handle]********/
  278.  
  279.     void SendRemote(byte code)
  280.     {
  281.       var fn = MCT.GetRoot + MCR.Remote;
  282.       var args = MCD.GetArgs(fn, code);
  283.       if (!MMF.WriteBytes(args))
  284.         MessageBox.Show(MCR.Err12);
  285.  
  286.       // develop Enabled locks
  287.       Enabled = false;
  288.     }
  289.  
  290.     bool FindNext
  291.     { set { if (!value) return;
  292.       SendRemote(1); } }
  293.  
  294.     bool Replace
  295.     { set { if (!value) return;
  296.       SendRemote(2); } }
  297.  
  298.     bool ReplaceAll
  299.     { set { if (!value) return;
  300.         SendRemote(3); } }
  301.    
  302.     bool CancelSearch
  303.     { set { if (!value) return;
  304.       SendRemote(4); } }
  305.  
  306. #endregion Outgoing Messaging
  307.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  308.  
  309.  
  310. #region Incoming Messaging
  311.  
  312.     // Rev5.3.0.21 Design Changes
  313.     // this to a FileSystemWatcher
  314.     // sent directly from: MyEditor
  315.     //  .Smesa via SearchReplace.cs
  316.     void SetupWatcher4MeComms()
  317.     {
  318.       Beagle.NotifyFilter =
  319.         NotifyFilters.FileName;
  320.       Beagle.InternalBufferSize  = 32;
  321.       Beagle.EnableRaisingEvents = false;
  322.  
  323.       // Setup File System Watcher:
  324.       var dir = Application.StartupPath;
  325.       if (string.IsNullOrEmpty(dir)
  326.         || !Directory.Exists(dir)) throw
  327.         new ArgumentException(MCR.Err14);
  328.  
  329.       Beagle.Path = dir;
  330.       var fn = dir + MCR.Search;
  331.       Beagle.Filter = Path.GetFileName(fn);
  332.  
  333.       // Start Clean Each Run.
  334.       if (File.Exists(fn)) File.Delete(fn);
  335.  
  336.       // Create Eventhandler...
  337.       Beagle.Created += WatchRemote;
  338.       Beagle.EnableRaisingEvents = true;
  339.     }
  340.  
  341.     /*********************************/
  342.     void WatchRemote(// from MyEditor
  343.       object sender, FileSystemEventArgs e)
  344.     {
  345.       Thread.CurrentThread.Name =
  346.         "Msg Detected";
  347.       if (searchBox.InvokeRequired)
  348.         Invoke(new Invoker1(SearchTask));
  349.       else SearchTask();
  350.     }
  351.     /*********************************/
  352.     delegate void Invoker1();
  353.    
  354.     // Back on UI Thread at this point.
  355.     void SearchTask()
  356.     {
  357.       Thread.CurrentThread.Name =
  358.         "Search Task";
  359.       Enabled = true;
  360.       var fn = Application
  361.         .StartupPath + MCR.Search;
  362.       if (!File.Exists(fn)) return;
  363.  
  364.       // Now read the file in and then
  365.       // it's deleted after the read.
  366.       var bytes = MMF.ReadBytes(
  367.         MCD.GetArgs(fn, 0));
  368.  
  369.       if (Convert.ToByte(
  370.         bytes[0]) < 2) LetsGo();
  371.       else
  372.         AllDone();
  373.       #region Release Version TestCode
  374.       //const string t =
  375.       //  "Made it to Search Task with\n" +
  376.       //  "a TASK of: ";
  377.       //MessageBox.Show(t + task);
  378.       #endregion
  379.     }
  380.    
  381.     // Async Msg From MyEditor.
  382.     // Basic CTS Signal Circuit Logic.
  383.     // (Clear To Send)
  384.     void LetsGo()
  385.     {
  386.       // testwell LetsGo();
  387.       using (new Mutex(true, "GOM505"))
  388.       {
  389.         // hack UNFINISHED CODE
  390.  
  391.  
  392.         // testcode LetsGo
  393.         const string txt =
  394.           "Made it to Lets Go!";
  395.         MessageBox.Show(txt);
  396.       }
  397.     }
  398.  
  399.     // All Done on Editor End, now what?
  400.     // Act on Search Task Completed
  401.     // in SmesaSearch over here in SF2.
  402.     void AllDone()
  403.     {
  404.       // breakpoint AllDone();
  405.       using (new Mutex(true, "DONEM521"))
  406.       {
  407.         MatchesFound = Info = GetNewInfo;
  408.         IndexesFound = Indexes =
  409.           new Collection<int>();
  410.       }
  411.     }
  412. #endregion Incoming Messaging
  413.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  414.  
  415.  
  416. #region Free Parking For View Only.
  417.  
  418.  
  419. #endregion Free Parking For View Only
  420.     //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  421.  
  422.  
  423.   }
  424. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement