示例#1
0
        private async Task <DependencyGraphNode> BuildGraphAtDependency(
            IRemoteFactory remoteFactory,
            DependencyDetail rootDependency,
            List <DependencyDetail> updateList,
            Dictionary <string, DependencyGraphNode> nodeCache)
        {
            DependencyGraphBuildOptions dependencyGraphBuildOptions = new DependencyGraphBuildOptions()
            {
                IncludeToolset  = true,
                LookupBuilds    = true,
                NodeDiff        = NodeDiff.None,
                EarlyBuildBreak = new EarlyBreakOn
                {
                    Type    = EarlyBreakOnType.Assets,
                    BreakOn = new List <string>(updateList.Select(d => d.Name))
                }
            };

            DependencyGraph dependencyGraph = await DependencyGraph.BuildRemoteDependencyGraphAsync(
                remoteFactory, null, rootDependency.RepoUri, rootDependency.Commit, dependencyGraphBuildOptions, _logger);

            // Cache all nodes in this built graph.
            foreach (DependencyGraphNode node in dependencyGraph.Nodes)
            {
                if (!nodeCache.ContainsKey($"{node.Repository}@{node.Commit}"))
                {
                    nodeCache.Add($"{node.Repository}@{node.Commit}", node);
                }
            }

            return(dependencyGraph.Root);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Configuring client...");
            RemotingConfiguration.Configure("ConsoleClient.exe.config");

            Console.WriteLine("Creating proxy...");
            IRemoteFactory factory = (IRemoteFactory)RemotingHelper.CreateProxy(typeof(IRemoteFactory));

            Console.WriteLine("Calling GetAge()...");
            int age = factory.GetAge();

            Console.WriteLine(">> Call successful: " + age.ToString());

            Console.WriteLine("Calling GetPerson()...");
            Person p = factory.GetPerson();

            Console.WriteLine(">> Person retrieved: {0} {1}, {2}", p.Firstname, p.Lastname, p.Age.ToString());
            Console.WriteLine(">>>> New properties: {0} {1}", p.Birthdate, p.Comments);

            Console.WriteLine("Calling UploadPerson()...");
            Person up = new Person("Upload", "Test", 20);

            up.Birthdate = DateTime.Now.AddDays(2);
            up.Comments  = "Two days older person!";
            factory.UploadPerson(up);
            Console.WriteLine(">> Upload called successfully!");

            Console.ReadLine();
        }
 public BuildTimeController(
     ILogger <BuildTimeController> logger,
     IRemoteFactory remoteFactory)
 {
     _logger        = logger;
     _remoteFactory = remoteFactory;
 }
示例#4
0
        private async Task CoherencyUpdatesAsync(
            IRemote barOnlyRemote,
            IRemoteFactory remoteFactory,
            List <DependencyDetail> currentDependencies,
            List <DependencyDetail> dependenciesToUpdate)
        {
            Console.WriteLine("Checking for coherency updates...");

            // Now run a coherency update based on the current set of dependencies updated
            // from the previous pass.
            List <DependencyUpdate> coherencyUpdates =
                await barOnlyRemote.GetRequiredCoherencyUpdatesAsync(currentDependencies, remoteFactory);

            foreach (DependencyUpdate dependencyUpdate in coherencyUpdates)
            {
                DependencyDetail from            = dependencyUpdate.From;
                DependencyDetail to              = dependencyUpdate.To;
                DependencyDetail coherencyParent = currentDependencies.First(d =>
                                                                             d.Name.Equals(from.CoherentParentDependencyName, StringComparison.OrdinalIgnoreCase));
                // Print out what we are going to do.
                Console.WriteLine($"Updating '{from.Name}': '{from.Version}' => '{to.Version}' " +
                                  $"to ensure coherency with {from.CoherentParentDependencyName}@{coherencyParent.Version}");

                // Final list of dependencies to update
                dependenciesToUpdate.Add(to);
            }
        }
