Beispiel #1
0
        /// <summary>
        /// gets the current config, makes sure it is not a production environment, and prints the configuration
        /// </summary>
        /// <param name="environmentName">name of the environment that will be created or cleaned</param>
        /// <param name="kvr">key vault settings reader</param>
        /// <returns>validate and print task</returns>
        private static async Task ValidateAndPrintConfiguration(string environmentName, ISettingsReaderAsync kvr)
        {
            if (doAll || doTables)
            {
                if (string.IsNullOrWhiteSpace(await kvr.ReadValueAsync("AzureStorageConnectionString")))
                {
                    Console.WriteLine("Error! AzureStorageConnectionString in your configuration is null or whitespace. Aborting...");
                    System.Environment.Exit(-1);
                }
            }

            if (doAll || doLogs)
            {
                if (string.IsNullOrWhiteSpace(await kvr.ReadValueAsync("AzureStorageConnectionString")))
                {
                    Console.WriteLine("Error! AzureStorageConnectionString in your configuration is null or whitespace. Aborting...");
                    System.Environment.Exit(-1);
                }
            }

            if (doClean && ProdConfiguration.IsProduction(await kvr.ReadValueAsync("AzureStorageConnectionString")))
            {
                Console.WriteLine("Error! Your configuration includes a production service. Aborting...");
                System.Environment.Exit(-1);
            }

            Console.WriteLine();
            Console.Write("Environment name: ");
            Console.WriteLine(environmentName);
            Console.WriteLine();
            Console.WriteLine("Current configuration:");

            if (doAll || doTables)
            {
                Console.WriteLine("\tAzure table storage string: " + await kvr.ReadValueAsync("AzureStorageConnectionString"));
            }

            if (doAll || doLogs)
            {
                Console.WriteLine("\tAzure diagnostics table storage string: " + await kvr.ReadValueAsync("AzureStorageConnectionString"));
            }

            Console.WriteLine();
        }
