P2Labs
...finger on the pulse...
Username: Password:  Remember me    

P2Libs

.NET libraries for the professional developer...

Overview
We received a lot of inquiries as to whether our libraries could be packaged for sale to developers. We thought about it and agreed. Now you too can have professional functionality with bullet proof code that is in use all over the world.
  All our libs are available by PayPal™ purchase only (sorry, corporate purchase orders are not accepted). However, each purchase comes with a 30 day total satisfaction money back guarantee.
 
  Pricing on application and priced per developer seat. Binary and source code licenses are available. Please note, a copyright notice must be included in your application's About box stating P2Labs' copyright ownership. Exact wording will be supplied upon successful registration of the product. Please contact our Sales Department for further information.
 
P2BuildInfo
Access all your assembly's details in one easy step. // set our title bar text to include a version number using ( P2Labs.BuildInfo bi = new P2Labs.BuildInfo() ) { this.Text = "My Application version: " + bi.Version; this.Copyright = "My Application version: " + bi.Copyright; }
 
P2Dictionary
Super fast and threadsafe dictionary (replace those hash tables now) // // create our thread safe dictionary to hold string keys and // values (or store other types as values) // P2Labs.Dictionary.ThreadSafeDictionary dict; dict = new P2Labs.Dictionary.ThreadSafeDictionary< string, string >(); if ( dict != null ) { // add an entry (can be called from worker threads with no impact) dict.Add( new KeyValuePair( "uniqueKey", "value" ) ); // locate an entry (can be called from worker threads with no impact) string strValue = (string)dict.TryGetValue( "uniqueKey" ); // determine number of entries (can be called from worker threads with no impact) int iNumEntries = dict.Count; // access using array syntax (can be called from worker threads with no impact) string strAnotherValue = (string)dict[ "uniqueKey" ]; // remove an entry (can be called from worker threads with no impact) bool fSuccess = dict.Remove( "uniqueKey" ); }
 
P2FormState
Save and restore your form's location and state // save form state into application property WindowState using ( P2Labs.FormState fs = new P2Labs.FormState () ) { Properties.Settings.Default.WindowState = fs.Save( this ); Properties.Save(); } // restore form state from application property WindowState using ( P2Labs.FormState fs = new P2Labs.FormState () ) { fs.SetFormState( this, Properties.Settings.Default.WindowState ); Properties.Save(); }
 
P2GetOpts
Access all command line arguments with ease.
May be combined e.g. -c -m -f Filename or -cmf FileName // process command line arguments // c and m are switches and f represents a filename will be following while ( ( c = P2Labs.GetOpt.GetOptions(GetCommandLineArgs(),"cf:m" ) ) != ( -1 ) ) { switch ( (char)c ) { case 'c': // -c command line arg detected so do something break; case 'm': // -m command line arg detected so do something break; case 'f': // -f command line arg detected - file name must follow string strFilename = P2Labs.GetOpt.Text.ToUpper(); break; default: // something passed we don't know about return; } }
 
P2Hyperlink
Launch the default application for a particular URI. // launch browser and go to web site using ( P2Labs.Hyperlink hl = new P2Labs.Hyperlink() ) { hl.GoTo( "http://www.P2Labs.com" ); } // send an email to P2Labs support group using ( P2Labs.Hyperlink hl = new P2Labs.Hyperlink() ) { hl.GoTo( "mailto:support@P2Labs.com" ); } // call P2Labs support hotline using ( P2Labs.Hyperlink hl = new P2Labs.Hyperlink() ) { hl.GoTo( "callto:555.555.5555" ); } // can combine all three previous statements as well... using ( P2Labs.Hyperlink hl = new P2Labs.Hyperlink() ) { hl.GoTo( "http://www.P2Labs.com" ); hl.GoTo( "mailto:support@P2Labs.com" ); hl.GoTo( "callto:555.555.5555" ); }
 
