1
0
Fork 0
mirror of https://github.com/wagesj45/cs-mic.git synced 2025-01-21 12:32:57 -06:00

Migrating from Sourceforge to Codeplex. Initial checkin starting with version 1.1.5.0 source code.

This commit is contained in:
Jordan Wages 2013-10-20 03:46:38 +00:00
parent f7165325f7
commit c41167bfc4
44 changed files with 7608 additions and 0 deletions

View file

@ -0,0 +1,136 @@
==========================================================================
Visual Studio Team System: Overview of Authoring and Running Tests
==========================================================================
This overview describes the features for authoring and running tests in
Visual Studio Team System and Visual Studio Team Edition for Software Testers.
Opening Tests
-------------
To open a test, open a test project or a test metadata file (a file with
extension .vsmdi) that contains the definition of the test. You can find
test projects and metadata files in Solution Explorer.
Viewing Tests
-------------
To see which tests are available to you, open the Test View window. Or,
if you have installed Team Edition for Software Testers, you can also open
the Test List Editor window to view tests.
To open the Test View window, click the Test menu, point to Windows, and
then click Test View. To open the Test List Editor window (if you have
installed Team Edition for Software Testers), click Test, point to Windows,
and then click Test List Editor.
Running Tests
-------------
You can run tests from the Test View window and the Test List Editor window.
See Viewing Tests to learn how to open these windows. To run one or more
tests displayed in the Test View window, first select the tests in that
window; to select multiple tests, hold either the Shift or CTRL key while
clicking tests. Then click the Run Tests button in the Test View window
toolbar.
If you have installed Visual Studio Team Edition for Software Testers, you can
also use the Test List Editor window to run tests. To run tests in Test List Editor,
select the check box next to each test that you want to run. Then click the
Run Tests button in the Test List Editor window toolbar.
Viewing Test Results
--------------------
When you run a test or a series of tests, the results of the test run will be
shown in the Test Results window. Each individual test in the run is shown on
a separate line so that you can see its status. The window contains an
embedded status bar in the top half of the window that provides you with
summary details of the complete test run.
To see more detailed results for a particular test result, double-click it in
the Test Results window. This opens a window that provides more information
about the particular test result, such as any specific error messages returned
by the test.
Changing the way that tests are run
-----------------------------------
Each time you run one or more tests, a collection of settings is used to
determine how those tests are run. These settings are contained in a “test
run configuration” file.
Here is a partial list of the changes you can make with a test run
configuration file:
- Change the naming scheme for each test run.
- Change the test controller that the tests are run on so that you can run
tests remotely.
- Gather code coverage data for the code being tested so that you can see
which lines of code are covered by your tests.
- Enable and disable test deployment.
- Specify additional files to deploy before tests are run.
- Select a different host, ASP.NET, for running ASP.NET unit tests.
- Select a different host, the smart device test host, for running smart device unit tests.
- Set various properties for the test agents that run your tests.
- Run custom scripts at the start and end of each test run so that you can
set up the test environment exactly as required each time tests are run.
- Set time limits for tests and test runs.
- Set the browser mix and the number of times to repeat Web tests in the
test run.
By default, a test run configuration file is created whenever you create a
new test project. You make changes to this file by double-clicking it in
Solution Explorer and then changing its settings. (Test run configuration
files have the extension .testrunconfig.)
A solution can contain multiple test run configuration files. Only one of
those files, known as the “Active” test run configuration file, is used to
determine the settings that are currently used for test runs. You select
the active test run configuration by clicking Select Active Test Run
Configuration on the Test menu.
-------------------------------------------------------------------------------
Test Types
----------
Using Visual Studio Team Edition for Software Testers, you can create a number
of different test types:
Unit test: Use a unit test to create a programmatic test in C++, Visual C# or
Visual Basic that exercises source code. A unit test calls the methods of a
class, passing suitable parameters, and verifies that the returned value is
what you expect.
There are three specialized variants of unit tests:
- Data-driven unit tests are created when you configure a unit test to be
called repeatedly for each row of a data source. The data from each row
is used by the unit test as input data.
- ASP.NET unit tests are unit tests that exercise code in an ASP.NET Web
application.
- Smart device unit tests are unit tests that are deployed to a smart device
or emulator and then executed by the smart device test host.
Web Test: Web tests consist of an ordered series of HTTP requests that you
record in a browser session using Microsoft Internet Explorer. You can have
the test report specific details about the pages or sites it requests, such
as whether a particular page contains a specified string.
Load Test: You use a load test to encapsulate non-manual tests, such as
unit, Web, and generic tests, and then run them simultaneously by using
virtual users. Running these tests under load generates test results,
including performance and other counters, in tables and in graphs.
Generic test: A generic test is an existing program wrapped to function as a
test in Visual Studio. The following are examples of tests or programs that
you can turn into generic tests:
- An existing test that uses process exit codes to communicate whether the
test passed or failed. 0 indicates passing and any other value indicates
a failure.
- A general program to obtain specific functionality during a test scenario.
- A test or program that uses a special XML file (called a “summary results
file”), to communicate detailed results.
Manual test: The manual test type is used when the test tasks are to be
completed by a test engineer as opposed to an automated script.
Ordered test: Use an ordered test to execute a set of tests in an order you
specify.
-------------------------------------------------------------------------------

