예제 #1
0
        /// <summary>
        /// Sets one or more security and/or resource policies to an empty job.
        /// </summary>
        /// <returns>
        ///    <list type="bullet">
        ///    <item>
        ///      <term>ErrInvalidArgs</term>
        ///      <description>
        ///        policy was not a valid pointer, or count was 0, or policy was not ZX_JOB_POL_RELATIVE or ZX_JOB_POL_ABSOLUTE, or topic was not ZX_JOB_POL_BASIC.
        ///      </description>
        ///    </item>
        ///    <item>
        ///      <term>ErrBadHandle</term>
        ///      <description>
        ///        handle is not valid handle.
        ///      </description>
        ///    </item>
        ///    <item>
        ///      <term>ErrWrongType</term>
        ///      <description>
        ///        handle is not a job handle.
        ///      </description>
        ///    </item>
        ///    <item>
        ///      <term>ErrAccessDenied</term>
        ///      <description>
        ///        handle does not have ZX_POL_RIGHT_SET right.
        ///      </description>
        ///    </item>
        ///    <item>
        ///      <term>ErrBadState</term>
        ///      <description>
        ///        the job has existing jobs or processes alive.
        ///      </description>
        ///    </item>
        ///    <item>
        ///      <term>ErrOutOfRange</term>
        ///      <description>
        ///        count is bigger than ZX_POL_MAX or condition is bigger than ZX_POL_MAX.
        ///      </description>
        ///    </item>
        ///    <item>
        ///      <term>ErrAlreadyExists</term>
        ///      <description>
        ///        existing policy conflicts with the new policy.
        ///      </description>
        ///    </item>
        ///    <item>
        ///      <term>ErrNotSupported</term>
        ///      <description>
        ///        an entry in policy has an invalid value.
        ///      </description>
        ///    </item>
        ///    <item>
        ///      <term>ErrNoMemory</term>
        ///      <description>
        ///        Failure due to lack of memory. There is no good way for userspace to handle this (unlikely) error. In a future build this error will no longer occur.
        ///      </description>
        ///    </item>
        /// </list>
        /// </returns>
        /// <param name="options">Options.</param>
        /// <param name="policy">Policy.</param>
        /// <remarks>
        /// <para>The job‘s effective policies is the combination of the parent’s effective policies and the policies specified in policy.
        /// The effect in the case of conflict between the existing policies and the new policies is controlled by options values
        /// </para>
        /// <para>
        /// After this call succeeds any new child process or child job will have the new effective policy applied to it.
        /// </para>
        /// </remarks>
        public ZxStatus job_set_policy(PolicyOption options, BasicPolicy [] policy)
        {
            if (policy == null)
            {
                throw new ArgumentNullException(nameof(policy));
            }

            return(zx_job_set_policy((uint)handle, options, ZX_JOB_POL_BASIC, policy, (uint)policy.Length));
        }
예제 #2
0
    void OpenDialog()
    {
        dialogGameObject.SetActive(true);
        dialogDarkenBgGameObject.SetActive(true);
        dialogOpen = true;

        //Create the options
        List <Policy> presentedOptions = new List <Policy>();


        for (int i = 0; i < optionCount; i++)
        {
            Policy option = policies[Random.Range(0, policies.Count)];
            if (presentedOptions.Contains(option))
            {
                //Try to find a different option
                i--;
                continue;
            }
            else
            {
                presentedOptions.Add(option);
            }
        }

        //Display them on the UI
        foreach (Policy policy in presentedOptions)
        {
            PolicyOption policyOption = Instantiate(policyOptionPrefab, policyOptionsListGameObject.transform).GetComponent <PolicyOption>();

            policyOption.icon.sprite      = policy.icon;
            policyOption.title.text       = policy.name;
            policyOption.description.text = policy.description;

            policyOption.money.text  = policy.money.ToString();
            policyOption.money.color = GetEffectColor(policy.money);

            policyOption.earningRate.text  = policy.earningRate.ToString("+#;-#;0");
            policyOption.earningRate.color = GetEffectColor(policy.earningRate);

            policyOption.satisfaction.text  = policy.satisfaction.ToString("+#;-#;0");
            policyOption.satisfaction.color = GetEffectColor(policy.satisfaction);

            policyOption.emissionsClean.text  = policy.emissionsClean.ToString("+#;-#;0");
            policyOption.emissionsClean.color = GetEffectColor(policy.emissionsClean);

            policyOption.emissionsDirty.text  = policy.emissionsDirty.ToString("+#;-#;0");
            policyOption.emissionsDirty.color = GetEffectColor(policy.emissionsDirty, true);

            policyOption.requiredSatisfaction.text = policy.requiredSatisfaction.ToString();
            policyOption.bribeCost.text            = policy.bribeCost.ToString();

            policyOption.propose.onClick.AddListener(() => { Propose(policy); });
            policyOption.bribe.onClick.AddListener(() => { Bribe(policy); });
        }
    }
