static ComparisonNode MakeComparisonNode(string info_file, string dll_file)
        {
            if (!File.Exists(info_file))
            {
                Console.Error.WriteLine("{0} does not exist", info_file);
                return(null);
            }
            if (!File.Exists(dll_file))
            {
                Console.Error.WriteLine("{0} does not exist", dll_file);
                return(null);
            }

            CompareContext cc = new CompareContext(
                () => new MasterAssembly(info_file),
                () => new CecilAssembly(dll_file));

            cc.ProgressChanged += delegate(object sender, CompareProgressChangedEventArgs a)
            {
                //Console.Error.WriteLine (a.Message);
            };
            bool have_error = false;

            cc.Error += delegate(object sender, CompareErrorEventArgs args)
            {
                have_error = true;
                Console.Error.WriteLine("Error loading {0}: {1}", info_file, args.Message.Split(Environment.NewLine.ToCharArray())[0]);
            };
            ManualResetEvent r = new ManualResetEvent(false);

            cc.Finished += delegate
            {
                r.Set();
            };
            cc.Compare();
            r.WaitOne();
            if (have_error)
            {
                return(null);
            }
            cc.Comparison.PropagateCounts();
            return(cc.Comparison);
        }
    public void StartCompare(WaitCallback done)
    {
        AdditionalInfoWindow.Visible = false;

        progressbar1.Visible          = true;
        progressbar1.Adjustment.Lower = 0;
        progressbar1.Adjustment.Upper = 100;

        // clear our existing content
        if (context != null)
        {
            context.StopCompare();
        }

        // Go to the actual tree page.
        notebook1.Page = 0;

        // now generate new content asynchronously
        context = new CompareContext(reference_loader, target_loader);

        context.ProgressChanged += delegate(object sender, CompareProgressChangedEventArgs e) {
            Application.Invoke(delegate {
                Status   = e.Message;
                Progress = e.Progress;
            });
        };

        context.Error += delegate(object sender, CompareErrorEventArgs e) {
            Application.Invoke(delegate {
                Console.WriteLine("ERROR: {0}", e.Message);
                MessageDialog md = new MessageDialog(this, 0, MessageType.Error, ButtonsType.Ok, false,
                                                     e.Message);
                md.Response += delegate(object s, ResponseArgs ra) {
                    md.Hide();
                };
                md.Show();
                Status               = String.Format("Comparison failed at {0}", DateTime.Now);
                Progress             = 0.0;
                progressbar1.Visible = false;
            });
        };

        context.Finished += delegate(object sender, EventArgs e) {
            Application.Invoke(delegate {
                DateTime finish_time = DateTime.Now;

                if (context.Comparison != null)
                {
                    Status = String.Format("Comparison completed at {0}", finish_time);

                    context.Comparison.PropagateCounts();
                    PopulateTreeFromComparison(context.Comparison);
                    Progress = 0.0;

                    CompareHistory[] history = Config.Recent[0].History;

                    if (history == null || history.Length == 0 ||
                        (history[history.Length - 1].Extras != context.Comparison.Extra ||
                         history[history.Length - 1].Errors != context.Comparison.Warning ||
                         history[history.Length - 1].Missing != context.Comparison.Missing ||
                         history[history.Length - 1].Niexs != context.Comparison.Niex ||
                         history[history.Length - 1].Todos != context.Comparison.Todo))
                    {
                        CompareHistory history_entry = new CompareHistory();
                        history_entry.CompareTime    = finish_time;
                        history_entry.Extras         = context.Comparison.Extra;
                        history_entry.Errors         = context.Comparison.Warning;
                        history_entry.Missing        = context.Comparison.Missing;
                        history_entry.Niexs          = context.Comparison.Niex;
                        history_entry.Todos          = context.Comparison.Todo;
                        Config.Recent[0].AddHistoryEntry(history_entry);
                        Config.Save();
                    }
                }
                else
                {
                    Status = "Comparison not completed - no data returned.";
                }

                done(this);
                progressbar1.Visible = false;
            });
        };
        treeStore.Clear();
        context.Compare();
    }
