Example #1
0
        /// <summary>
        /// The "real" main. This is where all the work in the program starts.
        /// </summary>
        ///<remarks>
        ///Due to technical reasons (see the remarks on "WriteContracts" and "GetContracts"),
        ///the contracts are gathered first then they are written out. This is instead of
        ///writting the contracts while they are being found.
        ///</remarks>
        ///<remarks>
        ///The contracts are gathered first then they are written out. We make one pass over the assembly
        ///to gather contracts, then one pass over the XML file to write out the contracts. This is instead
        ///of writing the contracts as they are being found, because all members in the assembly may not
        ///be represented in the XML file or may appear in a different order.
        ///</remarks>
        public static int RealMain(string[] args)
        {
            #region Parse options
            var options = new Options();
            options.Parse(args);
            if (options.HelpRequested)
            {
                options.PrintOptions("");
                return(1);
            }
            if (options.HasErrors)
            {
                options.PrintErrorsAndExit(Console.Out);
                return(-1);
            }
            if (options.breakIntoDebugger)
            {
                System.Diagnostics.Debugger.Break();
            }
            if (options.assembly == null && options.GeneralArguments.Count > 0)
            {
                options.assembly = options.GeneralArguments[0];
            }
            #endregion
            try
            {
                TrySendLeaderBoardPing(options);

                #region Set up the DocTracker. (Used for debug output.)
                TextWriter writer = null; //A null writer is allowed.
                if (options.debug)
                {
                    if (options.outFile != null)
                    {
                        writer = new StreamWriter(options.outFile);
                    }
                    else
                    {
                        writer = Console.Out;
                    }
                }
                DocTracker docTracker = new DocTracker(writer);
                #endregion
                #region Collect and write contracts
                var contracts = GetContracts(options, docTracker);
                WriteContracts(contracts, options, docTracker);
                #endregion
                #region Write contract statistics
                docTracker.WriteContractsPerKind(MemberKind.Type);
                docTracker.WriteContractsPerKind(MemberKind.Property);
                docTracker.WriteContractsPerKind(MemberKind.Method);
                #endregion
            }
            catch
            {
                SendLeaderBoardFailure();
                throw;
            }
            return(0); //success
        }
Example #2
0
    /// <summary>
    /// The "real" main. This is where all the work in the program starts.
    /// </summary>
    ///<remarks>
    ///Due to technical reasons (see the remarks on "WriteContracts" and "GetContracts"),
    ///the contracts are gathered first then they are written out. This is instead of
    ///writting the contracts while they are being found.
    ///</remarks>
    ///<remarks>
    ///The contracts are gathered first then they are written out. We make one pass over the assembly 
    ///to gather contracts, then one pass over the XML file to write out the contracts. This is instead 
    ///of writing the contracts as they are being found, because all members in the assembly may not 
    ///be represented in the XML file or may appear in a different order. 
    ///</remarks>
    public static int RealMain(string[] args)
    {
      #region Parse options
      var options = new Options();
      options.Parse(args);
      if (options.HelpRequested)
      {
        options.PrintOptions("");
        return 1;
      }
      if (options.HasErrors)
      {
        options.PrintErrorsAndExit(Console.Out);
        return -1;
      }
      if (options.breakIntoDebugger) {
        System.Diagnostics.Debugger.Break();
      }
      if (options.assembly == null && options.GeneralArguments.Count > 0)
      {
        options.assembly = options.GeneralArguments[0];
      }
      #endregion
      try
      {
        TrySendLeaderBoardPing(options);

        #region Set up the DocTracker. (Used for debug output.)
        TextWriter writer = null; //A null writer is allowed.
        if (options.debug)
        {
          if (options.outFile != null)
            writer = new StreamWriter(options.outFile);
          else
            writer = Console.Out;
        }
        DocTracker docTracker = new DocTracker(writer);
        #endregion
        #region Collect and write contracts
        var contracts = GetContracts(options, docTracker);
        WriteContracts(contracts, options, docTracker);
        #endregion
        #region Write contract statistics
        docTracker.WriteContractsPerKind(MemberKind.Type);
        docTracker.WriteContractsPerKind(MemberKind.Property);
        docTracker.WriteContractsPerKind(MemberKind.Method);
        #endregion
      }
      catch
      {
        SendLeaderBoardFailure();
        throw;
      }
      return 0; //success
    }
Example #3
0
        /// <summary>
        /// The main entry point for the program
        /// </summary>
        /// <param name="args">An assembly to be loaded by the program</param>
        public static void Main(string[] args)
        {
            var options = new Options();

            options.Parse(args);

            if (options.HasErrors)
            {
                if (options.HelpRequested)
                {
                    options.PrintOptions("");
                }
                Environment.Exit(-1);
            }

            HostEnvironment host   = new HostEnvironment();
            IModule         module = host.LoadUnitFrom(options.assembly) as IModule;

            if (module == null || module == Dummy.Module || module == Dummy.Assembly)
            {
                Console.WriteLine("'{0}' is not a PE file containing a CLR module or assembly.", options.assembly);
                return;
            }

            if (options.outToFile)
            {
                StreamWriter consoleStream = new StreamWriter("buildOutput.txt");
                Console.SetOut(consoleStream);
            }

            string    xmlDocSaveName;
            XDocument xDoc           = null; //TODO: Use XmlReader instead of LINQ to XML
            XElement  membersElement = null;

            if (!String.IsNullOrEmpty(options.xmlFile))
            {
                //Load the XML File
                try
                {
                    xDoc = XDocument.Load(options.xmlFile);
                }
                catch
                {
                    Console.WriteLine(options.xmlFile + " is not a XML file.");
                    return;
                }
                var docEl = xDoc.Element("doc"); //Navigate to "doc"
                if (docEl == null)
                {
                    Console.WriteLine(options.xmlFile + " is not a valid XML reference file; it does not contain a \"doc\" element.");
                    return;
                }
                membersElement = docEl.Element("members"); //Navigate to "members"
                if (membersElement == null)
                {
                    Console.WriteLine(options.xmlFile + " is not a valid XML reference file; it does not contain a \"members\" element.");
                    return;
                }
                xmlDocSaveName = options.xmlFile;
            }
            else
            {
                //Build a new XML File
                XDeclaration xDeclaration = new XDeclaration("1.0", null, null);
                membersElement = new XElement("members");
                xDoc           = new XDocument(xDeclaration,
                                               new XElement("doc",
                                                            membersElement));

                // membersElement = xDoc.Element("doc").Element("members");

                string fileName = options.assembly;
                fileName       = fileName.TrimEnd(".dll".ToCharArray());
                xmlDocSaveName = fileName + ".xml";
            }

            //Establish the traverser
            var contractMethods = new ContractMethods(host);
            IContractProvider contractProvider = new Microsoft.Cci.ILToCodeModel.LazyContractProvider(host, module, contractMethods);
            IMetadataVisitor  traverser        = new ContractTraverser(host, contractProvider, membersElement, options);

            traverser.Visit(module);

            xDoc.Save(xmlDocSaveName, SaveOptions.None);

            Console.Out.Close();
        }