예제 #3
0
        protected void CreatePolicyOptionDto(Policy pol, PolicyDTO dto)
        {
            PolicyOption option = pol.Option;

            dto.Option = new PolicyOptionDTO()
            {
                AnnualPremium = option.AnnualPremium,
                Code          = option.Code,
                Description   = option.Description,
                Excess        = option.Excess,
                AgreedValue   = option.AgreedValue
            };
        }
        public override async Task <PolicyOption> CalculatePolicyOption(Policy policy)
        {
            PolicyOption       result;
            List <CoverOption> coverOptions;

            using (InsuranceDbContext context = ContextFactory.CreateContext())
            {
                coverOptions = await context.CoverOptions.OrderBy(x => x.MinimumAgreedValue).ToListAsync();
            }

            if (policy.Option == null)
            {
                //
                // Create a new option
                //
                result = new PolicyOption();

                CoverOption firstOption = coverOptions.First();

                result.Code        = firstOption.Code;
                result.Description = firstOption.Description;
                result.AgreedValue = firstOption.MinimumAgreedValue.ToString(CultureInfo.InvariantCulture);
                result.Excess      = firstOption.Excess;
                result.CreatedAt   = DateTime.UtcNow;
            }
            else
            {
                //
                // Keep the object and just recaclulate the premium
                //
                result = policy.Option;
            }

            decimal agreedValue = Convert.ToDecimal(result.AgreedValue);

            CoverOption matchingCover = coverOptions.FirstOrDefault(x => x.MinimumAgreedValue <= agreedValue && x.MaximumAgreedValue >= agreedValue);

            if (matchingCover == null)
            {
                throw new BadRequestException("Unable to determine annual premium");
            }

            result.Code          = matchingCover.Code;
            result.Description   = matchingCover.Description;
            result.AnnualPremium = matchingCover.AnnualPremium;

            return(result);
        }
예제 #5
0
 private PolicyOption CreatePolicyOptionFromCoverOption(PolicyOption option, PolicyOptionDTO optionDto)
 {
     option.AgreedValue = optionDto.AgreedValue;
     return(option);
 }
예제 #6
0
 extern static ZxStatus zx_job_set_policy(uint handle, PolicyOption options, uint topic, BasicPolicy [] policy, uint count);
예제 #7
0
        public static void AddCustomHttpClient(this IServiceCollection services, string baseAddress, KeyValuePair <string, string>[] headers, PolicyOption policyOption)
        {
            services.AddSingleton <IPolicyBuilder, PolicyBuilder>();

            services
            .AddHttpClient <ICustomHttpClient, CustomHttpClient.CustomHttpClient>(client =>
            {
                client.BaseAddress = new Uri(baseAddress);

                AddDefaultRequestHeaders(headers, client);
            })
            .AddPolicyHandler((serviceProvider, httpRequestMessage) =>
            {
                var policyBuilder = serviceProvider.GetRequiredService <IPolicyBuilder>();

                return(policyBuilder.BuildGenericPolicy(policyOption));
            });
        }