public ODObject GetFirstItemByUniqueField(string collection, string field, string fieldValue, string mode = "eq") { ODObject result = null; List <XmlElement> entries; switch (mode) { case "contains": { entries = this.GetPage(this._dataServiceUrl + collection + "Collection?$filter=substringof('" + fieldValue + "'," + field + ")"); break; } case "eq": case "equals": default: { if (fieldValue != "true" && fieldValue != "false") { fieldValue = "'" + fieldValue + "'"; } entries = this.GetPage(this._dataServiceUrl + collection + "Collection?$filter=" + field + " eq " + fieldValue); break; } } foreach (XmlElement entry in entries) { if (entry.Name == "entry") { result = ODBase.getObjectFromEntry(collection, entry); return(result); } } return(result); }
/// <summary> /// loads Dictionary "Many" with links to this object /// </summary> public void LoadMany(ODBase odbase, string Collection, string joinField) { List <XmlElement> entries = odbase.GetAllPages(Collection, joinField + " eq guid'" + this.Guid + "'"); List <ODObject> result = new List <ODObject>(); foreach (XmlElement entry in entries) { if (entry.Name == "entry") { ODObject o = new ODObject(); o._data = ODBase.GetEntryFields(entry); o._Collection = Collection; o.Guid = o["Id"].ToString(); result.Add(o); } } if (result.Count > 0) { this.Many[Collection] = result; } else { this.Many.Remove(Collection); } }
public bool UploadBinary(ODBase odb, byte[] bytes, bool saveFiletypeAndSize = true, bool saveSHA256Hash = true) { string result1 = odb.UploadBinary(this._Collection, this.Guid, bytes, saveSHA256Hash); if (result1 != "") { if (saveFiletypeAndSize || saveSHA256Hash) { if (saveFiletypeAndSize) { this["Size"] = bytes.Length; this["TypeId"] = ODBase.CommonIds.fileTypeFile; } if (saveSHA256Hash) { this["Hash"] = result1; } this.Update(odb); } return(true); } else { return(false); } }
public void DeleteLink(ODBase odb, string CollectionTo) { odb.DeleteLink(this._Collection, this.Guid, CollectionTo); if (this.HasProperty(CollectionTo + "Id")) { this[CollectionTo + "Id"] = null; } }
// dispose реализовывать? /// <summary> /// Deletes object. Not disposing. Calling Update method will recreate object /// </summary> public void Delete(ODBase odb) { if (this.Guid != string.Empty) { odb.DeleteItem(this._Collection, this.Guid); this.Guid = string.Empty; this["Id"] = null; } }
/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// protected static internal ODObject getObjectFromEntry(string collection, XmlElement entry) { ODObject result = new ODObject(); result._data = ODBase.GetEntryFields(entry); result._binaryDataLink = ODBase.GetDataLink(entry); result._Collection = collection; result.Guid = result["Id"].ToString(); return(result); }
public byte[] GetData(ODBase odb) { if (this.hasBinaryData) { return(odb.GetData(odb._dataServiceUrl + this._binaryDataLink)); } else { return(new byte[0]); } }
/// <summary> /// Creates or updates object /// </summary> public string Update(ODBase odb) { this.FixDateBug(); if (this.Guid == string.Empty) { // to create return(odb.AddItem(this._Collection, this._data)); } else { // to update return(odb.UpdateItem(this._Collection, this.Guid, this._data)); } }
/// <summary> /// HIGHLY NOT RECOMMENDED /// </summary> public List <ODObject> GetAllItemsByQuery(string collection, string query, int maxIterations = 10) { List <ODObject> result = new List <ODObject>(); List <XmlElement> entries = this.GetAllPages(collection, query, maxIterations); foreach (XmlElement entry in entries) { if (entry.Name == "entry") { ODObject item = ODBase.getObjectFromEntry(collection, entry); result.Add(item); } } return(result); }
public List <ODObject> GetSomeItemsByQuery(string collection, string query, int skip) { List <ODObject> result = new List <ODObject>(); List <XmlElement> entries = this.GetPage(this._dataServiceUrl + collection + "Collection?$filter=" + (query != "" ? query : "1 eq 1") + (skip > 0 ? "&$skip=" + skip : "")); foreach (XmlElement entry in entries) { if (entry.Name == "entry") { ODObject item = ODBase.getObjectFromEntry(collection, entry); result.Add(item); } } return(result); }
public ODObject GetFirstItemByQuery(string collection, string query) { ODObject result = null; List <XmlElement> entries = this.GetPage(this._dataServiceUrl + collection + "Collection?$filter=" + query); foreach (XmlElement entry in entries) { if (entry.Name == "entry") { result = ODBase.getObjectFromEntry(collection, entry); return(result); } } return(result); }
public Dictionary <string, ODObject> GetDictionaryByUniqueField(string collection, string field, string query, int maxIterations = 10) { List <XmlElement> entries = this.GetAllPages(collection, query, maxIterations); Dictionary <string, ODObject> result = new Dictionary <string, ODObject>(); foreach (XmlElement entry in entries) { if (entry.Name == "entry") { ODObject o = ODBase.getObjectFromEntry(collection, entry); if (o._data.ContainsKey(field)) { result[o[field].ToString()] = o; } } } return(result); }
/// <summary> /// Finds and initializes object. Throws exception if not found. /// </summary> public ODObject(ODBase odb, string Collection, string Guid) { this.Guid = Guid; this._Collection = Collection; this._data = null; List <XmlElement> elements = odb.GetPage(odb.GetCollectionPageUrl(Collection) + "Collection(guid'" + Guid + "')"); if (elements.Count == 1) { this._data = ODBase.GetEntryFields(elements[0]); } if (this._data == null || this._data.Count == 0) { throw new Exception(Collection + "Collection(guid'" + Guid + "') not found"); } this._binaryDataLink = ODBase.GetDataLink(elements[0]); }
/// <summary> /// loads Dictionary "Many" with links to this object /// </summary> public void LoadMany(ODBase odbase, string Collection) { this.LoadMany(odbase, Collection, this._Collection + "/Id"); }