Наследование: System.Collections.CollectionBase
 public CodeNamespace()
 {
     this.imports = new CodeNamespaceImportCollection();
     this.comments = new CodeCommentStatementCollection();
     this.classes = new CodeTypeDeclarationCollection();
     this.namespaces = new CodeNamespaceCollection();
 }
 internal static void FixStandardNamespacesAndRootNamespace(CodeNamespaceCollection codeNamespaces, string rootNS, SupportedLanguages language)
 {
     if (language == SupportedLanguages.VB)
     {
         foreach (CodeNamespace namespace2 in codeNamespaces)
         {
             if (namespace2.Name == rootNS)
             {
                 namespace2.Name = string.Empty;
                 namespace2.UserData.Add("TruncatedNamespace", null);
             }
             else if (namespace2.Name.StartsWith(rootNS + ".", StringComparison.Ordinal))
             {
                 namespace2.Name = namespace2.Name.Substring(rootNS.Length + 1);
                 namespace2.UserData.Add("TruncatedNamespace", null);
             }
         }
     }
     foreach (CodeNamespace namespace3 in codeNamespaces)
     {
         Hashtable hashtable = new Hashtable();
         foreach (CodeNamespaceImport import in namespace3.Imports)
         {
             hashtable.Add(import.Namespace, import);
         }
         foreach (string str in standardNamespaces)
         {
             if (!hashtable.Contains(str))
             {
                 namespace3.Imports.Add(new CodeNamespaceImport(str));
             }
         }
     }
 }
 public CodeNamespace()
 {
     this.imports    = new CodeNamespaceImportCollection();
     this.comments   = new CodeCommentStatementCollection();
     this.classes    = new CodeTypeDeclarationCollection();
     this.namespaces = new CodeNamespaceCollection();
 }
 private CodeNamespace(SerializationInfo info, StreamingContext context)
 {
     this.imports = new CodeNamespaceImportCollection();
     this.comments = new CodeCommentStatementCollection();
     this.classes = new CodeTypeDeclarationCollection();
     this.namespaces = new CodeNamespaceCollection();
 }
 private CodeNamespace(SerializationInfo info, StreamingContext context)
 {
     this.imports    = new CodeNamespaceImportCollection();
     this.comments   = new CodeCommentStatementCollection();
     this.classes    = new CodeTypeDeclarationCollection();
     this.namespaces = new CodeNamespaceCollection();
 }
 /// <summary>Finds the client type by name in the provided collection of namespaces.</summary>
 /// <param name="typeName">The name of the client type for which to search.</param>
 /// <param name="namespaces">The collection of namespaces to search.</param>
 /// <returns>The client type if found; otherwise, null.</returns>
 internal static CodeTypeDeclaration FindClientType(string typeName, CodeNamespaceCollection namespaces)
 {
     return (from ns in namespaces.Cast<CodeNamespace>()
             from type in ns.Types.Cast<CodeTypeDeclaration>()
             where type.Name == typeName
             select type).FirstOrDefault();
 }
Пример #7
0
		public void Constructor1_NullItem ()
		{
			CodeNamespace[] namespaces = new CodeNamespace[] { 
				new CodeNamespace (), null };

			CodeNamespaceCollection coll = new CodeNamespaceCollection (
				namespaces);
		}
Пример #8
0
		public void Constructor0 ()
		{
			CodeNamespaceCollection coll = new CodeNamespaceCollection ();
			Assert.IsFalse (((IList) coll).IsFixedSize, "#1");
			Assert.IsFalse (((IList) coll).IsReadOnly, "#2");
			Assert.AreEqual (0, coll.Count, "#3");
			Assert.IsFalse (((ICollection) coll).IsSynchronized, "#4");
			Assert.IsNotNull (((ICollection) coll).SyncRoot, "#5");
		}
 public void AddRange(CodeNamespaceCollection value)
 {
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     int count = value.Count;
     for (int i = 0; i < count; i++)
     {
         this.Add(value[i]);
     }
 }
Пример #10
0
		public void Constructor1 ()
		{
			CodeNamespace ns1 = new CodeNamespace ();
			CodeNamespace ns2 = new CodeNamespace ();

			CodeNamespace[] namespaces = new CodeNamespace[] { ns1, ns2 };
			CodeNamespaceCollection coll = new CodeNamespaceCollection (
				namespaces);

			Assert.AreEqual (2, coll.Count, "#1");
			Assert.AreEqual (0, coll.IndexOf (ns1), "#2");
			Assert.AreEqual (1, coll.IndexOf (ns2), "#3");
		}
