private void cmdAdd() { bool repeat = true; int count = 0; string path = ""; string objName = ""; PersistentObjects objs = new PersistentObjects(); while ( repeat ) { Console.WriteLine( "Enter count to add:" ); string str = Console.ReadLine(); try { count = Convert.ToInt32( str ); repeat = false; } catch { } } Console.WriteLine( "Enter object name:" ); objName = Console.ReadLine(); repeat = true; while ( repeat ) { Console.WriteLine( "Enter path to file:" ); path = Console.ReadLine(); if ( (string.IsNullOrEmpty( path )) || File.Exists( path ) ) repeat = false; } Console.WriteLine( DateTime.Now.ToLongTimeString() + ": Starting to create objects " ); TestObject prevObj = null; TestObject obj; Random rnd = new Random(); for ( int i = 0; i < count; i++ ) { obj = new TestObject(); obj.Name = (string.IsNullOrEmpty( objName ) ? i.ToString() : objName); obj._int = rnd.Next( 0, 100 ); obj._bool = ( rnd.Next(0,1) == 1 ? true : false ); obj._double = (Double) rnd.Next( 1, 10 ) / 0.33; obj._datetime = DateTime.Now; obj._string = "String for object" + obj._int; if ( !string.IsNullOrEmpty( path ) ) obj._stream = new PersistentStream( path ); if ( prevObj != null ) obj.Parents.Add( prevObj ); objs.Add( obj ); prevObj = obj; } Console.WriteLine( DateTime.Now.ToLongTimeString() + ": Starting to SAVE objects " ); if ( m_transEnabled ) { m_trans = getTrans(); m_trans.Add( objs, PersistentTransaction.ACTION.Save ); Console.WriteLine( DateTime.Now.ToLongTimeString() + ": Add request added to transaction" ); } else { foreach ( PersistentObject cpobj in objs ) cpobj.Save(); Console.WriteLine( DateTime.Now.ToLongTimeString() + ": End" ); Console.WriteLine( " " + objs.Count + " was added.\n" ); } }
private void cmdTrans() { m_transEnabled = (m_transEnabled ? false : true); if ( !m_transEnabled ) m_trans = null; Console.WriteLine( DateTime.Now.ToLongTimeString() + ": Transaction Mode " + (m_transEnabled ? "On":"Off") ); }