示例#5
0
        static void Main(string[] args)
        {
            HttpChannel channel = new HttpChannel();

            ChannelServices.RegisterChannel(channel);

            Console.WriteLine("Acqu. Rem. Instance");
            IRemoteFactory fact = (IRemoteFactory)Activator.GetObject(
                typeof(IRemoteFactory),
                "http://localhost:1234/factory.soap");

            Console.WriteLine("Client.Main(): Acquiring object from factory");
            IRemoteObject obj1 = fact.getNewInstance();

            Console.WriteLine("Client.Main(): Sleeping one second");
            System.Threading.Thread.Sleep(1000);

            Console.WriteLine("Client.Main(): Setting value");
            try
            {
                obj1.setValue(42);
            }
            catch (Exception e)
            {
                Console.WriteLine("Client.Main(). EXCEPTION \n{0}", e.Message);
            }

            Console.ReadLine();
        }
示例#6
0
        public SecondServer()
        {
            System.Diagnostics.Debug.WriteLine("Initializing server...");

            _proxy = (IRemoteFactory)RemotingHelper.CreateProxy(typeof(IRemoteFactory));

            System.Diagnostics.Debug.WriteLine("Server initialized!");
        }
示例#7
0
        private void ActionCall_Click(object sender, System.EventArgs e)
        {
            IRemoteFactory proxy = (IRemoteFactory)RemotingHelper.CreateProxy(typeof(IRemoteFactory));
            Person         p     = proxy.GetPerson();

            ListResults.Items.Add(string.Format("{0} {1}, {2}",
                                                p.Firstname, p.Lastname, p.Age));
        }
示例#8
0
 public ChannelsController(BuildAssetRegistryContext context,
                           IRemoteFactory factory,
                           ILogger <ChannelsController> logger)
 {
     _context       = context;
     _remoteFactory = factory;
     Logger         = logger;
 }
        private static async Task DoLatestInChannelGraphNodeDiffAsync(
            IRemoteFactory remoteFactory,
            ILogger logger,
            Dictionary <string, DependencyGraphNode> nodeCache,
            Dictionary <string, DependencyGraphNode> visitedRepoUriNodes)
        {
            logger.LogInformation("Running latest in channel node diff.");

            IRemote barOnlyRemote = await remoteFactory.GetBarOnlyRemoteAsync(logger);

            // Walk each node in the graph and diff against the latest build in the channel
            // that was also applied to the node.
            Dictionary <string, string> latestCommitCache = new Dictionary <string, string>();

            foreach (DependencyGraphNode node in nodeCache.Values)
            {
                // Start with an unknown diff.
                node.DiffFrom = GitDiff.UnknownDiff();

                if (node.ContributingBuilds.Any())
                {
                    // Choose latest build of node that has a channel.
                    Build newestBuildWithChannel = node.ContributingBuilds.OrderByDescending(b => b.DateProduced).FirstOrDefault(
                        b => b.Channels != null && b.Channels.Any());
                    // If no build was found (e.g. build was flowed without a channel or channel was removed from
                    // a build, then no diff from latest.
                    if (newestBuildWithChannel != null)
                    {
                        int channelId = newestBuildWithChannel.Channels.First().Id;
                        // Just choose the first channel. This algorithm is mostly just heuristic.
                        string latestCommitKey = $"{node.Repository}@{channelId}";
                        string latestCommit    = null;
                        if (!latestCommitCache.TryGetValue(latestCommitKey, out latestCommit))
                        {
                            // Look up latest build in the channel
                            var latestBuild = await barOnlyRemote.GetLatestBuildAsync(node.Repository, channelId);

                            // Could be null, if the only build was removed from the channel
                            if (latestBuild != null)
                            {
                                latestCommit = latestBuild.Commit;
                            }
                            // Add to cache
                            latestCommitCache.Add(latestCommitKey, latestCommit);
                        }

                        // Perform diff if there is a latest commit.
                        if (!string.IsNullOrEmpty(latestCommit))
                        {
                            IRemote repoRemote = await remoteFactory.GetRemoteAsync(node.Repository, logger);

                            // This will return a no-diff if latestCommit == node.Commit
                            node.DiffFrom = await repoRemote.GitDiffAsync(node.Repository, latestCommit, node.Commit);
                        }
                    }
                }
            }
        }
