C# Client Library
A C# Client Library for the AnalyzeRe REST API
Loading...
Searching...
No Matches
Scripts.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Diagnostics;
4
5using AnalyzeRe;
8
10{
13 public static partial class Scripts
14 {
15 // Iterates over all objects in a collection on the server and executes an action delegate on it.
16 public static void ModifyAll<T>(Action<T> Modifier) where T : IAPIResource
17 {
18 IEnumerable<T> collectionItems = API.GetResourceList<T>().items;
19 int processed = 0;
20 foreach (T item in collectionItems)
21 {
22 Modifier(item);
23 item.Put();
24 processed++;
25 }
26 Debug.WriteLine("Processed " + processed + " " + typeof(T).Name + " objects.\n");
27 }
28
29 public static void GenerateAdditionalDataOnServer()
30 {
31 string[] companyNames = { "Brilliantly Limited", "Ephesian Assurance", "Jana's Limited", "Jurua Corp.", "Sargasso's Corp.", "Uighur's Insurance", "Colloquiums Co.", "Ballparks Limited", "Bullfrog's Corp.", "Convocation's Re", "Apalachicola's Insurance", "Letterman Shield", "Bellboy's Assurance", "Barr's Limited", "Condescend Co.", "Bulldog Corp.", "Chalky Holdings", "Cardinals Insurance", "Chimera's Holdings", "Justin Insurance", "Oneal Assurance", "Nicholson Co.", "Apt Holdings", "Lean's Assurance", "Patrica Co.", "CD's Assurance", "Buckner's Assurance", "Rastafarian Insurance", "Conscripts Insurance", "Shanna's Corp.", "Wylie's Assured", "Sopwith's Shield", "Wisconsinite's Co.", "Laverne's Limited", "Hoover's Shield", "Noble's Re", "Cajole Shield", "Bigness Co.", "Conviction Limited", "Algiers Corp.", "Adelaide Insurance", "Boston's Re", "Rojas Re", "Purana Holdings", "Account's Re", "Anemometer Corp.", "Club Insurance", "Miro Re", "Melanie's Re", "Clarissa's Re", "Carvings Corp.", "Hugo Insurance", "Siberian Shield", "Coinage Insurance", "Chitchat's Assurance", "Xenophon Insurance", "Annie's Corp.", "Biodegradable Holdings", "Construe Co.", "Debora Assurance", "Damon Shield", "Alyce Assured", "Atalanta Limited", "Corrugates Insurance", "Krystal Shield", "Goff's Assured", "Bloodsuckers Limited", "McClure Corp.", "Miltonic Assured", "Hummer's Shield", "Convoke Insurance", "Acids Holdings", "Muzak Assurance", "Catharsis Assured", "Schulz's Insurance", "Squibb's Corp.", "Horus's Assured", "Cezanne Holdings", "Moog Limited", "Classmates Re", "Portia's Re", "Arabesque's Shield", "Billboard Co.", "Archly Assured", "Cappuccinos Assurance", "Fredericton Corp.", "Contreras Limited", "Rottweiler's Assured", "Dubai Assured", "Blurted Holdings", "Methodism Insurance", "Mazzini Limited", "Casements Shield", "Apostate's Insurance", "Chained Assured", "Knopf's Assurance", "Businessmen Assured", "Constables Assured", "Susquehanna Insurance" };
32 ModifyAll(delegate (ILayer_WithTerms item)
33 {
34 // Give it a new Description
35 Random rand = new Random(item.id.GetHashCode());
36 // string newDescription = companyNames[rand.Next(companyNames.Length)];
37 Debug.WriteLine(item.id + " - Description: " + item.description /*+ " -> " + newDescription*/);
38 // item.description = newDescription;
39
40 // Give it a new Participation (one of 10%, 20%, ..., 100%, or 25%, or 75%)
41 double newShare = (double)((rand.Next(12) + 1)) / 10.0;
42 newShare = newShare == 1.1 ? 0.25 : newShare == 1.2 ? 0.75 : newShare;
43 Debug.WriteLine(new String(' ', item.id.Length + 3) + "Share: " + item.participation + " -> " + newShare);
44 item.participation = newShare;
45
46 // Give it a new Premium (increments of 50K)
47 double newPrem = ((double)rand.Next(20)) * 5000 * (rand.Next(1) == 1 ? 10 : (rand.Next(1) == 1 ? 100 : 1));
48 Debug.WriteLine(new String(' ', item.id.Length + 3) + "Premium: " + item.premium + " -> " + newPrem);
49 item.premium = new MonetaryUnit(newPrem, "USD");
50
51 // Give it a new Inception/Expiry
52 DateTime newIncept = new DateTime(DateTime.UtcNow.Year, rand.Next(12) + 1, 1);
53 Debug.WriteLine(new String(' ', item.id.Length + 3) + "Inception: " + item.inception_date + " -> " + newIncept);
54 item.inception_date = newIncept;
55 item.expiry_date = newIncept.AddYears(1);
56 });
57
58 ModifyAll(delegate (ELTLossSet item)
59 {
60 Random rand = new Random(item.id.GetHashCode());
61 // Give it a new Description
62 // string newDescription = (String.Join(" ", item.event_catalogs.FirstOrDefault().Value.tags) + " losses in " + item.currency + " from " + item.event_catalogs.FirstOrDefault().Value.source).Trim();
63 // Debug.WriteLine(item.analysis.ToString());
64 Debug.WriteLine(item.id + " - Description: " + item.description /*+ " -> " + newDescription*/);
65 // item.description = newDescription;
66
67 // Also set the currency
68 // Debug.WriteLine(new String(' ', item.primary_key.Length + 3) + "Currency: " + item.currency + " -> USD");
69 // item.currency = "USD";
70 });
71 }
72 }
73}
A collection of scripts that are sometimes used to batch seed or modify data on a test server.
Definition Scripts.cs:14
static void GenerateAdditionalDataOnServer()
Definition Scripts.cs:29
static void ModifyAll< T >(Action< T > Modifier)
Definition Scripts.cs:16
API methods / requests made available to the user.
static ICollectionResponse< IAPIResource > GetResourceList(Type resourceType, IEnumerable< Parameter > requestParameters=null, string collectionNameOverride=null, int? timeout=null)
Get a collection of resources from the server.
Representation of a single loss set with an associated event loss table.
Definition ELTLossSet.cs:10
Representation of a monetary value with a currency.
string description
A user-friendly description of the resource.
Interface for Base class used by all resources.
string id
The resource's unique identifier. It will be used in the request URL when requesting the resource fro...
Abstract representation of a layer with terms.
DateTime? inception_date
The date and time when the contract takes effect.