Beispiel #2
0
        public void BasicSearchTopicsTests()
        {
            // get the connection strings
            ISettingsReader sr = new AppSettingsReader();
            string          searchServiceName     = sr.ReadValue("SearchServiceName");
            string          searchServiceAdminKey = sr.ReadValue("SearchServiceAdminKey");

            // TO do this test successfully, we need to DELETE THE INDEX!!!
            // THIS TEST IS DESTRUCTIVE
            // make sure this is not production
            Assert.IsFalse(ProdConfiguration.IsProduction(searchServiceName));

            var log = new Log(LogDestination.Debug, Log.DefaultCategoryName);

            // instantiate the search interface
            SocialPlus.Server.Search.SearchTopics searchTopics = new SocialPlus.Server.Search.SearchTopics(log, searchServiceName, searchServiceAdminKey);

            // clean the index
            searchTopics.DeleteIndex().Wait();
            searchTopics.CreateIndex().Wait();
            System.Threading.Thread.Sleep(1000); // there appears to be an Azure delay in indexing

            // test empty topic tags
            List <TopicDocument> topics         = new List <TopicDocument>();
            TopicDocument        topicEmptyTags = new TopicDocument("topicEmptyTags", null, "hello", null, "freshpaint", "John", 1, DateTime.Now);

            topics.Add(topicEmptyTags);
            searchTopics.AddTopics(topics).Wait();
            System.Threading.Thread.Sleep(1000); // there appears to be an Azure delay in indexing
            List <TopicDocumentResult> resultEmptyTags = searchTopics.Search(topicEmptyTags.TopicText, searchTopicTags: false, searchTopicText: true).Result;

            Assert.IsNotNull(resultEmptyTags);
            Assert.AreEqual(resultEmptyTags.Count, 1);
            Assert.AreEqual(resultEmptyTags[0].TopicHandle, topicEmptyTags.TopicHandle);

            // cleanup
            topics.Clear();
            searchTopics.DeleteTopic(topicEmptyTags.TopicHandle).Wait();

            // insert some items
            TopicDocument topic1 = new TopicDocument("topic1", "title1212", "text1", new List <string>()
            {
                "tag1", "tag2"
            }, "app1", "user1", 95, DateTime.Now.AddDays(-1));
            TopicDocument topic2 = new TopicDocument("topic2", "title2", "title1212", new List <string>()
            {
                topic1.TopicTags[0], "tag3"
            }, "app2", "user2", 90, DateTime.Now);

            topics.Add(topic1);
            topics.Add(topic2);
            searchTopics.AddTopics(topics).Wait();
            System.Threading.Thread.Sleep(1000); // there appears to be an Azure delay in indexing

            // basic search functionality and ordering
            List <TopicDocumentResult> result1 = searchTopics.Search(topic1.TopicTags[0]).Result;

            Assert.IsNotNull(result1);
            Assert.AreEqual(result1.Count, 2);
            Assert.AreEqual(result1[0].TopicHandle, topic2.TopicHandle);
            Assert.AreEqual(result1[1].TopicHandle, topic1.TopicHandle);

            // test search on other fields
            result1 = searchTopics.Search("titl*", null, null, false, true, false).Result;
            Assert.IsNotNull(result1);
            Assert.AreEqual(result1.Count, 2);
            List <string> topicHandles = result1.ConvertAll <string>(o => o.TopicHandle);

            Assert.IsTrue(topicHandles.Contains(topic1.TopicHandle));
            Assert.IsTrue(topicHandles.Contains(topic2.TopicHandle));

            result1 = searchTopics.Search("title2", null, null, false, true, false).Result;
            Assert.IsNotNull(result1);
            Assert.AreEqual(result1.Count, 1);
            Assert.AreEqual(result1[0].TopicHandle, topic2.TopicHandle);

            result1 = searchTopics.Search("tag*", null, null, false, true, false).Result;
            Assert.IsNotNull(result1);
            Assert.AreEqual(result1.Count, 0);

            result1 = searchTopics.Search("title1212", null, null, false, false, true).Result;
            Assert.IsNotNull(result1);
            Assert.AreEqual(result1.Count, 1);
            Assert.AreEqual(result1[0].TopicHandle, topic2.TopicHandle);

            result1 = searchTopics.Search("title1212", null, null, false, true, true).Result;
            Assert.IsNotNull(result1);
            Assert.AreEqual(result1.Count, 2);
            topicHandles = result1.ConvertAll <string>(o => o.TopicHandle);
            Assert.IsTrue(topicHandles.Contains(topic1.TopicHandle));
            Assert.IsTrue(topicHandles.Contains(topic2.TopicHandle));

            // test search for a particular user's topics
            result1 = searchTopics.Search("tag*", null, topic2.UserHandle).Result;
            Assert.IsNotNull(result1);
            Assert.AreEqual(result1.Count, 1);
            Assert.AreEqual(result1[0].TopicHandle, topic2.TopicHandle);

            // test search for a particular user and particular apps topics
            result1 = searchTopics.Search("tag*", topic2.AppHandle, topic2.UserHandle).Result;
            Assert.IsNotNull(result1);
            Assert.AreEqual(result1.Count, 1);
            Assert.AreEqual(result1[0].TopicHandle, topic2.TopicHandle);

            result1 = searchTopics.Search("tag*", topic1.AppHandle, topic2.UserHandle).Result;
            Assert.IsNotNull(result1);
            Assert.AreEqual(result1.Count, 0);

            // test updates
            topic2.SearchWeight = 80;
            topics.Clear();
            topics.Add(topic2);
            searchTopics.AddTopics(topics).Wait();
            System.Threading.Thread.Sleep(1000); // there appears to be an Azure delay in indexing
            result1 = searchTopics.Search(topic1.TopicTags[0]).Result;
            Assert.IsNotNull(result1);
            Assert.AreEqual(result1.Count, 2);
            Assert.AreEqual(result1[0].TopicHandle, topic1.TopicHandle);
            Assert.AreEqual(result1[1].TopicHandle, topic2.TopicHandle);

            // search with apps
            result1 = searchTopics.Search(topic1.TopicTags[0], topic2.AppHandle).Result;
            Assert.IsNotNull(result1);
            Assert.AreEqual(result1.Count, 1);
            Assert.AreEqual(result1[0].TopicHandle, topic2.TopicHandle);

            // search for limited set of records
            result1 = searchTopics.Search(topic1.TopicTags[0], null, null, true, false, false, 0, 1).Result;
            Assert.IsNotNull(result1);
            Assert.AreEqual(result1.Count, 1);
            Assert.AreEqual(result1[0].TopicHandle, topic1.TopicHandle);

            // search for non-existent record
            result1 = searchTopics.Search(new Random().Next().ToString()).Result;
            Assert.AreEqual(result1.Count, 0);

            // delete
            searchTopics.DeleteTopic(topic1.TopicHandle).Wait();
            System.Threading.Thread.Sleep(1000); // there appears to be an Azure delay in indexing
            result1 = searchTopics.Search(topic1.TopicTags[0]).Result;
            Assert.IsNotNull(result1);
            Assert.AreEqual(result1.Count, 1);
            Assert.AreEqual(result1[0].TopicHandle, topic2.TopicHandle);

            // number of records
            long numRecords = searchTopics.GetNumberOfDocuments().Result;

            Assert.AreNotEqual(numRecords, -1);

            // number of bytes
            long numBytes = searchTopics.GetStorageUsage().Result;

            Assert.AreNotEqual(numBytes, -1);

            // reset
            searchTopics.DeleteIndex().Wait();
            searchTopics.CreateIndex().Wait();
        }
