Add dynamic context and bot.builder project

This commit is contained in:
Shahin Shayandeh 2017-07-19 12:55:43 -07:00
Коммит f8c6d9ac90
8 изменённых файлов: 522 добавлений и 0 удалений

239
.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1,239 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
ecf/
rcf/
# Visual Studio 2015 cache/options directory
.vs/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
*.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
_NCrunch_*
.*crunch*.local.xml
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
## TODO: Comment the next line if you want to checkin your
## web deploy settings but do note that will include unencrypted
## passwords
#*.pubxml
## ignore imporeted publish xml files
*intercom-botdirectory-scratch\ -\ FTP.pubxml
*intercom-botdirectory-scratch\ -\ Web\ Deploy.pubxml
*.publishproj
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# Windows Azure Build Output
csx/
*.build.csdef
# Windows Store app package directory
AppPackages/
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# LightSwitch generated files
GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml
/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll
/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.xml
/PublishScripts/Scripts/Deploy-AzureResourceGroup-5.ps1
/PublishScripts
# User-specific files
Documentation/Doxygen_warnings.txt
# Build results
Documentation/docs/
# Azure publish profiles
*.pubxml
PublishProfiles/

28
Microsoft.Bot.Builder.sln Normal file
Просмотреть файл

@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Bot.Builder", "library\Microsoft.Bot.Builder\Microsoft.Bot.Builder.csproj", "{74908F42-3842-49B4-9344-60BB791FDE32}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Bot.Builder.Tests", "test\Microsoft.Bot.Builder.Tests\Microsoft.Bot.Builder.Tests.csproj", "{07D54838-D4F7-4CA1-9EED-E5C1470D584C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{74908F42-3842-49B4-9344-60BB791FDE32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{74908F42-3842-49B4-9344-60BB791FDE32}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74908F42-3842-49B4-9344-60BB791FDE32}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74908F42-3842-49B4-9344-60BB791FDE32}.Release|Any CPU.Build.0 = Release|Any CPU
{07D54838-D4F7-4CA1-9EED-E5C1470D584C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07D54838-D4F7-4CA1-9EED-E5C1470D584C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07D54838-D4F7-4CA1-9EED-E5C1470D584C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07D54838-D4F7-4CA1-9EED-E5C1470D584C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Просмотреть файл

@ -0,0 +1,92 @@
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Reflection;
namespace Microsoft.Bot.Builder
{
public class DynamicContext : DynamicObject
{
private Dictionary<string, object> dynamicProperties { get; set; } = new Dictionary<string, object>();
private string[] _objectProperties = null;
protected string[] objectProperties
{
get
{
if (_objectProperties == null)
{
lock (dynamicProperties)
{
if (_objectProperties == null)
_objectProperties = this.GetType().GetTypeInfo().DeclaredProperties
.Where(pi => pi.Name != "Item")
.Select(pi => pi.Name)
.ToArray();
}
}
return _objectProperties;
}
}
public override System.Collections.Generic.IEnumerable<string> GetDynamicMemberNames()
{
foreach (var p in this.objectProperties)
yield return p;
foreach (var key in this.dynamicProperties.Keys)
yield return key;
yield break;
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
return TryGetMember(binder.Name, out result);
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
return TrySetMember(binder.Name, value);
}
public dynamic this[string name]
{
get
{
object value;
this.TryGetMember(name, out value);
return value;
}
set { this.dynamicProperties[name] = value; }
}
private bool TryGetMember(string name, out object result)
{
if (this.dynamicProperties.ContainsKey(name))
{
result = this.dynamicProperties[name];
return true;
}
else if (this.objectProperties.Contains(name))
{
var prop = this.GetType().GetTypeInfo().GetDeclaredProperty(name);
result = prop.GetValue(this);
return true;
}
result = null;
return false;
}
private bool TrySetMember(string name, object value)
{
var prop = this.GetType().GetTypeInfo().GetDeclaredProperty(name);
if (prop != null)
{
prop.SetValue(this, value);
return true;
}
dynamicProperties[name] = value;
return true;
}
}
}

Просмотреть файл

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Dynamic.Runtime" Version="4.3.0" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,53 @@
using System;
using System.Dynamic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.Bot.Builder.Tests
{
[TestClass]
public class DynamicContextTests
{
[TestMethod]
public void DynamicContext_DynamicProperties()
{
var testValue = "testValue";
var context = new DynamicContext();
context["test"] = testValue;
Assert.AreEqual(context["test"], "testValue");
}
class Context : DynamicContext
{
public string Name { get; set; }
}
class TestBinder : GetMemberBinder
{
public TestBinder(string name, bool ignoreCase) : base(name, ignoreCase)
{
}
public override DynamicMetaObject FallbackGetMember(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
{
throw new NotImplementedException();
}
}
[TestMethod]
public void DynamicContext_AccessDeclaredProperties()
{
var testValue = "testValue";
dynamic context = new Context();
context.Name = testValue;
context.Test = testValue;
Assert.AreEqual(context.Name, context.Test);
object value;
Assert.IsTrue((context as Context).TryGetMember(new TestBinder("Name", false), out value));
Assert.AreEqual(testValue, value as string);
}
}
}

Просмотреть файл

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{07D54838-D4F7-4CA1-9EED-E5C1470D584C}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Bot.Builder.Tests</RootNamespace>
<AssemblyName>Microsoft.Bot.Builder.Tests</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</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>
</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>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="DynamicContextTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\library\Microsoft.Bot.Builder\Microsoft.Bot.Builder.csproj">
<Project>{74908f42-3842-49b4-9344-60bb791fde32}</Project>
<Name>Microsoft.Bot.Builder</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.targets'))" />
</Target>
<Import Project="..\..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.targets')" />
</Project>

Просмотреть файл

@ -0,0 +1,20 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("Microsoft.Bot.Builder.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Microsoft.Bot.Builder.Tests")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("07d54838-d4f7-4ca1-9eed-e5c1470d584c")]
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Просмотреть файл

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MSTest.TestAdapter" version="1.1.11" targetFramework="net461" />
<package id="MSTest.TestFramework" version="1.1.11" targetFramework="net461" />
</packages>