示例#10
0
        private void ActionCall_Click(object sender, System.EventArgs e)
        {
            // Get the transparent proxy for the factory
            IRemoteFactory proxy = WinApplication.ServerProxy;
            Person         p     = proxy.GetPerson();

            TextResults.AppendText(
                string.Format("{0} {1}, {2}\r\n", p.Firstname, p.Lastname, p.Age));
        }
 public BuildsController(
     BuildAssetRegistryContext context,
     IBackgroundQueue queue,
     ISystemClock clock,
     IRemoteFactory factory)
     : base(context, clock)
 {
     Queue   = queue;
     Factory = factory;
 }
        private async Task <int> CoherencyUpdatesAsync(
            IRemote barOnlyRemote,
            IRemoteFactory remoteFactory,
            List <DependencyDetail> currentDependencies,
            List <DependencyDetail> dependenciesToUpdate)
        {
            Console.WriteLine("Checking for coherency updates...");

            CoherencyMode coherencyMode = CoherencyMode.Legacy;

            if (_options.StrictCoherency)
            {
                coherencyMode = CoherencyMode.Strict;
            }

            List <DependencyUpdate> coherencyUpdates = null;

            try
            {
                // Now run a coherency update based on the current set of dependencies updated
                // from the previous pass.
                coherencyUpdates = await barOnlyRemote.GetRequiredCoherencyUpdatesAsync(
                    currentDependencies, remoteFactory, coherencyMode);
            }
            catch (DarcCoherencyException e)
            {
                Console.WriteLine("Coherency updates failed for the following dependencies:");
                foreach (var error in e.Errors)
                {
                    Console.WriteLine($"  Unable to update {error.Dependency.Name} to have coherency with " +
                                      $"{error.Dependency.CoherentParentDependencyName}: {error.Error}");
                    foreach (string potentialSolution in error.PotentialSolutions)
                    {
                        Console.WriteLine($"    - {potentialSolution}");
                    }
                }
                return(Constants.ErrorCode);
            }

            foreach (DependencyUpdate dependencyUpdate in coherencyUpdates)
            {
                DependencyDetail from            = dependencyUpdate.From;
                DependencyDetail to              = dependencyUpdate.To;
                DependencyDetail coherencyParent = currentDependencies.First(d =>
                                                                             d.Name.Equals(from.CoherentParentDependencyName, StringComparison.OrdinalIgnoreCase));
                // Print out what we are going to do.
                Console.WriteLine($"Updating '{from.Name}': '{from.Version}' => '{to.Version}' " +
                                  $"to ensure coherency with {from.CoherentParentDependencyName}@{coherencyParent.Version}");

                // Final list of dependencies to update
                dependenciesToUpdate.Add(to);
            }

            return(Constants.SuccessCode);
        }
 public PullRequestPolicyFailureNotifier(
     IGitHubTokenProvider gitHubTokenProvider,
     IGitHubClientFactory gitHubClientFactory,
     IRemoteFactory darcFactory,
     ILogger <PullRequestPolicyFailureNotifier> logger)
 {
     Logger = logger;
     GitHubTokenProvider = gitHubTokenProvider;
     GitHubClientFactory = gitHubClientFactory;
     DarcRemoteFactory   = darcFactory;
 }
 public BuildsController(BuildAssetRegistryContext context,
                         IRemoteFactory factory,
                         IServiceScopeFactory serviceScopeFactory,
                         BackgroundQueue queue,
                         ILogger <BuildsController> logger)
     : base(context)
 {
     RemoteFactory       = factory;
     ServiceScopeFactory = serviceScopeFactory;
     Queue  = queue;
     Logger = logger;
 }
