Example #1
0
        /// <summary>
        /// Render feature list
        /// </summary>
        private void RenderFeatureList(List<Feature> features, string[][] templateFields, List<KeyValuePair<FeatureRendererAttribute, IFeatureRenderer>> renderers, BuildItemGroup fileItemGroup, BuildItemGroup mobileItemGroup, Dictionary<String, StringCollection> parameters)
        {
            // Scan the class repo and start processing
            foreach (Feature f in features)
            {
                System.Diagnostics.Trace.WriteLine(String.Format("Rendering C# for '{0}'...", f.Name), "debug");

                // Is there a renderer for this feature
                KeyValuePair<FeatureRendererAttribute, IFeatureRenderer> fr = renderers.Find(o => o.Key.Feature == f.GetType());

                // Was a renderer found?
                if (fr.Key == null)
                    System.Diagnostics.Trace.WriteLine(String.Format("can't find renderer for {0}", f.GetType().Name), "warn");
                else
                {
                    string file = String.Empty;
                    try // To write the file
                    {
                        // Start the rendering
                        file = fr.Value.CreateFile(f, hostContext.Output);

                        // Is the renderer for a file
                        if (fr.Key.IsFile)
                        {

                            TextWriter tw = File.CreateText(file);
                            try // Render the file
                            {

                                string Header = Template.Default; // Set the header to the default

                                // Populate template fields
                                foreach (String[] st in templateFields)
                                    Header = Header.Replace(st[0], st[1]);

                                // Write header
                                tw.Write(Header);

                                // Render the template out
                                fr.Value.Render(parameters["rimbapi-target-ns"][0], parameters["rimbapi-api-ns"][0], f, tw);
                            }
                            finally
                            {
                                tw.Close();
                            }

                            // Add to the files in the project
                            string projName = file.Replace(hostContext.Output, "");
                            if (projName.StartsWith(Path.DirectorySeparatorChar.ToString()))
                                projName = projName.Substring(1);
                            if (Array.Find<BuildItem>(fileItemGroup.ToArray(), itm => itm.Include.Equals(projName)) == null)
                            {
                                fileItemGroup.AddNewItem("Compile", projName);
                                mobileItemGroup.AddNewItem("Compile", projName);
                            }
                            else
                                Trace.WriteLine(String.Format("Class '{0}' is defined more than once, second include is ignored", projName), "warn");

                        }
                    }
                    catch (NotSupportedException)
                    {
                        if (!String.IsNullOrEmpty(file)) File.Delete(file);
                    }
                    catch (Exception e)
                    {
                        if (!String.IsNullOrEmpty(file)) File.Delete(file);
                        System.Diagnostics.Trace.WriteLine(e.Message, "error");
                    }
                }
            }
        }
		public void TestToArray1 ()
		{
			BuildItemGroup big = new BuildItemGroup ();

			BuildItem[] items = big.ToArray ();

			Assert.AreEqual (0, items.Length, "A1");

			big.AddNewItem ("a", "b");
			big.AddNewItem ("c", "d");

			items = big.ToArray ();

			Assert.AreEqual ("a", items [0].Name, "A2");
			Assert.AreEqual ("c", items [1].Name, "A3");
		}
Example #3
0
 /// <summary>
 /// Amazingly sophisticated :) helper function to determine if the set of ITaskItems returned from 
 /// a task match the expected set of ITaskItems.  It can also check that the ITaskItems have the expected
 /// metadata, and that the ITaskItems are returned in the correct order.
 /// 
 /// The "expectedItemsString" is a formatted way of easily specifying which items you expect to see.
 /// The format is:
 /// 
 ///         itemspec1 :   metadataname1=metadatavalue1 ; metadataname2=metadatavalue2 ; ...
 ///         itemspec2 :   metadataname3=metadatavalue3 ; metadataname4=metadatavalue4 ; ...
 ///         itemspec3 :   metadataname5=metadatavalue5 ; metadataname6=metadatavalue6 ; ...
 /// 
 /// (Each item needs to be on its own line.)
 /// 
 /// </summary>
 /// <param name="expectedItemsString"></param>
 /// <param name="actualItems"></param>
 /// <owner>RGoel</owner>
 static internal void AssertItemsMatch
     (
     string expectedItemsString, 
     BuildItemGroup actualItems, 
     bool orderOfItemsShouldMatch
     )
 {
     AssertItemsMatch(expectedItemsString, actualItems.ToArray(), orderOfItemsShouldMatch);
 }
		public void TestRemoveItemAt1 ()
		{
			BuildItemGroup big = new BuildItemGroup ();

			big.AddNewItem ("a", "b");
			big.AddNewItem ("b", "c");
			big.AddNewItem ("c", "d");

			big.RemoveItemAt (1);

			BuildItem[] items = big.ToArray ();
			Assert.AreEqual (2, big.Count, "A1");
			Assert.AreEqual ("a", items [0].Name, "A2");
			Assert.AreEqual ("c", items [1].Name, "A3");
		}
Example #5
0
        public void ToArray()
        {
            XmlElement ig = CreatePersistedItemGroupElement();
            BuildItemGroup group = new BuildItemGroup(ig, false, new Project());
            BuildItem[] array = group.ToArray();

            Assertion.AssertEquals(2, array.Length);
            Assertion.AssertEquals("i1", array[0].Include);
            Assertion.AssertEquals("i2", array[1].Include);
        }