Example #1
0
        internal async Task <object> createDataAsync(Dictionary <string, object> tokens)
        {
            bool containsfile = tokens.ContainsKey("filepath");
            bool containsguid = tokens.ContainsKey("guid");
            bool containsurl  = tokens.ContainsKey("url");

            //to return Video created from LinkUpload, otherwise return null
            object result = null;

            if (((containsfile ^ containsguid) ^ containsurl) == true)
            {
                if (((containsfile & containsguid) & containsurl) == true)
                {
                    throw new VzaarApiException("Only one of the parameters: guid or url or filepath expected");
                }

                if (containsguid == true)
                {
                    record.Create(tokens);
                }
                else if (containsurl == true)
                {
                    result = LinkUpload.Create(tokens, record.RecordClient);
                }
                else
                {
                    string filepath = (string)tokens ["filepath"];

                    FileInfo file = new FileInfo(filepath);

                    if (file.Exists == false)
                    {
                        throw new VzaarApiException("File does not exist: " + filepath);
                    }

                    Signature signature = Signature.Create(filepath, record.RecordClient);

                    await record.RecordClient.HttpPostS3Async(filepath, signature);

                    tokens.Remove("filepath");
                    tokens.Add("guid", (string)signature ["guid"]);

                    await createDataAsync(tokens);
                }
            }
            else
            {
                throw new VzaarApiException();
            }

            return(result);
        }
Example #2
0
        public static void UsingVideoCreateGuid(string id, string token, string filepath)
        {
            try {
                Console.WriteLine("--Create(tokens) with GUID--");

                var signature = Signature.Create(filepath);

                //

                //-> here the file should be uploaded with your AWS uploader
                //   according to received signature (single or multipart)

                //

                Dictionary <string, object> tokens = new Dictionary <string, object> ()
                {
                    { "guid", signature["guid"] },
                    { "title", "MyMovie" },
                    { "description", "Initial description" }
                };

                var task2  = Video.CreateAsync(tokens);
                var video1 = task2.Result;


                Console.WriteLine("Id: " + video1["id"] + " Title: " + video1["title"]);

                //lookup
                Console.WriteLine("--Find(id)--");

                var item = Video.Find((long)video1["id"]);

                Console.WriteLine("--Access with property name--");
                Console.WriteLine("Id: " + video1["id"] + " Title: " + video1["title"]);

                Console.WriteLine("--Access with the record Type--");

                var record1 = (VideoType)item.ToTypeDef(typeof(VideoType));
                Console.WriteLine("Id: " + record1.id + " Title: " + record1.title + " Created: " + record1.created_at);

                Console.WriteLine("--Access with custom Type--");

                var record2 = (myType)item.ToTypeDef(typeof(myType));
                Console.WriteLine("Id: " + record2.id + " Title: " + record2.title);


                //update
                Console.WriteLine("--Update1--");

                Console.WriteLine("--Before: Save(tokens)--");
                Console.WriteLine("Id: " + item["id"] + " Description: " + item["description"]);

                Dictionary <string, object> tokens2 = new Dictionary <string, object> ()
                {
                    { "description", null }
                };


                item.Save(tokens2);

                Console.WriteLine("--After: Save(tokens)--");
                Console.WriteLine("Id: " + item["id"] + " Description: " + item["description"]);


                Console.WriteLine("--Update2--");

                Console.WriteLine("--Before: Save()--");
                Console.WriteLine("Id: " + item["id"] + " Title: " + item["title"]);

                item["title"] = "Updated title";

                item["title"] = null;

                if (item.Edited)
                {
                    item.Save();
                }

                item["title"] = "Updated title";

                if (item.Edited)
                {
                    item.Save();
                }

                Console.WriteLine("--After: Save()--");
                Console.WriteLine("Id: " + item["id"] + " Title: " + item["title"]);


//				Console.WriteLine ("--Delete--");
//
//				var videoId = (long)item ["id"];
//				item.Delete ();
//
//				Console.WriteLine ("--Find after delete--");
//				item = Video.Find (videoId);
            } catch (VzaarApiException ve) {
                Console.Write("!!!!!!!!! EXCEPTION !!!!!!!!!");
                Console.WriteLine(ve.Message);
            } catch (Exception e) {
                Console.Write("!!!!!!!!! EXCEPTION !!!!!!!!!");
                Console.WriteLine(e.Message);

                if (e is AggregateException)
                {
                    AggregateException ae = (AggregateException)e;

                    var flatten = ae.Flatten();

                    foreach (var fe in flatten.InnerExceptions)
                    {
                        if (fe is VzaarApiException)
                        {
                            Console.WriteLine(fe.Message);
                        }
                    }
                }
            }
        }
Example #3
0
        public static void ReadingSignature(string id, string token, string filepath)
        {
            try {
                Console.WriteLine("--Single()--");
                FileInfo file = new FileInfo(filepath);

                Signature single1 = Signature.Single();

                Console.WriteLine("guid: " + single1["guid"]);

                Console.WriteLine("--Single(tokens)--");

                var tokens1 = new Dictionary <string, object> ()
                {
                    { "filename", file.Name },
                    { "uploader", Client.UPLOADER }
                };

                Signature single2 = Signature.Single(tokens1);

                var record1 = (UploadSignatureType)single2.ToTypeDef(typeof(UploadSignatureType));

                Console.WriteLine("guid: " + record1.guid);


                Console.WriteLine("--Multipart(tokens)--");

                //FileInfo file = new FileInfo (filepath);

                var tokens2 = new Dictionary <string, object> ()
                {
                    { "filename", file.Name },
                    //{"uploader", "myUploader"},
                    { "uploader", Client.UPLOADER },
                    { "filesize", 3221225472 },
                };

                var multipart1 = Signature.Multipart(tokens2);

                Console.WriteLine("guid: " + multipart1["guid"] + " Parts: " + multipart1["parts"].ToString());

                Console.WriteLine("--FromFile--");

                var signature = Signature.Create(filepath);

                if (signature["parts"] == null)
                {
                    Console.WriteLine("guid: " + signature["guid"]);
                }
                else
                {
                    Console.WriteLine("guid: " + signature["guid"] + " Parts: " + signature["parts"]);
                }
            } catch (VzaarApiException ve) {
                Console.Write("!!!!!!!!! EXCEPTION !!!!!!!!!");
                Console.WriteLine(ve.Message);
            } catch (Exception e) {
                Console.Write("!!!!!!!!! EXCEPTION !!!!!!!!!");
                Console.WriteLine(e.Message);

                if (e is AggregateException)
                {
                    AggregateException ae = (AggregateException)e;

                    var flatten = ae.Flatten();

                    foreach (var fe in flatten.InnerExceptions)
                    {
                        if (fe is VzaarApiException)
                        {
                            Console.WriteLine(fe.Message);
                        }
                    }
                }
            }
        }