private void srcmlGenWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            Object[]      array  = new Object[2];
            DirectoryInfo source = e.Argument as DirectoryInfo;

            var docPath = getPathFor(source);

            if (null == docPath)
            {
                docPath = Path.GetTempFileName();
            }

            array[0] = source as Object;

            try
            {
                var       so  = new SrcML();
                SrcMLFile doc = so.GenerateSrcMLFromDirectory(source.FullName, docPath);
                array[1] = (doc == null ? null : doc.FileName as Object);
            }
            catch (TargetInvocationException ex)
            {
                MessageBox.Show(String.Format("Could not load {0}: {1}", source.FullName, ex.Message));
            }
            catch (SrcMLException ex)
            {
                MessageBox.Show(String.Format("Could not load {0}: {1}", source.FullName, ex.Message));
            }

            e.Result = array;
        }
Exemple #2
0
        ExtractAllMethodsFromFile(string filePath)
        {
            // open the file and convert to srcml
            //var srcml = new SrcMLFile( filePath );
            //var baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            //var srcmlPath = Path.Combine(baseDir,"..", "..","..","..","External");
            var srcmlPath = @"C:\Users\kh\Documents\GitHubVisualStudio\Swummary\External";

            Console.WriteLine(srcmlPath);

            var srcml = new SrcML(srcmlPath);

            //var srcml = new SrcMLGenerator();
            srcml.GenerateSrcMLFromFile(filePath, Path.Combine(filePath, ".xml"));
            //var srcmlFile =
            var srcmlFile = srcml.GenerateSrcMLFromFile(filePath, Path.Combine(filePath, ".xml"));

            //var ns = new NamespaceDefinition();


            // get a grip on the parts we care about
            var fileUnits = srcmlFile.FileUnits;
            var parser    = new CPlusPlusCodeParser(); //TODO: allow language to be chosen or detected

            // iterate through the mess to build a list of what we want
            var methodList = new List <Tuple <string, string, MethodDefinition> >();

            foreach (var file in fileUnits)
            {
                var fileScope = parser.ParseFileUnit(file);
                var methods   = fileScope.GetDescendants <MethodDefinition>();

                string filename = file.Name.ToString();
                foreach (var method in methods)
                {
                    string methodName = method.Name.ToString();
                    var    definition = method.GetDescendants <MethodDefinition>().Single();

                    var element = new Tuple <string, string, MethodDefinition>(filename, methodName, definition);
                    methodList.Add(element);
                }
            }

            // done!
            return(methodList.AsEnumerable());
        }
        public TransformPreviewControl()
        {
            InitializeComponent();

            dataGridView1.AutoGenerateColumns = false;

            try
            {
                srcml = new SrcML();
            }
            catch (FileNotFoundException e)
            {
                string msg = String.Format("{0}: {1}\n{2}", e.Source, e.Message, e.StackTrace);
                if (e.InnerException != null)
                {
                    msg += String.Format("\n{0}", e.InnerException);
                }
            }

            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

            projectSrcmlFolder        = null;
            sourceDirectories         = new BindingList <DirectoryInfo>();
            srcmlDict                 = new Dictionary <DirectoryInfo, string>(new DirectoryInfoComparer());
            outputSourceDirectoryList = new BindingList <DirectoryInfo>();

            inputFolderComboBox.DataSource    = sourceDirectories;
            inputFolderComboBox.DisplayMember = "FullName";
            inputFolderComboBox.SelectedIndex = -1;

            outputFolderComboBox.DataSource    = outputSourceDirectoryList;
            outputFolderComboBox.DisplayMember = "FullName";
            outputFolderComboBox.SelectedIndex = -1;

            LocationColumn.DataPropertyName          = "Location";
            OriginalSourceColumn.DataPropertyName    = "Text";
            TransformedSourceColumn.DataPropertyName = "TransformedText";
            EnabledColumn.DataPropertyName           = "Enabled";
            setButtons();
        }
        public TransformPreviewControl()
        {
            InitializeComponent();

            dataGridView1.AutoGenerateColumns = false;

            try
            {
                srcml = new SrcML();
            }
            catch(FileNotFoundException e)
            {
                string msg = String.Format("{0}: {1}\n{2}", e.Source, e.Message, e.StackTrace);
                if (e.InnerException != null)
                    msg += String.Format("\n{0}", e.InnerException);
            }

            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

            projectSrcmlFolder = null;
            sourceDirectories = new BindingList<DirectoryInfo>();
            srcmlDict = new Dictionary<DirectoryInfo, string>(new DirectoryInfoComparer());
            outputSourceDirectoryList = new BindingList<DirectoryInfo>();

            inputFolderComboBox.DataSource = sourceDirectories;
            inputFolderComboBox.DisplayMember = "FullName";
            inputFolderComboBox.SelectedIndex = -1;

            outputFolderComboBox.DataSource = outputSourceDirectoryList;
            outputFolderComboBox.DisplayMember = "FullName";
            outputFolderComboBox.SelectedIndex = -1;

            LocationColumn.DataPropertyName = "Location";
            OriginalSourceColumn.DataPropertyName = "Text";
            TransformedSourceColumn.DataPropertyName = "TransformedText";
            EnabledColumn.DataPropertyName = "Enabled";
            setButtons();
        }
        private void srcmlGenWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            Object[] array = new Object[2];
            DirectoryInfo source = e.Argument as DirectoryInfo;
            
            var docPath = getPathFor(source);
            if (null == docPath)
                docPath = Path.GetTempFileName();
            
            array[0] = source as Object;
            
            try
            {
                var so = new SrcML();
                SrcMLFile doc = so.GenerateSrcMLFromDirectory(source.FullName, docPath);
                array[1] = (doc == null ? null : doc.FileName as Object);
            }
            catch (TargetInvocationException ex)
            {
                MessageBox.Show(String.Format("Could not load {0}: {1}", source.FullName, ex.Message));
            }
            catch (SrcMLException ex)
            {
                MessageBox.Show(String.Format("Could not load {0}: {1}", source.FullName, ex.Message));
            }

            e.Result = array;
        }