Example #1
0
    //**********************************************************************************
        private static void addXAMLreferences(cfgNode itemGroup)
        {
            cfgNode   n;
            attribute attr;
        //******************************************************************************
        // Add references to support XAML and WPF
        //******************************************************************************
            n          = new cfgNode("Reference");
            attr       = new attribute();
            attr.name  = "Include";
            attr.value = "WindowsBase";
            n.attributes.Add(attr);
            itemGroup.children.Add(n);

            n          = new cfgNode("Reference");
            attr       = new attribute();
            attr.name  = "Include";
            attr.value = "PresentationCore";
            n.attributes.Add(attr);
            itemGroup.children.Add(n);

            n          = new cfgNode("Reference");
            attr       = new attribute();
            attr.name  = "Include";
            attr.value = "PresentationFramework";
            n.attributes.Add(attr);
            itemGroup.children.Add(n);
        }
Example #2
0
        public int parse(XmlTextReader r)
        {
            bool parse_doc = !r.IsEmptyElement;

            if (r.HasAttributes)
            {
                for (int i = 0; i < r.AttributeCount; i++)
                {
                    r.MoveToAttribute(i);
                    attribute a = new attribute();
                    a.name  = r.Name;
                    a.value = r.Value;
                    attributes.Add(a);
                }
            }
            while (parse_doc)
            {
                parse_doc = r.Read();
                switch (r.NodeType)
                {
                case XmlNodeType.Element:
                    cfgNode n = new cfgNode(r.Name);
                    n.parse(r);
                    children.Add(n);
                    break;
                //
                //you can handle other cases here
                //

                case XmlNodeType.EndElement:
                    parse_doc = false;
                    break;

                case XmlNodeType.Text:
                    text = r.Value;
                    break;
                }
            }

            return(children.Count);
        }
Example #3
0
    //**********************************************************************************
        private static void addXAMLcode(cfgNode itemGroup, Project p)
        {
            int       i = 0;
            cfgNode   n;
            cfgNode   cn;
            attribute attr;
        //******************************************************************************
        // Add Application definition files
        //******************************************************************************
            n          = new cfgNode("ApplicationDefinition");
            attr       = new attribute();
            attr.name  = "Include";
            attr.value = "App.xaml";
            n.attributes.Add(attr);
            cn         = new cfgNode("Generator");
            cn.text    = "MSBuild:Compile";
            n.children.Add(cn);
            cn         = new cfgNode("SubType");
            cn.text    = "Designer";
            n.children.Add(cn);
            itemGroup.children.Insert(i++, n);

            n          = new cfgNode("Compile");
            attr       = new attribute();
            attr.name  = "Include";
            attr.value = "App.xaml.cs";
            n.attributes.Add(attr);
            cn         = new cfgNode("DependentUpon");
            cn.text    = "App.xaml";
            n.children.Add(cn);
            cn         = new cfgNode("SubType");
            cn.text    = "Code";
            n.children.Add(cn);
            itemGroup.children.Insert(i++, n);
        //******************************************************************************
        // Add converted form source files...
        //******************************************************************************
            foreach (cForm f in p.forms)
            {
            //**************************************************************************
            // XAML definition - replaces designer file
            //**************************************************************************
                n          = new cfgNode("Page");
                attr       = new attribute();
                attr.name  = "Include";
                attr.value = Project.formFile(f.definition_file, ".xaml");
                n.attributes.Add(attr);
                cn         = new cfgNode("Generator");
                cn.text    = "MSBuild:Compile";
                n.children.Add(cn);
                cn         = new cfgNode("SubType");
                cn.text    = "Designer";
                n.children.Add(cn);
                itemGroup.children.Insert(i++, n);
            //**************************************************************************
            // CS file - replaces form source file
            //**************************************************************************
                n          = new cfgNode("Compile");
                attr       = new attribute();
                attr.name  = "Include";
                attr.value = Project.formFile(f.definition_file, ".xaml.cs");
                n.attributes.Add(attr);
                cn         = new cfgNode("DependentUpon");
                cn.text    = Project.formFile(f.definition_file, ".xaml");
                n.children.Add(cn);
                cn         = new cfgNode("SubType");
                cn.text    = "Code";
                n.children.Add(cn);
                itemGroup.children.Insert(i++, n);
            }
        }
Example #4
0
    //**********************************************************************************
    // This method creates a new configuration file - csproj - for WPF.
    //**********************************************************************************
        public static void convertConfiguration(Project project)
        {
        //******************************************************************************
        // Walk through the project children
        //******************************************************************************
            foreach (cfgNode c in project.children)
            {
            //**************************************************************************
            // ItemGroup - contains references and source files
            //**************************************************************************
                if (c.name == "ItemGroup")
                {
                    bool      add_xaml_code = false;
                    bool      add_xaml_ref  = false;
                    ArrayList remove        = new ArrayList();
                //**********************************************************************
                // Look for statements we need to convert
                //**********************************************************************
                    foreach (cfgNode item in c.children)
                    {
                        switch (item.name)
                        {
                            case "Reference":   // Reference group
                            //**********************************************************
                            // add WPF references...
                            //**********************************************************
                                add_xaml_ref = true;
                                break;
                            case "Compile":     // Source group
                            //**********************************************************
                            // remove Form files and add WPF files/defs
                            //**********************************************************
                                add_xaml_code = true;
                                if (item.attributes.Count > 0)
                                {
                                    attribute a  = (attribute)item.attributes[0];
                                //******************************************************
                                // Skip any property files...
                                //******************************************************
                                    if (a.value.Contains("Properties\\")) break;
                                //******************************************************
                                // Check for files to remove...
                                //******************************************************
                                    if (a.value == "Program.cs" ||
                                        a.value.Contains(".Designer.cs"))
                                    {
                                        remove.Add(item);
                                    }
                                //******************************************************
                                // Also remove any form sources - already converted to 
                                // XAML equivalent
                                //******************************************************
                                    foreach (cfgNode cn in item.children)
                                    {
                                        if (cn.name == "SubType" &&
                                            cn.text == "Form")
                                        {
                                            remove.Add(item);
                                            break;
                                        }
                                    }
                                }
                                break;
                            case "EmbeddedResource":    // Resource
                            //**********************************************************
                            // remove Form resources
                            //**********************************************************
                                foreach (attribute a in item.attributes)    
                                {
                                    if (project.isFormResx(a.value))
                                    {
                                        remove.Add(item);
                                    }
                                }

                                break;
                        }
                    }
                //**********************************************************************
                // Remove the items we found...
                //**********************************************************************
                    foreach (cfgNode item in remove)
                        c.children.Remove(item);
                //**********************************************************************
                // Add code and references for WPF/XAML
                //**********************************************************************
                    if (add_xaml_code) addXAMLcode(c, project);
                    if (add_xaml_ref)  addXAMLreferences(c);
                }
            }
        }