Exemplo n.º 1
0
        private void InstallPluginIfRequired()
        {
            if (!myUnitySolutionTracker.IsUnityProjectFolder.Value)
            {
                return;
            }

            if (myPluginInstallations.Contains(mySolution.SolutionFilePath))
            {
                return;
            }

            if (!myBoundSettingsStore.GetValue((UnitySettings s) => s.InstallUnity3DRiderPlugin))
            {
                return;
            }

            // forcing fresh install due to being unable to provide proper setting until InputField is patched in Rider
            // ReSharper disable once ArgumentsStyleNamedExpression
            var installationInfo = myDetector.GetInstallationInfo(myCurrentVersion, previousInstallationDir: FileSystemPath.Empty);

            if (!installationInfo.ShouldInstallPlugin)
            {
                myLogger.Info("Plugin should not be installed.");
                if (installationInfo.ExistingFiles.Count > 0)
                {
                    myLogger.Info("Already existing plugin files:\n{0}", string.Join("\n", installationInfo.ExistingFiles));
                }

                return;
            }

            QueueInstall(installationInfo);
            myQueue.Enqueue(() => { myRefresher.Refresh(false); });
        }
Exemplo n.º 2
0
        public async Task AllTasksAreDequeuedOnce()
        {
            const int             count       = 5000;
            const int             workerCount = 10;
            ProcessingQueue <int> queue       = new ProcessingQueue <int>(() => { });

            foreach (int task in Enumerable.Range(0, count))
            {
                queue.Enqueue(task);
            }


            var tasks = Enumerable.Range(0, workerCount)
                        .Select(workerIndex => Task.Run(() =>
            {
                var dequeuedItems = new List <int>();
                while (queue.TryDequeue(out int item))
                {
                    dequeuedItems.Add(item);
                }
                return(dequeuedItems);
            }))
                        .ToList();
            await Task.WhenAll(tasks);

            var countsPerThread  = tasks.Select(t => t.Result.Count).ToList(); // just verify it does not have an extremely peaked distribution
            var allDequeuedItems = tasks.Select(t => t.Result)
                                   .Concat()
                                   .Distinct()
                                   .ToList();

            Assert.AreEqual(count, allDequeuedItems.Count);
        }
 private void QueueInstall(UnityPluginDetector.InstallationInfo installationInfo, bool force = false)
 {
     myQueue.Enqueue(() =>
     {
         Install(installationInfo, force);
         myPluginInstallations.Add(mySolution.SolutionFilePath);
     });
 }
Exemplo n.º 4
0
 private void UpdateProcessingQueue(WorkItem workItem)
 {
     if (ProcessingQueue.CapacitiesLeft && workItem != null)
     {
         CreateAndEnqueueInstuction(methodName: ProductionAgent.InstuctionsMethods.ProductionStarted.ToString(),
                                    objectToProcess: workItem,
                                    targetAgent: workItem.ProductionAgent);
         ProcessingQueue.Enqueue(workItem);
         Queue.Remove(workItem);
     }
 }
Exemplo n.º 5
0
        private void InstallPluginIfRequired(ICollection <IProject> projects)
        {
            if (projects.Count == 0)
            {
                return;
            }

            InstallFromResource(@"Library\resharper-unity-libs\nunit3.5.0\nunit.framework.dll", ".Unity3dRider.Library.resharper_unity_libs.nunit3._5._0.nunit.framework.dll");
            InstallFromResource(@"Library\resharper-unity-libs\pdb2mdb.exe", ".Unity3dRider.Library.resharper_unity_libs.pdb2mdb.exe");

            if (myPluginInstallations.Contains(mySolution.SolutionFilePath))
            {
                return;
            }

            if (!myBoundSettingsStore.GetValue((UnitySettings s) => s.InstallUnity3DRiderPlugin))
            {
                return;
            }

            // forcing fresh install due to being unable to provide proper setting until InputField is patched in Rider
            // ReSharper disable once ArgumentsStyleNamedExpression
            var installationInfo = myDetector.GetInstallationInfo(projects, previousInstallationDir: FileSystemPath.Empty);

            if (!installationInfo.ShouldInstallPlugin)
            {
                myLogger.Info("Plugin should not be installed.");
                if (installationInfo.ExistingFiles.Count > 0)
                {
                    myLogger.Info("Already existing plugin files:\n{0}", string.Join("\n", installationInfo.ExistingFiles));
                }

                return;
            }

            myQueue.Enqueue(() =>
            {
                Install(installationInfo);
                myPluginInstallations.Add(mySolution.SolutionFilePath);
            });
        }
