Esempio n. 1
0
 public PageViewModel(Page page, DatabaseViewModel parentDatabase, SessionBase session)
   : base(parentDatabase, true)
 {
   m_dbNum = page.Database.DatabaseNumber;
   m_pageNum = page.PageNumber;
   m_session = session;
 }
Esempio n. 2
0
 public CustomerContact(string company, string firstName, string lastName, string email, string address,
                        string addressLine2, string city, string zipCode, string state, string country, string countryCode, string phone, string fax,
                        string mobile, string skypeName, string webSite, string userName, string password, string howFoundOther, int howFoundChoice,
                        SessionBase session)
 {
   this.company = company;
   this.firstName = firstName;
   this.lastName = lastName;
   this.email = email;
   this.address = address;
   this.addressLine2 = addressLine2;
   this.city = city;
   this.zipCode = zipCode;
   this.state = state;
   this.country = country;
   this.countryCode = countryCode;
   this.phone = phone;
   this.fax = fax;
   this.mobile = mobile;
   this.skypeName = skypeName;
   this.webSite = webSite;
   this.userName = userName;
   this.password = password;
   this.howFoundOther = howFoundOther;
   this.howFoundVelocityDb = (HowFound) howFoundChoice;
   priorVerifiedEmailSet = new SortedSetAny<string>();
 }
Esempio n. 3
0
 void processsMovies(SessionBase session)
 {
   UInt32 actorDbNum = session.DatabaseNumberOf(typeof(Actor));
   foreach (Movie movie in unchasedMovie)
   {
     if (chasedMovie.Contains(movie.ShortId) == false)
     {
       chasedMovie.Add(movie.ShortId);
       foreach (ActingPerson acting in movie.Cast)
       {
         if (acting.DatabaseNumber == actorDbNum)
         {
           if (chasedActor.Contains(acting.ShortId) == false)
           {
             unchasedPerson.Add(acting);
             chasedActor.Add(acting.ShortId);
             resultArray[bacon]++;
           }
         }
         else
           if (chasedActress.Contains(acting.ShortId) == false)
           {
             unchasedPerson.Add(acting);
             chasedActress.Add(acting.ShortId);
             resultArray[bacon]++;
           }
       }
     }
   }
   unchasedMovie.Clear();
 }
Esempio n. 4
0
        public Artist(Link link, SessionBase session, bool browse = false)
        {
            this.Handle = libspotify.sp_link_as_artist(link.Handle);
            this._session = session;

            Init(browse);
        }
Esempio n. 5
0
 public override void Unpersist(SessionBase session)
 {
   m_folder.Files.Remove(this);
   if (m_fileContent != null)
     Content.Unpersist(session);
   base.Unpersist(session);
 }
Esempio n. 6
0
        public void Plug(IOThread ioThread, SessionBase session)
        {
            m_session = session;
            m_encoder.SetMsgSource(session);

            // get the first message from the session because we don't want to send identities
            var msg = new Msg();
            msg.InitEmpty();

            bool ok = session.PullMsg(ref msg);

            if (ok)
            {
                msg.Close();
            }

            AddSocket(m_socket);            

            if (!m_delayedStart)
            {
                StartConnecting();
            }
            else
            {
                m_state = State.Delaying;                
                AddTimer(GetNewReconnectIvl(), ReconnectTimerId);
            }
        }
Esempio n. 7
0
        public Artist(IntPtr artistPtr, SessionBase session, bool browse = false)
        {
            this.Handle = artistPtr;
            this._session = session;

            Init(browse);
        }
 public FederationViewModel(IList<Database> databases, SessionBase session)
 {
   _databases = new ReadOnlyCollection<DatabaseViewModel>(
     (from database in databases
      select new DatabaseViewModel(database, session))
      .ToList());
 }
Esempio n. 9
0
 public ObjectViewModel(object obj, FieldViewModel parentView, int arrayIndex, bool encodedOid, SessionBase session)
   : base(parentView, true)
 {
   m_session = session;
   if (encodedOid)
   {
     if (obj.GetType() == typeof(UInt64))
     {
       m_objectId = (UInt64)obj;
       m_objectAsString = "[" + arrayIndex.ToString() + "] " + new Oid(m_objectId).ToString();
     }
     else
     {
       Oid oid = new Oid(parentView.ParentId);
       oid = new Oid(oid.Database, (UInt32)obj);
       m_objectId = oid.Id;
       m_objectAsString = "[" + arrayIndex.ToString() + "] " + new OidShort(oid.IdShort).ToString();
     }
   }
   else
   {
     IOptimizedPersistable pObj = obj as IOptimizedPersistable;
     if (pObj == null)
       session.GlobalObjWrapperGet(obj, out pObj);
     if (pObj != null)
       m_objectId = pObj.Id;
     m_session = session;
     if (pObj != null && pObj.WrappedObject != obj)
       m_objectAsString = "[" + arrayIndex.ToString() + "] " + pObj.WrappedObject.ToString() + " " + new Oid(pObj.Id);
     else
       m_objectAsString = "[" + arrayIndex.ToString() + "] " + obj.ToString();
   }
 }
Esempio n. 10
0
 public static HashSet<GeoObj> SearchGeoHashIndex(SessionBase session, double lat, double lon, double radius)
 {
   HashSet<GeoObj> resultSet = new HashSet<GeoObj>();
   WGS84Point center = new WGS84Point(lat, lon);
   GeoHashCircleQuery query = new GeoHashCircleQuery(center, radius); // radius in meters
   BoundingBox bbox = query.BoundingBox;
   var btreeSet = session.AllObjects<BTreeSet<GeoObj>>().FirstOrDefault();
   foreach (GeoHash hash in query.SearchHashes)
   {
     var itr = btreeSet.Iterator();
     itr.GoTo(new GeoObj(hash.LongValue));
     var current = itr.Current();
     while (current != null)
     {
       GeoHash geoHash = GeoHash.FromLongValue(current.GeoHash);
       if ((geoHash.SignificantBits >= hash.SignificantBits && geoHash.Within(hash)) || (geoHash.SignificantBits < hash.SignificantBits && hash.Within(geoHash)))
       {
         if (!(current.Latitude < bbox.MinLat || current.Latitude > bbox.MaxLat || current.Longitude < bbox.MinLon || current.Longitude > bbox.MaxLon))
           resultSet.Add(current);
         current = itr.Next();
       }
       else
         break;
     }
   }
   return resultSet;
 }
Esempio n. 11
0
 public ImdbRoot(SessionBase session)
 {   
   actorSet = new BTreeSet<Actor>(null, session);
   actressSet = new BTreeSet<Actress>(null, session);
   actingByNameSet = new BTreeSet<ActingPerson>(actingByNameComparer, session);
   movieSet = new BTreeSet<Movie>(movieNameHashComparer, session, 10000, sizeof(Int32));
 }
Esempio n. 12
0
    public Document(UInt64 id): base(id) {} // for lookups

    public Document(string url, IndexRoot indexRoot, SessionBase session)
    {
      this.url = url;
      HashCodeComparer<Word> hashCodeComparer = new HashCodeComparer<Word>();
      m_wordHit = new BTreeMapOidShort<Word, WordHit>(null, session);
      m_wordHit.TransientBatchSize = 10000;
      wordSet = new BTreeSetOidShort<Word>(hashCodeComparer, session, 1500, sizeof(int));
    }
Esempio n. 13
0
 public Root(SessionBase session, ushort maxEntriesPerNode)
 { 
   CompareCustomerEmail compareCustomerEmail = new CompareCustomerEmail();
   CompareCustomerUserName compareCustomerUserName = new CompareCustomerUserName();
   customersByEmail = new BTreeSet<CustomerContact>(compareCustomerEmail, session, maxEntriesPerNode);
   customersByUserName = new BTreeSet<CustomerContact>(compareCustomerUserName, session, maxEntriesPerNode);
   lastCustomerIdNumber = 0;     
 }
 public void createDatabaseLocations(SessionBase session)
 {
   session.BeginUpdate();
   Person person = new Person("Mats", "Persson", 54);
   session.Persist(person);
   session.Commit();
   verifyDatabaseLocations(session);
 }
