コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
ファイル: ODataClient.cs プロジェクト: larsw/Simple.OData
        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));
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
 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));
 }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
ファイル: SchemaProvider.cs プロジェクト: larsw/Simple.OData
        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);
        }
コード例 #10
0
        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);
            }
        }
コード例 #11
0
ファイル: ODataClient.cs プロジェクト: larsw/Simple.OData
        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);
        }
コード例 #12
0
        private HttpCommand CreateUnlinkCommand(string tableName, string associationName, string entryPath)
        {
            var commandText = ODataHelper.CreateLinkCommand(entryPath, associationName);

            return(HttpCommand.Delete(commandText));
        }
コード例 #13
0
        public override IDictionary <string, object> GetEntry(HttpCommand command)
        {
            var text = Request(command.Request);

            return(ODataHelper.GetData(text).First());
        }