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]); } }
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]); } }
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]); }
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); } }
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 override IO.Item Commit() { if (!this.Completed) { IO.Item dbitem = this.BuildItem(); IO.Response response = this.SendItem(dbitem); if (!response.IsError) { if (response.Items.Count() == 1) { this.Result = response.Items.First(); if (this.Result.ConfigID.Equals(this.Item.ConfigID)) { if (!this.Result.ID.Equals(this.Item.ID)) { // New Version of Item Model.Item newversion = this.Item.Store.Get(this.Result.ID); Model.Item oldversion = this.Item; this.Item = newversion; this.UpdateItem(this.Result); oldversion.OnSuperceded(newversion); } else { this.UpdateItem(this.Result); } } else { // Result does not match Item throw new Exceptions.ServerException("Server response does not match original Item"); } } this.Completed = true; } else { this.Completed = true; if (response.ErrorMessage != "Aras.Server.Core.ItemIsNotLockedException") { throw new Exceptions.ServerException(response); } } } return(this.Result); }
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); } } } }
internal override IO.Item Commit() { if (!this.Completed) { // Write File to Cache using (FileStream cachefile = new FileStream(((Model.File) this.Item).CacheFilename.FullName, FileMode.Open)) { IO.Response response = this.Transaction.Session.IO.VaultWrite(cachefile, ((Model.File) this.Item).VaultFilename); if (!response.IsError) { if (response.Items.Count() == 1) { this.Result = response.Items.First(); if (this.Result.ConfigID.Equals(this.Item.ConfigID)) { if (!this.Result.ID.Equals(this.Item.ID)) { // New Version of Item //Model.Item newversion = this.Item.Session.Store(this.Item.ItemType).Get(this.Result); //Model.Item oldversion = this.Item; //this.Item = newversion; //this.UpdateItem(this.Result); //oldversion.OnSuperceded(newversion); } else { this.UpdateItem(this.Result); } this.Item.UpdateProperties(this.Result); } else { // Result does not match Item throw new Exceptions.ServerException("Server response does not match original Item"); } } } } this.Completed = true; } return(this.Result); }
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); } } }
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); } }
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); }
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; } }
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); } }
public ServerException(IO.Response Response) : base(Response.ErrorMessage) { }
public Response VaultWrite(Stream Stream, String Filename) { IO.Response response = null; // Read Cached File byte[] filebytes = null; if (Stream is MemoryStream) { filebytes = ((MemoryStream)Stream).ToArray(); } else { using (MemoryStream ms = new MemoryStream()) { Stream.CopyTo(ms); filebytes = ms.ToArray(); } } // Build Request String contentboundary = "-------------S36Ut9A3ZtWwum"; MultipartFormDataContent content = new MultipartFormDataContent(contentboundary); StringContent soapaction = new StringContent("ApplyItem"); content.Add(soapaction, "SOAPACTION"); StringContent authuser = new StringContent(this.Username); content.Add(authuser, "AUTHUSER"); StringContent password = new StringContent(this.Password); content.Add(password, "AUTHPASSWORD"); StringContent database = new StringContent(this.Database.ID); content.Add(database, "DATABASE"); StringContent locale = new StringContent(""); content.Add(locale, "LOCALE"); StringContent timezone = new StringContent("GMT Standard Time"); content.Add(timezone, "TIMEZONE_NAME"); StringContent vault = new StringContent(this.VaultID); content.Add(vault, "VAULTID"); IO.Item dbfile = new IO.Item("File", "add"); dbfile.ID = Server.NewID(); dbfile.SetProperty("filename", Filename); dbfile.SetProperty("file_size", filebytes.Length.ToString()); IO.Item dbloacted = new IO.Item("Located", "add"); dbloacted.SetProperty("related_id", this.VaultID); dbfile.AddRelationship(dbloacted); String xmldata = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body><ApplyItem>" + dbfile.GetString() + "</ApplyItem></SOAP-ENV:Body></SOAP-ENV:Envelope>"; StringContent xml = new StringContent(xmldata); content.Add(xml, "XMLdata"); ByteArrayContent filedata = new ByteArrayContent(filebytes); content.Add(filedata, dbfile.ID, Filename); // Post Request to Vault Server HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.VaultBaseURL); request.CookieContainer = this.Cookies; request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; request.ContentType = "multipart/form-data; boundary=" + contentboundary; request.Method = "POST"; request.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore); request.Headers.Add("Cache-Control", "no-cache"); request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; using (Stream poststream = request.GetRequestStream()) { content.CopyToAsync(poststream); } using (HttpWebResponse webresponse = (HttpWebResponse)request.GetResponse()) { using (Stream result = webresponse.GetResponseStream()) { XmlDocument doc = new XmlDocument(); doc.Load(result); response = new IO.Response(webresponse.Cookies, doc); } } return(response); }