//public event NavigatedEventHandler OnNavigated;
 public PModelObjectNavigator(PBaseObject owner)
 {
     _owner = owner;
     //levels = new List<string>();
     // _positionInLevel = new List<int>();
     _path = new PNavigatorPath();
 }
 public int IndexOf(PBaseObject obj)
 {
     if (obj != null)
         return _items.IndexOf(obj);
     else
         return -1;
 }
 public RCollection(PBaseObject owner, string name, bool deferredLoad, IDataModel model)
 {
     _items = new List<PBaseObject>();
     Owner = owner;
     Name = name;
     _deferredLoad = deferredLoad;
     _loaded = false;
     _model = model;
 }
Beispiel #4
0
        //private Dictionary<string, string> _items;
        public PTemplates(PBaseObject ownerObject)
        {
            NotFoundMarks = new PNotFoundMarks();
            //_loadFiles(Directory.GetCurrentDirectory());
            OwnerObject = ownerObject;

            // шаблонизатор пренадлежит объекту?
            //if (ownerObject != null)
            //{
            //    // подпишемся на ответ от Api
            //    ownerObject.Model.HostRersponse += new EventHandler<HostQueryEventArgs>(ProcessHostResponse);
            //}
        }
 public bool IsChildOf(PBaseObject obj)
 {
     if (obj == null)
         return false;
     PCollection coll = this._ownerCollection;
     while (coll != null)
     {
         if (coll.Owner == obj)
             return true;
         coll = coll.Owner._ownerCollection;
     }
     return false;
 }
        //public List<int> GetPathTo(PBaseObject toObject)
        //{
        //    List<int> path = new List<int>();
        //    if (toObject._ownerCollection == null)
        //        return null;
        //    PBaseObject obj = toObject;
        //    while (obj._ownerCollection.Owner != null)
        //    {
        //        path.Insert(0, obj._ownerCollection.IndexOf(obj));
        //        if (obj._ownerCollection.Owner == this)
        //        {
        //            return path;
        //        }
        //        obj = obj._ownerCollection.Owner;
        //    }
        //    return null;
        //}
        public PNavigatorPath GetPathTo(PBaseObject toObject)
        {
            PNavigatorPath path = new PNavigatorPath();

            if (toObject._ownerCollection == null)
                return null;

            PBaseObject obj = toObject;
            while (obj._ownerCollection.Owner != null)
            {
                path.Parts.Insert(0, new PNavigatorPartPath(obj._ownerCollection.Name, obj._ownerCollection.IndexOf(obj)));
                if (obj._ownerCollection.Owner == this)
                {
                    return path;
                }

                obj = obj._ownerCollection.Owner;
            }
            return null;
        }
 public bool GetAttrWithObject(string name, bool findInOwners, out string val, out PBaseObject obj)
 {
     if (_attrs.TryGetValue(name.ToLower(), out val))
     {
         obj = this;
         return true;
     }
     else if (this._ownerCollection != null && findInOwners) // рекурсивно ищем во всех владельцах
     {
         obj = this._ownerCollection.Owner;
         return this._ownerCollection.Owner.GetAttr(name, true, out val);
     }
     else
     {
         obj = null;
         return false;
     }
 }
        //public void SetObject(PBaseObject obj)
        //{
        //    this._current = obj;
        //    foreach (PModelObjectNavigatorPathLevel level in Levels)
        //    {
        //        level.Index = 0;
        //    }
        //    if (this._current == null)
        //    {
        //        this.Pointer = null;
        //    }
        //    else
        //    {
        //        _updatePointer();
        //    }
        //    //_enableControls((this._current != null));
        //}
        //private void _enableControls(bool e)
        //{
        //    foreach (PModelObjectNavigatorPathLevel lvl in Levels)
        //    {
        //        lvl.UiControl.Enabled = e;
        //    }
        //}
        //public string GetPathString()
        //{
        //    string ret = "";
        //    foreach (string lvl in _levels)
        //    {
        //        ret += ((ret != "") ? "/" : "") + lvl + "[" + lvl.ToString() + "]";
        //    }
        //    return ret;
        //}
        //private void _updatePointer()
        //{
        //    if (this._current == null)
        //        throw new Exception("Текущий объект не задан");
        //    RBaseObject o = this._current;
        //    foreach (RModelObjectNavigatorPathLevel lvl in _levels)
        //    {
        //        RCollection coll = o.GetCollection(lvl.CollectionName, false);
        //        if (coll == null)
        //        {
        //            throw new Exception("Указанная в конфигурации коллекция '" + lvl.CollectionName + "' не описана в переданном объекте");
        //        }
        //        else
        //        {
        //            int index = lvl.Index;
        //            if (index < 0)
        //            {
        //                index = coll.Count() - 1;
        //                lvl.Index = index;
        //            }
        //            o = coll.GetObject(index);
        //            if (o != null)
        //            {
        //                this.Pointer = o;
        //            }
        //            else
        //            {
        //                break;
        //            }
        //        }
        //    }
        //    OnNavigated(this, this.Pointer);
        //}
        //private void _updatePointer()
        //{
        //    if (_owner == null)
        //    {
        //        throw new Exception("Текущий объект не задан");
        //    }
        //    PBaseObject owner = _owner;
        //    for (int ii = 0; ii < _levels.Count(); ii++)
        //    {
        //        string level = _levels[ii];
        //        int position = _positionInLevel[ii];
        //        PCollection collection = owner.GetCollection(level, false);
        //        if (collection == null)
        //        {
        //            throw new Exception("Указанная в конфигурации коллекция '" + level + "' не описана в переданном объекте");
        //        }
        //        else
        //        {
        //            if (position < 0)
        //            {
        //                position = collection.Count() - 1;
        //                _positionInLevel[ii] = position;
        //            }
        //            PBaseObject obj = collection.GetObject(position);
        //            if (obj != null)
        //            {
        //                this.Pointer = obj;
        //                owner = obj;
        //            }
        //            else
        //            {
        //                break;
        //            }
        //        }
        //    }
        //}
        private void _updatePointer()
        {
            if (_owner == null)
            {
                throw new Exception("Текущий объект не задан");
            }

            PBaseObject owner = _owner;
            for (int ii = 0; ii < _path.Parts.Count(); ii++)
            {
                string level = _path.Parts[ii].Level;
                int position = _path.Parts[ii].PositionInLevel;

                PCollection collection = owner.GetCollection(level, false);
                if (collection == null)
                {
                    throw new Exception("Указанная в конфигурации коллекция '" + level + "' не описана в переданном объекте");
                }
                else
                {
                    if (position < 0)
                    {
                        position = collection.Count() - 1;
                        _path.Parts[ii].PositionInLevel = position;
                    }
                    PBaseObject obj = collection.GetObject(position);
                    if (obj != null)
                    {
                        this.Pointer = obj;
                        owner = obj;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
 public PBaseObject NextSibling(PBaseObject obj)
 {
     int i = this._items.IndexOf(obj) + 1;
     return (i >= this._items.Count()) ? null : this._items[i];
 }
Beispiel #10
0
 public PBaseObject InsertObject(PBaseObject obj)
 {
     _items.Add(obj);
     return obj;
 }
Beispiel #11
0
 public PBaseObject PrevSibling(PBaseObject obj)
 {
     int i = this._items.IndexOf(obj) - 1;
     return (i < 0) ? null : this._items[i];
 }
Beispiel #12
0
 // запрос
 //public void RiseHostRequest(string textRequest)
 //{
 //    HostRequest(this, new HostQueryEventArgs()
 //    {
 //        Text = textRequest
 //    });
 //}
 //// ответ
 //public void RiseHostResponse(string textResponse)
 //{
 //    HostRersponse(this, new HostQueryEventArgs()
 //    {
 //        Text = textResponse
 //    });
 //}
 public PBaseObject FindObjectById(int id, PBaseObject where)
 {
     PBaseObject ret = null;
     if (_listObjects.TryGetValue(id, out ret))
     {
         //return ret.IsChildOf(where) ? ret : null;
         return ret;
     }
     else
         return null;
 }
Beispiel #13
0
        private PBaseObject LoadNewObject(int id, PCollection ownerCollection)
        {
            PBaseObject obj = new PBaseObject(id, ownerCollection, this);

            if (ownerCollection != null)
                ownerCollection.InsertObject(obj);
            Dictionary<string, string> attrs = this._db.ListAttributes(id);
            foreach (KeyValuePair<string, string> p in attrs)
            {
                obj.SetAttr(p.Key, p.Value);
            }

            List<string> listColl = this._db.ListCollections(id);

            foreach (string coll in listColl)
            {
                obj.GetCollection(coll, true);
            }

            _listObjects.Add(obj.Id, obj);
            return obj;
        }
Beispiel #14
0
        public PCollection NewCollection(PBaseObject owner, string name)
        {
            PCollection col = new PCollection(owner, name, this.DeferredLoad, this);
            if (!this.DeferredLoad)
            {
                this.FillCollection(col);
            }

            return col;
        }
Beispiel #15
0
        public void LoadModel()
        {
            //this.Templates.Clear();
            //Dictionary<string, string> tList = this._db.ListTemplates(this._modelCode);
            //foreach (KeyValuePair<string, string> p in tList)
            //{
            //    this.Templates.AddTemplate(p.Key, p.Value);
            //}

            this.Data = this.GetRootObject();
        }