View file

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{C03AD9DF-630F-4C88-A9D4-8B4B450CCB54}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CSMICTests</RootNamespace>
<AssemblyName>CSMICTests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="InputInterpreterTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="AuthoringTests.txt" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\csmic\csmic.csproj">
<Project>{7BBA4BA2-E885-4D89-8710-F1A609616B7D}</Project>
<Name>csmic</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Shadow Include="Test References\csmic.accessor" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View file

@ -0,0 +1,10 @@
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = ""
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
}

View file

@ -0,0 +1,216 @@
using csmic;
using csmic.Extensions;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace CSMICTests
{
/// <summary>
///This is a test class for InputInterpreterTest and is intended
///to contain all InputInterpreterTest Unit Tests
///</summary>
[TestClass()]
public class InputInterpreterTest
{
private TestContext testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
#region Additional test attributes
//
//You can use the following additional attributes as you write your tests:
//
//Use ClassInitialize to run code before running the first test in the class
//[ClassInitialize()]
//public static void MyClassInitialize(TestContext testContext)
//{
//}
//
//Use ClassCleanup to run code after all tests in a class have run
//[ClassCleanup()]
//public static void MyClassCleanup()
//{
//}
//
//Use TestInitialize to run code before running each test
//[TestInitialize()]
//public void MyTestInitialize()
//{
//}
//
//Use TestCleanup to run code after each test has run
//[TestCleanup()]
//public void MyTestCleanup()
//{
//}
//
#endregion
/// <summary>
///A test for Interpret
///</summary>
[TestMethod()]
public void InterpretTest()
{
InputInterpreter target = new InputInterpreter();
target.CodedFunctions.Add(CodedFunctionFactory.Create("addfive", 1, rf => rf[0] + 5));
//HighLoadTest(target, "+1");
//HighLoadTest(target, "+sin(1)");
//HighLoadTest(target, "+precision(0.123456789, 7)");
//HighLoadTest(target, "+2*(2 + 5)/tan(sin(4))");
//HighLoadTest(target, "+2*2/3-1.23456");
ExpressionDecimalTest(target, "2+2", 4);
ExpressionDecimalTest(target, "1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10", 55);
ExpressionDecimalTest(target, "4 + 2 / 1 - 3 * 2", 0);
ExpressionDecimalTest(target, "16*2 - 2*3", 26);
ExpressionDecimalTest(target, "7-6+3*2", 7);
ExpressionDecimalTest(target, "1/-2*-1", 0.5M);
ExpressionDecimalTest(target, "12 + 26 / -2 + 3", 2);
ExpressionDecimalTest(target, "0.02395/1000", 0.00002395M);
ExpressionDecimalTest(target, "0100010101b", 277);
ExpressionDecimalTest(target, "0xabcdef", 11259375);
ExpressionDecimalTest(target, "11111111b + 0xFF", 510);
ExpressionDecimalTest(target, "10011001b * 0x01bAc", 1083852);
ExpressionDecimalTest(target, "log(sin(((25*200) - 5000)^1943),2)", decimal.MinValue);
ExpressionDecimalTest(target, "log(cos(((25*200) - 5000)^1943),2)", 0);
ExpressionDecimalTest(target, "cos(2^3)", -0.145500033808614M);
ExpressionDecimalTest(target, "addfive(30)", 35);
ExpressionDecimalTest(target, "precision(1.23456789, 4)", 1.2346M);
ExpressionDecimalTest(target, "3000 * (log(1 + 3162, 2))", 34881.2335215522M);
ExpressionDecimalTest(target, "(((12)))", 12);
ExpressionOutputTest(target, "z := (3*x) - (2*y)", "(3*x)-(2*y)");
ExpressionOutputTest(target, "x :: 3", "3");
ExpressionOutputTest(target, "y :: 2", "2");
ExpressionOutputTest(target, "x", "3");
ExpressionOutputTest(target, "y", "2");
ExpressionOutputTest(target, "z", "5");
ExpressionOutputTest(target, "z + 2", "7");
ExpressionOutputTest(target, "y :: 3", "3");
ExpressionOutputTest(target, "z", "3");
ExpressionOutputTest(target, "arr -> [3,6,9,12]", "3,6,9,12");
ExpressionOutputTest(target, "arr[1]", "6");
ExpressionOutputTest(target, "arr[1+1]", "9");
ExpressionOutputTest(target, "arr[2+44]", "0");
ExpressionOutputTest(target, "log(sin(((25*200) - 5000)^1943),2)", "log(sin(((25*200) - 5000)^1943),2)".Interpret());
ExpressionOutputTest(target, "log(cos(((25*200) - 5000)^1943),2)", "log(cos(((25*200) - 5000)^1943),2)".Interpret());
}
[TestMethod]
public void AsyncTest()
{
InputInterpreter interpreter = new InputInterpreter();
interpreter.InterpretAsync("2 + 2", i =>
{
Assert.IsTrue(i.Output == "4");
});
}
[TestMethod]
public void ComputableTest()
{
InputInterpreter interpreter = new InputInterpreter();
interpreter.Interpret("1");
Assert.IsTrue(interpreter.AsComputable(c => c.Add(5)).Resolve().Decimal == 6);
Assert.IsTrue(interpreter.AsComputable(c => c.Subtract(5)).Resolve().Decimal == 1);
Assert.IsTrue(interpreter.AsComputable(c => c.Multiply(5)).Resolve().Decimal == 5);
Assert.IsTrue(interpreter.AsComputable(c => c.Divide(1)).Resolve().Decimal == 5);
Assert.IsTrue(interpreter.AsComputable(c => c.Mod(1)).Resolve().Decimal == 0);
Assert.IsTrue(interpreter.AsComputable(c => c.RaiseToPower(5)).Resolve().Decimal == 0);
interpreter.Interpret("1");
Assert.IsTrue(interpreter.ToComputable().Add(5).Resolve().Decimal == 6);
Assert.IsTrue(interpreter.ToComputable().Subtract(5).Resolve().Decimal == 1);
Assert.IsTrue(interpreter.ToComputable().Multiply(5).Resolve().Decimal == 5);
Assert.IsTrue(interpreter.ToComputable().Divide(1).Resolve().Decimal == 5);
Assert.IsTrue(interpreter.ToComputable().Mod(1).Resolve().Decimal == 0);
Assert.IsTrue(interpreter.ToComputable().RaiseToPower(5).Resolve().Decimal == 0);
interpreter.Interpret("1");
Assert.IsTrue(interpreter.AsComputable(c => c.Add(5)).ResolveTo(i => i.Decimal) == 6);
Assert.IsTrue(interpreter.AsComputable(c => c.Subtract(5)).ResolveTo(i => i.Int) == 1);
interpreter.Interpret("5");
int[] ia = new int[] { 1,2,3 };
var test = interpreter.AsComputable(computable => computable.ForAll(ia, sub => sub.RaiseToPower)).Resolve();
Assert.IsTrue(test.Output == "15625");
}
/// <summary>
/// Tests a value repeated 10,000 times and checks for an execution time less than 200 milliseconds.
/// </summary>
/// <param name="target">The input interpreter.</param>
/// <param name="value">The value to repeat and test.</param>
public void HighLoadTest(InputInterpreter target, string value)
{
StringBuilder builder = new StringBuilder();
string input = string.Empty;
System.TimeSpan baseTime = new System.TimeSpan();
for (int i = 0; i < 1000; i++)
{
builder.Append(value);
}
input = builder.ToString();
target.Interpret(input);
baseTime = target.LastExecutionTime;
builder = new StringBuilder();
for (int i = 0; i < 100000; i++)
{
builder.Append(value);
}
input = builder.ToString();
target.Interpret(input);
Assert.IsTrue(target.LastExecutionTime <= System.TimeSpan.FromTicks((baseTime.Ticks + 1 * 100) + 100), string.Format("{0} failed the high load test.", value));
}
/// <summary>
/// Tests a given expression for a decimal result.
/// </summary>
/// <param name="target">The input interpreter.</param>
/// <param name="input">The input to execute.</param>
/// <param name="expected">The expected value.</param>
public void ExpressionDecimalTest(InputInterpreter target, string input, decimal expected)
{
target.Interpret(input);
Assert.AreEqual(expected, target.Decimal, string.Format("{0} returned {1} but {2} was expected.", input, target.Decimal, expected));
}
/// <summary>
/// Tests a given expression for a string result.
/// </summary>
/// <param name="target">The input interpreter.</param>
/// <param name="input">The input to execute.</param>
/// <param name="expected">The expected value.</param>
public void ExpressionOutputTest(InputInterpreter target, string input, string expected)
{
target.Interpret(input);
Assert.AreEqual(expected, target.Output, string.Format("{0} returned {1} but {2} was expected.", input, target.Decimal, expected));
}
}
}

