Пример #1
0
        public Session Login(String Username, String AccessToken)
        {
            lock (this.SessionCacheLock)
            {
                if (!this.SessionCache.ContainsKey(Username))
                {
                    IO.Request  request  = new IO.Request(IO.Request.Operations.ValidateUser, this, Username, AccessToken);
                    IO.Response response = request.Execute();

                    if (!response.IsError)
                    {
                        this.SessionCache[Username] = new Session(this, response.Result, Username, AccessToken);
                    }
                    else
                    {
                        throw new Exceptions.ServerException(response);
                    }
                }
                else
                {
                    this.SessionCache[Username].UpdateAccesToken(AccessToken);
                }

                return(this.SessionCache[Username]);
            }
        }
Пример #2
0
        public Item Get(String ID)
        {
            if (!this.Cache.ContainsKey(ID))
            {
                // Run Query
                IO.Request  request  = this.ItemType.Session.IO.Request(IO.Request.Operations.ApplyItem, this.Query.DBQuery(ID));
                IO.Response response = request.Execute();

                if (!response.IsError)
                {
                    if (response.Items.Count() == 1)
                    {
                        // Add to Cache
                        this.Create(response.Items.First());
                    }
                    else
                    {
                        throw new Exceptions.ServerException("Item ID not found: " + ID);
                    }
                }
                else
                {
                    throw new Exceptions.ServerException(response);
                }
            }

            return(this.Cache[ID]);
        }
Пример #3
0
        public Session Login(String Username, String Password)
        {
            lock (this.SessionCacheLock)
            {
                if (!this.SessionCache.ContainsKey(Username))
                {
                    IO.Request  request  = new IO.Request(IO.Request.Operations.ValidateUser, this, Username, Password);
                    IO.Response response = request.Execute();

                    if (!response.IsError)
                    {
                        this.SessionCache[Username] = new Session(this, response.Result, Username, Password, response.Cookies);
                    }
                    else
                    {
                        throw new Exceptions.ServerException(response);
                    }
                }
                else
                {
                    // Check Password
                    if (!this.SessionCache[Username].Password.Equals(Password))
                    {
                        throw new Exceptions.ArgumentException("Invalid Password");
                    }
                }

                return(this.SessionCache[Username]);
            }
        }
Пример #4
0
        internal void Refresh(Item Item)
        {
            if (this.Cache.ContainsKey(Item.ID))
            {
                // Run Query
                IO.Request  request  = this.ItemType.Session.IO.Request(IO.Request.Operations.ApplyItem, this.Query.DBQuery(Item.ID));
                IO.Response response = request.Execute();

                if (!response.IsError)
                {
                    if (response.Items.Count() == 1)
                    {
                        // Update Item
                        this.Cache[Item.ID].UpdateProperties(response.Items.First());
                    }
                    else
                    {
                        throw new Exceptions.ServerException("Item ID not found: " + Item.ID);
                    }
                }
                else
                {
                    throw new Exceptions.ServerException(response);
                }
            }
            else
            {
                throw new Exceptions.ServerException("Item ID not found: " + Item.ID);
            }
        }
Пример #5
0
        internal void UnLock()
        {
            switch (this.State)
            {
            case Model.Item.States.Stored:

                switch (this.Locked)
                {
                case Model.Item.Locks.User:

                    IO.Item lockitem = new IO.Item(this.ItemType.Name, "unlock");
                    lockitem.ID        = this.ID;
                    lockitem.DoGetItem = false;
                    IO.Request  request  = this.ItemType.Session.IO.Request(IO.Request.Operations.ApplyItem, lockitem);
                    IO.Response response = request.Execute();

                    if (!response.IsError)
                    {
                        this.Locked = Model.Item.Locks.None;
                        this.Action = Model.Item.Actions.Read;
                    }
                    else
                    {
                        if (response.ErrorMessage == "Aras.Server.Core.ItemIsNotLockedException")
                        {
                            this.Locked = Model.Item.Locks.None;
                            this.Action = Model.Item.Actions.Read;
                        }
                        else
                        {
                            throw new Exceptions.ServerException(response);
                        }
                    }

                    break;

                case Model.Item.Locks.None:

                    // Item not Locked
                    this.Action = Model.Item.Actions.Read;

                    break;

                case Model.Item.Locks.OtherUser:

                    throw new Exceptions.ServerException("Item locked by another User");
                }

                break;

            case Model.Item.States.Deleted:

                throw new Exceptions.ArgumentException("Item is Deleted");

            default:

                break;
            }
        }