示例#3
0
        public static void Main(string[] args)
        {
            string myassembly = Assembly.GetExecutingAssembly().Location;

            monoroot    = new FileInfo(myassembly).Directory.Parent.Parent.Parent.Parent.FullName;
            monolibmono = monoroot + "/../Mono/builds/monodistribution/lib/mono/";

            string originalprofiledirectory = UnityProfilesUtils.DirectoryNameFromProfile(UnityProfiles.None);
            Dictionary <UnityProfiles, UnityProfilesDocumentation> docs = new Dictionary <UnityProfiles, UnityProfilesDocumentation> ();
            UnityProfilesDocumentation mergedDoc = new UnityProfilesDocumentation();

            Dictionary <string, MasterAssembly> masterInfos = new Dictionary <string, MasterAssembly> ();

            foreach (var file in Directory.GetFiles(monolibmono + originalprofiledirectory, "*.dll"))
            {
                if (!file.Contains("mscorlib") && !file.Contains("System."))
                {
                    continue;
                }
                // FIXME: for some reason, mono-api-info.exe fails on these assemblies (Cecil failure).
                if (file.Contains("System.Web.DynamicData.dll"))
                {
                    continue;
                }
                if (file.Contains("System.Web.Extensions.dll"))
                {
                    continue;
                }
                if (file.Contains("System.Web.Routing.dll"))
                {
                    continue;
                }
                if (file.Contains("System.Web.dll"))
                {
                    continue;
                }

                string assemblyname = Path.GetFileName(file);
                Console.WriteLine("Reading reference assembly {0}", assemblyname);

                string         originalxml = GenerateAPIInfo(file);
                MasterAssembly reference   = new MasterAssembly(originalxml);
                masterInfos [assemblyname] = reference;
            }

            foreach (UnityProfiles profile in UnityProfilesUtils.ListProfiles())
            {
                var newprofiledirectory = profile.DirectoryNameFromProfile();

                Console.WriteLine(" *** Working on profile {0} (directory {1})", profile, newprofiledirectory);

                foreach (var file in Directory.GetFiles(monolibmono + newprofiledirectory, "*.dll"))
                {
                    if (!file.Contains("mscorlib") && !file.Contains("System."))
                    {
                        continue;
                    }
                    // FIXME: for some reason, mono-api-info.exe fails on these assemblies (Cecil failure).
                    if (file.Contains("System.Web.DynamicData.dll"))
                    {
                        continue;
                    }
                    if (file.Contains("System.Web.Extensions.dll"))
                    {
                        continue;
                    }
                    if (file.Contains("System.Web.Routing.dll"))
                    {
                        continue;
                    }
                    if (file.Contains("System.Web.dll"))
                    {
                        continue;
                    }

                    string assemblyname = Path.GetFileName(file);
                    Console.WriteLine("Working on assembly {0}", assemblyname);

                    if (!masterInfos.ContainsKey(assemblyname))
                    {
                        Console.WriteLine("Assembly {0} from profile {1} not found in main master infos, skipping", assemblyname, profile);
                        continue;
                    }

                    Console.WriteLine("Reading assembly {0} in profile {1}", assemblyname, profile);
                    string newxml = GenerateAPIInfo(file);
                    GuiCompare.MasterAssembly target = new MasterAssembly(newxml);

                    GuiCompare.MasterAssembly  reference = masterInfos [assemblyname];
                    UnityProfilesDocumentation currentProfileDocumentation = new UnityProfilesDocumentation();
                    docs [profile] = currentProfileDocumentation;

                    CompareContext comparer = new CompareContext(() => reference, () => target, profile, currentProfileDocumentation);
                    //CompareContext comparer = new CompareContext(() => reference,() => target, profile, doc);

                    bool finished = false;
                    comparer.Finished        += (a, b) => finished = true;
                    comparer.ProgressChanged += (a, b) => Console.WriteLine(b.ToString());
                    comparer.Compare();
                    while (!finished)
                    {
                        Console.WriteLine("Waiting for comparison to finish...");
                        Thread.Sleep(2000);
                    }

                    // Handle errors here...
                }
            }

            // Merge profiles
            foreach (UnityProfiles profile in UnityProfilesUtils.ListProfiles())
            {
                Console.WriteLine(" *** Merging profile {0}", profile);
                UnityProfilesDocumentation currentDoc = docs [profile];
                foreach (DocumentedNamespace ns in currentDoc.Namespaces)
                {
                    DocumentedNamespace referenceNs = mergedDoc.AddReferenceNamespace(ns.Name);
                    foreach (DocumentedClass c in ns.Classes)
                    {
                        DocumentedClass referenceClass = referenceNs.AddReferenceClass(c.Name);
                        referenceClass.AddSupportedProfile(profile);
                        foreach (DocumentedMember member in c.Members)
                        {
                            DocumentedMember referenceMember;
                            if (member is DocumentedField)
                            {
                                referenceMember = referenceClass.AddReferenceField(member.Name);
                            }
                            else if (member is DocumentedProperty)
                            {
                                referenceMember = referenceClass.AddReferenceProperty(member.Name);
                            }
                            else if (member is DocumentedMethod)
                            {
                                referenceMember = referenceClass.AddReferenceMethod(member.Name);
                            }
                            else
                            {
                                referenceMember = null;
                            }
                            referenceMember.AddSupportedProfile(profile);
                        }
                    }
                }
            }

            // Generate report here...
            Console.WriteLine(" *** Dumping merged docs");
            //mergedDoc.DebugDump ();
        }