示例#15
0
        /// <summary>
        ///     Diff each node in the graph against the latest build in
        ///     the graph.
        /// </summary>
        /// <param name="remoteFactory"></param>
        /// <param name="logger"></param>
        /// <param name="nodeCache"></param>
        /// <param name="visitedRepoUriNodes"></param>
        /// <returns></returns>
        private static async Task DoLatestInGraphNodeDiffAsync(
            IRemoteFactory remoteFactory,
            ILogger logger,
            Dictionary <string, DependencyGraphNode> nodeCache,
            Dictionary <string, DependencyGraphNode> visitedRepoUriNodes)
        {
            logger.LogInformation("Running latest in graph node diff.");

            // Find the build of each repo in the graph, then
            // get the diff info from the latest
            foreach (string repo in visitedRepoUriNodes.Keys)
            {
                // Get all nodes with this value
                List <DependencyGraphNode> nodes = nodeCache.Values.Where(n => n.Repository == repo).ToList();
                // If only one, determine latest
                if (nodes.Count > 1)
                {
                    // Find latest
                    DependencyGraphNode newestNode = null;
                    Build newestBuild = null;
                    foreach (DependencyGraphNode node in nodes)
                    {
                        if (newestNode == null)
                        {
                            newestNode = node;
                            if (newestNode.ContributingBuilds.Any())
                            {
                                newestBuild = newestNode.ContributingBuilds.OrderByDescending(b => b.DateProduced).First();
                            }
                        }
                        else if (node.ContributingBuilds.Any(b => b.DateProduced > newestBuild?.DateProduced))
                        {
                            newestNode  = node;
                            newestBuild = newestNode.ContributingBuilds.OrderByDescending(b => b.DateProduced).First();
                        }
                    }

                    // Compare all other nodes to the latest
                    foreach (DependencyGraphNode node in nodes)
                    {
                        IRemote repoRemote = await remoteFactory.GetRemoteAsync(node.Repository, logger);

                        // If node == newestNode, returns no diff.
                        node.DiffFrom = await repoRemote.GitDiffAsync(node.Repository, newestNode.Commit, node.Commit);
                    }
                }
                else
                {
                    DependencyGraphNode singleNode = nodes.Single();
                    singleNode.DiffFrom = GitDiff.NoDiff(singleNode.Commit);
                }
            }
        }
示例#16
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("Configuring client...");
            RemotingConfiguration.Configure("ConsoleClient.exe.config");

            System.Console.WriteLine("Calling server 1...");
            IRemoteFactory factory = (IRemoteFactory)RemotingHelper.CreateProxy(typeof(IRemoteFactory));
            Person         p       = factory.GetPerson();

            System.Console.WriteLine(">> Person retrieved: {0} {1}, {2}", p.Firstname, p.Lastname, p.Age.ToString());
            System.Console.WriteLine();
        }
示例#17
0
        /// <summary>
        ///     Given a repo and branch, determine what updates are required to satisfy
        ///     coherency constraints.
        /// </summary>
        /// <param name="repoUri">Repository uri to check for updates in.</param>
        /// <param name="branch">Branch to check for updates in.</param>
        /// <param name="remoteFactory">Remote factory use in walking the repo dependency graph.</param>
        /// <returns>List of dependencies requiring updates (with updated info).</returns>
        public async Task <List <DependencyUpdate> > GetRequiredCoherencyUpdatesAsync(
            string repoUri,
            string branch,
            IRemoteFactory remoteFactory)
        {
            CheckForValidGitClient();
            _logger.LogInformation($"Determining required coherency updates in {repoUri}@{branch}...");

            IEnumerable <DependencyDetail> currentDependencies =
                await _fileManager.ParseVersionDetailsXmlAsync(repoUri, branch);

            return(await GetRequiredCoherencyUpdatesAsync(currentDependencies, remoteFactory));
        }
 public DependencyUpdater(
     IReliableStateManager stateManager,
     ILogger <DependencyUpdater> logger,
     BuildAssetRegistryContext context,
     IRemoteFactory factory,
     IActorProxyFactory <ISubscriptionActor> subscriptionActorFactory)
 {
     StateManager             = stateManager;
     Logger                   = logger;
     Context                  = context;
     RemoteFactory            = factory;
     SubscriptionActorFactory = subscriptionActorFactory;
 }