Esempio n. 15
0
 public AspNetIdentity(SessionBase session)
 {
   m_adapterMap = new BTreeMap<string, UserLoginInfoAdapter>(null, session);
   m_userSet = new BTreeSet<IdentityUser>(null, session);
   m_roleSet = new BTreeSet<IdentityRole>(null, session);
   m_emailToId = new BTreeMap<string, ulong>(null, session);
   m_userNameToId = new BTreeMap<string, ulong>(null, session);
 }
Esempio n. 16
0
 public FieldViewModel(IOptimizedPersistable parentObj, DataMember member, ObjectViewModel parentObject, SessionBase session)
   : base(parentObject, true)
 {
   _session = session;
   page = parentObj.Page;
   memberObj = member.GetMemberValue(parentObj.WrappedObject);
   isEncodedOidArray = (parentObj as BTreeNode) != null && memberObj != null && (memberObj as Array) != null && (member.Field.Name == "keysArray" || member.Field.Name == "valuesArray");
   fieldAsString = OptimizedPersistable.ToStringDetails(member, parentObj.WrappedObject, parentObj, parentObj.Page, true);
 }
Esempio n. 17
0
 public FederationViewModel(FederationInfo federationInfo) : base(null, true)
 {
   m_federationInfo = federationInfo;
   if (m_federationInfo.UsesServerClient || (SessionBase.IsSameHost(m_federationInfo.HostName, SessionBase.LocalHost) == false))
     m_session = new ServerClientSession(m_federationInfo.SystemDbsPath, m_federationInfo.HostName, m_federationInfo.WaitForMilliSeconds, m_federationInfo.UsePessimisticLocking == false);
   else
     m_session = new SessionNoServer(m_federationInfo.SystemDbsPath, m_federationInfo.WaitForMilliSeconds, m_federationInfo.UsePessimisticLocking == false);
   m_session.BeginRead();
 }
Esempio n. 18
0
    //public BTreeMap<Word, UInt32> globalWordCount;

    public IndexRoot(ushort nodeSize, SessionBase session)
    {
      hashCodeComparer = new HashCodeComparer<Word>();
      lexicon = new Lexicon(nodeSize, hashCodeComparer, session);
      lexicon.Persist(session, lexicon);
      repository = new Repository(nodeSize, session);
      repository.Persist(session, repository, true);
      //globalWordCount = new BTreeMap<Word, uint>(null, session);
    }
 public FederationViewModel(FederationInfo federationInfo) : base(null, true)
 {
   m_federationInfo = federationInfo;
   if (m_federationInfo.UsesServerClient || (m_federationInfo.HostName.Length > 0 &&  m_federationInfo.HostName!= Dns.GetHostName()))
     m_session = new ServerClientSession(m_federationInfo.SystemDbsPath, m_federationInfo.HostName);
   else
     m_session = new SessionNoServer(m_federationInfo.SystemDbsPath);
   m_session.BeginRead();
 }
 public void moveDatabaseLocations(SessionBase session, string updatedHostName, string newPath)
 {
     session.BeginUpdate(false);
     DatabaseLocation bootLocation = session.DatabaseLocations.LocationForDb(0);
     DatabaseLocation locationNew = new DatabaseLocation(updatedHostName, newPath, bootLocation.StartDatabaseNumber, bootLocation.EndDatabaseNumber, session,
         bootLocation.CompressPages, bootLocation.PageEncryption, bootLocation.IsBackupLocation, bootLocation.BackupOfOrForLocation);
     bootLocation = session.NewLocation(locationNew);
     session.Commit(false);
 }
