private static void WaiterMethod()
 {
     ColorConsole.WriteWarning("Waiting for auto-reset event signal. Thread ID :" + Thread.CurrentThread.ManagedThreadId);
     _autoResetEvent.WaitOne();
     ColorConsole.WriteInfo("Done.");
     _autoResetEvent.Close();
 }
Пример #2
0
        private async static Task DoSomething(string description)
        {
            await Task.Delay(TimeSpan.FromSeconds(1));

            ColorConsole.WriteInfo($"work with {description}.... {DateTime.UtcNow}");
            throw new NotImplementedException();
        }
        public int ConsolidateTransitiveDependencies(bool checkOnly)
        {
            RestoreSolution();

            ColorConsole.WriteInfo($"Generate dependency graph for {m_options.SolutionFile} please wait....");
            var graphSpec       = m_dependencyGraphReader.GenerateDependencyGraph(m_options.SolutionFile, m_options.MsBuildPath);
            var graph           = m_dependencyGraphAnalyzer.AnalyzeDependencyGraph(graphSpec);
            var requiredUpdates = graph.IdentifyRequiredNugetUpdates(m_options.Verbose).ToList();
            int result          = 0;    // success

            if (requiredUpdates.Any())
            {
                if (checkOnly)
                {
                    var packages = requiredUpdates.GroupBy(x => x.Library.Name).ToList();
                    ColorConsole.WriteWarning($"{packages.Count} packages are referenced with different versions:");
                    foreach (var package in packages)
                    {
                        var firstOccurrence = package.First();
                        ColorConsole.WriteWarning($"Upgrade of {firstOccurrence.Library.Name} to version {firstOccurrence.TargetVersion} required in {package.Count()} projects");
                    }
                    ColorConsole.WriteWarning("run this command again with the fix option to fix this");
                    result = requiredUpdates.Count;
                }
                else
                {
                    UpdatePackageReferences(requiredUpdates);
                }
            }
            else
            {
                ColorConsole.WriteInfo("all packages are referenced with the same version");
            }
            return(result);            // success
        }
