private SettingsStorageMountPoint CreateMountPoint(Lifetime lifetime, string name, double priority,
                                                           IIsAvailable isAvailable, SettingsStorageProvidersCollection settingsStorageProviders)
        {
            var storage    = SettingsStorageFactory.CreateStorage(lifetime, name, myLogger, myInternedKeyPaths);
            var mountPoint = new SettingsStorageMountPoint(storage, SettingsStorageMountPoint.MountPath.Default,
                                                           MountPointFlags.IsDefaultValues, priority, isAvailable, name);

            settingsStorageProviders.MountPoints.Add(lifetime, mountPoint);
            settingsStorageProviders.Storages.Add(lifetime, storage);

            return(mountPoint);
        }
        public void OnHasUnityReference()
        {
            if (SolutionMountPoint == null)
            {
                SolutionMountPoint = CreateSolutionMountPoint();
                foreach (var provider in mySolutionSettingsProviders)
                {
                    provider.InitialiseSolutionSettings(SolutionMountPoint);
                }

                myProjectMountPoints = new Dictionary <IProject, SettingsStorageMountPoint>();
            }
        }
Exemplo n.º 3
0
        public FindAndLoadSettings(Lifetime lifetimeComponent, SettingsStorageProvidersCollection publisher, SolutionFileLocationLive solfile, IThreading threading, IFileSystemTracker filetracker, FileSettingsStorageBehavior behavior, ISolution solution, IShellLocks locks)
        {
            // In case the solution path changes, watch each value anew
            solfile.SolutionFileLocation.ForEachValue_NotNull(lifetimeComponent, (lifetimeLocation, location) =>
            {
                double priority = ProjectModelSettingsStorageMountPointPriorityClasses.SolutionShared;
                for (FileSystemPath dir = location.Directory; !dir.IsNullOrEmpty(); dir = dir.Directory)
                {
                    try
                    {
                        priority *= .9; // The upper folder, the lower priority (regular solution-shared file takes over all of them)

                        // Walk up folders
                        // TODO: add file-system-watcher here
                        foreach (FileSystemPath settingsfile in dir.GetChildFiles("*." + AutoLoadExtension, PathSearchFlags.ExcludeDirectories | PathSearchFlags.ExcludeHidden))
                        {
                            var relativePath = settingsfile.MakeRelativeTo(location.Directory).FullPath;
                            var name         = relativePath.Replace("." + AutoLoadExtension, "");

                            // Physical storage
                            IProperty <FileSystemPath> livepath = new Property <FileSystemPath>(lifetimeLocation, "StoragePath", settingsfile);
                            var storage = new XmlFileSettingsStorage(lifetimeLocation, name, livepath, SettingsStoreSerializationToXmlDiskFile.SavingEmptyContent.KeepFile, threading, filetracker, behavior, null);

                            // Mount as a layer
                            IIsAvailable availability        = new IsAvailableByDataConstant <ISolution>(lifetimeLocation, ProjectModelDataConstants.SOLUTION, solution, locks); // Only when querying in solution context (includes Application-Wide)
                            ISettingsStorageMountPoint mount = new SettingsStorageMountPoint(storage.Storage, SettingsStorageMountPoint.MountPath.Default, 0, priority, availability, name);

                            // Metadata
                            livepath.FlowInto(lifetimeLocation, mount.Metadata.GetOrCreateProperty(UserFriendlySettingsLayers.DiskFilePath, null, true));
                            mount.Metadata.Set(UserFriendlySettingsLayers.Origin, string.Format("Automatically loaded from solution parent folder, \"{0}\"", relativePath));
                            mount.Metadata.Set(UserInjectedSettingsLayers.IsHostingUserInjections, true);

                            // Publish
                            publisher.Storages.Add(lifetimeLocation, storage.Storage);
                            publisher.MountPoints.Add(lifetimeLocation, mount);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.LogException(ex);
                    }
                }
            });
        }
Exemplo n.º 4
0
        private static SettingsStorageMountPoint CreateMountPoint(Lifetime projectLifetime,
                                                                  IProject project, SettingsStorageProvidersCollection settingsStorageProviders,
                                                                  IShellLocks locks, ILogger logger,
                                                                  InternKeyPathComponent interned)
        {
            var storageName = $"Project {project.Name} (Unity)";
            var storage     = SettingsStorageFactory.CreateStorage(projectLifetime, storageName, logger, interned);
            var isAvailable = new IsAvailableByDataConstant <IProject>(projectLifetime,
                                                                       ProjectModelDataConstants.Project, project, locks);

            // Set at a priority less than the .csproj.dotSettings layer, so we can be overridden
            var priority   = ProjectModelSettingsStorageMountPointPriorityClasses.ProjectShared * 0.9;
            var mountPoint = new SettingsStorageMountPoint(storage, SettingsStorageMountPoint.MountPath.Default,
                                                           MountPointFlags.IsDefaultValues, priority, isAvailable, storageName);

            settingsStorageProviders.MountPoints.Add(projectLifetime, mountPoint);
            settingsStorageProviders.Storages.Add(projectLifetime, storage);

            return(mountPoint);
        }
Exemplo n.º 5
0
 private void InitLanguageLevelSettings(SettingsStorageMountPoint mountPoint)
 {
     // Unity only supports C# 5 for now, but they don't currently put the language level
     // in the csproj (yet - https://twitter.com/jbevain/status/643419833594474496)
     SetValue(mountPoint, (CSharpLanguageProjectSettings s) => s.LanguageLevel, CSharpLanguageLevel.CSharp50);
 }
Exemplo n.º 6
0
        private void InitLanguageLevelSettings(IProject project, SettingsStorageMountPoint mountPoint)
        {
            if (!project.IsUnityGeneratedProject())
            {
                return; // https://github.com/JetBrains/resharper-unity/issues/150
            }
            // Make sure ReSharper doesn't suggest code changes that won't compile in Unity
            // due to mismatched C# language levels (e.g. C#6 "elvis" operator)
            //
            // * Unity prior to 5.5 uses an old mono compiler that only supports C# 4
            // * Unity 5.5 and later adds C# 6 support as an option. This is enabled by setting
            //   the API compatibility level to NET_4_6
            // * The CSharp60Support plugin replaces the compiler with either C# 6 or C# 7.0
            //   It can be recognised by a folder called `CSharp60Support` or `CSharp70Support`
            //   in the root of the project
            //   (https://bitbucket.org/alexzzzz/unity-c-5.0-and-6.0-integration)
            // * Note that since Unity 2017.2, we've been special-cased in the Unity csproj generation
            //   and we've been getting v4.5 for old runtime and default values (4.7.1) for new. So where
            //   it says 3.5 below, that depends on the version of Unity. Older versions will give us 3.5,
            //   newer versions 4.5. We don't need this special case, so hopefully it will be removed in 2018.3
            //
            // Scenarios:
            // * No VSTU installed (including Unity 5.5)
            //   .csproj has NO `LangVersion`. `TargetFrameworkVersion` will be `v3.5`
            // * Early versions of VSTU
            //   .csproj has NO `LangVersion`. `TargetFrameworkVersion` will be `v3.5`
            // * Later versions of VSTU
            //   `LangVersion` is correctly set to "4". `TargetFrameworkVersion` will be `v3.5`
            //   OR `LangVersion` is set to "6" or "latest". `TargetFrameworkVersion` will be `v4.7.1`
            // * VSTU for 5.5
            //   `LangVersion` is set to "default". `TargetFrameworkVersion` will be `v3.5` or `v4.6`
            //   Note that "default" for VS"15" or Rider will be C# 7.0!
            // * Unity3dRider is installed
            //   Uses Unity's own generation and adds correct `LangVersion`
            //   `TargetFrameworkVersion` will be correct for the selected runtime
            // * CSharp60Support is installed
            //   .csproj has NO `LangVersion`
            //   `TargetFrameworkVersion` is NOT accurate (support for C# 6 is not dependent on/trigger by .net 4.6)
            //   Look for `CSharp60Support` or `CSharp70Support` folders
            //
            // Actions:
            // If `LangVersion` is missing or "default"
            // then override based on `TargetFrameworkVersion` or presence of `CSharp60Support`/`CSharp70Support`
            // else do nothing
            //
            // Notes:
            // * Unity and VSTU have two separate .csproj routines. VSTU adds extra references,
            //   the VSTU project flavour GUID and imports UnityVs.targets, which disables the
            //   `GenerateTargetFrameworkMonikerAttribute` target
            // * CSharp60Support post-processes the .csproj file directly if VSTU is not installed.
            //   If it is installed, it registers a delegate with `ProjectFilesGenerator.ProjectFileGeneration`
            //   and removes it before it's written to disk
            // * `LangVersion` can be conditionally specified, which makes checking for "default" awkward
            // * If Unity3dRider + CSharp60Support are both installed, last write wins
            //   Order of post-processing is non-deterministic, so Rider's LangVersion might be removed
            // * Unity3dRider can set `TargetFrameworkVersion` to `v4.5` on non-Windows machines to fix
            //   an issue resolving System.Linq

            var languageLevel = ReSharperSettingsCSharpLanguageLevel.Default;

            if (IsLangVersionMissing(project) || IsLangVersionDefault(project))
            {
                // Support for https://bitbucket.org/alexzzzz/unity-c-5.0-and-6.0-integration
                // See also https://github.com/JetBrains/resharper-unity/issues/50#issuecomment-257611218
                if (project.Location.CombineWithShortName("CSharp70Support").ExistsDirectory)
                {
                    languageLevel = ReSharperSettingsCSharpLanguageLevel.CSharp70;
                }
                else if (project.Location.CombineWithShortName("CSharp60Support").ExistsDirectory)
                {
                    languageLevel = ReSharperSettingsCSharpLanguageLevel.CSharp60;
                }
                else
                {
                    languageLevel = IsTargetFrameworkAtLeast46(project)
                        ? ReSharperSettingsCSharpLanguageLevel.CSharp60
                        : ReSharperSettingsCSharpLanguageLevel.CSharp40;
                }
            }
            SetValue(mountPoint, (CSharpLanguageProjectSettings s) => s.LanguageLevel, languageLevel);
        }
Exemplo n.º 7
0
 private void InitialiseSettingValues(IProject project, SettingsStorageMountPoint mountPoint)
 {
     InitNamespaceProviderSettings(mountPoint);
     InitLanguageLevelSettings(project, mountPoint);
 }