Beispiel #3
0
        public void AdvancedSearchTopicsTests()
        {
            // get the connection strings
            AppSettingsReader sr = new AppSettingsReader();
            string            searchServiceName     = sr.ReadValue("SearchServiceName");
            string            searchServiceAdminKey = sr.ReadValue("SearchServiceAdminKey");

            // TO do this test successfully, we need to DELETE THE INDEX!!!
            // THIS TEST IS DESTRUCTIVE
            // make sure this is not production
            Assert.IsFalse(ProdConfiguration.IsProduction(searchServiceName));

            var log = new Log(LogDestination.Debug, Log.DefaultCategoryName);

            // instantiate the search interface
            SocialPlus.Server.Search.SearchTopics searchTopics = new SocialPlus.Server.Search.SearchTopics(log, searchServiceName, searchServiceAdminKey);

            // clean the index
            searchTopics.DeleteIndex().Wait();
            searchTopics.CreateIndex().Wait();
            System.Threading.Thread.Sleep(1000); // there appears to be an Azure delay in indexing

            // insert some items
            List <TopicDocument> topics = new List <TopicDocument>();
            TopicDocument        topic1 = new TopicDocument("topic1", "title1", "text1", new List <string>()
            {
                "jane", "canada"
            }, "app1", "user1", 1, DateTime.Now.AddDays(-21));
            TopicDocument topic2 = new TopicDocument("topic2", "title2", "text2", new List <string>()
            {
                topic1.TopicTags[1], "britain"
            }, topic1.AppHandle, "user2", 1, DateTime.Now.AddDays(-21));
            TopicDocument topic3 = new TopicDocument("topic3", "title3", "text3", new List <string>()
            {
                topic1.TopicTags[0]
            }, topic1.AppHandle, "user3", 1, DateTime.Now.AddDays(-21));
            TopicDocument topic4 = new TopicDocument("topic4", "title4", "text4", new List <string>()
            {
                "california", "!!hai!!"
            }, "app2", "user4", 1, DateTime.Now);
            TopicDocument topic5 = new TopicDocument("topic5", "title5", "text5", new List <string>()
            {
                topic4.TopicTags[0]
            }, topic4.AppHandle, "user5", 1, DateTime.Now);
            TopicDocument topic6 = new TopicDocument("topic6", "title6", "text6", new List <string>()
            {
                topic4.TopicTags[1]
            }, topic4.AppHandle, "user6", 1, DateTime.Now);
            TopicDocument topic7 = new TopicDocument("topic7", "title7", "text7", new List <string>()
            {
                topic4.TopicTags[1], "cantilever"
            }, topic4.AppHandle, "user7", 1, DateTime.Now);

            topics.Add(topic1);
            topics.Add(topic2);
            topics.Add(topic3);
            topics.Add(topic4);
            topics.Add(topic5);
            topics.Add(topic6);
            topics.Add(topic7);
            searchTopics.AddTopics(topics).Wait();
            System.Threading.Thread.Sleep(1000); // there appears to be an Azure delay in indexing

            // test trending topics
            TimeSpan month = new TimeSpan(31, 0, 0, 0);
            TimeSpan week  = new TimeSpan(7, 0, 0, 0);
            List <Tuple <string, double> > trendingTopics = searchTopics.GetTrendingTopicTags(month).Result;

            Assert.AreEqual(trendingTopics.Count, 6);
            Assert.AreEqual(trendingTopics[0].Item1, topic4.TopicTags[1]);
            Assert.AreEqual(trendingTopics[0].Item2, 3);
            Assert.AreEqual(trendingTopics[1].Item2, 2);
            Assert.AreEqual(trendingTopics[2].Item2, 2);
            Assert.AreEqual(trendingTopics[3].Item2, 2);
            Assert.AreEqual(trendingTopics[4].Item2, 1);
            Assert.AreEqual(trendingTopics[5].Item2, 1);

            // test trending topics filtered by app
            trendingTopics = searchTopics.GetTrendingTopicTags(month, topic1.AppHandle).Result;
            Assert.AreEqual(trendingTopics.Count, 3);
            Assert.AreEqual(trendingTopics[0].Item2, 2);
            Assert.AreEqual(trendingTopics[1].Item2, 2);
            Assert.AreEqual(trendingTopics[2].Item1, topic2.TopicTags[1]);
            Assert.AreEqual(trendingTopics[2].Item2, 1);

            // test trending topics for past week
            trendingTopics = searchTopics.GetTrendingTopicTags(week).Result;
            Assert.AreEqual(trendingTopics.Count, 3);
            Assert.AreEqual(trendingTopics[0].Item1, topic4.TopicTags[1]);
            Assert.AreEqual(trendingTopics[0].Item2, 3);
            Assert.AreEqual(trendingTopics[1].Item1, topic4.TopicTags[0]);
            Assert.AreEqual(trendingTopics[1].Item2, 2);
            Assert.AreEqual(trendingTopics[2].Item1, topic7.TopicTags[1]);
            Assert.AreEqual(trendingTopics[2].Item2, 1);

            // test autocomplete
            List <string> autocomplete = new List <string>();

            autocomplete = searchTopics.AutoCompleteTopicTag("bri").Result;
            Assert.AreEqual(autocomplete.Count, 2);
            Assert.IsTrue(autocomplete.Contains(topic1.TopicTags[0]));
            Assert.IsTrue(autocomplete.Contains(topic2.TopicTags[1]));

            // test autocomplete non fuzzy search
            autocomplete = searchTopics.AutoCompleteTopicTag("can").Result;
            Assert.AreEqual(autocomplete.Count, 2);
            Assert.IsTrue(autocomplete.Contains(topic1.TopicTags[1]));
            Assert.IsTrue(autocomplete.Contains(topic7.TopicTags[1]));

            // test autocomplete fuzzy search
            autocomplete = searchTopics.AutoCompleteTopicTag("can", null, true).Result;
            Assert.AreEqual(autocomplete.Count, 3);
            Assert.IsTrue(autocomplete.Contains(topic1.TopicTags[1]));
            Assert.IsTrue(autocomplete.Contains(topic4.TopicTags[0]));
            Assert.IsTrue(autocomplete.Contains(topic7.TopicTags[1]));

            // test autocomplete fuzzy search with app filter
            autocomplete = searchTopics.AutoCompleteTopicTag("can", topic4.AppHandle, true).Result;
            Assert.AreEqual(autocomplete.Count, 2);
            Assert.IsTrue(autocomplete.Contains(topic4.TopicTags[0]));
            Assert.IsTrue(autocomplete.Contains(topic7.TopicTags[1]));

            // test autocomplete with symbols
            autocomplete = searchTopics.AutoCompleteTopicTag("!!h").Result;
            Assert.AreEqual(autocomplete.Count, 1);
            Assert.AreEqual(autocomplete[0], topic4.TopicTags[1]);

            // reset
            searchTopics.DeleteIndex().Wait();
            searchTopics.CreateIndex().Wait();
        }
