コード例 #1
0
        PropertyDescriptorCollection CreateProperties()
        {
            // The name in child Activity will shadow the name in parent.
            Dictionary <string, object> names = new Dictionary <string, object>();

            List <PropertyDescriptorImpl> propertyList = new List <PropertyDescriptorImpl>();

            LocationReferenceEnvironment environment = this.activityInstance.Activity.PublicEnvironment;
            bool isLocalEnvironment = true;

            while (environment != null)
            {
                foreach (LocationReference locRef in environment.GetLocationReferences())
                {
                    if (this.IncludesLocalVariables || !isLocalEnvironment || !(locRef is Variable))
                    {
                        AddProperty(locRef, names, propertyList);
                    }
                }

                environment        = environment.Parent;
                isLocalEnvironment = false;
            }

            return(new PropertyDescriptorCollection(propertyList.ToArray(), true));
        }
        static bool FindLocationReferencesFromEnvironment(LocationReferenceEnvironment environment, string targetName)
        {
            LocationReference foundLocationReference = null;            
            LocationReferenceEnvironment currentEnvironment;
            bool foundMultiple = false;

            currentEnvironment = environment;            
            while (currentEnvironment != null)
            {
                foreach (LocationReference reference in currentEnvironment.GetLocationReferences())
                {
                    if (string.Equals(reference.Name, targetName, StringComparison.OrdinalIgnoreCase))
                    {
                        if (foundLocationReference != null)
                        {
                            foundMultiple = true;
                            return foundMultiple;
                        }

                        foundLocationReference = reference;
                    }
                }

                currentEnvironment = currentEnvironment.Parent;
            }

            return foundMultiple;
        }
コード例 #3
0
        public Activity RecompileReference(ActivityWithResult lValue, out Type returnType, out SourceExpressionException compileError, out VisualBasicSettings vbSettings)
        {
            ITextExpression textExpression = lValue as ITextExpression;

            if (textExpression == null || textExpression.Language != Language)
            {
                throw FxTrace.Exception.AsError(new ArgumentException());
            }
            string expressionText = textExpression.ExpressionText;
            LocationReferenceEnvironment environment = lValue.GetParentEnvironment();

            List <string> namespaces;
            List <string> referencedAssemblies;

            GetAllImportReferences(lValue, out namespaces, out referencedAssemblies);

            return(CreatePrecompiledReference(
                       null,
                       expressionText,
                       namespaces,
                       referencedAssemblies,
                       environment,
                       out returnType,
                       out compileError,
                       out vbSettings));
        }
 internal ValidationContext(ActivityUtilities.ChildActivity owner, ActivityUtilities.ActivityCallStack parentChain, ProcessActivityTreeOptions options, LocationReferenceEnvironment environment)
 {
     this.owner = owner;
     this.parentChain = parentChain;
     this.options = options;
     this.environment = environment;
 }
 public ActivityLocationReferenceEnvironment(LocationReferenceEnvironment parent)
 {
     base.Parent = parent;
     if (base.Parent != null)
     {
         this.InternalRoot = parent.Root;
     }
 }
コード例 #6
0
 public ActivityLocationReferenceEnvironment(LocationReferenceEnvironment parent)
 {
     base.Parent = parent;
     if (base.Parent != null)
     {
         this.InternalRoot = parent.Root;
     }
 }
コード例 #7
0
 public ActivityLocationReferenceEnvironment(LocationReferenceEnvironment parent)
 {
     Parent = parent;
     if (Parent != null)
     {
         CompileExpressions = parent.CompileExpressions;
         InternalRoot       = parent.Root;
     }
 }
コード例 #8
0
        private PropertyDescriptorCollection CreateProperties()
        {
            Dictionary <string, object>   names        = new Dictionary <string, object>();
            List <PropertyDescriptorImpl> propertyList = new List <PropertyDescriptorImpl>();

            for (LocationReferenceEnvironment environment = this.activityInstance.Activity.PublicEnvironment; environment != null; environment = environment.Parent)
            {
                foreach (LocationReference reference in environment.GetLocationReferences())
                {
                    this.AddProperty(reference, names, propertyList);
                }
            }
            return(new PropertyDescriptorCollection(propertyList.ToArray(), true));
        }
