本文整理汇总了C#中Activity.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Activity.GetType方法的具体用法?C# Activity.GetType怎么用?C# Activity.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Activity
的用法示例。
在下文中一共展示了Activity.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetExpressionString
internal static string GetExpressionString(Activity expression, ParserContext context)
{
string expressionString = null;
if (expression != null)
{
Type expressionType = expression.GetType();
Type expressionArgumentType = expressionType.IsGenericType ? expressionType.GetGenericArguments()[0] : typeof(object);
bool isLiteral = expressionType.IsGenericType ? Type.Equals(typeof(Literal<>), expressionType.GetGenericTypeDefinition()) : false;
//handle ITextExpression
if (expression is ITextExpression)
{
ITextExpression textExpression = expression as ITextExpression;
expressionString = textExpression.ExpressionText;
}
//handle Literal Expression
else if (isLiteral)
{
TypeConverter converter = XamlUtilities.GetConverter(expressionArgumentType);
if (converter != null && converter.CanConvertTo(context, typeof(string)))
{
PropertyInfo literalValueProperty = expressionType.GetProperty("Value");
Fx.Assert(literalValueProperty != null && literalValueProperty.GetGetMethod() != null, "Literal<T> must have the Value property with a public get accessor.");
object literalValue = literalValueProperty.GetValue(expression, null);
string convertedString = null;
if (literalValue != null)
{
try
{
convertedString = converter.ConvertToString(context, literalValue);
}
catch (ArgumentException)
{
convertedString = literalValue.ToString();
}
}
expressionString = expressionArgumentType == typeof(string) ? ("\"" + convertedString + "\"") : convertedString;
}
}
else if (expressionType.IsGenericType &&
(expressionType.GetGenericTypeDefinition() == typeof(VariableValue<>) ||
expressionType.GetGenericTypeDefinition() == typeof(VariableReference<>)))
{
PropertyInfo variableProperty = expression.GetType().GetProperty("Variable");
Variable variable = variableProperty.GetValue(expression, null) as Variable;
if (variable != null)
{
expressionString = variable.Name;
}
}
}
return expressionString;
}
示例2: GetApplicableAchievements
protected virtual IEnumerable<Achievement> GetApplicableAchievements(Activity trigger)
{
int currentActivityCount = GetCurrentActivityCount(trigger);
string triggerActivityType = trigger.GetType().FullName;
IQueryable<Achievement> applicableAchievements =
Repository.Query<Achievement>()
.Where(x => x.TargetActivityTypeName == triggerActivityType)
.Where(x => x.TriggerCount == currentActivityCount);
return applicableAchievements;
}
示例3: GetActivityType
internal static Type GetActivityType(IServiceProvider serviceProvider, Activity refActivity)
{
Type type = null;
string typeName = refActivity.GetValue(WorkflowMarkupSerializer.XClassProperty) as string;
if (refActivity.Site != null && !string.IsNullOrEmpty(typeName))
{
ITypeProvider typeProvider = serviceProvider.GetService(typeof(ITypeProvider)) as ITypeProvider;
if (typeProvider != null && !string.IsNullOrEmpty(typeName))
type = typeProvider.GetType(typeName, false);
}
else
{
type = refActivity.GetType();
}
return type;
}
示例4: ProcessAchievements
private IEnumerable<ActivityResult> ProcessAchievements(Activity activity, IEnumerable<AwardedAchievement> achievements)
{
IEnumerable<Developer> developers = achievements.Select(x => x.Developer).Distinct();
if(developers.Count() > 1)
Logger.Info("Activity triggered Achievements for more than the current developer. The following developers were affected: ",
string.Join(", ", developers.Select(x => x.Key).ToArray()));
foreach (Developer developer in developers)
{
Logger.Debug("Updating {0}'s statistics...", developer.Key);
Repository.Refresh(developer);
StatisticsGenerator.UpdateStatistics(developer);
Repository.Save(developer);
Logger.Info("Updated developer statistics", achievements.Count());
StatisticsGenerator.UpdateRankings();
Logger.Info("Updated developer rankings", achievements.Count());
Logger.Info(
"Done logging developer activity. Developer ID: {0}; Activity ID: {1}; ActivityType: [{2}]; Timestamp: {3}",
developer.ID, activity.ID, activity.GetType().FullName, activity.Timestamp);
yield return new ActivityResult()
{
Activity = activity.Key,
Developer = developer.Key,
AwardedAchievementCount = achievements.Count(),
AwardedAchievements = achievements.Select(x => x.Key).ToArray(),
};
}
}
示例5: ApplyActivityParameters
private static void ApplyActivityParameters(Activity activity, IDictionary<string, string> activityParameters)
{
foreach (string key in activityParameters.Keys)
{
string value = activityParameters[key];
Type activityType = activity.GetType();
PropertyInfo property = activityType.GetProperty(key);
property.SetValue(activity, value, new object[] {});
}
}
示例6: InvalidOperationException
void IWorkflowCoreRuntime.PersistInstanceState(Activity activity)
{
if (!ServiceEnvironment.IsInServiceThread(this.InstanceId))
throw new InvalidOperationException(ExecutionStringManager.MustUseRuntimeThread);
bool persistOnClose = false;
if (activity.UserData.Contains(typeof(PersistOnCloseAttribute)))
{
persistOnClose = (bool)activity.UserData[typeof(PersistOnCloseAttribute)];
}
else
{
object[] attributes = activity.GetType().GetCustomAttributes(typeof(PersistOnCloseAttribute), true);
if (attributes != null && attributes.Length > 0)
persistOnClose = true;
}
if (persistOnClose && this.WorkflowRuntime.GetService<WorkflowPersistenceService>() == null)
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, ExecutionStringManager.MissingPersistenceServiceWithPersistOnClose, activity.Name));
this.ScheduleDelayedItems(activity);
bool unlock = (activity.Parent == null) ? true : false;
bool needsCompensation = false; //
this.Persist(activity, unlock, needsCompensation);
}
示例7: ValidateActivity
internal static void ValidateActivity(Activity activity, WorkflowCompilerParameters parameters, WorkflowCompilerResults results)
{
ValidationErrorCollection errors = null;
ValidationManager validationManager = new ValidationManager(WorkflowCompilationContext.Current.ServiceProvider);
foreach (Validator validator in validationManager.GetValidators(activity.GetType()))
{
// Validate recursively.
try
{
errors = validator.Validate(validationManager, activity);
foreach (ValidationError error in errors)
{
if (!error.UserData.Contains(typeof(Activity)))
error.UserData[typeof(Activity)] = activity;
results.Errors.Add(CreateXomlCompilerError(error, parameters));
}
}
catch (TargetInvocationException tie)
{
Exception e = tie.InnerException ?? tie;
ValidationError error = new ValidationError(SR.GetString(SR.Error_ValidatorThrewException, e.GetType().FullName, validator.GetType().FullName, activity.Name, e.ToString()), ErrorNumbers.Error_ValidatorThrewException);
results.Errors.Add(CreateXomlCompilerError(error, parameters));
}
catch (Exception e)
{
ValidationError error = new ValidationError(SR.GetString(SR.Error_ValidatorThrewException, e.GetType().FullName, validator.GetType().FullName, activity.Name, e.ToString()), ErrorNumbers.Error_ValidatorThrewException);
results.Errors.Add(CreateXomlCompilerError(error, parameters));
}
}
}
示例8: CreateActivityParameterEvaluator
private ActivityParameterEvaluator CreateActivityParameterEvaluator(string propertyName, Activity propertyOwner)
{
var type = propertyOwner.GetType();
PropertyInfo propInfo;
try
{
propInfo = type.GetProperty(propertyName, true, false);
}
catch (Exception ex)
{
throw new WorkflowSchemeParserException(string.Format(
"Ошибка получения св-ва {0}", propertyName), ex, this);
}
return new ActivityParameterEvaluator(propInfo, propertyOwner);
}
示例9: CreateDesigner
internal static ActivityDesigner CreateDesigner(IServiceProvider serviceProvider, Activity activity)
{
IDesigner designer = null;
Type designerType = GetDesignerType(serviceProvider, activity.GetType(), typeof(IDesigner));
if (designerType == null)
designerType = GetDesignerType(serviceProvider, activity.GetType(), null);
if (designerType != null)
{
try
{
designer = Activator.CreateInstance(designerType, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance, null, null, null) as IDesigner;
designer.Initialize(activity);
}
catch
{
//Eat the exception thrown
}
}
return (designer as ActivityDesigner);
}
示例10: Initialize
/// <summary>
/// Initializes the designer with associated activity.
/// </summary>
/// <param name="activity">Activity with which the designer needs to be initialized.</param>
protected virtual void Initialize(Activity activity)
{
if (activity == null)
throw new ArgumentNullException("activity");
if (IsRootDesigner)
{
// Listen for the completed load. When finished, we need to select the form. We don'
// want to do it before we're done, however, or else the dimensions of the selection rectangle
// could be off because during load, change events are not fired.
IDesignerHost designerHost = (IDesignerHost)GetService(typeof(IDesignerHost));
if (designerHost != null && InvokingDesigner == null)
designerHost.LoadComplete += new EventHandler(OnLoadComplete);
IComponentChangeService changeService = GetService(typeof(IComponentChangeService)) as IComponentChangeService;
if (changeService != null)
{
changeService.ComponentChanged += new ComponentChangedEventHandler(OnComponentChanged);
changeService.ComponentRename += new ComponentRenameEventHandler(OnComponentRenamed);
}
}
this.Text = (!String.IsNullOrEmpty(activity.Name)) ? activity.Name : activity.GetType().Name;
this.Image = StockImage;
//We need to update the Verbs when the designer first loads up
RefreshDesignerVerbs();
if (IsLocked)
DesignerHelpers.MakePropertiesReadOnly(activity.Site, activity);
}
示例11: AddActivityToDesigner
public void AddActivityToDesigner(Activity activity)
{
if (activity == null)
throw new ArgumentNullException("activity");
IDesignerHost designerHost = GetService(typeof(IDesignerHost)) as IDesignerHost;
if (designerHost == null)
throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(IDesignerHost).FullName));
if (activity.Parent == null && designerHost.RootComponent == null)
{
string fullClassName = activity.GetValue(WorkflowMarkupSerializer.XClassProperty) as String;
string rootSiteName = (!string.IsNullOrEmpty(fullClassName)) ? Helpers.GetClassName(fullClassName) : Helpers.GetClassName(activity.GetType().FullName);
designerHost.Container.Add(activity, rootSiteName);
AddTargetFrameworkProvider(activity);
}
else
{
designerHost.Container.Add(activity, activity.QualifiedName);
AddTargetFrameworkProvider(activity);
}
if (activity is CompositeActivity)
{
foreach (Activity activity2 in Helpers.GetNestedActivities(activity as CompositeActivity))
{
designerHost.Container.Add(activity2, activity2.QualifiedName);
AddTargetFrameworkProvider(activity2);
}
}
}
示例12: GetCurrentActivityCount
protected virtual int GetCurrentActivityCount(Activity trigger)
{
if (trigger == null)
throw new ApplicationException("Expected to be associated an Activity, but none was specified");
// Get all previous instances of this type of activity
int currentCount = trigger.Developer.History.Count(x => x.GetType() == trigger.GetType());
// The history should already include this trigger, but
// if not increment the count to take this one into account
if (!trigger.Developer.History.Any(x => x == trigger))
currentCount += 1;
return currentCount;
}
示例13: GetSourceLocations
static internal Dictionary<object, SourceLocation> GetSourceLocations(Activity rootActivity, out string sourcePath, out bool isTemporaryFile, out byte[] checksum)
{
isTemporaryFile = false;
checksum = null;
string symbolString = DebugSymbol.GetSymbol(rootActivity) as String;
if (string.IsNullOrEmpty(symbolString) && rootActivity.Children != null && rootActivity.Children.Count > 0)
{ // In case of actual root is wrapped either in x:Class activity or CorrelationScope
Activity body = rootActivity.Children[0];
string bodySymbolString = DebugSymbol.GetSymbol(body) as String;
if (!string.IsNullOrEmpty(bodySymbolString))
{
rootActivity = body;
symbolString = bodySymbolString;
}
}
if (!string.IsNullOrEmpty(symbolString))
{
try
{
WorkflowSymbol wfSymbol = WorkflowSymbol.Decode(symbolString);
if (wfSymbol != null)
{
sourcePath = wfSymbol.FileName;
checksum = wfSymbol.GetChecksum();
// rootActivity is the activity with the attached symbol string.
// rootActivity.RootActivity is the workflow root activity.
// if they are not the same, then it must be compiled XAML, because loose XAML (i.e. XAMLX) always have the symbol attached at the root.
if (rootActivity.RootActivity != rootActivity)
{
Fx.Assert(rootActivity.Parent != null, "Compiled XAML implementation always have a parent.");
rootActivity = rootActivity.Parent;
}
return GetSourceLocations(rootActivity, wfSymbol, translateInternalActivityToOrigin: false);
}
}
catch (SerializationException)
{
// Ignore invalid symbol.
}
}
sourcePath = XamlDebuggerXmlReader.GetFileName(rootActivity) as string;
Dictionary<object, SourceLocation> mapping;
Assembly localAssembly;
bool permissionRevertNeeded = false;
// This may not be the local assembly since it may not be the real root for x:Class
localAssembly = rootActivity.GetType().Assembly;
if (rootActivity.Parent != null)
{
localAssembly = rootActivity.Parent.GetType().Assembly;
}
if (rootActivity.Children != null && rootActivity.Children.Count > 0)
{ // In case of actual root is wrapped either in x:Class activity or CorrelationScope
Activity body = rootActivity.Children[0];
string bodySourcePath = XamlDebuggerXmlReader.GetFileName(body) as string;
if (!string.IsNullOrEmpty(bodySourcePath))
{
rootActivity = body;
sourcePath = bodySourcePath;
}
}
try
{
Fx.Assert(!string.IsNullOrEmpty(sourcePath), "If sourcePath is null, it should have been short-circuited before reaching here.");
SourceLocation tempSourceLocation;
Activity tempRootActivity;
checksum = SymbolHelper.CalculateChecksum(sourcePath);
if (TryGetSourceLocation(rootActivity, sourcePath, checksum, out tempSourceLocation)) // already has source location.
{
tempRootActivity = rootActivity;
}
else
{
byte[] buffer;
// Need to store the file in memory temporary so don't have to re-read the file twice
// for XamlDebugXmlReader's BracketLocator.
// If there is a debugger attached, Assert FileIOPermission for Read access to the specific file.
if (System.Diagnostics.Debugger.IsAttached)
{
permissionRevertNeeded = true;
FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.Read, sourcePath);
permission.Assert();
}
try
{
FileInfo fi = new FileInfo(sourcePath);
buffer = new byte[fi.Length];
using (FileStream fs = new FileStream(sourcePath, FileMode.Open, FileAccess.Read))
{
fs.Read(buffer, 0, buffer.Length);
//.........这里部分代码省略.........
示例14: CreateEventHolder
private EventHolder CreateEventHolder(string eventName, Activity eventOwner)
{
var type = eventOwner.GetType();
EventInfo evInfo;
try
{
evInfo = type.GetEvent(eventName);
if (evInfo == null)
throw new Exception(string.Format("Тип {0} не содержит события public {1}", type.Name, eventName));
}
catch (Exception ex)
{
throw new WorkflowSchemeParserException(string.Format(
"Ошибка получения события {0}", eventName), ex, this);
}
return new EventHolder(evInfo, eventOwner);
}
示例15: GetArgumentAccessorWrappers
public List<ArgumentAccessorWrapper> GetArgumentAccessorWrappers(Activity activity)
{
Fx.Assert(activity != null, "activity cannot be null.");
List<ArgumentAccessorWrapper> argumentAccessorWrappers = null;
if (!this.argumentAccessorWrappersCache.TryGetValue(activity, out argumentAccessorWrappers))
{
Func<Activity, IEnumerable<ArgumentAccessor>> argumentAccessorsGenerator;
if (ActivityArgumentHelper.TryGetArgumentAccessorsGenerator(activity.GetType(), out argumentAccessorsGenerator))
{
IEnumerable<ArgumentAccessor> argumentAccessors = argumentAccessorsGenerator(activity);
if (argumentAccessors != null)
{
argumentAccessorWrappers = new List<ArgumentAccessorWrapper>();
foreach (ArgumentAccessor argumentAccessor in argumentAccessors)
{
if (argumentAccessor != null && argumentAccessor.Getter != null)
{
Argument argument = argumentAccessor.Getter(activity);
if (argument != null)
{
ArgumentAccessorWrapper argumentAccessorWrapper = new ArgumentAccessorWrapper(argumentAccessor, argument);
argumentAccessorWrappers.Add(argumentAccessorWrapper);
}
}
}
this.argumentAccessorWrappersCache.Add(activity, argumentAccessorWrappers);
}
}
}
return argumentAccessorWrappers;
}