Exemplo n.º 6
0
        public async Task NeverDequeuedItemCannotBeRemoved()
        {
            const int             item      = 0;
            const int             otherItem = 1;
            ProcessingQueue <int> queue     = new ProcessingQueue <int>(() => { });

            queue.Enqueue(item);
            await DelayDelta();

            // should throw because otherItem is not being processed yet
            queue.OnProcessed(otherItem);
        }
Exemplo n.º 7
0
        public async Task DequeuedItemIsStillIncludedInCount()
        {
            const int             item  = 0;
            ProcessingQueue <int> queue = new ProcessingQueue <int>(() => { });

            queue.Enqueue(item);
            await DelayDelta();

            bool dequeued = queue.TryDequeue(out int dequeuedItem);

            Assert.AreEqual(1, queue.Count);
        }
Exemplo n.º 8
0
        public async Task DequeuedItemIsInProcessingList()
        {
            const int             item  = 0;
            ProcessingQueue <int> queue = new ProcessingQueue <int>(() => { });

            queue.Enqueue(item);
            await DelayDelta();

            queue.TryDequeue(out int dequeuedItem);
            queue.OnProcessed(dequeuedItem);

            Assert.IsTrue(queue.CurrentlyProcessingTasks.Contains(dequeuedItem));
        }
Exemplo n.º 9
0
        public async Task AddedItemCanBeDequeued()
        {
            const int             item  = 0;
            ProcessingQueue <int> queue = new ProcessingQueue <int>(() => { });

            queue.Enqueue(item);
            await DelayDelta();

            bool dequeued = queue.TryDequeue(out int dequeuedItem);

            Assert.IsTrue(dequeued);
            Assert.AreEqual(item, dequeuedItem);
        }
Exemplo n.º 10
0
        protected override void Read()
        {
            BinaryFormatter formatter = new BinaryFormatter();

            using (var file = new FileStream(InputFilePath, FileMode.Open, FileAccess.Read))
            {
                var totalChunkCount = (long)formatter.Deserialize(file);
                while (file.Position < file.Length)
                {
                    var chunk = (FileChunk)formatter.Deserialize(file);
                    ProcessingQueue.Enqueue(chunk);
                }
            }
            ProcessingQueue.Close();
        }
Exemplo n.º 11
0
        public async Task DequeuedItemCanBeRemoved()
        {
            const int             item  = 0;
            ProcessingQueue <int> queue = new ProcessingQueue <int>(() => { });

            queue.Enqueue(item);
            await DelayDelta();

            queue.TryDequeue(out int dequeuedItem);

            // assertion is that the following does not throw
            queue.OnProcessed(dequeuedItem);

            Assert.AreEqual(0, queue.Count);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Enqueue text to the log with formatting
        /// </summary>
        /// <param name="text">Text to write to the log</param>
        /// <param name="logLevel">LogLevel for the log, defaults to USER</param>
        private void LogInternal(string text, LogLevel logLevel = LogLevel.USER)
        {
            // Null text gets ignored
            if (text == null)
            {
                return;
            }

            // If we have verbose logs but not enabled, ignore
            if (logLevel == LogLevel.VERBOSE && !App.Options.VerboseLogging)
            {
                return;
            }

            // Enqueue the text
            logQueue.Enqueue(new LogLine(text, logLevel));
        }
Exemplo n.º 13
0
        private static void AddToProcessingQueue(string path)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException("Item cannot be added to queue.", path);
            }

            var handler = HandlerFactory.GetInputHandler(path);

            if (handler != null)
            {
                c_queue.Enqueue(handler);
                c_loadedPaths.Add(handler.FilePath, handler);
            }

            StartNextInProcessingQueue();
        }
