public static NinjaDudsAwsApi Init(bool local = false)
        {
            if (Current == null)
            {
                Current = new NinjaDudsAwsApi();
                Current.InternalInit(local);
            }

            return(Current);
        }
예제 #2
0
        public async void TestWebApi()
        {
            NinjaDudsAwsApi.Init(true);
            NinjaDudsAwsApi api = NinjaDudsAwsApi.Current;

            try
            {
                dynamic obj = JsObj();
                obj.Key             = "key2.png";
                obj.Content         = Utility.PngToBase64(@"C:\Users\blank\Pictures\lumpiakitchen.png");
                obj.IsBase64Encoded = true;
                obj.ContentType     = "image/png";

                await api.S3UploadAsync(obj);

                obj     = JsObj();
                obj.Key = "key2.png";

                var s3DownloadResponse = await api.S3DownloadAsync(obj);

                ImageViewer.Source = Utility.Base64ToPng(s3DownloadResponse.content);

                obj                    = JsObj();
                obj.TableName          = "NinjaDudsMainTablexxLocalxx";
                obj.Item               = JsObj();
                obj.Item.PK            = "*****@*****.**";
                obj.Item.SK            = "jjjjjjjjj";
                obj.Item.CustomMessage = "cool";

                await api.DbPutAsync(obj);

                obj           = JsObj();
                obj.TableName = "NinjaDudsMainTablexxLocalxx";
                obj.Key       = JsObj();
                obj.Key.PK    = "*****@*****.**";
                obj.Key.SK    = "jjjjjjjjj";

                obj = await api.DbGetAsync(obj);


                obj                           = JsObj();
                obj.TableName                 = "NinjaDudsMainTablexxLocalxx";
                obj.Key                       = JsObj();
                obj.Key.PK                    = "*****@*****.**";
                obj.Key.SK                    = "jjjjjjjjj";
                obj.UpdateExpression          = "set CustomMessage = :r";
                obj.ExpressionAttributeValues = JsObj(
                    ":r", "Cool part 2"
                    );

                //Add the following to update conditionally
                //obj.ConditionExpression = "size(info.actors) > :num";
                //obj.ExpressionAttributeValues = JsObj(":num", 3);

                await api.DbUpdateAsync(obj);

                obj           = JsObj();
                obj.TableName = "NinjaDudsMainTablexxLocalxx";
                obj.Key       = JsObj();
                obj.Key.PK    = "*****@*****.**";
                obj.Key.SK    = "jjjjjjjjj";

                await api.DbDeleteAsync(obj);

                obj           = JsObj();
                obj.TableName = "NinjaDudsMainTablexxLocalxx";
                obj.KeyConditionExpression   = "#key = :value";
                obj.ExpressionAttributeNames = JsObj(
                    "#key", "PK"
                    );

                obj.ExpressionAttributeValues = JsObj(
                    ":value", "*****@*****.**"
                    );

                List <object> j = await api.DbQueryAsync(obj);



                //THIS EXAMPLE IS TO DOWNLOAD MULTIPLE IMAGES
                //List<Tuple<string, System.Windows.Controls.Image>> keys = new List<Tuple<string, System.Windows.Controls.Image>>();
                //keys.Add(new Tuple<string, System.Windows.Controls.Image>("key1.png", this.ImageViewer));
                //keys.Add(new Tuple<string, System.Windows.Controls.Image>("key2.png", this.ImageViewer2));

                //foreach (var key in keys)
                //{

                //    Task t = Task.Factory.StartNew(async (object obj) =>
                //    {
                //        Tuple<string, System.Windows.Controls.Image> data = obj as Tuple<string, System.Windows.Controls.Image>;

                //        Debug.WriteLine(data.Item1);

                //        S3DownloadRequest downloadRequest = new S3DownloadRequest()
                //        {
                //            Key = data.Item1
                //        };


                //        var s3DownloadResponse = await api.S3DownloadAsync(downloadRequest);
                //        data.Item2.Dispatcher.Invoke(() =>
                //        {
                //            data.Item2.Source = Base64ToPng(s3DownloadResponse.Content);
                //        });


                //    },
                //    key);

                //    Tasks.Add(t);

                //}
            }
            catch (Exception ex)
            {
                dynamic err = Utility.ToJsObj(ex.Message);
                int     x   = 9;
            }



            //    var person = new Person()
            //    {
            //        Email = "*****@*****.**",
            //        FirstName = "Alan",
            //        LastName = "Purugganan"
            //    };

            //    var options = new JsonSerializerOptions()
            //    {
            //        IgnoreNullValues = true,
            //        PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
            //        PropertyNameCaseInsensitive = true
            //};

            //string json = JsonSerializer.Serialize<S3UploadRequest>(s3UploadRequest, options);

            //using var client = new HttpClient();


            //client.BaseAddress = (local)
            //    ? new Uri("http://127.0.0.1:3000")
            //    : new Uri("https://xwvhb77s80.execute-api.us-east-1.amazonaws.com");

            //var content = new StringContent(json, Encoding.UTF8, "application/json");

            //string pathFolder = (local)
            //    ? ""
            //    : "/Prod";

            //string path = pathFolder + "/s3-upload";

            //var result = await client.PostAsync(path, content);


            //string message = "Error";

            //if(result.StatusCode == System.Net.HttpStatusCode.OK)
            //{
            //    json = await result.Content.ReadAsStringAsync();
            //    var responseBody = JsonSerializer.Deserialize<Response>(json, options);
            //    message = responseBody.Message;
            //}

            //Console.WriteLine(message);

            ////now attempt a read
            //result = await client.GetAsync("/Prod/read-examples");

            //message = "Error";

            //if (result.StatusCode == System.Net.HttpStatusCode.OK)
            //{
            //    json = await result.Content.ReadAsStringAsync();
            //    var messageItems = JsonSerializer.Deserialize<ResponseB>(json, options);
            //    int x = 9;
            //}
        }