Beispiel #4
0
        public void AllSearchUsersTests()
        {
            // get the connection strings
            ISettingsReader sr = new AppSettingsReader();
            string          searchServiceName     = sr.ReadValue("SearchServiceName");
            string          searchServiceAdminKey = sr.ReadValue("SearchServiceAdminKey");

            // TO do this test successfully, we need to DELETE THE INDEX!!!
            // THIS TEST IS DESTRUCTIVE
            // make sure this is not production
            Assert.IsFalse(ProdConfiguration.IsProduction(searchServiceName));

            var log = new Log(LogDestination.Debug, Log.DefaultCategoryName);

            // instantiate the search interface
            SocialPlus.Server.Search.SearchUsers searchUsers = new SocialPlus.Server.Search.SearchUsers(log, searchServiceName, searchServiceAdminKey);

            // clean the index
            searchUsers.DeleteIndex().Wait();
            searchUsers.CreateIndex().Wait();
            System.Threading.Thread.Sleep(1000); // there appears to be an Azure delay in indexing

            // insert some items
            List <UserDocument> users = new List <UserDocument>();

            users.Add(new UserDocument("f00_testXXX", "l00_testXXX", "app1", "u00_testXXX"));
            users.Add(new UserDocument("f01_testXXX", "l01_testXXX", "app1", "u01_testXXX"));
            users.Add(new UserDocument("f02_testXXX", "l02_testXXX", "app2", "u02_testXXX"));
            searchUsers.AddUsers(users).Wait();
            System.Threading.Thread.Sleep(1000); // there appears to be an Azure delay in indexing

            // basic search functionality
            List <UserDocumentResult> result1 = searchUsers.Search("l00_testXXX").Result;

            Assert.IsNotNull(result1);
            Assert.AreEqual(result1.Count, 1);
            Assert.AreEqual(result1[0].AppHandle, "app1");
            Assert.AreEqual(result1[0].UserHandle, "u00_testXXX");

            // substring search
            result1 = searchUsers.Search("f0*").Result;
            Assert.IsNotNull(result1);
            Assert.AreEqual(result1.Count, 3);
            List <string> userHandles = result1.ConvertAll <string>(o => o.UserHandle);

            Assert.IsTrue(userHandles.Contains("u00_testXXX"));
            Assert.IsTrue(userHandles.Contains("u01_testXXX"));
            Assert.IsTrue(userHandles.Contains("u02_testXXX"));

            // limit search functionality by app
            result1 = searchUsers.Search("f0*", "app1").Result;
            Assert.IsNotNull(result1);
            Assert.AreEqual(result1.Count, 2);
            userHandles = result1.ConvertAll <string>(o => o.UserHandle);
            Assert.IsTrue(userHandles.Contains("u00_testXXX"));
            Assert.IsTrue(userHandles.Contains("u01_testXXX"));

            // test updates
            UserDocument user = new UserDocument("d00_testXXX", "l00_testXXX", "app1", "u00_testXXX");

            searchUsers.AddUser(user).Wait();
            System.Threading.Thread.Sleep(1000); // there appears to be an Azure delay in indexing
            result1 = searchUsers.Search("d00*").Result;
            Assert.IsNotNull(result1);
            Assert.AreEqual(result1.Count, 1);
            Assert.AreEqual(result1[0].AppHandle, "app1");
            Assert.AreEqual(result1[0].UserHandle, "u00_testXXX");

            // search for limited set of records
            result1 = searchUsers.Search("l0*", null, 1, 2).Result;
            Assert.IsNotNull(result1);
            Assert.AreEqual(result1.Count, 2);
            userHandles = result1.ConvertAll <string>(o => o.UserHandle);
            Assert.IsTrue(userHandles.Contains("u00_testXXX") || userHandles.Contains("u01_testXXX") || userHandles.Contains("u02_testXXX"));
            result1 = searchUsers.Search("l0*", null, 1, 1).Result;
            Assert.IsNotNull(result1);
            Assert.AreEqual(result1.Count, 1);
            userHandles = result1.ConvertAll <string>(o => o.UserHandle);
            Assert.IsTrue(userHandles.Contains("u00_testXXX") || userHandles.Contains("u01_testXXX") || userHandles.Contains("u02_testXXX"));

            // search for non-existent record
            result1 = searchUsers.Search("AA11").Result;
            Assert.AreEqual(result1.Count, 0);

            // number of records
            long numRecords = searchUsers.GetNumberOfDocuments().Result;

            Assert.AreNotEqual(numRecords, -1);

            // number of bytes
            long numBytes = searchUsers.GetStorageUsage().Result;

            Assert.AreNotEqual(numBytes, -1);

            // delete
            searchUsers.DeleteUser("u00_testXXX", "app1").Wait();
            searchUsers.DeleteUser("u01_testXXX", "app1").Wait();
            searchUsers.DeleteUser("u02_testXXX", "app2").Wait();
            System.Threading.Thread.Sleep(1000); // there appears to be an Azure delay in indexing
            result1 = searchUsers.Search("*test*").Result;
            Assert.AreEqual(result1.Count, 0);
        }
