-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IGNITE-3427 .NET: Moved examples from Spring XML to app.config. This c…
…loses #897.
- Loading branch information
Showing
25 changed files
with
210 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestAppConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Apache.Ignite.Core.Tests | ||
{ | ||
using System; | ||
using System.Linq; | ||
using System.Configuration; | ||
using System.Reflection; | ||
|
||
/// <summary> | ||
/// Replaces app.config at runtime for test purposes. | ||
/// </summary> | ||
public static class TestAppConfig | ||
{ | ||
/// <summary> | ||
/// Changes the current app config with the specified one. | ||
/// </summary> | ||
/// <param name="path">The path.</param> | ||
/// <returns>Disposable object that will revert the change when disposed.</returns> | ||
public static IDisposable Change(string path) | ||
{ | ||
return new ChangeAppConfig(path); | ||
} | ||
|
||
/// <summary> | ||
/// Disposable config changer. | ||
/// </summary> | ||
private class ChangeAppConfig : IDisposable | ||
{ | ||
/** */ | ||
private readonly string _oldConfig = | ||
AppDomain.CurrentDomain.GetData("APP_CONFIG_FILE").ToString(); | ||
|
||
/** */ | ||
private bool _isDisposed; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ChangeAppConfig"/> class. | ||
/// </summary> | ||
/// <param name="path">The path.</param> | ||
public ChangeAppConfig(string path) | ||
{ | ||
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", path); | ||
ResetConfigMechanism(); | ||
} | ||
|
||
/** <inheritdoc /> */ | ||
public void Dispose() | ||
{ | ||
if (!_isDisposed) | ||
{ | ||
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", _oldConfig); | ||
ResetConfigMechanism(); | ||
|
||
|
||
_isDisposed = true; | ||
} | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
/// <summary> | ||
/// Resets the internal configuration mechanism. | ||
/// </summary> | ||
private static void ResetConfigMechanism() | ||
{ | ||
// ReSharper disable PossibleNullReferenceException | ||
|
||
typeof(ConfigurationManager) | ||
.GetField("s_initState", BindingFlags.NonPublic | BindingFlags.Static) | ||
.SetValue(null, 0); | ||
|
||
typeof(ConfigurationManager) | ||
.GetField("s_configSystem", BindingFlags.NonPublic | BindingFlags.Static) | ||
.SetValue(null, null); | ||
|
||
typeof(ConfigurationManager) | ||
.Assembly.GetTypes().First(x => x.FullName == "System.Configuration.ClientConfigPaths") | ||
.GetField("s_current", BindingFlags.NonPublic | BindingFlags.Static) | ||
.SetValue(null, null); | ||
|
||
// ReSharper restore PossibleNullReferenceException | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.