示例#1
0
        public override void EvaluateInternal(H holder, MemberInfo groupKey)
        {
            // вычисляем все переменные, от которой зависит данная переменная
            foreach (MetaVariable <H, I> vd in DependsOn)
            {
                vd.Evaluate(holder, groupKey, LastMoniker);
            }

            // для каждого периода времени вычисляем значение переменной
            foreach (var tp in Period.Periods.Select((t, i) => new TimeArg <I>(t, i, groupKey, Period.Name, this.Name)))
            {
                T result;
                // выставляем в holder значения мета-переменных от которых зависит данная переменная
                foreach (MetaVariable <H, I> vd in DependsOn)
                {
                    vd.ApplyValueForHolder(holder, tp);
                }
                // вычисляем новое значение и заносим его в Results
                result = CompiledWriter(tp);
                Results.Add(tp, result);
                // если требуется вернуть значение переменной, то записываем результат в мета-переменную
                // holder содержить набор значений всех переменных на момент времени t
                if (Readers.Any())
                {
                    ApplyValueForHolder(holder, tp);
                    ExecuteAllReaders(tp);
                }
            }
        }
示例#2
0
        /// <remarks>Throws <see cref="InvalidDiscoveryException"/> if the discovery result is invalid.</remarks>
        public void Rediscovery()
        {
            using (var session = new Session(_conn, _logger))
            {
                var result = session.Run($"CALL {ProcedureName}");
                var record = result.Single();
                // TODO require an IT to make sure List or IList, Dictionary or IDictionary
                foreach (var servers in record["servers"].As <List <Dictionary <string, object> > >())
                {
                    var addresses = servers["addresses"].As <List <string> >();
                    var role      = servers["role"].As <string>();
                    switch (role)
                    {
                    case "READ":
                        Readers = addresses.Select(BoltRoutingUri).ToArray();
                        break;

                    case "WRITE":
                        Writers = addresses.Select(BoltRoutingUri).ToArray();
                        break;

                    case "ROUTE":
                        Routers = addresses.Select(BoltRoutingUri).ToArray();
                        break;
                    }
                }
                ExpireAfterSeconds = record["ttl"].As <long>();
            }
            if (!Readers.Any() || !Writers.Any() || !Routers.Any())
            {
                throw new InvalidDiscoveryException(
                          $"Invalid discovery result: discovered {Routers.Count()} routers, " +
                          $"{Writers.Count()} writers and {Readers.Count()} readers. A Redisvoery is required.");
            }
        }
        public override void EvaluateInternal(H holder, MemberInfo groupKey)
        {
            // вычисляем переменную из котрой следует получить значения
            CalculatedVariable <H, T, I> basedVar = (CalculatedVariable <H, T, I>)DependsOn.Single();

            // check basedVar.Period == this.Period; (они должны совпадать)
            basedVar.Evaluate(holder, groupKey, LastMoniker);

            var periods = Period.Periods.Select((t, i) => new TimeArg <I>(t, i, groupKey, Period.Name, this.Name));

            if (Shift >= 0)
            {
                ShiftData(basedVar, periods, Shift);
            }
            else
            {
                var p2 = Period.Periods.Reverse().Select((t, i) => new TimeArg <I>(t, i, groupKey, Period.Name, this.Name));
                ShiftData(basedVar, p2, -Shift);
            }

            foreach (var tp in periods)
            {
                if (Readers.Any())
                {
                    ApplyValueForHolder(holder, tp);
                    ExecuteAllReaders(tp);
                }
            }
        }
示例#4
0
        public override void EvaluateInternal(H holder, MemberInfo groupKey)
        {
            // вычисляем переменную из котрой следует получить значения
            CalculatedVariable <H, T, I> basedVar = (CalculatedVariable <H, T, I>)DependsOn.Single();

            basedVar.Evaluate(holder, groupKey, LastMoniker);

            // для каждого периода времени вычисляем значение переменной
            foreach (var tp in Period.Periods.Select((t, i) => new TimeArg <I>(t, i, groupKey, Period.Name, this.Name)))
            {
                I        next      = Period.Periods.FirstOrDefault(p => Operator.GreaterThan(p, tp.T));
                var      subPeriod = basedVar.Period.Between(tp.T, next);
                List <T> result    = Activator.CreateInstance <List <T> >();
                Int32    c         = 0;
                foreach (I s in subPeriod)
                {
                    var ta = new TimeArg <I>(s, c++, groupKey, basedVar.Period.Name, basedVar.Name);
                    result.Add((T)basedVar.Results[ta]);
                }

                Results.Add(tp, result);
                // если требуется вернуть значение переменной, то записываем результат в свойство
                // holder, это свойство будет содержить список значений всех переменных на момент времени t
                if (Readers.Any())
                {
                    ApplyValueForHolder(holder, tp);
                    ExecuteAllReaders(tp);
                }
            }
        }