Beispiel #5
0
        /// <summary>
        /// Parse the command line arguments and perform some validation checks.
        /// </summary>
        /// <param name="args">command line arguments</param>
        private static void ParseArgs(string[] args)
        {
            string order = null;
            int    i     = 0;

            while (i < args.Length)
            {
                if (args[i].StartsWith("-Action=", StringComparison.CurrentCultureIgnoreCase))
                {
                    int prefixLen = "-Action=".Length;
                    action = args[i].Substring(prefixLen);
                    i++;
                    continue;
                }
                else if (args[i].StartsWith("-Container=", StringComparison.CurrentCultureIgnoreCase))
                {
                    int prefixLen = "-Container=".Length;
                    containerName = args[i].Substring(prefixLen);
                    i++;
                    continue;
                }
                else if (args[i].StartsWith("-FK=", StringComparison.CurrentCultureIgnoreCase))
                {
                    int prefixLen = "-FK=".Length;
                    feedKey = args[i].Substring(prefixLen);
                    i++;
                    continue;
                }
                else if (args[i].StartsWith("-Name=", StringComparison.CurrentCultureIgnoreCase))
                {
                    int prefixLen = "-Name=".Length;
                    environmentName = args[i].Substring(prefixLen);
                    i++;
                    continue;
                }
                else if (args[i].StartsWith("-OK=", StringComparison.CurrentCultureIgnoreCase))
                {
                    int prefixLen = "-OK=".Length;
                    objKey = args[i].Substring(prefixLen);
                    i++;
                    continue;
                }
                else if (args[i].StartsWith("-Order=", StringComparison.CurrentCultureIgnoreCase))
                {
                    int prefixLen = "-Order=".Length;
                    order = args[i].Substring(prefixLen);

                    // if order is specified, make sure it is a valid choice
                    if (!(order.Equals("ascending", StringComparison.CurrentCultureIgnoreCase) ||
                          order.Equals("descending", StringComparison.CurrentCultureIgnoreCase)))
                    {
                        Console.WriteLine("Usage error: order must be ascending or descending");
                        Usage();
                        Environment.Exit(0);
                    }

                    i++;
                    continue;
                }
                else if (args[i].Equals("-Persistent", StringComparison.CurrentCultureIgnoreCase))
                {
                    redisType = RedisType.Persistent;
                    i++;
                    continue;
                }
                else if (args[i].StartsWith("-PK=", StringComparison.CurrentCultureIgnoreCase))
                {
                    int prefixLen = "-PK=".Length;
                    partitionKey = args[i].Substring(prefixLen);
                    i++;
                    continue;
                }
                else if (args[i].StartsWith("-Table=", StringComparison.CurrentCultureIgnoreCase))
                {
                    int prefixLen = "-Table=".Length;
                    tableName = args[i].Substring(prefixLen);
                    i++;
                    continue;
                }
                else if (args[i].Equals("-Volatile"))
                {
                    redisType = RedisType.Volatile;
                    i++;
                    continue;
                }
                else
                {
                    // default case
                    Console.WriteLine($"Unrecognized parameter: {args[i]}");
                    i++;
                }
            }

            if (string.IsNullOrWhiteSpace(environmentName))
            {
                Console.WriteLine("Usage error: must specify name of environment");
                Usage();
                Environment.Exit(0);
            }

            if (action != "delete" && action != "get" && action != "get-info" && action != "get-rank-feed")
            {
                Console.WriteLine("Usage error: invalid action.");
                Console.WriteLine("             Supported actions are delete, get, get-info, get-rank-feed");
                Usage();
                Environment.Exit(0);
            }

            if (action == "get-rank-feed")
            {
                if (order == null)
                {
                    Console.WriteLine("Usage error: must specify ordering for get-rank-feed");
                    Usage();
                    Environment.Exit(0);
                }

                if (order.Equals("ascending", StringComparison.CurrentCultureIgnoreCase))
                {
                    rankFeedOrder = Order.Ascending;
                }
                else if (order.Equals("descending", StringComparison.CurrentCultureIgnoreCase))
                {
                    rankFeedOrder = Order.Descending;
                }

                if (feedKey == null)
                {
                    Console.WriteLine("Usage error: must specify feed key for get-rank-feed");
                    Usage();
                    Environment.Exit(0);
                }
            }

            if (action == "get" || action == "delete")
            {
                if (objKey == null)
                {
                    Console.WriteLine("Usage error: must specify object key for get or delete");
                    Usage();
                    Environment.Exit(0);
                }
            }

            if (action != "get-info" && (containerName == null || tableName == null || partitionKey == null))
            {
                Console.WriteLine("Usage error: must specify container name, table name, partition key.");
                Usage();
                Environment.Exit(0);
            }

            // avoid accidental modification to a persistent Redis instance in a production environment
            if (action == "delete" && redisType == RedisType.Persistent && ProdConfiguration.IsProduction(environmentName))
            {
                Console.WriteLine("Error! Your configuration modifies a production service. Aborting...");
                Environment.Exit(-1);
            }
        }