コード例 #9
0
        public override bool IsVisible(LocationReference locationReference)
        {
            if (locationReference == null)
            {
                throw FxTrace.Exception.ArgumentNull("locationReference");
            }

            LocationReferenceEnvironment currentScope = this;

            while (currentScope != null)
            {
                ActivityLocationReferenceEnvironment activityEnvironment = currentScope as ActivityLocationReferenceEnvironment;

                if (activityEnvironment != null)
                {
                    if (activityEnvironment.declarations != null)
                    {
                        foreach (LocationReference declaration in activityEnvironment.declarations.Values)
                        {
                            if (locationReference == declaration)
                            {
                                return(true);
                            }
                        }
                    }

                    if (activityEnvironment.unnamedDeclarations != null)
                    {
                        for (int i = 0; i < activityEnvironment.unnamedDeclarations.Count; i++)
                        {
                            if (locationReference == activityEnvironment.unnamedDeclarations[i])
                            {
                                return(true);
                            }
                        }
                    }
                }
                else
                {
                    return(currentScope.IsVisible(locationReference));
                }

                currentScope = currentScope.Parent;
            }

            return(false);
        }
 public static void CacheMetadata(Activity rootActivity, LocationReferenceEnvironment hostEnvironment)
 {
     if (rootActivity == null)
     {
         throw FxTrace.Exception.ArgumentNull("rootActivity");
     }
     if (rootActivity.HasBeenAssociatedWithAnInstance)
     {
         throw FxTrace.Exception.AsError(new InvalidOperationException(System.Activities.SR.RootActivityAlreadyAssociatedWithInstance(rootActivity.DisplayName)));
     }
     IList<ValidationError> validationErrors = null;
     if (hostEnvironment == null)
     {
         hostEnvironment = new ActivityLocationReferenceEnvironment();
     }
     ActivityUtilities.CacheRootMetadata(rootActivity, hostEnvironment, ProcessActivityTreeOptions.FullCachingOptions, null, ref validationErrors);
     ActivityValidationServices.ThrowIfViolationsExist(validationErrors);
 }
コード例 #11
0
        public static void CacheMetadata(Activity rootActivity, LocationReferenceEnvironment hostEnvironment)
        {
            if (rootActivity == null)
            {
                throw FxTrace.Exception.ArgumentNull("rootActivity");
            }
            if (rootActivity.HasBeenAssociatedWithAnInstance)
            {
                throw FxTrace.Exception.AsError(new InvalidOperationException(System.Activities.SR.RootActivityAlreadyAssociatedWithInstance(rootActivity.DisplayName)));
            }
            IList <ValidationError> validationErrors = null;

            if (hostEnvironment == null)
            {
                hostEnvironment = new ActivityLocationReferenceEnvironment();
            }
            ActivityUtilities.CacheRootMetadata(rootActivity, hostEnvironment, ProcessActivityTreeOptions.FullCachingOptions, null, ref validationErrors);
            ActivityValidationServices.ThrowIfViolationsExist(validationErrors);
        }
コード例 #12
0
 public static void CacheRootMetadata(Activity activity, LocationReferenceEnvironment hostEnvironment, ProcessActivityTreeOptions options, ProcessActivityCallback callback, ref IList <ValidationError> validationErrors)
 {
     if (!ShouldShortcut(activity, options))
     {
         lock (activity.ThisLock)
         {
             if (!ShouldShortcut(activity, options))
             {
                 if (activity.HasBeenAssociatedWithAnInstance)
                 {
                     throw FxTrace.Exception.AsError(new InvalidOperationException(System.Activities.SR.RootActivityAlreadyAssociatedWithInstance(activity.DisplayName)));
                 }
                 activity.InitializeAsRoot(hostEnvironment);
                 ProcessActivityTreeCore(new ChildActivity(activity, true), null, options, callback, ref validationErrors);
                 if (!ActivityValidationServices.HasErrors(validationErrors) && options.IsRuntimeReadyOptions)
                 {
                     activity.SetRuntimeReady();
                 }
             }
         }
     }
 }