示例#19
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("Configuring client...");
            RemotingConfiguration.Configure("ConsoleClient.exe.config");

            System.Console.WriteLine("Creating proxy...");
            IRemoteFactory factory = (IRemoteFactory)RemotingHelper.CreateProxy(typeof(IRemoteFactory));

            System.Console.WriteLine("Calling UploadPerson()...");
            factory.UploadPerson(new Person("Test", "Upload", 24));
            System.Console.WriteLine(">> Upload called successfully!");

            System.Console.ReadLine();
        }
示例#20
0
        static void Main(string[] args)
        {
            String filename = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

            RemotingConfiguration.Configure(filename);

            IRemoteFactory fact = (IRemoteFactory)RemotingHelper.CreateProxy(typeof(IRemoteFactory));
            IRemoteObject  cao  = fact.CreateInstance();

            IRemoteSponsorFactory sf = (IRemoteSponsorFactory)RemotingHelper.CreateProxy(typeof(IRemoteSponsorFactory));
            InstanceSponsor       sp = sf.CreateSponsor();

            EnsureKeepAlive keepalive = new EnsureKeepAlive(sp);

            ILease le = (ILease)((MarshalByRefObject)cao).GetLifetimeService();

            le.Register(sp);

            try
            {
                Console.WriteLine("{0} CLIENT: Calling DoSomething()", DateTime.Now);
                cao.DoSomething();
            }
            catch (Exception e)
            {
                Console.WriteLine(" --> EX: Timeout in first call\n{0}", e.Message);
            }

            Console.WriteLine("{0} CLIENT: Sleeping for 6 seconds", DateTime.Now);
            Thread.Sleep(6000);

            try
            {
                Console.WriteLine("{0} CLIENT: Calling DoSomething()", DateTime.Now);
                cao.DoSomething();
            }
            catch (Exception e)
            {
                Console.WriteLine(" --> EX: Timeout in second call\n{0}", e.Message);
            }

            Console.WriteLine("{0} CLIENT: Unregistering sponsor", DateTime.Now);
            le.Unregister(sp);
            keepalive.StopKeepAlive();

            Console.WriteLine("Finished ... press <return> to exit");
            Console.ReadLine();
            Console.ReadLine();
        }
示例#21
0
        static void Main(string[] args)
        {
            HttpChannel channel = new HttpChannel();

            ChannelServices.RegisterChannel(channel);


            Console.WriteLine("Client.Main(): Creating factory");
            IRemoteFactory fact = (IRemoteFactory)Activator.GetObject(
                typeof(IRemoteFactory),
                "http://localhost:1235/factory.soap");

            IRemoteObject obj1 = fact.GetNewInstance();


            Console.WriteLine("Done");
            Console.ReadLine();
        }
示例#22
0
 /// <summary>
 ///     Builds a dependency graph given a root repo and commit using remotes.
 /// </summary>
 /// <param name="remoteFactory">Factory that can create remotes based on repo uris</param>
 /// <param name="repoUri">Root repository URI</param>
 /// <param name="commit">Root commit</param>
 /// <param name="options">Graph build options.</param>
 /// <param name="logger">Logger</param>
 /// <returns>New dependency graph.</returns>
 public static async Task <DependencyGraph> BuildRemoteDependencyGraphAsync(
     IRemoteFactory remoteFactory,
     string repoUri,
     string commit,
     DependencyGraphBuildOptions options,
     ILogger logger)
 {
     return(await BuildDependencyGraphImplAsync(
                remoteFactory,
                null, /* no initial root dependencies */
                repoUri,
                commit,
                options,
                true,
                logger,
                null,
                null,
                null));
 }