Exemplo n.º 14
0
        protected override void Read()
        {
            var buffer       = new byte[ChunkByteSize];
            var chunkCounter = 1;

            using (var file = new FileStream(InputFilePath, FileMode.Open, FileAccess.Read))
            {
                int numBytesRead = file.Read(buffer, 0, ChunkByteSize);

                while (numBytesRead > 0)
                {
                    ProcessingQueue.Enqueue(chunkCounter++, buffer);
                    numBytesRead = file.Read(buffer, 0, buffer.Length);
                }
            }
            ProcessingQueue.Close();
        }
Exemplo n.º 15
0
        /**************************
        *   ===== Downloading =====
        **************************/

        private async Task DownloadThread(int id)
        {
            string html = await client.GetThread(id);

            ProcessingQueue.Enqueue(new UnparsedThread(id, html));
        }
Exemplo n.º 16
0
        private void InstallPluginIfRequired()
        {
            if (!myUnitySolutionTracker.IsUnityProjectFolder.Value)
            {
                return;
            }

            if (myPluginInstallations.Contains(mySolution.SolutionFilePath))
            {
                return;
            }

            if (!myBoundSettingsStore.GetValue((UnitySettings s) => s.InstallUnity3DRiderPlugin))
            {
                return;
            }

            // Unity 2019.2+ is expected to have com.unity.ide.rider package, which loads EditorPlugin directly from Rider installation
            var manifestJsonFile = mySolution.SolutionDirectory.Combine("Packages/manifest.json");

            if (manifestJsonFile.ExistsFile)
            {
                var text = manifestJsonFile.ReadAllText2().Text;
                //"com.unity.ide.rider": "1.0.7"
                var match = Regex.Match(text, @"""com\.unity\.ide\.rider""\s*:\s*""(?<version>.*)""", RegexOptions.Multiline);
                if (match.Success)
                {
                    if (Version.TryParse(match.Groups["version"].Value, out var version))
                    {
                        if (version >= new Version(1, 0, 7))
                        {
                            myLogger.Verbose($"com.unity.ide.rider version {version}. Skip EditorPlugin installation.");
                            return;
                        }

                        myLogger.Verbose($"com.unity.ide.rider version {version}. EditorPlugin installation continues.");
                    }
                }
            }

            var localPackage = mySolution.SolutionDirectory.Combine("Packages/com.unity.ide.rider/package.json");

            if (localPackage.ExistsFile)
            {
                myLogger.Verbose("Local package com.unity.ide.rider detected, skip EditorPlugin installation.");
                return;
            }

            // forcing fresh install due to being unable to provide proper setting until InputField is patched in Rider
            // ReSharper disable once ArgumentsStyleNamedExpression
            var installationInfo = myDetector.GetInstallationInfo(myCurrentVersion, previousInstallationDir: FileSystemPath.Empty);

            if (!installationInfo.ShouldInstallPlugin)
            {
                myLogger.Info("Plugin should not be installed.");
                if (installationInfo.ExistingFiles.Count > 0)
                {
                    myLogger.Info("Already existing plugin files:\n{0}",
                                  string.Join("\n", installationInfo.ExistingFiles));
                }

                return;
            }

            QueueInstall(installationInfo);
            myQueue.Enqueue(() =>
            {
                mySolution.Locks.Tasks.StartNew(myLifetime, Scheduling.MainDispatcher,
                                                () => myRefresher.Refresh(RefreshType.Normal));
            });
        }
Exemplo n.º 17
0
 /// <summary>
 /// Event handler for data returned from a process
 /// </summary>
 private void OutputToLog(object proc, string args) => outputQueue.Enqueue(args);