View file

@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CSMICTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CSMICTests")]
[assembly: AssemblyCopyright("Copyright © 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM componenets. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("8e6bded0-27ba-4d6b-a785-988958ca4b10")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View file

@ -0,0 +1,2 @@
csmic.dll
Desktop

View file

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<!-- The configuration and platform will be used to determine which
assemblies to include from solution and project documentation
sources -->
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{b60970b9-771a-4ebb-9978-89f55163888f}</ProjectGuid>
<SHFBSchemaVersion>1.9.5.0</SHFBSchemaVersion>
<!-- AssemblyName, Name, and RootNamespace are not used by SHFB but Visual
Studio adds them anyway -->
<AssemblyName>HelpFile</AssemblyName>
<RootNamespace>HelpFile</RootNamespace>
<Name>HelpFile</Name>
<!-- SHFB properties -->
<OutputPath>.\Help\</OutputPath>
<HtmlHelpName>csmic_help</HtmlHelpName>
<Language>en-US</Language>
<HelpFileFormat>HtmlHelp1, Website</HelpFileFormat>
<IndentHtml>False</IndentHtml>
<FrameworkVersion>.NET Framework 4.0</FrameworkVersion>
<KeepLogFile>True</KeepLogFile>
<DisableCodeBlockComponent>False</DisableCodeBlockComponent>
<CppCommentsFixup>False</CppCommentsFixup>
<CleanIntermediates>True</CleanIntermediates>
<SyntaxFilters>Standard</SyntaxFilters>
<SdkLinkTarget>Blank</SdkLinkTarget>
<RootNamespaceTitle>csmic</RootNamespaceTitle>
<RootNamespaceContainer>True</RootNamespaceContainer>
<PresentationStyle>VS2010</PresentationStyle>
<Preliminary>False</Preliminary>
<NamingMethod>Guid</NamingMethod>
<HelpTitle>CS-MIC - C Sharp Math Input Control</HelpTitle>
<FooterText>Please visit the &amp;lt%3ba href=&amp;quot%3bhttp://cs-mic.com&amp;quot%3b&amp;gt%3bofficial site&amp;lt%3b/a&amp;gt%3b for more information.</FooterText>
<FeedbackEMailLinkText>Please feel free to provide feedback!</FeedbackEMailLinkText>
<FeedbackEMailAddress>jordan%40jordanwages.com</FeedbackEMailAddress>
<CopyrightText>Copyright 2012</CopyrightText>
<ContentPlacement>AboveNamespaces</ContentPlacement>
<WebsiteSdkLinkType>Msdn</WebsiteSdkLinkType>
<HtmlSdkLinkType>Msdn</HtmlSdkLinkType>
<IncludeFavorites>True</IncludeFavorites>
<BinaryTOC>True</BinaryTOC>
<ProjectSummary>CS-MIC is a .NET library written in C# designed to give developers easy access to expression parsing. For many developers, there is no need to involve complicated settings and formats. With few exposed methods and objects, CS-MIC makes basic expression solving as simple as possible with as little logic required from developers as possible. In fact, one can pull a value with only one line of code.</ProjectSummary>
<VisibleItems>Attributes, ExplicitInterfaceImplementations, InheritedMembers, InheritedFrameworkMembers, Internals, Protected, SealedProtected</VisibleItems>
<DocumentationSources>
<DocumentationSource sourceFile="..\csmic\bin\Release\csmic.dll" />
<DocumentationSource sourceFile="..\csmic\bin\Release\csmic.xml" />
</DocumentationSources>
<ApiFilter />
<ComponentConfigurations />
<HelpAttributes />
<NamespaceSummaries />
<PlugInConfigurations />
<BuildLogFile />
<HtmlHelp1xCompilerPath />
<HtmlHelp2xCompilerPath />
<SandcastlePath />
<WorkingPath />
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>
<!-- There are no properties for these groups. AnyCPU needs to appear in
order for Visual Studio to perform the build. The others are optional
common platform types that may appear. -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|Win32' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|Win32' ">
</PropertyGroup>
<!-- Import the SHFB build targets -->
<Import Project="$(SHFBROOT)\SandcastleHelpFileBuilder.targets" />
</Project>

View file

@ -0,0 +1,10 @@
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = ""
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
}

54
CS-MIC/csmic/csmic.sln Normal file
View file

@ -0,0 +1,54 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csmic", "csmic\csmic.csproj", "{7BBA4BA2-E885-4D89-8710-F1A609616B7D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSMICTests", "CSMICTests\CSMICTests.csproj", "{C03AD9DF-630F-4C88-A9D4-8B4B450CCB54}"
EndProject
Project("{7CF6DF6D-3B04-46F8-A40B-537D21BCA0B4}") = "HelpFile", "HelpFile\HelpFile.shfbproj", "{B60970B9-771A-4EBB-9978-89F55163888F}"
EndProject
Global
GlobalSection(TeamFoundationVersionControl) = preSolution
SccNumberOfProjects = 4
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
SccTeamFoundationServer = https://tfs.codeplex.com/tfs/tfs35
SccLocalPath0 = .
SccProjectUniqueName1 = csmic\\csmic.csproj
SccProjectName1 = csmic
SccLocalPath1 = csmic
SccProjectUniqueName2 = CSMICTests\\CSMICTests.csproj
SccProjectName2 = CSMICTests
SccLocalPath2 = CSMICTests
SccProjectUniqueName3 = HelpFile\\HelpFile.shfbproj
SccProjectName3 = HelpFile
SccLocalPath3 = HelpFile
EndGlobalSection
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = csmic8.vsmdi
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7BBA4BA2-E885-4D89-8710-F1A609616B7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7BBA4BA2-E885-4D89-8710-F1A609616B7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7BBA4BA2-E885-4D89-8710-F1A609616B7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7BBA4BA2-E885-4D89-8710-F1A609616B7D}.Release|Any CPU.Build.0 = Release|Any CPU
{C03AD9DF-630F-4C88-A9D4-8B4B450CCB54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C03AD9DF-630F-4C88-A9D4-8B4B450CCB54}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C03AD9DF-630F-4C88-A9D4-8B4B450CCB54}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C03AD9DF-630F-4C88-A9D4-8B4B450CCB54}.Release|Any CPU.Build.0 = Release|Any CPU
{B60970B9-771A-4EBB-9978-89F55163888F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B60970B9-771A-4EBB-9978-89F55163888F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B60970B9-771A-4EBB-9978-89F55163888F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B60970B9-771A-4EBB-9978-89F55163888F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(SubversionScc) = preSolution
Svn-Managed = True
Manager = AnkhSVN - Subversion Support for Visual Studio
EndGlobalSection
EndGlobal

10
CS-MIC/csmic/csmic.vssscc Normal file
View file

@ -0,0 +1,10 @@
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = ""
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT"
}