示例#23
0
        /// <summary>
        ///     Validate that the graph build options are correct.
        /// </summary>
        /// <param name="remoteFactory"></param>
        /// <param name="rootDependencies"></param>
        /// <param name="repoUri"></param>
        /// <param name="commit"></param>
        /// <param name="options"></param>
        /// <param name="remote"></param>
        /// <param name="logger"></param>
        /// <param name="reposFolder"></param>
        /// <param name="remotesMap"></param>
        /// <param name="testPath"></param>
        private static void ValidateBuildOptions(
            IRemoteFactory remoteFactory,
            IEnumerable <DependencyDetail> rootDependencies,
            string repoUri,
            string commit,
            DependencyGraphBuildOptions options,
            bool remote,
            ILogger logger,
            string reposFolder,
            IEnumerable <string> remotesMap,
            string testPath)
        {
            // Fail fast if darcSettings is null in a remote scenario
            if (remote && remoteFactory == null)
            {
                throw new DarcException("Remote graph build requires a remote factory.");
            }

            if (rootDependencies != null && !rootDependencies.Any())
            {
                throw new DarcException("Root dependencies were not supplied.");
            }

            if (!remote)
            {
                if (options.LookupBuilds)
                {
                    throw new DarcException("Build lookup only available in remote build mode.");
                }
                if (options.NodeDiff != NodeDiff.None)
                {
                    throw new DarcException($"Node diff type '{options.NodeDiff}' only available in remote build mode.");
                }
            }
            else
            {
                if (options.NodeDiff != NodeDiff.None && !options.LookupBuilds)
                {
                    throw new DarcException("Node diff requires build lookup.");
                }
            }
        }
示例#24
0
 /// <summary>
 ///     Builds a dependency graph given a root repo and commit.
 /// </summary>
 /// <param name="remoteFactory">Factory that can create remotes based on repo uris</param>
 /// <param name="rootDependencies">Root set of dependencies</param>
 /// <param name="repoUri">Root repository URI</param>
 /// <param name="commit">Root commit</param>
 /// <param name="options">Graph build options.</param>
 /// <param name="logger">Logger</param>
 /// <returns>New dependency graph.</returns>
 public static async Task <DependencyGraph> BuildRemoteDependencyGraphAsync(
     IRemoteFactory remoteFactory,
     IEnumerable <DependencyDetail> rootDependencies,
     string repoUri,
     string commit,
     DependencyGraphBuildOptions options,
     ILogger logger)
 {
     return(await BuildDependencyGraphImplAsync(
                remoteFactory,
                rootDependencies,
                repoUri,
                commit,
                options,
                true,
                logger,
                null,
                null,
                null));
 }
示例#25
0
 protected PullRequestActorImplementation(
     ActorId id,
     IReminderManager reminders,
     IActorStateManager stateManager,
     IMergePolicyEvaluator mergePolicyEvaluator,
     BuildAssetRegistryContext context,
     IRemoteFactory darcFactory,
     ILoggerFactory loggerFactory,
     IActionRunner actionRunner,
     Func <ActorId, ISubscriptionActor> subscriptionActorFactory)
 {
     Id                       = id;
     Reminders                = reminders;
     StateManager             = stateManager;
     MergePolicyEvaluator     = mergePolicyEvaluator;
     Context                  = context;
     DarcRemoteFactory        = darcFactory;
     ActionRunner             = actionRunner;
     SubscriptionActorFactory = subscriptionActorFactory;
     Logger                   = loggerFactory.CreateLogger(TypeNameHelper.GetTypeDisplayName(GetType()));
 }
示例#26
0
        static void Main(string[] args)
        {
            Console.WriteLine("Configuring client...");
            RemotingConfiguration.Configure("ConsoleClient.exe.config");

            Console.WriteLine("Creating proxy...");
            IRemoteFactory factory = (IRemoteFactory)RemotingHelper.CreateProxy(typeof(IRemoteFactory));

            Console.WriteLine("Calling GetAge()...");
            int age = factory.GetAge();

            Console.WriteLine(">> Call successful: " + age.ToString());

            Console.WriteLine("Calling GetPerson()...");
            Person p = factory.GetPerson();

            Console.WriteLine(">> Person retrieved: {0} {1}, {2}", p.Firstname, p.Lastname, p.Age.ToString());

            Console.WriteLine("Calling UploadPerson()...");
            factory.UploadPerson(new Person("Upload", "Test", 20));
            Console.WriteLine(">> Upload called successfully!");

            Console.ReadLine();
        }