Exemplo n.º 18
0
        private void InstallPluginIfRequired()
        {
            if (!myUnitySolutionTracker.IsUnityProjectFolder.Value)
            {
                return;
            }

            if (myPluginInstallations.Contains(mySolution.SolutionFilePath))
            {
                return;
            }

            if (!myBoundSettingsStore.GetValue((UnitySettings s) => s.InstallUnity3DRiderPlugin))
            {
                return;
            }

            var versionForSolution = myUnityVersion.ActualVersionForSolution.Value;

            if (versionForSolution >= new Version("2019.2")) // 2019.2+ would not work fine either without Rider package, and when package is present it loads EditorPlugin directly from Rider installation.
            {
                var installationInfoToRemove = myDetector.GetInstallationInfo(myCurrentVersion, previousInstallationDir: FileSystemPath.Empty);
                if (!installationInfoToRemove.PluginDirectory.IsAbsolute)
                {
                    return;
                }

                var pluginDll = installationInfoToRemove.PluginDirectory.Combine(PluginPathsProvider.BasicPluginDllFile);
                if (pluginDll.ExistsFile)
                {
                    myQueue.Enqueue(() =>
                    {
                        myLogger.Info($"Remove {pluginDll}. Rider package should be used instead.");
                        pluginDll.DeleteFile();
                        FileSystemPath.Parse(pluginDll.FullPath + ".meta").DeleteFile();

                        // jetbrainsDir is usually "Assets\Plugins\Editor\JetBrains", however custom locations were also possible
                        var jetbrainsDir = installationInfoToRemove.PluginDirectory;
                        if (jetbrainsDir.GetChildren().Any() || jetbrainsDir.Name != "JetBrains")
                        {
                            return;
                        }
                        jetbrainsDir.DeleteDirectoryNonRecursive();
                        FileSystemPath.Parse(jetbrainsDir.FullPath + ".meta").DeleteFile();
                        var pluginsEditorDir = jetbrainsDir.Directory;
                        if (pluginsEditorDir.GetChildren().Any() || pluginsEditorDir.Name != "Editor")
                        {
                            return;
                        }
                        pluginsEditorDir.DeleteDirectoryNonRecursive();
                        FileSystemPath.Parse(pluginsEditorDir.FullPath + ".meta").DeleteFile();
                        var pluginsDir = pluginsEditorDir.Directory;
                        if (pluginsDir.GetChildren().Any() || pluginsDir.Name != "Plugins")
                        {
                            return;
                        }
                        pluginsDir.DeleteDirectoryNonRecursive();
                        FileSystemPath.Parse(pluginsDir.FullPath + ".meta").DeleteFile();
                    });
                }
                return;
            }

            // forcing fresh install due to being unable to provide proper setting until InputField is patched in Rider
            // ReSharper disable once ArgumentsStyleNamedExpression
            var installationInfo = myDetector.GetInstallationInfo(myCurrentVersion, previousInstallationDir: FileSystemPath.Empty);

            if (!installationInfo.ShouldInstallPlugin)
            {
                myLogger.Info("Plugin should not be installed.");
                if (installationInfo.ExistingFiles.Count > 0)
                {
                    myLogger.Info("Already existing plugin files:\n{0}",
                                  string.Join("\n", installationInfo.ExistingFiles));
                }

                return;
            }

            QueueInstall(installationInfo);
            myQueue.Enqueue(() =>
            {
                mySolution.Locks.Tasks.StartNew(myLifetime, Scheduling.MainGuard,
                                                () => myRefresher.StartRefresh(RefreshType.Normal));
            });
        }