View file

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace csmic
{
/// <summary> Coded function factory. </summary>
/// <remarks>
/// This class generates new coded functions dynamically.
/// </remarks>
public static class CodedFunctionFactory
{
/// <summary> Creates a new ICodedFunction interface object that implements the dynamic method described. </summary>
/// <param name="functionName"> Name of the function. </param>
/// <param name="numExpectedArguments"> Number of expected arguments. </param>
/// <param name="methodBody"> The method body. </param>
/// <returns> An ICodedFunction interface object. </returns>
public static ICodedFunction Create(string functionName, int numExpectedArguments, Func<decimal[], decimal> methodBody)
{
return new GenericCodedFunction(functionName, numExpectedArguments, methodBody);
}
}
}

View file

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace csmic.CodedFunctions
{
/// <summary>
/// A coded implementation of the absolute value function.
/// </summary>
class CF_Abs : ICodedFunction
{
#region ICodedFunction Members
/// <summary>
/// Expects 1 argument.
/// </summary>
public int NumExpectedArguments
{
get { return 1; }
}
/// <summary>
/// The name of the function.
/// </summary>
public string FunctionName
{
get { return "abs"; }
}
/// <summary>
/// Executes a code block.
/// </summary>
/// <param name="args">The arguments used in the code block.</param>
/// <returns>The absolute value of the argument.</returns>
public decimal Execute(params decimal[] args)
{
decimal output = 0;
if (args.Length == this.NumExpectedArguments)
{
decimal input = args[0];
output = Math.Abs(input);
}
return output;
}
#endregion
}
}