Пример #11
0
        /// <devdoc>
        ///     <para>
        ///       Adds the contents of another <see cref='System.CodeDom.CodeNamespaceCollection'/> to the end of the collection.
        ///    </para>
        /// </devdoc>
        public void AddRange(CodeNamespaceCollection value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            int currentCount = value.Count;

            for (int i = 0; i < currentCount; i = ((i) + (1)))
            {
                this.Add(value[i]);
            }
        }
Пример #12
0
		public void Constructor1_Deny_Unrestricted ()
		{
			CodeNamespaceCollection coll = new CodeNamespaceCollection (array);
			coll.CopyTo (array, 0);
			Assert.AreEqual (1, coll.Add (cn), "Add");
			Assert.AreSame (cn, coll[0], "this[int]");
			coll.AddRange (array);
			coll.AddRange (coll);
			Assert.IsTrue (coll.Contains (cn), "Contains");
			Assert.AreEqual (0, coll.IndexOf (cn), "IndexOf");
			coll.Insert (0, cn);
			coll.Remove (cn);
		}
Пример #13
0
        public void AddRange(CodeNamespaceCollection value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            int count = value.Count;

            for (int i = 0; i < count; i++)
            {
                Add(value[i]);
            }
        }
Пример #14
0
        public CodeNamespaceCollection GenerateActivityClasses(List<Activity> activities)
        {
            var activityBuilderFactory = new ActivityBuilderFactory();
            var activityClasses = new CodeNamespaceCollection();
            foreach (var activity in activities)
            {
                var activityBuilder = activityBuilderFactory.Get(activity.Type);

                var activityCodeDom = activityBuilder.Build(activity);

                activityClasses.AddRange(activityCodeDom.ClassesToGenerate);
                this.activityNameToServiceNameDictionnary.Add(activity.Name, activityCodeDom.InvocationCode);
            }
            return activityClasses;
        }
 private CodeTypeDeclaration CreateOrGetServiceDeclaration(Activity rootActivity, CodeNamespaceCollection codeNamespaceCollection)
 {
     string namespaceName = "";
     CodeNamespace webServiceCodeNamespace = null;
     string fullName = rootActivity.GetType().FullName;
     CodeTypeDeclaration webserviceCodeTypeDeclaration = null;
     if (rootActivity.GetType().FullName.IndexOf(".") != -1)
     {
         namespaceName = rootActivity.GetType().FullName.Substring(0, rootActivity.GetType().FullName.LastIndexOf('.'));
     }
     foreach (CodeNamespace namespace3 in codeNamespaceCollection)
     {
         if (namespace3.Name == namespaceName)
         {
             webServiceCodeNamespace = namespace3;
             break;
         }
     }
     if (webServiceCodeNamespace == null)
     {
         webServiceCodeNamespace = this.GetWebServiceCodeNamespace(namespaceName);
         codeNamespaceCollection.Add(webServiceCodeNamespace);
     }
     string str3 = fullName.Substring(fullName.LastIndexOf('.') + 1) + "_WebService";
     foreach (CodeTypeDeclaration declaration2 in webServiceCodeNamespace.Types)
     {
         if (declaration2.Name == str3)
         {
             webserviceCodeTypeDeclaration = declaration2;
             break;
         }
     }
     if (webserviceCodeTypeDeclaration == null)
     {
         webserviceCodeTypeDeclaration = this.GetWebserviceCodeTypeDeclaration(fullName.Substring(fullName.LastIndexOf('.') + 1));
         webServiceCodeNamespace.Types.Add(webserviceCodeTypeDeclaration);
         webServiceCodeNamespace.Imports.Add(new CodeNamespaceImport("System"));
         webServiceCodeNamespace.Imports.Add(new CodeNamespaceImport("System.Web"));
         webServiceCodeNamespace.Imports.Add(new CodeNamespaceImport("System.Web.Services"));
         webServiceCodeNamespace.Imports.Add(new CodeNamespaceImport("System.Web.Services.Protocols"));
         webServiceCodeNamespace.Imports.Add(new CodeNamespaceImport("System.Workflow.Runtime.Hosting"));
         webServiceCodeNamespace.Imports.Add(new CodeNamespaceImport("System.Workflow.Activities"));
     }
     return webserviceCodeTypeDeclaration;
 }
Пример #16
0
        public CodeNamespaceCollection Build(JavaActivity activity)
        {
            var javaNamespace = new CodeNamespace(activity.PackageName);

            // Generate the Service
            javaNamespace.Imports.AddRange(this.GenerateImports());
            var javaClass = this.GenerateClass(activity);
            javaClass.Members.Add(this.GenerateInvokeMethod());
            javaNamespace.Types.Add(javaClass);

            var codeNameSpaces =  new CodeNamespaceCollection {javaNamespace};

            // Generate the corresponding interface
            if (ConfigurationApp.GetProperty ("IsJavaInterfaceAlreadyGenerated") != "true")
            {
                //TODO : Refactor because it's a bit dirty
                var javaServiceInterfaceNameSpace = InterfaceExtractorFromClass.Extract(javaClass, TargetAppNameSpaceService.javaToolsNameSpace);
                javaServiceInterfaceNameSpace.Types[0].Name = "IJavaActivtyService";
                codeNameSpaces.Add(javaServiceInterfaceNameSpace);
                ConfigurationApp.SaveProperty("IsJavaInterfaceAlreadyGenerated", "true");
            }

            return codeNameSpaces;
        }
