Ejemplo n.º 1
0
        public UnityEditorProtocol(Lifetime lifetime, ILogger logger, UnityHost host,
                                   IScheduler dispatcher, IShellLocks locks, ISolution solution, PluginPathsProvider pluginPathsProvider,
                                   ISettingsStore settingsStore, Application.ActivityTrackingNew.UsageStatistics usageStatistics)
        {
            myComponentLifetime   = lifetime;
            myLogger              = logger;
            myDispatcher          = dispatcher;
            myLocks               = locks;
            mySolution            = solution;
            myPluginPathsProvider = pluginPathsProvider;
            myUsageStatistics     = usageStatistics;
            myHost = host;
            myBoundSettingsStore =
                settingsStore.BindToContextLive(lifetime, ContextRange.Smart(solution.ToDataContext()));
            mySessionLifetimes = new SequentialLifetimes(lifetime);
            myUnityModel       = new Property <EditorPluginModel>(lifetime, "unityModelProperty", null)
                                 .EnsureReadonly(myReadonlyToken).EnsureThisThread();

            if (!ProjectExtensions.IsAbleToEstablishProtocolConnectionWithUnity(solution.SolutionFilePath))
            {
                return;
            }

            if (solution.GetData(ProjectModelExtensions.ProtocolSolutionKey) == null)
            {
                return;
            }

            var solFolder = mySolution.SolutionFilePath.Directory;

            AdviseModelData(lifetime, mySolution.GetProtocolSolution());

            // todo: consider non-Unity Solution with Unity-generated projects
            var protocolInstancePath = solFolder.Combine("Library/ProtocolInstance.json");

            protocolInstancePath.Directory.CreateDirectory();

            var watcher = new FileSystemWatcher();

            watcher.Path         = protocolInstancePath.Directory.FullPath;
            watcher.NotifyFilter =
                NotifyFilters.LastAccess |
                NotifyFilters.LastWrite; //Watch for changes in LastAccess and LastWrite times
            watcher.Filter = protocolInstancePath.Name;

            // Add event handlers.
            watcher.Changed += OnChanged;
            watcher.Created += OnChanged;

            watcher.EnableRaisingEvents = true; // Begin watching.

            // connect on start of Rider
            CreateProtocols(protocolInstancePath);
        }