public void TestSetup()
        {
            AppContext = new TraceLabTestApplication(TestContext);

            //set current location
            currentLocation = AppContext.BaseTestDirectory;

            //create config definition using createwrapper method of the ComponentMetadataDefinition class
            var configDef = ComponentScannerHelper_Accessor.CreateConfigWrapperDefinition(typeof(MockConfig));
            testConfig = new ConfigWrapper(configDef);

            //set the values of MockConfig
            mockFileAbsolutePath = Path.Combine(currentLocation, mockFile);
            Stream file = File.Create(mockFileAbsolutePath);
            file.Close(); //close file so that it is not being used by this process anymore

            configFilePath = new FilePath();
            configFilePath.Init(mockFileAbsolutePath, currentLocation);
            //the key matches property name in the MockConfig
            testConfig.ConfigValues["MockFile"].Value = configFilePath;

            mockDirAbsolutePath = Path.Combine(currentLocation, mockDir);
            Directory.CreateDirectory(mockDirAbsolutePath);
            Assert.IsTrue(Directory.Exists(mockDirAbsolutePath));

            configDirPath = new DirectoryPath();
            configDirPath.Init(mockDirAbsolutePath, currentLocation);
            //the key matches property name in the MockConfig
            testConfig.ConfigValues["MockDirectory"].Value = configDirPath;
        }
Example #2
0
        // END HERZUM SPRINT 4.3: TLAB-238 TLAB-243

        // HERZUM SPRINT 4.3: TLAB-202
        public override void SetFilePath (String newFilenameLocation)
        {
            #if DEBUG
            ///Console.WriteLine ("SetFilePath Absolute = " + newFilePath);
            #endif

            if(newFilenameLocation != null) 
            {
                FilePath path = Property.GetValue(Instance) as FilePath;
                if(path != null) 
                {
                    path.Absolute = newFilenameLocation;
                }
                else 
                {
                    //construct new filepath
                    path = new FilePath();
                    //string experimentPath = TODO - get experiment path
                    //string dataRoot = System.IO.Path.GetDirectoryName(experimentPath);
                    string dataRoot = null;

                    // HERZUM SPRINT 5.0: TLAB-238 TLAB-243
                    dataRoot = DataRoot;
                    // END HERZUM SPRINT 5.0: TLAB-238 TLAB-243

                    path.Init(newFilenameLocation, dataRoot);
                }

                Property.SetValue(Instance, path);
            }
        }