Пример #17
0
		public void Constructor2 ()
		{
			CodeNamespace ns1 = new CodeNamespace ();
			CodeNamespace ns2 = new CodeNamespace ();

			CodeNamespaceCollection c = new CodeNamespaceCollection ();
			c.Add (ns1);
			c.Add (ns2);

			CodeNamespaceCollection coll = new CodeNamespaceCollection (c);
			Assert.AreEqual (2, coll.Count, "#1");
			Assert.AreEqual (0, coll.IndexOf (ns1), "#2");
			Assert.AreEqual (1, coll.IndexOf (ns2), "#3");
		}
		protected virtual void ThrowOnNoTypes(CodeNamespaceCollection namespaces, string element)
		{
			if (namespaces.Count == 0)
			{
				throw new InvalidOperationException(
					string.Format(CultureInfo.CurrentCulture, Properties.Resources.CodeGenerationElementWithoutType, element));
			}
		}
Пример #19
0
	public void AddRange(CodeNamespaceCollection value)
	{
		foreach(CodeNamespace e in value)
		{
			List.Add(e);
		}
	}
Пример #20
0
 public void AddRange(CodeNamespaceCollection value)
 {
     throw new NotImplementedException();
 }
Пример #21
0
        /// <summary>
        /// Used when adding a new type to a code namespace. Method looks for a matching namespace
        /// in the namespaces collection or adds a new one if it does not exist.
        /// </summary>
        /// <param name="codeNamespaces">A collection of code namespaces.</param>
        /// <param name="namespaceName">A string containig the name of the namespace to find or add.</param>
        /// <returns>A code namespace object containing a new code namespace or an existing namespace.</returns>
        internal static CodeNamespace GetDotNetNamespace(CodeNamespaceCollection codeNamespaces, string namespaceName)
        {
            CodeNamespace dotNetNamespace = null;
            string dotNetNamespaceName = GenerateDotNetNamespace(namespaceName);

            // Search for the namespace
            foreach (CodeNamespace codeNs in codeNamespaces)
            {
                if (codeNs.Name == dotNetNamespaceName)
                    return codeNs;
            }

            // If namespace was not found create on and add it to the namespaces collection
            dotNetNamespace = new CodeNamespace(dotNetNamespaceName);
            codeNamespaces.Add(dotNetNamespace);

            s_namespaceToDotNetNamespace[dotNetNamespace] = namespaceName;

            return dotNetNamespace;
        }
