本文整理汇总了C#中QueryContext.Collect方法的典型用法代码示例。如果您正苦于以下问题:C# QueryContext.Collect方法的具体用法?C# QueryContext.Collect怎么用?C# QueryContext.Collect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QueryContext
的用法示例。
在下文中一共展示了QueryContext.Collect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compile
private static ServicePlan Compile(Dictionary<MethodInfo, MethodCallExpression> expressions, object serviceObject)
{
// step: collect all types, methods, variables referenced in this expression
var workerQueue = new Queue<KeyValuePair<MethodInfo, MethodCallExpression>>();
foreach (var exp in expressions)
{
workerQueue.Enqueue(new KeyValuePair<MethodInfo, MethodCallExpression>(exp.Key, exp.Value));
}
var contexts = new Dictionary<MethodInfo, QueryContext>();
while (workerQueue.Count > 0)
{
var exp = workerQueue.Dequeue();
var context = new QueryContext(serviceObject, exp.Value, exp.Key.Name);
context.Collect();
contexts.Add(exp.Key, context);
foreach (var s in context.ExternalComposedSerivce.Where(s => !contexts.ContainsKey(s.Key)))
{
workerQueue.Enqueue(new KeyValuePair<MethodInfo, MethodCallExpression>(s.Key, s.Value));
}
}
// step: prepare service plan
var codeGenerator = new CodeGenerator();
var name = serviceObject.GetType().Name + "." + codeGenerator.AppId;
var plan = new ServicePlan
{
DependentServices = contexts
.SelectMany(c => c.Value.Services.Select(r => r.Value))
.DistinctBy(s => s.URL)
.ToArray(),
Package = new ServicePackage()
};
SystemHelper.CreateOrCleanDirectory(name);
// step: generate composed service code
var sources = new HashSet<string>();
var libs = new HashSet<string>();
var dir = name + ".Source";
SystemHelper.CreateOrCleanDirectory(dir);
libs.Add(Path.Combine(Environment.GetEnvironmentVariable("DSN_ROOT"), "lib", "dsn.dev.csharp.dll"));
libs.Add(Path.Combine(Environment.GetEnvironmentVariable("DSN_ROOT"), "lib", "Thrift.dll"));
var code = codeGenerator.BuildRdsn(serviceObject.GetType(), contexts.Select(c => c.Value).ToArray());
SystemHelper.StringToFile(code, Path.Combine(dir, name + ".cs"));
sources.Add(Path.Combine(dir, name + ".cs"));
libs.UnionWith(QueryContext.KnownLibs);
// step: generate client code for all dependent services
foreach (var s in contexts
.SelectMany(c => c.Value.Services.Select(r => r.Value))
.DistinctBy(s => s.PackageName)
.Select(s => s.ExtractSpec()))
{
var provider = SpecProviderManager.Instance().GetProvider(s.SType);
Trace.Assert(null != provider, "Language provider missing for type " + s.SType);
LinkageInfo linkInfo;
var err = provider.GenerateServiceClient(s, dir, ClientLanguage.Client_CSharp, ClientPlatform.Windows, out linkInfo);
Trace.Assert(FlowErrorCode.Success == err);
sources.UnionWith(linkInfo.Sources);
libs.UnionWith(linkInfo.DynamicLibraries);
}
// step: fill service plan
plan.Package.Spec = new ServiceSpec
{
SType = ServiceSpecType.thrift,
MainSpecFile = serviceObject.GetType().Name + ".thrift",
ReferencedSpecFiles = plan.DependentServices
.DistinctBy(s => s.PackageName)
.Where(s => s.Spec.SType == ServiceSpecType.thrift)
.SelectMany(s =>
{
var spec = s.ExtractSpec();
var specFiles = new List<string> { spec.MainSpecFile };
SystemHelper.SafeCopy(Path.Combine(spec.Directory, spec.MainSpecFile),
Path.Combine(name, spec.MainSpecFile), false);
foreach (var ds in spec.ReferencedSpecFiles)
{
specFiles.Add(ds);
SystemHelper.SafeCopy(Path.Combine(spec.Directory, ds), Path.Combine(name, ds), false);
}
return specFiles;
}
)
.Distinct()
.ToList(),
Directory = name
};
plan.Package.MainSpec = ServiceContract.GenerateStandAloneThriftSpec(serviceObject.GetType(), plan.Package.Spec.ReferencedSpecFiles);
SystemHelper.StringToFile(plan.Package.MainSpec, Path.Combine(name, plan.Package.Spec.MainSpecFile));
if (SystemHelper.RunProcess("php.exe", Path.Combine(Environment.GetEnvironmentVariable("DSN_ROOT"), "bin", "dsn.generate_code.php") + " " + Path.Combine(name, plan.Package.Spec.MainSpecFile) + " csharp " + dir + " binary layer3") == 0)
//.........这里部分代码省略.........