View file

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace csmic.CodedFunctions
{
/// <summary>
/// A coded implementation of the cosine function.
/// </summary>
class CF_Cos : ICodedFunction
{
#region ICodedFunction Members
/// <summary>
/// Expects 1 argument.
/// </summary>
public int NumExpectedArguments
{
get { return 1; }
}
/// <summary>
/// The name of the function.
/// </summary>
public string FunctionName
{
get { return "cos"; }
}
/// <summary>
/// Executes a code block.
/// </summary>
/// <param name="args">The arguments used in the code block.</param>
/// <returns>The cosine of the argument.</returns>
public decimal Execute(params decimal[] args)
{
decimal output = 0;
if (args.Length == this.NumExpectedArguments)
{
decimal input = args[0];
output = (decimal)Math.Cos((double)input);
}
return output;
}
#endregion
}
}

View file

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace csmic.CodedFunctions
{
/// <summary>
/// A coded implementation of the exponential function based on the constant e.
/// </summary>
class CF_Exp : ICodedFunction
{
#region ICodedFunction Members
/// <summary>
/// Expects 1 argument.
/// </summary>
public int NumExpectedArguments
{
get { return 1; }
}
/// <summary>
/// The name of the function.
/// </summary>
public string FunctionName
{
get { return "exp"; }
}
/// <summary>
/// Executes a code block.
/// </summary>
/// <param name="args">The arguments used in the code block.</param>
/// <returns>The constant e raised to the power of the argument.</returns>
public decimal Execute(params decimal[] args)
{
decimal output = 0;
if (args.Length == this.NumExpectedArguments)
{
decimal input = args[0];
output = (decimal)Math.Exp((double)input);
}
return output;
}
#endregion
}
}

View file

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace csmic.CodedFunctions
{
/// <summary>
/// A coded implementation of the log function.
/// </summary>
class CF_Log : ICodedFunction
{
#region ICodedFunction Members
/// <summary>
/// Expects 2 arguments.
/// </summary>
public int NumExpectedArguments
{
get { return 2; }
}
/// <summary>
/// The name of the function.
/// </summary>
public string FunctionName
{
get { return "log"; }
}
/// <summary>
/// Executes a code block.
/// </summary>
/// <param name="args">The arguments used in the code block.</param>
/// <returns>The log of the first argument to the base of the second argument.</returns>
public decimal Execute(params decimal[] args)
{
decimal output = 0;
if (args.Length == this.NumExpectedArguments)
{
decimal input = args[0];
decimal logBase = args[1];
try
{
output = (decimal)Math.Log((double)input, (double)logBase);
}
catch
{
output = decimal.MinValue;
}
}
return output;
}
#endregion
}
}