Example #3
0
        public static List<ICSM11DataSet> ImportDatasets(FilePath XMLfile)
        {
            XmlDocument XMLdoc = new XmlDocument();
            XMLdoc.Load(XMLfile.Absolute);

            string[] s = XMLfile.Absolute.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
            StringBuilder path = new StringBuilder();
            for (long i = 0; i < s.Length - 1; i++)
            {
                path.Append(s[i]);
                path.Append("\\");
            }
            path.Append(XMLdoc.GetElementsByTagName("Datasets")[0].Attributes["Directory"].Value.Replace('/', '\\'));
            string RTMsimspath = XMLdoc.GetElementsByTagName("Datasets")[0].Attributes["PrecomputedRTMSimilaritiesDirectory"].Value.Replace('/', '\\');

            List<ICSM11DataSet> datasets = new List<ICSM11DataSet>();
            XmlNodeList nodelist = XMLdoc.GetElementsByTagName("Dataset");

            foreach (XmlNode node in nodelist)
            {
                ICSM11DataSet dataset = new ICSM11DataSet();
                dataset.SourceArtifacts = path + node["Corpus"].Attributes["Directory"].Value + node["Corpus"]["SourceArtifacts"].InnerText
                    + "#" + node["Corpus"]["SourceArtifacts"].Attributes["Extension"].Value;
                dataset.TargetArtifacts = path + node["Corpus"].Attributes["Directory"].Value + node["Corpus"]["TargetArtifacts"].InnerText
                    + "#" + node["Corpus"]["TargetArtifacts"].Attributes["Extension"].Value;
                dataset.Oracle = path + node["Corpus"].Attributes["Directory"].Value + node["Corpus"]["Oracle"].InnerText;
                dataset.Name = node.Attributes["Name"].Value;
                dataset.PrecomputedRTMSimilarities = path + RTMsimspath + node["Settings"]["PrecomputedRTMSimilarities"].InnerText;
                dataset.RTM = new RTMSettings
                {
                    Alpha = Convert.ToDouble(node["Settings"]["RTM"]["Alpha"].InnerText),
                    Beta = Convert.ToDouble(node["Settings"]["RTM"]["Beta"].InnerText),
                    Eta = Convert.ToDouble(node["Settings"]["RTM"]["Eta"].InnerText),
                    NumTopics = Convert.ToInt32(node["Settings"]["RTM"]["NumTopics"].InnerText),
                };
                dataset.PCA = new PCASettings
                {
                    VSM_JS = Convert.ToDouble(node["Settings"]["PCA"]["VSM_JS"].InnerText),
                    VSM_RTM = Convert.ToDouble(node["Settings"]["PCA"]["VSM_RTM"].InnerText),
                    JS_RTM = Convert.ToDouble(node["Settings"]["PCA"]["JS_RTM"].InnerText),
                };
                datasets.Add(dataset);
            }

            return datasets;
        }
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if(values == null)
                throw new ArgumentNullException("values");
            if (values.Length != 2)
                throw new ArgumentException("Invalid number of arguments");
            if (targetType != typeof(FilePath) && targetType != typeof(DirectoryPath))
                throw new NotSupportedException("This converter only converts to filepaths");
            if (values[1] == System.Windows.DependencyProperty.UnsetValue)
                throw new ArgumentException("The experiment path has to be set. If filepath is null, the new FilePath object is initialized based on experiment path.");

            BasePath path = null;

            //if experiment path is set extract the experiment root, that is the data root for
            //FilePaths and DirectoryPaths
            if (targetType == typeof(FilePath))
            {
                path = (FilePath)values[0];
                //if experiment path has been set 
                if (path == null)
                {
                    string experimentPath = (string)values[1];
                    string dataRoot = System.IO.Path.GetDirectoryName(experimentPath);
                    path = new FilePath();
                    path.Init("", dataRoot);
                }
            }
            else if (targetType == typeof(DirectoryPath))
            {
                path = (DirectoryPath)values[0];
                if (path == null)
                {
                    string experimentPath = (string)values[1];
                    string dataRoot = System.IO.Path.GetDirectoryName(experimentPath);
                    path = new DirectoryPath();
                    path.Init("", dataRoot);
                }
            }
            
            return path;
        }
        public override void LaunchDialogue ()
        {
            string newFilenameLocation = SelectFileDialog(null);
            if(newFilenameLocation != null) 
            {
                FilePath path = Property.GetValue(Instance) as FilePath;
                if(path != null) 
                {
                    path.Absolute = newFilenameLocation;
                }
                else 
                {
                    //construct new filepath
                    path = new FilePath();
                    //string experimentPath = TODO - get experiment path
                    //string dataRoot = System.IO.Path.GetDirectoryName(experimentPath);
                    string dataRoot = null;

                    path.Init(newFilenameLocation, dataRoot);
                }

                Property.SetValue(Instance, path);
            }
        }
        public void DataRootDoesNotHaveTrailingSlash()
        {
            string absolutePath = @"C:\Foo\Stuff.xml"; // TODO: Initialize to an appropriate value
            string dataRoot = @"C:\Foo";
            FilePath target = new FilePath();
            target.Init(absolutePath, dataRoot);

            // Internally, DataRoot needs a directory separator appended to it.
            Assert.AreEqual(dataRoot + System.IO.Path.DirectorySeparatorChar, target.DataRoot);
            Assert.AreEqual(absolutePath, target.Absolute);
            Assert.AreEqual(absolutePath.Remove(0, dataRoot.Length + 1), target.Relative);
        }
        public void TestChangeDataRoot()
        {
            string root = @"C:\packageMain\";
            string file = @"C:\stuff.txt";

            FilePath path = new FilePath();
            path.Init(file, root);
            string expectedRelative = @"..\stuff.txt";
            Assert.AreEqual(expectedRelative, path.Relative);

            //change data root
            string newRoot = @"C:\packageMain\foo";
            path.SetDataRoot(newRoot, true);
            //it should update relative
            expectedRelative = @"..\..\stuff.txt";
            Assert.AreEqual(expectedRelative, path.Relative);
        }
        public void TestDetermineRelative3()
        {
            string root = @"C:\packageMain\";
            string file = @"C:\foo\stuff.txt";

            FilePath path = new FilePath();
            path.Init(file, root);

            string expectedRelative = @"..\foo\stuff.txt";

            Assert.AreEqual(expectedRelative, path.Relative);
        }
 public void op_ImplicitTest()
 {
     string expected = @"C:\Foo\Stuff";
     FilePath path = new FilePath();
     path.Init(expected);
     string actual;
     actual = path;
     Assert.AreEqual(expected, actual);
 }
        public void WriteXmlTest()
        {
            string absolute = @"C:\Foo\Stuff.xml";
            string dataRoot = @"C:\Foo";
            FilePath path = new FilePath();
            path.Init(absolute, dataRoot);
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            using (XmlWriter writer = XmlWriter.Create(@"FilePathXmlWriterTest.xml", settings))
            {
                var formatter = new System.Xml.Serialization.XmlSerializer(typeof(FilePath));
                formatter.Serialize(writer, path);
                writer.Close();
            }

            using (System.IO.FileStream stream1 = new System.IO.FileStream("Version2FilePath.xml", System.IO.FileMode.Open), stream2 = new System.IO.FileStream("FilePathXmlWriterTest.xml", System.IO.FileMode.Open))
            {
                //Assert.AreEqual(stream1.Length, stream2.Length);
                string expected;
                System.IO.StreamReader reader = new System.IO.StreamReader(stream1);
                expected = reader.ReadToEnd();

                reader = new System.IO.StreamReader(stream2);
                string actual = reader.ReadToEnd();

                Assert.AreEqual(expected, actual);
            }
        }
 public void FilePathConstructorTest1()
 {
     string absolutePath = @"C:\Foo\Stuff.xml";
     FilePath target = new FilePath();
     target.Init(absolutePath);
     Assert.AreEqual(absolutePath, target.Absolute);
     Assert.AreEqual(null, target.Relative);
     Assert.AreEqual(null, target.DataRoot);
 }
 public void CanMixAndMatchDirectorySeperators()
 {
     string absolutePath = @"C:\Foo\Stuff.xml";
     string dataRoot = @"C:\Foo/";
     string realRoot = dataRoot.Replace(System.IO.Path.AltDirectorySeparatorChar, System.IO.Path.DirectorySeparatorChar);
     FilePath target = new FilePath();
     target.Init(absolutePath, dataRoot);
     Assert.AreEqual(realRoot, target.DataRoot);
     Assert.AreEqual(absolutePath, target.Absolute);
     Assert.AreEqual(absolutePath.Remove(0, realRoot.Length), target.Relative);
 }
 public void DataRootDoesHaveTrailingSlash()
 {
     string absolutePath = @"C:\Foo\Stuff.xml"; // TODO: Initialize to an appropriate value
     string dataRoot = @"C:\Foo\";
     FilePath target = new FilePath();
     target.Init(absolutePath, dataRoot);
     Assert.AreEqual(dataRoot, target.DataRoot);
     Assert.AreEqual(absolutePath, target.Absolute);
     Assert.AreEqual(absolutePath.Remove(0, dataRoot.Length), target.Relative);
 }
        /// <summary>
        /// Imports INFORMATION about corpora from an XML file.
        /// For use with a loop importer.
        /// </summary>
        /// <param name="XMLfile">File location object</param>
        /// <returns>List of dataset information</returns>
        public static List<DataSet> ImportDatasets(FilePath XMLfile)
        {
            XmlDocument XMLdoc = new XmlDocument();
            XMLdoc.Load(XMLfile.Absolute);

            string[] s = XMLfile.Absolute.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
            StringBuilder path = new StringBuilder();
            for (long i = 0; i < s.Length - 1; i++)
            {
                path.Append(s[i]);
                path.Append("\\");
            }
            path.Append(XMLdoc.GetElementsByTagName("Datasets")[0].Attributes["Directory"].Value.Replace('/', '\\'));

            List<DataSet> datasets = new List<DataSet>();
            XmlNodeList nodelist = XMLdoc.GetElementsByTagName("Dataset");

            foreach (XmlNode node in nodelist)
            {
                DataSet dataset = new DataSet();
                dataset.SourceArtifacts = path + node["Corpus"]["SourceArtifacts"].InnerText;
                dataset.TargetArtifacts = path + node["Corpus"]["TargetArtifacts"].InnerText;
                dataset.Oracle = path + node["Corpus"]["Oracle"].InnerText;
                dataset.Name = node.Attributes["Name"].Value;
                datasets.Add(dataset);
            }

            return datasets;
        }
        /// <summary>
        /// Opens a file browser dialog when the button is clicked.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void BrowseButtonClick(object sender, RoutedEventArgs e)
        {
            Ookii.Dialogs.Wpf.VistaFileDialog fileDialog = new Ookii.Dialogs.Wpf.VistaOpenFileDialog();
            
            //don't check if file exists, as dialog might be used for specifying the output filepath
            fileDialog.CheckFileExists = false;
            fileDialog.Title = "Select File";

            bool? success = fileDialog.ShowDialog();
            if (success == true)
            {
                try
                {
                    FilePath path = new FilePath();
                    path.Init(fileDialog.FileName, Path.DataRoot);
                    Path = path;
                }
                catch (System.ArgumentException ex)
                {
                    NLog.LogManager.GetCurrentClassLogger().ErrorException("Failed to set reference to a file", ex);
                    MessageBox.Show(ex.Message, "Failed to set reference to a file", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
            }
        }
        /// <summary>
        /// If the chosen item is a file then the Select Button is enabled, and the correct path is set.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedPropertyChangedEventArgs&lt;System.Object&gt;"/> instance containing the event data.</param>
        private void PkgFileChooser_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            var file = PackageFileChooser.SelectedItem as PackageFileContentItem;
            if (file != null)
            {
                SelectButton.IsEnabled = true;
                PackageViewModel package = null;
                // Get the Package parent
                PackageContentItem parent = file.Parent;
                package = parent as PackageViewModel;
                while (package == null && parent != null)
                {
                    parent = parent.Parent;
                    package = parent as PackageViewModel;
                }

                if (package != null)
                {
                    TraceLabSDK.PackageSystem.IPackageReference reference = new TraceLab.Core.PackageSystem.PackageReference(package.Package);

                    var path = new TraceLab.Core.Components.TraceLabFilePath();
                    path.Init(reference, file.ID);
                    Path = path;
                }
            }
            else
            {
                SelectButton.IsEnabled = false;
            }
        }