コード例 #1
0
        public void CanCreateVariousPaths()
        {
            FilePath path;
            string   expected;

            expected = Path.Combine("this", "is", "a", "path");
            path     = FilePath.Build("this", "is", "a", "path");
            Assert.AreEqual(expected, path.ToString());

            expected = "";
            path     = FilePath.Empty;
            Assert.AreEqual(expected, path.ToString());
            Assert.IsTrue(path.IsEmpty);
            Assert.IsTrue(path.IsNullOrEmpty);

            expected = null;
            path     = FilePath.Null;
            Assert.AreEqual(expected, path.ToString());
            Assert.IsTrue(path.IsNull);
            Assert.IsTrue(path.IsNullOrEmpty);

            expected = Path.Combine("this", "is", "a", "path");
            path     = new FilePath(expected);
            Assert.AreEqual(expected, path.ToString());

            expected = Path.Combine(expected, "and", "more");
            path     = path.Combine("and", "more");
            Assert.AreEqual(expected, path.ToString());

            expected = "file.txt";
            path     = new FilePath("file").ChangeExtension(".txt");
            Assert.AreEqual(expected, path.ToString());

            expected = "file.txt";
            path     = new FilePath("file.type").ChangeExtension(".txt");
            Assert.AreEqual(expected, path.ToString());

            // TODO: Test file:// scheme
        }
コード例 #2
0
        static void HandleUserDataMigration(object sender, ExtensionNodeEventArgs args)
        {
            if (args.Change != ExtensionChange.Add)
            {
                return;
            }

            var node = (UserDataMigrationNode)args.ExtensionNode;

            if (!CheckVersion(node, version))
            {
                return;
            }

            FilePath source = FilePath.Null;
            FilePath target = FilePath.Null;

            try {
                source = profile.GetLocation(node.SourceKind).Combine(node.SourcePath);
                target = UserProfile.Current.GetLocation(node.TargetKind).Combine(node.TargetPath);

                bool sourceIsDirectory = Directory.Exists(source);

                if (sourceIsDirectory)
                {
                    if (Directory.Exists(target))
                    {
                        return;
                    }
                }
                else
                {
                    if (File.Exists(target) || Directory.Exists(target) || !File.Exists(source))
                    {
                        return;
                    }
                }

                LoggingService.LogInfo("Migrating '{0}' to '{1}'", source, target);
                if (!sourceIsDirectory)
                {
                    Directory.CreateDirectory(target.ParentDirectory);
                }

                var handler = node.GetHandler();
                if (handler != null)
                {
                    handler.Migrate(source, target);
                    return;
                }

                if (sourceIsDirectory)
                {
                    DirectoryCopy(source, target);
                }
                else
                {
                    File.Copy(source, target);
                }
            } catch (Exception ex) {
                string message = string.Format("{0}: Failed to migrate '{1}' to '{2}'",
                                               node.Addin.Id, source.ToString() ?? "", target.ToString() ?? "");
                LoggingService.LogError(message, ex);
            }
        }
コード例 #3
0
        private void UpdateProjectFile(Models.Package[] packages, MonoDevelop.Core.FilePath projectFilePath)
        {
            var fallBackString = $@"<PropertyGroup>
                                    <TargetFramework>netstandard2.0</TargetFramework>
                                       <AssetTargetFallback>{GetFallbackPlatforms(packages)}</AssetTargetFallback>
                                     </PropertyGroup>";

            var xmlString = $@"<?xml version=""1.0"" encoding=""utf-8""?>
                                                    <Project Sdk = ""Microsoft.NET.Sdk"" >
                                                    <PropertyGroup>
                                                        <TargetFramework>netstandard2.0</TargetFramework>
                                                    </PropertyGroup>{fallBackString}
                                                    <ItemGroup>";



            var packageReferences = String.Empty;
            var packagesArray     = packages.ToArray();

            foreach (var package in packagesArray)
            {
                packageReferences += $"<PackageReference Include=\"{package.Id}\" Version=\"{package.Version}\" />";
            }


            xmlString = xmlString + packageReferences + "</ItemGroup></Project>";

            var currentItem = IdeApp.ProjectOperations.CurrentSelectedSolution.Items.FirstOrDefault(x => x.FileName.ParentDirectory.ToString() == projectFilePath.ToString());
            var csprojPath  = currentItem.FileName.ToString();

            File.Delete(csprojPath);
            File.WriteAllText(csprojPath, xmlString);
        }