示例#27
0
        static void Main(string[] args)
        {
            HttpChannel channel = new HttpChannel();

            ChannelServices.RegisterChannel(channel);

            Console.WriteLine("Client.Main(): Creating factory");
            IRemoteFactory fact = (IRemoteFactory)Activator.GetObject(
                typeof(IRemoteFactory),
                "http://localhost:1234/factory.soap");

            Console.WriteLine("Client.Main(): Acquiring first object from factory");
            IRemoteObject obj1 = fact.getNewInstance();

            obj1.setValue(42);

            Console.WriteLine("Client.Main(): Acquiring second object from factory");
            IRemoteObject obj2 = fact.getNewInstance(4711);

            Console.WriteLine("Obj1.getValue(): {0}", obj1.getValue());
            Console.WriteLine("Obj2.getValue(): {0}", obj2.getValue());

            Console.ReadLine();
        }
示例#28
0
        static void Main(string[] args)
        {
            String filename = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

            RemotingConfiguration.Configure(filename);

            IRemoteFactory fact = (IRemoteFactory)RemotingHelper.CreateProxy(typeof(IRemoteFactory));
            IRemoteObject  cao  = fact.CreateInstance();

            try
            {
                Console.WriteLine("{0} CLIENT: Calling doSomething()", DateTime.Now);
                cao.DoSomething();
            }
            catch (Exception e)
            {
                Console.WriteLine(" --> EX: Timeout in first call\n{0}", e.Message);
            }

            Console.WriteLine("{0} CLIENT: Sleeping for 5 seconds", DateTime.Now);
            Thread.Sleep(5000);

            try
            {
                Console.WriteLine("{0} CLIENT: Calling doSomething()", DateTime.Now);
                cao.DoSomething();
            }
            catch (Exception e)
            {
                Console.WriteLine(" --> EX: Timeout in second call\n{0}", e.Message);
            }

            Console.WriteLine("Finished ... press <return> to exit");
            Console.ReadLine();
            Console.ReadLine();
        }
示例#29
0
        private async Task <int> CoherencyUpdatesAsync(
            IRemote barOnlyRemote,
            IRemoteFactory remoteFactory,
            List <DependencyDetail> currentDependencies,
            List <DependencyDetail> dependenciesToUpdate)
        {
            Console.WriteLine("Checking for coherency updates...");

            CoherencyMode coherencyMode = CoherencyMode.Strict;

            if (_options.LegacyCoherency)
            {
                coherencyMode = CoherencyMode.Legacy;
            }
            else
            {
                Console.WriteLine("Using 'Strict' coherency mode. If this fails, a second attempt utilizing 'Legacy' Coherency mode will be made.");
            }

            List <DependencyUpdate> coherencyUpdates = null;
            bool updateSucceeded = false;

            try
            {
                // Now run a coherency update based on the current set of dependencies updated from the previous pass.
                coherencyUpdates = await barOnlyRemote.GetRequiredCoherencyUpdatesAsync(currentDependencies, remoteFactory, coherencyMode);

                updateSucceeded = true;
            }
            catch (DarcCoherencyException e)
            {
                PrettyPrintCoherencyErrors(e);
            }

            if (coherencyMode == CoherencyMode.Strict && !updateSucceeded)
            {
                Console.WriteLine("Attempting fallback to Legacy coherency");
                try
                {
                    // Now run a coherency update based on the current set of dependencies updated from the previous pass.
                    coherencyUpdates = await barOnlyRemote.GetRequiredCoherencyUpdatesAsync(currentDependencies, remoteFactory, CoherencyMode.Legacy);

                    Console.WriteLine("... Legacy-mode fallback worked");
                    updateSucceeded = true;
                }
                catch (DarcCoherencyException e)
                {
                    PrettyPrintCoherencyErrors(e);
                }
            }
            if (!updateSucceeded)
            {
                return(Constants.ErrorCode);
            }

            foreach (DependencyUpdate dependencyUpdate in coherencyUpdates)
            {
                DependencyDetail from            = dependencyUpdate.From;
                DependencyDetail to              = dependencyUpdate.To;
                DependencyDetail coherencyParent = currentDependencies.First(d =>
                                                                             d.Name.Equals(from.CoherentParentDependencyName, StringComparison.OrdinalIgnoreCase));
                // Print out what we are going to do.
                Console.WriteLine($"Updating '{from.Name}': '{from.Version}' => '{to.Version}' " +
                                  $"to ensure coherency with {from.CoherentParentDependencyName}@{coherencyParent.Version}");

                // Final list of dependencies to update
                dependenciesToUpdate.Add(to);
            }

            return(Constants.SuccessCode);
        }