Пример #6
0
        public void Refresh()
        {
            // Run Query
            IO.Item dbquery = this.Query.DBQuery();

            if (dbquery != null)
            {
                if (this.Source != null)
                {
                    dbquery.SetProperty("source_id", this.Source.ID);
                }

                IO.Request  request  = this.ItemType.Session.IO.Request(IO.Request.Operations.ApplyItem, dbquery);
                IO.Response response = request.Execute();

                if (!response.IsError)
                {
                    this.Load(response.Items);

                    if (this.Paging)
                    {
                        if (response.Items.Count() > 0)
                        {
                            this.NoPages = response.Items.First().PageMax;
                        }
                        else
                        {
                            this.NoPages = 0;
                        }
                    }
                    else
                    {
                        this.NoPages = 0;
                    }
                }
                else
                {
                    if (!response.ErrorMessage.Equals("No items of type " + this.ItemType.Name + " found."))
                    {
                        throw new Exceptions.ServerException(response);
                    }
                    else
                    {
                        this.Load(null);
                    }
                }
            }
        }
Пример #7
0
        public void UpdateAccesToken(String AccessToken)
        {
            if (!this.AccessToken.Equals(AccessToken))
            {
                IO.Request  request  = new IO.Request(IO.Request.Operations.ValidateUser, this.Database, this.Username, AccessToken);
                IO.Response response = request.Execute();

                if (!response.IsError)
                {
                    this.AccessToken = AccessToken;
                }
                else
                {
                    throw new Exceptions.ServerException(response);
                }
            }
        }
Пример #8
0
        public void Promote(Relationships.LifeCycleState NewState)
        {
            IO.Request request = this.ItemType.Session.IO.Request(IO.Request.Operations.PromoteItem);
            IO.Item    item    = request.NewItem(this.ItemType.Name, "get");
            item.ID = this.ID;
            item.SetProperty("state", NewState.Name);
            IO.Response response = request.Execute();

            if (!response.IsError)
            {
                // Update Current State
                this.Property(this.ItemType.PropertyType("current_state")).SetValue(NewState);
                this.Property(this.ItemType.PropertyType("state")).SetValue(NewState.Name);
            }
            else
            {
                throw new Exceptions.ServerException(response);
            }
        }