示例#5
0
        public override void EvaluateInternal(H holder, MemberInfo groupKey)
        {
            // вычисляем переменную из котрой следует получить значения
            CalculatedVariable <H, T, I> basedVar = (CalculatedVariable <H, T, I>)DependsOn.Single();

            // вычислять не требуется, т.к. переменная должна быть уже вычислена в более глубокой группе

            // для каждого периода времени вычисляем значение переменной
            foreach (var tp in Period.Periods.Select((t, i) => new TimeArg <I>(t, i, groupKey, Period.Name, this.Name)))
            {
                Dictionary <K, T> result = Activator.CreateInstance <Dictionary <K, T> >();
                //foreach (var p in basedVar.Results.Where(pair => pair.Key.T == tp.T && pair.Key.ForMember.ParentMember == groupKey))
                foreach (var p in basedVar.Results.Where(pair => Operator.Equal(pair.Key.T, tp.T) && pair.Key.ForGroupMember.Parents.Contains(groupKey)))
                {
                    result.Add((K)p.Key.GroupKey, p.Value);
                }

                Results.Add(tp, result);
                // если требуется вернуть значение переменной, то записываем результат в свойство
                // holder, это свойство будет содержить список значений всех переменных на момент времени t
                if (Readers.Any())
                {
                    ApplyValueForHolder(holder, tp);
                    ExecuteAllReaders(tp);
                }
            }
        }
 void ISecureConfigurationStore.AllowAccessFrom(IHaveServiceIdentity serviceIdentity)
 {
     if (Readers.Any(r => r.Id == serviceIdentity.Id))
     {
         return;
     }
     Readers.Add(serviceIdentity);
 }
        /// <remarks>Throws <see cref="ProtocolException"/> if the discovery result is invalid.</remarks>
        /// <remarks>Throws <see cref="ServiceUnavailableException"/> if the no discovery procedure could be found in the server.</remarks>
        public void Rediscovery()
        {
            try
            {
                using (var provider = new SingleConnectionBasedConnectionProvider(_conn))
                    using (var session = new Session(provider, _logger))
                    {
                        var result = session.Run(DiscoveryProcedure);
                        var record = result.Single();

                        foreach (var servers in record["servers"].As <List <Dictionary <string, object> > >())
                        {
                            var addresses = servers["addresses"].As <List <string> >();
                            var role      = servers["role"].As <string>();
                            switch (role)
                            {
                            case "READ":
                                Readers = addresses.Select(BoltRoutingUri).ToArray();
                                break;

                            case "WRITE":
                                Writers = addresses.Select(BoltRoutingUri).ToArray();
                                break;

                            case "ROUTE":
                                Routers = addresses.Select(BoltRoutingUri).ToArray();
                                break;
                            }
                        }
                        ExpireAfterSeconds = record["ttl"].As <long>();
                    }
            }
            catch (ClientException e)
            {
                throw new ServiceUnavailableException(
                          $"Error when calling `getServers` procedure: {e.Message}. " +
                          "Please make sure that there is a Neo4j 3.1+ causal cluster up running.", e);
            }
            catch (Exception e)
            {
                // for any reason we failed to do a discovery
                throw new ProtocolException(
                          $"Error when parsing `getServers` result: {e.Message}.");
            }

            if (!Readers.Any() || !Routers.Any())
            {
                throw new ProtocolException(
                          $"Invalid discovery result: discovered {Routers.Count()} routers, " +
                          $"{Writers.Count()} writers and {Readers.Count()} readers.");
            }
        }
示例#8
0
        public async Task RediscoveryAsync()
        {
            var provider = new SingleConnectionBasedConnectionProvider(_conn);
            var session  = new Session(provider, _logger);

            try
            {
                var result = await session.RunAsync(DiscoveryProcedure).ConfigureAwait(false);

                var record = await result.SingleAsync().ConfigureAwait(false);

                ParseDiscoveryResult(record);
            }
            catch (Exception e)
            {
                HandleDiscoveryException(e);
            }
            finally
            {
                try
                {
                    await session.CloseAsync().ConfigureAwait(false);
                }
                catch (Exception)
                {
                    // ignore any exception
                }
                await provider.CloseAsync().ConfigureAwait(false);
            }

            if (!Readers.Any() || !Routers.Any())
            {
                throw new ProtocolException(
                          $"Invalid discovery result: discovered {Routers.Count()} routers, " +
                          $"{Writers.Count()} writers and {Readers.Count()} readers.");
            }
        }
示例#9
0
        /// <remarks>Throws <see cref="ProtocolException"/> if the discovery result is invalid.</remarks>
        /// <remarks>Throws <see cref="ServiceUnavailableException"/> if the no discovery procedure could be found in the server.</remarks>
        public void Rediscovery()
        {
            try
            {
                using (var provider = new SingleConnectionBasedConnectionProvider(_conn))
                    using (var session = new Session(provider, _logger))
                    {
                        var result = session.Run(DiscoveryProcedure);
                        var record = result.Single();
                        ParseDiscoveryResult(record);
                    }
            }
            catch (Exception e)
            {
                HandleDiscoveryException(e);
            }

            if (!Readers.Any() || !Routers.Any())
            {
                throw new ProtocolException(
                          $"Invalid discovery result: discovered {Routers.Count()} routers, " +
                          $"{Writers.Count()} writers and {Readers.Count()} readers.");
            }
        }
