Example #1
0
        // END HERZUM SPRINT 4.3: TLAB-238 TLAB-243

        // HERZUM SPRINT 4.2: TLAB-202
        public override void SetDirectory (String newDirectoryLocation)
        {
            if(newDirectoryLocation != null) 
            {
                DirectoryPath path = Property.GetValue(Instance) as DirectoryPath;
                if(path != null) 
                {
                    path.Absolute = newDirectoryLocation;
                }
                else   
                {
                    //construct new filepath
                    path = new DirectoryPath();
                    //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(newDirectoryLocation, dataRoot);
                }

                Property.SetValue(Instance, path);
            }
        }
        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 newDirectoryLocation = SelectFileDialog(null);
     if(newDirectoryLocation != null) 
     {
         DirectoryPath path = Property.GetValue(Instance) as DirectoryPath;
         if(path != null) 
         {
             path.Absolute = newDirectoryLocation;
         }
         else 
         {
             //construct new filepath
             path = new DirectoryPath();
             //string experimentPath = TODO - get experiment path
             //string dataRoot = System.IO.Path.GetDirectoryName(experimentPath);
             string dataRoot = null;
             
             path.Init(newDirectoryLocation, dataRoot);
         }
         
         Property.SetValue(Instance, path);
     }
 }
        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;
        }
        /// <summary>
        /// Opens a folder 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.VistaFolderBrowserDialog folderDialog = new Ookii.Dialogs.Wpf.VistaFolderBrowserDialog();
            folderDialog.ShowNewFolderButton = true;

            bool? success = folderDialog.ShowDialog();
            if (success == true && Directory.Exists(folderDialog.SelectedPath))
            {
                try
                {
                    DirectoryPath path = new DirectoryPath();
                    path.Init(folderDialog.SelectedPath, 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 Package or Folder 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 PkgFolderChooser_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            bool enableButton = false;
            PackageFolderContentItem folder = PackageFileChooser.SelectedItem as PackageFolderContentItem;
            if (folder != null && !(folder is PackageViewModel))
            {
                Stack<string> subDirs = new Stack<string>();
                subDirs.Push(folder.Label);

                PackageContentItem parent = folder.Parent;
                while (parent.Parent != null)
                {
                    subDirs.Push(parent.Label);
                    parent = parent.Parent;
                }

                PackageViewModel package = parent as PackageViewModel;
                if (package != null)
                {
                    string subDirectory = "";
                    while (subDirs.Count > 0)
                    {
                        subDirectory = System.IO.Path.Combine(subDirectory, subDirs.Pop());
                    }

                    if (Directory.Exists(System.IO.Path.Combine(package.Package.Location, subDirectory)))
                    {
                        TraceLabSDK.PackageSystem.IPackageReference reference = new TraceLab.Core.PackageSystem.PackageReference(package.Package);
                        TraceLabDirectoryPath path = new TraceLabDirectoryPath();
                        path.Init(reference, subDirectory);
                        Path = path;
                        enableButton = true;
                    }
                }
            }
            else if (folder != null && folder is PackageViewModel)
            {
                PackageViewModel package = folder as PackageViewModel;
                if (Directory.Exists(package.Package.Location))
                {
                    TraceLabSDK.PackageSystem.IPackageReference reference = new TraceLab.Core.PackageSystem.PackageReference(package.Package);
                    TraceLabDirectoryPath path = new TraceLabDirectoryPath();
                    path.Init(reference, ".");
                    Path = path;
                    enableButton = true;
                }
            }
            SelectButton.IsEnabled = enableButton;
        }