本文整理汇总了C#中Application.CreateQueryTemplate方法的典型用法代码示例。如果您正苦于以下问题:C# Application.CreateQueryTemplate方法的具体用法?C# Application.CreateQueryTemplate怎么用?C# Application.CreateQueryTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Application
的用法示例。
在下文中一共展示了Application.CreateQueryTemplate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateQuery
/// <summary>
/// Creates and binds a query with a single input stream.
/// </summary>
private static Query CreateQuery(Application application, CepStream<EventType> streamDefinition, Uri inputAddress, Uri outputAddress)
{
QueryTemplate template = application.CreateQueryTemplate("QueryTemplate", null, streamDefinition);
QueryBinder binder = new QueryBinder(template);
InputAdapter inputAdapter = application.CreateInputAdapter<WcfInputAdapterFactory>("InputAdapter", null);
binder.BindProducer("Input", inputAdapter, inputAddress, EventShape.Point);
OutputAdapter outputAdapter = application.CreateOutputAdapter<WcfOutputAdapterFactory>("OutputAdapter", null);
binder.AddConsumer("Output", outputAdapter, outputAddress, EventShape.Point, StreamEventOrder.FullyOrdered);
Query query = application.CreateQuery("Query", null, binder);
return query;
}
示例2: CreateQuery
private static Query CreateQuery(Application application, CepStream<BrandQuote> streamDefinition, BrandQuoteInputConfig inputConfig, BrandQuoteOutputConfig outputConfig)
{
var template = application.CreateQueryTemplate("QueryTemplate", null, streamDefinition);
var binder = new QueryBinder(template);
var inputAdapter = application.CreateInputAdapter<BrandQuoteInputAdapterFactory>("InputAdapter", null);
binder.BindProducer("Input", inputAdapter, inputConfig, EventShape.Point);
var outputAdapter = application.CreateOutputAdapter<BrandQuoteOutputAdapterFactory>("OutputAdapter", null);
binder.AddConsumer("Output", outputAdapter, outputConfig, EventShape.Point, StreamEventOrder.FullyOrdered);
var query = application.CreateQuery("Query", null, binder);
return query;
}
示例3: CreateQueryTemplate
/// <summary>
/// Contains the query logic in form of a query template.
/// </summary>
/// <param name="application">Application to host the query template.</param>
/// <returns>The new query template object.</returns>
private static QueryTemplate CreateQueryTemplate(Application application)
{
// Create stream objects as basis for query template
// specification. The specified names will be used when binding
// the query template's inputs to event producers.
CepStream<SensorReading> sensorStream = CepStream<SensorReading>.Create("sensorInput");
CepStream<LocationData> locationStream = CepStream<LocationData>.Create("locationInput");
// Extend duration of each sensor reading, so that they fall in
// a one-minute sliding window. Group by sensor ID and calculate the
// average vehicular count per group within each window.
// Include the grouping key in the aggregation result.
var avgCount = from oneMinReading in sensorStream.AlterEventDuration(e => TimeSpan.FromMinutes(1))
group oneMinReading by oneMinReading.SensorId into oneGroup
from eventWindow in oneGroup.SnapshotWindow(SnapshotWindowOutputPolicy.Clip)
select new { avgCount = eventWindow.Avg(e => e.VehicularCount), SensorId = oneGroup.Key };
// Join sensors and locations. Moreover, filter the count
// result by a threshold, which is looked up based on the
// sensor location through a user-defined function.
var joined = from averageEvent in avgCount
join locationData in locationStream
on averageEvent.SensorId equals locationData.SensorId
where averageEvent.avgCount > UserFunctions.LocationCountThreshold(locationData.LocationId)
select new
{
SensorId = locationData.SensorId,
LocationID = locationData.LocationId,
VehicularCount = averageEvent.avgCount
};
return application.CreateQueryTemplate("SampleQueryTemplate", string.Empty, joined);
}
示例4: createUserFilterExampleQuery
/// <summary>
/// Example of using a user-defined filter
/// </summary>
/// <param name="application"></param>
/// <param name="inputConfig"></param>
/// <param name="outputConfig"></param>
/// <param name="inputAdapter"></param>
/// <param name="outputAdapter"></param>
/// <returns></returns>
private static Query createUserFilterExampleQuery(Application application, StockQuoteInputConfig inputConfig, StockQuoteOutputConfig outputConfig, InputAdapter inputAdapter, OutputAdapter outputAdapter)
{
var input = CepStream<StockQuote>.Create("input");
var filteredCepStream = from e in input
where UserDefinedFilter(e.FieldID)
select e;
var queryTemplate = application.CreateQueryTemplate("userFilterExampleTemplate", "Description...", filteredCepStream);
var queryBinder = new QueryBinder(queryTemplate);
queryBinder.BindProducer<StockQuote>("input", inputAdapter, inputConfig, EventShape.Point);
queryBinder.AddConsumer<StockQuote>("output", outputAdapter, outputConfig, EventShape.Point, StreamEventOrder.ChainOrdered);
var query = application.CreateQuery("userFilterExampleQuery", "Description...", queryBinder);
return query;
}
示例5: createStandardDeviationExampleQuery
/// <summary>
/// Example of using a user-defined aggregate
/// </summary>
/// <param name="application"></param>
/// <param name="inputConfig"></param>
/// <param name="outputConfig"></param>
/// <param name="inputAdapter"></param>
/// <param name="outputAdapter"></param>
/// <returns></returns>
private static Query createStandardDeviationExampleQuery(Application application, StockQuoteInputConfig inputConfig, StockQuoteOutputConfig outputConfig, InputAdapter inputAdapter, OutputAdapter outputAdapter)
{
var input = CepStream<StockQuote>.Create("input");
var stddevCepStream = from w in input.Where(e => e.FieldID == "Close")
.HoppingWindow(TimeSpan.FromDays(7), TimeSpan.FromDays(1), HoppingWindowOutputPolicy.ClipToWindowEnd)
select new StockQuote()
{
StockID = "ERIC",
FieldID = "7-day Stddev",
Value = w.StandardDeviation()
};
var queryTemplate = application.CreateQueryTemplate("standardDeviationExampleTemplate", "Description...", stddevCepStream);
var queryBinder = new QueryBinder(queryTemplate);
queryBinder.BindProducer<StockQuote>("input", inputAdapter, inputConfig, EventShape.Point);
queryBinder.AddConsumer<StockQuote>("output", outputAdapter, outputConfig, EventShape.Point, StreamEventOrder.ChainOrdered);
var query = application.CreateQuery("standardDeviationExampleQuery", "Description...", queryBinder);
return query;
}
示例6: createGroupApplyExampleQuery
/// <summary>
/// Example of a grouping and calculation of averages for the groups
/// </summary>
/// <param name="application"></param>
/// <param name="inputConfig"></param>
/// <param name="outputConfig"></param>
/// <param name="inputAdapter"></param>
/// <param name="outputAdapter"></param>
/// <returns></returns>
private static Query createGroupApplyExampleQuery(Application application, StockQuoteInputConfig inputConfig, StockQuoteOutputConfig outputConfig, InputAdapter inputAdapter, OutputAdapter outputAdapter)
{
var input = CepStream<StockQuote>.Create("input");
var ericUSDGroupCepStream = from e in input
group e by e.FieldID into eGroup
from w in eGroup.HoppingWindow(TimeSpan.FromDays(7), TimeSpan.FromDays(1), HoppingWindowOutputPolicy.ClipToWindowEnd)
select new StockQuote()
{
StockID = "ERIC 7-day avg",
FieldID = eGroup.Key,
Value = w.Avg(e => e.Value)
};
var queryTemplate = application.CreateQueryTemplate("groupApplyExampleTemplate", "Description...", ericUSDGroupCepStream);
var queryBinder = new QueryBinder(queryTemplate);
queryBinder.BindProducer<StockQuote>("input", inputAdapter, inputConfig, EventShape.Point);
queryBinder.AddConsumer<StockQuote>("output", outputAdapter, outputConfig, EventShape.Point, StreamEventOrder.ChainOrdered);
var query = application.CreateQuery("groupApplyExampleQuery", "Description...", queryBinder);
return query;
}
示例7: createCrossJoinExampleQuery
/// <summary>
/// Compare USD and SEK stock prices using given exchange rate. Example of a cross join.
/// </summary>
/// <param name="application"></param>
/// <param name="ericUSDConfig"></param>
/// <param name="ericSEKConfig"></param>
/// <param name="USDSEKConfig"></param>
/// <param name="outputConfig"></param>
/// <param name="inputAdapter"></param>
/// <param name="outputAdapter"></param>
/// <returns></returns>
private static Query createCrossJoinExampleQuery(Application application, StockQuoteInputConfig ericUSDConfig, StockQuoteInputConfig ericSEKConfig, StockQuoteInputConfig USDSEKConfig, StockQuoteOutputConfig outputConfig, InputAdapter inputAdapter, OutputAdapter outputAdapter)
{
var ericUSDStream = CepStream<StockQuote>.Create("ericUSDStream");
var ericSEKStream = CepStream<StockQuote>.Create("ericSEKStream");
var USDSEKStream = CepStream<StockQuote>.Create("USDSEKStream");
var ericRecalcCepStream = from eUSD in ericUSDStream
from eXch in USDSEKStream // Cross join
where eUSD.FieldID == "Close"
select new StockQuote()
{
StockID = "ERIC-Recalc",
FieldID = "Close",
Value = eUSD.Value * eXch.Value // Convert ERIC USD quote to SEK
};
var ericCompareCepStream = from eRecalc in ericRecalcCepStream
from eSEK in ericSEKStream
where eSEK.FieldID == "Close"
select new StockQuote()
{
StockID = "ERIC-Compare",
FieldID = "Diff",
Value = eSEK.Value - eRecalc.Value
};
var queryTemplate = application.CreateQueryTemplate("ericCompareTemplate", "Description...", ericCompareCepStream);
var queryBinder = new QueryBinder(queryTemplate);
queryBinder.BindProducer<StockQuote>("ericUSDStream", inputAdapter, ericUSDConfig, EventShape.Point);
queryBinder.BindProducer<StockQuote>("ericSEKStream", inputAdapter, ericSEKConfig, EventShape.Point);
queryBinder.BindProducer<StockQuote>("USDSEKStream", inputAdapter, USDSEKConfig, EventShape.Point);
queryBinder.AddConsumer<StockQuote>("output", outputAdapter, outputConfig, EventShape.Point, StreamEventOrder.ChainOrdered);
var query = application.CreateQuery("ericCompareQuery", "Description...", queryBinder);
return query;
}
示例8: createBigLooserExampleQuery
/// <summary>
/// Example of detecting when stock price falls more than 10% in 7 days
/// </summary>
/// <param name="application"></param>
/// <param name="inputConfig"></param>
/// <param name="outputConfig"></param>
/// <param name="inputAdapter"></param>
/// <param name="outputAdapter"></param>
/// <returns></returns>
private static Query createBigLooserExampleQuery(Application application, StockQuoteInputConfig inputConfig, StockQuoteOutputConfig outputConfig, InputAdapter inputAdapter, OutputAdapter outputAdapter)
{
var input = CepStream<StockQuote>.Create("input");
var bigLooserCepStream = (from e1 in input
from e2 in input.ShiftEventTime(e => e.StartTime.AddDays(7))
where e1.FieldID == "Close" && e2.FieldID == "Close"
select new StockQuote()
{
StockID = "ERIC > 10% drop",
FieldID = "Close",
Value = (e1.Value - e2.Value) / e2.Value * 100
}).Where(e => e.Value < -10);
var queryTemplate = application.CreateQueryTemplate("bigLooserExampleTemplate", "Description...", bigLooserCepStream);
var queryBinder = new QueryBinder(queryTemplate);
queryBinder.BindProducer<StockQuote>("input", inputAdapter, inputConfig, EventShape.Point);
queryBinder.AddConsumer<StockQuote>("output", outputAdapter, outputConfig, EventShape.Point, StreamEventOrder.ChainOrdered);
var query = application.CreateQuery("bigLooserExampleQuery", "Description...", queryBinder);
return query;
}