View file

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace csmic.CodedFunctions
{
/// <summary>
/// A coded implementation of a precision function.
/// </summary>
class CF_Precision : ICodedFunction
{
#region ICodedFunction Members
/// <summary>
/// Expects 2 arguments.
/// </summary>
public int NumExpectedArguments
{
get { return 2; }
}
/// <summary>
/// The name of the function.
/// </summary>
public string FunctionName
{
get { return "precision"; }
}
/// <summary>
/// Executes a code block.
/// </summary>
/// <param name="args">The arguments used in the code block.</param>
/// <returns>The first argument to the precision of the argument.</returns>
public decimal Execute(params decimal[] args)
{
decimal output = 0;
if (args.Length == this.NumExpectedArguments)
{
decimal input = args[0];
decimal precision = args[1];
output = (decimal)Math.Round(input, (int)precision);
}
return output;
}
#endregion
}
}

View file

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace csmic.CodedFunctions
{
/// <summary>
/// A coded implementation of a rounded function.
/// </summary>
class CF_Round : ICodedFunction
{
#region ICodedFunction Members
/// <summary>
/// Expects 1 argument.
/// </summary>
public int NumExpectedArguments
{
get { return 1; }
}
/// <summary>
/// The name of the function.
/// </summary>
public string FunctionName
{
get { return "round"; }
}
/// <summary>
/// Executes a code block.
/// </summary>
/// <param name="args">The arguments used in the code block.</param>
/// <returns>The rounded argument.</returns>
public decimal Execute(params decimal[] args)
{
decimal output = 0;
if (args.Length == this.NumExpectedArguments)
{
decimal input = args[0];
output = Math.Round(input);
}
return output;
}
#endregion
}
}

View file

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace csmic.CodedFunctions
{
/// <summary>
/// A coded implementation of the sine function.
/// </summary>
class CF_Sin : ICodedFunction
{
#region ICodedFunction Members
/// <summary>
/// Expects 1 argument.
/// </summary>
public int NumExpectedArguments
{
get { return 1; }
}
/// <summary>
/// The name of the function.
/// </summary>
public string FunctionName
{
get { return "sin"; }
}
/// <summary>
/// Executes a code block.
/// </summary>
/// <param name="args">The arguments used in the code block.</param>
/// <returns>The sine of the argument.</returns>
public decimal Execute(params decimal[] args)
{
decimal output = 0;
if (args.Length == this.NumExpectedArguments)
{
decimal input = args[0];
output = (decimal)Math.Sin((double)input);
}
return output;
}
#endregion
}
}

View file

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace csmic.CodedFunctions
{
/// <summary>
/// A coded implementation of the squre root function.
/// </summary>
class CF_Sqrt : ICodedFunction
{
#region ICodedFunction Members
/// <summary>
/// Expects 1 argument.
/// </summary>
public int NumExpectedArguments
{
get { return 1; }
}
/// <summary>
/// The name of the function.
/// </summary>
public string FunctionName
{
get { return "sqrt"; }
}
/// <summary>
/// Executes a code block.
/// </summary>
/// <param name="args">The arguments used in the code block.</param>
/// <returns>The square root of the argument.</returns>
public decimal Execute(params decimal[] args)
{
decimal output = 0;
if (args.Length == this.NumExpectedArguments)
{
decimal input = args[0];
output = (decimal)Math.Sqrt((double)input);
}
return output;
}
#endregion
}
}

View file

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace csmic.CodedFunctions
{
/// <summary>
/// A coded implementation of the tangent function.
/// </summary>
class CF_Tan : ICodedFunction
{
#region ICodedFunction Members
/// <summary>
/// Expects 1 argument.
/// </summary>
public int NumExpectedArguments
{
get { return 1; }
}
/// <summary>
/// The name of the function.
/// </summary>
public string FunctionName
{
get { return "tan"; }
}
/// <summary>
/// Executes a code block.
/// </summary>
/// <param name="args">The arguments used in the code block.</param>
/// <returns>The tangent of the argument.</returns>
public decimal Execute(params decimal[] args)
{
decimal output = 0;
if (args.Length == this.NumExpectedArguments)
{
decimal input = args[0];
output = (decimal)Math.Tan((double)input);
}
return output;
}
#endregion
}
}

View file