Esempio n. 21
0
 public void InitDatabase()
 {
   if (Directory.Exists(testDir))
     Directory.Delete(testDir, true);
   Directory.CreateDirectory(testDir);
   File.Copy(licensePath, testDir + "4.odb");
   _session = new SessionNoServer(testDir);
   _session.BeginUpdate();
 }
 void Initialize()
 {
   SessionBase.BaseDatabasePath = Properties.Settings.Default.BaseDatabasePath;
   m_session = new SessionNoServer(Properties.Settings.Default.DatabaseManagerDirectory);
   try
   {
     m_session.BeginUpdate();
     List<FederationViewModel> federationInfos = new List<FederationViewModel>();
     List<FederationInfo> federationInfosToRemove = new List<FederationInfo>();
     foreach (FederationInfo info in m_session.AllObjects<FederationInfo>())
     {
       try
       {
         federationInfos.Add(new FederationViewModel(info));
       }
       catch (Exception ex)
       {
         if (MessageBox.Show(ex.Message + " for " + info.HostName + " " + info.SystemDbsPath + " Remove this Database?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
           federationInfosToRemove.Add(info);
       }
     }
     foreach (FederationInfo info in federationInfosToRemove)
       info.Unpersist(m_session);
     if (federationInfos.Count() == 0)
     {
       string host = Properties.Settings.Default.DatabaseManagerHost;
       if (host == null || host.Length == 0)
         host = Dns.GetHostName();
       FederationInfo info = new FederationInfo(host,
         Properties.Settings.Default.DatabaseManagerDirectory,
         Properties.Settings.Default.TcpIpPortNumber,
         Properties.Settings.Default.DoWindowsAuthentication,
         null,
         Properties.Settings.Default.WaitForLockMilliseconds,
         Properties.Settings.Default.UseClientServer,
         "Database Manager");
       m_session.Persist(info);
       m_session.Commit();
       federationInfos.Add(new FederationViewModel(info));
     }
     if (m_session.InTransaction)
       m_session.Commit();
     m_federationViews = federationInfos;
   }
   catch (Exception ex)
   {
     if (m_session.InTransaction)
       m_session.Abort();
     if (MessageBox.Show(ex.Message + " for " + SessionBase.LocalHost + " " + Properties.Settings.Default.DatabaseManagerDirectory + " Remove this Database?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
     {
       DirectoryInfo dir = new DirectoryInfo(Properties.Settings.Default.DatabaseManagerDirectory);
       dir.Delete(true);
       Initialize();
     }
   }
 }
Esempio n. 23
0
 /// <summary>
 /// 调用函数.
 /// </summary>
 /// <param name="session"></param>
 /// <param name="msg"></param>
 /// <returns></returns>
 public Result Call(SessionBase session, APIMessage msg)
 {
     Result result = null;
     MessageHandler handler;
     _messageApilist.TryGetValue(msg.Type, out handler);
     if (handler == null)
         return result;
     result = handler(session, msg.Parameters);
     return result;
 }
Esempio n. 24
0
 public ObjectViewModel(IOptimizedPersistable obj, FieldViewModel parentView, SessionBase session)
   : base(parentView, true)
 {
   _object = obj;
   _session = session;
   if (obj.WrappedObject != obj)
     objectAsString = obj.WrappedObject.ToString() + " " + new Oid(obj.Id);
   else
     objectAsString = obj.ToString();
 }
Esempio n. 25
0
 public ObjectViewModel(IOptimizedPersistable obj, TreeViewItemViewModel parentPage, SessionBase session)
   : base(parentPage, true)
 {
   m_objectId = obj.Id;
   m_session = session;
   if (obj.WrappedObject != obj)
     m_objectAsString = obj.WrappedObject.ToString() + " " + new Oid(obj.Id);
   else
     m_objectAsString = obj.ToString();
 }
Esempio n. 26
0
 public FieldViewModel(IOptimizedPersistable parentObj, DataMember member, ObjectViewModel parentObject, SessionBase session)
   : base(parentObject, true)
 {
   m_member = member;
   m_session = session;
   m_parentId = parentObj.Id; 
   object memberObj = member.GetMemberValue(parentObj.WrappedObject);
   m_isEncodedOidArray = (parentObj as BTreeNode) != null && memberObj != null && (memberObj as Array) != null && (member.Field.Name == "keysArray" || member.Field.Name == "valuesArray");
   m_isEncodedOidArray = m_isEncodedOidArray || parentObj.GetType().IsGenericType && parentObj.GetType().GetGenericTypeDefinition() == typeof(WeakReferenceList<>);
   m_fieldAsString = Utilities.ToStringDetails(member, parentObj.WrappedObject, parentObj, parentObj.Page, true);
 }
 public void verifyDatabaseLocations(SessionBase session)
 {
   session.BeginRead();
   foreach (Person person in session.AllObjects<Person>())
   {
     Console.WriteLine(person.ToString());
     Assert.AreEqual(person.FirstName, "Mats");
   }
   session.Commit();
   session.Verify();
 }
Esempio n. 28
0
        /// <summary>
        /// 表示http回复
        /// </summary>
        /// <param name="session">会话</param>
        public HttpResponse(SessionBase session)
        {
            this.session = session;

            this.Charset = Encoding.UTF8;
            this.Status = 200;
            this.StatusDescription = "OK";

            this.Headers = new HttpHeader();
            this.ContentType = "text/html";
        }
Esempio n. 29
0
 public Folder(string name, Folder parentFolder, SessionBase session) : base(name)
 {
   CompareByField<FileInDb> comparerByFileName = new CompareByField<FileInDb>("m_name", session, false, true);
   m_files = new BTreeSet<FileInDb>(comparerByFileName, session, 10000, CommonTypes.s_sizeOfUInt32);
   CompareByField<Folder> comparerByFolderName = new CompareByField<Folder>("m_name", session, false, true);
   m_subFolders = new BTreeSet<Folder>(comparerByFolderName, session, 10000, CommonTypes.s_sizeOfUInt32);
   if (parentFolder != null)
   {
     m_parentFolder = parentFolder;
     m_parentFolder.Folders.AddFast(this);
   }
 }
Esempio n. 30
0
 public override void Unpersist(SessionBase session)
 {
   if (IsPersistent)
   {
     foreach (var file in m_files.ToArray())
       file.Unpersist(session);
     m_files.Unpersist(session);
     foreach (var folder in m_subFolders.ToArray())
       folder.Unpersist(session);
     m_subFolders.Unpersist(session);
     base.Unpersist(session);
   }
 }
Esempio n. 31
0
 static public void SyncWith(this SessionBase sessionToUpdate, SessionBase sessionOther)
 {
     SyncWith(sessionToUpdate, sessionOther, (session, version, change) => false);
 }
Esempio n. 32
0
        static IEnumerable <Key> LessThan <Key>(BTreeBase <Key, Key> sourceCollection, BinaryExpression binExp)
#if WINDOWS_PHONE
            where Key : new()
#endif
        {
            SessionBase          session    = sourceCollection.Session;
            Expression           leftSide   = binExp.Left;
            Expression           rightSide  = binExp.Right;
            object               rightValue = GetRightValue(leftSide, rightSide);
            CompareByField <Key> comparer   = sourceCollection.Comparer as CompareByField <Key>;

            if (leftSide.NodeType == ExpressionType.Parameter)
            {
                Key key = (Key)rightValue;
                if (key != null)
                {
                    BTreeSetIterator <Key> itr = sourceCollection.Iterator();
                    if (itr.GoTo(key))
                    {
                        while (itr.Previous() != null)
                        {
                            yield return(itr.Current());
                        }
                    }
                }
            }
            else
            {
                if (comparer != null)
                {
                    //if we were able to create a hash from the right side (likely)
                    MemberExpression returnedEx = null;
#if WINDOWS_PHONE || WINDOWS_UWP || NET_CORE
                    Key key = (Key)Activator.CreateInstance(typeof(Key));
#else
                    Key key = (Key)FormatterServices.GetUninitializedObject(typeof(Key));
#endif
                    if (comparer.FieldsToCompare == null)
                    {
                        comparer.SetupFieldsToCompare();
                    }
                    DataMember dataMember = comparer.FieldsToCompare[0];
                    if (rightValue != null && HasIndexablePropertyOnLeft <Key>(leftSide, sourceCollection, dataMember, out returnedEx))
                    {
                        //cast to MemberExpression - it allows us to get the property
                        MemberExpression propExp  = (MemberExpression)returnedEx;
                        MemberInfo       property = propExp.Member;
                        foreach (DataMember member in comparer.FieldsToCompare.Skip(1))
                        {
                            if (member.GetTypeCode == TypeCode.String)
                            {
                                member.SetMemberValue(key, "");
                            }
                        }
                        dataMember.SetMemberValueWithPossibleConvert(key, rightValue);
                        BTreeSetIterator <Key> itr = sourceCollection.Iterator();
                        itr.GoTo(key);
                        var v = itr.Current();
                        if (v == null)
                        {
                            v = itr.Previous();
                        }
                        while (v != null && comparer.CompareField(dataMember, key, v, 0) == 0)
                        {
                            v = itr.Previous();
                        }
                        while (v != null)
                        {
                            yield return(v);

                            v = itr.Previous();
                        }
                    }
                    else if (leftSide.NodeType == ExpressionType.Call)
                    {
                        // don't know yet how to handle TODO

                        /*MethodCallExpression expression = leftSide as MethodCallExpression;
                         * Trace.Out.WriteLine("Method: " + expression.Method.Name);
                         * Trace.Out.WriteLine("Args: ");
                         * foreach (var exp in expression.Arguments)
                         * sourceCollection where */
                    }
                }
            }
        }
 protected IMessage Alloc_OC_Broadcast_Public_NT(SessionBase session, Packet packet)
 {
     return(new Msg_OC_Broadcast_Public_NT(m_server, session, packet));
 }
Esempio n. 34
0
        public void Recover1(SessionBase session)
        {
            Database db = null;

            session.BeginUpdate();
            session.RegisterClass(typeof(SortedSetAny <int>));
            session.RegisterClass(typeof(SortedSetAny <float>));
            db = session.OpenDatabase(88, true, false);
            if (db != null)
            {
                session.DeleteDatabase(db);
            }
            db = session.OpenDatabase(89, true, false);
            if (db != null)
            {
                session.DeleteDatabase(db);
            }
            session.Commit();
            session.BeginUpdate();
            db = session.NewDatabase(88);
            session.FlushUpdates();
            session.Abort();
            session.BeginUpdate();
            db = session.NewDatabase(88);
            SortedSetAny <float> floatSet;
            Oid       floatSetOid;
            string    dbPath = System.IO.Path.Combine(systemDir, "89.odb");
            Placement place  = new Placement(88);

            for (int i = 0; i < 10; i++)
            {
                floatSet = new SortedSetAny <float>();
                floatSet.Persist(place, session);
                floatSetOid = floatSet.Oid;
            }
            db = session.NewDatabase(89);
            session.Commit();
            File.Delete(dbPath);
            session.BeginUpdate();
            db = session.NewDatabase(89);
            session.Commit();
            FileInfo info = new FileInfo(dbPath);

            info.CopyTo(dbPath + "X");
            session.BeginUpdate();
            SortedSetAny <int> intSet;

            place = new Placement(89);
            for (int i = 0; i < 10; i++)
            {
                intSet = new SortedSetAny <int>();
                intSet.Persist(place, session);
            }
            db = session.OpenDatabase(88);
            var list = db.AllObjects <SortedSetAny <float> >();

            foreach (SortedSetAny <float> set in list)
            {
                set.Unpersist(session);
            }
            db = session.OpenDatabase(89);
            session.Commit();
            intSet = null;
            db     = null; // release refs so that cached data isn't stale
            File.Delete(dbPath);
            info = new FileInfo(dbPath + "X");
            info.MoveTo(dbPath);
            session.BeginUpdate();
            intSet = (SortedSetAny <int>)session.Open(89, 1, 1, false);
            Debug.Assert(intSet == null);
            object o = session.Open(88, 1, 1, false);

            floatSet = (SortedSetAny <float>)o;
            Debug.Assert(floatSet != null);
            session.Checkpoint();
            db = session.OpenDatabase(88);
            session.DeleteDatabase(db);
            db = session.OpenDatabase(89);
            session.DeleteDatabase(db);
            session.Commit();
        }
 public Msg_Svr_RegisterAtCenter_RQ(appServer server, SessionBase session, Packet packet)
 {
     m_server     = server;
     m_recvPacket = packet;
     m_session    = session as ServerSession;
 }
        /// <summary>
        /// Persists this object.
        /// </summary>
        /// <param name="placeHint">Use placement as specified by this object type, see <see cref="OptimizedPersistable.PlacementDatabaseNumber"/>, <see cref="OptimizedPersistable.ObjectsPerPage()"/> and <see cref="OptimizedPersistable.PagesPerDatabase()"/></param>
        /// <param name="session">The session managing this object</param>
        /// <param name="persistRefs">Persist any referenced object now or delay until flush/commit</param>
        /// <param name="disableFlush">Controlls possible flushing of updated pages. Set to true if you want to prevent updated pages from being flushed to disk and setting such pages to a non updated state.</param>
        /// <returns>The object id of the persistent object</returns>
        public virtual UInt64 Persist(SessionBase session, IOptimizedPersistable placeHint, bool persistRefs = true, bool disableFlush = false)
        {
            Placement place = new Placement(session, placeHint, this, persistRefs, UInt32.MaxValue, placeHint.FlushIfPageFull);

            return(session.Persist(place, this, session.OpenSchema(false), UInt16.MaxValue - 1, disableFlush));
        }
 /// <summary>
 /// This function is called when an object has been read from disk before all data members (fields) have been fully loaded. Override this to provide your own initializtions of transient data.
 /// </summary>
 /// <param name="session">The active session managing this object</param>
 public virtual void InitializeAfterRecreate(SessionBase session)
 {
 }
Esempio n. 38
0
        public void IndexSample(bool useServerSession)
        {
            string           brandName              = "Toyota";
            string           color                  = "Blue";
            int              maxPassengers          = 5;
            int              fuelCapacity           = 40;
            double           litresPer100Kilometers = 5;
            DateTime         modelYear              = new DateTime(2003, 1, 1);
            string           modelName              = "Highlander";
            int              maxSpeed               = 200;
            int              odometer               = 100000;
            string           registrationState      = "Texas";
            string           registrationPlate      = "TX343434";
            string           insurancePolicy        = "CAA7878787";
            DriversLicense   license                = new DriversLicense("California", "B7788888", DateTime.Now + new TimeSpan(1825, 0, 0, 0));
            Person           person                 = new Person("Mats Persson", license);
            InsuranceCompany insuranceCompany       = new InsuranceCompany("Allstate", "858727878");
            Car              car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed,
                                           odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                foreach (Database db in session.OpenAllDatabases(true))
                {
                    if (db.DatabaseNumber >= 10 || db.DatabaseNumber == SessionBase.IndexDescriptorDatabaseNumber)
                    {
                        session.DeleteDatabase(db);
                    }
                }
                session.Commit();

                session.BeginUpdate();
                DatabaseLocation defaultLocation = session.DatabaseLocations.Default();
                List <Database>  dbList          = session.OpenLocationDatabases(defaultLocation, true);
                foreach (Database db in dbList)
                {
                    if (db.DatabaseNumber > Database.InitialReservedDatabaseNumbers)
                    {
                        session.DeleteDatabase(db);
                    }
                }
                session.DeleteLocation(defaultLocation);
                session.Commit();
                CreateDirectoryAndCopyLicenseDb();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginRead();
                int ct     = 0;
                var mIndex = session.Index <Motorcycle>();
                if (mIndex != null)
                {
                    foreach (Motorcycle mc in session.Index <Motorcycle>())
                    {
                        Assert.NotNull(mc);
                        ++ct;
                    }
                }
                Assert.AreEqual(ct, 0);
                session.Commit();
            }
            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                for (int i = 0; i < 10000; i++)
                {
                    Motorcycle mc = new Motorcycle();
                    session.Persist(mc);
                }
                session.Commit();
                session.BeginUpdate();
                int ct     = 0;
                var mIndex = session.Index <Car>();
                if (mIndex != null)
                {
                    foreach (Car c in mIndex)
                    {
                        Assert.NotNull(c);
                        ++ct;
                    }
                }
                Assert.AreEqual(ct, 0);
                ct = 0;
                session.RegisterClass(typeof(Person));
                foreach (Person p in session.AllObjects <Person>(true, false))
                {
                    Assert.NotNull(p);
                    ++ct;
                }
                session.Commit();
                session.BeginRead();
                ct = 0;
                foreach (Motorcycle mc in session.AllObjects <Motorcycle>(false, true))
                {
                    Assert.NotNull(mc);
                    ++ct;
                }
                Assert.AreEqual(ct, 10000);
                session.Commit();
                session.BeginRead();
                ct = 0;
                foreach (Motorcycle mc in session.AllObjects <Motorcycle>(false, true))
                {
                    Assert.NotNull(mc);
                    ++ct;
                }
                Assert.AreEqual(ct, 10000);
                session.Abort();
                session.BeginRead();
                ct = 0;
                foreach (Motorcycle mc in session.AllObjects <Motorcycle>(false, true))
                {
                    Assert.NotNull(mc);
                    ++ct;
                }
                Assert.AreEqual(ct, 10000);
                session.Commit();
                session.BeginRead();
                ct = 0;
                foreach (Motorcycle mc in session.Index <Motorcycle>())
                {
                    Assert.NotNull(mc);
                    ++ct;
                }
                Assert.AreEqual(ct, 10000);
                session.Abort();
                session.BeginRead();
                ct = 0;
                foreach (Motorcycle mc in session.Index <Motorcycle>())
                {
                    Assert.NotNull(mc);
                    ++ct;
                }
                Assert.AreEqual(ct, 10000);
                session.Commit();
                try
                {
                    ct = 0;
                    foreach (Motorcycle mc in session.Index <Motorcycle>())
                    {
                        Assert.NotNull(mc);
                        ++ct;
                    }
                    Assert.AreEqual(ct, 10000);
                }
                catch (NotInTransactionException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                session.BeginUpdate();
                ct = 0;
                foreach (Motorcycle mc in session.AllObjects <Motorcycle>(false, true))
                {
                    if (++ct % 2 == 0)
                    {
                        mc.Unpersist(session);
                    }
                }
                ct = 0;
                foreach (Motorcycle mc in session.Index <Motorcycle>())
                {
                    ++ct;
                }
                Assert.AreEqual(ct, 5000);
                session.Abort();
                session.BeginUpdate();
                ct = 0;
                foreach (Motorcycle mc in session.AllObjects <Motorcycle>(false, true))
                {
                    if (++ct % 2 == 0)
                    {
                        mc.Unpersist(session);
                    }
                }
                ct = 0;
                foreach (Motorcycle mc in session.Index <Motorcycle>())
                {
                    Assert.NotNull(mc);
                    ++ct;
                }
                Assert.AreEqual(ct, 5000);
                ct = 0;
                foreach (Motorcycle mc in session.Index <Motorcycle>("cc"))
                {
                    Assert.NotNull(mc);
                    ++ct;
                }
                Assert.AreEqual(ct, 5000);
                ct = 0;
                try
                {
                    foreach (Motorcycle mc in session.Index <Motorcycle>("ccx"))
                    {
                        Assert.NotNull(mc);
                        ++ct;
                    }
                    Assert.AreEqual(ct, 5000);
                }
                catch (FieldDoesNotExistException)
                {
                }
                session.Commit();
                session.BeginUpdate();
                ct = 0;
                double prior = -44.0;
                foreach (Motorcycle mc in session.Index <Motorcycle>("cc"))
                {
                    Assert.NotNull(mc);
                    mc.CC = mc.CC - prior;
                    prior = mc.CC;
                    ++ct;
                }
                Assert.AreEqual(ct, 2500);
                for (int i = 0; i < 95000; i++)
                {
                    Motorcycle mc = new Motorcycle();
                    session.Persist(mc);
                }
                session.FlushUpdates();
                ct = 0;
                foreach (Motorcycle mc in session.Index <Motorcycle>())
                {
                    Assert.NotNull(mc);
                    ++ct;
                }
                Assert.AreEqual(ct, 100000);
                session.Abort();
                session.BeginUpdate();
                ct    = 0;
                prior = double.MinValue;
                foreach (Motorcycle mc in session.Index <Motorcycle>("cc"))
                {
                    Assert.NotNull(mc);
                    Assert.GreaterOrEqual(mc.CC, prior);
                    prior = mc.CC;
                    ++ct;
                    if (ct < 25)
                    {
                        Console.Write(prior.ToString() + " ");
                    }
                }
                ct    = 0;
                prior = -44.0;
                foreach (Motorcycle mc in session.Index <Motorcycle>("cc"))
                {
                    Assert.NotNull(mc);
                    mc.CC = mc.CC - prior;
                    prior = mc.CC;
                    ++ct;
                }
                Assert.AreEqual(ct, 2500);
                session.Commit();
                session.BeginUpdate();
                ct    = 0;
                prior = double.MinValue;
                foreach (Motorcycle mc in session.Index <Motorcycle>("cc"))
                {
                    Assert.NotNull(mc);
                    Assert.GreaterOrEqual(mc.CC, prior);
                    prior = mc.CC;
                    ++ct;
                }
                for (int i = 0; i < 95000; i++)
                {
                    Motorcycle mc = new Motorcycle();
                    session.Persist(mc);
                    DataBaseFileEntry dbEntry = new DataBaseFileEntry {
                        Something = "Something"
                    };
                    session.Persist(dbEntry);
                    mc.AddChild(dbEntry);
                    mc.AddChild(dbEntry);
                }
                session.FlushUpdates();
                ct = 0;
                foreach (Motorcycle mc in session.Index <Motorcycle>())
                {
                    Assert.NotNull(mc);
                    ++ct;
                }
                Assert.AreEqual(ct, 100000);
                session.Commit();
                session.BeginRead();
                session.Abort();
                session.BeginUpdate();
                foreach (Motorcycle mc in session.Index <Motorcycle>())
                {
                    Assert.NotNull(mc);
                    VelocityDbList <DataBaseFileEntry> children = mc.Children;
                    if (children != null && children.Count > 0)
                    {
                        mc.RemoveChild(children[0]);
                    }
                    ++ct;
                }
                session.Commit();
                session.BeginRead();
                ct    = 0;
                prior = double.MinValue;
                foreach (Motorcycle mc in session.Index <Motorcycle>("cc"))
                {
                    Assert.NotNull(mc);
                    Assert.GreaterOrEqual(mc.CC, prior);
                    prior = mc.CC;
                    ++ct;
                }
                Assert.AreEqual(ct, 100000);
                session.Commit();
                Console.WriteLine("Motorcycle index Test OK");
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                session.Persist(car);
                registrationState = "Maine";
                car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed,
                              odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);
                session.Persist(car);
                color                  = "Red";
                maxPassengers          = 5;
                fuelCapacity           = 50;
                litresPer100Kilometers = 8;
                modelYear              = new DateTime(2006, 1, 1);
                brandName              = "Toyota";
                modelName              = "Tacoma";
                maxSpeed               = 210;
                odometer               = 50000;
                registrationState      = "Texas";
                registrationPlate      = "TX343433";
                insurancePolicy        = "CAA7878777";
                car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed,
                              odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);
                session.Persist(car);
                color                  = "Black";
                maxPassengers          = 5;
                fuelCapacity           = 60;
                litresPer100Kilometers = 3;
                modelYear              = new DateTime(2001, 1, 1);
                brandName              = "Lincoln";
                modelName              = "Town Car";
                maxSpeed               = 220;
                odometer               = 250000;
                registrationState      = "Texas";
                registrationPlate      = "TX543433";
                insurancePolicy        = "CAA7878775";
                for (int i = 0; i < 1; i++)
                {
                    registrationState = RandomString(2);
                    registrationPlate = RandomString(12);
                    car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed, odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);
                    session.Persist(car);
                    color                  = null;
                    maxPassengers          = i;
                    fuelCapacity           = 60;
                    litresPer100Kilometers = 3;
                    modelYear              = new DateTime(2001, 1, 1);
                    brandName              = "Null Car";
                    modelName              = null;
                    maxSpeed               = 220;
                    odometer               = 250000;
                    insurancePolicy        = null;
                }
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginRead();
                Console.WriteLine("Blue Cars");
                BTreeSet <Car> bTree = session.Index <Car>("color");
                foreach (Car c in (from aCar in bTree where aCar.Color == "Blue" select aCar))
                {
                    Console.WriteLine(c.ToStringDetails(session));
                }
                Console.WriteLine("Cars in fuel efficierncy order");
                foreach (Car c in session.Index <Car>("litresPer100Kilometers"))
                {
                    Console.WriteLine(c.ToStringDetails(session));
                }
                Console.WriteLine("Vehicles ordered modelYear, brandName, modelName, color");
                foreach (Vehicle v in session.Index <Vehicle>())
                {
                    Console.WriteLine(v.ToStringDetails(session));
                }
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                // these LINQ statements will trigger a binary search lookup (not a linear serach) of the matching Car objects in the BTreeSet
                Car c = (from aCar in session.Index <Car>("color") where aCar.Color == "Blue" select aCar).First();
                c.Color = "Green";
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                // these LINQ statements will trigger a binary search lookup (not a linear serach) of the matching Car objects in the BTreeSet
                Car    c  = (from aCar in session.Index <Car>("color") where aCar.Color == "Green" select aCar).First();
                UInt64 id = c.Id;
                session.DeleteObject(id);
                session.Abort();
                session.BeginUpdate();
                session.DeleteObject(id);
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                session.BeginRead();
                // these LINQ statements will trigger a binary search lookup (not a linear serach) of the matching Car objects in the BTreeSet
                Console.WriteLine("Blue Cars");
                foreach (Car c in (from aCar in session.Index <Car>("color") where aCar.Color == "Blue" select aCar))
                {
                    Console.WriteLine(c.ToStringDetails(session));
                }
                session.Commit();
                sw.Stop();
                Console.WriteLine(sw.Elapsed);
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                for (int i = 0; i < 10000; i++)
                { // add some junk to make search harder
                    car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, i,
                                  odometer, registrationState, registrationPlate + i, insuranceCompany, insurancePolicy);
                    session.Persist(car);
                }
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginRead();
                // these LINQ statements will trigger a binary search lookup (not a linear serach) of the matching Car objects in the BTreeSet
                Console.WriteLine("Blue Cars");
                foreach (Car c in (from aCar in session.Index <Car>("color") where aCar.Color == "Blue" select aCar))
                {
                    Console.WriteLine(c.ToStringDetails(session));
                }
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                Car c = (from aCar in session.Index <Car>("color") where aCar.Color == "Blue" select aCar).First();
                c.Unpersist(session);
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginRead();
                foreach (Car c in session.Index <Car>())
                {
                    Console.WriteLine(c.ToStringDetails(session));
                }
                Console.WriteLine("Blue Cars");
                foreach (Car c in (from aCar in session.Index <Car>() where aCar.Color == "Blue" select aCar))
                {
                    Console.WriteLine(c.ToStringDetails(session));
                }
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                InsuranceCompany prior = insuranceCompany;
                try
                {
                    for (int i = 0; i < 100000; i++)
                    {
                        insuranceCompany = new InsuranceCompany("AAA", "858787878");
                        insuranceCompany.Persist(session, prior);
                        prior = insuranceCompany;
                    }
                    Assert.IsTrue(false); // should not get here
                }
                catch (UniqueConstraintException)
                {
                }
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginRead();
                Database db = session.OpenDatabase(session.DatabaseNumberOf(typeof(InsuranceCompany)));
                var      q  = from company in session.Index <InsuranceCompany>("name", db) where company.Name == "AAA" select company;
                foreach (InsuranceCompany company in q)
                {
                    Console.WriteLine(company.ToStringDetails(session)); // only one will match
                }
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                InsuranceCompany prior = insuranceCompany;
                try
                {
                    for (int i = 0; i < 100000; i++)
                    {
                        insuranceCompany = new InsuranceCompany("AAA", "858787878");
                        session.Persist(insuranceCompany);
                    }
                    Assert.IsTrue(false); // should not get here
                }
                catch (UniqueConstraintException)
                {
                }
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginRead();
                Database db = session.OpenDatabase(session.DatabaseNumberOf(typeof(InsuranceCompany)));
                var      q  = from company in session.Index <InsuranceCompany>("name", db) where company.Name == "AAA" select company;
                foreach (InsuranceCompany company in q)
                {
                    Console.WriteLine(company.ToStringDetails(session)); // only one will match
                }
                bool exists = (from anEntry in session.Index <InsuranceCompany>("name", db) where anEntry.Name == "AAA" select 0).Any();
                Assert.IsTrue(exists);
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                try
                {
                    for (int i = 0; i < 100000; i++)
                    {
                        insuranceCompany = new InsuranceCompanySpecial("AAA", "858787878");
                        session.Persist(insuranceCompany);
                    }
                    Assert.IsTrue(false); // should not get here
                }
                catch (UniqueConstraintException)
                {
                }
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                try
                {
                    for (int i = 0; i < 100000; i++)
                    {
                        insuranceCompany = new InsuranceCompanySpecial2("AAA", "858787878");
                        session.Persist(insuranceCompany);
                    }
                    Assert.IsTrue(false); // should not get here
                }
                catch (UniqueConstraintException)
                {
                }
                session.Commit();
            }

            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                session.BeginRead();
                Database db = session.OpenDatabase(session.DatabaseNumberOf(typeof(InsuranceCompanySpecial)));
                var      q  = from company in session.Index <InsuranceCompany>("name", db) where company.Name == "AAA" select company;
                foreach (InsuranceCompany company in q)
                {
                    Console.WriteLine(company.ToStringDetails(session)); // only one will match
                }
                bool exists = (from anEntry in session.Index <InsuranceCompanySpecial>("name", db) where anEntry.Name == "AAA" select 0).Any();
                Assert.IsTrue(exists);
                session.Commit();
            }
        }
