Esempio n. 1
0
        /// <summary>
        /// Resets this enumerator preparing it for a fresh new execution.
        /// </summary>
        public void Reset()
        {
            try { if (_Enumerator != null)
                  {
                      _Enumerator.Dispose();
                  }
            }
            catch { }
            try { if (_CoreCommand != null)
                  {
                      _CoreCommand.Dispose();
                  }
            }
            catch { }

            if (_Indented)
            {
                DebugEx.Unindent();
            }
            _Indented = false;

            _Enumerator  = null;
            _CoreCommand = null;
            _Current     = null;
        }
Esempio n. 2
0
        /// <summary>
        /// Invoked when disposing or finalizing this instance.
        /// </summary>
        /// <param name="disposing">True if the object is being disposed, false otherwise.</param>
        protected virtual void OnDispose(bool disposing)
        {
            if (disposing)
            {
                try { Reset(); }
                catch { }
            }

            _Enumerator  = null;
            _CoreCommand = null;
            _Command     = null;
            _Current     = null;

            _IsDisposed = true;
        }
Esempio n. 3
0
        /// <summary>
        /// Executes the command if it has not been executed yet in this instance. Returns true
        /// if a new record is available, or false otherwise.
        /// </summary>
        public bool MoveNext()
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(this.ToString());
            }
            try
            {
                if (_CoreCommand == null)                 // Preparing iterations...
                {
                    _CoreCommand = _Command.GenerateCoreCommand(); if (_CoreCommand == null)
                    {
                        throw new CannotCreateException("Cannot create a core query command for this '{0}'.".FormatWith(this));
                    }

                    _Enumerator = _CoreCommand.GetEnumerator(); if (_Enumerator == null)
                    {
                        throw new CannotCreateException("Cannot create a core query enumerator for this '{0}'.".FormatWith(this));
                    }

                    DebugEx.IndentWriteLine("\n- Query: entering '{0}'...".FormatWith(_Command.TraceString()));
                    _Indented = true;
                }

                _Current = null; bool r = _Enumerator.MoveNext(); if (r)                 // Current iteration...
                {
                    var record     = _Enumerator.CurrentRecord;
                    var disposable = true;
                    var map        = _Command.Map;

                    lock (map.Repository.MasterLock)
                    {
                        if (map.TrackEntities)
                        {
                            var node = map.MetaEntities.FindNode(record); if (node != null)
                            {
                                foreach (var meta in node)
                                {
                                    T obj = (T)meta.Entity; if (obj == null)
                                    {
                                        DebugEx.IndentWriteLine("\n- Query: meta invalid '{0}'.".FormatWith(meta));
                                        DebugEx.Unindent();
                                        continue;
                                    }

                                    if (_Current == null)
                                    {
                                        _Current = obj;
                                    }
                                    else
                                    if (map.ProxyType != null &&
                                        map.ProxyType != _Current.GetType() &&
                                        map.ProxyType == obj.GetType())
                                    {
                                        _Current = obj;
                                    }

                                    if (meta.Completed)
                                    {
                                        DebugEx.IndentWriteLine("\n- Query: meta completed '{0}'.".FormatWith(meta));
                                        DebugEx.Unindent();
                                        continue;
                                    }

                                    DebugEx.IndentWriteLine("\n- Query: hydrating meta '{0}'.".FormatWith(meta));
                                    meta.Record = record.Clone();
                                    map.LoadEntity(meta.Record, obj);
                                    map.CompleteMembers(meta);
                                    DebugEx.Unindent();
                                }
                            }
                        }

                        if (_Current == null)
                        {
                            DebugEx.IndentWriteLine("\n- Query: new meta '{0}({1})'.".FormatWith(map.EntityType.EasyName(), record));
                            _Current     = map.NewEntity(); var meta = MetaEntity.Locate(_Current);
                            meta.Record  = record; disposable = false;
                            meta.UberMap = map; if (map.TrackEntities)
                            {
                                map.MetaEntities.Add(meta);
                            }
                            map.LoadEntity(meta.Record, _Current);
                            map.CompleteMembers(meta);
                            DebugEx.Unindent();
                        }
                    }

                    if (disposable)
                    {
                        record.Dispose();
                    }
                }
                else
                {
                    Reset();
                }

                return(r);
            }
            catch
            {
                try { Dispose(); }
                catch { }

                throw;
            }
        }