Пример #4
0
        static SynchronizationContextsPractice()
        {
            Console.ForegroundColor = ConsoleColor.Green;
            string info = "A ContextBoundObject can be thought of as a “remote” object, meaning all method calls are intercepted. " +
                          "\nTo make this interception possible, when we instantiate AutoLock, the CLR actually returns a proxy — an object with the same methods and properties of an AutoLock object, which acts as an intermediary. It's via this intermediary that the automatic locking takes place. Overall, the interception adds around a microsecond to each method call.";

            ColorConsole.WriteInfo(info);
        }
        public static void PrintUsingAutoResetEvent()
        {
            ColorConsole.WriteInfo("An AutoResetEvent is like a ticket turnstile: inserting a ticket lets exactly one person through.");

            new Thread(WaiterMethod).Start();
            Thread.Sleep(2000);
            _autoResetEvent.Set();
            ColorConsole.WriteInfo("Signal Received.");
        }
        private void RestoreSolution()
        {
            var runner = new ProcessRunner();

            ColorConsole.WriteInfo($"Restore {m_options.SolutionFile}");
            var result = runner.Run("dotnet", null, new[] { "restore", m_options.SolutionFile });

            if (!result.IsSuccess)
            {
                ColorConsole.WriteError($"restoring failed {result.Errors} ");
            }
        }
        public IEnumerable <RequiredNugetUpdate> IdentifyRequiredNugetUpdates(bool verbose)
        {
            if (verbose)
            {
                if (m_assemblyLookup.Any(a => a.Value.OccurrenceList.Count > 1))
                {
                    foreach (var duplicateVersions in m_assemblyLookup.Where(a => a.Value.OccurrenceList.Count > 1))
                    {
                        ColorConsole.WriteLine($"Duplicate dependency: {duplicateVersions.Key}", ConsoleColor.Red);
                        foreach (var occurrences in duplicateVersions.Value.OccurrenceList)
                        {
                            ColorConsole.WriteLine($"\t{occurrences.Key}: used in", ConsoleColor.Green);
                            foreach (var projectAndOccurrence in occurrences.Value.GroupBy(x => x.Root))
                            {
                                ColorConsole.WriteLine($"\t\t{projectAndOccurrence.Key}:");
                                foreach (var directReferencedNugets in projectAndOccurrence
                                         .GroupBy(x => x.DirectReference)
                                         .Select(x => new
                                {
                                    MaxLvl = x.Max(v => v.Lvl),
                                    DirectAssembly = x.Key
                                })
                                         .OrderBy(x => x.MaxLvl))
                                {
                                    if (directReferencedNugets.MaxLvl == 0)
                                    {
                                        ColorConsole.WriteLine("\t\t\tdirect reference", ConsoleColor.Green);
                                    }
                                    else
                                    {
                                        ColorConsole.WriteEmbeddedColorLine(
                                            $"\t\t\t{duplicateVersions.Key} transitive reference({directReferencedNugets.MaxLvl})" +
                                            $" of [Yellow]{directReferencedNugets.DirectAssembly.Name}-{directReferencedNugets.DirectAssembly.Version}[/Yellow]");
                                    }
                                }
                            }
                        }
                    }
                }
            }
            ColorConsole.WriteInfo($"{m_assemblyLookup.Count} dependencies found in {m_dependencyGraphSpec.Projects.Count} projects");
            var duplicates            = m_assemblyLookup.Where(a => a.Value.OccurrenceList.Count > 1).ToList();
            var maxVersionLookup      = duplicates.ToDictionary(x => x.Key, x => x.Value.OccurrenceList.Keys.Max());
            var projectWithMaxVersion = duplicates.ToDictionary(x => x.Key, x => x.Value.ProjectWithMaxVersion);

            var updateRequired = duplicates.SelectMany(kvp =>
                                                       kvp.Value.OccurrenceList.Where(x => x.Key < maxVersionLookup[kvp.Key]).SelectMany(x => x.Value)).ToList();

            return(updateRequired.Select(x =>
                                         new RequiredNugetUpdate(x.ProjectPath, x.Target, maxVersionLookup[x.Target.Name], x.Lvl == 0, x.DirectReference.Name, projectWithMaxVersion[x.Target.Name]))
                   .Distinct(new RequiredNugetUpdateEqualityComparer()));
        }
        public static void CallSetBeforeWaitOne()
        {
            System.Console.WriteLine("============CALL SET BEFORE WAIT ONE============\n");

            ColorConsole.WriteInfo("An AutoResetEvent is like a ticket turnstile: inserting a ticket lets exactly one person through.");
            ColorConsole.WriteInfo("If set is called before Wait, the handle stays open for as long as it takes until some thread calls WaitOne.");
            System.Console.WriteLine("\n");

            _autoResetEvent.Set();
            ColorConsole.WriteInfo("Signal Received.");
            new Thread(WaiterMethod).Start();
            Thread.Sleep(2000);
            System.Console.WriteLine("Method Completed.");
            _autoResetEvent.Close();
        }
Пример #9
0
        public static void TestSemaphore()
        {
            ColorConsole.WriteInfo("", "SEMAPHORE PRACTICE");

            Thread t1 = new Thread(PrintSemaphore);

            t1.Start();
            Thread t2 = new Thread(PrintSemaphore);

            t2.Start();
            Thread t3 = new Thread(PrintSemaphore);

            t3.Start();
            Thread t4 = new Thread(PrintSemaphore);

            t4.Start();
        }
Пример #10
0
        public static void TwoWaySignal()
        {
            ColorConsole.WriteInfo("Two Way Signal DEMO.");
            Thread th = new Thread(DoWork);

            th.Start();

            System.Console.WriteLine("Ready Wait One.");
            _ready.WaitOne();
            System.Console.WriteLine("Ready Signal Received.");

            System.Console.WriteLine("Go Set.");
            _go.Set();

            lock (_locker)
            {
                _isDone = true;
            }
        }
Пример #11
0
 public void Demo()
 {
     ColorConsole.WriteInfo("Inside method DEMO. Thread ID : " + Thread.CurrentThread.ManagedThreadId);
     Thread.Sleep(1000);
     Console.WriteLine("Thread execution completed.");
 }