Пример #22
0
		public void Remove_Null ()
		{
			CodeNamespaceCollection coll = new CodeNamespaceCollection ();
			coll.Remove ((CodeNamespace) null);
		}
 CodeNamespaceCollection GenerateProcessVariablesNamespaces(TibcoBWProcess tibcoBwProcessToGenerate)
 {
     CodeNamespaceCollection processVariableNameNamespaces = new CodeNamespaceCollection();
     if (tibcoBwProcessToGenerate.ProcessVariables != null)
     {
         foreach (var item in tibcoBwProcessToGenerate.ProcessVariables)
         {
             if (!IsBasicType(item.Parameter.Type))
             {
                 processVariableNameNamespaces.Add(this.xsdClassGenerator.Build(item.ObjectXNodes, tibcoBwProcessToGenerate.NameSpace));
             }
         }
     }
     return processVariableNameNamespaces;
 }
		public void AddRange_Null_Item ()
		{
			CodeNamespaceCollection coll = new CodeNamespaceCollection ();
			coll.AddRange (new CodeNamespace[] { null });
		}
        public CodeNamespaceCollection (CodeNamespaceCollection value) {

          return default(CodeNamespaceCollection);
        }
        public void AddRange (CodeNamespaceCollection! value) {
            Contract.Requires(value != null);

        }
        internal static void ReapplyRootNamespace(CodeNamespaceCollection codeNamespaces, string rootNS, SupportedLanguages language)
        {
            if (language == SupportedLanguages.VB)
            {
                foreach (CodeNamespace codeNamespace in codeNamespaces)
                {
                    if (codeNamespace.UserData.Contains("TruncatedNamespace"))
                    {
                        if (codeNamespace.Name == null || codeNamespace.Name.Length == 0)
                            codeNamespace.Name = rootNS;
                        else if (codeNamespace.Name.StartsWith(rootNS + ".", StringComparison.Ordinal))
                            codeNamespace.Name = rootNS + "." + codeNamespace.Name;

                        codeNamespace.UserData.Remove("TruncatedNamespace");
                    }
                }
            }
        }
 internal static CodeNamespaceCollection GenerateCodeFromXomlDocument(Activity rootActivity, string filePath, string rootNamespace, SupportedLanguages language, IServiceProvider serviceProvider)
 {
     CodeNamespaceCollection namespaces = new CodeNamespaceCollection();
     CodeDomProvider codeDomProvider = CompilerHelpers.GetCodeDomProvider(language);
     string str = rootActivity.GetValue(WorkflowMarkupSerializer.XClassProperty) as string;
     CodeTypeDeclaration declaration = null;
     if ((codeDomProvider != null) && !string.IsNullOrEmpty(str))
     {
         string str2;
         string str3;
         Helpers.GetNamespaceAndClassName(str, out str2, out str3);
         if (codeDomProvider.IsValidIdentifier(str3))
         {
             DesignerSerializationManager manager = new DesignerSerializationManager(serviceProvider);
             using (manager.CreateSession())
             {
                 ActivityCodeDomSerializationManager manager2 = new ActivityCodeDomSerializationManager(manager);
                 TypeCodeDomSerializer serializer = manager2.GetSerializer(rootActivity.GetType(), typeof(TypeCodeDomSerializer)) as TypeCodeDomSerializer;
                 bool flag = true;
                 ArrayList list = new ArrayList();
                 list.Add(rootActivity);
                 if (rootActivity is CompositeActivity)
                 {
                     foreach (Activity activity in Helpers.GetNestedActivities((CompositeActivity) rootActivity))
                     {
                         if (!Helpers.IsActivityLocked(activity))
                         {
                             if (codeDomProvider.IsValidIdentifier(manager2.GetName(activity)))
                             {
                                 list.Insert(0, activity);
                             }
                             else
                             {
                                 flag = false;
                                 break;
                             }
                         }
                     }
                 }
                 if (flag)
                 {
                     DummySite site = new DummySite();
                     foreach (Activity activity2 in list)
                     {
                         activity2.Site = site;
                     }
                     rootActivity.Site = site;
                     declaration = serializer.Serialize(manager2, rootActivity, list);
                     declaration.IsPartial = true;
                     if ((filePath != null) && (filePath.Length > 0))
                     {
                         MD5 md = new MD5CryptoServiceProvider();
                         byte[] buffer = null;
                         using (StreamReader reader = new StreamReader(filePath))
                         {
                             buffer = md.ComputeHash(reader.BaseStream);
                         }
                         string str4 = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}", new object[] { buffer[0].ToString("X2", CultureInfo.InvariantCulture), buffer[1].ToString("X2", CultureInfo.InvariantCulture), buffer[2].ToString("X2", CultureInfo.InvariantCulture), buffer[3].ToString("X2", CultureInfo.InvariantCulture), buffer[4].ToString("X2", CultureInfo.InvariantCulture), buffer[5].ToString("X2", CultureInfo.InvariantCulture), buffer[6].ToString("X2", CultureInfo.InvariantCulture), buffer[7].ToString("X2", CultureInfo.InvariantCulture), buffer[8].ToString("X2", CultureInfo.InvariantCulture), buffer[9].ToString("X2", CultureInfo.InvariantCulture), buffer[10].ToString("X2", CultureInfo.InvariantCulture), buffer[11].ToString("X2", CultureInfo.InvariantCulture), buffer[12].ToString("X2", CultureInfo.InvariantCulture), buffer[13].ToString("X2", CultureInfo.InvariantCulture), buffer[14].ToString("X2", CultureInfo.InvariantCulture), buffer[15].ToString("X2", CultureInfo.InvariantCulture) });
                         CodeAttributeDeclaration declaration2 = new CodeAttributeDeclaration(typeof(WorkflowMarkupSourceAttribute).FullName);
                         declaration2.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(filePath)));
                         declaration2.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(str4)));
                         declaration.CustomAttributes.Add(declaration2);
                     }
                     CodeNamespace namespace2 = new CodeNamespace(str2);
                     namespace2.Types.Add(declaration);
                     namespaces.Add(namespace2);
                 }
             }
         }
     }
     if (declaration != null)
     {
         Queue queue = new Queue(new object[] { rootActivity });
         while (queue.Count > 0)
         {
             Activity activity3 = (Activity) queue.Dequeue();
             if (!Helpers.IsActivityLocked(activity3))
             {
                 Queue queue2 = new Queue(new object[] { activity3 });
                 while (queue2.Count > 0)
                 {
                     Activity activity4 = (Activity) queue2.Dequeue();
                     if (activity4 is CompositeActivity)
                     {
                         foreach (Activity activity5 in ((CompositeActivity) activity4).Activities)
                         {
                             queue2.Enqueue(activity5);
                         }
                     }
                     CodeTypeMemberCollection members = activity4.GetValue(WorkflowMarkupSerializer.XCodeProperty) as CodeTypeMemberCollection;
                     if (members != null)
                     {
                         foreach (CodeSnippetTypeMember member in members)
                         {
                             declaration.Members.Add(member);
                         }
                     }
                 }
             }
         }
         if (language == SupportedLanguages.CSharp)
         {
             declaration.LinePragma = new CodeLinePragma((string) rootActivity.GetValue(ActivityCodeDomSerializer.MarkupFileNameProperty), Math.Max((int) rootActivity.GetValue(ActivityMarkupSerializer.StartLineProperty), 1));
         }
         CodeConstructor constructor = null;
         CodeMemberMethod method = null;
         foreach (CodeTypeMember member2 in declaration.Members)
         {
             if ((constructor == null) && (member2 is CodeConstructor))
             {
                 constructor = member2 as CodeConstructor;
             }
             if (((method == null) && (member2 is CodeMemberMethod)) && member2.Name.Equals("InitializeComponent", StringComparison.Ordinal))
             {
                 method = member2 as CodeMemberMethod;
             }
             if ((constructor != null) && (method != null))
             {
                 break;
             }
         }
         if (constructor != null)
         {
             constructor.LinePragma = new CodeLinePragma((string) rootActivity.GetValue(ActivityCodeDomSerializer.MarkupFileNameProperty), Math.Max((int) rootActivity.GetValue(ActivityMarkupSerializer.StartLineProperty), 1));
         }
         if ((method != null) && (language == SupportedLanguages.CSharp))
         {
             method.LinePragma = new CodeLinePragma((string) rootActivity.GetValue(ActivityCodeDomSerializer.MarkupFileNameProperty), Math.Max((int) rootActivity.GetValue(ActivityMarkupSerializer.StartLineProperty), 1));
         }
     }
     List<string> list2 = rootActivity.GetValue(WorkflowMarkupSerializer.ClrNamespacesProperty) as List<string>;
     if (list2 != null)
     {
         foreach (CodeNamespace namespace3 in namespaces)
         {
             foreach (string str5 in list2)
             {
                 if (!string.IsNullOrEmpty(str5))
                 {
                     CodeNamespaceImport import = new CodeNamespaceImport(str5) {
                         LinePragma = new CodeLinePragma((string) rootActivity.GetValue(ActivityCodeDomSerializer.MarkupFileNameProperty), Math.Max((int) rootActivity.GetValue(ActivityMarkupSerializer.StartLineProperty), 1))
                     };
                     namespace3.Imports.Add(import);
                 }
             }
         }
     }
     return namespaces;
 }
        internal static CodeNamespaceCollection GenerateCodeFromXomlDocument(Activity rootActivity, string filePath, string rootNamespace, SupportedLanguages language, IServiceProvider serviceProvider)
        {
            CodeNamespaceCollection codeNamespaces = new CodeNamespaceCollection();
            CodeDomProvider codeDomProvider = CompilerHelpers.GetCodeDomProvider(language);

            // generate activity class
            string activityFullClassName = rootActivity.GetValue(WorkflowMarkupSerializer.XClassProperty) as string;
            CodeTypeDeclaration activityTypeDeclaration = null;
            if (codeDomProvider != null && !string.IsNullOrEmpty(activityFullClassName))
            {
                // get class and namespace names
                string activityNamespaceName, activityClassName;
                Helpers.GetNamespaceAndClassName(activityFullClassName, out activityNamespaceName, out activityClassName);
                if (codeDomProvider.IsValidIdentifier(activityClassName))
                {
                    DesignerSerializationManager designerSerializationManager = new DesignerSerializationManager(serviceProvider);
                    using (designerSerializationManager.CreateSession())
                    {
                        ActivityCodeDomSerializationManager codeDomSerializationManager = new ActivityCodeDomSerializationManager(designerSerializationManager);
                        TypeCodeDomSerializer typeCodeDomSerializer = codeDomSerializationManager.GetSerializer(rootActivity.GetType(), typeof(TypeCodeDomSerializer)) as TypeCodeDomSerializer;

                        // get all activities
                        bool generateCode = true;

                        ArrayList allActivities = new ArrayList();
                        allActivities.Add(rootActivity);
                        if (rootActivity is CompositeActivity)
                        {
                            foreach (Activity activity in Helpers.GetNestedActivities((CompositeActivity)rootActivity))
                            {
                                if (Helpers.IsActivityLocked(activity))
                                    continue;
                                if (codeDomProvider.IsValidIdentifier(codeDomSerializationManager.GetName(activity)))
                                {
                                    // WinOE Bug 14561.  This is to fix a performance problem.  When an activity is added to the activity
                                    // tree at the runtime, it's much faster if the ID of the activity is already set.  The code that
                                    // the CodeDomSerializer generates will add the activity first before it sets the ID for the child
                                    // activity.  We can change that order by always serializing the children first.  Therefore, we 
                                    // construct a list where we guarantee that the child will be serialized before its parent.
                                    allActivities.Insert(0, activity);
                                }
                                else
                                {
                                    generateCode = false;
                                    break;
                                }
                            }
                        }

                        if (generateCode)
                        {
                            // Work around!! TypeCodeDomSerializer checks that root component has a site or not, otherwise it
                            // does not serialize it look at ComponentTypeCodeDomSerializer.cs
                            DummySite dummySite = new DummySite();
                            foreach (Activity nestedActivity in allActivities)
                                ((IComponent)nestedActivity).Site = dummySite;
                            ((IComponent)rootActivity).Site = dummySite;

                            // create activity partial class
                            activityTypeDeclaration = typeCodeDomSerializer.Serialize(codeDomSerializationManager, rootActivity, allActivities);
                            activityTypeDeclaration.IsPartial = true;

                            // add checksum attribute
                            if (filePath != null && filePath.Length > 0)
                            {
                                MD5 md5 = new MD5CryptoServiceProvider();
                                byte[] checksumBytes = null;
                                using (StreamReader streamReader = new StreamReader(filePath))
                                    checksumBytes = md5.ComputeHash(streamReader.BaseStream);
                                string checksum = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}", new object[] { checksumBytes[0].ToString("X2", CultureInfo.InvariantCulture), checksumBytes[1].ToString("X2", CultureInfo.InvariantCulture), checksumBytes[2].ToString("X2", CultureInfo.InvariantCulture), checksumBytes[3].ToString("X2", CultureInfo.InvariantCulture), checksumBytes[4].ToString("X2", CultureInfo.InvariantCulture), checksumBytes[5].ToString("X2", CultureInfo.InvariantCulture), checksumBytes[6].ToString("X2", CultureInfo.InvariantCulture), checksumBytes[7].ToString("X2", CultureInfo.InvariantCulture), checksumBytes[8].ToString("X2", CultureInfo.InvariantCulture), checksumBytes[9].ToString("X2", CultureInfo.InvariantCulture), checksumBytes[10].ToString("X2", CultureInfo.InvariantCulture), checksumBytes[11].ToString("X2", CultureInfo.InvariantCulture), checksumBytes[12].ToString("X2", CultureInfo.InvariantCulture), checksumBytes[13].ToString("X2", CultureInfo.InvariantCulture), checksumBytes[14].ToString("X2", CultureInfo.InvariantCulture), checksumBytes[15].ToString("X2", CultureInfo.InvariantCulture) });
                                CodeAttributeDeclaration xomlSourceAttribute = new CodeAttributeDeclaration(typeof(WorkflowMarkupSourceAttribute).FullName);
                                xomlSourceAttribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(filePath)));
                                xomlSourceAttribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(checksum)));
                                activityTypeDeclaration.CustomAttributes.Add(xomlSourceAttribute);
                            }

                            // create a new namespace and add activity class into that
                            CodeNamespace activityCodeNamespace = new CodeNamespace(activityNamespaceName);
                            activityCodeNamespace.Types.Add(activityTypeDeclaration);
                            codeNamespaces.Add(activityCodeNamespace);
                        }
                    }
                }
            }

            // generate code for x:Code
            if (activityTypeDeclaration != null)
            {
                Queue activitiesQueue = new Queue(new object[] { rootActivity });
                while (activitiesQueue.Count > 0)
                {
                    Activity activity = (Activity)activitiesQueue.Dequeue();
                    if (Helpers.IsActivityLocked(activity))
                        continue;

                    Queue childActivities = new Queue(new object[] { activity });
                    while (childActivities.Count > 0)
                    {
                        Activity childActivity = (Activity)childActivities.Dequeue();
                        if (childActivity is CompositeActivity)
                        {
                            foreach (Activity nestedChildActivity in ((CompositeActivity)childActivity).Activities)
                            {
                                childActivities.Enqueue(nestedChildActivity);
                            }
                        }

                        // generate x:Code
                        CodeTypeMemberCollection codeSegments = childActivity.GetValue(WorkflowMarkupSerializer.XCodeProperty) as CodeTypeMemberCollection;
                        if (codeSegments != null)
                        {
                            foreach (CodeSnippetTypeMember codeSegmentMember in codeSegments)
                                activityTypeDeclaration.Members.Add(codeSegmentMember);
                        }
                    }
                }

                if (language == SupportedLanguages.CSharp)
                    activityTypeDeclaration.LinePragma = new CodeLinePragma((string)rootActivity.GetValue(ActivityCodeDomSerializer.MarkupFileNameProperty), Math.Max((int)rootActivity.GetValue(ActivityMarkupSerializer.StartLineProperty), 1));

                //Now make sure we that we also emit line pragma around the constructor
                CodeConstructor constructor = null;
                CodeMemberMethod method = null;
                foreach (CodeTypeMember typeMember in activityTypeDeclaration.Members)
                {
                    if (constructor == null && typeMember is CodeConstructor)
                        constructor = typeMember as CodeConstructor;

                    if (method == null && typeMember is CodeMemberMethod && typeMember.Name.Equals("InitializeComponent", StringComparison.Ordinal))
                        method = typeMember as CodeMemberMethod;

                    if (constructor != null && method != null)
                        break;
                }

                if (constructor != null)
                    constructor.LinePragma = new CodeLinePragma((string)rootActivity.GetValue(ActivityCodeDomSerializer.MarkupFileNameProperty), Math.Max((int)rootActivity.GetValue(ActivityMarkupSerializer.StartLineProperty), 1));

                if (method != null && language == SupportedLanguages.CSharp)
                    method.LinePragma = new CodeLinePragma((string)rootActivity.GetValue(ActivityCodeDomSerializer.MarkupFileNameProperty), Math.Max((int)rootActivity.GetValue(ActivityMarkupSerializer.StartLineProperty), 1));
            }

            // generate mappings
            List<String> clrNamespaces = rootActivity.GetValue(WorkflowMarkupSerializer.ClrNamespacesProperty) as List<String>;
            if (clrNamespaces != null)
            {
                // foreach namespace add these mappings
                foreach (CodeNamespace codeNamespace in codeNamespaces)
                {
                    foreach (string clrNamespace in clrNamespaces)
                    {
                        if (!String.IsNullOrEmpty(clrNamespace))
                        {
                            CodeNamespaceImport codeNamespaceImport = new CodeNamespaceImport(clrNamespace);
                            codeNamespaceImport.LinePragma = new CodeLinePragma((string)rootActivity.GetValue(ActivityCodeDomSerializer.MarkupFileNameProperty), Math.Max((int)rootActivity.GetValue(ActivityMarkupSerializer.StartLineProperty), 1));
                            codeNamespace.Imports.Add(codeNamespaceImport);
                        }
                    }
                }
            }
            // return namespaces
            return codeNamespaces;
        }