Beispiel #6
0
        /// <summary>
        /// gets the current config from app.config, make sure it is not a production environment, prints the configuration
        /// </summary>
        /// <param name="environmentName">name of the environment that will be created or cleaned</param>
        /// <param name="kvr">key vault settings reader</param>
        /// <returns>validate and print task</returns>
        private static async Task ValidateAndPrintConfiguration(string environmentName, ISettingsReaderAsync kvr)
        {
            if (doAll || doSearch)
            {
                // check that all of the required settings are not null or whitespace
                if (string.IsNullOrWhiteSpace(await kvr.ReadValueAsync("SearchServiceName")))
                {
                    Console.WriteLine("Error! SearchServiceName in your configuration is null or whitespace. Aborting...");
                    System.Environment.Exit(-1);
                }

                if (string.IsNullOrWhiteSpace(await kvr.ReadValueAsync("SearchServiceAdminKey")))
                {
                    Console.WriteLine("Error! SearchServiceAdminKey in your configuration is null or whitespace. Aborting...");
                    System.Environment.Exit(-1);
                }
            }

            if (doAll || doQueues)
            {
                if (string.IsNullOrWhiteSpace(await kvr.ReadValueAsync("ServiceBusConnectionString")))
                {
                    Console.WriteLine("Error! ServiceBusConnectionString in your configuration is null or whitespace. Aborting...");
                    System.Environment.Exit(-1);
                }
            }

            if (doAll || doTables)
            {
                if (string.IsNullOrWhiteSpace(await kvr.ReadValueAsync("AzureStorageConnectionString")))
                {
                    Console.WriteLine("Error! AzureStorageConnectionString in your configuration is null or whitespace. Aborting...");
                    System.Environment.Exit(-1);
                }
            }

            if (doAll || doBlobs || doLogs)
            {
                if (string.IsNullOrWhiteSpace(await kvr.ReadValueAsync("AzureBlobStorageConnectionString")))
                {
                    Console.WriteLine("Error! AzureBlobStorageConnectionString in your configuration is null or whitespace. Aborting...");
                    System.Environment.Exit(-1);
                }
            }

            if (doAll || doRedis)
            {
                if (string.IsNullOrWhiteSpace(await kvr.ReadValueAsync("VolatileRedisConnectionString")))
                {
                    Console.WriteLine("Error! VolatileRedisConnectionString in your configuration is null or whitespace. Aborting...");
                    System.Environment.Exit(-1);
                }

                if (string.IsNullOrWhiteSpace(await kvr.ReadValueAsync("PersistentRedisConnectionString")))
                {
                    Console.WriteLine("Error! PersistentRedisConnectionString in your configuration is null or whitespace. Aborting...");
                    System.Environment.Exit(-1);
                }
            }

            // for clean operations, make sure we are not operating on a production service
            if (doClean && (ProdConfiguration.IsProduction(await kvr.ReadValueAsync("SearchServiceName")) ||
                            ProdConfiguration.IsProduction(await kvr.ReadValueAsync("ServiceBusConnectionString")) ||
                            ProdConfiguration.IsProduction(await kvr.ReadValueAsync("AzureStorageConnectionString")) ||
                            ProdConfiguration.IsProduction(await kvr.ReadValueAsync("AzureBlobStorageConnectionString")) ||
                            ProdConfiguration.IsProduction(await kvr.ReadValueAsync("VolatileRedisConnectionString")) ||
                            ProdConfiguration.IsProduction(await kvr.ReadValueAsync("PersistentRedisConnectionString"))))
            {
                Console.WriteLine("Error! Your configuration includes a production service. Aborting...");
                System.Environment.Exit(-1);
            }

            Console.WriteLine();
            Console.Write("Environment name: ");
            Console.WriteLine(environmentName);
            Console.WriteLine();
            Console.WriteLine("Current configuration:");
            if (doAll || doSearch)
            {
                Console.WriteLine("\tsearch service name: " + await kvr.ReadValueAsync("SearchServiceName"));
                Console.WriteLine("\tsearch admin key: " + await kvr.ReadValueAsync("SearchServiceAdminKey"));
            }

            if (doAll || doQueues)
            {
                Console.WriteLine("\tservice bus connection string: " + await kvr.ReadValueAsync("ServiceBusConnectionString"));
            }

            if (doAll || doTables)
            {
                Console.WriteLine("\tazure table storage string: " + await kvr.ReadValueAsync("AzureStorageConnectionString"));
            }

            if (doAll || doBlobs || doLogs)
            {
                Console.WriteLine("\tazure blob storage string: " + await kvr.ReadValueAsync("AzureBlobStorageConnectionString"));
            }

            if (doAll || doRedis)
            {
                Console.WriteLine("\tredis connection strings: ");
                Console.WriteLine("\t Volatile = {0}", await kvr.ReadValueAsync("VolatileRedisConnectionString"));
                Console.WriteLine("\t Persistent = {0}", await kvr.ReadValueAsync("PersistentRedisConnectionString"));
            }

            Console.WriteLine();
            Console.WriteLine();
        }