Пример #1
0
        private static CosmosSettings GetCosmosConfiguration()
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json");

            Configuration = builder.Build();

            var cosmosSettings = new CosmosSettings()
            {
                DbUrl              = Configuration.GetSection("cosmos")["DbUrl"],
                DbName             = Configuration.GetSection("cosmos")["DbName"],
                CollectionName     = Configuration.GetSection("cosmos")["CollectionName"],
                AuthorizationKey   = Configuration.GetSection("cosmos")["AuthorizationKey"],
                MaxConnectionLimit = Convert.ToInt32(Configuration.GetSection("cosmos")["MaxConnectionLimit"]),
                OfferThroughput    = Convert.ToInt32(Configuration.GetSection("cosmos")["OfferThroughput"])
            };

            return(cosmosSettings);
        }
Пример #2
0
        static void Main(string[] args)
        {
            cosmosSettings = GetCosmosConfiguration();
            client         = new DocumentClient(new Uri(cosmosSettings.DbUrl), cosmosSettings.AuthorizationKey);

            try
            {
                /******* Create Documents**************/

                // CreateDocuments().ConfigureAwait(false);

                /*******  Create Documents***********/


                /*******  Query Document By Document Id*****************/

                // string documentId = "acb113cb-ece6-4ad7-b53b-e269872c2db2";
                // var response = GetDocument(documentId);

                // Console.WriteLine(response.Result.User.Name + " " + response.Result.Text);
                // Console.WriteLine("1.2 - Query Document By Document Id - Complete");

                /*******  Query Document By Document Id*****************/

                /*******  UPDATE / REPLACE DOCUMENTS********************************/

                // Console.WriteLine("1.3 - Update/Replace Documents - Start");
                // string documentId = "acb113cb-ece6-4ad7-b53b-e269872c2db2";
                // var response = GetDocument(documentId);
                // var tweetToModify = response.Result;
                // tweetToModify.User.ScreenName = "Azure Specialist";
                // UpdateDocument(tweetToModify).ConfigureAwait(false);
                // Console.WriteLine("1.3 - Update/Replace Documents - Complete");

                /*******  UPDATE / REPLACE DOCUMENTS********************************/


                /********* UPSERT DOCUMENTS********************************/

                //Create a new Tweet
                // var tweet = TweetManager.CreateTweet("Welcome to #Cosmo SQL API Level 500");
                // UpsertDocument(tweet).ConfigureAwait(false);

                /********* UPSERT DOCUMENTS********************************/

                /********************* DELETE DOCUMENT ****************************/
                // var documentToDelete = "c5eeb2f0-2c16-46a8-9031-b271093b4ecd";
                // DeleteDocument(documentToDelete).ConfigureAwait(false);

                /*************************************************************/

                /***************************Query Documents (Tweets) By User*******************************/
                // var tweets = GetTweetsByUser("AzureDev");

                // foreach (var tweet in tweets)
                // {
                //    Console.WriteLine(tweet.UserName + "-" + tweet.Message + "\n");
                // }

                /***************************Query Documents (Tweets) By HashTag*******************************/

                /***************************Query Documents (Tweets) By HashTag*******************************/
                Console.WriteLine("1.4 - Query Documents (Tweets) By HashTag Start");
                var tweets = GetTweetByHashTag("#marketing");

                foreach (var tweet in tweets)
                {
                    Console.WriteLine(tweet.UserName + "-" + tweet.Message + "\n");
                }

                /***************************Query Documents (Tweets) By HashTag*******************************/
            }
            catch (ArgumentException aex)
            {
                Console.WriteLine($"Caught ArgumentException: {aex.Message}");
            }

            Console.Read();
        }