Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This goes with the MemoryMappings.cs, the latest edition. Obviously, for those familiar with IPC: The WriteStrings() method can be called from one App or instance of the same App and the ReadStrings() from another App or instance of the same App. Allowing strings, pointers and bytes to be passed from one to the other. -JpE-
- // The client or server side can then have a System.FileSystemWatcher Event for the file to be changed by the other (client/server) and act on it accordingly. ;-)
- protected internal FileSystemWatcher
- SharedWatcher { get; set; } // Declare Property used below.
- #region Shared Data Watcher & Handler
- // Setup File System Watcher:
- [PermissionSet(SecurityAction.Demand,
- Name = "FullTrust")]
- private void SetupSharedWatcher()
- {
- SharedWatcher.NotifyFilter
- = NotifyFilters.LastWrite
- | NotifyFilters.CreationTime;
- // testwell w & w/o (above)
- SharedWatcher
- .InternalBufferSize = 1;
- SharedWatcher
- .EnableRaisingEvents = false;
- SharedWatcher.Path =
- Path.GetDirectoryName(
- PFS.Default.PathMmf3);
- SharedWatcher.Filter =
- MCT.SharedFile;
- // Point Delegate to Eventhandler.
- SharedWatcher.Changed +=
- SharedEventHandler;
- SharedWatcher
- .EnableRaisingEvents = true;
- }
- [PermissionSet(SecurityAction.Demand,
- Name = "FullTrust")]
- private void SharedEventHandler(
- object sender, FileSystemEventArgs e)
- {
- // temporary TestCode 4 Release vers testing.
- MessageBox.Show("Shared Event Handler Hit...");
- //
- if (!ReadSharedData()) return;
- if (menuStrip1.InvokeRequired)
- { // testcode
- //if (MCT.Testing)
- MessageBox.Show(PFR.PbS);
- Invoke(new Invoker(GetProperties));
- }
- else GetProperties();
- //Validate();
- }
- // NOTE: using MMF = MyCustomLibrary.MemoryMappings; in the header. Shorthand.
- // (See the MMF calls in the sample code below.)
- private void TestCodeLauncher(
- object sender, EventArgs e)
- {
- // code that tests MemoryMappings.ReadStrings() & WriteStrings. Just faked the args so call them with that. Read it back in for Part 2.
- var strings=
- new Collection<string>
- {"Testing strings, test test test.","Hello World!","String 3","4","string 5","6 string","string 7","The 8th String","The bottom of the 9th!","10th string","string #11","thfsahf fshfeeifj jkljfksdjkjf ieiiif jfkdkls l\n\nhahahah love it akfjsakjei sjk hskshf fjksdhfhue\n\nHeheh just testing a long string here.","snowball","testcode","15","16 string","string 17","string 18","19th string","Tada string #20!\nskjdfsk fjfidowijwei fkdsjk fjkdsjie jfkdjs;al;sjfj jfijw0ew slfklks'; jfdsasp[df fdks jgjkszllkshfhdhskh hfjksh hfjs sksdhf jhsue hfjdsk fhue\n\njskkjfj jfidosijfk jlksdjkhf -JpE-"};
- var args=
- new object[]
- {Path.GetDirectoryName(Data[0].ToString()) +
- "\\testStrings.sme",0,2,strings,true,"testMmf"};
- // Faked args & strings ^^^^^^^^^^^^^^
- // So now we can test it all out and trace through the MemoryMappings Class.
- MMF.WriteStrings(args); // NOTE Ease of MMF usages here. Write call can be in the client or server side and the Read call in the other, see.
- var read=MMF.ReadStrings(args);
- var coun=0;
- MessageBox.Show(read.Aggregate(
- "",(current,s)=>current+string.Format(
- "String#{0}: {1}\n",++coun,s)));
- // todo Space for Rent
- }
Add Comment
Please, Sign In to add comment