P2IniFile
Read and write to ini files with ease. // write settings to iniFile string strValue = "My Value"; int iValue = 69; bool fValue = true; using ( /b>P2Labs.IniFile if = new P2Labs.IniFile ( "nameOfIniFile" ) ) { if.Write( "section", "stringKey", stringValue ); if.Write( "section", "intKey", intValue ); if.Write( "section", "boolKey", boolValue ); } // read setting from iniFile using ( P2Labs.IniFile if = new P2Labs.IniFile ( "nameOfIniFile" ) ) { strValue = if.ReadString( "section", "stringKey" ); iValue = if.ReadInt( "section", "intKey" ); fValue = if.ReadBool( "section", "boolKey" ); }
 
P2Ipc
Communicate across processes easily. Full asynchronous handling. // send a message using ( P2Labs.Ipc ipc = new P2Labs.Ipc() ) { ipc.Send( "ChannelName", "MessageText" ); }
 
P2Json
Super fast JSON serializer / deserializer. // objOut is a complex object (of type MyObject) containing many items string s = string.Empty; // serialize to a string so we can write it out s = P2Labs.Json.JsonConvert.SerializeObject ( objOut, P2Labs.Json.Formatting.Indented, new P2Labs.Json.JsonSerializerSettings { NullValueHandling = P2Labs.Json.NullValueHandling.Ignore } ); // deserialize back to object MyObject objIn = P2Labs.Json.JsonConvert.DeserializeObject( s );
 
P2Logger
Write to log files with full multi-user and thread safe support. // log a message using ( P2Labs.Logger lo = new P2Labs.Logger( "nameOfLogFile" ) ) { lo.Log( "Message", P2Labs.Logger.Level.Error; }
 
P2Plurals
Tired of seeing "you have changed 1 files" as a message? Now get correct grammer easily. // determine correct message based on count using ( P2Labs.Plurals pl = new P2Labs.Plurals() ) { string strMessage = "You have changed " + pl.PluralPhrase( 1, "file"); }
 
P2RedBlackTree
FAST red black tree for storage and recall of objects. // create a red black tree using ( P2Labs.RedBlack.Tree myTree = new P2Labs.RedBlack.Tree() ) { // add an object - obj1 (of type MyObject) MyTreeObj obj1 = new MyTreeObj( "Some data" ); if ( obj1 != null ) { // create a key object with a key of 1 & add it to the tree MyTreeKey key1 = new MyTreeKey( 1 ); if ( key1 != null ) { // // add it to the tree // myTree.Add( key1,obj1 ); } } // add another object - obj2 (of type MyObject) MyTreeObj obj2 = new MyTreeObj( "Some more data" ); if ( obj2 != null ) { // create a key object with a key of 2 & add it to the tree MyTreeKey key1 = new MyTreeKey( 2 ); if ( key2 != null ) { // // add it to the tree // myTree.Add( key2,obj2 ); } } // traverse the tree with an enumerator using ( P2Labs.RedBlack.TreeEnumerator myEnumerator = myTree.GetEnumerator() ) { string s = string.Empty; while ( myEnumerator.MoveNext() ) { s += string.Format( "Key: {0} Data:{1}\n", myEnumerator.Key, ((MyTreeObj)myEnumerator.Value).Data ); } // s now holds all data } // remove a specific node with a key of 1 MyTreeKey keyToRemove = new MyTreeKey( 1 ); if ( keyToRemove != null ) { myTree.Remove( keyToRemove ); } // empty the tree of all nodes myTree.Clear(); }
 
P2Scheduler
Need an event to fire but want it to run in the background? Done! // // in your form - set when we want the timer to fire // we'll set it to fire in 1 day and 3 hrs and 15 minutes & 10 secs time // System.DateTime dtNow = System.DateTime.Now; System.TimeSpan tsDiff = new TimeSpan( 1,3,15,10 ); System.DateTime dtWhen = dtNow + tsDiff; // // create a scheduler with the timestamp when to fire // and your event handler to be called when it occurs // P2Labs.Scheduler myScheduler = new P2Labs.Scheduler( dtWhen, SchedulerFired ); if ( myScheduler != null ) myScheduler.Start(); ... ... // // elsewhere in your form's code - declare your handler function // void SchedulerFired( object sender, System.ComponentModel.RunWorkerCompletedEventArgs e ) { // // this is called when the scheduler fires // }
 
