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; } }
internal Item(ItemType ItemType) { this.ItemType = ItemType; this.ID = IO.Server.NewID(); this.ConfigID = this.ID; this.Generation = 1; this.IsCurrent = true; this.State = Model.Item.States.New; this.Action = Model.Item.Actions.Create; this.Locked = Model.Item.Locks.User; this.PropertyCache = new Dictionary <PropertyType, Property>(); }
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; } }