static async Task RunAsync(string[] args)
        {
            if (args.Length < 2)
            {
                WSUtilities.PrintVersionMesssage("MIReport", "1.0");
                Console.WriteLine("MIReport.exe [settings file] [output file]");
                Console.WriteLine("MIReport.exe --example [settings file]");
                return;
            }
            if (args[0].ToLower() == "--example")
            {
                Console.WriteLine(WSSettings.WriteExample(args[1]));
                return;
            }
            try
            {
                WSSettings  settings = WSSettings.Load(args[0]);
                WSAPIClient client   = WSAPIClient.ForToken(settings);
                _ = await client.DoOIDC(settings);

                client = WSAPIClient.ForMIMEType(settings, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                var bytes = await client.GetByteArrayAsync("/api/mireport");

                using (StreamWriter sw = new StreamWriter(args[1]))
                {
                    sw.Write(bytes);
                    Console.WriteLine("{0} bytes written to {1}", bytes.Length, args[1]);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #2
0
        static async Task RunAsync(string[] args)
        {
            if (args.Length < 1)
            {
                WSUtilities.PrintVersionMesssage("HelloWorld", "1.0");
                Console.WriteLine("HelloWorld.exe [settings file]");
                return;
            }
            try
            {
                WSSettings  settings = WSSettings.Load(args[0]);
                WSAPIClient client   = WSAPIClient.ForToken(settings);
                _ = await client.DoOIDC(settings);

                client = WSAPIClient.ForJSON(settings);
                WSUserMyDetailsResult user = await client.DoGet <WSUserMyDetailsResult>("/api/user/myDetails");

                Console.WriteLine("username:{0} companyId:{1} uniqueID:{2} {3} {4}",
                                  user.username, user.companyId, user.uniqueID, user.teams.Count, user.teams.Count == 1 ? "team" : "teams");
                foreach (var t in user.teams)
                {
                    Console.WriteLine("teamId:{0} name:{1} channel:{2}", t.teamId, t.name, t.channel);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        static async Task RunAsync(string[] args)
        {
            if (args.Length < 1)
            {
                WSUtilities.PrintVersionMesssage("RisksList", "1.0");
                Console.WriteLine("RisksList.exe [settings file]");
                Console.WriteLine("RisksList.exe [settings file] ID (value)");
                Console.WriteLine("RisksList.exe [settings file] UMR (value)");
                Console.WriteLine("RisksList.exe [settings file] STATUS (value)");
                Console.WriteLine("RisksList.exe [settings file] INSUREDNAME (value)");
                Console.WriteLine("RisksList.exe --example [settings file]");
                return;
            }
            try
            {
                if (args[0].ToLower() == "--example" && args.Length > 1)
                {
                    Console.WriteLine(WSSettings.WriteExample(args[1]));
                    return;
                }


                Filter filter = new Filter(args);

                WSSettings  settings = WSSettings.Load(args[0]);
                WSAPIClient client   = WSAPIClient.ForToken(settings);
                _ = await client.DoOIDC(settings);

                client = WSAPIClient.ForJSON(settings);
                List <Risk> risks = await client.DoGet <List <Risk> >("/api/risks");

                Console.WriteLine("{0} risks loaded", risks.Count);
                foreach (var risk in risks)
                {
                    if (filter.Check(risk))
                    {
                        Console.WriteLine(String.Join(" : ",
                                                      new String[] { risk.id, risk.Status, risk.umr, risk.InsuredName }));
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        static async Task RunAsync(string[] args)
        {
            if (args.Length < 2)
            {
                WSUtilities.PrintVersionMesssage("VerifyAttachments", "1.0");
                Console.WriteLine("VerifyAttachments.exe [settings file] [IC]");
                Console.WriteLine("Gets the number of channels in IC::ATCH and looks for more channels in /risks/root items");
                return;
            }
            try
            {
                WSSettings  settings = WSSettings.Load(args[0]);
                WSAPIClient client   = WSAPIClient.ForToken(settings);
                _ = await client.DoOIDC(settings);

                client = WSAPIClient.ForJSON(settings);
                string           url = String.Format("/api/documents/{0}", args[1] + "::ATCH");
                PlatformDocument doc = await client.DoGet <PlatformDocument>(url);

                Console.WriteLine("{0} has {1} channel(s)", doc._id, doc.channels.Count);

                url = string.Format("/api/risks/root/{0}", args[1]);
                List <RisksRootResult> risksRootResult = await client.DoGet <List <RisksRootResult> >(url);

                Console.WriteLine("{0} results from {1}", risksRootResult.Count, url);
                foreach (var r in risksRootResult)
                {
                    string prefix = "";
                    if (r.channels.Count > doc.channels.Count)
                    {
                        prefix = "ERROR: ";
                    }
                    Console.WriteLine("{0}{1} has {2} channel(s)", prefix, r.id, r.channels.Count);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: " + ex.Message);
            }
        }
        static async Task RunAsync(string [] args)
        {
            if (args.Length < 2)
            {
                WSUtilities.PrintVersionMesssage("RiskPack", "1.0");
                Console.WriteLine("riskpack.exe [settings file] [riskID]");
                Console.WriteLine("riskpack.exe --example [settings file]");
                return;
            }
            if (args[0].ToLower() == "--example")
            {
                Console.WriteLine(WSSettings.WriteExample(args[1]));
                return;
            }
            WSSettings settings;

            try
            {
                settings = WSSettings.Load(args[0]);
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR {0}", ex.Message);
                return;
            }
            string json = String.Empty, req = String.Empty;

            try
            {
                string folder = WSUtilities.MakeSafeFilename(args[1]) + DateTime.Now.ToString("_ddMMyy_HHmmss");
                Directory.CreateDirectory(folder);

                WSAPIClient client = WSAPIClient.ForToken(settings);
                _ = await client.DoOIDC(settings);

                req    = String.Format("/export/pdf/{0}", args[1]);
                client = WSAPIClient.ForPDF(settings);

                var bytes = await client.GetByteArrayAsync(req);

                WriteFile(folder, args[1] + ".pdf", bytes);

                client = WSAPIClient.ForJSON(settings);
                req    = String.Format("/api/attachments/{0}", MakeATCH(args[1]));
                json   = await client.GetStringAsync(req);

                Dictionary <String, WSAttachment> dict = JsonConvert.DeserializeObject <Dictionary <String, WSAttachment> >(json);
                foreach (string key in dict.Keys)
                {
                    WSAttachment att = dict[key];
                    client = WSAPIClient.ForMIMEType(settings, att.content_type);
                    req    = string.Format("/api/attachments/{0}/{1}", MakeATCH(args[1]), key);
                    bytes  = await client.GetByteArrayAsync(req);

                    WriteFile(folder, key, bytes);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("Last URL was {0}", req);
            }
        }
        static async Task RunAsync(string[] args)
        {
            if (args.Length < 2)
            {
                WSUtilities.PrintVersionMesssage("EvidenceOfCover", "1.1");
                Console.WriteLine("EvidenceOfCover.exe [settings file] [json template] [riskID]");
                Console.WriteLine("EvidenceOfCover.exe --example [settings file]");
                return;
            }
            if (args[0].ToLower() == "--example")
            {
                Console.WriteLine(WSSettings.WriteExample(args[1]));
                return;
            }
            if (args.Length < 3)
            {
                Console.WriteLine("EvidenceOfCover.exe [settings file] [json template] [riskID]");
                return;
            }
            WSSettings settings;

            try
            {
                settings = WSSettings.Load(args[0]);
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR {0}", ex.Message);
                return;
            }

            string json = String.Empty, req = String.Empty;

            try
            {
                if (!File.Exists(args[1]))
                {
                    Console.WriteLine("No template file " + args[1]);
                    return;
                }
                String template = "";
                using (StreamReader sr = new StreamReader(args[1]))
                {
                    template = sr.ReadToEnd();
                }
                Regex           rgx     = new Regex(@"\[\[(?<heading>[^\]]*)\]\]");
                MatchCollection matches = rgx.Matches(template);
                WSAPIClient     client  = WSAPIClient.ForToken(settings);
                _ = await client.DoOIDC(settings);

                client = WSAPIClient.ForJSON(settings);
                foreach (Match m in matches)
                {
                    String heading = m.Groups["heading"].Value;
                    String tidied = "", fixedVariable = FixedVariable(heading);

                    if (fixedVariable != null)
                    {
                        tidied = fixedVariable;
                    }
                    else
                    {
                        req = String.Format("/api/risks/{0}/lineitem/{1}/crlf", args[2], heading);
                        RisksLineItemCRLFResponse text = await client.DoGet <RisksLineItemCRLFResponse>(req);

                        if (text != null && text.text != null)
                        {
                            tidied = text.text.Replace("\n", "\\n");
                        }
                    }
                    Console.WriteLine("{0} = {1}", heading, tidied);
                    String grail = "[[" + heading + "]]";
                    template = template.Replace(grail, tidied);
                }
                // /api/lines/$IC/combinedSets
                req = String.Format("/api/lines/{0}/combinedSets", WSUtilities.GetRoot(args[2]));
                var signedlines = await client.DoGet <List <CombinedSet> >(req);

                Decimal total = 0m;
                PMTable table = new PMTable();
                table.widths.Add("25%");
                table.widths.Add("*");
                List <PMCell> row = new List <PMCell>();

                foreach (CombinedSet cs in signedlines)
                {
                    if (cs.type == "RWSignedLineSet")
                    {
                        foreach (Content c in cs.contents)
                        {
                            foreach (Impression i in c.impressions)
                            {
                                Console.WriteLine("{0} {1} {2}", cs.type, i.signedLinePercentageString, i.stamp.businessUnit);
                                row = new List <PMCell>();
                                row.Add(new PMCell(i.signedLinePercentageString + "%"));
                                row.Add(new PMCell(i.stamp.businessUnit));
                                table.body.Add(row);
                                Decimal signedLinePercentage;
                                if (Decimal.TryParse(i.signedLinePercentageString, out signedLinePercentage))
                                {
                                    total += signedLinePercentage;
                                }
                            }
                        }
                    }
                }
                Console.WriteLine("Total {0}", total);

                row = new List <PMCell>();
                row.Add(new PMCell(total.ToString() + "%"));
                row.Add(new PMCell(""));
                table.body.Add(row);
                String tableJSON = JsonConvert.SerializeObject(table, Formatting.Indented);
                //Console.WriteLine(tableJSON);
                template = template.Replace("\"signed_lines_table\"", tableJSON);

                //String input = "tmp" + DateTime.Now.ToString("ddMMyyyy_HHmmss") + ".json";
                String pdffile = "tmp" + DateTime.Now.ToString("ddMMyyyy_HHmmss") + ".pdf";

                // https://stackoverflow.com/questions/36625881/how-do-i-pass-an-object-to-httpclient-postasync-and-serialize-as-a-json-body
                var buffer = System.Text.Encoding.UTF8.GetBytes(template);
                //WriteFile(input, buffer);
                var byteContent = new ByteArrayContent(buffer);
                byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                req = "/pdfmake/";
                HttpResponseMessage responseMessage = await client.PostAsync(req, byteContent);

                var bytes = await responseMessage.Content.ReadAsByteArrayAsync();

                WriteFile(pdffile, bytes);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("Last URL was {0}", req);
            }
        }