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); } }
/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// 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); }
/// <summary> /// Prepares new object in Collection, CreatedOn and Modified will be set to DateTime.Now /// Call Update method for save /// </summary> public static ODObject NewObject(string Collection) { ODObject result = new ODObject(); result._Collection = Collection; result._data = new Dictionary <string, object>(); result._data["CreatedOn"] = DateTime.Now.ToUniversalTime().ToString("o"); result._data["ModifiedOn"] = DateTime.Now.ToUniversalTime().ToString("o"); return(result); }
/// <summary> /// deprecated /// </summary> public void MergeWith(ODObject second) { Dictionary <string, object> secondData = new Dictionary <string, object>(); foreach (KeyValuePair <string, object> kvp in second._data) { if (kvp.Key != "Id") { secondData.Add(kvp.Key, kvp.Value); } } this.MergeWith(secondData); }
/// <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); }
/* DEPRECATED */ private ODObject GetOrCreateByUniqueField(string collection, string field, string name) { int errsNum = this.errorMessages.Count; ODObject result = this.GetFirstItemByUniqueField(collection, field, name); if (result != null) { return(result); } if (this.errorMessages.Count == errsNum) // если ошибок не было { result = ODObject.NewObject(collection); result["Name"] = name; result.Update(this); result = this.GetFirstItemByUniqueField(collection, field, name); } 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); }