Esempio n. 39
0
        string DisplayData(bool useServerSession)
        {
            using (SessionBase session = useServerSession ? (SessionBase) new ServerClientSession(systemDir) : (SessionBase) new SessionNoServer(systemDir))
            {
                StringBuilder sb = new StringBuilder();
                session.BeginRead();
                try
                {
                    BTreeBase <RDerby1, RDerby1> index = null;
                    try
                    {
                        session.Index <RDerby1>();
                    }
                    catch (IndexDatabaseNotSpecifiedException)
                    {
                        UInt32   dbId = session.DatabaseNumberOf(typeof(RDerby1));
                        Database db   = session.OpenDatabase(dbId);
                        index = session.Index <RDerby1>(db);
                    }

                    // for testing
                    //var index = session.Index<Test1_0_0Class>("name2");


                    // create variable so that can examine in Locals

                    if (index != null) // should not be null?
                    {
                        // get all
                        var testEntries = from t in index
                                          select t;

                        int count = testEntries.ToList <RDerby1>().Count;
                        int i     = 0;

                        sb.AppendLine("Session Details:");
                        sb.AppendLine(index.ToStringDetails(session));
                        sb.AppendLine("Results:");
                        foreach (RDerby1 test in testEntries)
                        {
                            try
                            {
                                string values = test.Name + ", " + test.Name2 + ", " + test.Added;

                                sb.AppendLine(string.Format("{0, -5:00000}: {1}", i++, values));
                            }
                            catch (Exception ex)
                            {
                                return("Exception thrown in for each loop: " + ex.Message);
                            }
                        }
                    }
                    else
                    {
                        return("Index was null");
                        // why is the index null?
                    }
                }
                catch (Exception ex)
                {
                    return("Exception occured prior to loop: " + ex.Message);
                    // examine problem using breakpoint.
                }
                finally
                {
                    session.Commit();
                }
                return(sb.ToString());
            }
        }