Пример #30
0
		public void Constructor1_Null () {
			CodeNamespaceCollection coll = new CodeNamespaceCollection (
				(CodeNamespace[]) null);
		}
 public void AddRange(CodeNamespaceCollection !value)
 {
     Contract.Requires(value != null);
 }
Пример #32
0
 /// <devdoc>
 ///     <para>
 ///       Initializes a new instance of <see cref='System.CodeDom.CodeNamespaceCollection'/> based on another <see cref='System.CodeDom.CodeNamespaceCollection'/>.
 ///    </para>
 /// </devdoc>
 public CodeNamespaceCollection(CodeNamespaceCollection value) {
     this.AddRange(value);
 }
 public CodeNamespaceCollection(CodeNamespaceCollection value)
 {
     return(default(CodeNamespaceCollection));
 }
Пример #34
0
        /// <summary>
        /// Gets the DotNetNamespace for a given typename
        /// </summary>
        /// <param name="codeNamespaces">The CodeNamespace collection to search in.</param>
        /// <param name="typeName">The name of a type (data contract) to search for.</param>
        /// <returns>The DotNetNamespace for the given type if found, otherwise an empty string.</returns>
        internal static string GetNamespaceFromType(CodeNamespaceCollection codeNamespaces, string typeName)
        {
            // strip off the namespace
            int idx = typeName.LastIndexOf(".");
            string ns = "";

            if(idx >= 0)
            {
                ns = typeName.Substring(0, idx);
                
                typeName = typeName.Remove(0, idx+1);
            }
            
            // Search for the namespace
            foreach (CodeNamespace codeNs in codeNamespaces)
            {
                if(codeNs.Name == ns || ns == "")
                {
                    foreach(CodeTypeDeclaration ctd in codeNs.Types)
                    {
                        if(ctd.Name == typeName)
                        {
                            if(s_namespaceToDotNetNamespace.ContainsKey(codeNs))
                            {
                                return s_namespaceToDotNetNamespace[codeNs];
                            }
                            else
                            {
                                return "";
                            }
                        }
                    }
                }
            }
            
            return "";
        }
        public Type[] Generate(IEnumerable<XPathModuleInfo> modules)
        {
            bool debuggerIsAttached = Debugger.IsAttached;

             var generatedTypeNames = new List<string>();

             var compilerParams = new CompilerParameters {
            GenerateInMemory = !debuggerIsAttached,
            ReferencedAssemblies = {
               // current assembly
               typeof(IntegratedExtensionFunctionGenerator).Assembly.Location,

               // Saxon.Api
               typeof(ExtensionFunctionDefinition).Assembly.Location,

               // System
               typeof(Uri).Assembly.Location,

               // System.Core
               typeof(Enumerable).Assembly.Location,
            }
             };

             var namespaces = new CodeNamespaceCollection();

             foreach (XPathModuleInfo module in modules) {

            string[] functionDefTypeNames;

            namespaces.Add(GenerateModuleTypes(module, out functionDefTypeNames));
            generatedTypeNames.AddRange(functionDefTypeNames);

            AddAssemblyReference(compilerParams, module.Type.Assembly);

            foreach (XPathFunctionInfo function in module.Functions) {
               AddAssemblyReference(compilerParams, function.ReturnType.ClrType.Assembly);

               foreach (XPathVariableInfo param in function.Parameters) {
                  AddAssemblyReference(compilerParams, param.Type.ClrType.Assembly);
               }
            }
             }

             var compileUnit = new CodeCompileUnit();
             compileUnit.Namespaces.AddRange(namespaces);

             CompilerResults result = this.provider.CompileAssemblyFromDom(compilerParams, compileUnit);

             CompilerError firstError = result.Errors.Cast<CompilerError>().FirstOrDefault(e => !e.IsWarning);

             if (firstError != null) {

            using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture)) {

               provider.GenerateCodeFromCompileUnit(compileUnit, stringWriter, null);

               if (debuggerIsAttached) {
                  Debugger.Log(0, Debugger.DefaultCategory, "Integrated extension function generation error:" + Environment.NewLine);
                  Debugger.Log(0, Debugger.DefaultCategory, stringWriter.ToString());
               }
            }

            throw new ArgumentException(firstError.ErrorText, "modules");
             }

             if (debuggerIsAttached) {
            Debugger.Log(0, Debugger.DefaultCategory, "Integrated extension function(s) generated " + result.PathToAssembly + Environment.NewLine);
             }

             return generatedTypeNames
            .Select(n => result.CompiledAssembly.GetType(n, throwOnError: true))
            .ToArray();
        }
