Ejemplo n.º 1
0
        static void WriteFile(string folder, string filename, Byte[] bytes)
        {
            string fullfilename = Path.Combine(folder, WSUtilities.MakeSafeFilename(filename));

            using (var fs = new FileStream(fullfilename, FileMode.Create, FileAccess.Write))
            {
                fs.Write(bytes, 0, bytes.Length);
            }
            Console.WriteLine("{0} written, {1} bytes", fullfilename, bytes.Length);
        }
Ejemplo n.º 2
0
        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);
            }
        }