示例#10
0
        public override void WriteYaml(StreamWriter writer, AssetManager assetManager, ILoggerFactory loggerFactory,
                                       int indent = 0)
        {
            var spaces = "".PadLeft(indent);

            writer.Write($"{spaces}aks:\n");
            spaces = "".PadLeft(indent + 2);
            writer.Write($"{spaces}clusterName: {ClusterName}\n");
            writer.Write($"{spaces}dnsPrefix: {DnsPrefix}\n");
            writer.Write($"{spaces}version: {Version}\n");
            writer.Write($"{spaces}vmSize: {VmSize}\n");
            writer.Write($"{spaces}nodeCount: {NodeCount}\n");
            writer.Write($"{spaces}ownerUpn: {AksOwnerAadUpn}\n");

            writer.Write($"{spaces}access:\n");

            if (Readers?.Any() == true)
            {
                spaces = "".PadLeft(indent + 4);
                writer.Write($"{spaces}readers:");

                spaces = "".PadLeft(indent + 6);
                foreach (var aadIdentity in Readers)
                {
                    writer.Write($"{spaces}name: {aadIdentity.Name}\n");
                    writer.Write($"{spaces}type: {aadIdentity.Type}\n");
                }
            }

            if (Contributors?.Any() == true)
            {
                spaces = "".PadLeft(indent + 4);
                writer.Write($"{spaces}contributors:");

                spaces = "".PadLeft(indent + 6);
                foreach (var aadIdentity in Contributors)
                {
                    writer.Write($"{spaces}name: {aadIdentity.Name}\n");
                    writer.Write($"{spaces}type: {aadIdentity.Type}\n");
                }
            }

            if (Owners?.Any() == true)
            {
                spaces = "".PadLeft(indent + 4);
                writer.Write($"{spaces}owners:");

                spaces = "".PadLeft(indent + 6);
                foreach (var aadIdentity in Owners)
                {
                    writer.Write($"{spaces}name: {aadIdentity.Name}\n");
                    writer.Write($"{spaces}type: {aadIdentity.Type}\n");
                }
            }

            spaces = "".PadLeft(indent + 2);
            writer.Write($"{spaces}useDevSpaces: {UseDevSpaces}\n");
            writer.Write($"{spaces}useTerraform: {UseTerraform}\n");
            writer.Write($"{spaces}useIstio: {UseIstio}\n");
            writer.Write($"{spaces}useCertManager: {UseCertManager}\n");

            if (KeyVaultAccess?.Any() == true)
            {
                spaces = "".PadLeft(indent + 2);
                writer.Write($"{spaces}keyVaultAccess:\n");

                foreach (var option in KeyVaultAccess)
                {
                    spaces = "".PadLeft(indent + 4);
                    writer.Write($"{spaces}- {option}\n");
                }
            }

            if (Metrics?.Any() == true)
            {
                spaces = "".PadLeft(indent + 2);
                writer.Write($"{spaces}metrics:\n");

                foreach (var option in Metrics)
                {
                    spaces = "".PadLeft(indent + 4);
                    writer.Write($"{spaces}- {option}\n");
                }
            }

            if (Logging?.Any() == true)
            {
                spaces = "".PadLeft(indent + 2);
                writer.Write($"{spaces}logging:\n");

                foreach (var option in Logging)
                {
                    spaces = "".PadLeft(indent + 4);
                    writer.Write($"{spaces}- {option}\n");
                }
            }

            if (Tracing?.Any() == true)
            {
                spaces = "".PadLeft(indent + 2);
                writer.Write($"{spaces}tracing:\n");

                foreach (var option in Tracing)
                {
                    spaces = "".PadLeft(indent + 4);
                    writer.Write($"{spaces}- {option}\n");
                }
            }

            if (Ingress?.Any() == true)
            {
                spaces = "".PadLeft(indent + 2);
                writer.Write($"{spaces}ingress:\n");

                foreach (var option in Ingress)
                {
                    spaces = "".PadLeft(indent + 4);
                    writer.Write($"{spaces}- {option}\n");
                }
            }

            if (Certs?.Any() == true)
            {
                spaces = "".PadLeft(indent + 2);
                writer.Write($"{spaces}certs:\n");

                foreach (var cert in Certs)
                {
                    spaces = "".PadLeft(indent + 4);
                    writer.Write($"{spaces}- name: {cert.Name}\n");
                    if (!string.IsNullOrEmpty(cert.Type))
                    {
                        writer.Write($"{spaces}  type: {cert.Type}\n");
                    }
                }
            }

            if (Secrets != null)
            {
                spaces = "".PadLeft(indent + 2);
                writer.Write($"{spaces}secrets:\n");

                spaces = "".PadLeft(indent + 4);
                writer.Write($"{spaces}addContainerRegistryAccess: {Secrets.AddContainerRegistryAccess}\n");
                writer.Write($"{spaces}addKeyVaultAccess: {Secrets.AddKeyVaultAccess}\n");
                writer.Write($"{spaces}addAppInsightsKey: {Secrets.AddAppInsightsKey}\n");
            }
        }