Пример #36
0
 /// <devdoc>
 ///     <para>
 ///       Initializes a new instance of <see cref='System.CodeDom.CodeNamespaceCollection'/> based on another <see cref='System.CodeDom.CodeNamespaceCollection'/>.
 ///    </para>
 /// </devdoc>
 public CodeNamespaceCollection(CodeNamespaceCollection value)
 {
     this.AddRange(value);
 }
Пример #37
0
 public CodeNamespaceCollection(CodeNamespaceCollection value)
 {
     throw new NotImplementedException();
 }
        internal static void FixStandardNamespacesAndRootNamespace(CodeNamespaceCollection codeNamespaces, string rootNS, SupportedLanguages language)
        {
            // add the standard imports to all the namespaces.
            if (language == SupportedLanguages.VB)
            {
                foreach (CodeNamespace codeNamespace in codeNamespaces)
                {
                    if (codeNamespace.Name == rootNS)
                    {
                        codeNamespace.Name = string.Empty;
                        codeNamespace.UserData.Add("TruncatedNamespace", null);
                    }
                    else if (codeNamespace.Name.StartsWith(rootNS + ".", StringComparison.Ordinal))
                    {
                        codeNamespace.Name = codeNamespace.Name.Substring(rootNS.Length + 1);
                        codeNamespace.UserData.Add("TruncatedNamespace", null);
                    }
                }
            }

            foreach (CodeNamespace codeNamespace in codeNamespaces)
            {
                Hashtable definedNamespaces = new Hashtable();
                foreach (CodeNamespaceImport codeNamespaceImport in codeNamespace.Imports)
                    definedNamespaces.Add(codeNamespaceImport.Namespace, codeNamespaceImport);

                foreach (string standardNS in standardNamespaces)
                    if (!definedNamespaces.Contains(standardNS))//add only new imports
                        codeNamespace.Imports.Add(new CodeNamespaceImport(standardNS));
            }
        }
Пример #39
0
 protected void Rewrite(CodeNamespaceCollection target, CodeNamespaceCollection source, ref bool didRewrite)
 {
     foreach (CodeNamespace item in source)
     {
         target.Add(this.Rewrite(item, ref didRewrite));
     }
 }