@ -0,0 +1,182 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace csmic.ComputableEngine
{
/// <summary> Computable class. </summary>
public sealed class Computable
{
#region Members
/// <summary> The expression to be built.</summary>
private string expression;
/// <summary> The interpreter to act as a base.</summary>
private InputInterpreter interpreter;
#region Constants
/// <summary> The add symbol.</summary>
private const string ADD = "+";
/// <summary> The substract symbol.</summary>
private const string SUBSTRACT = "-";
/// <summary> The divide symbol.</summary>
private const string DIVIDE = "/";
/// <summary> The multiply symbol.</summary>
private const string MULTIPLY = "*";
/// <summary> The modifier symbol.</summary>
private const string MOD = "%";
/// <summary> The power symbol.</summary>
private const string POWER = "^";
#endregion
#endregion
#region Properties
/// <summary> Gets the expression. </summary>
/// <value> The expression. </value>
internal string Expression
{
get
{
return this.expression;
}
}
#endregion
#region Constructor
/// <summary> Creates a Computable instance. </summary>
/// <param name="expression"> The expression. </param>
/// <param name="interpreter"> The interpreter. </param>
internal Computable(string expression, InputInterpreter interpreter)
{
this.expression = expression;
this.interpreter = interpreter;
}
#endregion
#region Methods
/// <summary> Resolves the computable as an input interpreter having calculated the input. </summary>
/// <returns> The computable as an input interpreter. </returns>
public InputInterpreter Resolve()
{
this.interpreter.Interpret(this.Expression);
return this.interpreter;
}
/// <summary> Resolve the computer to a type <typeparamref name="T"/>. </summary>
/// <typeparam name="T"> Generic type parameter. </typeparam>
/// <param name="selector"> The selector function. </param>
/// <returns> . </returns>
public T ResolveTo<T>(Func<InputInterpreter, T> selector)
{
return selector(this.Resolve());
}
/// <summary> Form the operation given the operation constant and an argument. </summary>
/// <param name="operation"> The operation constant. </param>
/// <param name="argument"> The argument. </param>
/// <returns> A string with the given operation appended. </returns>
private string FormOperation(string operation, object argument)
{
return string.Format("({0} {1} {2})", this.Expression, operation, argument);
}
/// <summary> Form the function <paramref name="name"/> with the current expression as the first argument, followed by <paramref name="arguments"/>. </summary>
/// <param name="name"> The name of the function. </param>
/// <param name="arguments"> The arguments. </param>
/// <returns> . </returns>
private string FormFunction(string name, object[] arguments)
{
return string.Format("{0}({1})", name, string.Join(",", this.Expression, arguments));
}
/// <summary> Adds addend. </summary>
/// <param name="addend"> The decimal to add. </param>
/// <returns> A computable class after the addition. </returns>
public Computable Add(decimal addend)
{
this.expression = FormOperation(ADD, addend);
return this;
}
/// <summary> Subtracts the subtrahend. </summary>
/// <param name="subtrahend"> The subtrahend. </param>
/// <returns> A computable class after the subtraction. </returns>
public Computable Subtract(decimal subtrahend)
{
this.expression = FormOperation(SUBSTRACT, subtrahend);
return this;
}
/// <summary> Multiplies the multiplicand. </summary>
/// <param name="multiplicand"> The multiplicand. </param>
/// <returns> A computable class after the mulitplication. </returns>
public Computable Multiply(decimal multiplicand)
{
this.expression = FormOperation(MULTIPLY, multiplicand);
return this;
}
/// <summary> Divides the divisor. </summary>
/// <param name="divisor"> The divisor. </param>
/// <returns> A computable class after the divison. </returns>
public Computable Divide(decimal divisor)
{
this.expression = FormOperation(DIVIDE, divisor);
return this;
}
/// <summary> Mods using a given divisor. </summary>
/// <param name="divisor"> The divisor. </param>
/// <returns> A computable class after the mod. </returns>
public Computable Mod(decimal divisor)
{
this.expression = FormOperation(MOD, divisor);
return this;
}
/// <summary> Raises to power of the given integer value. </summary>
/// <param name="power"> The power. </param>
/// <returns> A computable class after the power operation. </returns>
public Computable RaiseToPower(int power)
{
this.expression = FormOperation(POWER, power);
return this;
}
/// <summary> Applies the function <paramref name="name"/> with the current expression as the first argument, followed by <paramref name="arguments"/>. </summary>
/// <param name="name"> The name of the function. </param>
/// <param name="arguments"> The arguments. </param>
/// <returns> A computable class after the function is applied. </returns>
public Computable ApplyFunction(string name, object[] arguments)
{
this.expression = FormFunction(name, arguments);
return this;
}
/// <summary> Executes a command for all items in a collection. </summary>
/// <typeparam name="T"> Generic type parameter. </typeparam>
/// <param name="items"> The items of type <typeparamref name="T"/>. </param>
/// <param name="action"> The action belonging to type <see cref="Computable"/>. </param>
/// <returns> . </returns>
public Computable ForAll<T>(ICollection<T> items, Func<Computable, Func<T, Computable>> action)
{
foreach (T item in items)
{
action(this)(item);
}
return this;
}
#endregion
}
}

View file