Esempio n. 40
0
 public EdgeViewModel(Edge edge, TreeViewItemViewModel parentPage, SessionBase session)
     : base(parentPage, true)
 {
     _edge     = edge;
     m_session = session;
 }
Esempio n. 41
0
 private void ProcessPollingRoutine(SessionBase session)
 {
     Run(session.CurrentModule.ModuleIdentifier, session.PollingRoutine, session.Channel,
         true);
 }
Esempio n. 42
0
 public FieldViewModel(IOptimizedPersistable parentObj, DataMember member, ObjectViewModel parentObject, SessionBase session)
     : base(parentObject, true)
 {
     _session          = session;
     page              = parentObj.Page;
     memberObj         = member.GetMemberValue(parentObj.WrappedObject);
     isEncodedOidArray = (parentObj as BTreeNode) != null && memberObj != null && (memberObj as Array) != null && (member.Field.Name == "keysArray" || member.Field.Name == "valuesArray");
     fieldAsString     = Utilities.ToStringDetails(member, parentObj.WrappedObject, parentObj, parentObj.Page, true);
 }
Esempio n. 43
0
        static public void SyncWith(this SessionBase sessionToUpdate, SessionBase sessionToRead, Func <SessionBase, UInt64, Change, bool> doUpdate)
        {
            UInt64 currentVersion;
            UInt64 pageToReadVersion;
            bool   conflictFound = false;

            using (var reader = sessionToRead.BeginRead())
            {
                Changes changes = (Changes)sessionToRead.Open(5, 1, 1, false);
                if (changes != null)
                {
                    using (var updater = sessionToUpdate.BeginUpdate())
                    {
                        var         dbs = sessionToUpdate.OpenAllDatabases();
                        ReplicaSync matchingReplicaSync = null;
                        foreach (ReplicaSync sync in sessionToUpdate.AllObjects <ReplicaSync>())
                        {
                            if (sync.SyncFromHost == sessionToRead.SystemHostName && sync.SyncFromPath == sessionToRead.SystemDirectory)
                            {
                                matchingReplicaSync = sync;
                                break;
                            }
                        }
                        if (changes.ChangeList.Count > 0)
                        {
                            foreach (TransactionChanges transactionChanges in changes.ChangeList)
                            {
                                if (matchingReplicaSync == null || matchingReplicaSync.TransactionNumber < transactionChanges.TransactionNumber)
                                {
                                    foreach (Change change in transactionChanges.ChangeList)
                                    {
                                        Database dbToUpdate = sessionToUpdate.OpenDatabase(change.DatabaseId, false, false);
                                        Database dbToRead   = sessionToRead.OpenDatabase(change.DatabaseId, false, false);
                                        string   dbName     = dbToRead != null ? dbToRead.Name : null;
                                        if (change.Deleted)
                                        {
                                            if (dbToUpdate == null) // does not exist
                                            {
                                                continue;
                                            }
                                            if (change.PageId == 0) // Database delete
                                            {
                                                currentVersion = dbToUpdate.GetPage().PageInfo.VersionNumber;
                                                if (currentVersion < change.Version)
                                                {
                                                    sessionToUpdate.DeleteDatabase(dbToUpdate);
                                                }
                                                else
                                                {
                                                    conflictFound = true;
                                                    if (doUpdate(sessionToUpdate, currentVersion, change))
                                                    {
                                                        sessionToUpdate.DeleteDatabase(dbToUpdate);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                Page page = sessionToUpdate.OpenPage(dbToUpdate, change.PageId);
                                                if (page == null) // page does not exist
                                                {
                                                    continue;
                                                }
                                                currentVersion = page.PageInfo.VersionNumber;
                                                if (currentVersion < change.Version)
                                                {
                                                    sessionToUpdate.DeletePage(dbToUpdate, page);
                                                }
                                                else
                                                {
                                                    conflictFound = true;
                                                    if (doUpdate(sessionToUpdate, currentVersion, change))
                                                    {
                                                        sessionToUpdate.DeleteDatabase(dbToUpdate);
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (dbToUpdate == null) // does not exist
                                            {
                                                dbToUpdate = sessionToUpdate.NewDatabase(change.DatabaseId, 0, dbName);
                                            }
                                            if (change.PageId > 0)
                                            {
                                                Page pageToUpdate = sessionToUpdate.OpenPage(dbToUpdate, change.PageId);
                                                Page pageToRead   = sessionToRead.OpenPage(dbToRead, change.PageId);
                                                if (pageToRead == null) // upcoming (not yet processed) changes must have deleted this page
                                                {
                                                    continue;
                                                }
                                                currentVersion    = pageToUpdate == null ? 0 : pageToUpdate.PageInfo.VersionNumber;
                                                pageToReadVersion = pageToRead.PageInfo.VersionNumber;
                                                if (currentVersion < pageToReadVersion || dbToUpdate.IsNew)
                                                {
                                                    sessionToUpdate.ReplacePage(dbToUpdate, pageToUpdate, pageToRead);
                                                }
                                                else
                                                {
                                                    conflictFound = true;
                                                    if (doUpdate(sessionToUpdate, currentVersion, change))
                                                    {
                                                        sessionToUpdate.ReplacePage(dbToUpdate, pageToUpdate, pageToRead);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            UInt64 lastTransactionNumber = changes.ChangeList.Last().TransactionNumber;
                            if (matchingReplicaSync != null)
                            {
                                matchingReplicaSync.TransactionNumber = lastTransactionNumber;
                            }
                            if (conflictFound)
                            {
                                sessionToUpdate.Verify();
                            }
                            sessionToUpdate.Commit();
                            if (matchingReplicaSync == null)
                            {
                                sessionToUpdate.BeginUpdate(); // separate transaction or else gets confused with databases added by sync
                                matchingReplicaSync = new ReplicaSync(sessionToRead, lastTransactionNumber);
                                sessionToUpdate.Persist(matchingReplicaSync);
                                sessionToUpdate.Commit();
                            }
                        }
                    }
                }
            }
        }
Esempio n. 44
0
        static public SyncOperationStatistics MicrosoftSync(this SessionBase sessionToUpdate, SessionBase sessionToRead)
        {
            SyncProvider     sourceProvider = new SyncProvider(sessionToRead);
            SyncProvider     destProvider   = new SyncProvider(sessionToUpdate);
            SyncOrchestrator syncAgent      = new SyncOrchestrator();

            syncAgent.LocalProvider  = sourceProvider;
            syncAgent.RemoteProvider = destProvider;
            return(syncAgent.Synchronize());
        }
 public void ReadMe(TypeVersion typeVersion, byte[] memberBytes, ref int offset, SessionBase session,
                    Page page, bool useOidShort, Schema schema, bool openRefs, List <IOptimizedPersistable> toLoadMembers,
                    int graphDepth, int graphDepthToLoad, bool primitivesOnly)
 {
     OptimizedPersistable.ReadMeUsingSchemaReflection(typeVersion, memberBytes, ref offset, this, session, page, useOidShort, schema, openRefs, toLoadMembers, graphDepth, graphDepthToLoad, primitivesOnly);
 }
Esempio n. 46
0
 private void SignupUsernameDisplay(SessionBase session)
 {
     session.SendToClient("\r\n|CYAN||B|Please enter a unique Username (Max. 29 Characters):|RESET||WHITE||B|\r\n".EncodeToANSIArray());
     session.SessionState = EnumSessionState.SignupUsernameInput;
 }
 public virtual void PersistMyReferences(SessionBase session, bool inFlush)
 {
     Shape.PersistRefences(WrappedObject, m_page.PageInfo, this, session, inFlush);
 }
Esempio n. 48
0
        /// <summary>
        ///     Invokes Method based on the Session State
        /// </summary>
        /// <param name="session"></param>
        /// <param name="modules"></param>
        public bool ProcessSessionState(SessionBase session, Dictionary <string, MbbsModule> modules)
        {
            switch (session.SessionState)
            {
            case EnumSessionState.Unauthenticated:
                WelcomeScreenDisplay(session);
                break;

            case EnumSessionState.LoginUsernameDisplay:
                LoginUsernameDisplay(session);
                break;

            case EnumSessionState.LoginUsernameInput:
                LoginUsernameInput(session);
                break;

            case EnumSessionState.LoginPasswordDisplay:
                LoginPasswordDisplay(session);
                break;

            case EnumSessionState.LoginPasswordInput:
                LoginPasswordInput(session);
                break;

            case EnumSessionState.SignupPasswordConfirmDisplay:
                SignupPasswordConfirmDisplay(session);
                break;

            case EnumSessionState.SignupPasswordConfirmInput:
                SignupPasswordConfirmInput(session);
                break;

            case EnumSessionState.MainMenuDisplay:
                MainMenuDisplay(session, modules);
                break;

            case EnumSessionState.MainMenuInputDisplay:
                MainMenuInputDisplay(session);
                break;

            case EnumSessionState.MainMenuInput:
                MainMenuInput(session, modules);
                break;

            case EnumSessionState.ConfirmLogoffDisplay:
                LogoffConfirmationDisplay(session);
                break;

            case EnumSessionState.ConfirmLogoffInput:
                LogoffConfirmationInput(session);
                break;

            case EnumSessionState.SignupUsernameDisplay:
                SignupUsernameDisplay(session);
                break;

            case EnumSessionState.SignupUsernameInput:
                SignupUsernameInput(session);
                break;

            case EnumSessionState.SignupPasswordDisplay:
                SignupPasswordDisplay(session);
                break;

            case EnumSessionState.SignupPasswordInput:
                SignupPasswordInput(session);
                break;

            case EnumSessionState.SignupEmailDisplay:
                SignupEmailDisplay(session);
                break;

            case EnumSessionState.SignupEmailInput:
                SignupEmailInput(session);
                break;

            case EnumSessionState.LoggingOffDisplay:
                LoggingOffDisplay(session);
                break;

            default:
                return(false);
            }

            return(true);
        }
 /// <summary>
 /// Persists this object.
 /// </summary>
 /// <param name="place">The placement rules to follow when persisting this object</param>
 /// <param name="session">The session managing this object</param>
 /// <param name="persistRefs">If true, objects referenced from this object will also be persisted</param>
 /// <param name="disableFlush">If true, disables possible flushing of updated pages while persisting this object; otherwise pasge flushing may occur</param>
 /// <returns>The object id of the persistent object</returns>
 public virtual UInt64 Persist(Placement place, SessionBase session, bool persistRefs = true, bool disableFlush = false, Queue <IOptimizedPersistable> toPersist = null)
 {
     return(session.Persist(place, this, session.OpenSchema(false), place.MaxObjectsPerPage, disableFlush, toPersist));
 }
Esempio n. 50
0
 private void SignupEmailDisplay(SessionBase session)
 {
     session.SendToClient("\r\n|CYAN||B|Please enter a valid e-Mail Address:|RESET|\r\n|WHITE||B|".EncodeToANSIArray());
     session.SessionState = EnumSessionState.SignupEmailInput;
 }
 /// <summary>
 /// This function is called when an object has been read from disk and all data members (fields) have been loaded. Override this to provide your own initializtions of transient data.
 /// </summary>
 /// <param name="session">The active session managing this object</param>
 public virtual void InitializeAfterRead(SessionBase session)
 {
 }
Esempio n. 52
0
 private void ProcessSTSROU(SessionBase session)
 {
     session.StatusChange = false;
     Run(session.CurrentModule.ModuleIdentifier, session.CurrentModule.EntryPoints["stsrou"],
         session.Channel);
 }
Esempio n. 53
0
 public Mechanism(SessionBase session, Options options)
 {
     Session = session;
     Options = options;
 }
Esempio n. 54
0
        public void sessionPoolTest()
        {
            const int   numberOfSessions = 5;
            SessionPool pool             = new SessionPool(numberOfSessions, () => new SessionNoServer(systemDir));

            {
                int         sessionId = -1;
                SessionBase session   = null;
                try
                {
                    session = pool.GetSession(out sessionId);
                    session.BeginUpdate();
                    for (int i = 0; i < 1000; i++)
                    {
                        Man man = new Man();
                        session.Persist(man);
                    }
                    session.Commit();
                }
                catch (Exception e)
                {
                    if (session != null)
                    {
                        session.Abort();
                    }
                    Console.WriteLine(e.Message);
                    throw e;
                }
                finally
                {
                    pool.FreeSession(sessionId, session);
                }
            }

            Parallel.ForEach(Enumerable.Range(0, numberOfSessions * 5),
                             x =>
            {
                int sessionId       = -1;
                SessionBase session = null;
                try
                {
                    session = pool.GetSession(out sessionId);
                    if (session.InTransaction == false)
                    {
                        session.BeginRead();
                    }
                    var allMen   = session.AllObjects <Man>();
                    int allMenCt = allMen.Count();
                    foreach (Man man in allMen)
                    {
                        double lat = man.Lattitude;
                    }
                    Console.WriteLine("Man Count is: " + allMenCt + " Session Id is: " + sessionId + " Current task id is: " + (Task.CurrentId.HasValue ? Task.CurrentId.Value.ToString() : "unknown"));
                }
                catch (Exception e)
                {
                    if (session != null)
                    {
                        session.Abort();
                    }
                    Console.WriteLine(e.Message);
                    throw e;
                }
                finally
                {
                    pool.FreeSession(sessionId, session);
                }
            });
        }
Esempio n. 55
0
        static public IEnumerable <Key> Where <Key>(this BTreeBase <Key, Key> sourceCollection, Expression <Func <Key, bool> > expr)
#if WINDOWS_PHONE
            where Key : new()
#endif
        {
            if (sourceCollection != null)
            {
                bool                 noIndex  = true;
                SessionBase          session  = sourceCollection.Session;
                CompareByField <Key> comparer = sourceCollection.Comparer as CompareByField <Key>;
                BinaryExpression     binExp   = expr.Body as BinaryExpression;
                if (binExp != null && canUseIndex <Key>(sourceCollection, binExp, comparer))
                {
                    session.WaitForIndexUpdates();
                    switch (expr.Body.NodeType)
                    {
                    case ExpressionType.AndAlso:
                    {
                        noIndex = AndUseIndex(sourceCollection, binExp) == false;
                        if (noIndex == false)
                        {
                            foreach (var x in And <Key>(sourceCollection, binExp))
                            {
                                yield return(x);
                            }
                        }
                        else
                        {
                            BinaryExpression leftExpr = (BinaryExpression)binExp.Left;
                            binExp = leftExpr;
                            switch (binExp.NodeType)
                            {
                            case ExpressionType.Equal:
                            {
                                noIndex = EqualUseIndex <Key>(sourceCollection, binExp) == false;
                                if (noIndex == false)
                                {
                                    IEnumerable <Key> equal  = Equal <Key>(sourceCollection, binExp);
                                    IEnumerable <Key> result = equal.Where <Key>(expr.Compile());
                                    foreach (Key resultItem in result)
                                    {
                                        yield return(resultItem);
                                    }
                                }
                                yield break;
                            }

                            case ExpressionType.LessThan:
                            {
                                noIndex = LessThanUseIndex <Key>(sourceCollection, binExp) == false;
                                if (noIndex == false)
                                {
                                    IEnumerable <Key> lessThan = LessThan <Key>(sourceCollection, binExp);
                                    IEnumerable <Key> result   = lessThan.Where <Key>(expr.Compile());
                                    foreach (Key resultItem in result)
                                    {
                                        yield return(resultItem);
                                    }
                                }
                                yield break;
                            }

                            case ExpressionType.LessThanOrEqual:
                            {
                                noIndex = LessThanOrEqualUseIndex <Key>(sourceCollection, binExp) == false;
                                if (noIndex == false)
                                {
                                    IEnumerable <Key> lessThan = LessThanOrEqual <Key>(sourceCollection, binExp);
                                    IEnumerable <Key> result   = lessThan.Where <Key>(expr.Compile());
                                    foreach (Key resultItem in result)
                                    {
                                        yield return(resultItem);
                                    }
                                }
                                yield break;
                            }

                            case ExpressionType.GreaterThan:
                            {
                                noIndex = GreaterThanUseIndex <Key>(sourceCollection, binExp) == false;
                                if (noIndex == false)
                                {
                                    IEnumerable <Key> greaterThan = GreaterThan <Key>(sourceCollection, binExp);
                                    IEnumerable <Key> result      = greaterThan.Where <Key>(expr.Compile());
                                    foreach (Key resultItem in result)
                                    {
                                        yield return(resultItem);
                                    }
                                }
                                yield break;
                            }

                            case ExpressionType.GreaterThanOrEqual:
                            {
                                noIndex = GreaterThanOrEqualUseIndex <Key>(sourceCollection, binExp) == false;
                                if (noIndex == false)
                                {
                                    IEnumerable <Key> greaterThan = GreaterThanOrEqual <Key>(sourceCollection, binExp);
                                    IEnumerable <Key> result      = greaterThan.Where <Key>(expr.Compile());
                                    foreach (Key resultItem in result)
                                    {
                                        yield return(resultItem);
                                    }
                                }
                                yield break;
                            }
                            }
                            ;
                        }
                    }
                    break;

                    case ExpressionType.Equal:
                    {
                        noIndex = EqualUseIndex <Key>(sourceCollection, binExp) == false;
                        if (noIndex == false)
                        {
                            foreach (var x in Equal <Key>(sourceCollection, binExp))
                            {
                                yield return(x);
                            }
                        }
                    }
                    break;

                    case ExpressionType.GreaterThan:
                    {
                        noIndex = GreaterThanUseIndex <Key>(sourceCollection, binExp) == false;
                        if (noIndex == false)
                        {
                            foreach (var x in GreaterThan <Key>(sourceCollection, binExp))
                            {
                                yield return(x);
                            }
                        }
                    }
                    break;

                    case ExpressionType.GreaterThanOrEqual:
                    {
                        noIndex = GreaterThanOrEqualUseIndex <Key>(sourceCollection, binExp) == false;
                        if (noIndex == false)
                        {
                            foreach (var x in GreaterThanOrEqual <Key>(sourceCollection, binExp))
                            {
                                yield return(x);
                            }
                        }
                    }
                    break;

                    case ExpressionType.LessThan:
                    {
                        noIndex = LessThanUseIndex <Key>(sourceCollection, binExp) == false;
                        if (noIndex == false)
                        {
                            foreach (var x in LessThan <Key>(sourceCollection, binExp))
                            {
                                yield return(x);
                            }
                        }
                    }
                    break;

                    case ExpressionType.LessThanOrEqual:
                    {
                        noIndex = LessThanOrEqualUseIndex <Key>(sourceCollection, binExp) == false;
                        if (noIndex == false)
                        {
                            foreach (var x in LessThanOrEqual <Key>(sourceCollection, binExp))
                            {
                                yield return(x);
                            }
                        }
                    }
                    break;
                    }
                }
                if (noIndex) //no index?  just do it the normal slow way then...
                {
                    IEnumerable <Key> sourceEnum;
                    if (sourceCollection.UsesOidShort)
                    {
                        BTreeSetOidShort <Key> c = (BTreeSetOidShort <Key>)sourceCollection;
                        sourceEnum = c.AsEnumerable <Key>();
                    }
                    else
                    {
                        BTreeSet <Key> c = (BTreeSet <Key>)sourceCollection;
                        sourceEnum = c.AsEnumerable <Key>();
                    }
                    IEnumerable <Key> result = sourceEnum.Where <Key>(expr.Compile());
                    foreach (Key resultItem in result)
                    {
                        yield return(resultItem);
                    }
                }
            }
        }
Esempio n. 56
0
        private VersionManager <VelocityDbSchema.Samples.Sample1.Person> GetVersionManager(SessionBase session)
        {
            Database db = session.OpenDatabase(VersionManager <VelocityDbSchema.Samples.Sample1.Person> .versionMangerDatabase, false, false);

            if (db != null)
            {
                var versionManager = db.AllObjects <VersionManager <VelocityDbSchema.Samples.Sample1.Person> >().FirstOrDefault(vmObject => vmObject.RecordType == RecordType.Person);
                return(versionManager);
            }
            else
            {
                return(default(VersionManager <VelocityDbSchema.Samples.Sample1.Person>));
            }
        }
 protected IMessage Alloc_Msg_OA_Broadcast_SetNotice_RS(SessionBase session, Packet packet)
 {
     return(new Msg_OA_Broadcast_SetNotice_RS(m_server, session, packet));
 }
 public virtual byte[] WriteMe(TypeVersion typeVersion, bool addShapeNumber, PageInfo pageInfo, IOptimizedPersistable owner, SessionBase session, bool inFlush)
 {
     return(OptimizedPersistable.WriteMeUsingSchemaReflection(typeVersion, this, addShapeNumber, pageInfo, owner, session, inFlush));
 }
 public Msg_Svr_GetWorldList_RS(appServer server, SessionBase session, Packet packet)
 {
     m_server     = server;
     m_recvPacket = packet;
     m_session    = session as Session;
 }
Esempio n. 60
0
 /// <summary>
 ///     Assigns a Channel # to a session and adds it to the Channel Dictionary
 /// </summary>
 /// <param name="session"></param>
 public void AddSession(SessionBase session)
 {
     _incomingSessions.Enqueue(session);
     _logger.Info($"Session {session.SessionId} added to incoming queue");
 }