MakeRelativePath() public static méthode

public static MakeRelativePath ( string from, bool isFromDir, string to, bool isToDir ) : string
from string
isFromDir bool
to string
isToDir bool
Résultat string
Exemple #1
0
        public TestSuit(bool create, TestSuitVm baseTestSuit)
        {
            _settings = Settings.Default;
            _create   = create;

            InitializeComponent();

            this.Title = create ? "New test suit" : "Edit test suit";

            var root = Path.GetFullPath(_settings.TestsLocationRoot);

            _testsRootTextBlock.Text = root;
            var paths = baseTestSuit == null
        ? ""
        : string.Join(Environment.NewLine,
                      baseTestSuit.SynatxModules.Select(m =>
                                                        Utils.MakeRelativePath(from: root, isFromDir: true, to: m.GetType().Assembly.Location, isToDir: false)).Distinct());

            _assemblies.Text = paths;
            UpdateSyntaxModules(paths, root);

            _timer.Interval = TimeSpan.FromSeconds(1.3);
            _timer.Stop();
            _timer.Tick += _assembliesEdit_timer_Tick;
        }
Exemple #2
0
        public TestSuitDialog(bool create, TestSuitVm baseTestSuit)
        {
            _settings     = Settings.Default;
            _create       = create;
            _baseTestSuit = baseTestSuit;

            InitializeComponent();

            this.Title = create ? "New test suit" : "Edit test suit";

            var root = baseTestSuit.Solution.RootFolder;

            _rootFolder = root;
            _testsRootTextBlock.Text = root;
            var paths = string.Join(Environment.NewLine,
                                    baseTestSuit.SynatxModules.Select(m =>
                                                                      Utils.MakeRelativePath(@from: root, isFromDir: true, to: m.GetType().Assembly.Location, isToDir: false)).Distinct());

            _assemblies.Text = paths;

            if (!create)
            {
                if (string.IsNullOrWhiteSpace(paths))
                {
                    _assemblies.Text = paths = string.Join(Environment.NewLine, baseTestSuit.LibPaths);
                }
                this._testSuitName.Text = baseTestSuit.Name;
            }

            UpdateSyntaxModules(paths, root);

            var items = (ObservableCollection <SyntaxModuleVm>)_syntaxModules.ItemsSource;
            var selectedSynatxModules = baseTestSuit.SynatxModules.Join(items, d => d, suit => suit.GrammarDescriptor, (d, suit) => suit);

            foreach (var selectedSynatxModule in selectedSynatxModules)
            {
                selectedSynatxModule.IsChecked = true;
            }

            UpdateStartRules(baseTestSuit.StartRule == null || baseTestSuit.StartRule.IsStartRule);

            if (baseTestSuit.StartRule != null)
            {
                foreach (var x in _startRuleComboBox.ItemsSource)
                {
                    if (x == baseTestSuit.StartRule)
                    {
                        _startRuleComboBox.SelectedItem = x;
                    }
                }
            }

            _timer.Interval = TimeSpan.FromSeconds(1.3);
            _timer.Stop();
            _timer.Tick += _assembliesEdit_timer_Tick;
        }
Exemple #3
0
        private static void OnLibsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var model      = (TestSuiteCreateOrEditModel)d;
            var normalized = new HashSet <LibReference>();
            var suitPath   = model.SuitPath;

            foreach (var libPath in Utils.GetAssemblyPaths((string)e.NewValue))
            {
                var fullAssemblyPath = Path.GetFullPath(Path.IsPathRooted(libPath) ? libPath : Path.Combine(suitPath, libPath));

                if (File.Exists(fullAssemblyPath))
                {
                    var relativePath = Utils.MakeRelativePath(suitPath, true, fullAssemblyPath, false);
                    normalized.Add(new FileLibReference(relativePath));
                }
                else
                {
                    // treat as assembly full name
                    normalized.Add(new FullNameLibReference(libPath));
                }
            }
            model.NormalizedLibs = normalized.ToArray();
        }
Exemple #4
0
        private void MakeAllPathsRelative()
        {
            var assemblyPaths             = _assemblies.Text.Trim('\n', '\r', '\t', ' ');
            var result                    = new List <string>();
            var testsLocationRootFullPath = Path.GetFullPath(_rootFolder);

            foreach (var assemblyPath in Utils.GetAssemblyPaths(assemblyPaths))
            {
                var path                 = Path.Combine(testsLocationRootFullPath, assemblyPath.Trim());
                var fullPath             = Path.GetFullPath(path);
                var relativeAssemblyPath = Utils.MakeRelativePath(testsLocationRootFullPath, true, fullPath, false);
                if (!string.IsNullOrWhiteSpace(relativeAssemblyPath))
                {
                    result.Add(relativeAssemblyPath);
                }
            }

            var text = string.Join(Environment.NewLine, result);

            if (assemblyPaths != text)
            {
                _assemblies.Text = string.Join(Environment.NewLine, result);
            }
        }