コード例 #13
0
 public override bool TryGetLocationReference(string name, out LocationReference result)
 {
     if (name == null)
     {
         LocationReferenceEnvironment parent = base.Parent;
         while (parent is ActivityLocationReferenceEnvironment)
         {
             parent = parent.Parent;
         }
         if (parent != null)
         {
             return(parent.TryGetLocationReference(name, out result));
         }
     }
     else
     {
         if ((this.declarations != null) && this.declarations.TryGetValue(name, out result))
         {
             return(true);
         }
         bool flag = false;
         LocationReferenceEnvironment environment2 = base.Parent;
         while ((environment2 != null) && (environment2 is ActivityLocationReferenceEnvironment))
         {
             ActivityLocationReferenceEnvironment environment3 = (ActivityLocationReferenceEnvironment)environment2;
             if ((environment3.declarations != null) && environment3.declarations.TryGetValue(name, out result))
             {
                 return(true);
             }
             environment2 = environment2.Parent;
         }
         if ((!flag && (environment2 != null)) && environment2.TryGetLocationReference(name, out result))
         {
             return(true);
         }
     }
     result = null;
     return(false);
 }
コード例 #14
0
 public override bool IsVisible(LocationReference locationReference)
 {
     if (locationReference == null)
     {
         throw FxTrace.Exception.ArgumentNull("locationReference");
     }
     for (LocationReferenceEnvironment environment = this; environment != null; environment = environment.Parent)
     {
         ActivityLocationReferenceEnvironment environment2 = environment as ActivityLocationReferenceEnvironment;
         if (environment2 == null)
         {
             return(environment.IsVisible(locationReference));
         }
         if (environment2.declarations != null)
         {
             foreach (LocationReference reference in environment2.declarations.Values)
             {
                 if (locationReference == reference)
                 {
                     return(true);
                 }
             }
         }
         if (environment2.unnamedDeclarations != null)
         {
             for (int i = 0; i < environment2.unnamedDeclarations.Count; i++)
             {
                 if (locationReference == environment2.unnamedDeclarations[i])
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
コード例 #15
0
        public override bool TryGetLocationReference(string name, out LocationReference result)
        {
            if (name == null)
            {
                // We don't allow null names in our LocationReferenceEnvironment but
                // a custom declared environment might.  We need to walk up
                // to the root and see if it chains to a
                // non-ActivityLocationReferenceEnvironment implementation
                LocationReferenceEnvironment currentEnvironment = this.Parent;

                while (currentEnvironment is ActivityLocationReferenceEnvironment)
                {
                    currentEnvironment = currentEnvironment.Parent;
                }

                if (currentEnvironment != null)
                {
                    Fx.Assert(!(currentEnvironment is ActivityLocationReferenceEnvironment), "We must be at a non-ActivityLocationReferenceEnvironment implementation.");

                    return(currentEnvironment.TryGetLocationReference(name, out result));
                }
            }
            else
            {
                if (this.declarations != null && this.declarations.TryGetValue(name, out result))
                {
                    return(true);
                }

                bool found = false;
                LocationReferenceEnvironment currentEnvironment = this.Parent;
                LocationReferenceEnvironment rootEnvironment    = this;

                // Loop through all of the ActivityLocationReferenceEnvironments we have chained together
                while (currentEnvironment != null && currentEnvironment is ActivityLocationReferenceEnvironment)
                {
                    ActivityLocationReferenceEnvironment activityEnvironment = (ActivityLocationReferenceEnvironment)currentEnvironment;
                    if (activityEnvironment.declarations != null && activityEnvironment.declarations.TryGetValue(name, out result))
                    {
                        return(true);
                    }

                    rootEnvironment    = currentEnvironment;
                    currentEnvironment = currentEnvironment.Parent;
                }

                if (!found)
                {
                    if (currentEnvironment != null)
                    {
                        // Looks like we have a non-ActivityLocationReferenceEnvironment at the root
                        Fx.Assert(!(currentEnvironment is ActivityLocationReferenceEnvironment), "We should have some other host environment at this point.");
                        if (currentEnvironment.TryGetLocationReference(name, out result))
                        {
                            return(true);
                        }
                    }
                }
            }

            result = null;
            return(false);
        }
コード例 #16
0
        public static Activity CreatePrecompiledVisualBasicReference(Type targetType, string expressionText, IEnumerable<string> namespaces, IEnumerable<string> referencedAssemblies,
            LocationReferenceEnvironment environment,
            out Type returnType,
            out SourceExpressionException compileError,
            out VisualBasicSettings vbSettings)
        {
            LambdaExpression lambda = null;
            HashSet<string> namespacesSet = new HashSet<string>();
            HashSet<AssemblyName> assembliesSet = new HashSet<AssemblyName>();
            compileError = null;
            returnType = null;

            if (namespaces != null)
            {
                foreach (string ns in namespaces)
                {
                    if (ns != null)
                    {
                        namespacesSet.Add(ns);
                    }                    
                }
            }

            if (referencedAssemblies != null)
            {
                foreach (string assm in referencedAssemblies)
                {
                    if (assm != null)
                    {
                        assembliesSet.Add(new AssemblyName(assm));
                    }                    
                }
            }
            
            VisualBasicHelper vbhelper = new VisualBasicHelper(expressionText, assembliesSet, namespacesSet);
            if (targetType == null)
            {
                try
                {
                    lambda = vbhelper.CompileNonGeneric(environment);
                    if (lambda != null)
                    {
                        // inspect the expressionTree to see if it is a valid location expression(L-value)
                        string extraErrorMessage;
                        if (!ExpressionUtilities.IsLocation(lambda, targetType, out extraErrorMessage))
                        {
                            string errorMessage = SR.InvalidLValueExpression;
                            if (extraErrorMessage != null)
                            {
                                errorMessage += ":" + extraErrorMessage;
                            }
                            throw FxTrace.Exception.AsError(
                                new SourceExpressionException(SR.CompilerErrorSpecificExpression(expressionText, errorMessage)));
                        }
                        returnType = lambda.ReturnType;
                    }
                }
                catch (SourceExpressionException e)
                {
                    compileError = e;
                    returnType = typeof(object);
                }
                targetType = returnType;
            }
            else
            {
                MethodInfo genericCompileMethod = typeof(VisualBasicHelper).GetMethod("Compile", new Type[] { typeof(LocationReferenceEnvironment) });
                genericCompileMethod = genericCompileMethod.MakeGenericMethod(new Type[] { targetType });
                try
                {
                    lambda = (LambdaExpression)genericCompileMethod.Invoke(vbhelper, new object[] { environment });
                    // inspect the expressionTree to see if it is a valid location expression(L-value)
                    string extraErrorMessage = null;
                    if (!ExpressionUtilities.IsLocation(lambda, targetType, out extraErrorMessage))
                    {
                        string errorMessage = SR.InvalidLValueExpression;
                        if (extraErrorMessage != null)
                        {
                            errorMessage += ":" + extraErrorMessage;
                        }
                        throw FxTrace.Exception.AsError(
                            new SourceExpressionException(SR.CompilerErrorSpecificExpression(expressionText, errorMessage)));
                    }
                    returnType = targetType;
                }
                catch (SourceExpressionException e)
                {
                    compileError = e;
                    returnType = typeof(object);
                }
                catch (TargetInvocationException e)
                {
                    SourceExpressionException se = e.InnerException as SourceExpressionException;
                    if (se != null)
                    {
                        compileError = se;
                        returnType = typeof(object);
                    }
                    else
                    {
                        throw FxTrace.Exception.AsError(e.InnerException);
                    }
                }
            }

            vbSettings = new VisualBasicSettings();
            if (lambda != null)
            {
                HashSet<Type> typeReferences = new HashSet<Type>();
                FindTypeReferences(lambda.Body, typeReferences);
                foreach (Type type in typeReferences)
                {
                    Assembly tassembly = type.Assembly;
                    if (tassembly.IsDynamic)
                    {
                        continue;
                    }
                    string assemblyName = VisualBasicHelper.GetFastAssemblyName(tassembly).Name;
                    VisualBasicImportReference importReference = new VisualBasicImportReference { Assembly = assemblyName, Import = type.Namespace };
                    vbSettings.ImportReferences.Add(importReference);
                }
            }

            Type concreteHelperType = VisualBasicExpressionFactoryType.MakeGenericType(targetType);
            VisualBasicExpressionFactory expressionFactory = (VisualBasicExpressionFactory)Activator.CreateInstance(concreteHelperType);

            return expressionFactory.CreateVisualBasicReference(expressionText);
        }       
コード例 #17
0
        public Activity CreatePrecompiledValue(Type targetType, string expressionText, IEnumerable <string> namespaces, IEnumerable <string> referencedAssemblies,
                                               LocationReferenceEnvironment environment, out Type returnType, out SourceExpressionException compileError, out VisualBasicSettings vbSettings)
        {
            LambdaExpression       lambda        = null;
            HashSet <string>       namespacesSet = new HashSet <string>();
            HashSet <AssemblyName> assembliesSet = new HashSet <AssemblyName>();

            compileError = null;
            returnType   = null;

            if (namespaces != null)
            {
                foreach (string ns in namespaces)
                {
                    if (ns != null)
                    {
                        namespacesSet.Add(ns);
                    }
                }
            }

            if (referencedAssemblies != null)
            {
                foreach (string assm in referencedAssemblies)
                {
                    if (assm != null)
                    {
                        assembliesSet.Add(new AssemblyName(assm));
                    }
                }
            }

            var compilerHelper = CreateJitCompilerHelper(expressionText, assembliesSet, namespacesSet);

            if (targetType == null)
            {
                try
                {
                    lambda = compilerHelper.CompileNonGeneric(environment);
                    if (lambda != null)
                    {
                        returnType = lambda.ReturnType;
                    }
                }
                catch (SourceExpressionException e)
                {
                    compileError = e;
                    returnType   = typeof(object);
                }
                targetType = returnType;
            }
            else
            {
                MethodInfo genericCompileMethod = compilerHelper.GetType().GetMethod("Compile", new Type[] { typeof(LocationReferenceEnvironment) });
                genericCompileMethod = genericCompileMethod.MakeGenericMethod(new Type[] { targetType });
                try
                {
                    lambda     = (LambdaExpression)genericCompileMethod.Invoke(compilerHelper, new object[] { environment });
                    returnType = targetType;
                }
                catch (TargetInvocationException e)
                {
                    SourceExpressionException se = e.InnerException as SourceExpressionException;
                    if (se != null)
                    {
                        compileError = se;
                        returnType   = typeof(object);
                    }
                    else
                    {
                        throw FxTrace.Exception.AsError(e.InnerException);
                    }
                }
            }

            vbSettings = new VisualBasicSettings();
            if (lambda != null)
            {
                HashSet <Type> typeReferences = new HashSet <Type>();
                FindTypeReferences(lambda.Body, typeReferences);
                foreach (Type type in typeReferences)
                {
                    Assembly tassembly = type.Assembly;
                    if (tassembly.IsDynamic)
                    {
                        continue;
                    }
                    string assemblyName = AssemblyReference.GetFastAssemblyName(tassembly).Name;
                    VisualBasicImportReference importReference = new VisualBasicImportReference {
                        Assembly = assemblyName, Import = type.Namespace
                    };
                    vbSettings.ImportReferences.Add(importReference);
                }
            }

            Type concreteHelperType             = ExpressionFactoryType.MakeGenericType(targetType);
            ExpressionFactory expressionFactory = (ExpressionFactory)Activator.CreateInstance(concreteHelperType);

            return(expressionFactory.CreateValue(expressionText));
        }
コード例 #18
0
        internal bool InitializeRelationship(Activity parent, ActivityCollectionType collectionType, ref IList <ValidationError> validationErrors)
        {
            if (this.cacheId == parent.CacheId)
            {
                Fx.Assert(this.owner != null, "We must have set the owner when we set the cache ID");

                // This means that we've already encountered a parent in the tree

                // Validate that it is visible.

                // In order to see the activity the new parent must be
                // in the implementation IdSpace of an activity which has
                // a public reference to it.
                Activity referenceTarget = parent.MemberOf.Owner;

                if (referenceTarget == null)
                {
                    Activity handler = this.Handler;

                    if (handler == null)
                    {
                        ActivityUtilities.Add(ref validationErrors, new ValidationError(SR.ActivityDelegateCannotBeReferencedWithoutTargetNoHandler(parent.DisplayName, this.owner.DisplayName), false, parent));
                    }
                    else
                    {
                        ActivityUtilities.Add(ref validationErrors, new ValidationError(SR.ActivityDelegateCannotBeReferencedWithoutTarget(handler.DisplayName, parent.DisplayName, this.owner.DisplayName), false, parent));
                    }

                    return(false);
                }
                else if (!referenceTarget.Delegates.Contains(this) && !referenceTarget.ImportedDelegates.Contains(this))
                {
                    Activity handler = this.Handler;

                    if (handler == null)
                    {
                        ActivityUtilities.Add(ref validationErrors, new ValidationError(SR.ActivityDelegateCannotBeReferencedNoHandler(parent.DisplayName, referenceTarget.DisplayName, this.owner.DisplayName), false, parent));
                    }
                    else
                    {
                        ActivityUtilities.Add(ref validationErrors, new ValidationError(SR.ActivityDelegateCannotBeReferenced(handler.DisplayName, parent.DisplayName, referenceTarget.DisplayName, this.owner.DisplayName), false, parent));
                    }

                    return(false);
                }

                // This is a valid reference so we want to allow
                // normal processing to proceed.
                return(true);
            }

            this.owner   = parent;
            this.cacheId = parent.CacheId;
            this.parentCollectionType = collectionType;
            InternalCacheMetadata();

            // We need to setup the delegate environment so that it is
            // available when we process the Handler.
            LocationReferenceEnvironment delegateEnvironment = null;

            if (collectionType == ActivityCollectionType.Implementation)
            {
                delegateEnvironment = parent.ImplementationEnvironment;
            }
            else
            {
                delegateEnvironment = parent.PublicEnvironment;
            }

            if (this.RuntimeDelegateArguments.Count > 0)
            {
                ActivityLocationReferenceEnvironment newEnvironment = new ActivityLocationReferenceEnvironment(delegateEnvironment);
                delegateEnvironment = newEnvironment;

                for (int argumentIndex = 0; argumentIndex < this.RuntimeDelegateArguments.Count; argumentIndex++)
                {
                    RuntimeDelegateArgument runtimeDelegateArgument = this.RuntimeDelegateArguments[argumentIndex];
                    DelegateArgument        delegateArgument        = runtimeDelegateArgument.BoundArgument;

                    if (delegateArgument != null)
                    {
                        if (delegateArgument.Direction != runtimeDelegateArgument.Direction)
                        {
                            ActivityUtilities.Add(ref validationErrors, new ValidationError(SR.RuntimeDelegateArgumentDirectionIncorrect, parent));
                        }

                        if (delegateArgument.Type != runtimeDelegateArgument.Type)
                        {
                            ActivityUtilities.Add(ref validationErrors, new ValidationError(SR.RuntimeDelegateArgumentTypeIncorrect, parent));
                        }

                        // NOTE: We don't initialize this relationship here because
                        // at runtime we'll actually just place these variables in the
                        // environment of the Handler.  We'll initialize and set an
                        // ID when we process the Handler.
                        newEnvironment.Declare(delegateArgument, this.owner, ref validationErrors);
                    }
                }
            }

            this.Environment = delegateEnvironment;

            if (this.Handler != null)
            {
                return(this.Handler.InitializeRelationship(this, collectionType, ref validationErrors));
            }

            return(true);
        }
 public static Activity CreatePrecompiledVisualBasicReference(Type targetType, string expressionText, IEnumerable<string> namespaces, IEnumerable<string> referencedAssemblies, LocationReferenceEnvironment environment, out Type returnType, out SourceExpressionException compileError, out VisualBasicSettings vbSettings)
 {
     LambdaExpression expression = null;
     HashSet<string> namespaceImportsNames = new HashSet<string>();
     HashSet<AssemblyName> refAssemNames = new HashSet<AssemblyName>();
     compileError = null;
     returnType = null;
     if (namespaces != null)
     {
         foreach (string str in namespaces)
         {
             if (str != null)
             {
                 namespaceImportsNames.Add(str);
             }
         }
     }
     if (referencedAssemblies != null)
     {
         foreach (string str2 in referencedAssemblies)
         {
             if (str2 != null)
             {
                 refAssemNames.Add(new AssemblyName(str2));
             }
         }
     }
     VisualBasicHelper helper = new VisualBasicHelper(expressionText, refAssemNames, namespaceImportsNames);
     if (targetType == null)
     {
         try
         {
             expression = helper.CompileNonGeneric(environment);
             if (expression != null)
             {
                 string str3;
                 if (!ExpressionUtilities.IsLocation(expression, targetType, out str3))
                 {
                     string invalidLValueExpression = System.Activities.SR.InvalidLValueExpression;
                     if (str3 != null)
                     {
                         invalidLValueExpression = invalidLValueExpression + ":" + str3;
                     }
                     throw FxTrace.Exception.AsError(new SourceExpressionException(System.Activities.SR.CompilerErrorSpecificExpression(expressionText, invalidLValueExpression)));
                 }
                 returnType = expression.ReturnType;
             }
         }
         catch (SourceExpressionException exception)
         {
             compileError = exception;
             returnType = typeof(object);
         }
         targetType = returnType;
     }
     else
     {
         MethodInfo info = typeof(VisualBasicHelper).GetMethod("Compile", new Type[] { typeof(LocationReferenceEnvironment) }).MakeGenericMethod(new Type[] { targetType });
         try
         {
             expression = (LambdaExpression) info.Invoke(helper, new object[] { environment });
             string extraErrorMessage = null;
             if (!ExpressionUtilities.IsLocation(expression, targetType, out extraErrorMessage))
             {
                 string str6 = System.Activities.SR.InvalidLValueExpression;
                 if (extraErrorMessage != null)
                 {
                     str6 = str6 + ":" + extraErrorMessage;
                 }
                 throw FxTrace.Exception.AsError(new SourceExpressionException(System.Activities.SR.CompilerErrorSpecificExpression(expressionText, str6)));
             }
             returnType = targetType;
         }
         catch (SourceExpressionException exception2)
         {
             compileError = exception2;
             returnType = typeof(object);
         }
         catch (TargetInvocationException exception3)
         {
             SourceExpressionException innerException = exception3.InnerException as SourceExpressionException;
             if (innerException == null)
             {
                 throw FxTrace.Exception.AsError(exception3.InnerException);
             }
             compileError = innerException;
             returnType = typeof(object);
         }
     }
     vbSettings = new VisualBasicSettings();
     if (expression != null)
     {
         HashSet<Type> typeReferences = new HashSet<Type>();
         FindTypeReferences(expression.Body, typeReferences);
         foreach (Type type in typeReferences)
         {
             Assembly assembly = type.Assembly;
             if (!assembly.IsDynamic)
             {
                 string name = VisualBasicHelper.GetFastAssemblyName(assembly).Name;
                 VisualBasicImportReference item = new VisualBasicImportReference {
                     Assembly = name,
                     Import = type.Namespace
                 };
                 vbSettings.ImportReferences.Add(item);
             }
         }
     }
     VisualBasicExpressionFactory factory = (VisualBasicExpressionFactory) Activator.CreateInstance(VisualBasicExpressionFactoryType.MakeGenericType(new Type[] { targetType }));
     return factory.CreateVisualBasicReference(expressionText);
 }
コード例 #20
0
ファイル: ActivityMetadata.cs プロジェクト: x-strong/CoreWF
 internal ActivityMetadata(Activity activity, LocationReferenceEnvironment environment, bool createEmptyBindings)
 {
     this.activity            = activity;
     this.environment         = environment;
     this.createEmptyBindings = createEmptyBindings;
 }
コード例 #21
0
 public static void CacheMetadata(Activity rootActivity, LocationReferenceEnvironment hostEnvironment)
 {
     throw new NotImplementedException();
 }
コード例 #22
0
        internal bool InitializeRelationship(Activity parent, ActivityCollectionType collectionType, ref IList <ValidationError> validationErrors)
        {
            if (this.cacheId == parent.CacheId)
            {
                Activity owner = parent.MemberOf.Owner;
                if (owner == null)
                {
                    Activity activity2 = this.Handler;
                    if (activity2 == null)
                    {
                        ActivityUtilities.Add <ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.ActivityDelegateCannotBeReferencedWithoutTargetNoHandler(parent.DisplayName, this.owner.DisplayName), false, parent));
                    }
                    else
                    {
                        ActivityUtilities.Add <ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.ActivityDelegateCannotBeReferencedWithoutTarget(activity2.DisplayName, parent.DisplayName, this.owner.DisplayName), false, parent));
                    }
                    return(false);
                }
                if (owner.Delegates.Contains(this) || owner.ImportedDelegates.Contains(this))
                {
                    return(true);
                }
                Activity handler = this.Handler;
                if (handler == null)
                {
                    ActivityUtilities.Add <ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.ActivityDelegateCannotBeReferencedNoHandler(parent.DisplayName, owner.DisplayName, this.owner.DisplayName), false, parent));
                }
                else
                {
                    ActivityUtilities.Add <ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.ActivityDelegateCannotBeReferenced(handler.DisplayName, parent.DisplayName, owner.DisplayName, this.owner.DisplayName), false, parent));
                }
                return(false);
            }
            this.owner   = parent;
            this.cacheId = parent.CacheId;
            this.parentCollectionType = collectionType;
            this.InternalCacheMetadata();
            LocationReferenceEnvironment implementationEnvironment = null;

            if (collectionType == ActivityCollectionType.Implementation)
            {
                implementationEnvironment = parent.ImplementationEnvironment;
            }
            else
            {
                implementationEnvironment = parent.PublicEnvironment;
            }
            if (this.RuntimeDelegateArguments.Count > 0)
            {
                ActivityLocationReferenceEnvironment environment2 = new ActivityLocationReferenceEnvironment(implementationEnvironment);
                implementationEnvironment = environment2;
                for (int i = 0; i < this.RuntimeDelegateArguments.Count; i++)
                {
                    RuntimeDelegateArgument argument      = this.RuntimeDelegateArguments[i];
                    DelegateArgument        boundArgument = argument.BoundArgument;
                    if (boundArgument != null)
                    {
                        if (boundArgument.Direction != argument.Direction)
                        {
                            ActivityUtilities.Add <ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.RuntimeDelegateArgumentDirectionIncorrect, parent));
                        }
                        if (boundArgument.Type != argument.Type)
                        {
                            ActivityUtilities.Add <ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.RuntimeDelegateArgumentTypeIncorrect, parent));
                        }
                        environment2.Declare(boundArgument, this.owner, ref validationErrors);
                    }
                }
            }
            this.Environment = implementationEnvironment;
            if (this.Handler != null)
            {
                return(this.Handler.InitializeRelationship(this, collectionType, ref validationErrors));
            }
            return(true);
        }
コード例 #23
0
		public static void CacheMetadata (Activity rootActivity, LocationReferenceEnvironment hostEnvironment)
		{
			throw new NotImplementedException ();
		}