diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 00000000..86120424 --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,43 @@ +name: Build and Test + +on: + push: + branches: [ main, master, develop ] + pull_request: + branches: [ main, master, develop ] + workflow_dispatch: + +jobs: + build: + uses: ./.github/workflows/compile.yml + + test: + name: Run Tests + needs: build + runs-on: windows-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup NuGet + uses: NuGet/setup-nuget@v2 + + - name: Download debug build artifacts + uses: actions/download-artifact@v4 + with: + name: debug + path: dist/Debug + + - name: Install NUnit console runner + run: nuget install NUnit.Runners -Version 2.7.1 -OutputDirectory packages -Source https://api.nuget.org/v3/index.json + + - name: Run tests + run: packages/NUnit.Runners.2.7.1/tools/nunit-console.exe dist/Debug/Net452/Saleslogix.SData.Client.Test.dll /nologo /result=test-results.xml + + - name: Upload test results + if: always() + uses: actions/upload-artifact@v4 + with: + name: test-results + path: test-results.xml diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index f056ad23..8355920b 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -5,7 +5,7 @@ on: jobs: build: - runs-on: windows-2019 + runs-on: windows-latest steps: - uses: actions/checkout@v4 - uses: microsoft/setup-msbuild@v1.3.3 @@ -13,6 +13,9 @@ jobs: with: dotnet-version: "8.0.x" + - name: Install .NET Framework 4.5.2 targeting pack + run: choco install netfx-4.5.2-devpack -y --no-progress + - name: debug build shell: pwsh run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6a9f7e6b..b509ef28 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,7 @@ jobs: uses: ./.github/workflows/compile.yml nuget_job: needs: build_job - runs-on: windows-2019 + runs-on: windows-latest steps: - uses: actions/checkout@v4 - uses: nuget/setup-nuget@v1 diff --git a/.gitignore b/.gitignore index d49c5cc7..deecbeb9 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ *.sdf ipch/ obj/ +objnet/ [Bb]in [Dd]ebug*/ [Rr]elease*/ @@ -33,6 +34,10 @@ _ReSharper*/ [Tt]est[Rr]esult* *.ReSharper +#NuGet +packages/ +*.nupkg + #OS junk files Thumbs.db *.DS_Store diff --git a/DotNetSDataClient.Framework.sln b/DotNetSDataClient.Framework.sln index 9a234dbf..1255286c 100644 --- a/DotNetSDataClient.Framework.sln +++ b/DotNetSDataClient.Framework.sln @@ -10,12 +10,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlxFileBrowser", "demos\Slx EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlxJobScheduler", "demos\SlxJobScheduler\SlxJobScheduler.csproj", "{5CC2002C-8D4A-47F3-847C-3C8EAF485C36}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Saleslogix.SData.Client.Test_4_0", "Saleslogix.SData.Client.Test\Saleslogix.SData.Client.Test_4_0.csproj", "{92C27580-82D9-46FC-8E4A-9B75E6FF6C2B}" - ProjectSection(ProjectDependencies) = postProject - {FEECA9B9-980E-470F-81BA-C56ABD8D520E} = {FEECA9B9-980E-470F-81BA-C56ABD8D520E} - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Saleslogix.SData.Client_4_0", "Saleslogix.SData.Client\Saleslogix.SData.Client_4_0.csproj", "{FEECA9B9-980E-470F-81BA-C56ABD8D520E}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Saleslogix.SData.Client.Test_452", "Saleslogix.SData.Client.Test\Saleslogix.SData.Client.Test_452.csproj", "{92C27580-82D9-46FC-8E4A-9B75E6FF6C2B}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Saleslogix.SData.Client_48", "Saleslogix.SData.Client\Saleslogix.SData.Client_48.csproj", "{A1A43E15-7A71-4E99-B287-04ED341860D4}" ProjectSection(ProjectDependencies) = postProject @@ -25,9 +20,6 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{11DC44D8-8C25-468D-9F91-8922B9BB5D42}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Saleslogix.SData.Client_452", "Saleslogix.SData.Client\Saleslogix.SData.Client_452.csproj", "{E6CFD34D-762D-47BC-AF2D-B47ED6020D2A}" - ProjectSection(ProjectDependencies) = postProject - {FEECA9B9-980E-470F-81BA-C56ABD8D520E} = {FEECA9B9-980E-470F-81BA-C56ABD8D520E} - EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Saleslogix.SData.Client_472", "Saleslogix.SData.Client\Saleslogix.SData.Client_472.csproj", "{17BDC943-9A2F-4E9C-B605-63491448D50F}" ProjectSection(ProjectDependencies) = postProject @@ -82,16 +74,6 @@ Global {92C27580-82D9-46FC-8E4A-9B75E6FF6C2B}.Release|ARM.ActiveCfg = Release|Any CPU {92C27580-82D9-46FC-8E4A-9B75E6FF6C2B}.Release|x64.ActiveCfg = Release|Any CPU {92C27580-82D9-46FC-8E4A-9B75E6FF6C2B}.Release|x86.ActiveCfg = Release|Any CPU - {FEECA9B9-980E-470F-81BA-C56ABD8D520E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FEECA9B9-980E-470F-81BA-C56ABD8D520E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FEECA9B9-980E-470F-81BA-C56ABD8D520E}.Debug|ARM.ActiveCfg = Debug|Any CPU - {FEECA9B9-980E-470F-81BA-C56ABD8D520E}.Debug|x64.ActiveCfg = Debug|Any CPU - {FEECA9B9-980E-470F-81BA-C56ABD8D520E}.Debug|x86.ActiveCfg = Debug|Any CPU - {FEECA9B9-980E-470F-81BA-C56ABD8D520E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FEECA9B9-980E-470F-81BA-C56ABD8D520E}.Release|Any CPU.Build.0 = Release|Any CPU - {FEECA9B9-980E-470F-81BA-C56ABD8D520E}.Release|ARM.ActiveCfg = Release|Any CPU - {FEECA9B9-980E-470F-81BA-C56ABD8D520E}.Release|x64.ActiveCfg = Release|Any CPU - {FEECA9B9-980E-470F-81BA-C56ABD8D520E}.Release|x86.ActiveCfg = Release|Any CPU {A1A43E15-7A71-4E99-B287-04ED341860D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A1A43E15-7A71-4E99-B287-04ED341860D4}.Debug|Any CPU.Build.0 = Debug|Any CPU {A1A43E15-7A71-4E99-B287-04ED341860D4}.Debug|ARM.ActiveCfg = Debug|Any CPU diff --git a/Saleslogix.SData.Client.Test/SDataClientTests.cs b/Saleslogix.SData.Client.Test/SDataClientTests.cs index 70932531..fe4352e0 100644 --- a/Saleslogix.SData.Client.Test/SDataClientTests.cs +++ b/Saleslogix.SData.Client.Test/SDataClientTests.cs @@ -10,6 +10,127 @@ namespace Saleslogix.SData.Client.Test [TestFixture] public class SDataClientTests { + #region UserAgent Tests + + [Test] + public void UserAgent_NotSet_UsesDefault() + { + // When UserAgent is not set at all, the default should be used. + SDataRequest capturedRequest = null; + var requestMock = new Mock(null, null, null); + requestMock.SetupAllProperties(); + requestMock.Setup(x => x.GetResponse()).Returns(new SDataResponse(HttpStatusCode.OK, null, null, null, null, null, null, null, null)); + var requestFactory = new Func(uri => + { + capturedRequest = requestMock.Object; + return capturedRequest; + }); + + var client = new SDataClient("test://dummy", requestFactory); + // Do NOT set client.UserAgent - leave it at default + client.Execute(new SDataParameters { Path = "test" }); + + Assert.That(capturedRequest.UserAgent, Is.EqualTo(SDataConstants.UserAgent)); + } + + [Test] + public void UserAgent_SetToNull_FallsBackToDefault() + { + // When UserAgent is explicitly set to null, the default should be used. + SDataRequest capturedRequest = null; + var requestMock = new Mock(null, null, null); + requestMock.SetupAllProperties(); + requestMock.Setup(x => x.GetResponse()).Returns(new SDataResponse(HttpStatusCode.OK, null, null, null, null, null, null, null, null)); + var requestFactory = new Func(uri => + { + capturedRequest = requestMock.Object; + return capturedRequest; + }); + + var client = new SDataClient("test://dummy", requestFactory); + client.UserAgent = null; + client.Execute(new SDataParameters { Path = "test" }); + + Assert.That(capturedRequest.UserAgent, Is.EqualTo(SDataConstants.UserAgent)); + } + + [Test] + public void UserAgent_SetToEmpty_FallsBackToDefault() + { + // When UserAgent is explicitly set to empty string, the default should be used. + SDataRequest capturedRequest = null; + var requestMock = new Mock(null, null, null); + requestMock.SetupAllProperties(); + requestMock.Setup(x => x.GetResponse()).Returns(new SDataResponse(HttpStatusCode.OK, null, null, null, null, null, null, null, null)); + var requestFactory = new Func(uri => + { + capturedRequest = requestMock.Object; + return capturedRequest; + }); + + var client = new SDataClient("test://dummy", requestFactory); + client.UserAgent = ""; + client.Execute(new SDataParameters { Path = "test" }); + + Assert.That(capturedRequest.UserAgent, Is.EqualTo(SDataConstants.UserAgent)); + } + + [Test] + public void UserAgent_SetToWhitespace_FallsBackToDefault() + { + // When UserAgent is explicitly set to whitespace, the default should be used. + SDataRequest capturedRequest = null; + var requestMock = new Mock(null, null, null); + requestMock.SetupAllProperties(); + requestMock.Setup(x => x.GetResponse()).Returns(new SDataResponse(HttpStatusCode.OK, null, null, null, null, null, null, null, null)); + var requestFactory = new Func(uri => + { + capturedRequest = requestMock.Object; + return capturedRequest; + }); + + var client = new SDataClient("test://dummy", requestFactory); + client.UserAgent = " "; + client.Execute(new SDataParameters { Path = "test" }); + + Assert.That(capturedRequest.UserAgent, Is.EqualTo(SDataConstants.UserAgent)); + } + + [Test] + public void UserAgent_SetToCustomValue_UsesCustomValue() + { + // When UserAgent is set to a custom value, that value should be used. + SDataRequest capturedRequest = null; + var requestMock = new Mock(null, null, null); + requestMock.SetupAllProperties(); + requestMock.Setup(x => x.GetResponse()).Returns(new SDataResponse(HttpStatusCode.OK, null, null, null, null, null, null, null, null)); + var requestFactory = new Func(uri => + { + capturedRequest = requestMock.Object; + return capturedRequest; + }); + + var client = new SDataClient("test://dummy", requestFactory); + client.UserAgent = "MyCustomApp/1.0"; + client.Execute(new SDataParameters { Path = "test" }); + + Assert.That(capturedRequest.UserAgent, Is.EqualTo("MyCustomApp/1.0")); + } + + [Test] + public void UserAgent_InstanceIsolation_DoesNotAffectOtherInstances() + { + // Setting UserAgent on one instance should not affect another instance. + var client1 = new SDataClient("test://dummy1"); + var client2 = new SDataClient("test://dummy2"); + + client1.UserAgent = "CustomAgent1"; + + Assert.That(client1.UserAgent, Is.EqualTo("CustomAgent1")); + Assert.That(client2.UserAgent, Is.EqualTo(SDataConstants.UserAgent)); + } + + #endregion [Test] public void Execute_Test() { diff --git a/Saleslogix.SData.Client.Test/Saleslogix.SData.Client.Test_4_0.csproj b/Saleslogix.SData.Client.Test/Saleslogix.SData.Client.Test_452.csproj similarity index 72% rename from Saleslogix.SData.Client.Test/Saleslogix.SData.Client.Test_4_0.csproj rename to Saleslogix.SData.Client.Test/Saleslogix.SData.Client.Test_452.csproj index 63751894..71c47c80 100644 --- a/Saleslogix.SData.Client.Test/Saleslogix.SData.Client.Test_4_0.csproj +++ b/Saleslogix.SData.Client.Test/Saleslogix.SData.Client.Test_452.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -10,19 +10,21 @@ Properties Saleslogix.SData.Client.Test Saleslogix.SData.Client.Test - v4.0 + v4.5.2 512 true ..\DotNetSDataClient.snk + true full false - ..\dist\Debug\Net40\ + ..\dist\Debug\Net452\ DEBUG;TRACE;NET_4_0 prompt 4 + false pdbonly @@ -31,6 +33,7 @@ TRACE;NET_4_0 prompt 4 + false @@ -40,6 +43,38 @@ ..\dependencies\NUnit\nunit.framework.dll + + ..\dependencies\NUnitTestAdapter\NUnit.VisualStudio.TestAdapter.dll + true + + + ..\dependencies\NUnitTestAdapter\nunit.core.dll + true + + + ..\dependencies\NUnitTestAdapter\nunit.core.interfaces.dll + true + + + ..\dependencies\NUnitTestAdapter\nunit.util.dll + true + + + ..\dependencies\NUnitTestAdapter\Mono.Cecil.dll + true + + + ..\dependencies\NUnitTestAdapter\Mono.Cecil.Mdb.dll + true + + + ..\dependencies\NUnitTestAdapter\Mono.Cecil.Pdb.dll + true + + + ..\dependencies\NUnitTestAdapter\Mono.Cecil.Rocks.dll + true + 3.5 @@ -94,17 +129,10 @@ - - {FEECA9B9-980E-470F-81BA-C56ABD8D520E} - Saleslogix.SData.Client_4_0 + + {e6cfd34d-762d-47bc-af2d-b47ed6020d2a} + Saleslogix.SData.Client_452 - \ No newline at end of file diff --git a/Saleslogix.SData.Client/Directory.Build.props b/Saleslogix.SData.Client/Directory.Build.props new file mode 100644 index 00000000..14af6435 --- /dev/null +++ b/Saleslogix.SData.Client/Directory.Build.props @@ -0,0 +1,16 @@ + + + + + objnet\ + $(MSBuildThisFileDirectory)objnet\ + + + diff --git a/Saleslogix.SData.Client/Framework/SDataRequest.cs b/Saleslogix.SData.Client/Framework/SDataRequest.cs index 86aaf510..f6973ff3 100644 --- a/Saleslogix.SData.Client/Framework/SDataRequest.cs +++ b/Saleslogix.SData.Client/Framework/SDataRequest.cs @@ -44,7 +44,7 @@ public SDataRequest(string uri = null, HttpMethod method = HttpMethod.Get, objec { Uri = uri; #if !PCL && !NETFX_CORE && !SILVERLIGHT - UserAgent = "DotNetSDataClient"; + UserAgent = SDataConstants.UserAgent; Timeout = 120000; #endif TimeoutRetryAttempts = 1; @@ -444,11 +444,7 @@ private WebRequest CreateRequest(string uri, out MediaType? contentType, out obj httpRequest.ReadWriteTimeout = Timeout; httpRequest.KeepAlive = false; httpRequest.ProtocolVersion = HttpVersion.Version10; - - if (UserAgent != null) - { - httpRequest.UserAgent = UserAgent; - } + httpRequest.UserAgent = !string.IsNullOrWhiteSpace(UserAgent) ? UserAgent : SDataConstants.UserAgent; #endif if (Accept != null) { diff --git a/Saleslogix.SData.Client/LinqBridge.cs b/Saleslogix.SData.Client/LinqBridge.cs deleted file mode 100644 index 3f195115..00000000 --- a/Saleslogix.SData.Client/LinqBridge.cs +++ /dev/null @@ -1,3100 +0,0 @@ -#region License, Terms and Author(s) -// -// LINQBridge -// Copyright (c) 2007 Atif Aziz, Joseph Albahari. All rights reserved. -// -// Author(s): -// -// Atif Aziz, http://www.raboof.com -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the New BSD License, a copy of which should have -// been delivered along with this distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -#endregion - -// $Id: Enumerable.cs c08984d432b1 2012/04/17 16:05:19 azizatif $ - -namespace System.Linq -{ - #region Imports - - using System; - using System.Collections; - using System.Collections.Generic; - using System.Diagnostics; - using LinqBridge; - - #endregion - - /// - /// Provides a set of static (Shared in Visual Basic) methods for - /// querying objects that implement . - /// - - static partial class Enumerable - { - /// - /// Returns the input typed as . - /// - - public static IEnumerable AsEnumerable(this IEnumerable source) - { - return source; - } - - /// - /// Returns an empty that has the - /// specified type argument. - /// - - public static IEnumerable Empty() - { - return Sequence.Empty; - } - - /// - /// Converts the elements of an to the - /// specified type. - /// - - public static IEnumerable Cast( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - return CastYield(source); - } - - private static IEnumerable CastYield( - IEnumerable source) - { - foreach (var item in source) - yield return (TResult) item; - } - - /// - /// Filters the elements of an based on a specified type. - /// - - public static IEnumerable OfType( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - return OfTypeYield(source); - } - - private static IEnumerable OfTypeYield( - IEnumerable source) - { - foreach (var item in source) - if (item is TResult) - yield return (TResult) item; - } - - /// - /// Generates a sequence of integral numbers within a specified range. - /// - /// The value of the first integer in the sequence. - /// The number of sequential integers to generate. - - public static IEnumerable Range(int start, int count) - { - if (count < 0) - throw new ArgumentOutOfRangeException("count", count, null); - - var end = (long) start + count; - if (end - 1 >= int.MaxValue) - throw new ArgumentOutOfRangeException("count", count, null); - - return RangeYield(start, end); - } - - private static IEnumerable RangeYield(int start, long end) - { - for (var i = start; i < end; i++) - yield return i; - } - - /// - /// Generates a sequence that contains one repeated value. - /// - - public static IEnumerable Repeat(TResult element, int count) - { - if (count < 0) throw new ArgumentOutOfRangeException("count", count, null); - - return RepeatYield(element, count); - } - - private static IEnumerable RepeatYield(TResult element, int count) - { - for (var i = 0; i < count; i++) - yield return element; - } - - /// - /// Filters a sequence of values based on a predicate. - /// - - public static IEnumerable Where( - this IEnumerable source, - Func predicate) - { - if (predicate == null) throw new ArgumentNullException("predicate"); - - return source.Where((item, i) => predicate(item)); - } - - /// - /// Filters a sequence of values based on a predicate. - /// Each element's index is used in the logic of the predicate function. - /// - - public static IEnumerable Where( - this IEnumerable source, - Func predicate) - { - if (source == null) throw new ArgumentNullException("source"); - if (predicate == null) throw new ArgumentNullException("predicate"); - - return WhereYield(source, predicate); - } - - private static IEnumerable WhereYield( - IEnumerable source, - Func predicate) - { - var i = 0; - foreach (var item in source) - if (predicate(item, i++)) - yield return item; - } - - /// - /// Projects each element of a sequence into a new form. - /// - - public static IEnumerable Select( - this IEnumerable source, - Func selector) - { - if (selector == null) throw new ArgumentNullException("selector"); - - return source.Select((item, i) => selector(item)); - } - - /// - /// Projects each element of a sequence into a new form by - /// incorporating the element's index. - /// - - public static IEnumerable Select( - this IEnumerable source, - Func selector) - { - if (source == null) throw new ArgumentNullException("source"); - if (selector == null) throw new ArgumentNullException("selector"); - - return SelectYield(source, selector); - } - - private static IEnumerable SelectYield( - IEnumerable source, - Func selector) - { - var i = 0; - foreach (var item in source) - yield return selector(item, i++); - } - - /// - /// Projects each element of a sequence to an - /// and flattens the resulting sequences into one sequence. - /// - - public static IEnumerable SelectMany( - this IEnumerable source, - Func> selector) - { - if (selector == null) throw new ArgumentNullException("selector"); - - return source.SelectMany((item, i) => selector(item)); - } - - /// - /// Projects each element of a sequence to an , - /// and flattens the resulting sequences into one sequence. The - /// index of each source element is used in the projected form of - /// that element. - /// - - public static IEnumerable SelectMany( - this IEnumerable source, - Func> selector) - { - if (selector == null) throw new ArgumentNullException("selector"); - - return source.SelectMany(selector, (item, subitem) => subitem); - } - - /// - /// Projects each element of a sequence to an , - /// flattens the resulting sequences into one sequence, and invokes - /// a result selector function on each element therein. - /// - - public static IEnumerable SelectMany( - this IEnumerable source, - Func> collectionSelector, - Func resultSelector) - { - if (collectionSelector == null) throw new ArgumentNullException("collectionSelector"); - - return source.SelectMany((item, i) => collectionSelector(item), resultSelector); - } - - /// - /// Projects each element of a sequence to an , - /// flattens the resulting sequences into one sequence, and invokes - /// a result selector function on each element therein. The index of - /// each source element is used in the intermediate projected form - /// of that element. - /// - - public static IEnumerable SelectMany( - this IEnumerable source, - Func> collectionSelector, - Func resultSelector) - { - if (source == null) throw new ArgumentNullException("source"); - if (collectionSelector == null) throw new ArgumentNullException("collectionSelector"); - if (resultSelector == null) throw new ArgumentNullException("resultSelector"); - - return SelectManyYield(source, collectionSelector, resultSelector); - } - - private static IEnumerable SelectManyYield( - this IEnumerable source, - Func> collectionSelector, - Func resultSelector) - { - var i = 0; - foreach (var item in source) - foreach (var subitem in collectionSelector(item, i++)) - yield return resultSelector(item, subitem); - } - - /// - /// Returns elements from a sequence as long as a specified condition is true. - /// - - public static IEnumerable TakeWhile( - this IEnumerable source, - Func predicate) - { - if (predicate == null) throw new ArgumentNullException("predicate"); - - return source.TakeWhile((item, i) => predicate(item)); - } - - /// - /// Returns elements from a sequence as long as a specified condition is true. - /// The element's index is used in the logic of the predicate function. - /// - - public static IEnumerable TakeWhile( - this IEnumerable source, - Func predicate) - { - if (source == null) throw new ArgumentNullException("source"); - if (predicate == null) throw new ArgumentNullException("predicate"); - - return TakeWhileYield(source, predicate); - } - - private static IEnumerable TakeWhileYield( - this IEnumerable source, - Func predicate) - { - var i = 0; - foreach (var item in source) - if (predicate(item, i++)) - yield return item; - else - break; - } - - /// - /// Returns a specified number of contiguous elements from the start - /// of a sequence. - /// - - public static IEnumerable Take( - this IEnumerable source, - int count) - { - return source.TakeWhile((item, i) => i < count); - } - - private static class Futures - { - public static readonly Func Default = () => default(T); - public static readonly Func Undefined = () => { throw new InvalidOperationException(); }; - } - - /// - /// Base implementation of First operator. - /// - - private static TSource FirstImpl( - this IEnumerable source, - Func empty) - { - if (source == null) throw new ArgumentNullException("source"); - Debug.Assert(empty != null); - - var list = source as IList; // optimized case for lists - if (list != null) - return list.Count > 0 ? list[0] : empty(); - - using (var e = source.GetEnumerator()) // fallback for enumeration - return e.MoveNext() ? e.Current : empty(); - } - - /// - /// Returns the first element of a sequence. - /// - - public static TSource First( - this IEnumerable source) - { - return source.FirstImpl(Futures.Undefined); - } - - /// - /// Returns the first element in a sequence that satisfies a specified condition. - /// - - public static TSource First( - this IEnumerable source, - Func predicate) - { - return First(source.Where(predicate)); - } - - /// - /// Returns the first element of a sequence, or a default value if - /// the sequence contains no elements. - /// - - public static TSource FirstOrDefault( - this IEnumerable source) - { - return source.FirstImpl(Futures.Default); - } - - /// - /// Returns the first element of the sequence that satisfies a - /// condition or a default value if no such element is found. - /// - - public static TSource FirstOrDefault( - this IEnumerable source, - Func predicate) - { - return FirstOrDefault(source.Where(predicate)); - } - - /// - /// Base implementation of Last operator. - /// - - private static TSource LastImpl( - this IEnumerable source, - Func empty) - { - if (source == null) throw new ArgumentNullException("source"); - - var list = source as IList; // optimized case for lists - if (list != null) - return list.Count > 0 ? list[list.Count - 1] : empty(); - - using (var e = source.GetEnumerator()) - { - if (!e.MoveNext()) - return empty(); - - var last = e.Current; - while (e.MoveNext()) - last = e.Current; - - return last; - } - } - - /// - /// Returns the last element of a sequence. - /// - public static TSource Last( - this IEnumerable source) - { - return source.LastImpl(Futures.Undefined); - } - - /// - /// Returns the last element of a sequence that satisfies a - /// specified condition. - /// - - public static TSource Last( - this IEnumerable source, - Func predicate) - { - return Last(source.Where(predicate)); - } - - /// - /// Returns the last element of a sequence, or a default value if - /// the sequence contains no elements. - /// - - public static TSource LastOrDefault( - this IEnumerable source) - { - return source.LastImpl(Futures.Default); - } - - /// - /// Returns the last element of a sequence that satisfies a - /// condition or a default value if no such element is found. - /// - - public static TSource LastOrDefault( - this IEnumerable source, - Func predicate) - { - return LastOrDefault(source.Where(predicate)); - } - - /// - /// Base implementation of Single operator. - /// - - private static TSource SingleImpl( - this IEnumerable source, - Func empty) - { - if (source == null) throw new ArgumentNullException("source"); - - using (var e = source.GetEnumerator()) - { - if (e.MoveNext()) - { - var single = e.Current; - if (!e.MoveNext()) - return single; - - throw new InvalidOperationException(); - } - - return empty(); - } - } - - /// - /// Returns the only element of a sequence, and throws an exception - /// if there is not exactly one element in the sequence. - /// - - public static TSource Single( - this IEnumerable source) - { - return source.SingleImpl(Futures.Undefined); - } - - /// - /// Returns the only element of a sequence that satisfies a - /// specified condition, and throws an exception if more than one - /// such element exists. - /// - - public static TSource Single( - this IEnumerable source, - Func predicate) - { - return Single(source.Where(predicate)); - } - - /// - /// Returns the only element of a sequence, or a default value if - /// the sequence is empty; this method throws an exception if there - /// is more than one element in the sequence. - /// - - public static TSource SingleOrDefault( - this IEnumerable source) - { - return source.SingleImpl(Futures.Default); - } - - /// - /// Returns the only element of a sequence that satisfies a - /// specified condition or a default value if no such element - /// exists; this method throws an exception if more than one element - /// satisfies the condition. - /// - - public static TSource SingleOrDefault( - this IEnumerable source, - Func predicate) - { - return SingleOrDefault(source.Where(predicate)); - } - - /// - /// Returns the element at a specified index in a sequence. - /// - - public static TSource ElementAt( - this IEnumerable source, - int index) - { - if (source == null) throw new ArgumentNullException("source"); - - if (index < 0) - throw new ArgumentOutOfRangeException("index", index, null); - - var list = source as IList; - if (list != null) - return list[index]; - - try - { - return source.SkipWhile((item, i) => i < index).First(); - } - catch (InvalidOperationException) // if thrown by First - { - throw new ArgumentOutOfRangeException("index", index, null); - } - } - - /// - /// Returns the element at a specified index in a sequence or a - /// default value if the index is out of range. - /// - - public static TSource ElementAtOrDefault( - this IEnumerable source, - int index) - { - if (source == null) throw new ArgumentNullException("source"); - - if (index < 0) - return default(TSource); - - var list = source as IList; - if (list != null) - return index < list.Count ? list[index] : default(TSource); - - return source.SkipWhile((item, i) => i < index).FirstOrDefault(); - } - - /// - /// Inverts the order of the elements in a sequence. - /// - - public static IEnumerable Reverse( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - return ReverseYield(source); - } - - private static IEnumerable ReverseYield(IEnumerable source) - { - var stack = new Stack(); - foreach (var item in source) - stack.Push(item); - - foreach (var item in stack) - yield return item; - } - - /// - /// Bypasses elements in a sequence as long as a specified condition - /// is true and then returns the remaining elements. - /// - - public static IEnumerable SkipWhile( - this IEnumerable source, - Func predicate) - { - if (predicate == null) throw new ArgumentNullException("predicate"); - - return source.SkipWhile((item, i) => predicate(item)); - } - - /// - /// Bypasses elements in a sequence as long as a specified condition - /// is true and then returns the remaining elements. The element's - /// index is used in the logic of the predicate function. - /// - - public static IEnumerable SkipWhile( - this IEnumerable source, - Func predicate) - { - if (source == null) throw new ArgumentNullException("source"); - if (predicate == null) throw new ArgumentNullException("predicate"); - - return SkipWhileYield(source, predicate); - } - - private static IEnumerable SkipWhileYield( - IEnumerable source, - Func predicate) - { - using (var e = source.GetEnumerator()) - { - for (var i = 0; ; i++) - { - if (!e.MoveNext()) - yield break; - - if (!predicate(e.Current, i)) - break; - } - - do { yield return e.Current; } while (e.MoveNext()); - } - } - - /// - /// Bypasses a specified number of elements in a sequence and then - /// returns the remaining elements. - /// - - public static IEnumerable Skip( - this IEnumerable source, - int count) - { - return source.SkipWhile((item, i) => i < count); - } - - /// - /// Returns the number of elements in a sequence. - /// - - public static int Count( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - var collection = source as ICollection; - return collection != null - ? collection.Count - : source.Aggregate(0, (count, item) => checked(count + 1)); - } - - /// - /// Returns a number that represents how many elements in the - /// specified sequence satisfy a condition. - /// - - public static int Count( - this IEnumerable source, - Func predicate) - { - return Count(source.Where(predicate)); - } - - /// - /// Returns an that represents the total number - /// of elements in a sequence. - /// - - public static long LongCount( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - var array = source as Array; - return array != null - ? array.LongLength - : source.Aggregate(0L, (count, item) => count + 1); - } - - /// - /// Returns an that represents how many elements - /// in a sequence satisfy a condition. - /// - - public static long LongCount( - this IEnumerable source, - Func predicate) - { - return LongCount(source.Where(predicate)); - } - - /// - /// Concatenates two sequences. - /// - - public static IEnumerable Concat( - this IEnumerable first, - IEnumerable second) - { - if (first == null) throw new ArgumentNullException("first"); - if (second == null) throw new ArgumentNullException("second"); - - return ConcatYield(first, second); - } - - private static IEnumerable ConcatYield( - IEnumerable first, - IEnumerable second) - { - foreach (var item in first) - yield return item; - - foreach (var item in second) - yield return item; - } - - /// - /// Creates a from an . - /// - - public static List ToList( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - return new List(source); - } - - /// - /// Creates an array from an . - /// - - public static TSource[] ToArray( - this IEnumerable source) - { - return source.ToList().ToArray(); - } - - /// - /// Returns distinct elements from a sequence by using the default - /// equality comparer to compare values. - /// - - public static IEnumerable Distinct( - this IEnumerable source) - { - return Distinct(source, /* comparer */ null); - } - - /// - /// Returns distinct elements from a sequence by using a specified - /// to compare values. - /// - - public static IEnumerable Distinct( - this IEnumerable source, - IEqualityComparer comparer) - { - if (source == null) throw new ArgumentNullException("source"); - - return DistinctYield(source, comparer); - } - - private static IEnumerable DistinctYield( - IEnumerable source, - IEqualityComparer comparer) - { - var set = new Dictionary(comparer); - var gotNull = false; - - foreach (var item in source) - { - if (item == null) - { - if (gotNull) - continue; - gotNull = true; - } - else - { - if (set.ContainsKey(item)) - continue; - set.Add(item, null); - } - - yield return item; - } - } - - /// - /// Creates a from an - /// according to a specified key - /// selector function. - /// - - public static ILookup ToLookup( - this IEnumerable source, - Func keySelector) - { - return ToLookup(source, keySelector, e => e, /* comparer */ null); - } - - /// - /// Creates a from an - /// according to a specified key - /// selector function and a key comparer. - /// - - public static ILookup ToLookup( - this IEnumerable source, - Func keySelector, - IEqualityComparer comparer) - { - return ToLookup(source, keySelector, e => e, comparer); - } - - /// - /// Creates a from an - /// according to specified key - /// and element selector functions. - /// - - public static ILookup ToLookup( - this IEnumerable source, - Func keySelector, - Func elementSelector) - { - return ToLookup(source, keySelector, elementSelector, /* comparer */ null); - } - - /// - /// Creates a from an - /// according to a specified key - /// selector function, a comparer and an element selector function. - /// - - public static ILookup ToLookup( - this IEnumerable source, - Func keySelector, - Func elementSelector, - IEqualityComparer comparer) - { - if (source == null) throw new ArgumentNullException("source"); - if (keySelector == null) throw new ArgumentNullException("keySelector"); - if (elementSelector == null) throw new ArgumentNullException("elementSelector"); - - var lookup = new Lookup(comparer); - - foreach (var item in source) - { - var key = keySelector(item); - - var grouping = (Grouping) lookup.Find(key); - if (grouping == null) - { - grouping = new Grouping(key); - lookup.Add(grouping); - } - - grouping.Add(elementSelector(item)); - } - - return lookup; - } - - /// - /// Groups the elements of a sequence according to a specified key - /// selector function. - /// - - public static IEnumerable> GroupBy( - this IEnumerable source, - Func keySelector) - { - return GroupBy(source, keySelector, /* comparer */ null); - } - - /// - /// Groups the elements of a sequence according to a specified key - /// selector function and compares the keys by using a specified - /// comparer. - /// - - public static IEnumerable> GroupBy( - this IEnumerable source, - Func keySelector, - IEqualityComparer comparer) - { - return GroupBy(source, keySelector, e => e, comparer); - } - - /// - /// Groups the elements of a sequence according to a specified key - /// selector function and projects the elements for each group by - /// using a specified function. - /// - - public static IEnumerable> GroupBy( - this IEnumerable source, - Func keySelector, - Func elementSelector) - { - return GroupBy(source, keySelector, elementSelector, /* comparer */ null); - } - - /// - /// Groups the elements of a sequence according to a specified key - /// selector function and creates a result value from each group and - /// its key. - /// - - public static IEnumerable> GroupBy( - this IEnumerable source, - Func keySelector, - Func elementSelector, - IEqualityComparer comparer) - { - if (source == null) throw new ArgumentNullException("source"); - if (keySelector == null) throw new ArgumentNullException("keySelector"); - if (elementSelector == null) throw new ArgumentNullException("elementSelector"); - - return ToLookup(source, keySelector, elementSelector, comparer); - } - - /// - /// Groups the elements of a sequence according to a key selector - /// function. The keys are compared by using a comparer and each - /// group's elements are projected by using a specified function. - /// - - public static IEnumerable GroupBy( - this IEnumerable source, - Func keySelector, - Func, TResult> resultSelector) - { - return GroupBy(source, keySelector, resultSelector, /* comparer */ null); - } - - /// - /// Groups the elements of a sequence according to a specified key - /// selector function and creates a result value from each group and - /// its key. The elements of each group are projected by using a - /// specified function. - /// - - public static IEnumerable GroupBy( - this IEnumerable source, - Func keySelector, - Func, TResult> resultSelector, - IEqualityComparer comparer) - { - if (source == null) throw new ArgumentNullException("source"); - if (keySelector == null) throw new ArgumentNullException("keySelector"); - if (resultSelector == null) throw new ArgumentNullException("resultSelector"); - - return ToLookup(source, keySelector, comparer).Select(g => resultSelector(g.Key, g)); - } - - /// - /// Groups the elements of a sequence according to a specified key - /// selector function and creates a result value from each group and - /// its key. The keys are compared by using a specified comparer. - /// - - public static IEnumerable GroupBy( - this IEnumerable source, - Func keySelector, - Func elementSelector, - Func, TResult> resultSelector) - { - return GroupBy(source, keySelector, elementSelector, resultSelector, /* comparer */ null); - } - - /// - /// Groups the elements of a sequence according to a specified key - /// selector function and creates a result value from each group and - /// its key. Key values are compared by using a specified comparer, - /// and the elements of each group are projected by using a - /// specified function. - /// - - public static IEnumerable GroupBy( - this IEnumerable source, - Func keySelector, - Func elementSelector, - Func, TResult> resultSelector, - IEqualityComparer comparer) - { - if (source == null) throw new ArgumentNullException("source"); - if (keySelector == null) throw new ArgumentNullException("keySelector"); - if (elementSelector == null) throw new ArgumentNullException("elementSelector"); - if (resultSelector == null) throw new ArgumentNullException("resultSelector"); - - return ToLookup(source, keySelector, elementSelector, comparer) - .Select(g => resultSelector(g.Key, g)); - } - - /// - /// Applies an accumulator function over a sequence. - /// - - public static TSource Aggregate( - this IEnumerable source, - Func func) - { - if (source == null) throw new ArgumentNullException("source"); - if (func == null) throw new ArgumentNullException("func"); - - using (var e = source.GetEnumerator()) - { - if (!e.MoveNext()) - throw new InvalidOperationException(); - - return e.Renumerable().Skip(1).Aggregate(e.Current, func); - } - } - - /// - /// Applies an accumulator function over a sequence. The specified - /// seed value is used as the initial accumulator value. - /// - - public static TAccumulate Aggregate( - this IEnumerable source, - TAccumulate seed, - Func func) - { - return Aggregate(source, seed, func, r => r); - } - - /// - /// Applies an accumulator function over a sequence. The specified - /// seed value is used as the initial accumulator value, and the - /// specified function is used to select the result value. - /// - - public static TResult Aggregate( - this IEnumerable source, - TAccumulate seed, - Func func, - Func resultSelector) - { - if (source == null) throw new ArgumentNullException("source"); - if (func == null) throw new ArgumentNullException("func"); - if (resultSelector == null) throw new ArgumentNullException("resultSelector"); - - var result = seed; - - foreach (var item in source) - result = func(result, item); - - return resultSelector(result); - } - - /// - /// Produces the set union of two sequences by using the default - /// equality comparer. - /// - - public static IEnumerable Union( - this IEnumerable first, - IEnumerable second) - { - return Union(first, second, /* comparer */ null); - } - - /// - /// Produces the set union of two sequences by using a specified - /// . - /// - - public static IEnumerable Union( - this IEnumerable first, - IEnumerable second, - IEqualityComparer comparer) - { - return first.Concat(second).Distinct(comparer); - } - - /// - /// Returns the elements of the specified sequence or the type - /// parameter's default value in a singleton collection if the - /// sequence is empty. - /// - - public static IEnumerable DefaultIfEmpty( - this IEnumerable source) - { - return source.DefaultIfEmpty(default(TSource)); - } - - /// - /// Returns the elements of the specified sequence or the specified - /// value in a singleton collection if the sequence is empty. - /// - - public static IEnumerable DefaultIfEmpty( - this IEnumerable source, - TSource defaultValue) - { - if (source == null) throw new ArgumentNullException("source"); - - return DefaultIfEmptyYield(source, defaultValue); - } - - private static IEnumerable DefaultIfEmptyYield( - IEnumerable source, - TSource defaultValue) - { - using (var e = source.GetEnumerator()) - { - if (!e.MoveNext()) - yield return defaultValue; - else - do { yield return e.Current; } while (e.MoveNext()); - } - } - - /// - /// Determines whether all elements of a sequence satisfy a condition. - /// - - public static bool All( - this IEnumerable source, - Func predicate) - { - if (source == null) throw new ArgumentNullException("source"); - if (predicate == null) throw new ArgumentNullException("predicate"); - - foreach (var item in source) - if (!predicate(item)) - return false; - - return true; - } - - /// - /// Determines whether a sequence contains any elements. - /// - - public static bool Any( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - using (var e = source.GetEnumerator()) - return e.MoveNext(); - } - - /// - /// Determines whether any element of a sequence satisfies a - /// condition. - /// - - public static bool Any( - this IEnumerable source, - Func predicate) - { - return source.Where(predicate).Any(); - } - - /// - /// Determines whether a sequence contains a specified element by - /// using the default equality comparer. - /// - - public static bool Contains( - this IEnumerable source, - TSource value) - { - return source.Contains(value, /* comparer */ null); - } - - /// - /// Determines whether a sequence contains a specified element by - /// using a specified . - /// - - public static bool Contains( - this IEnumerable source, - TSource value, - IEqualityComparer comparer) - { - if (source == null) throw new ArgumentNullException("source"); - - if (comparer == null) - { - var collection = source as ICollection; - if (collection != null) - return collection.Contains(value); - } - - comparer = comparer ?? EqualityComparer.Default; - return source.Any(item => comparer.Equals(item, value)); - } - - /// - /// Determines whether two sequences are equal by comparing the - /// elements by using the default equality comparer for their type. - /// - - public static bool SequenceEqual( - this IEnumerable first, - IEnumerable second) - { - return first.SequenceEqual(second, /* comparer */ null); - } - - /// - /// Determines whether two sequences are equal by comparing their - /// elements by using a specified . - /// - - public static bool SequenceEqual( - this IEnumerable first, - IEnumerable second, - IEqualityComparer comparer) - { - if (first == null) throw new ArgumentNullException("frist"); - if (second == null) throw new ArgumentNullException("second"); - - comparer = comparer ?? EqualityComparer.Default; - - using (IEnumerator lhs = first.GetEnumerator(), - rhs = second.GetEnumerator()) - { - do - { - if (!lhs.MoveNext()) - return !rhs.MoveNext(); - - if (!rhs.MoveNext()) - return false; - } - while (comparer.Equals(lhs.Current, rhs.Current)); - } - - return false; - } - - /// - /// Base implementation for Min/Max operator. - /// - - private static TSource MinMaxImpl( - this IEnumerable source, - Func lesser) - { - if (source == null) throw new ArgumentNullException("source"); - Debug.Assert(lesser != null); - - if (typeof(TSource).IsClass) // ReSharper disable CompareNonConstrainedGenericWithNull - source = source.Where(e => e != null).DefaultIfEmpty(); // ReSharper restore CompareNonConstrainedGenericWithNull - - return source.Aggregate((a, item) => lesser(a, item) ? a : item); - } - - /// - /// Base implementation for Min/Max operator for nullable types. - /// - - private static TSource? MinMaxImpl( - this IEnumerable source, - TSource? seed, Func lesser) where TSource : struct - { - if (source == null) throw new ArgumentNullException("source"); - Debug.Assert(lesser != null); - - return source.Aggregate(seed, (a, item) => lesser(a, item) ? a : item); - // == MinMaxImpl(Repeat(null, 1).Concat(source), lesser); - } - - /// - /// Returns the minimum value in a generic sequence. - /// - - public static TSource Min( - this IEnumerable source) - { - var comparer = Comparer.Default; - return source.MinMaxImpl((x, y) => comparer.Compare(x, y) < 0); - } - - /// - /// Invokes a transform function on each element of a generic - /// sequence and returns the minimum resulting value. - /// - - public static TResult Min( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Min(); - } - - /// - /// Returns the maximum value in a generic sequence. - /// - - public static TSource Max( - this IEnumerable source) - { - var comparer = Comparer.Default; - return source.MinMaxImpl((x, y) => comparer.Compare(x, y) > 0); - } - - /// - /// Invokes a transform function on each element of a generic - /// sequence and returns the maximum resulting value. - /// - - public static TResult Max( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Max(); - } - - /// - /// Makes an enumerator seen as enumerable once more. - /// - /// - /// The supplied enumerator must have been started. The first element - /// returned is the element the enumerator was on when passed in. - /// DO NOT use this method if the caller must be a generator. It is - /// mostly safe among aggregate operations. - /// - - private static IEnumerable Renumerable(this IEnumerator e) - { - Debug.Assert(e != null); - - do { yield return e.Current; } while (e.MoveNext()); - } - - /// - /// Sorts the elements of a sequence in ascending order according to a key. - /// - - public static IOrderedEnumerable OrderBy( - this IEnumerable source, - Func keySelector) - { - return source.OrderBy(keySelector, /* comparer */ null); - } - - /// - /// Sorts the elements of a sequence in ascending order by using a - /// specified comparer. - /// - - public static IOrderedEnumerable OrderBy( - this IEnumerable source, - Func keySelector, - IComparer comparer) - { - if (source == null) throw new ArgumentNullException("source"); - if (keySelector == null) throw new ArgumentNullException("keySelector"); - - return new OrderedEnumerable(source, keySelector, comparer, /* descending */ false); - } - - /// - /// Sorts the elements of a sequence in descending order according to a key. - /// - - public static IOrderedEnumerable OrderByDescending( - this IEnumerable source, - Func keySelector) - { - return source.OrderByDescending(keySelector, /* comparer */ null); - } - - /// - /// Sorts the elements of a sequence in descending order by using a - /// specified comparer. - /// - - public static IOrderedEnumerable OrderByDescending( - this IEnumerable source, - Func keySelector, - IComparer comparer) - { - if (source == null) throw new ArgumentNullException("source"); - if (source == null) throw new ArgumentNullException("keySelector"); - - return new OrderedEnumerable(source, keySelector, comparer, /* descending */ true); - } - - /// - /// Performs a subsequent ordering of the elements in a sequence in - /// ascending order according to a key. - /// - - public static IOrderedEnumerable ThenBy( - this IOrderedEnumerable source, - Func keySelector) - { - return source.ThenBy(keySelector, /* comparer */ null); - } - - /// - /// Performs a subsequent ordering of the elements in a sequence in - /// ascending order by using a specified comparer. - /// - - public static IOrderedEnumerable ThenBy( - this IOrderedEnumerable source, - Func keySelector, - IComparer comparer) - { - if (source == null) throw new ArgumentNullException("source"); - - return source.CreateOrderedEnumerable(keySelector, comparer, /* descending */ false); - } - - /// - /// Performs a subsequent ordering of the elements in a sequence in - /// descending order, according to a key. - /// - - public static IOrderedEnumerable ThenByDescending( - this IOrderedEnumerable source, - Func keySelector) - { - return source.ThenByDescending(keySelector, /* comparer */ null); - } - - /// - /// Performs a subsequent ordering of the elements in a sequence in - /// descending order by using a specified comparer. - /// - - public static IOrderedEnumerable ThenByDescending( - this IOrderedEnumerable source, - Func keySelector, - IComparer comparer) - { - if (source == null) throw new ArgumentNullException("source"); - - return source.CreateOrderedEnumerable(keySelector, comparer, /* descending */ true); - } - - /// - /// Base implementation for Intersect and Except operators. - /// - - private static IEnumerable IntersectExceptImpl( - this IEnumerable first, - IEnumerable second, - IEqualityComparer comparer, - bool flag) - { - if (first == null) throw new ArgumentNullException("first"); - if (second == null) throw new ArgumentNullException("second"); - - var keys = new List>(); - var flags = new Dictionary, bool>(new KeyComparer(comparer)); - - foreach (var item in from item in first - select new Key(item) into item - where !flags.ContainsKey(item) - select item) - { - flags.Add(item, !flag); - keys.Add(item); - } - - foreach (var item in from item in second - select new Key(item) into item - where flags.ContainsKey(item) - select item) - { - flags[item] = flag; - } - - // - // As per docs, "the marked elements are yielded in the order in - // which they were collected. - // - - return from item in keys where flags[item] select item.Value; - } - - /// - /// Produces the set intersection of two sequences by using the - /// default equality comparer to compare values. - /// - - public static IEnumerable Intersect( - this IEnumerable first, - IEnumerable second) - { - return first.Intersect(second, /* comparer */ null); - } - - /// - /// Produces the set intersection of two sequences by using the - /// specified to compare values. - /// - - public static IEnumerable Intersect( - this IEnumerable first, - IEnumerable second, - IEqualityComparer comparer) - { - return IntersectExceptImpl(first, second, comparer, /* flag */ true); - } - - /// - /// Produces the set difference of two sequences by using the - /// default equality comparer to compare values. - /// - - public static IEnumerable Except( - this IEnumerable first, - IEnumerable second) - { - return first.Except(second, /* comparer */ null); - } - - /// - /// Produces the set difference of two sequences by using the - /// specified to compare values. - /// - - public static IEnumerable Except( - this IEnumerable first, - IEnumerable second, - IEqualityComparer comparer) - { - return IntersectExceptImpl(first, second, comparer, /* flag */ false); - } - - /// - /// Creates a from an - /// according to a specified key - /// selector function. - /// - - public static Dictionary ToDictionary( - this IEnumerable source, - Func keySelector) - { - return source.ToDictionary(keySelector, /* comparer */ null); - } - - /// - /// Creates a from an - /// according to a specified key - /// selector function and key comparer. - /// - - public static Dictionary ToDictionary( - this IEnumerable source, - Func keySelector, - IEqualityComparer comparer) - { - return source.ToDictionary(keySelector, e => e, comparer); - } - - /// - /// Creates a from an - /// according to specified key - /// selector and element selector functions. - /// - - public static Dictionary ToDictionary( - this IEnumerable source, - Func keySelector, - Func elementSelector) - { - return source.ToDictionary(keySelector, elementSelector, /* comparer */ null); - } - - /// - /// Creates a from an - /// according to a specified key - /// selector function, a comparer, and an element selector function. - /// - - public static Dictionary ToDictionary( - this IEnumerable source, - Func keySelector, - Func elementSelector, - IEqualityComparer comparer) - { - if (source == null) throw new ArgumentNullException("source"); - if (keySelector == null) throw new ArgumentNullException("keySelector"); - if (elementSelector == null) throw new ArgumentNullException("elementSelector"); - - var dict = new Dictionary(comparer); - - foreach (var item in source) - { - // - // ToDictionary is meant to throw ArgumentNullException if - // keySelector produces a key that is null and - // Argument exception if keySelector produces duplicate keys - // for two elements. Incidentally, the doucmentation for - // IDictionary.Add says that the Add method - // throws the same exceptions under the same circumstances - // so we don't need to do any additional checking or work - // here and let the Add implementation do all the heavy - // lifting. - // - - dict.Add(keySelector(item), elementSelector(item)); - } - - return dict; - } - - /// - /// Correlates the elements of two sequences based on matching keys. - /// The default equality comparer is used to compare keys. - /// - - public static IEnumerable Join( - this IEnumerable outer, - IEnumerable inner, - Func outerKeySelector, - Func innerKeySelector, - Func resultSelector) - { - return outer.Join(inner, outerKeySelector, innerKeySelector, resultSelector, /* comparer */ null); - } - - /// - /// Correlates the elements of two sequences based on matching keys. - /// The default equality comparer is used to compare keys. A - /// specified is used to compare keys. - /// - - public static IEnumerable Join( - this IEnumerable outer, - IEnumerable inner, - Func outerKeySelector, - Func innerKeySelector, - Func resultSelector, - IEqualityComparer comparer) - { - if (outer == null) throw new ArgumentNullException("outer"); - if (inner == null) throw new ArgumentNullException("inner"); - if (outerKeySelector == null) throw new ArgumentNullException("outerKeySelector"); - if (innerKeySelector == null) throw new ArgumentNullException("innerKeySelector"); - if (resultSelector == null) throw new ArgumentNullException("resultSelector"); - - var lookup = inner.ToLookup(innerKeySelector, comparer); - - return - from o in outer - from i in lookup[outerKeySelector(o)] - select resultSelector(o, i); - } - - /// - /// Correlates the elements of two sequences based on equality of - /// keys and groups the results. The default equality comparer is - /// used to compare keys. - /// - - public static IEnumerable GroupJoin( - this IEnumerable outer, - IEnumerable inner, - Func outerKeySelector, - Func innerKeySelector, - Func, TResult> resultSelector) - { - return outer.GroupJoin(inner, outerKeySelector, innerKeySelector, resultSelector, /* comparer */ null); - } - - /// - /// Correlates the elements of two sequences based on equality of - /// keys and groups the results. The default equality comparer is - /// used to compare keys. A specified - /// is used to compare keys. - /// - - public static IEnumerable GroupJoin( - this IEnumerable outer, - IEnumerable inner, - Func outerKeySelector, - Func innerKeySelector, - Func, TResult> resultSelector, - IEqualityComparer comparer) - { - if (outer == null) throw new ArgumentNullException("outer"); - if (inner == null) throw new ArgumentNullException("inner"); - if (outerKeySelector == null) throw new ArgumentNullException("outerKeySelector"); - if (innerKeySelector == null) throw new ArgumentNullException("innerKeySelector"); - if (resultSelector == null) throw new ArgumentNullException("resultSelector"); - - var lookup = inner.ToLookup(innerKeySelector, comparer); - return outer.Select(o => resultSelector(o, lookup[outerKeySelector(o)])); - } - - private static class Sequence - { - public static readonly IEnumerable Empty = new T[0]; - } - - private sealed class Grouping : List, IGrouping - { - internal Grouping(K key) - { - Key = key; - } - - public K Key { get; private set; } - } - } -} - -// $Id: Enumerable.g.tt 71137f497bf2 2012/04/16 20:01:27 azizatif $ - -namespace System.Linq -{ - #region Imports - - using System; - using System.Collections.Generic; - - #endregion - - // This partial implementation was template-generated: - // Mon, 16 Apr 2012 20:05:53 GMT - - partial class Enumerable - { - /// - /// Computes the sum of a sequence of nullable values. - /// - - public static int Sum( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - int sum = 0; - foreach (var num in source) - sum = checked(sum + num); - - return sum; - } - - /// - /// Computes the sum of a sequence of nullable - /// values that are obtained by invoking a transform function on - /// each element of the input sequence. - /// - - public static int Sum( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Sum(); - } - - /// - /// Computes the average of a sequence of nullable values. - /// - - public static double Average( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - long sum = 0; - long count = 0; - - foreach (var num in source) - checked - { - sum += (int) num; - count++; - } - - if (count == 0) - throw new InvalidOperationException(); - - return (double) sum / count; - } - - /// - /// Computes the average of a sequence of nullable values - /// that are obtained by invoking a transform function on each - /// element of the input sequence. - /// - - public static double Average( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Average(); - } - - - /// - /// Computes the sum of a sequence of values. - /// - - public static int? Sum( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - int sum = 0; - foreach (var num in source) - sum = checked(sum + (num ?? 0)); - - return sum; - } - - /// - /// Computes the sum of a sequence of - /// values that are obtained by invoking a transform function on - /// each element of the input sequence. - /// - - public static int? Sum( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Sum(); - } - - /// - /// Computes the average of a sequence of values. - /// - - public static double? Average( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - long sum = 0; - long count = 0; - - foreach (var num in source.Where(n => n != null)) - checked - { - sum += (int) num; - count++; - } - - if (count == 0) - return null; - - return (double?) sum / count; - } - - /// - /// Computes the average of a sequence of values - /// that are obtained by invoking a transform function on each - /// element of the input sequence. - /// - - public static double? Average( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Average(); - } - - /// - /// Returns the minimum value in a sequence of nullable - /// values. - /// - - public static int? Min( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - return MinMaxImpl(source.Where(x => x != null), null, (min, x) => min < x); - } - - /// - /// Invokes a transform function on each element of a sequence and - /// returns the minimum nullable value. - /// - - public static int? Min( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Min(); - } - - /// - /// Returns the maximum value in a sequence of nullable - /// values. - /// - - public static int? Max( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - return MinMaxImpl(source.Where(x => x != null), - null, (max, x) => x == null || (max != null && x.Value < max.Value)); - } - - /// - /// Invokes a transform function on each element of a sequence and - /// returns the maximum nullable value. - /// - - public static int? Max( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Max(); - } - - /// - /// Computes the sum of a sequence of nullable values. - /// - - public static long Sum( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - long sum = 0; - foreach (var num in source) - sum = checked(sum + num); - - return sum; - } - - /// - /// Computes the sum of a sequence of nullable - /// values that are obtained by invoking a transform function on - /// each element of the input sequence. - /// - - public static long Sum( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Sum(); - } - - /// - /// Computes the average of a sequence of nullable values. - /// - - public static double Average( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - long sum = 0; - long count = 0; - - foreach (var num in source) - checked - { - sum += (long) num; - count++; - } - - if (count == 0) - throw new InvalidOperationException(); - - return (double) sum / count; - } - - /// - /// Computes the average of a sequence of nullable values - /// that are obtained by invoking a transform function on each - /// element of the input sequence. - /// - - public static double Average( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Average(); - } - - - /// - /// Computes the sum of a sequence of values. - /// - - public static long? Sum( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - long sum = 0; - foreach (var num in source) - sum = checked(sum + (num ?? 0)); - - return sum; - } - - /// - /// Computes the sum of a sequence of - /// values that are obtained by invoking a transform function on - /// each element of the input sequence. - /// - - public static long? Sum( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Sum(); - } - - /// - /// Computes the average of a sequence of values. - /// - - public static double? Average( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - long sum = 0; - long count = 0; - - foreach (var num in source.Where(n => n != null)) - checked - { - sum += (long) num; - count++; - } - - if (count == 0) - return null; - - return (double?) sum / count; - } - - /// - /// Computes the average of a sequence of values - /// that are obtained by invoking a transform function on each - /// element of the input sequence. - /// - - public static double? Average( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Average(); - } - - /// - /// Returns the minimum value in a sequence of nullable - /// values. - /// - - public static long? Min( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - return MinMaxImpl(source.Where(x => x != null), null, (min, x) => min < x); - } - - /// - /// Invokes a transform function on each element of a sequence and - /// returns the minimum nullable value. - /// - - public static long? Min( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Min(); - } - - /// - /// Returns the maximum value in a sequence of nullable - /// values. - /// - - public static long? Max( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - return MinMaxImpl(source.Where(x => x != null), - null, (max, x) => x == null || (max != null && x.Value < max.Value)); - } - - /// - /// Invokes a transform function on each element of a sequence and - /// returns the maximum nullable value. - /// - - public static long? Max( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Max(); - } - - /// - /// Computes the sum of a sequence of nullable values. - /// - - public static float Sum( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - float sum = 0; - foreach (var num in source) - sum = checked(sum + num); - - return sum; - } - - /// - /// Computes the sum of a sequence of nullable - /// values that are obtained by invoking a transform function on - /// each element of the input sequence. - /// - - public static float Sum( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Sum(); - } - - /// - /// Computes the average of a sequence of nullable values. - /// - - public static float Average( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - float sum = 0; - long count = 0; - - foreach (var num in source) - checked - { - sum += (float) num; - count++; - } - - if (count == 0) - throw new InvalidOperationException(); - - return (float) sum / count; - } - - /// - /// Computes the average of a sequence of nullable values - /// that are obtained by invoking a transform function on each - /// element of the input sequence. - /// - - public static float Average( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Average(); - } - - - /// - /// Computes the sum of a sequence of values. - /// - - public static float? Sum( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - float sum = 0; - foreach (var num in source) - sum = checked(sum + (num ?? 0)); - - return sum; - } - - /// - /// Computes the sum of a sequence of - /// values that are obtained by invoking a transform function on - /// each element of the input sequence. - /// - - public static float? Sum( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Sum(); - } - - /// - /// Computes the average of a sequence of values. - /// - - public static float? Average( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - float sum = 0; - long count = 0; - - foreach (var num in source.Where(n => n != null)) - checked - { - sum += (float) num; - count++; - } - - if (count == 0) - return null; - - return (float?) sum / count; - } - - /// - /// Computes the average of a sequence of values - /// that are obtained by invoking a transform function on each - /// element of the input sequence. - /// - - public static float? Average( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Average(); - } - - /// - /// Returns the minimum value in a sequence of nullable - /// values. - /// - - public static float? Min( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - return MinMaxImpl(source.Where(x => x != null), null, (min, x) => min < x); - } - - /// - /// Invokes a transform function on each element of a sequence and - /// returns the minimum nullable value. - /// - - public static float? Min( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Min(); - } - - /// - /// Returns the maximum value in a sequence of nullable - /// values. - /// - - public static float? Max( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - return MinMaxImpl(source.Where(x => x != null), - null, (max, x) => x == null || (max != null && x.Value < max.Value)); - } - - /// - /// Invokes a transform function on each element of a sequence and - /// returns the maximum nullable value. - /// - - public static float? Max( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Max(); - } - - /// - /// Computes the sum of a sequence of nullable values. - /// - - public static double Sum( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - double sum = 0; - foreach (var num in source) - sum = checked(sum + num); - - return sum; - } - - /// - /// Computes the sum of a sequence of nullable - /// values that are obtained by invoking a transform function on - /// each element of the input sequence. - /// - - public static double Sum( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Sum(); - } - - /// - /// Computes the average of a sequence of nullable values. - /// - - public static double Average( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - double sum = 0; - long count = 0; - - foreach (var num in source) - checked - { - sum += (double) num; - count++; - } - - if (count == 0) - throw new InvalidOperationException(); - - return (double) sum / count; - } - - /// - /// Computes the average of a sequence of nullable values - /// that are obtained by invoking a transform function on each - /// element of the input sequence. - /// - - public static double Average( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Average(); - } - - - /// - /// Computes the sum of a sequence of values. - /// - - public static double? Sum( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - double sum = 0; - foreach (var num in source) - sum = checked(sum + (num ?? 0)); - - return sum; - } - - /// - /// Computes the sum of a sequence of - /// values that are obtained by invoking a transform function on - /// each element of the input sequence. - /// - - public static double? Sum( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Sum(); - } - - /// - /// Computes the average of a sequence of values. - /// - - public static double? Average( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - double sum = 0; - long count = 0; - - foreach (var num in source.Where(n => n != null)) - checked - { - sum += (double) num; - count++; - } - - if (count == 0) - return null; - - return (double?) sum / count; - } - - /// - /// Computes the average of a sequence of values - /// that are obtained by invoking a transform function on each - /// element of the input sequence. - /// - - public static double? Average( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Average(); - } - - /// - /// Returns the minimum value in a sequence of nullable - /// values. - /// - - public static double? Min( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - return MinMaxImpl(source.Where(x => x != null), null, (min, x) => min < x); - } - - /// - /// Invokes a transform function on each element of a sequence and - /// returns the minimum nullable value. - /// - - public static double? Min( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Min(); - } - - /// - /// Returns the maximum value in a sequence of nullable - /// values. - /// - - public static double? Max( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - return MinMaxImpl(source.Where(x => x != null), - null, (max, x) => x == null || (max != null && x.Value < max.Value)); - } - - /// - /// Invokes a transform function on each element of a sequence and - /// returns the maximum nullable value. - /// - - public static double? Max( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Max(); - } - - /// - /// Computes the sum of a sequence of nullable values. - /// - - public static decimal Sum( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - decimal sum = 0; - foreach (var num in source) - sum = checked(sum + num); - - return sum; - } - - /// - /// Computes the sum of a sequence of nullable - /// values that are obtained by invoking a transform function on - /// each element of the input sequence. - /// - - public static decimal Sum( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Sum(); - } - - /// - /// Computes the average of a sequence of nullable values. - /// - - public static decimal Average( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - decimal sum = 0; - long count = 0; - - foreach (var num in source) - checked - { - sum += (decimal) num; - count++; - } - - if (count == 0) - throw new InvalidOperationException(); - - return (decimal) sum / count; - } - - /// - /// Computes the average of a sequence of nullable values - /// that are obtained by invoking a transform function on each - /// element of the input sequence. - /// - - public static decimal Average( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Average(); - } - - - /// - /// Computes the sum of a sequence of values. - /// - - public static decimal? Sum( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - decimal sum = 0; - foreach (var num in source) - sum = checked(sum + (num ?? 0)); - - return sum; - } - - /// - /// Computes the sum of a sequence of - /// values that are obtained by invoking a transform function on - /// each element of the input sequence. - /// - - public static decimal? Sum( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Sum(); - } - - /// - /// Computes the average of a sequence of values. - /// - - public static decimal? Average( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - decimal sum = 0; - long count = 0; - - foreach (var num in source.Where(n => n != null)) - checked - { - sum += (decimal) num; - count++; - } - - if (count == 0) - return null; - - return (decimal?) sum / count; - } - - /// - /// Computes the average of a sequence of values - /// that are obtained by invoking a transform function on each - /// element of the input sequence. - /// - - public static decimal? Average( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Average(); - } - - /// - /// Returns the minimum value in a sequence of nullable - /// values. - /// - - public static decimal? Min( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - return MinMaxImpl(source.Where(x => x != null), null, (min, x) => min < x); - } - - /// - /// Invokes a transform function on each element of a sequence and - /// returns the minimum nullable value. - /// - - public static decimal? Min( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Min(); - } - - /// - /// Returns the maximum value in a sequence of nullable - /// values. - /// - - public static decimal? Max( - this IEnumerable source) - { - if (source == null) throw new ArgumentNullException("source"); - - return MinMaxImpl(source.Where(x => x != null), - null, (max, x) => x == null || (max != null && x.Value < max.Value)); - } - - /// - /// Invokes a transform function on each element of a sequence and - /// returns the maximum nullable value. - /// - - public static decimal? Max( - this IEnumerable source, - Func selector) - { - return source.Select(selector).Max(); - } - } -} - -// $Id: ExtensionAttribute.cs 898b3d493ed6 2012/04/17 20:09:57 azizatif $ - -namespace System.Runtime.CompilerServices -{ - /// - /// This attribute allows us to define extension methods without - /// requiring .NET Framework 3.5. For more information, see the section, - /// Extension Methods in .NET Framework 2.0 Apps, - /// of Basic Instincts: Extension Methods - /// column in MSDN Magazine, - /// issue Nov 2007. - /// - - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly)] - sealed partial class ExtensionAttribute : Attribute { } -} - -// $Id: Func.cs 71137f497bf2 2012/04/16 20:01:27 azizatif $ - -namespace System -{ -#if LINQBRIDGE_LIB - public delegate TResult Func(); - public delegate TResult Func(T a); - public delegate TResult Func(T1 arg1, T2 arg2); - public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3); - public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4); -#else - delegate TResult Func(); - delegate TResult Func(T a); - delegate TResult Func(T1 arg1, T2 arg2); - delegate TResult Func(T1 arg1, T2 arg2, T3 arg3); - delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4); -#endif -} - -// $Id: IGrouping.cs 71137f497bf2 2012/04/16 20:01:27 azizatif $ - -namespace System.Linq -{ - #region Imports - - using System.Collections.Generic; - - #endregion - - /// - /// Represents a collection of objects that have a common key. - /// - - partial interface IGrouping : IEnumerable - { - /// - /// Gets the key of the . - /// - - TKey Key { get; } - } -} - -// $Id: ILookup.cs 71137f497bf2 2012/04/16 20:01:27 azizatif $ - -namespace System.Linq -{ - using System.Collections.Generic; - - /// - /// Defines an indexer, size property, and Boolean search method for - /// data structures that map keys to - /// sequences of values. - /// - - partial interface ILookup : IEnumerable> - { - bool Contains(TKey key); - int Count { get; } - IEnumerable this[TKey key] { get; } - } -} - -// $Id: Internal.cs 1567e00f1a20 2012/04/17 16:09:51 azizatif $ - -namespace LinqBridge -{ - #region Imports - - using System; - using System.Collections.Generic; - - #endregion - - /// - /// This type is not intended to be used directly from user code. - /// It may be removed or changed in a future version without notice. - /// - - sealed class DelegatingComparer : IComparer - { - private readonly Func _comparer; - - public DelegatingComparer(Func comparer) - { - if (comparer == null) throw new ArgumentNullException("comparer"); - _comparer = comparer; - } - - public int Compare(T x, T y) { return _comparer(x, y); } - } - - /// - /// This type is not intended to be used directly from user code. - /// It may be removed or changed in a future version without notice. - /// - - struct Key - { - public Key(T value) : this() { Value = value; } - public T Value { get; private set; } - } - - /// - /// This type is not intended to be used directly from user code. - /// It may be removed or changed in a future version without notice. - /// - - sealed class KeyComparer : IEqualityComparer> - { - private readonly IEqualityComparer _innerComparer; - - public KeyComparer(IEqualityComparer innerComparer) - { - _innerComparer = innerComparer ?? EqualityComparer.Default; - } - - public bool Equals(Key x, Key y) - { - return _innerComparer.Equals(x.Value, y.Value); - } - - public int GetHashCode(Key obj) - { - return obj.Value == null ? 0 : _innerComparer.GetHashCode(obj.Value); - } - } -} - -// $Id: IOrderedEnumerable.cs 71137f497bf2 2012/04/16 20:01:27 azizatif $ - -namespace System.Linq -{ - using System.Collections.Generic; - - /// - /// Represents a sorted sequence. - /// - - partial interface IOrderedEnumerable : IEnumerable - { - /// - /// Performs a subsequent ordering on the elements of an - /// according to a key. - /// - - IOrderedEnumerable CreateOrderedEnumerable( - Func keySelector, IComparer comparer, bool descending); - } -} - -// $Id: Lookup.cs c08984d432b1 2012/04/17 16:05:19 azizatif $ - -namespace System.Linq -{ - #region Imports - - using System; - using System.Collections; - using System.Collections.Generic; - using IEnumerable=System.Collections.IEnumerable; - using LinqBridge; - - #endregion - - /// - /// Represents a collection of keys each mapped to one or more values. - /// - - internal sealed class Lookup : ILookup - { - private readonly Dictionary, IGrouping> _map; - private readonly List> _orderedKeys; // remember order of insertion - - internal Lookup(IEqualityComparer comparer) - { - _map = new Dictionary, IGrouping>(new KeyComparer(comparer)); - _orderedKeys = new List>(); - } - - internal void Add(IGrouping item) - { - var key = new Key(item.Key); - _map.Add(key, item); - _orderedKeys.Add(key); - } - - internal IEnumerable Find(TKey key) - { - IGrouping grouping; - return _map.TryGetValue(new Key(key), out grouping) ? grouping : null; - } - - /// - /// Gets the number of key/value collection pairs in the . - /// - - public int Count - { - get { return _map.Count; } - } - - /// - /// Gets the collection of values indexed by the specified key. - /// - - public IEnumerable this[TKey key] - { - get - { - IGrouping result; - return _map.TryGetValue(new Key(key), out result) ? result : Enumerable.Empty(); - } - } - - /// - /// Determines whether a specified key is in the . - /// - - public bool Contains(TKey key) - { - return _map.ContainsKey(new Key(key)); - } - - /// - /// Applies a transform function to each key and its associated - /// values and returns the results. - /// - - public IEnumerable ApplyResultSelector( - Func, TResult> resultSelector) - { - if (resultSelector == null) - throw new ArgumentNullException("resultSelector"); - - foreach (var pair in _map) - yield return resultSelector(pair.Key.Value, pair.Value); - } - - /// - /// Returns a generic enumerator that iterates through the . - /// - - public IEnumerator> GetEnumerator() - { - foreach (var key in _orderedKeys) - yield return _map[key]; - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } -} - -// $Id: OrderedEnumerable.cs 71137f497bf2 2012/04/16 20:01:27 azizatif $ - -namespace LinqBridge -{ - #region Imports - - using System; - using System.Collections; - using System.Collections.Generic; - using System.Diagnostics; - using System.Linq; - - #endregion - - internal sealed class OrderedEnumerable : IOrderedEnumerable - { - private readonly IEnumerable _source; - private readonly Func, IComparer> _comparerComposer; - - public OrderedEnumerable(IEnumerable source, - Func keySelector, IComparer comparer, bool descending) : - this(source, (_, next) => next, keySelector, comparer, descending) {} - - private OrderedEnumerable(IEnumerable source, - Func, IComparer> parent, - Func keySelector, IComparer comparer, bool descending) - { - if (source == null) throw new ArgumentNullException("source"); - if (keySelector == null) throw new ArgumentNullException("keySelector"); - Debug.Assert(parent != null); - - _source = source; - - comparer = comparer ?? Comparer.Default; - var direction = descending ? -1 : 1; - - _comparerComposer = (items, next) => - { - Debug.Assert(items != null); - Debug.Assert(next != null); - - var keys = new K[items.Length]; - for (var i = 0; i < items.Length; i++) - keys[i] = keySelector(items[i]); - - return parent(items, new DelegatingComparer((i, j) => - { - var result = direction * comparer.Compare(keys[i], keys[j]); - return result != 0 ? result : next.Compare(i, j); - })); - }; - } - - public IOrderedEnumerable CreateOrderedEnumerable( - Func keySelector, IComparer comparer, bool descending) - { - return new OrderedEnumerable(_source, _comparerComposer, keySelector, comparer, descending); - } - - public IEnumerator GetEnumerator() - { - // - // Sort using Array.Sort but docs say that it performs an - // unstable sort. LINQ, on the other hand, says OrderBy performs - // a stable sort. Use the item position then as a tie - // breaker when all keys compare equal, thus making the sort - // stable. - // - - var items = _source.ToArray(); - var positionComparer = new DelegatingComparer((i, j) => i.CompareTo(j)); - var comparer = _comparerComposer(items, positionComparer); - var keys = new int[items.Length]; - for (var i = 0; i < keys.Length; i++) - keys[i] = i; - Array.Sort(keys, items, comparer); - return ((IEnumerable) items).GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - } -} - -// $Id: Action.cs 71137f497bf2 2012/04/16 20:01:27 azizatif $ - -namespace System -{ -#if LINQBRIDGE_LIB - public delegate void Action(); - public delegate void Action(T1 arg1, T2 arg2); - public delegate void Action(T1 arg1, T2 arg2, T3 arg3); - public delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4); -#else - delegate void Action(); - delegate void Action(T1 arg1, T2 arg2); - delegate void Action(T1 arg1, T2 arg2, T3 arg3); - delegate void Action(T1 arg1, T2 arg2, T3 arg3, T4 arg4); -#endif -} - diff --git a/Saleslogix.SData.Client/LinqToXml/Extensions.cs b/Saleslogix.SData.Client/LinqToXml/Extensions.cs deleted file mode 100644 index 5ef37901..00000000 --- a/Saleslogix.SData.Client/LinqToXml/Extensions.cs +++ /dev/null @@ -1,176 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace System.Xml.Linq -{ - internal static class Extensions - { - public static IEnumerable Ancestors (this IEnumerable source) where T : XNode - { - foreach (T item in source) - for (XElement n = item.Parent as XElement; n != null; n = n.Parent as XElement) - yield return n; - } - - public static IEnumerable Ancestors (this IEnumerable source, XName name) where T : XNode - { - foreach (T item in source) - for (XElement n = item.Parent as XElement; n != null; n = n.Parent as XElement) - if (n.Name == name) - yield return n; - } - - public static IEnumerable AncestorsAndSelf (this IEnumerable source) - { - foreach (XElement item in source) - for (XElement n = item as XElement; n != null; n = n.Parent as XElement) - yield return n; - } - - public static IEnumerable AncestorsAndSelf (this IEnumerable source, XName name) - { - foreach (XElement item in source) - for (XElement n = item as XElement; n != null; n = n.Parent as XElement) - if (n.Name == name) - yield return n; - } - - public static IEnumerable Attributes (this IEnumerable source) - { - foreach (XElement item in source) - foreach (XAttribute attr in item.Attributes ()) - yield return attr; - } - - public static IEnumerable Attributes (this IEnumerable source, XName name) - { - foreach (XElement item in source) - foreach (XAttribute attr in item.Attributes (name)) - yield return attr; - } - - public static IEnumerable DescendantNodes ( - this IEnumerable source) where T : XContainer - { - foreach (XContainer item in source) - foreach (XNode n in item.DescendantNodes ()) - yield return n; - } - - public static IEnumerable DescendantNodesAndSelf ( - this IEnumerable source) - { - foreach (XElement item in source) - foreach (XNode n in item.DescendantNodesAndSelf ()) - yield return n; - } - - public static IEnumerable Descendants ( - this IEnumerable source) where T : XContainer - { - foreach (XContainer item in source) - foreach (XElement n in item.Descendants ()) - yield return n; - } - - public static IEnumerable Descendants ( - this IEnumerable source, XName name) where T : XContainer - { - foreach (XContainer item in source) - foreach (XElement n in item.Descendants (name)) - yield return n; - } - - public static IEnumerable DescendantsAndSelf ( - this IEnumerable source) - { - foreach (XElement item in source) - foreach (XElement n in item.DescendantsAndSelf ()) - yield return n; - } - - public static IEnumerable DescendantsAndSelf ( - this IEnumerable source, XName name) - { - foreach (XElement item in source) - foreach (XElement n in item.DescendantsAndSelf (name)) - yield return n; - } - - public static IEnumerable Elements ( - this IEnumerable source) where T : XContainer - { - foreach (XContainer item in source) - foreach (XElement n in item.Elements ()) - yield return n; - } - - public static IEnumerable Elements ( - this IEnumerable source, XName name) where T : XContainer - { - foreach (XContainer item in source) - foreach (XElement n in item.Elements (name)) - yield return n; - } - - public static IEnumerable InDocumentOrder ( - this IEnumerable source) where T : XNode - { - List list = new List (); - foreach (XNode n in source) - list.Add (n); - list.Sort (XNode.DocumentOrderComparer); - foreach (T n in list) - yield return n; - } - - public static IEnumerable Nodes ( - this IEnumerable source) where T : XContainer - { - foreach (XContainer item in source) - foreach (XNode n in item.Nodes ()) - yield return n; - } - - public static void Remove (this IEnumerable source) - { - foreach (XAttribute item in source) - item.Remove (); - } - - public static void Remove (this IEnumerable source) where T : XNode - { - var l = new List (source); - foreach (T item in l) - item.Remove (); - } - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/LoadOptions.cs b/Saleslogix.SData.Client/LinqToXml/LoadOptions.cs deleted file mode 100644 index d5e0d6aa..00000000 --- a/Saleslogix.SData.Client/LinqToXml/LoadOptions.cs +++ /dev/null @@ -1,39 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace System.Xml.Linq -{ - [Flags] - internal enum LoadOptions - { - None = 0, - PreserveWhitespace = 1, - SetBaseUri = 2, - SetLineInfo = 4, - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/SaveOptions.cs b/Saleslogix.SData.Client/LinqToXml/SaveOptions.cs deleted file mode 100644 index be089d6b..00000000 --- a/Saleslogix.SData.Client/LinqToXml/SaveOptions.cs +++ /dev/null @@ -1,40 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; - -namespace System.Xml.Linq -{ - [Flags] - internal enum SaveOptions - { - None = 0, - DisableFormatting = 1, -#if NET_4_0 - OmitDuplicateNamespaces = 2 -#endif - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/XAttribute.cs b/Saleslogix.SData.Client/LinqToXml/XAttribute.cs deleted file mode 100644 index 873a2ad0..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XAttribute.cs +++ /dev/null @@ -1,344 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; -using System.Text; -using System.Xml; - -namespace System.Xml.Linq -{ - internal class XAttribute : XObject - { - static readonly XAttribute [] empty_array = new XAttribute [0]; - - public static IEnumerable EmptySequence { - get { return empty_array; } - } - - XName name; - string value; - XAttribute next; - XAttribute previous; - - public XAttribute (XAttribute other) - { - if (other == null) - throw new ArgumentNullException ("other"); - name = other.name; - value = other.value; - } - - public XAttribute (XName name, object value) - { - if (name == null) - throw new ArgumentNullException ("name"); - this.name = name; - SetValue (value); - } - - public static explicit operator bool (XAttribute attribute) - { - if (attribute == null) - throw new ArgumentNullException ("attribute"); - return XUtil.ConvertToBoolean (attribute.value); - } - - public static explicit operator bool? (XAttribute attribute) - { - if (attribute == null) - return null; - - return attribute.value == null ? (bool?) null : XUtil.ConvertToBoolean (attribute.value); - } - - public static explicit operator DateTime (XAttribute attribute) - { - if (attribute == null) - throw new ArgumentNullException ("attribute"); - return XUtil.ToDateTime (attribute.value); - } - - public static explicit operator DateTime? (XAttribute attribute) - { - if (attribute == null) - return null; - - return attribute.value == null ? (DateTime?) null : XUtil.ToDateTime (attribute.value); - } - -#if !TARGET_JVM // Same as for System.Xml.XmlConvert.ToDateTimeOffset - - public static explicit operator DateTimeOffset (XAttribute attribute) - { - if (attribute == null) - throw new ArgumentNullException ("attribute"); - return XmlConvert.ToDateTimeOffset (attribute.value); - } - - public static explicit operator DateTimeOffset? (XAttribute attribute) - { - if (attribute == null) - return null; - - return attribute.value == null ? (DateTimeOffset?) null : XmlConvert.ToDateTimeOffset (attribute.value); - } - -#endif - - public static explicit operator decimal (XAttribute attribute) - { - if (attribute == null) - throw new ArgumentNullException ("attribute"); - return XmlConvert.ToDecimal (attribute.value); - } - - public static explicit operator decimal? (XAttribute attribute) - { - if (attribute == null) - return null; - - return attribute.value == null ? (decimal?) null : XmlConvert.ToDecimal (attribute.value); - } - - public static explicit operator double (XAttribute attribute) - { - if (attribute == null) - throw new ArgumentNullException ("attribute"); - return XmlConvert.ToDouble (attribute.value); - } - - public static explicit operator double? (XAttribute attribute) - { - if (attribute == null) - return null; - - return attribute.value == null ? (double?) null : XmlConvert.ToDouble (attribute.value); - } - - public static explicit operator float (XAttribute attribute) - { - if (attribute == null) - throw new ArgumentNullException ("attribute"); - return XmlConvert.ToSingle (attribute.value); - } - - public static explicit operator float? (XAttribute attribute) - { - if (attribute == null) - return null; - - return attribute.value == null ? (float?) null : XmlConvert.ToSingle (attribute.value); - } - - public static explicit operator Guid (XAttribute attribute) - { - if (attribute == null) - throw new ArgumentNullException ("attribute"); - return XmlConvert.ToGuid (attribute.value); - } - - public static explicit operator Guid? (XAttribute attribute) - { - if (attribute == null) - return null; - - return attribute.value == null ? (Guid?) null : XmlConvert.ToGuid (attribute.value); - } - - public static explicit operator int (XAttribute attribute) - { - if (attribute == null) - throw new ArgumentNullException ("attribute"); - return XmlConvert.ToInt32 (attribute.value); - } - - public static explicit operator int? (XAttribute attribute) - { - if (attribute == null) - return null; - - return attribute.value == null ? (int?) null : XmlConvert.ToInt32 (attribute.value); - } - - public static explicit operator long (XAttribute attribute) - { - if (attribute == null) - throw new ArgumentNullException ("attribute"); - return XmlConvert.ToInt64 (attribute.value); - } - - public static explicit operator long? (XAttribute attribute) - { - if (attribute == null) - return null; - - return attribute.value == null ? (long?) null : XmlConvert.ToInt64 (attribute.value); - } - - public static explicit operator uint (XAttribute attribute) - { - if (attribute == null) - throw new ArgumentNullException ("attribute"); - return XmlConvert.ToUInt32 (attribute.value); - } - - public static explicit operator uint? (XAttribute attribute) - { - if (attribute == null) - return null; - - return attribute.value == null ? (uint?) null : XmlConvert.ToUInt32 (attribute.value); - } - - public static explicit operator ulong (XAttribute attribute) - { - if (attribute == null) - throw new ArgumentNullException ("attribute"); - return XmlConvert.ToUInt64 (attribute.value); - } - - public static explicit operator ulong? (XAttribute attribute) - { - if (attribute == null) - return null; - - return attribute.value == null ? (ulong?) null : XmlConvert.ToUInt64 (attribute.value); - } - - public static explicit operator TimeSpan (XAttribute attribute) - { - if (attribute == null) - throw new ArgumentNullException ("attribute"); - return XmlConvert.ToTimeSpan (attribute.value); - } - - public static explicit operator TimeSpan? (XAttribute attribute) - { - if (attribute == null) - return null; - - return attribute.value == null ? (TimeSpan?) null : XmlConvert.ToTimeSpan (attribute.value); - } - - public static explicit operator string (XAttribute attribute) - { - if (attribute == null) - return null; - - return attribute.value; - } - - public bool IsNamespaceDeclaration { - get { return name.Namespace == XNamespace.Xmlns || (name.LocalName == "xmlns" && name.Namespace == XNamespace.None); } - } - - public XName Name { - get { return name; } - } - - public XAttribute NextAttribute { - get { return next; } - internal set { next = value; } - } - - public override XmlNodeType NodeType { - get { return XmlNodeType.Attribute; } - } - - public XAttribute PreviousAttribute { - get { return previous; } - internal set { previous = value; } - } - - public string Value { - get { return XUtil.ToString (value); } - set { SetValue (value); } - } - - public void Remove () - { - if (Parent != null) { - var owner = Owner; - owner.OnRemovingObject (this); - if (next != null) - next.previous = previous; - if (previous != null) - previous.next = next; - if (Parent.FirstAttribute == this) - Parent.FirstAttribute = next; - if (Parent.LastAttribute == this) - Parent.LastAttribute = previous; - SetOwner (null); - owner.OnRemovedObject (this); - } - next = null; - previous = null; - } - - public void SetValue (object value) - { - if (value == null) - throw new ArgumentNullException ("value"); - - OnValueChanging (this); - this.value = XUtil.ToString (value); - OnValueChanged (this); - } - - static readonly char [] escapeChars = new char [] {'<', '>', '&', '"', '\r', '\n', '\t'}; - - public override string ToString () - { - StringBuilder sb = new StringBuilder (); - sb.Append (name.ToString ()); - sb.Append ("=\""); - int start = 0; - do { - int idx = value.IndexOfAny (escapeChars, start); - if (idx < 0) { - if (start > 0) - sb.Append (value, start, value.Length - start); - else - sb.Append (value); - sb.Append ("\""); - return sb.ToString (); - } - sb.Append (value, start, idx - start); - switch (value [idx]) { - case '&': sb.Append ("&"); break; - case '<': sb.Append ("<"); break; - case '>': sb.Append (">"); break; - case '"': sb.Append ("""); break; - case '\r': sb.Append (" "); break; - case '\n': sb.Append (" "); break; - case '\t': sb.Append (" "); break; - } - start = idx + 1; - } while (true); - } - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/XCData.cs b/Saleslogix.SData.Client/LinqToXml/XCData.cs deleted file mode 100644 index db63ee52..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XCData.cs +++ /dev/null @@ -1,71 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Text; -using System.Xml; - -namespace System.Xml.Linq -{ - internal class XCData : XText - { - public XCData (string value) - : base (value) - { - } - - public XCData (XCData other) - : base (other) - { - } - - public override XmlNodeType NodeType { - get { return XmlNodeType.CDATA; } - } - - public override void WriteTo (XmlWriter writer) - { - int start = 0; - StringBuilder sb = null; - for (int i = 0; i < Value.Length - 2; i++) { - if (Value [i] == ']' && Value [i + 1] == ']' - && Value [i + 2] == '>') { - if (sb == null) - sb = new StringBuilder (); - sb.Append (Value, start, i - start); - sb.Append ("]]>"); - start = i + 3; - } - } - if (start != 0 && start != Value.Length) - sb.Append (Value, start, Value.Length - start); - writer.WriteCData (sb == null ? Value : sb.ToString ()); - } - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/XComment.cs b/Saleslogix.SData.Client/LinqToXml/XComment.cs deleted file mode 100644 index 6d8c0649..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XComment.cs +++ /dev/null @@ -1,60 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Xml; - -namespace System.Xml.Linq -{ - internal class XComment : XNode - { - string value; - - public XComment (string value) - { - this.value = value; - } - - public XComment (XComment other) - { - this.value = other.value; - } - - public override XmlNodeType NodeType { - get { return XmlNodeType.Comment; } - } - - public string Value { - get { return value; } - set { this.value = value; } - } - - public override void WriteTo (XmlWriter writer) - { - writer.WriteComment (value); - } - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/XContainer.cs b/Saleslogix.SData.Client/LinqToXml/XContainer.cs deleted file mode 100644 index 67878cba..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XContainer.cs +++ /dev/null @@ -1,235 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Text; -using System.Xml; - -namespace System.Xml.Linq -{ - internal abstract class XContainer : XNode - { - internal XContainer () - { - } - - XNode first; - XNode last; - - public XNode FirstNode { - get { return first; } - internal set { first = value; } - } - - public XNode LastNode { - get { return last; } - internal set { last = value; } - } - - void CheckChildType (object o, bool addFirst) - { - if (o == null || o is string || o is XNode) - return; - if (o is IEnumerable) { - foreach (object oc in ((IEnumerable) o)) - CheckChildType (oc, addFirst); - return; - } - else - throw new ArgumentException ("Invalid child type: " + o.GetType ()); - } - - public void Add (object content) - { - if (content == null) - return; - - foreach (object o in XUtil.ExpandArray (content)) - { - if (!OnAddingObject (o, false, last, false)) - { - var node = XUtil.ToNode (o); - OnAddingObject (node); - AddNode (node); - OnAddedObject (node); - } - } - } - - void AddNode (XNode n) - { - CheckChildType (n, false); - n = (XNode) XUtil.GetDetachedObject (n); - n.SetOwner (this); - if (first == null) - last = first = n; - else { - last.NextNode = n; - n.PreviousNode = last; - last = n; - } - } - - public void Add (params object [] content) - { - if (content == null) - return; - foreach (object o in XUtil.ExpandArray (content)) - Add (o); - } - - public void AddFirst (object content) - { - if (first == null) - Add (content); - else - first.AddBeforeSelf (XUtil.ExpandArray (content)); - } - - public void AddFirst (params object [] content) - { - if (content == null) - return; - if (first == null) - Add (content); - else - foreach (object o in XUtil.ExpandArray (content)) - if (!OnAddingObject (o, false, first.PreviousNode, true)) - first.AddBeforeSelf (o); - } - - internal virtual bool OnAddingObject (object o, bool rejectAttribute, XNode refNode, bool addFirst) - { - return false; - } - - public XmlWriter CreateWriter () - { - return new XNodeWriter (this); - } - - public IEnumerable Nodes () - { - XNode next; - for (XNode n = FirstNode; n != null; n = next) { - next = n.NextNode; - yield return n; - } - } - - public IEnumerable DescendantNodes () - { - foreach (XNode n in Nodes ()) { - yield return n; - XContainer c = n as XContainer; - if (c != null) - foreach (XNode d in c.DescendantNodes ()) - yield return d; - } - } - - public IEnumerable Descendants () - { - foreach (XNode n in DescendantNodes ()) { - XElement el = n as XElement; - if (el != null) - yield return el; - } - } - - public IEnumerable Descendants (XName name) - { - foreach (XElement el in Descendants ()) - if (el.Name == name) - yield return el; - } - - public IEnumerable Elements () - { - foreach (XNode n in Nodes ()) { - XElement el = n as XElement; - if (el != null) - yield return el; - } - } - - public IEnumerable Elements (XName name) - { - foreach (XElement el in Elements ()) - if (el.Name == name) - yield return el; - } - - public XElement Element (XName name) - { - foreach (XElement el in Elements ()) - if (el.Name == name) - return el; - return null; - } - - internal void ReadContentFrom (XmlReader reader, LoadOptions options) - { - while (!reader.EOF) { - if (reader.NodeType == XmlNodeType.EndElement) - // end of the element. - break; - Add (XNode.ReadFrom (reader, options)); - } - } - - public void RemoveNodes () - { - foreach (XNode n in Nodes ()) - n.Remove (); - } - - public void ReplaceNodes (object content) - { - // First, it creates a snapshot copy, then removes the contents, and then adds the copy. http://msdn.microsoft.com/en-us/library/system.xml.linq.xcontainer.replacenodes.aspx - - if (FirstNode == null) { - Add (content); - return; - } - - var l = new List (); - foreach (var obj in XUtil.ExpandArray (content)) - l.Add (obj); - - RemoveNodes (); - Add (l); - } - - public void ReplaceNodes (params object [] content) - { - ReplaceNodes ((object) content); - } - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/XDeclaration.cs b/Saleslogix.SData.Client/LinqToXml/XDeclaration.cs deleted file mode 100644 index 88b9af22..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XDeclaration.cs +++ /dev/null @@ -1,101 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Text; -using System.Xml; - -namespace System.Xml.Linq -{ - internal class XDeclaration - { - string encoding, standalone, version; - - public XDeclaration (string version, string encoding, string standalone) - { - this.version = version; - this.encoding = encoding; - this.standalone = standalone; - } - - public XDeclaration (XDeclaration other) - { - if (other == null) - throw new ArgumentNullException ("other"); - this.version = other.version; - this.encoding = other.encoding; - this.standalone = other.standalone; - } - - public string Encoding { - get { return encoding; } - set { encoding = value; } - } - - public string Standalone { - get { return standalone; } - set { standalone = value; } - } - - public string Version { - get { return version; } - set { version = value; } - } - - public override string ToString () - { - return String.Concat (""); - } - - /* - public override void WriteTo (XmlWriter w) - { - StringBuilder sb = new StringBuilder (); - sb.AppendFormat ("version=\"{0}\"", version); - if (encoding != null) - sb.AppendFormat (" encoding=\"{0}\"", encoding); - if (standalone != null) - sb.AppendFormat (" standalone=\"{0}\"", standalone); - // "xml" is not allowed PI, but because of nasty - // XmlWriter API design it must pass. - w.WriteProcessingInstruction ("xml", sb.ToString ()); - } - */ - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/XDocument.cs b/Saleslogix.SData.Client/LinqToXml/XDocument.cs deleted file mode 100644 index 7a1c52af..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XDocument.cs +++ /dev/null @@ -1,292 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Text; -using System.Xml; -using System.Xml.Schema; -using System.Xml.Serialization; - -namespace System.Xml.Linq -{ - internal class XDocument : XContainer - { - XDeclaration xmldecl; - - public XDocument () - { - } - - public XDocument (params object [] content) - { - Add (content); - } - - public XDocument (XDeclaration declaration, params object [] content) - { - Declaration = declaration; - Add (content); - } - - public XDocument (XDocument other) - { - foreach (object o in other.Nodes ()) - Add (XUtil.Clone (o)); - } - - public XDeclaration Declaration { - get { return xmldecl; } - set { xmldecl = value; } - } - - public XDocumentType DocumentType { - get { - foreach (object o in Nodes ()) - if (o is XDocumentType) - return (XDocumentType) o; - return null; - } - } - - public override XmlNodeType NodeType { - get { return XmlNodeType.Document; } - } - - public XElement Root { - get { - foreach (object o in Nodes ()) - if (o is XElement) - return (XElement) o; - return null; - } - } - - public static XDocument Load (string uri) - { - return Load (uri, LoadOptions.None); - } - - public static XDocument Load (string uri, LoadOptions options) - { - XmlReaderSettings s = new XmlReaderSettings (); - s.ProhibitDtd = false; // see XNodeNavigatorTest.MoveToId(). - s.IgnoreWhitespace = (options & LoadOptions.PreserveWhitespace) == 0; - using (XmlReader r = XmlReader.Create (uri, s)) { - return LoadCore (r, options); - } - } - - public static XDocument Load (Stream stream) - { - return Load (new StreamReader (stream), LoadOptions.None); - } - - public static XDocument Load (Stream stream, LoadOptions options) - { - return Load (new StreamReader (stream), options); - } - - public static XDocument Load (TextReader textReader) - { - return Load (textReader, LoadOptions.None); - } - - public static XDocument Load (TextReader textReader, LoadOptions options) - { - XmlReaderSettings s = new XmlReaderSettings (); - s.ProhibitDtd = false; // see XNodeNavigatorTest.MoveToId(). - s.IgnoreWhitespace = (options & LoadOptions.PreserveWhitespace) == 0; - using (XmlReader r = XmlReader.Create (textReader, s)) { - return LoadCore (r, options); - } - } - - public static XDocument Load (XmlReader reader) - { - return Load (reader, LoadOptions.None); - } - - public static XDocument Load (XmlReader reader, LoadOptions options) - { - XmlReaderSettings s = reader.Settings != null ? reader.Settings.Clone () : new XmlReaderSettings (); - s.IgnoreWhitespace = (options & LoadOptions.PreserveWhitespace) == 0; - using (XmlReader r = XmlReader.Create (reader, s)) { - return LoadCore (r, options); - } - } - - static XDocument LoadCore (XmlReader reader, LoadOptions options) - { - XDocument doc = new XDocument (); - doc.ReadContent (reader, options); - return doc; - } - - void ReadContent (XmlReader reader, LoadOptions options) - { - if (reader.ReadState == ReadState.Initial) - reader.Read (); - this.FillLineInfoAndBaseUri (reader, options); - if (reader.NodeType == XmlNodeType.XmlDeclaration) { - Declaration = new XDeclaration ( - reader.GetAttribute ("version"), - reader.GetAttribute ("encoding"), - reader.GetAttribute ("standalone")); - reader.Read (); - } - ReadContentFrom (reader, options); - if (Root == null) - throw new InvalidOperationException ("The document element is missing."); - } - - static void ValidateWhitespace (string s) - { - for (int i = 0; i < s.Length; i++) - switch (s [i]) { - case ' ': case '\t': case '\n': case '\r': - continue; - default: - throw new ArgumentException ("Non-whitespace text appears directly in the document."); - } - } - - public static XDocument Parse (string text) - { - return Parse (text, LoadOptions.None); - } - - public static XDocument Parse (string text, LoadOptions options) - { - return Load (new StringReader (text), options); - } - - public void Save (string fileName) - { - Save (fileName, SaveOptions.None); - } - - public void Save (string fileName, SaveOptions options) - { - XmlWriterSettings s = new XmlWriterSettings (); - if ((options & SaveOptions.DisableFormatting) == SaveOptions.None) - s.Indent = true; -#if NET_4_0 - if ((options & SaveOptions.OmitDuplicateNamespaces) == SaveOptions.OmitDuplicateNamespaces) - s.NamespaceHandling |= NamespaceHandling.OmitDuplicates; -#endif - - using (XmlWriter w = XmlWriter.Create (fileName, s)) { - Save (w); - } - } - - public void Save (TextWriter textWriter) - { - Save (textWriter, SaveOptions.None); - } - - public void Save (TextWriter textWriter, SaveOptions options) - { - XmlWriterSettings s = new XmlWriterSettings (); - if ((options & SaveOptions.DisableFormatting) == SaveOptions.None) - s.Indent = true; -#if NET_4_0 - if ((options & SaveOptions.OmitDuplicateNamespaces) == SaveOptions.OmitDuplicateNamespaces) - s.NamespaceHandling |= NamespaceHandling.OmitDuplicates; -#endif - using (XmlWriter w = XmlWriter.Create (textWriter, s)) { - Save (w); - } - } - - public void Save (XmlWriter writer) - { - WriteTo (writer); - } - - public override void WriteTo (XmlWriter writer) - { - if (xmldecl != null && xmldecl.Standalone != null) - writer.WriteStartDocument (xmldecl.Standalone == "yes"); - else - writer.WriteStartDocument (); - foreach (XNode node in Nodes ()) - node.WriteTo (writer); - } - - internal override bool OnAddingObject (object obj, bool rejectAttribute, XNode refNode, bool addFirst) - { - VerifyAddedNode (obj, addFirst); - return false; - } - - void VerifyAddedNode (object node, bool addFirst) - { - if (node == null) - throw new InvalidOperationException ("Only a node is allowed here"); - - if (node is string) - ValidateWhitespace ((string) node); - if (node is XText) - ValidateWhitespace (((XText) node).Value); - else if (node is XDocumentType) { - if (DocumentType != null) - throw new InvalidOperationException ("There already is another document type declaration"); - if (Root != null && !addFirst) - throw new InvalidOperationException ("A document type cannot be added after the document element"); - } - else if (node is XElement) { - if (Root != null) - throw new InvalidOperationException ("There already is another document element"); - if (DocumentType != null && addFirst) - throw new InvalidOperationException ("An element cannot be added before the document type declaration"); - } - } -#if NET_4_0 - public void Save (Stream stream) - { - Save (stream, SaveOptions.None); - } - - public void Save (Stream stream, SaveOptions options) - { - XmlWriterSettings s = new XmlWriterSettings (); - if ((options & SaveOptions.DisableFormatting) == SaveOptions.None) - s.Indent = true; - if ((options & SaveOptions.OmitDuplicateNamespaces) == SaveOptions.OmitDuplicateNamespaces) - s.NamespaceHandling |= NamespaceHandling.OmitDuplicates; - - using (var writer = XmlWriter.Create (stream, s)){ - Save (writer); - } - } - -#endif - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/XDocumentType.cs b/Saleslogix.SData.Client/LinqToXml/XDocumentType.cs deleted file mode 100644 index 0fda050f..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XDocumentType.cs +++ /dev/null @@ -1,106 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Text; -using System.Xml; - -namespace System.Xml.Linq -{ - internal class XDocumentType : XNode - { - string name, pubid, sysid, intSubset; - - public XDocumentType (string name, string publicId, string systemId, string internalSubset) - { - this.name = name; - pubid = publicId; - sysid = systemId; - intSubset = internalSubset; - } - - public XDocumentType (XDocumentType other) - { - if (other == null) - throw new ArgumentNullException ("other"); - name = other.name; - pubid = other.pubid; - sysid = other.sysid; - intSubset = other.intSubset; - } - - public string Name { - get { return name; } - set { - if (value == null) - throw new ArgumentNullException ("value"); - name = value; - } - } - - public string PublicId { - get { return pubid; } - set { - if (value == null) - throw new ArgumentNullException ("value"); - pubid = value; - } - } - - public string SystemId { - get { return sysid; } - set { - if (value == null) - throw new ArgumentNullException ("value"); - sysid = value; - } - } - - public string InternalSubset { - get { return intSubset; } - set { - if (value == null) - throw new ArgumentNullException ("value"); - intSubset = value; - } - } - - public override XmlNodeType NodeType { - get { return XmlNodeType.DocumentType; } - } - - public override void WriteTo (XmlWriter writer) - { - XDocument doc = Document; - XElement root = doc.Root; - if (root != null) - writer.WriteDocType (root.Name.LocalName, pubid, sysid, intSubset); - } - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/XElement.cs b/Saleslogix.SData.Client/LinqToXml/XElement.cs deleted file mode 100644 index fe846769..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XElement.cs +++ /dev/null @@ -1,818 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Xml; -using System.Xml.Schema; -using System.Xml.Serialization; - -namespace System.Xml.Linq -{ - [XmlSchemaProvider (null, IsAny = true)] - internal class XElement : XContainer, IXmlSerializable - { - static IEnumerable emptySequence = - new List (); - - public static IEnumerable EmptySequence { - get { return emptySequence; } - } - - XName name; - XAttribute attr_first, attr_last; - bool explicit_is_empty = true; - - public XElement (XName name, object content) - { - if (name == null) - throw new ArgumentNullException ("name"); - this.name = name; - Add (content); - } - - public XElement (XElement other) - { - if (other == null) - throw new ArgumentNullException ("other"); - name = other.name; - Add (other.Attributes ()); - Add (other.Nodes ()); - } - - public XElement (XName name) - { - if (name == null) - throw new ArgumentNullException ("name"); - this.name = name; - } - - public XElement (XName name, params object [] content) - { - if (name == null) - throw new ArgumentNullException ("name"); - this.name = name; - Add (content); - } - - public XElement (XStreamingElement other) - { - if (other == null) - throw new ArgumentNullException ("other"); - this.name = other.Name; - Add (other.Contents); - } - - public static explicit operator bool (XElement element) - { - if (element == null) - throw new ArgumentNullException ("element"); - return XUtil.ConvertToBoolean (element.Value); - } - - public static explicit operator bool? (XElement element) - { - if (element == null) - return null; - - return element.Value == null ? (bool?) null : XUtil.ConvertToBoolean (element.Value); - } - - public static explicit operator DateTime (XElement element) - { - if (element == null) - throw new ArgumentNullException ("element"); - return XUtil.ToDateTime (element.Value); - } - - public static explicit operator DateTime? (XElement element) - { - if (element == null) - return null; - - return element.Value == null ? (DateTime?) null : XUtil.ToDateTime (element.Value); - } - -#if !TARGET_JVM // Same as for System.Xml.XmlConvert.ToDateTimeOffset - - public static explicit operator DateTimeOffset (XElement element) - { - if (element == null) - throw new ArgumentNullException ("element"); - return XmlConvert.ToDateTimeOffset (element.Value); - } - - public static explicit operator DateTimeOffset? (XElement element) - { - if (element == null) - return null; - - return element.Value == null ? (DateTimeOffset?) null : XmlConvert.ToDateTimeOffset (element.Value); - } - -#endif - - public static explicit operator decimal (XElement element) - { - if (element == null) - throw new ArgumentNullException ("element"); - return XmlConvert.ToDecimal (element.Value); - } - - public static explicit operator decimal? (XElement element) - { - if (element == null) - return null; - - return element.Value == null ? (decimal?) null : XmlConvert.ToDecimal (element.Value); - } - - public static explicit operator double (XElement element) - { - if (element == null) - throw new ArgumentNullException ("element"); - return XmlConvert.ToDouble (element.Value); - } - - public static explicit operator double? (XElement element) - { - if (element == null) - return null; - - return element.Value == null ? (double?) null : XmlConvert.ToDouble (element.Value); - } - - public static explicit operator float (XElement element) - { - if (element == null) - throw new ArgumentNullException ("element"); - return XmlConvert.ToSingle (element.Value); - } - - public static explicit operator float? (XElement element) - { - if (element == null) - return null; - - return element.Value == null ? (float?) null : XmlConvert.ToSingle (element.Value); - } - - public static explicit operator Guid (XElement element) - { - if (element == null) - throw new ArgumentNullException ("element"); - return XmlConvert.ToGuid (element.Value); - } - - public static explicit operator Guid? (XElement element) - { - if (element == null) - return null; - - return element.Value == null ? (Guid?) null : XmlConvert.ToGuid (element.Value); - } - - public static explicit operator int (XElement element) - { - if (element == null) - throw new ArgumentNullException ("element"); - return XmlConvert.ToInt32 (element.Value); - } - - public static explicit operator int? (XElement element) - { - if (element == null) - return null; - - return element.Value == null ? (int?) null : XmlConvert.ToInt32 (element.Value); - } - - public static explicit operator long (XElement element) - { - if (element == null) - throw new ArgumentNullException ("element"); - return XmlConvert.ToInt64 (element.Value); - } - - public static explicit operator long? (XElement element) - { - if (element == null) - return null; - - return element.Value == null ? (long?) null : XmlConvert.ToInt64 (element.Value); - } - - public static explicit operator uint (XElement element) - { - if (element == null) - throw new ArgumentNullException ("element"); - return XmlConvert.ToUInt32 (element.Value); - } - - public static explicit operator uint? (XElement element) - { - if (element == null) - return null; - - return element.Value == null ? (uint?) null : XmlConvert.ToUInt32 (element.Value); - } - - public static explicit operator ulong (XElement element) - { - if (element == null) - throw new ArgumentNullException ("element"); - return XmlConvert.ToUInt64 (element.Value); - } - - public static explicit operator ulong? (XElement element) - { - if (element == null) - return null; - - return element.Value == null ? (ulong?) null : XmlConvert.ToUInt64 (element.Value); - } - - public static explicit operator TimeSpan (XElement element) - { - if (element == null) - throw new ArgumentNullException ("element"); - return XmlConvert.ToTimeSpan (element.Value); - } - - public static explicit operator TimeSpan? (XElement element) - { - if (element == null) - return null; - - return element.Value == null ? (TimeSpan?) null : XmlConvert.ToTimeSpan (element.Value); - } - - public static explicit operator string (XElement element) - { - if (element == null) - return null; - - return element.Value; - } - - public XAttribute FirstAttribute { - get { return attr_first; } - internal set { attr_first = value; } - } - - public XAttribute LastAttribute { - get { return attr_last; } - internal set { attr_last = value; } - } - - public bool HasAttributes { - get { return attr_first != null; } - } - - public bool HasElements { - get { - foreach (object o in Nodes ()) - if (o is XElement) - return true; - return false; - } - } - - public bool IsEmpty { - get { return !Nodes ().GetEnumerator ().MoveNext () && explicit_is_empty; } - internal set { explicit_is_empty = value; } - } - - public XName Name { - get { return name; } - set { - if (value == null) - throw new ArgumentNullException ("Name"); - OnNameChanging (this); - name = value; - OnNameChanged (this); - } - } - - public override XmlNodeType NodeType { - get { return XmlNodeType.Element; } - } - - public string Value { - get { - StringBuilder sb = null; - foreach (XNode n in Nodes ()) { - if (sb == null) - sb = new StringBuilder (); - if (n is XText) - sb.Append (((XText) n).Value); - else if (n is XElement) - sb.Append (((XElement) n).Value); - } - return sb == null ? String.Empty : sb.ToString (); - } - set { - RemoveNodes (); - Add (value); - } - } - - IEnumerable GetAncestorList (XName name, bool getMeIn) - { - List list = new List (); - if (getMeIn) - list.Add (this); - for (XElement el = Parent as XElement; el != null; el = el.Parent as XElement) - if (name == null || el.Name == name) - list.Add (el); - return list; - } - - public XAttribute Attribute (XName name) - { - foreach (XAttribute a in Attributes ()) - if (a.Name == name) - return a; - return null; - } - - public IEnumerable Attributes () - { - XAttribute next; - for (XAttribute a = attr_first; a != null; a = next) { - next = a.NextAttribute; - yield return a; - } - } - - // huh? - public IEnumerable Attributes (XName name) - { - foreach (XAttribute a in Attributes ()) - if (a.Name == name) - yield return a; - } - - static void DefineDefaultSettings (XmlReaderSettings settings, LoadOptions options) - { - settings.ProhibitDtd = false; - - settings.IgnoreWhitespace = (options & LoadOptions.PreserveWhitespace) == 0; - } - - static XmlReaderSettings CreateDefaultSettings (LoadOptions options) - { - var settings = new XmlReaderSettings (); - DefineDefaultSettings (settings, options); - return settings; - } - - public static XElement Load (string uri) - { - return Load (uri, LoadOptions.None); - } - - public static XElement Load (string uri, LoadOptions options) - { - XmlReaderSettings s = CreateDefaultSettings (options); - - using (XmlReader r = XmlReader.Create (uri, s)) { - return LoadCore (r, options); - } - } - - public static XElement Load (TextReader textReader) - { - return Load (textReader, LoadOptions.None); - } - - public static XElement Load (TextReader textReader, LoadOptions options) - { - XmlReaderSettings s = CreateDefaultSettings (options); - - using (XmlReader r = XmlReader.Create (textReader, s)) { - return LoadCore (r, options); - } - } - - public static XElement Load (XmlReader reader) - { - return Load (reader, LoadOptions.None); - } - - public static XElement Load (XmlReader reader, LoadOptions options) - { - XmlReaderSettings s = reader.Settings != null ? reader.Settings.Clone () : new XmlReaderSettings (); - DefineDefaultSettings (s, options); - - using (XmlReader r = XmlReader.Create (reader, s)) { - return LoadCore (r, options); - } - } - -#if NET_4_0 - public static XElement Load (Stream stream) - { - return Load (stream, LoadOptions.None); - } - - public static XElement Load (Stream stream, LoadOptions options) - { - XmlReaderSettings s = new XmlReaderSettings (); - DefineDefaultSettings (s, options); - - using (XmlReader r = XmlReader.Create (stream, s)) { - return LoadCore (r, options); - } - } -#endif - - internal static XElement LoadCore (XmlReader r, LoadOptions options) - { - r.MoveToContent (); - if (r.NodeType != XmlNodeType.Element) - throw new InvalidOperationException ("The XmlReader must be positioned at an element"); - XName name = XName.Get (r.LocalName, r.NamespaceURI); - XElement e = new XElement (name); - e.FillLineInfoAndBaseUri (r, options); - - if (r.MoveToFirstAttribute ()) { - do { - // not sure how current Orcas behavior makes sense here though ... - if (r.LocalName == "xmlns" && r.NamespaceURI == XNamespace.Xmlns.NamespaceName) - e.SetAttributeValue (XNamespace.None.GetName ("xmlns"), r.Value); - else - e.SetAttributeValue (XName.Get (r.LocalName, r.NamespaceURI), r.Value); - e.LastAttribute.FillLineInfoAndBaseUri (r, options); - } while (r.MoveToNextAttribute ()); - r.MoveToElement (); - } - if (!r.IsEmptyElement) { - r.Read (); - e.ReadContentFrom (r, options); - r.ReadEndElement (); - e.explicit_is_empty = false; - } else { - e.explicit_is_empty = true; - r.Read (); - } - return e; - } - - public static XElement Parse (string text) - { - return Parse (text, LoadOptions.None); - } - - public static XElement Parse (string text, LoadOptions options) - { - return Load (new StringReader (text), options); - } - - public void RemoveAll () - { - RemoveAttributes (); - RemoveNodes (); - } - - public void RemoveAttributes () - { - while (attr_first != null) - attr_last.Remove (); - } - - public void Save (string fileName) - { - Save (fileName, SaveOptions.None); - } - - public void Save (string fileName, SaveOptions options) - { - XmlWriterSettings s = new XmlWriterSettings (); - - if ((options & SaveOptions.DisableFormatting) == SaveOptions.None) - s.Indent = true; -#if NET_4_0 - if ((options & SaveOptions.OmitDuplicateNamespaces) == SaveOptions.OmitDuplicateNamespaces) - s.NamespaceHandling |= NamespaceHandling.OmitDuplicates; -#endif - using (XmlWriter w = XmlWriter.Create (fileName, s)) { - Save (w); - } - } - - public void Save (TextWriter textWriter) - { - Save (textWriter, SaveOptions.None); - } - - public void Save (TextWriter textWriter, SaveOptions options) - { - XmlWriterSettings s = new XmlWriterSettings (); - - if ((options & SaveOptions.DisableFormatting) == SaveOptions.None) - s.Indent = true; -#if NET_4_0 - if ((options & SaveOptions.OmitDuplicateNamespaces) == SaveOptions.OmitDuplicateNamespaces) - s.NamespaceHandling |= NamespaceHandling.OmitDuplicates; -#endif - using (XmlWriter w = XmlWriter.Create (textWriter, s)) { - Save (w); - } - } - - public void Save (XmlWriter writer) - { - WriteTo (writer); - } - -#if NET_4_0 - public void Save (Stream stream) - { - Save (stream, SaveOptions.None); - } - - public void Save (Stream stream, SaveOptions options) - { - XmlWriterSettings s = new XmlWriterSettings (); - if ((options & SaveOptions.DisableFormatting) == SaveOptions.None) - s.Indent = true; - if ((options & SaveOptions.OmitDuplicateNamespaces) == SaveOptions.OmitDuplicateNamespaces) - s.NamespaceHandling |= NamespaceHandling.OmitDuplicates; - - using (var writer = XmlWriter.Create (stream, s)){ - Save (writer); - } - } -#endif - public IEnumerable AncestorsAndSelf () - { - return GetAncestorList (null, true); - } - - public IEnumerable AncestorsAndSelf (XName name) - { - return GetAncestorList (name, true); - } - - public IEnumerable DescendantsAndSelf () - { - List list = new List (); - list.Add (this); - list.AddRange (Descendants ()); - return list; - } - - public IEnumerable DescendantsAndSelf (XName name) - { - List list = new List (); - if (name == this.name) - list.Add (this); - list.AddRange (Descendants (name)); - return list; - } - - public IEnumerable DescendantNodesAndSelf () - { - yield return this; - foreach (XNode node in DescendantNodes ()) - yield return node; - } - - public void SetAttributeValue (XName name, object value) - { - XAttribute a = Attribute (name); - if (value == null) { - if (a != null) - a.Remove (); - } else { - if (a == null) { - SetAttributeObject (new XAttribute (name, value)); - } - else - a.Value = XUtil.ToString (value); - } - } - - void SetAttributeObject (XAttribute a) - { - OnAddingObject (a); - a = (XAttribute) XUtil.GetDetachedObject (a); - a.SetOwner (this); - if (attr_first == null) { - attr_first = a; - attr_last = a; - } else { - attr_last.NextAttribute = a; - a.PreviousAttribute = attr_last; - attr_last = a; - } - OnAddedObject (a); - } - - string LookupPrefix (string ns, XmlWriter w) - { - string prefix = ns.Length > 0 ? GetPrefixOfNamespace (ns) ?? w.LookupPrefix (ns) : String.Empty; - foreach (XAttribute a in Attributes ()) { - if (a.IsNamespaceDeclaration && a.Value == ns) { - if (a.Name.Namespace == XNamespace.Xmlns) - prefix = a.Name.LocalName; - // otherwise xmlns="..." - break; - } - } - return prefix; - } - - static string CreateDummyNamespace (ref int createdNS, IEnumerable atts, bool isAttr) - { - if (!isAttr && atts.All (a => a.Name.LocalName != "xmlns" || a.Name.NamespaceName == XNamespace.Xmlns.NamespaceName)) - return String.Empty; - string p = null; - do { - p = "p" + (++createdNS); - // check conflict - if (atts.All (a => a.Name.LocalName != p || a.Name.NamespaceName == XNamespace.Xmlns.NamespaceName)) - break; - } while (true); - return p; - } - - public override void WriteTo (XmlWriter writer) - { - // some people expect the same prefix output as in input, - // in the loss of performance... see bug #466423. - string prefix = LookupPrefix (name.NamespaceName, writer); - int createdNS = 0; - if (prefix == null) - prefix = CreateDummyNamespace (ref createdNS, Attributes (), false); - - writer.WriteStartElement (prefix, name.LocalName, name.Namespace.NamespaceName); - - foreach (XAttribute a in Attributes ()) { - if (a.IsNamespaceDeclaration) { - if (a.Name.Namespace == XNamespace.Xmlns) - writer.WriteAttributeString ("xmlns", a.Name.LocalName, XNamespace.Xmlns.NamespaceName, a.Value); - else - writer.WriteAttributeString ("xmlns", a.Value); - } else { - string apfix = LookupPrefix (a.Name.NamespaceName, writer); - if (apfix == null) - apfix = CreateDummyNamespace (ref createdNS, Attributes (), true); - writer.WriteAttributeString (apfix, a.Name.LocalName, a.Name.Namespace.NamespaceName, a.Value); - } - } - - foreach (XNode node in Nodes ()) - node.WriteTo (writer); - - if (explicit_is_empty) - writer.WriteEndElement (); - else - writer.WriteFullEndElement (); - } - - public XNamespace GetDefaultNamespace () - { - for (XElement el = this; el != null; el = el.Parent) - foreach (XAttribute a in el.Attributes ()) - if (a.IsNamespaceDeclaration && a.Name.Namespace == XNamespace.None) - return XNamespace.Get (a.Value); - return XNamespace.None; // nothing is declared. - } - - public XNamespace GetNamespaceOfPrefix (string prefix) - { - for (XElement el = this; el != null; el = el.Parent) - foreach (XAttribute a in el.Attributes ()) - if (a.IsNamespaceDeclaration && (prefix.Length == 0 && a.Name.LocalName == "xmlns" || a.Name.LocalName == prefix)) - return XNamespace.Get (a.Value); - return XNamespace.None; // nothing is declared. - } - - public string GetPrefixOfNamespace (XNamespace ns) - { - foreach (string prefix in GetPrefixOfNamespaceCore (ns)) - if (GetNamespaceOfPrefix (prefix) == ns) - return prefix; - return null; // nothing is declared - } - - IEnumerable GetPrefixOfNamespaceCore (XNamespace ns) - { - for (XElement el = this; el != null; el = el.Parent) - foreach (XAttribute a in el.Attributes ()) - if (a.IsNamespaceDeclaration && a.Value == ns.NamespaceName) - yield return a.Name.Namespace == XNamespace.None ? String.Empty : a.Name.LocalName; - } - - public void ReplaceAll (object content) - { - RemoveNodes (); - Add (content); - } - - public void ReplaceAll (params object [] content) - { - RemoveNodes (); - Add (content); - } - - public void ReplaceAttributes (object content) - { - RemoveAttributes (); - Add (content); - } - - public void ReplaceAttributes (params object [] content) - { - RemoveAttributes (); - Add (content); - } - - public void SetElementValue (XName name, object value) - { - var element = Element (name); - if (element == null && value != null) { - Add (new XElement (name, value)); - } else if (element != null && value == null) { - element.Remove (); - } else - element.SetValue (value); - } - - public void SetValue (object value) - { - if (value == null) - throw new ArgumentNullException ("value"); - if (value is XAttribute || value is XDocument || value is XDeclaration || value is XDocumentType) - throw new ArgumentException (String.Format ("Node type {0} is not allowed as element value", value.GetType ())); - RemoveNodes (); - foreach (object o in XUtil.ExpandArray (value)) - Add (o); - } - - internal override bool OnAddingObject (object o, bool rejectAttribute, XNode refNode, bool addFirst) - { - if (o is XDocument || o is XDocumentType || o is XDeclaration || (rejectAttribute && o is XAttribute)) - throw new ArgumentException (String.Format ("A node of type {0} cannot be added as a content", o.GetType ())); - - XAttribute a = o as XAttribute; - if (a != null) { - foreach (XAttribute ia in Attributes ()) - if (a.Name == ia.Name) - throw new InvalidOperationException (String.Format ("Duplicate attribute: {0}", a.Name)); - SetAttributeObject (a); - return true; - } - else if (o is string && refNode is XText) { - ((XText) refNode).Value += o as string; - return true; - } - else - return false; - } - - void IXmlSerializable.WriteXml (XmlWriter writer) - { - Save (writer); - } - - void IXmlSerializable.ReadXml (XmlReader reader) - { - ReadContentFrom (reader, LoadOptions.None); - } - - XmlSchema IXmlSerializable.GetSchema () - { - return null; - } - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/XIterators.cs b/Saleslogix.SData.Client/LinqToXml/XIterators.cs deleted file mode 100644 index 4749ff0a..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XIterators.cs +++ /dev/null @@ -1,139 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -#if NET_2_0 - -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Text; -using System.Xml; - -using XPI = System.Xml.Linq.XProcessingInstruction; - - -namespace System.Xml.Linq -{ - /* - // Iterators - internal class XFilterIterator : IEnumerable - { - IEnumerable source; - XName name; - - public XFilterIterator (IEnumerable source, XName name) - { - this.source = source; - this.name = name; - } - - public IEnumerator GetEnumerator () - { - foreach (object o in source) { - if (! (o is T)) - continue; - if (name != null) { - if (o is XElement) { - if (((XElement) o).Name != name) - continue; - } - else if (o is XAttribute) { - if (((XAttribute) o).Name != name) - continue; - } - } - yield return (T) o; - } - } - - IEnumerator IEnumerable.GetEnumerator () - { - return GetEnumerator (); - } - } - - internal class XDescendantIterator : IEnumerable - { - IEnumerable source; - - public XDescendantIterator (IEnumerable source) - { - this.source = new XFilterIterator (source, null); - } - - public IEnumerator GetEnumerator () - { - foreach (T t1 in source) { - yield return t1; - XContainer xc = t1 as XContainer; - if (xc == null || xc.FirstChild == null) - continue; - foreach (T t2 in new XDescendantIterator (xc.Content ())) - yield return t2; - } - } - - IEnumerator IEnumerable.GetEnumerator () - { - return GetEnumerator (); - } - } - */ - -#if !LIST_BASED - internal class XChildrenIterator : IEnumerable - { - XContainer source; - XNode n; - - public XChildrenIterator (XContainer source) - { - this.source = source; - } - - public IEnumerator GetEnumerator () - { - if (n == null) { - n = source.FirstNode; - if (n == null) - yield break; - } - do { - yield return n; - n = n.NextNode; - } while (n != source.LastNode); - } - - IEnumerator IEnumerable.GetEnumerator () - { - return GetEnumerator (); - } - } -#endif -} - -#endif diff --git a/Saleslogix.SData.Client/LinqToXml/XName.cs b/Saleslogix.SData.Client/LinqToXml/XName.cs deleted file mode 100644 index ef466ade..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XName.cs +++ /dev/null @@ -1,171 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -#if NET_2_0 - -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Runtime.Serialization; -using System.Text; -using System.Xml; - -using XPI = System.Xml.Linq.XProcessingInstruction; - -namespace System.Xml.Linq -{ - [Serializable] - internal sealed class XName : IEquatable, ISerializable - { - string local; - XNamespace ns; - - XName (SerializationInfo info, StreamingContext context) - { - string expandedName = info.GetString ("name"); - string local, ns; - ExpandName (expandedName, out local, out ns); - this.local = local; - this.ns = XNamespace.Get (ns); - } - - internal XName (string local, XNamespace ns) - { - this.local = XmlConvert.VerifyNCName (local); - this.ns = ns; - } - - static Exception ErrorInvalidExpandedName () - { - return new ArgumentException ("Invalid expanded name."); - } - - public string LocalName { - get { return local; } - } - - public XNamespace Namespace { - get { return ns; } - } - - public string NamespaceName { - get { return ns.NamespaceName; } - } - - public override bool Equals (object obj) - { - XName n = obj as XName; - return n != null && this == n; - } - - bool IEquatable.Equals (XName other) - { - return this == other; - } - - public static XName Get (string expandedName) - { - string local, ns; - ExpandName (expandedName, out local, out ns); - return Get (local, ns); - } - - static void ExpandName (string expandedName, out string local, out string ns) - { - if (expandedName == null) - throw new ArgumentNullException ("expandedName"); - ns = null; - local = null; - if (expandedName.Length == 0) - throw ErrorInvalidExpandedName (); - //this.expanded = expandedName; - if (expandedName [0] == '{') { - for (int i = 1; i < expandedName.Length; i++) { - if (expandedName [i] == '}') - ns = expandedName.Substring (1, i - 1); - } - if (String.IsNullOrEmpty (ns)) // {}foo is invalid - throw ErrorInvalidExpandedName (); - if (expandedName.Length == ns.Length + 2) // {foo} is invalid - throw ErrorInvalidExpandedName (); - local = expandedName.Substring (ns.Length + 2); - } - else { - local = expandedName; - ns = String.Empty; - } - } - - public static XName Get (string localName, string namespaceName) - { - return XNamespace.Get (namespaceName).GetName (localName); - } - - public override int GetHashCode () - { - return local.GetHashCode () ^ ns.GetHashCode (); - } - - public static bool operator == (XName left, XName right) - { - if ((object) left == null) - return (object) right == null; - else if ((object) right == null) - return false; - return object.ReferenceEquals (left, right) || - left.local == right.local && left.ns == right.ns; - } - - public static implicit operator XName (string expandedName) - { - return expandedName == null ? null : Get (expandedName); - } - - public static bool operator != (XName left, XName right) - { - return ! (left == right); - } - - public override string ToString () - { - if (ns == XNamespace.None) - return local; - return String.Concat ("{", ns.NamespaceName, "}", local); - } - - // in .NET it is serialized as "NameSerializer". dunno how to create it. - void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context) - { - if (info == null) - throw new ArgumentNullException ("info"); - - info.AddValue ("name", ToString ()); - } - } -} - -#endif diff --git a/Saleslogix.SData.Client/LinqToXml/XNamespace.cs b/Saleslogix.SData.Client/LinqToXml/XNamespace.cs deleted file mode 100644 index d7075e7f..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XNamespace.cs +++ /dev/null @@ -1,139 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Text; -using System.Xml; - -namespace System.Xml.Linq -{ - internal sealed class XNamespace - { - static readonly XNamespace blank, xml, xmlns; - static Dictionary nstable; - - static XNamespace () - { - nstable = new Dictionary (); - blank = Get (String.Empty); - xml = Get ("http://www.w3.org/XML/1998/namespace"); - xmlns = Get ("http://www.w3.org/2000/xmlns/"); - } - - public static XNamespace None { - get { return blank; } - } - - public static XNamespace Xml { - get { return xml; } - } - - public static XNamespace Xmlns { - get { return xmlns; } - } - - public static XNamespace Get (string namespaceName) - { - lock (nstable) { - XNamespace ret; - if (!nstable.TryGetValue (namespaceName, out ret)) { - ret = new XNamespace (namespaceName); - nstable [namespaceName] = ret; - } - return ret; - } - } - - public XName GetName (string localName) - { - if (table == null) - table = new Dictionary (); - lock (table) { - XName ret; - if (!table.TryGetValue (localName, out ret)) { - ret = new XName (localName, this); - table [localName] = ret; - } - return ret; - } - } - - string uri; - Dictionary table; - - XNamespace (string namespaceName) - { - if (namespaceName == null) - throw new ArgumentNullException ("namespaceName"); - uri = namespaceName; - } - - public string NamespaceName { - get { return uri; } - } - - public override bool Equals (object obj) - { - if (Object.ReferenceEquals (this, obj)) - return true; - XNamespace ns = obj as XNamespace; - return ns != null && uri == ns.uri; - } - - public static bool operator == (XNamespace left, XNamespace right) - { - return (object) left != null ? left.Equals (right) : (object) right == null; - } - - public static bool operator != (XNamespace left, XNamespace right) - { - return ! (left == right); - } - - public static XName operator + (XNamespace ns, string localName) - { - return new XName (localName, ns); - } - - public static implicit operator XNamespace (string namespaceName) - { - return namespaceName != null ? XNamespace.Get (namespaceName) : null; - } - - public override int GetHashCode () - { - return uri.GetHashCode (); - } - - public override string ToString () - { - return uri; - } - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/XNode.cs b/Saleslogix.SData.Client/LinqToXml/XNode.cs deleted file mode 100644 index 83cd9da8..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XNode.cs +++ /dev/null @@ -1,346 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Text; -using System.Xml; - -using XPI = System.Xml.Linq.XProcessingInstruction; - -namespace System.Xml.Linq -{ - internal abstract class XNode : XObject - { - public static int CompareDocumentOrder (XNode n1, XNode n2) - { - return order_comparer.Compare (n1, n2); - } - - public static bool DeepEquals (XNode n1, XNode n2) - { - return eq_comparer.Equals (n1, n2); - } - - static XNodeEqualityComparer eq_comparer = - new XNodeEqualityComparer (); - static XNodeDocumentOrderComparer order_comparer = - new XNodeDocumentOrderComparer (); - - XNode previous; - XNode next; - - internal XNode () - { - } - - public static XNodeDocumentOrderComparer DocumentOrderComparer { - get { return order_comparer; } - } - - public static XNodeEqualityComparer EqualityComparer { - get { return eq_comparer; } - } - - public XNode PreviousNode { - get { return previous; } - internal set { previous = value; } - } - - public XNode NextNode { - get { return next; } - internal set { next = value; } - } - - public string ToString (SaveOptions options) - { - StringWriter sw = new StringWriter (); - XmlWriterSettings s = new XmlWriterSettings (); - s.ConformanceLevel = ConformanceLevel.Auto; - s.Indent = options != SaveOptions.DisableFormatting; - XmlWriter xw = XmlWriter.Create (sw, s); - WriteTo (xw); - xw.Close (); - return sw.ToString (); - } - - public void AddAfterSelf (object content) - { - if (Owner == null) - throw new InvalidOperationException (); - XNode here = this; - XNode orgNext = next; - foreach (object o in XUtil.ExpandArray (content)) { - if (o == null || Owner.OnAddingObject (o, true, here, false)) - continue; - XNode n = XUtil.ToNode (o); - Owner.OnAddingObject (n); - n = (XNode) XUtil.GetDetachedObject (n); - n.SetOwner (Owner); - n.previous = here; - here.next = n; - n.next = orgNext; - if (orgNext != null) - orgNext.previous = n; - else - Owner.LastNode = n; - here = n; - Owner.OnAddedObject (n); - } - } - - public void AddAfterSelf (params object [] content) - { - if (Owner == null) - throw new InvalidOperationException (); - AddAfterSelf ((object) content); - } - - public void AddBeforeSelf (object content) - { - if (Owner == null) - throw new InvalidOperationException (); - foreach (object o in XUtil.ExpandArray (content)) { - if (o == null || Owner.OnAddingObject (o, true, previous, true)) - continue; - - XNode n = XUtil.ToNode (o); - Owner.OnAddingObject (n); - n = (XNode) XUtil.GetDetachedObject (n); - n.SetOwner (Owner); - n.previous = previous; - n.next = this; - if (previous != null) - previous.next = n; - previous = n; - if (Owner.FirstNode == this) - Owner.FirstNode = n; - Owner.OnAddedObject (n); - } - } - - public void AddBeforeSelf (params object [] content) - { - if (Owner == null) - throw new InvalidOperationException (); - AddBeforeSelf ((object) content); - } - - public static XNode ReadFrom (XmlReader reader) - { - return ReadFrom (reader, LoadOptions.None); - } - - internal static XNode ReadFrom (XmlReader r, LoadOptions options) - { - switch (r.NodeType) { - case XmlNodeType.Element: - return XElement.LoadCore (r, options); - case XmlNodeType.Whitespace: - case XmlNodeType.SignificantWhitespace: - case XmlNodeType.Text: - XText t = new XText (r.Value); - t.FillLineInfoAndBaseUri (r, options); - r.Read (); - return t; - case XmlNodeType.CDATA: - XCData c = new XCData (r.Value); - c.FillLineInfoAndBaseUri (r, options); - r.Read (); - return c; - case XmlNodeType.ProcessingInstruction: - XPI pi = new XPI (r.Name, r.Value); - pi.FillLineInfoAndBaseUri (r, options); - r.Read (); - return pi; - case XmlNodeType.Comment: - XComment cm = new XComment (r.Value); - cm.FillLineInfoAndBaseUri (r, options); - r.Read (); - return cm; - case XmlNodeType.DocumentType: - XDocumentType d = new XDocumentType (r.Name, - r.GetAttribute ("PUBLIC"), - r.GetAttribute ("SYSTEM"), - r.Value); - d.FillLineInfoAndBaseUri (r, options); - r.Read (); - return d; - default: - throw new InvalidOperationException (String.Format ("Node type {0} is not supported", r.NodeType)); - } - } - - public void Remove () - { - if (Owner == null) - throw new InvalidOperationException ("Owner is missing"); - - var owner = Owner; - owner.OnRemovingObject (this); - if (Owner.FirstNode == this) - Owner.FirstNode = next; - if (Owner.LastNode == this) - Owner.LastNode = previous; - if (previous != null) - previous.next = next; - if (next != null) - next.previous = previous; - previous = null; - next = null; - SetOwner (null); - owner.OnRemovedObject (this); - } - - public override string ToString () - { - return ToString (SaveOptions.None); - } - - public abstract void WriteTo (XmlWriter writer); - - public IEnumerable Ancestors () - { - for (XElement el = Parent; el != null; el = el.Parent) - yield return el; - } - - public IEnumerable Ancestors (XName name) - { - foreach (XElement el in Ancestors ()) - if (el.Name == name) - yield return el; - } - - public XmlReader CreateReader () - { - return new XNodeReader (this); - } - -#if NET_4_0 - public XmlReader CreateReader (ReaderOptions readerOptions) - { - var r = new XNodeReader (this); - if ((readerOptions & ReaderOptions.OmitDuplicateNamespaces) != 0) - r.OmitDuplicateNamespaces = true; - - return r; - } -#endif - - public IEnumerable ElementsAfterSelf () - { - foreach (XNode n in NodesAfterSelf ()) - if (n is XElement) - yield return (XElement) n; - } - - public IEnumerable ElementsAfterSelf (XName name) - { - foreach (XElement el in ElementsAfterSelf ()) - if (el.Name == name) - yield return el; - } - - public IEnumerable ElementsBeforeSelf () - { - foreach (XNode n in NodesBeforeSelf ()) - if (n is XElement) - yield return (XElement) n; - } - - public IEnumerable ElementsBeforeSelf (XName name) - { - foreach (XElement el in ElementsBeforeSelf ()) - if (el.Name == name) - yield return el; - } - - public bool IsAfter (XNode node) - { - return XNode.DocumentOrderComparer.Compare (this, node) > 0; - } - - public bool IsBefore (XNode node) - { - return XNode.DocumentOrderComparer.Compare (this, node) < 0; - } - - public IEnumerable NodesAfterSelf () - { - if (Owner == null) - yield break; - for (XNode n = NextNode; n != null; n = n.NextNode) - yield return n; - } - - public IEnumerable NodesBeforeSelf () - { - if (Owner == null) - yield break; - for (XNode n = Owner.FirstNode; n != this; n = n.NextNode) - yield return n; - } - - public void ReplaceWith (object content) - { - if (Owner == null) - throw new InvalidOperationException (); - - XNode here = previous; - XNode orgNext = next; - XContainer orgOwner = Owner; - Remove(); - foreach (object o in XUtil.ExpandArray (content)) { - if (o == null || orgOwner.OnAddingObject (o, true, here, false)) - continue; - XNode n = XUtil.ToNode (o); - n = (XNode) XUtil.GetDetachedObject (n); - n.SetOwner (orgOwner); - n.previous = here; - if (here != null) - here.next = n; - else - orgOwner.FirstNode = n; - n.next = orgNext; - if (orgNext != null) - orgNext.previous = n; - else - orgOwner.LastNode = n; - here = n; - } - } - - public void ReplaceWith (params object [] content) - { - if (Owner == null) - throw new InvalidOperationException (); - ReplaceWith ((object) content); - } - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/XNodeDocumentOrderComparer.cs b/Saleslogix.SData.Client/LinqToXml/XNodeDocumentOrderComparer.cs deleted file mode 100644 index c4095524..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XNodeDocumentOrderComparer.cs +++ /dev/null @@ -1,155 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections; -using System.Collections.Generic; - -namespace System.Xml.Linq -{ - internal sealed class XNodeDocumentOrderComparer : IComparer, IComparer - { - public XNodeDocumentOrderComparer () - { - } - - enum CompareResult - { - Same, - Random, - Parent, - Child, - Ancestor, - Descendant, - Preceding, - Following - } - - public int Compare (XNode x, XNode y) - { - switch (CompareCore (x,y)) { - case CompareResult.Same: - return 0; - case CompareResult.Random: - return DateTime.Now.Ticks % 2 == 1 ? 1 : -1; - case CompareResult.Parent: - case CompareResult.Ancestor: - case CompareResult.Preceding: - return 1; - default: - return -1; - } - } - - CompareResult CompareCore (XNode n1, XNode n2) - { - if (n1 == n2) - return CompareResult.Same; - if (n1.Owner == null) { - if (n2.Owner == null) - // n1 and n2 do not share the same - // top-level node, so return semi- - // random value. - return CompareResult.Random; - - CompareResult result = CompareCore (n1, n2.Owner); - switch (result) { - case CompareResult.Same: - return CompareResult.Child; - case CompareResult.Child: - case CompareResult.Descendant: - return CompareResult.Descendant; - case CompareResult.Parent: - case CompareResult.Ancestor: - throw new Exception ("INTERNAL ERROR: should not happen"); - default: - return result; - } - } - // else - if (n2.Owner == null) { - // do reverse - CompareResult rev = CompareCore (n2, n1); - switch (rev) { - case CompareResult.Parent: - return CompareResult.Child; - case CompareResult.Child: - return CompareResult.Parent; - case CompareResult.Ancestor: - return CompareResult.Descendant; - case CompareResult.Descendant: - return CompareResult.Ancestor; - case CompareResult.Following: - return CompareResult.Preceding; - case CompareResult.Preceding: - return CompareResult.Following; - case CompareResult.Same: - case CompareResult.Random: - return rev; - } - } - // both have parents - CompareResult ret = CompareCore (n1.Owner, n2.Owner); - switch (ret) { - case CompareResult.Same: - // n1 and n2 are sibling each other. - return CompareSibling (n1, n2, CompareResult.Same); - case CompareResult.Child: - return CompareSibling (n1, n2.Owner, CompareResult.Child); - case CompareResult.Parent: - return CompareSibling (n1.Owner, n2, CompareResult.Parent); - case CompareResult.Descendant: - for (XNode i2 = n2; ; i2 = i2.Owner) - if (i2.Owner == n1.Owner) - return CompareSibling (n1, i2, CompareResult.Descendant); - case CompareResult.Ancestor: - for (XNode i1 = n1; ; i1 = i1.Owner) - if (i1.Owner == n2.Owner) - return CompareSibling (i1, n2, CompareResult.Ancestor); - default: - return ret; - } - } - - // results are returned as following/preceding, as it is also - // used for comparing parents. - CompareResult CompareSibling (XNode n1, XNode n2, CompareResult forSameValue) - { - if (n1 == n2) - return forSameValue; - - for (XNode n = n1.NextNode; n != null; n = n.NextNode) - if (n == n2) - return CompareResult.Following; - return CompareResult.Preceding; - } - - int IComparer.Compare (object n1, object n2) - { - return Compare ((XNode) n1, (XNode) n2); - } - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/XNodeEqualityComparer.cs b/Saleslogix.SData.Client/LinqToXml/XNodeEqualityComparer.cs deleted file mode 100644 index c3fc6ea7..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XNodeEqualityComparer.cs +++ /dev/null @@ -1,187 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections; -using System.Collections.Generic; - -using XPI = System.Xml.Linq.XProcessingInstruction; - -namespace System.Xml.Linq -{ - internal sealed class XNodeEqualityComparer : IEqualityComparer, IEqualityComparer - { - public XNodeEqualityComparer () - { - } - - public bool Equals (XNode x, XNode y) - { - if (x == null) - return y == null; - else if (y == null) - return false; - //throw new NotImplementedException (); - if (x.NodeType != y.NodeType) - return false; - switch (x.NodeType) { - case XmlNodeType.Document: - XDocument doc1 = (XDocument) x; - XDocument doc2 = (XDocument) y; - if (!Equals (doc1.Declaration, doc2.Declaration)) - return false; - IEnumerator id2 = doc2.Nodes ().GetEnumerator (); - foreach (XNode n in doc1.Nodes ()) { - if (!id2.MoveNext ()) - return false; - if (!Equals (n, id2.Current)) - return false; - } - return !id2.MoveNext (); - case XmlNodeType.Element: - XElement e1 = (XElement) x; - XElement e2 = (XElement) y; - if (e1.Name != e2.Name) - return false; - IEnumerator ia2 = e2.Attributes ().GetEnumerator (); - foreach (XAttribute n in e1.Attributes ()) { - if (!ia2.MoveNext ()) - return false; - if (!Equals (n, ia2.Current)) - return false; - } - if (ia2.MoveNext ()) - return false; - IEnumerator ie2 = e2.Nodes ().GetEnumerator (); - foreach (XNode n in e1.Nodes ()) { - if (!ie2.MoveNext ()) - return false; - if (!Equals (n, ie2.Current)) - return false; - } - return !ie2.MoveNext (); - case XmlNodeType.Comment: - XComment c1 = (XComment) x; - XComment c2 = (XComment) y; - return c1.Value == c2.Value; - case XmlNodeType.ProcessingInstruction: - XPI p1 = (XPI) x; - XPI p2 = (XPI) y; - return p1.Target == p2.Target && p1.Data == p2.Data; - case XmlNodeType.DocumentType: - XDocumentType d1 = (XDocumentType) x; - XDocumentType d2 = (XDocumentType) y; - return d1.Name == d2.Name && - d1.PublicId == d2.PublicId && - d1.SystemId == d2.SystemId && - d1.InternalSubset == d2.InternalSubset; - case XmlNodeType.Text: - return ((XText) x).Value == ((XText) y).Value; - } - throw new Exception ("INTERNAL ERROR: should not happen"); - } - - bool Equals (XAttribute a1, XAttribute a2) - { - if (a1 == null) - return a2 == null; - else if (a2 == null) - return false; - return a1.Name == a2.Name && a1.Value == a2.Value; - } - - bool Equals (XDeclaration d1, XDeclaration d2) - { - if (d1 == null) - return d2 == null; - else if (d2 == null) - return false; - return d1.Version == d2.Version && - d1.Encoding == d2.Encoding && - d1.Standalone == d2.Standalone; - } - - bool IEqualityComparer.Equals (object n1, object n2) - { - return Equals ((XNode) n1, (XNode) n2); - } - - int GetHashCode (XDeclaration d) - { - if (d == null) - return 0; - return (d.Version.GetHashCode () << 7) ^ - (d.Encoding.GetHashCode () << 6) ^ - d.Standalone.GetHashCode (); - } - - public int GetHashCode (XNode obj) - { - if (obj == null) - return 0; - int h = ((int) obj.NodeType << 6); - switch (obj.NodeType) { - case XmlNodeType.Document: - XDocument doc = (XDocument) obj; - h = h ^ GetHashCode (doc.Declaration); - foreach (XNode n in doc.Nodes ()) - h = h ^ (n.GetHashCode () << 5); - break; - case XmlNodeType.Element: - XElement el = (XElement) obj; - h = h ^ (el.Name.GetHashCode () << 3); - foreach (XAttribute a in el.Attributes ()) - h = h ^ (a.GetHashCode () << 7); - foreach (XNode n in el.Nodes ()) - h = h ^ (n.GetHashCode () << 6); - break; - case XmlNodeType.Comment: - h = h ^ ((XComment) obj).Value.GetHashCode (); - break; - case XmlNodeType.ProcessingInstruction: - XPI pi = (XPI) obj; - h = h ^ ((pi.Target.GetHashCode () << 6) + pi.Data.GetHashCode ()); - break; - case XmlNodeType.DocumentType: - XDocumentType dtd = (XDocumentType) obj; - h = h ^ (dtd.Name.GetHashCode () << 7) ^ - (dtd.PublicId.GetHashCode () << 6) ^ - (dtd.SystemId.GetHashCode () << 5) ^ - (dtd.InternalSubset.GetHashCode () << 4); - break; - case XmlNodeType.Text: - h = h ^ (((XText) obj).GetHashCode ()); - break; - } - return h; - } - - int IEqualityComparer.GetHashCode (object obj) - { - return GetHashCode ((XNode) obj); - } - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/XNodeNavigator.cs b/Saleslogix.SData.Client/LinqToXml/XNodeNavigator.cs deleted file mode 100644 index 55702bd1..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XNodeNavigator.cs +++ /dev/null @@ -1,422 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.IO; -using System.Text; -using System.Xml; -using System.Xml.Schema; -using System.Xml.XPath; - -using XPI = System.Xml.Linq.XProcessingInstruction; - -namespace System.Xml.Linq -{ - internal class XNodeNavigator : XPathNavigator - { - static readonly XAttribute attr_ns_xml = new XAttribute (XNamespace.Xmlns.GetName ("xml"), XNamespace.Xml.NamespaceName); - - XNode node; - XAttribute attr; - XmlNameTable name_table; - - public XNodeNavigator (XNode node, XmlNameTable nameTable) - { - this.node = node; - this.name_table = nameTable; - } - - public XNodeNavigator (XNodeNavigator other) - { - this.node = other.node; - this.attr = other.attr; - this.name_table = other.name_table; - } - - public override string BaseURI { - get { return node.BaseUri ?? String.Empty; } - } - - public override bool CanEdit { - get { return true; } - } - - public override bool HasAttributes { - get { - if (attr != null) - return false; - XElement el = node as XElement; - if (el == null) - return false; - foreach (var at in el.Attributes ()) - if (!at.IsNamespaceDeclaration) - return true; - return false; - } - } - - public override bool HasChildren { - get { - if (attr != null) - return false; - XContainer c = node as XContainer; - return c != null && c.FirstNode != null; - } - } - - public override bool IsEmptyElement { - get { - if (attr != null) - return false; - XElement el = node as XElement; - return el != null && el.IsEmpty; - } - } - - public override string LocalName { - get { - switch (NodeType) { - case XPathNodeType.Namespace: - return attr.Name.Namespace == XNamespace.None ? String.Empty : attr.Name.LocalName; - case XPathNodeType.Attribute: - return attr.Name.LocalName; - case XPathNodeType.Element: - return ((XElement) node).Name.LocalName; - case XPathNodeType.ProcessingInstruction: - return ((XPI) node).Target; - default: - return String.Empty; - } - } - } - - public override string Name { - get { - XName name = null; - switch (NodeType) { - case XPathNodeType.Attribute: - name = attr.Name; - break; - case XPathNodeType.Element: - name = ((XElement) node).Name; - break; - default: - return LocalName; - } - if (name.Namespace == XNamespace.None) - return name.LocalName; - XElement el = (node as XElement) ?? node.Parent; - if (el == null) - return name.LocalName; - string prefix = el.GetPrefixOfNamespace (name.Namespace); - return prefix.Length > 0 ? String.Concat (prefix, ":", name.LocalName) : name.LocalName; - } - } - - public override string NamespaceURI { - get { - switch (NodeType) { - case XPathNodeType.ProcessingInstruction: - case XPathNodeType.Namespace: - return String.Empty; - case XPathNodeType.Attribute: - return attr.Name.NamespaceName; - case XPathNodeType.Element: - return ((XElement) node).Name.NamespaceName; - default: - return String.Empty; - } - } - } - - public override XmlNameTable NameTable { - get { return name_table; } - } - - public override XPathNodeType NodeType { - get { - if (attr != null) - return attr.IsNamespaceDeclaration ? - XPathNodeType.Namespace : - XPathNodeType.Attribute; - switch (node.NodeType) { - case XmlNodeType.Element: - return XPathNodeType.Element; - case XmlNodeType.Document: - return XPathNodeType.Root; - case XmlNodeType.Comment: - return XPathNodeType.Comment; - case XmlNodeType.ProcessingInstruction: - return XPathNodeType.ProcessingInstruction; - default: - return XPathNodeType.Text; - } - } - } - - public override string Prefix { - get { - XName name = null; - switch (NodeType) { - case XPathNodeType.ProcessingInstruction: - case XPathNodeType.Namespace: - return String.Empty; - case XPathNodeType.Attribute: - name = attr.Name; - break; - case XPathNodeType.Element: - name = ((XElement) node).Name; - break; - default: - return LocalName; - } - if (name.Namespace == XNamespace.None) - return String.Empty; - XElement el = (node as XElement) ?? node.Parent; - if (el == null) - return String.Empty; - return el.GetPrefixOfNamespace (name.Namespace); - } - } - - public override IXmlSchemaInfo SchemaInfo { - get { return null; } - } - - public override object UnderlyingObject { - get { return attr != null ? (object) attr : node; } - } - - public override string Value { - get { - if (attr != null) - return attr.Value; - else - switch (NodeType) { - case XPathNodeType.Comment: - return ((XComment) node).Value; - case XPathNodeType.ProcessingInstruction: - return ((XPI) node).Data; - case XPathNodeType.Text: - string s = String.Empty; - for (var xn = node as XText; xn != null; xn = xn.NextNode as XText) - s += xn.Value; - return s; - case XPathNodeType.Element: - case XPathNodeType.Root: - return GetInnerText ((XContainer) node); - } - return String.Empty; - } - } - - string GetInnerText (XContainer node) - { - StringBuilder sb = null; - foreach (XNode n in node.Nodes ()) - GetInnerText (n, ref sb); - return sb != null ? sb.ToString () : String.Empty; - } - - void GetInnerText (XNode n, ref StringBuilder sb) - { - switch (n.NodeType) { - case XmlNodeType.Element: - foreach (XNode c in ((XElement) n).Nodes ()) - GetInnerText (c, ref sb); - break; - case XmlNodeType.Text: - case XmlNodeType.CDATA: - if (sb == null) - sb = new StringBuilder (); - sb.Append (((XText) n).Value); - break; - } - } - - public override XPathNavigator Clone () - { - return new XNodeNavigator (this); - } - - public override bool IsSamePosition (XPathNavigator other) - { - XNodeNavigator nav = other as XNodeNavigator; - if (nav == null || nav.node.Owner != node.Owner) - return false; - return node == nav.node && attr == nav.attr; - } - - public override bool MoveTo (XPathNavigator other) - { - XNodeNavigator nav = other as XNodeNavigator; - if (nav == null || nav.node.Document != node.Document) - return false; - node = nav.node; - attr = nav.attr; - return true; - } - - public override bool MoveToFirstAttribute () - { - if (attr != null) - return false; - XElement el = node as XElement; - if (el == null || !el.HasAttributes) - return false; - foreach (XAttribute a in el.Attributes ()) - if (!a.IsNamespaceDeclaration) { - attr = a; - return true; - } - return false; - } - - public override bool MoveToFirstChild () - { - if (attr != null) - return false; - XContainer c = node as XContainer; - if (c == null || c.FirstNode == null) - return false; - node = c.FirstNode; - attr = null; - return true; - } - - public override bool MoveToFirstNamespace (XPathNamespaceScope scope) - { - if (NodeType != XPathNodeType.Element) - return false; - for (XElement el = node as XElement; el != null; el = el.Parent) { - foreach (XAttribute a in el.Attributes ()) - if (a.IsNamespaceDeclaration) { - attr = a; - return true; - } - if (scope == XPathNamespaceScope.Local) - return false; - } - if (scope != XPathNamespaceScope.All) - return false; - attr = attr_ns_xml; - return true; - } - - public override bool MoveToId (string id) - { - throw new NotSupportedException ("This XPathNavigator does not support IDs"); - } - - public override bool MoveToNext () - { - XNode xn = node.NextNode; - if (xn is XText) - for (; xn != null; xn = xn.NextNode) - if (!(xn.NextNode is XText)) - break; - if (xn == null) - return false; - node = xn; - attr = null; - return true; - } - - public override bool MoveToNextAttribute () - { - if (attr == null) - return false; - if (attr.NextAttribute == null) - return false; - for (XAttribute a = attr.NextAttribute; a != null; a = a.NextAttribute) - if (!a.IsNamespaceDeclaration) { - attr = a; - return true; - } - return false; - } - - public override bool MoveToNextNamespace (XPathNamespaceScope scope) - { - if (attr == null) - return false; - for (XAttribute a = attr.NextAttribute; a != null; a = a.NextAttribute) - if (a.IsNamespaceDeclaration) { - attr = a; - return true; - } - - if (scope == XPathNamespaceScope.Local) - return false; - - if (attr == attr_ns_xml) - return false; // no next attribute - - for (XElement el = ((XElement) attr.Parent).Parent; el != null; el = el.Parent) { - foreach (XAttribute a in el.Attributes ()) - if (a.IsNamespaceDeclaration) { - attr = a; - return true; - } - } - if (scope != XPathNamespaceScope.All) - return false; - attr = attr_ns_xml; - return true; - } - - public override bool MoveToParent () - { - if (attr != null) { - attr = null; - return true; - } - if (node.Owner == null) - return false; - node = node.Owner; - return true; - } - - public override bool MoveToPrevious () - { - if (node.PreviousNode == null) - return false; - node = node.PreviousNode; - attr = null; - return true; - } - - public override void MoveToRoot () - { - attr = null; - if (node.Document != null) - node = node.Document; - else - while (node.Owner != null) - node = node.Owner; - } - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/XNodeReader.cs b/Saleslogix.SData.Client/LinqToXml/XNodeReader.cs deleted file mode 100644 index 95631f1b..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XNodeReader.cs +++ /dev/null @@ -1,547 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// Copyright 2011 Xamarin Inc (http://www.xamarin.com). -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Xml; - -using XPI = System.Xml.Linq.XProcessingInstruction; - -namespace System.Xml.Linq -{ - internal class XNodeReader : XmlReader, IXmlLineInfo - { - ReadState state = ReadState.Initial; - XNode node, start; - int attr = -1; - bool attr_value; - bool end_element; - NameTable name_table = new NameTable (); - - public XNodeReader (XNode node) - { - this.node = node; - start = node; - } - -#if NET_4_0 - internal bool OmitDuplicateNamespaces { get; set; } -#endif - - int IXmlLineInfo.LineNumber { - get { - var o = (XObject) GetCurrentAttribute () ?? node; - return o != null ? o.LineNumber : 0; - } - } - int IXmlLineInfo.LinePosition { - get { - var o = (XObject) GetCurrentAttribute () ?? node; - return o != null ? o.LinePosition : 0; - } - } - bool IXmlLineInfo.HasLineInfo () - { - var o = (XObject) GetCurrentAttribute () ?? node; - return o != null ? ((IXmlLineInfo) o).HasLineInfo () : false; - } - - public override int AttributeCount { - get { - if (state != ReadState.Interactive || end_element) - return 0; - int i = 0; - switch (node.NodeType) { - case XmlNodeType.Document: // this means xmldecl - XDeclaration xd = ((XDocument) node).Declaration; - i = (xd.Version != null ? 1 : 0) + - (xd.Encoding != null ? 1 : 0) + - (xd.Standalone != null ? 1 : 0); - return i; - case XmlNodeType.DocumentType: - XDocumentType dtd = (XDocumentType) node; - i = (dtd.PublicId != null ? 1 : 0) + - (dtd.SystemId != null ? 1 : 0) + - (dtd.InternalSubset != null ? 1 : 0); - return i; - case XmlNodeType.Element: - XElement el = (XElement) node; - for (XAttribute a = el.FirstAttribute; a != null; a = a.NextAttribute) - i++; - return i; - } - return 0; - } - } - - public override string BaseURI { - get { return node.BaseUri ?? String.Empty; } - } - - public override int Depth { - get { - if (EOF) - return 0; - int i = 0; - // document.Depth = 0, root.Depth = 0, others.Depth = they depend - for (XNode n = node.Parent; n != null; n = n.Parent) - i++; - if (attr >= 0) - i++; - if (attr_value) - i++; - return i; - } - } - - public override bool EOF { - get { return state == ReadState.EndOfFile || state == ReadState.Error; } - } - - public override bool HasAttributes { - get { - if (EOF || end_element || node == null) - return false; - - if (node is XElement) - return ((XElement) node).HasAttributes; - return AttributeCount > 0; - } - } - - public override bool HasValue { - get { - if (EOF) - return false; - if (attr >= 0) - return true; - switch (node.NodeType) { - case XmlNodeType.Element: - case XmlNodeType.Document: - case XmlNodeType.EndElement: - return false; - default: - return true; - } - } - } - - public override bool IsEmptyElement { - get { return !EOF && attr < 0 && node is XElement ? ((XElement) node).IsEmpty : false; } - } - - internal XAttribute GetCurrentAttribute () - { - return GetXAttribute (attr); - } - - XAttribute GetXAttribute (int idx) - { - if (EOF) - return null; - XElement el = node as XElement; - if (el == null) - return null; - int i = 0; - foreach (XAttribute a in el.Attributes ()) - if (i++ == idx) - return a; - return null; - } - - // XName for element and attribute, string for xmldecl attributes, doctype attribute, doctype name and PI, null for empty. - object GetCurrentName () - { - if (EOF || attr_value) - return null; - return GetName (attr); - } - - object GetName (int attr) - { - if (attr >= 0) { - switch (node.NodeType) { - case XmlNodeType.Element: - XAttribute a = GetXAttribute (attr); - return a.Name; - case XmlNodeType.DocumentType: - if (attr == 0) - return ((XDocumentType) node).PublicId != null ? "PUBLIC" : "SYSTEM"; - return "SYSTEM"; - case XmlNodeType.Document: - XDeclaration xd = ((XDocument) node).Declaration; - switch (attr) { - case 0: - return xd.Version != null ? "version" : xd.Encoding != null ? "encoding" : "standalone"; - case 1: - return xd.Version != null ? (xd.Encoding != null ? "encoding" : "standalone") : "standalone"; - } - return "standalone"; - } - } else { - switch (node.NodeType) { - case XmlNodeType.Document: - return "xml"; // xmldecl - case XmlNodeType.Element: - return ((XElement) node).Name; - case XmlNodeType.ProcessingInstruction: - return ((XPI) node).Target; - case XmlNodeType.DocumentType: - return ((XDocumentType) node).Name; - } - } - return null; - } - - public override string LocalName { - get { - object name = GetCurrentName (); - if (name == null) - return String.Empty; - if (name is string) - return (string) name; - return ((XName) name).LocalName; - } - } - - public override string NamespaceURI { - get { - XName name = GetCurrentName () as XName; - if (name != null) - // XName for "xmlns" has NamespaceName as "", so we have to return w3c xmlns as a special case. - return name.LocalName == "xmlns" && name.Namespace == XNamespace.None ? - XNamespace.Xmlns.NamespaceName : - name.NamespaceName; - return String.Empty; - } - } - - public override XmlNameTable NameTable { - get { return name_table; } - } - - public override XmlNodeType NodeType { - get { - return state != ReadState.Interactive ? XmlNodeType.None : - end_element ? XmlNodeType.EndElement : - attr_value ? XmlNodeType.Text : - attr >= 0 ? XmlNodeType.Attribute : - node.NodeType == XmlNodeType.Document ? XmlNodeType.XmlDeclaration : - node.NodeType; - } - } - - public override string Prefix { - get { - XName name = GetCurrentName () as XName; - if (name == null || name.Namespace == XNamespace.None) - return String.Empty; - XElement el = (node as XElement) ?? node.Parent; - if (el == null) - return String.Empty; - return el.GetPrefixOfNamespace (name.Namespace) ?? String.Empty; - } - } - - public override ReadState ReadState { - get { return state; } - } - - public override string Value { - get { - if (ReadState != ReadState.Interactive) - return String.Empty; - XAttribute a = GetCurrentAttribute (); - if (a != null) - return a.Value; - switch (node.NodeType) { - case XmlNodeType.Document: - XDeclaration xd = ((XDocument) node).Declaration; - if (attr >= 0) { - switch (LocalName) { - case "version": - return xd.Version; - case "encoding": - return xd.Encoding; - default: - return xd.Standalone; - } - } else { - string s = xd.ToString (); - return s.Substring (6, s.Length - 6 - 2); - } - case XmlNodeType.DocumentType: - XDocumentType dtd = (XDocumentType) node; - switch (LocalName) { - case "PUBLIC": - return dtd.PublicId; - case "SYSTEM": - return dtd.SystemId; - default: - return dtd.InternalSubset; - } - case XmlNodeType.ProcessingInstruction: - return ((XPI) node).Data; - case XmlNodeType.CDATA: - case XmlNodeType.Text: - return ((XText) node).Value; - case XmlNodeType.Comment: - return ((XComment) node).Value; - } - return String.Empty; - } - } - - public override void Close () - { - state = ReadState.Closed; - } - - public override string LookupNamespace (string prefix) - { - if (EOF) - return null; - XElement el = (node as XElement) ?? node.Parent; - if (el == null) - return null; - var xn = el.GetNamespaceOfPrefix (prefix); - return xn != XNamespace.None ? xn.NamespaceName : null; - } - - public override bool MoveToElement () - { - if (attr >= 0) { - attr_value = false; - attr = -1; - return true; - } - return false; - } - - public override bool MoveToFirstAttribute () - { - if (AttributeCount > 0) { - attr = 0; - attr_value = false; - return true; - } - return false; - } - - public override bool MoveToNextAttribute () - { - int c = AttributeCount; - if (attr + 1 < c) { - attr++; - attr_value = false; - return true; - } - return false; - } - - public override bool MoveToAttribute (string name) - { - if (name == null) - throw new ArgumentNullException ("name"); - - int c = AttributeCount; - bool match = false; - for (int i = 0; i < c; i++) { - object o = GetName (i); - if (o == null) - continue; - if ((o as string) == name) - match = true; - XName n = (XName) o; - if (name.EndsWith (n.LocalName, StringComparison.Ordinal) && name == GetPrefixedName ((XName) o)) - match = true; - if (match) { - attr = i; - attr_value = false; - return true; - } - } - return false; - } - - string GetPrefixedName (XName name) - { - XElement el = (node as XElement) ?? node.Parent; - if (el == null || - name.Namespace == XNamespace.None || - el.GetPrefixOfNamespace (name.Namespace) == String.Empty) - return name.LocalName; - return String.Concat (el.GetPrefixOfNamespace (name.Namespace), ":", name.LocalName); - } - - public override bool MoveToAttribute (string local, string ns) - { - if (local == null) - throw new ArgumentNullException ("local"); - if (ns == null) - throw new ArgumentNullException ("ns"); - - int c = AttributeCount; - bool match = false; - for (int i = 0; i < c; i++) { - object o = GetName (i); - if (o == null) - continue; - if ((o as string) == local && ns.Length == 0) - match = true; - XName n = (XName) o; - if (local == n.LocalName && ns == n.NamespaceName) - match = true; - if (match) { - attr = i; - attr_value = false; - return true; - } - } - return false; - } - - public override string GetAttribute (int i) - { - int a_bak = attr; - bool av_bak = attr_value; - try { - MoveToElement (); - MoveToAttribute (i); - return Value; - } finally { - attr = a_bak; - attr_value = av_bak; - } - } - - public override string GetAttribute (string name) - { - int a_bak = attr; - bool av_bak = attr_value; - try { - MoveToElement (); - return MoveToAttribute (name) ? Value : null; - } finally { - attr = a_bak; - attr_value = av_bak; - } - } - - public override string GetAttribute (string local, string ns) - { - int a_bak = attr; - bool av_bak = attr_value; - try { - MoveToElement (); - return MoveToAttribute (local, ns) ? Value : null; - } finally { - attr = a_bak; - attr_value = av_bak; - } - } - - public override bool Read () - { - // clear attribute state on element/xmldecl/dtd. - attr = -1; - attr_value = false; - - switch (state) { - case ReadState.Initial: - state = ReadState.Interactive; - XDocument doc = node as XDocument; - if (doc != null) { - if (doc.Declaration != null) - return true; - } - else - return true; // any other root - break; - case ReadState.Interactive: - break; - default: - return false; - } - - // when positioned on xmldecl, move to children - if (node is XDocument) { - XDocument doc = node as XDocument; - node = doc.FirstNode; - if (node == null) { - state = ReadState.EndOfFile; - return false; - } - node = doc.FirstNode; - return true; - } - - XElement c = node as XElement; - if (c != null && !end_element) { - if (c.FirstNode != null) { - node = c.FirstNode; - return true; - } else if (!c.IsEmpty) { - // empty but full EndElement - end_element = true; - return true; - } - } - end_element = false; - if (node.NextNode != null && node != start) { - node = node.NextNode; - return true; - } - if (node.Parent == null || node == start) { - state = ReadState.EndOfFile; - return false; - } - node = node.Parent; - end_element = true; - return true; - } - - public - override - bool ReadAttributeValue () - { - if (attr < 0 || attr_value) - return false; - attr_value = true; - return true; - } - - public override void ResolveEntity () - { - throw new NotSupportedException (); - } - - // Note that this does not return attribute node. - internal XNode CurrentNode { - get { return node; } - } - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/XNodeWriter.cs b/Saleslogix.SData.Client/LinqToXml/XNodeWriter.cs deleted file mode 100644 index 3ba281f1..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XNodeWriter.cs +++ /dev/null @@ -1,403 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Xml; - -namespace System.Xml.Linq -{ - internal class XNodeWriter : XmlWriter - { - public XNodeWriter (XContainer fragment) - { - root = fragment; - state = XmlNodeType.None; - current = fragment; - } - - XContainer root; - bool is_closed; - // If it is not null, then we are now inside the element. - XContainer current; - // If it is not null, then we are now inside the attribute. - XAttribute attribute; - - // None: started or closed. - // XmlDeclaration: after xmldecl. Never allow xmldecl. - // DocumentType: after doctype. Never allow xmldecl and doctype. - // Element: inside document element. - // - XmlNodeType state; - - // Properties - - public override WriteState WriteState { - get { - if (is_closed) - return WriteState.Closed; - if (attribute != null) - return WriteState.Attribute; - - switch (state) { - case XmlNodeType.None: - return WriteState.Start; - case XmlNodeType.XmlDeclaration: - return WriteState.Prolog; - case XmlNodeType.DocumentType: - return WriteState.Element; - default: - return WriteState.Content; - } - } - } - - /* - public override string XmlLang { - get { - for (XElement n = current as XElement; n != null; n = n.Parent as XElement) - if (n.HasAttribute ("xml:lang")) - return n.GetAttribute ("xml:lang"); - return String.Empty; - } - } - - public override XmlSpace XmlSpace { - get { - for (XElement n = current as XElement; n != null; n = n.Parent as XElement) { - string xs = n.GetAttribute ("xml:space"); - switch (xs) { - case "preserve": - return XmlSpace.Preserve; - case "default": - return XmlSpace.Default; - case "": - continue; - default: - throw new InvalidOperationException (String.Format ("Invalid xml:space {0}.", xs)); - } - } - return XmlSpace.None; - } - } - */ - - // Private Methods - - void CheckState () - { - if (is_closed) - throw new InvalidOperationException (); - - } - - void WritePossiblyTopLevelNode (XNode n, bool possiblyAttribute) - { - CheckState (); - if (!possiblyAttribute && attribute != null) - throw new InvalidOperationException (String.Format ("Current state is not acceptable for {0}.", n.NodeType)); - - if (state != XmlNodeType.Element) - root.Add (n); - else if (attribute != null) - attribute.Value += XUtil.ToString (n); - else - current.Add (n); - if (state == XmlNodeType.None) - state = XmlNodeType.XmlDeclaration; - } - - // unlike other XmlWriters the callers must set xmlns - // attribute to overwrite prefix. - void FillXmlns (XElement el, string prefix, XNamespace xns) - { - if (xns == XNamespace.Xmlns) - // do nothing for xmlns attributes - return; - if (prefix == null) - return; - - if (xns == XNamespace.None) - if (el.GetPrefixOfNamespace (xns) != prefix) - el.SetAttributeValue (prefix == String.Empty ? XNamespace.None.GetName ("xmlns") : XNamespace.Xmlns.GetName (prefix), xns.NamespaceName); - else if (el.GetDefaultNamespace () != XNamespace.None) - el.SetAttributeValue (XNamespace.None.GetName ("xmlns"), xns.NamespaceName); - } - - // Public Methods - - public override void Close () - { - CheckState (); - is_closed = true; - } - - public override void Flush () - { - } - - public override string LookupPrefix (string ns) - { - CheckState (); - if (current == null) - throw new InvalidOperationException (); - XElement el = (current as XElement) ?? current.Parent; - return el != null ? el.GetPrefixOfNamespace (XNamespace.Get (ns)) : null; - } - - // StartDocument - - public override void WriteStartDocument () - { - WriteStartDocument (null); - } - - public override void WriteStartDocument (bool standalone) - { - WriteStartDocument (standalone ? "yes" : "no"); - } - - void WriteStartDocument (string sddecl) - { - CheckState (); - if (state != XmlNodeType.None) - throw new InvalidOperationException ("Current state is not acceptable for xmldecl."); - XDocument doc = current as XDocument; - if (doc == null) - throw new InvalidOperationException ("Only document node can accept xml declaration"); - - doc.Declaration = new XDeclaration ("1.0", null, sddecl); - state = XmlNodeType.XmlDeclaration; - } - - // EndDocument - - public override void WriteEndDocument () - { - CheckState (); - - is_closed = true; - } - - // DocumentType - public override void WriteDocType (string name, string publicId, string systemId, string internalSubset) - { - CheckState (); - switch (state) { - case XmlNodeType.None: - case XmlNodeType.XmlDeclaration: - XDocument doc = current as XDocument; - if (doc == null) - throw new InvalidOperationException ("Only document node can accept doctype declaration"); - doc.Add (new XDocumentType (name, publicId, systemId, internalSubset)); - state = XmlNodeType.DocumentType; - break; - default: - throw new InvalidOperationException ("Current state is not acceptable for doctype."); - } - } - - // StartElement - - public override void WriteStartElement (string prefix, string name, string ns) - { - CheckState (); - - XNamespace xns = XNamespace.Get (ns ?? String.Empty); - XElement el = new XElement (xns.GetName (name)); - if (current == null) { - root.Add (el); - state = XmlNodeType.Element; - } else { - current.Add (el); - state = XmlNodeType.Element; - } - - FillXmlns (el, prefix, xns); - - current = el; - } - - // EndElement - - public override void WriteEndElement () - { - WriteEndElementInternal (false); - } - - public override void WriteFullEndElement () - { - WriteEndElementInternal (true); - } - - void WriteEndElementInternal (bool forceFull) - { - CheckState (); - if (current == null) - throw new InvalidOperationException ("Current state is not acceptable for endElement."); - - XElement el = current as XElement; - if (forceFull) - el.IsEmpty = false; - - current = current.Parent; - } - - // StartAttribute - - public override void WriteStartAttribute (string prefix, string name, string ns) - { - CheckState (); - if (attribute != null) - throw new InvalidOperationException ("There is an open attribute."); - XElement el = current as XElement; - if (el == null) - throw new InvalidOperationException ("Current state is not acceptable for startAttribute."); - if (prefix == null) - prefix = String.Empty; - - // special case: in XmlWriter context, xmlns="blah" is - // passeed as localName = "xmlns", ns = w3c_xmlns. - if (prefix.Length == 0 && name == "xmlns" && ns == XNamespace.Xmlns.NamespaceName) - ns = String.Empty; - - XNamespace xns = ns == null ? XNamespace.None : XNamespace.Get (ns); - el.SetAttributeValue (xns.GetName (name), String.Empty); - attribute = el.LastAttribute; - FillXmlns (el, ns != null ? prefix : null, xns); - } - - public override void WriteEndAttribute () - { - CheckState (); - if (attribute == null) - throw new InvalidOperationException ("Current state is not acceptable for startAttribute."); - - attribute = null; - } - - public override void WriteCData (string data) - { - CheckState (); - if (current == null) - throw new InvalidOperationException ("Current state is not acceptable for CDATAsection."); - - current.Add (new XCData (data)); - } - - public override void WriteComment (string comment) - { - WritePossiblyTopLevelNode (new XComment (comment), false); - } - - public override void WriteProcessingInstruction (string name, string value) - { - WritePossiblyTopLevelNode ( - new XProcessingInstruction (name, value), false); - } - - public override void WriteEntityRef (string name) - { - throw new NotSupportedException (); - } - - public override void WriteCharEntity (char c) - { - throw new NotSupportedException (); - } - - public override void WriteWhitespace (string ws) - { - // FIXME: check whitespace - WritePossiblyTopLevelNode (new XText (ws), true); - } - - public override void WriteString (string data) - { - CheckState (); - if (current == null) - throw new InvalidOperationException ("Current state is not acceptable for Text."); - - if (attribute != null) - attribute.Value += data; - else - current.Add (data); - } - - public override void WriteName (string name) - { - WriteString (name); - } - - public override void WriteNmToken (string nmtoken) - { - WriteString (nmtoken); - } - - public override void WriteQualifiedName (string name, string ns) - { - string prefix = LookupPrefix (ns); - if (prefix == null) - throw new ArgumentException (String.Format ("Invalid namespace {0}", ns)); - if (prefix != String.Empty) - WriteString (name); - else - WriteString (prefix + ":" + name); - } - - public override void WriteChars (char [] chars, int start, int len) - { - WriteString (new string (chars, start, len)); - } - - public override void WriteRaw (string data) - { - // It never supports raw string. - WriteString (data); - } - - public override void WriteRaw (char [] chars, int start, int len) - { - // It never supports raw string. - WriteChars (chars, start, len); - } - - public override void WriteBase64 (byte [] data, int start, int len) - { - // It never supports raw string. - WriteString (Convert.ToBase64String (data, start, len)); - } - - public override void WriteBinHex (byte [] data, int start, int len) - { - throw new NotImplementedException (); - } - - public override void WriteSurrogateCharEntity (char c1, char c2) - { - throw new NotImplementedException (); - } - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/XObject.cs b/Saleslogix.SData.Client/LinqToXml/XObject.cs deleted file mode 100644 index 4a0f8b72..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XObject.cs +++ /dev/null @@ -1,223 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Xml; - -namespace System.Xml.Linq -{ - internal abstract class XObject : IXmlLineInfo - { - internal XObject () - { - } - - XContainer owner; - List annotations; - string baseuri; - int line, column; - - public event EventHandler Changing; - public event EventHandler Changed; - - public string BaseUri { - get { return baseuri; } - internal set { baseuri = value; } - } - - public XDocument Document { - get { - if (this is XDocument) - return (XDocument) this; - - for (XContainer e = owner; e != null; e = e.owner) - if (e is XDocument) - return (XDocument) e; - return null; - } - } - - public abstract XmlNodeType NodeType { get; } - - public XElement Parent { - get { return owner as XElement; } - } - - internal XContainer Owner { - get { return owner; } - } - - internal void SetOwner (XContainer node) - { - owner = node; - } - - public void AddAnnotation (object annotation) - { - if (annotation == null) - throw new ArgumentNullException ("annotation"); - if (annotations == null) - annotations = new List (); - annotations.Add (annotation); - } - - public T Annotation () where T : class - { - return (T) Annotation (typeof (T)); - } - - public object Annotation (Type type) - { - return Annotations (type).FirstOrDefault (); - } - - public IEnumerable Annotations () where T : class - { - foreach (T o in Annotations (typeof (T))) - yield return o; - } - - public IEnumerable Annotations (Type type) - { - if (type == null) - throw new ArgumentNullException ("type"); - if (annotations == null) - yield break; - foreach (object o in annotations) - if (type.IsAssignableFrom (o.GetType ())) - yield return o; - } - - public void RemoveAnnotations () where T : class - { - RemoveAnnotations (typeof (T)); - } - - public void RemoveAnnotations (Type type) - { - if (annotations == null) - return; - for (int i = 0; i < annotations.Count; i++) - if (type.IsAssignableFrom (annotations [i].GetType ())) - annotations.RemoveAt (i); - } - - internal int LineNumber { - get { return line; } - set { line = value; } - } - - internal int LinePosition { - get { return column; } - set { column = value; } - } - - int IXmlLineInfo.LineNumber { - get { return LineNumber; } - } - - int IXmlLineInfo.LinePosition { - get { return LinePosition; } - } - - bool IXmlLineInfo.HasLineInfo () - { - return line > 0; - } - - internal void FillLineInfoAndBaseUri (XmlReader r, LoadOptions options) - { - if ((options & LoadOptions.SetLineInfo) != LoadOptions.None) { - IXmlLineInfo li = r as IXmlLineInfo; - if (li != null && li.HasLineInfo ()) { - LineNumber = li.LineNumber; - LinePosition = li.LinePosition; - } - } - if ((options & LoadOptions.SetBaseUri) != LoadOptions.None) - BaseUri = r.BaseURI; - } - - internal void OnAddingObject (object addedObject) - { - OnChanging (addedObject, new XObjectChangeEventArgs (XObjectChange.Add)); - } - - internal void OnAddedObject (object addedObject) - { - OnChanged (addedObject, new XObjectChangeEventArgs (XObjectChange.Add)); - } - - internal void OnNameChanging (object renamedObject) - { - OnChanging (renamedObject, new XObjectChangeEventArgs (System.Xml.Linq.XObjectChange.Name)); - } - - internal void OnNameChanged (object renamedObject) - { - OnChanged (renamedObject, new XObjectChangeEventArgs (System.Xml.Linq.XObjectChange.Name)); - } - - internal void OnRemovingObject (object removedObject) - { - OnChanging (removedObject, new XObjectChangeEventArgs (XObjectChange.Remove)); - } - - internal void OnRemovedObject (object removedObject) - { - OnChanged (removedObject, new XObjectChangeEventArgs (XObjectChange.Remove)); - } - - internal void OnValueChanging (object changedObject) - { - OnChanging (changedObject, new XObjectChangeEventArgs (XObjectChange.Value)); - } - - internal void OnValueChanged (object changedObject) - { - OnChanged (changedObject, new XObjectChangeEventArgs (XObjectChange.Value)); - } - - - void OnChanging (object sender, XObjectChangeEventArgs args) - { - if (Changing != null) - Changing (sender, args); - if (Parent != null) - Parent.OnChanging (sender, args); - } - - void OnChanged (object sender, XObjectChangeEventArgs args) - { - if (Changed != null) - Changed (sender, args); - if (Parent != null) - Parent.OnChanged (sender, args); - } - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/XObjectChange.cs b/Saleslogix.SData.Client/LinqToXml/XObjectChange.cs deleted file mode 100644 index 57de02c7..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XObjectChange.cs +++ /dev/null @@ -1,36 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace System.Xml.Linq -{ - internal enum XObjectChange - { - Add, - Remove, - Name, - Value - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/XObjectChangeEventArgs.cs b/Saleslogix.SData.Client/LinqToXml/XObjectChangeEventArgs.cs deleted file mode 100644 index cf19fa00..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XObjectChangeEventArgs.cs +++ /dev/null @@ -1,56 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Xml; - -namespace System.Xml.Linq -{ - internal class XObjectChangeEventArgs : EventArgs - { - public XObjectChangeEventArgs (XObjectChange objectChange) - { - this.type = objectChange; - } - - // Note that those fields cannot be directly referenced in - // any object comparisons, as there could be other instances. - public static readonly XObjectChangeEventArgs Add = - new XObjectChangeEventArgs (XObjectChange.Add); - public static readonly XObjectChangeEventArgs Name = - new XObjectChangeEventArgs (XObjectChange.Name); - public static readonly XObjectChangeEventArgs Remove = - new XObjectChangeEventArgs (XObjectChange.Remove); - public static readonly XObjectChangeEventArgs Value = - new XObjectChangeEventArgs (XObjectChange.Value); - - public XObjectChange ObjectChange { - get { return type; } - } - - XObjectChange type; - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/XProcessingInstruction.cs b/Saleslogix.SData.Client/LinqToXml/XProcessingInstruction.cs deleted file mode 100644 index fce48081..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XProcessingInstruction.cs +++ /dev/null @@ -1,82 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Xml; - -namespace System.Xml.Linq -{ - internal class XProcessingInstruction : XNode - { - string name; - string data; - - public XProcessingInstruction (string target, string data) - { - if (target == null) - throw new ArgumentNullException ("target"); - if (data == null) - throw new ArgumentNullException ("data"); - this.name = target; - this.data = data; - } - - public XProcessingInstruction (XProcessingInstruction other) - { - if (other == null) - throw new ArgumentNullException ("other"); - this.name = other.name; - this.data = other.data; - } - - public string Data { - get { return data; } - set { - if (value == null) - throw new ArgumentNullException ("value"); - this.data = value; - } - } - - public override XmlNodeType NodeType { - get { return XmlNodeType.ProcessingInstruction; } - } - - public string Target { - get { return name; } - set { - if (value == null) - throw new ArgumentNullException ("value"); - name = value; - } - } - - public override void WriteTo (XmlWriter writer) - { - writer.WriteProcessingInstruction (name, data); - } - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/XStreamingElement.cs b/Saleslogix.SData.Client/LinqToXml/XStreamingElement.cs deleted file mode 100644 index 88d07792..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XStreamingElement.cs +++ /dev/null @@ -1,184 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.IO; -using System.Collections.Generic; - -namespace System.Xml.Linq -{ - internal class XStreamingElement - { - public XStreamingElement (XName name) - { - Name = name; - } - - public XStreamingElement (XName name, object content) - : this (name) - { - Add (content); - } - - public XStreamingElement (XName name, params object [] content) - : this (name) - { - Add (content); - } - - XName name; - List contents; - - public XName Name { - get { return name; } - set { name = value; } - } - - internal IEnumerable Contents { - get { return contents; } - } - - public void Add (object content) - { - if (contents == null) - contents = new List (); - contents.Add (content); - } - - public void Add (params object [] content) - { - if (contents == null) - contents = new List (); - contents.Add (content); - } - - public void Save (string fileName) - { - using (TextWriter w = File.CreateText (fileName)) - Save (w, SaveOptions.None); - } - - public void Save (TextWriter textWriter) - { - Save (textWriter, SaveOptions.None); - } - - public void Save (XmlWriter writer) - { - WriteTo (writer); - } - - public void Save (string fileName, SaveOptions options) - { - using (TextWriter w = File.CreateText (fileName)) - Save (w, options); - } - - public void Save (TextWriter textWriter, SaveOptions options) - { - XmlWriterSettings s = new XmlWriterSettings (); - s.OmitXmlDeclaration = true; - - if ((options & SaveOptions.DisableFormatting) == SaveOptions.None) - s.Indent = true; -#if NET_4_0 - if ((options & SaveOptions.OmitDuplicateNamespaces) == SaveOptions.OmitDuplicateNamespaces) - s.NamespaceHandling |= NamespaceHandling.OmitDuplicates; -#endif - using (XmlWriter w = XmlWriter.Create (textWriter, s)) - WriteTo (w); - } - -#if NET_4_0 - public void Save (Stream stream) - { - Save (stream, SaveOptions.None); - } - - public void Save (Stream stream, SaveOptions options) - { - XmlWriterSettings s = new XmlWriterSettings (); - if ((options & SaveOptions.DisableFormatting) == SaveOptions.None) - s.Indent = true; - if ((options & SaveOptions.OmitDuplicateNamespaces) == SaveOptions.OmitDuplicateNamespaces) - s.NamespaceHandling |= NamespaceHandling.OmitDuplicates; - - using (var writer = XmlWriter.Create (stream, s)){ - WriteTo (writer); - } - } -#endif - - public override string ToString () - { - return ToString (SaveOptions.None); - } - - public string ToString (SaveOptions options) - { - StringWriter sw = new StringWriter (); - Save (sw, options); - return sw.ToString (); - } - - public void WriteTo (XmlWriter writer) - { - writer.WriteStartElement (name.LocalName, name.Namespace.NamespaceName); - WriteContents (contents, writer); - writer.WriteEndElement (); - } - - void WriteContents (IEnumerable items, XmlWriter w) - { - foreach (object o in XUtil.ExpandArray (items)) { - if (o == null) - continue; - else if (o is XStreamingElement) - ((XStreamingElement) o).WriteTo (w); - else if (o is XNode) - ((XNode) o).WriteTo (w); - else if (o is object []) - WriteContents ((object []) o, w); - else if (o is XAttribute) - WriteAttribute ((XAttribute) o, w); - else - new XText (o.ToString ()).WriteTo (w); - } - } - - void WriteAttribute (XAttribute a, XmlWriter w) - { - if (a.IsNamespaceDeclaration) { - if (a.Name.Namespace == XNamespace.Xmlns) - w.WriteAttributeString ("xmlns", a.Name.LocalName, XNamespace.Xmlns.NamespaceName, a.Value); - else - w.WriteAttributeString ("xmlns", a.Value); - } - else - w.WriteAttributeString (a.Name.LocalName, a.Name.Namespace.NamespaceName, a.Value); - } - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/XText.cs b/Saleslogix.SData.Client/LinqToXml/XText.cs deleted file mode 100644 index 63981424..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XText.cs +++ /dev/null @@ -1,70 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.IO; -using System.Linq; -using System.Text; -using System.Xml; - -namespace System.Xml.Linq -{ - internal class XText : XNode - { - string value; - - public XText (string value) - { - this.value = value; - } - - public XText (XText other) - { - value = other.value; - } - - public override XmlNodeType NodeType { - get { return XmlNodeType.Text; } - } - - public string Value { - get { return value; } - set { - if (value == null) - throw new ArgumentNullException ("value"); - this.value = value; - } - } - - public override void WriteTo (XmlWriter writer) - { - if (Value.Length > 0 && Value.All (c => c == ' ' || c == '\t' || c == '\r' || c == '\n')) - writer.WriteWhitespace (value); - else - writer.WriteString (value); - } - } -} diff --git a/Saleslogix.SData.Client/LinqToXml/XUtil.cs b/Saleslogix.SData.Client/LinqToXml/XUtil.cs deleted file mode 100644 index 69cb484b..00000000 --- a/Saleslogix.SData.Client/LinqToXml/XUtil.cs +++ /dev/null @@ -1,152 +0,0 @@ -// -// Authors: -// Atsushi Enomoto -// -// Copyright 2007 Novell (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Text; -using System.Xml; - -using XPI = System.Xml.Linq.XProcessingInstruction; - -namespace System.Xml.Linq -{ - internal static class XUtil - { - public const string XmlnsNamespace = - "http://www.w3.org/2000/xmlns/"; - - public static bool ConvertToBoolean (string s) - { - return XmlConvert.ToBoolean (s.ToLower (CultureInfo.InvariantCulture)); - } - - public static DateTime ToDateTime (string s) - { - try { - return XmlConvert.ToDateTime (s, XmlDateTimeSerializationMode.RoundtripKind); - } catch { - return DateTime.Parse (s); - } - } - - public static string ToString (object o) - { - if (o == null) - throw new InvalidOperationException ("Attempt to get string from null"); - - switch (Type.GetTypeCode (o.GetType ())) { - case TypeCode.String: - return (string) o; - case TypeCode.DateTime: - return XmlConvert.ToString ((DateTime) o, XmlDateTimeSerializationMode.RoundtripKind); - case TypeCode.Decimal: - return ((decimal) o).ToString (CultureInfo.InvariantCulture); - case TypeCode.Double: - return ((double) o).ToString ("r", CultureInfo.InvariantCulture); - case TypeCode.Single: - return ((float) o).ToString ("r", CultureInfo.InvariantCulture); - case TypeCode.Boolean: - // Valid XML values are `true' and `false', not `True' and `False' that boolean returns - return o.ToString().ToLower(); - default: - if (o is TimeSpan) - return XmlConvert.ToString ((TimeSpan) o); - if (o is DateTimeOffset) - return XmlConvert.ToString ((DateTimeOffset) o); - return o.ToString (); - } - } - - public static bool ToBoolean (object o) - { - throw new NotImplementedException (); - } - - public static Nullable ToNullableBoolean (object o) - { - throw new NotImplementedException (); - } - - public static IEnumerable ExpandArray (object o) - { - XNode n = o as XNode; - if (n != null) - yield return n; - else if (o is string) - yield return o; - else if (o is IEnumerable) - foreach (object obj in (IEnumerable) o) - foreach (object oo in ExpandArray (obj)) - yield return oo; - else - yield return o; - } - - public static XNode ToNode (object o) - { - if (o is XAttribute) - throw new ArgumentException ("Attribute node is not allowed as argument"); - XNode n = o as XNode; - if (n != null) - return n; - else if (o is string) - return new XText ((string) o); - else - return new XText (ToString (o)); - } - - public static object GetDetachedObject (XObject child) - { - return child.Owner != null ? Clone (child) : child; - } - - public static object Clone (object o) - { - if (o is string) - return (string) o; - if (o is XAttribute) - return new XAttribute ((XAttribute) o); - if (o is XElement) - return new XElement ((XElement) o); - if (o is XCData) - return new XCData ((XCData) o); - if (o is XComment) - return new XComment ((XComment) o); - if (o is XPI) - return new XPI ((XPI) o); - if (o is XDeclaration) - return new XDeclaration ((XDeclaration) o); - if (o is XDocumentType) - return new XDocumentType ((XDocumentType) o); - if (o is XText) - return new XText ((XText) o); - throw new ArgumentException (); - } - } -} diff --git a/Saleslogix.SData.Client/Properties/AssemblyInfo.cs b/Saleslogix.SData.Client/Properties/AssemblyInfo.cs index 4b213312..001ff6e9 100644 --- a/Saleslogix.SData.Client/Properties/AssemblyInfo.cs +++ b/Saleslogix.SData.Client/Properties/AssemblyInfo.cs @@ -9,9 +9,9 @@ [assembly: AssemblyTitle("Saleslogix.SData.Client")] [assembly: AssemblyDescription("Saleslogix SData client library for .NET")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("SalesLogix NA, LLC")] +[assembly: AssemblyCompany("Infor")] [assembly: AssemblyProduct("Saleslogix.SData.Client")] -[assembly: AssemblyCopyright("Copyright (c) 1997-2014, SalesLogix NA, LLC. All rights reserved.")] +[assembly: AssemblyCopyright("Copyright 2026 Infor. All rights reserved. www.infor.com")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -25,10 +25,10 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("2.1.0.0")] -[assembly: AssemblyFileVersion("2.1.0.0")] +[assembly: AssemblyVersion("2.0")] +[assembly: AssemblyFileVersion("2.0.3.1565")] [assembly: NeutralResourcesLanguage("en-US")] -[assembly: AssemblyInformationalVersion("2.1.0.0")] +[assembly: AssemblyInformationalVersion("2.0")] [assembly: InternalsVisibleTo("Saleslogix.SData.Client.Test, PublicKey=" + "00240000048000009400000006020000002400005253413100040000010001004f6d7cc2aca5bfa8" + "d454d328b17b843b6e660947a1b16f179307ff46cba02baef4670c51eba6a98e724b95e43719ba64" + diff --git a/Saleslogix.SData.Client/SDataClient.cs b/Saleslogix.SData.Client/SDataClient.cs index 1050a0c3..5f67a75a 100644 --- a/Saleslogix.SData.Client/SDataClient.cs +++ b/Saleslogix.SData.Client/SDataClient.cs @@ -51,7 +51,14 @@ internal SDataClient(string uri, Func requestFactory) public string Uri { get; set; } public string UserName { get; set; } public string Password { get; set; } - public string UserAgent { get; set; } + + private string _userAgent = SDataConstants.UserAgent; + public string UserAgent + { + get => _userAgent; + set => _userAgent = value; + } + public int? Timeout { get; set; } public int? TimeoutRetryAttempts { get; set; } public bool UseHttpMethodOverride { get; set; } @@ -462,7 +469,7 @@ private SDataRequest CreateRequest(SDataUri uri, HttpMethod method, object conte request.Proxy = Proxy; #endif #if !PCL && !NETFX_CORE && !SILVERLIGHT - request.UserAgent = UserAgent; + request.UserAgent = !string.IsNullOrWhiteSpace(UserAgent) ? UserAgent : SDataConstants.UserAgent; if (Timeout != null) { request.Timeout = Timeout.Value; diff --git a/Saleslogix.SData.Client/SDataConstants.cs b/Saleslogix.SData.Client/SDataConstants.cs new file mode 100644 index 00000000..a013e383 --- /dev/null +++ b/Saleslogix.SData.Client/SDataConstants.cs @@ -0,0 +1,7 @@ +namespace Saleslogix.SData.Client +{ + public static class SDataConstants + { + public const string UserAgent = "DotNetSDataClient"; + } +} \ No newline at end of file diff --git a/Saleslogix.SData.Client/Saleslogix.SData.Client_452.csproj b/Saleslogix.SData.Client/Saleslogix.SData.Client_452.csproj index 02293f3a..e39b684a 100644 --- a/Saleslogix.SData.Client/Saleslogix.SData.Client_452.csproj +++ b/Saleslogix.SData.Client/Saleslogix.SData.Client_452.csproj @@ -350,6 +350,7 @@ + diff --git a/Saleslogix.SData.Client/Saleslogix.SData.Client_472.csproj b/Saleslogix.SData.Client/Saleslogix.SData.Client_472.csproj index ee7fbe37..c5a08055 100644 --- a/Saleslogix.SData.Client/Saleslogix.SData.Client_472.csproj +++ b/Saleslogix.SData.Client/Saleslogix.SData.Client_472.csproj @@ -350,6 +350,7 @@ + diff --git a/Saleslogix.SData.Client/Saleslogix.SData.Client_48.csproj b/Saleslogix.SData.Client/Saleslogix.SData.Client_48.csproj index 9c7a8cda..1eed29dd 100644 --- a/Saleslogix.SData.Client/Saleslogix.SData.Client_48.csproj +++ b/Saleslogix.SData.Client/Saleslogix.SData.Client_48.csproj @@ -350,6 +350,7 @@ + diff --git a/Saleslogix.SData.Client/Saleslogix.SData.Client_4_0.csproj b/Saleslogix.SData.Client/Saleslogix.SData.Client_4_0.csproj index 5a50894a..1498a3c4 100644 --- a/Saleslogix.SData.Client/Saleslogix.SData.Client_4_0.csproj +++ b/Saleslogix.SData.Client/Saleslogix.SData.Client_4_0.csproj @@ -349,6 +349,7 @@ + @@ -370,6 +371,10 @@ + + + +