Example #1
0
        public async Task <ScenarioStatisticsRegistration> GetRegistrationInfo(ScenarioBase[] scenarios)
        {
            var result = new ScenarioStatisticsRegistration();

            var targetIds = _statisticsScenariosInfos
                            .Where(x => scenarios.Any(z => z.Id == x.ScenarioId))
                            .Select(x => x.ScenarioId)
                            .ToArray();

            result.Union(new ScenarioStatisticsRegistration(targetIds));

            // For remote scenarios

            if (scenarios.Length == 1 && targetIds.Length == 1)
            {
                return(result);
            }

            var remoteScenariosGroups = scenarios
                                        .OfType <RemoteScenario>()
                                        .GroupBy(x => x.Credentials)
                                        .ToArray();

            foreach (var group in remoteScenariosGroups)
            {
                result.Union(await GetRegistrationInfoInternal(group.ToArray()));
            }

            // End -- for remote scenarios

            return(result);
        }
Example #2
0
        public ScenarioStatisticsRegistration GetRegistrationInfo(ScenarioBase[] scenarios)
        {
            var result = new ScenarioStatisticsRegistration();

            //for remote scenarios

            var remoteScenariosGroups = scenarios
                                        .OfType <RemoteScenario>()
                                        .GroupBy(x => x.Credentials)
                                        .ToArray();

            foreach (var group in remoteScenariosGroups)
            {
                result.Union(GetRegistrationInfoInternal(group.ToArray()));
            }

            //end -- for remote scenarios

            var targetIds = _statisticsScenariosInfos
                            .Where(x => scenarios.Any(z => z.Id == x.ScenarioId))
                            .Select(x => x.ScenarioId)
                            .ToArray();

            result.Union(new ScenarioStatisticsRegistration(targetIds));

            return(result);
        }
Example #3
0
        private async Task <ScenarioStatisticsRegistration> GetRegistrationInfoInternal(RemoteScenario[] scenarios) // Only for equals credentials
        {
            if (!scenarios.Any())
            {
                return(new ScenarioStatisticsRegistration());
            }

            try
            {
                // Connection of first scenario is equals to other scenarios
                var firstScenario = scenarios.FirstOrDefault();
                if (!firstScenario.GetIsAvailable())
                {
                    throw new InvalidOperationException("Scenarios is unavailable");
                }

                var remoteScenariosInfo = scenarios.ToDictionary(x => x.RemoteScenarioId);
                var credentials         = firstScenario.Credentials;
                var client       = ServiceClientFactory.Current.GetClient(credentials);
                var remoteResult = await client.GetStatisticsRegistration(remoteScenariosInfo.Select(x => x.Value.RemoteScenarioId).ToArray());

                var result = new ScenarioStatisticsRegistration(remoteResult.RegisteredIds.Select(x => remoteScenariosInfo[x].Id).ToArray());

                return(result);
            }
            catch (Exception e)
            {
                // Connection failed
                Log.Debug($"Error while get scenario statistic registration info", e);
                return(new ScenarioStatisticsRegistration());
            }
        }
Example #4
0
        private ScenarioStatisticsRegistration GetRegistrationInfoInternal(RemoteScenario[] scenarios) //only for equals credentials
        {
            if (!scenarios.Any())
            {
                return(new ScenarioStatisticsRegistration());
            }

            try
            {
                var creds = scenarios.First().Credentials;

                var remoteScenariosInfo = scenarios.ToDictionary(x => x.RemoteScenarioId);

                var server = ClientFactory.GetServer(creds);

                var remoteResult = server
                                   .GetStatisticsRegistration(
                    new EncryptedList <string>(remoteScenariosInfo.Select(x => x.Value.RemoteScenarioId), creds.SecretKey))
                                   .Decrypt(creds.SecretKey);

                var result = new ScenarioStatisticsRegistration(
                    remoteResult.RegisteredIds.Select(x => remoteScenariosInfo[x].Id).ToArray());

                return(result);
            }
            catch
            {
                //connection failed
                return(new ScenarioStatisticsRegistration());
            }
        }