示例#30
0
        /// <summary>
        ///     Updates existing dependencies in the dependency files
        /// </summary>
        /// <param name="dependencies">Dependencies that need updates.</param>
        /// <param name="remote">Remote instance for gathering eng/common script updates.</param>
        /// <returns></returns>
        public async Task UpdateDependenciesAsync(List <DependencyDetail> dependencies, IRemoteFactory remoteFactory)
        {
            // TODO: This should use known updaters, but today the updaters for global.json can only
            // add, not actually update.  This needs a fix. https://github.com/dotnet/arcade/issues/1095

            /*List<DependencyDetail> defaultUpdates = new List<DependencyDetail>(, IRemote remote);
             * foreach (DependencyDetail dependency in dependencies)
             * {
             *  if (DependencyOperations.TryGetKnownUpdater(dependency.Name, out Delegate function))
             *  {
             *      await (Task)function.DynamicInvoke(_fileManager, _repo, dependency);
             *  }
             *  else
             *  {
             *      defaultUpdates.Add(dependency);
             *  }
             * }*/

            var fileContainer = await _fileManager.UpdateDependencyFiles(dependencies, _repo, null);

            List <GitFile> filesToUpdate = fileContainer.GetFilesToCommit();

            // TODO: This needs to be moved into some consistent handling between local/remote and add/update:
            // https://github.com/dotnet/arcade/issues/1095
            // If we are updating the arcade sdk we need to update the eng/common files as well
            DependencyDetail arcadeItem = dependencies.FirstOrDefault(
                i => string.Equals(i.Name, "Microsoft.DotNet.Arcade.Sdk", StringComparison.OrdinalIgnoreCase));

            if (arcadeItem != null)
            {
                try
                {
                    IRemote remote = await remoteFactory.GetRemoteAsync(arcadeItem.RepoUri, _logger);

                    List <GitFile> engCommonFiles = await remote.GetCommonScriptFilesAsync(arcadeItem.RepoUri, arcadeItem.Commit);

                    filesToUpdate.AddRange(engCommonFiles);

                    List <GitFile> localEngCommonFiles = await _gitClient.GetFilesAtCommitAsync(null, null, "eng/common");

                    foreach (GitFile file in localEngCommonFiles)
                    {
                        if (!engCommonFiles.Where(f => f.FilePath == file.FilePath).Any())
                        {
                            file.Operation = GitFileOperation.Delete;
                            filesToUpdate.Add(file);
                        }
                    }
                }
                catch (Exception exc) when
                    (exc.Message == "Not Found")
                {
                    _logger.LogWarning("Could not update 'eng/common'. Most likely this is a scenario " +
                                       "where a packages folder was passed and the commit which generated them is not " +
                                       "yet pushed.");
                }
            }

            // Push on local does not commit.
            await _gitClient.CommitFilesAsync(filesToUpdate, _repo, null, null);
        }