@ -0,0 +1,178 @@
using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Linq;
using System.Text;
namespace csmic.Extensions
{
/// <summary> CS-MIC extension methods. </summary>
public static class CSMICExtension
{
#region String
/// <summary> A string extension method that interprets as input the string that calls it. </summary>
/// <param name="input"> The input to act on. </param>
/// <returns> The output from the interpretation of the string. </returns>
public static string Interpret(this string input)
{
InputInterpreter interpreter = new InputInterpreter();
interpreter.Interpret(input);
return interpreter.Output;
}
/// <summary> A string extension method that executes as macro operation. </summary>
/// <param name="script"> The script to act on. </param>
/// <returns> The final output of the script. </returns>
public static string RunAsMacro(this string script)
{
MacroBuilder macro = new MacroBuilder(script, new InputInterpreter());
return macro.FinalOutput;
}
#endregion
#region IEnumerable<string>
/// <summary>
/// A string extension method that interprets as input the string that calls it.
/// </summary>
/// <param name="collection"> The collection to act on. </param>
/// <returns> The output from the interpretation of the string. </returns>
public static IEnumerable<string> Interpret(this IEnumerable<string> collection)
{
List<string> computed = new List<string>();
InputInterpreter interpreter = new InputInterpreter();
foreach (string input in collection)
{
interpreter.Interpret(input);
computed.Add(interpreter.Output);
}
return computed;
}
/// <summary>
/// A string extension method that interprets as input the string that calls it.
/// </summary>
/// <param name="collection"> The collection to act on. </param>
/// <param name="action"> The action. </param>
/// <returns> The output from the interpretation of the string. </returns>
public static IEnumerable<string> Interpret(this IEnumerable<string> collection, Action<InputInterpreter> action)
{
List<string> computed = new List<string>();
InputInterpreter interpreter = new InputInterpreter();
foreach (string input in collection)
{
interpreter.Interpret(input);
computed.Add(interpreter.Output);
action(interpreter);
}
return computed;
}
/// <summary> Enumerates input in this collection, returning a selection on the interpreter. </summary>
/// <typeparam name="T"> Generic type parameter. </typeparam>
/// <param name="collection"> The collection to act on. </param>
/// <param name="selection"> The selection. </param>
/// <returns>
/// An enumerator that allows foreach to be used to process interpret&lt; t&gt; in this
/// collection.
/// </returns>
public static IEnumerable<T> Interpret<T>(this IEnumerable<string> collection, Func<InputInterpreter, T> selection)
{
List<T> computed = new List<T>();
InputInterpreter interpreter = new InputInterpreter();
foreach (string input in collection)
{
interpreter.Interpret(input);
computed.Add(selection(interpreter));
}
return computed;
}
/// <summary> A string extension method that executes as macro operation. </summary>
/// <param name="collection"> The collection to act on. </param>
/// <returns> The final output of the script. </returns>
public static MacroBuilder RunAsMacro(this IEnumerable<string> collection)
{
return new MacroBuilder(string.Join(Environment.NewLine, collection.ToArray()), new InputInterpreter());
}
#endregion
#region IEnumerable<string> In Parallel
/// <summary> Enumerates input in parallel in this collection. </summary>
/// <param name="collection"> The collection to act on. </param>
/// <returns>
/// An enumerator that allows foreach to be used to process interpret in parallel in this
/// collection.
/// </returns>
public static IEnumerable<InputInterpreter> InterpretInParallel(this IEnumerable<string> collection)
{
ConcurrentBag<InputInterpreter> bag = new ConcurrentBag<InputInterpreter>();
collection.AsParallel().ForAll(input =>
{
InputInterpreter interpreter = new InputInterpreter();
interpreter.Interpret(input);
bag.Add(interpreter);
});
return bag;
}
/// <summary> Enumerates input in parallel this collection, returning a selection on the interpreter. </summary>
/// <typeparam name="T"> Generic type parameter. </typeparam>
/// <param name="collection"> The collection to act on. </param>
/// <param name="selection"> The selection. </param>
/// <returns>
/// An enumerator that allows foreach to be used to process interpret in parallel&lt; t&gt; in
/// this collection.
/// </returns>
public static IEnumerable<T> InterpretInParallel<T>(this IEnumerable<string> collection, Func<InputInterpreter, T> selection)
{
ConcurrentBag<T> bag = new ConcurrentBag<T>();
collection.AsParallel().ForAll(input =>
{
InputInterpreter interpreter = new InputInterpreter();
interpreter.Interpret(input);
bag.Add(selection(interpreter));
});
return bag;
}
#endregion
#region ParallelQuery<string>
/// <summary>
/// A string extension method that interprets as input the strings that calls it in parallel.
/// </summary>
/// <param name="collection"> The collection to act on. </param>
/// <returns> The output from the interpretation of the string. </returns>
public static IEnumerable<InputInterpreter> Interpret(this ParallelQuery<string> collection)
{
ConcurrentBag<InputInterpreter> bag = new ConcurrentBag<InputInterpreter>();
collection.ForAll(input =>
{
InputInterpreter interpreter = new InputInterpreter();
interpreter.Interpret(input);
bag.Add(interpreter);
});
return bag;
}
#endregion
}
}

View file