Пример #9
0
        public IEnumerable <Relationships.LifeCycleState> NextStates()
        {
            List <Relationships.LifeCycleState> ret = new List <Relationships.LifeCycleState>();

            if (this.State == Model.Item.States.Stored)
            {
                if (this.LifeCycleMap != null)
                {
                    IO.Request request = this.ItemType.Session.IO.Request(IO.Request.Operations.GetItemNextStates);
                    IO.Item    item    = request.NewItem(this.ItemType.Name, "get");
                    item.ID = this.ID;
                    IO.Response response = request.Execute();

                    if (!response.IsError)
                    {
                        if (response.Items.Count() > 0)
                        {
                            IO.Item lifecycletransisiton = response.Items.First();

                            foreach (IO.Item dblifecyclestate in lifecycletransisiton.ToStates)
                            {
                                foreach (Relationships.LifeCycleState lifecyclestate in this.LifeCycleMap.Relationships("Life Cycle State"))
                                {
                                    if (lifecyclestate.ID.Equals(dblifecyclestate.ID))
                                    {
                                        ret.Add(lifecyclestate);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        throw new Exceptions.ServerException(response);
                    }
                }
            }

            return(ret);
        }
Пример #10
0
        private void Lock()
        {
            switch (this.State)
            {
            case Model.Item.States.Stored:

                switch (this.Locked)
                {
                case Model.Item.Locks.None:

                    // Lock Item
                    IO.Item lockitem = new IO.Item(this.ItemType.Name, "lock");
                    lockitem.ID        = this.ID;
                    lockitem.DoGetItem = false;
                    IO.Request  request  = this.ItemType.Session.IO.Request(IO.Request.Operations.ApplyItem, lockitem);
                    IO.Response response = request.Execute();

                    if (!response.IsError)
                    {
                        this.Locked = Model.Item.Locks.User;
                        this.Action = Model.Item.Actions.Update;
                    }
                    else
                    {
                        if ((response.ErrorMessage != null) && response.ErrorMessage.Equals("Aras.Server.Core.ItemIsAlreadyLockedException"))
                        {
                            // Already Locked
                            this.Locked = Model.Item.Locks.User;
                            this.Action = Model.Item.Actions.Update;
                        }
                        else
                        {
                            throw new Exceptions.ServerException(response);
                        }
                    }

                    break;

                case Model.Item.Locks.User:

                    // Already locked by User
                    this.Action = Model.Item.Actions.Update;

                    break;

                case Model.Item.Locks.OtherUser:

                    throw new Exceptions.ServerException("Item locked by another user");
                }

                break;

            case Model.Item.States.Deleted:

                throw new Exceptions.ArgumentException("Item is Deleted");

            case Model.Item.States.New:

                // New Item not stored in database, no need to lock

                break;
            }
        }
Пример #11
0
        private void BuildCaches()
        {
            this.ItemTypeNameCache = new Dictionary <String, ItemType>();
            this.ItemTypeIDCache   = new Dictionary <String, ItemType>();

            // Build ItemType Cache
            IO.Request itemtyperequest = this.IO.Request(Aras.IO.Request.Operations.ApplyItem);
            IO.Item    itemtypequery   = itemtyperequest.NewItem("ItemType", "get");
            itemtypequery.Select = "id,name,is_relationship,class_structure,label,label_plural";

            IO.Item lifecyclemapquery = itemtyperequest.NewItem("ItemType Life Cycle", "get");
            lifecyclemapquery.Select = "class_path,related_id";
            itemtypequery.AddRelationship(lifecyclemapquery);

            IO.Response itemtyperesponse = itemtyperequest.Execute();

            if (!itemtyperesponse.IsError)
            {
                foreach (IO.Item dbitem in itemtyperesponse.Items)
                {
                    ItemType itemtype = null;

                    if (dbitem.GetProperty("is_relationship").Equals("1"))
                    {
                        itemtype = new RelationshipType(this, dbitem.ID, dbitem.GetProperty("name"), dbitem.GetProperty("label"), dbitem.GetProperty("label_plural"), dbitem.GetProperty("class_structure"));
                    }
                    else
                    {
                        itemtype = new ItemType(this, dbitem.ID, dbitem.GetProperty("name"), dbitem.GetProperty("label"), dbitem.GetProperty("label_plural"), dbitem.GetProperty("class_structure"));
                    }

                    this.ItemTypeIDCache[itemtype.ID]     = itemtype;
                    this.ItemTypeNameCache[itemtype.Name] = itemtype;

                    foreach (IO.Item itemtypelifecyclemap in dbitem.Relationships)
                    {
                        itemtype.AddLifeCycleMap(itemtypelifecyclemap.GetProperty("class_path"), itemtypelifecyclemap.GetPropertyItem("related_id").ID);
                    }
                }
            }
            else
            {
                throw new Exceptions.ServerException(itemtyperesponse);
            }

            // Build RelationshipType Cache
            IO.Request relationshiptyperequest = this.IO.Request(Aras.IO.Request.Operations.ApplyItem);
            IO.Item    relationshiptypequery   = relationshiptyperequest.NewItem("RelationshipType", "get");
            relationshiptypequery.Select = "relationship_id,source_id(id),related_id(id),grid_view";
            IO.Response relationshiptyperesponse = relationshiptyperequest.Execute();

            if (!relationshiptyperesponse.IsError)
            {
                foreach (IO.Item dbitem in relationshiptyperesponse.Items)
                {
                    RelationshipType relationshiptype = (RelationshipType)this.ItemTypeIDCache[dbitem.GetProperty("relationship_id")];

                    String source_id = dbitem.GetProperty("source_id");

                    if (!String.IsNullOrEmpty(source_id))
                    {
                        relationshiptype.Source = this.ItemTypeIDCache[source_id];
                        relationshiptype.Source.AddRelationshipType(relationshiptype);
                    }

                    String related_id = dbitem.GetProperty("related_id");

                    if (!String.IsNullOrEmpty(related_id))
                    {
                        relationshiptype.Related = this.ItemTypeIDCache[related_id];
                    }

                    switch (dbitem.GetProperty("grid_view"))
                    {
                    case "right":
                        relationshiptype.RelationshipGridView = RelationshipGridViews.Right;
                        break;

                    case "intermix":
                        relationshiptype.RelationshipGridView = RelationshipGridViews.InterMix;
                        break;

                    default:
                        relationshiptype.RelationshipGridView = RelationshipGridViews.Left;
                        break;
                    }
                }
            }
            else
            {
                throw new Exceptions.ServerException(relationshiptyperesponse);
            }
        }
Пример #12
0
 protected IO.Response SendItem(IO.Item DBItem)
 {
     // Send to Server
     IO.Request request = this.Transaction.Session.IO.Request(IO.Request.Operations.ApplyItem, DBItem);
     return(request.Execute());
 }