P2ScrollingBox
Want a professional scrolling control for credits? // create scroller and start P2Labs.ScrollingBox sb = new P2Labs.ScrollingBox (); if ( sb != null ) { sb.Lines.Add ( "This application brought to you by..." ); sb.Lines.Add ( "P2Labs" ); sb.Text = P2Labs.ScrollingBox.Text.Center; sb.Start(); }
 
P2Sound
Add sound to your application in one easy step. // play sound once using ( P2Labs.Sound so = new P2Labs.Sound () ) { so.PlayOnce( "com.P2Labs.test.wav" ); }
 
P2StructuredStorage
Create, read and write structured storage (compound document) files just like Microsoft Office™. // // create a new structured storage and write to it // using ( P2Labs.StructuredStorage.CompoundFile fOut = new P2Labs.StructuredStorage.CompoundFile() ) { // // create a new folder in it called MyFolder1 // P2Labs.StructuredStorage.CFStorage storFolder1 = fOut.RootStorage.AddStorage( "MyFolder1" ); if ( storFolder1 != null ) { // // create a folder within MyFolder1 called MyFolder2 // P2Labs.StructuredStorage.CFStorage storFolder2 = storFolder1.AddStorage( "MyFolder2" ); if ( storFolder2 != null ) { // // create a stream within MyFolder2 to hold data called MyStream1 // P2Labs.StructuredStorage.CFStream stream1 = storFolder2.AddStream( "MyStream1" ); if ( stream1 != null ) { // // write the data out to disk - text is held in strDataOut // stream1.SetText( strDataOut ); fOut.Save( strFileName ); fOut.Close(); } } } } // // open an existing structured storage file // using ( P2Labs.StructuredStorage.CompoundFile fIn = new P2Labs.StructuredStorage.CompoundFile( strFileName ) ) { // // open the folder called MyFolder1 // P2Labs.StructuredStorage.CFStorage storFolder1 = fIn.RootStorage.GetStorage( "MyFolder1" ); if ( storFolder1 != null ) { // // open the folder within MyFolder1 cvalled MyFolder2 // P2Labs.StructuredStorage.CFStorage storFolder2 = storFolder1.GetStorage( "MyFolder2" ); if ( storFolder2 != null ) { // // open the stream called MyStream1 // P2Labs.StructuredStorage.CFStream strIn = storFolder2.GetStream( "MyStream1" ); if ( strIn != null ) { // // get the text // string strDataIn = strIn.GetText(); if ( strDataIn.Length > 0 ) // strDataIn now holds the text fIn.Close(); } } } }
 
P2TaskDialog
Add Windows® Vista™ & Windows 7™ Task dialog boxes to your XP™ applications. // warn the user P2Labs.TaskDialog.MessageBox( "My Application", "Main Title", "Message", "Additional message", "For support please contact "P2Labs", "Don't warn me again", P2Labs.TaskButtons.OK, P2Labs.Icons.Error, P2Labs.Icons.Information ); }
 
P2WaitCursor
Easily switch to the hourglass cursor when carrying out operations. // do time consuming task using ( new P2Labs.WaitCursor() ) { // do task here... }
 
P2WebGet
Need to retrieve raw HTML from a web page. One simple call does it all for you. // // create our webget object and pass the URL // using ( P2Labs.WebGet wget = new P2Labs.WebGet( "http://P2Labs.com" ) ) { // // get the page and store it in strResponse // string strResponse = wget.Call(); }
 
P2XmlSerializer
Super fast serializer to write complex objects out to disk and read them back in. // objOut is a complex object containing collections, lists, arrays, etc. // write object out to disk using ( P2Labs.XmlSerializer serializerOut = new P2Labs.XmlSerializer() ) { serializerOut.WriteToDisk( objOut, "filename.xml" ) } // read data file into new complex object (all internal objects are automatically created) MyComplexObject objIn = null; using ( P2Labs.XmlSerializer serializerIn = new P2Labs.XmlSerializer() ) { objIn = (MyComplexObject)serializerIn.ReadFromDisk( "filename.xml" ) }