Exemplo n.º 19
0
        /// <summary>
        /// Main graph build method.
        /// Recursively builds the graph either until the size suffices or we are out of the nodes.
        /// </summary>
        /// <param name="startingPerson"></param>
        /// <param name="depth"></param>
        /// <param name="includePointingTo"></param>
        /// <param name="includeNonPersons"></param>
        /// <param name="aggressive"></param>
        private void BuildGraph(Person startingPerson, bool includePointingTo, bool includeNonPersons, bool aggressive = false)
        {
            List <GraphRelationRaw> branchList = new List <GraphRelationRaw>();

            // TODO: Don't open new connection every time.
            // Use connection pool.
            using (var connection = new QC.SqlConnection(GetConnectionString(HomeController.DefaultProviderName)))
            {
                connection.Open();
                using (var command = new QC.SqlCommand())
                {
                    command.Connection  = connection;
                    command.CommandType = DT.CommandType.Text;

                    // Queries here are not very optimized. Do better.
                    if (includePointingTo && !includeNonPersons)
                    {
                        command.CommandText = @"  
                            select entity_name as node_from, property_name as branch_name, link2 as node_to from properties1 
                            where link2 = @name and  exists (select name from persons where name = entity_name)
                            select entity_name as node_from, property_name as branch_name, link2 as node_to from properties1 
                            where entity_name = @name and link2 is not null and isPerson = 1
                        ";
                    }
                    else if (!includePointingTo && includeNonPersons)
                    {
                        command.CommandText = @"  
                            select entity_name as node_from, property_name as branch_name, link2 as node_to from properties1 
                            where entity_name = @name and link2 is not null
                        ";
                    }
                    else if (includePointingTo && includeNonPersons)
                    {
                        command.CommandText = @"
                            select entity_name as node_from, property_name as branch_name, link2 as node_to from properties1 
                            where (link2 = @name) or (entity_name = @name and link2 is not null)
                        ";
                    }
                    else
                    {
                        command.CommandText = @"  
                            select entity_name as node_from, property_name as branch_name, link2 as node_to from properties1 
                            where entity_name = @name and link2 is not null and isPerson = 1
                        ";
                    }

                    command.Parameters.AddWithValue("@name", startingPerson.Name);

                    QC.SqlDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        branchList.Add(
                            new GraphRelationRaw
                        {
                            From = reader.GetString(0),
                            Name = reader.GetString(1),
                            To   = reader.GetString(2)
                        });
                    }
                }
            }

            // Premature return if this is a dominant node
            // later in search.
            // This is an ugly edge case and should be removed at some point.
            if (branchList.Count > 20 && startingPerson.DistanceFromCenter > 1)
            {
                return;
            }

            foreach (var branch in branchList)
            {
                Person personFrom;
                Person personTo;

                bool isPersonFromNew = false;
                bool isPersonToNew   = false;

                if (!Persons.TryGetValue(branch.From, out personFrom))
                {
                    personFrom = new Person(branch.From, startingPerson.DistanceFromCenter + 1);
                    Persons.Add(personFrom.Name, personFrom);
                    isPersonFromNew = true;
                    ProcessingQueue.Enqueue(personFrom);
                }

                if (!Persons.TryGetValue(branch.To, out personTo))
                {
                    personTo = new Person(branch.To, startingPerson.DistanceFromCenter + 1);
                    Persons.Add(personTo.Name, personTo);
                    isPersonToNew = true;
                    ProcessingQueue.Enqueue(personTo);
                }

                if (isPersonFromNew)
                {
                    personFrom.DistanceFromCenter = personTo.DistanceFromCenter + 1;
                }

                if (isPersonToNew)
                {
                    personTo.DistanceFromCenter = personFrom.DistanceFromCenter + 1;
                }

                PersonConnections.Add(new Relation(personFrom, personTo, branch.Name));
            }

            // One more check, if we are early in the graph and we still don't have many results
            // do more aggressive search.
            if (startingPerson.DistanceFromCenter == 0 && Persons.Count < 5 && (!includePointingTo || !includeNonPersons))
            {
                if (!includePointingTo)
                {
                    BuildGraph(startingPerson, true, false);
                }
                else
                {
                    // Do full search.
                    BuildGraph(startingPerson, true, true);
                }
            }

            while (ProcessingQueue.Count != 0 && Persons.Count < MaxNumberOfPersonsPerGraph)
            {
                if (aggressive && startingPerson.DistanceFromCenter < 3)
                {
                    BuildGraph(ProcessingQueue.Dequeue(), true, true, aggressive);
                }
                else if (aggressive && startingPerson.DistanceFromCenter < 4)
                {
                    BuildGraph(ProcessingQueue.Dequeue(), true, false, aggressive);
                }
                if (startingPerson.DistanceFromCenter < 2 && Persons.Count < 5 && ProcessingQueue.Count < 5)
                {
                    BuildGraph(ProcessingQueue.Dequeue(), true, false);
                }
                else
                {
                    BuildGraph(ProcessingQueue.Dequeue(), false, false);
                }
            }
        }