public IDictionary <string, object> InsertEntry(string tableName, IDictionary <string, object> entryData, bool resultRequired) { var entryMembers = ParseEntryMembers(tableName, entryData); var entry = ODataHelper.CreateDataElement(entryMembers.Properties); foreach (var associatedData in entryMembers.AssociationsByValue) { CreateLinkElement(entry, tableName, associatedData); } var commandText = GetTableActualName(tableName); var command = HttpCommand.Post(commandText, entryData, entry.ToString()); _requestBuilder.AddCommandToRequest(command); var result = _requestRunner.InsertEntry(command, resultRequired); foreach (var associatedData in entryMembers.AssociationsByContentId) { var linkCommand = CreateLinkCommand(tableName, associatedData.Key, ODataHelper.CreateLinkPath(command.ContentId), ODataHelper.CreateLinkPath(associatedData.Value)); _requestBuilder.AddCommandToRequest(linkCommand); _requestRunner.InsertEntry(linkCommand, resultRequired); } return(result); }
private int UpdateEntryPropertiesAndAssociations(string tableName, IDictionary <string, object> entryKey, IDictionary <string, object> entryData, EntryMembers entryMembers) { bool merge = CheckMergeConditions(tableName, entryKey, entryData); var commandText = FormatGetKeyCommand(tableName, entryKey); var entryElement = ODataHelper.CreateDataElement(entryMembers.Properties); foreach (var associatedData in entryMembers.AssociationsByValue) { CreateLinkElement(entryElement, tableName, associatedData); } var command = new HttpCommand(merge ? RestVerbs.MERGE : RestVerbs.PUT, commandText, entryData, entryElement.ToString()); _requestBuilder.AddCommandToRequest(command); var result = _requestRunner.UpdateEntry(command); foreach (var associatedData in entryMembers.AssociationsByContentId) { var linkCommand = CreateLinkCommand(tableName, associatedData.Key, ODataHelper.CreateLinkPath(command.ContentId), ODataHelper.CreateLinkPath(associatedData.Value)); _requestBuilder.AddCommandToRequest(linkCommand); _requestRunner.UpdateEntry(linkCommand); } return(result); }
public override IEnumerable <IDictionary <string, object> > FindEntries(HttpCommand command, bool scalarResult, bool setTotalCount, out int totalCount) { using (var response = TryRequest(command.Request)) { totalCount = 0; IEnumerable <IDictionary <string, object> > result = null; if (response.StatusCode != HttpStatusCode.OK) { result = Enumerable.Empty <IDictionary <string, object> >(); } else { var stream = response.GetResponseStream(); if (setTotalCount) { result = ODataHelper.GetData(stream, out totalCount); } else { result = ODataHelper.GetData(response.GetResponseStream(), scalarResult); } } return(result); } }
private HttpCommand CreateLinkCommand(string tableName, string associationName, int entryContentId, int linkContentId) { var linkEntry = ODataHelper.CreateLinkElement(linkContentId); var linkMethod = _schema.FindTable(tableName).FindAssociation(associationName).IsMultiple ? RestVerbs.POST : RestVerbs.PUT; var commandText = string.Format("${0}/$links/{1}", entryContentId, associationName); return(new HttpCommand(linkMethod, commandText, null, linkEntry.ToString(), true)); }
private HttpCommand CreateLinkCommand(string tableName, string associationName, string entryPath, string linkPath) { var linkEntry = ODataHelper.CreateLinkElement(linkPath); var linkMethod = _schema.FindTable(tableName).FindAssociation(associationName).IsMultiple ? RestVerbs.POST : RestVerbs.PUT; var commandText = ODataHelper.CreateLinkCommand(entryPath, associationName); return(new HttpCommand(linkMethod, commandText, null, linkEntry.ToString(), true)); }
public override IDictionary <string, object> InsertEntry(HttpCommand command, bool resultRequired) { var text = Request(command.Request); if (resultRequired) { return(ODataHelper.GetData(text).First()); } else { return(null); } }
private SchemaProvider(string urlBase, string metadataString) { if (!string.IsNullOrEmpty(metadataString)) { _metadataString = new Lazy <string>(() => metadataString); } else { _metadataString = new Lazy <string>(() => RequestMetadataAsString(urlBase)); } _metadata = new Lazy <EdmSchema>(() => ODataHelper.GetSchema(_metadataString.Value)); _schema = new Lazy <Schema>(() => Schema.Get(this)); }
private void CreateLinkElement(XElement entry, string tableName, KeyValuePair <string, object> associatedData) { if (associatedData.Value == null) { return; } var association = _schema.FindTable(tableName).FindAssociation(associatedData.Key); var associatedKeyValues = GetLinkedEntryKeyValues(association.ReferenceTableName, associatedData); if (associatedKeyValues != null) { ODataHelper.AddDataLink(entry, association.ActualName, association.ReferenceTableName, associatedKeyValues); } }
private EdmSchema RequestMetadata() { var requestBuilder = new CommandRequestBuilder(_urlBase); var command = HttpCommand.Get("$metadata"); requestBuilder.AddCommandToRequest(command); using (var response = new CommandRequestRunner().TryRequest(command.Request)) { if (response.StatusCode == HttpStatusCode.OK) { return(ODataHelper.GetSchema(response.GetResponseStream())); } } // TODO return(null); }
public override IEnumerable <IEnumerable <IEnumerable <KeyValuePair <string, object> > > > ExecuteFunction(HttpCommand command) { using (var response = TryRequest(command.Request)) { IEnumerable <IEnumerable <IEnumerable <KeyValuePair <string, object> > > > result = null; if (response.StatusCode != HttpStatusCode.OK) { result = Enumerable.Empty <IEnumerable <IDictionary <string, object> > >(); } else { var stream = response.GetResponseStream(); result = new[] { ODataHelper.GetData(response.GetResponseStream(), false) }; } return(result); } }
private void CreateLinkElement(XElement entry, string tableName, KeyValuePair <string, object> associatedData) { if (associatedData.Value == null) { return; } var association = _schema.FindTable(tableName).FindAssociation(associatedData.Key); var entryProperties = GetLinkedEntryProperties(associatedData.Value); var associatedKeyNames = _schema.FindTable(association.ReferenceTableName).GetKeyNames(); var associatedKeyValues = new object[associatedKeyNames.Count()]; for (int index = 0; index < associatedKeyNames.Count(); index++) { bool ok = entryProperties.TryGetValue(associatedKeyNames[index], out associatedKeyValues[index]); if (!ok) { return; } } ODataHelper.AddDataLink(entry, association.ActualName, association.ReferenceTableName, associatedKeyValues); }
private HttpCommand CreateUnlinkCommand(string tableName, string associationName, string entryPath) { var commandText = ODataHelper.CreateLinkCommand(entryPath, associationName); return(HttpCommand.Delete(commandText)); }
public override IDictionary <string, object> GetEntry(HttpCommand command) { var text = Request(command.Request); return(ODataHelper.GetData(text).First()); }