예제 #1
0
 public async Task WriteConfig(SecretConfig config)
 {
     var request = new PutObjectRequest()
     {
         BucketName  = S3_BUCKET_NAME,
         Key         = S3_KEY_NAME,
         ContentBody = JsonConvert.SerializeObject(config)
     };
     await _s3.PutObjectAsync(request);
 }
예제 #2
0
        /// <summary>
        /// ディスコードのトークンがない場合に登録させます
        /// </summary>
        /// <param name="secret"></param>
        private static void CheckDiscordTokenSecret(SecretConfig secret)
        {
            if (string.IsNullOrWhiteSpace(secret.DiscordToken))
            {
                Console.WriteLine("DiscordのBot用のトークンを入力してください(secret.jsonに保存されるだけなので心配しないで");
                Console.Write(">");
                secret.DiscordToken = Console.ReadLine();
                Console.WriteLine();

                secret.UpdatedAt = DateTime.Now;
                secret.ToJsonFile(SecretConfig.PATH);
            }
        }
예제 #3
0
            //start of processing selections
            static void ProcessMenuSelectionT(string selection)
            {
                string result;

                int custID;

                custID = int.Parse(GetInput("Please enter your customer ID: "));
                SecretConfig  connStr = new SecretConfig();
                SqlConnection conn    = new SqlConnection(connStr.GetConnString());

                result = "dbo.spCustomers_DisplayOrdersByID"; //customer order history
                SqlCommand cmd = new SqlCommand(result, conn);

                cmd.CommandType = CommandType.StoredProcedure;
                SqlParameter param1 = new SqlParameter();

                //declare parameter and its data type
                param1 = cmd.Parameters.Add("@CustomerID", SqlDbType.Int);
                //establish the input or output direction
                param1.Direction = ParameterDirection.Input;
                //give value to the parameter...if not the default will be used.
                param1.Value = custID;
                //open the connection and read the results
                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader();

                Console.WriteLine("");
                while (reader.Read())
                {
                    Console.Write(reader[0].ToString());
                    Console.Write(" ");
                    Console.Write(reader[1].ToString());
                    Console.Write(" ");
                    Console.Write(reader[2].ToString());
                    Console.Write(" ");
                    Console.Write(reader[3].ToString());
                    Console.Write(" ");
                    Console.Write(reader[4].ToString());
                    Console.Write(" ");
                    Console.Write(reader[5].ToString());
                    Console.Write(" ");
                    Console.WriteLine(reader[6].ToString());
                }
                //Console.Read();

                //Close reader and connection
                reader.Close();
                conn.Close();
            }
예제 #4
0
            static void ProcessMenuSelectionU(string selection)
            {
                string result;

                string firstName = GetInput("Please enter the customer's firstname");
                string lastName  = GetInput("Please enter the customer's lastname");

                SecretConfig  connStr = new SecretConfig();
                SqlConnection conn    = new SqlConnection(connStr.GetConnString());

                result = "dbo.spCustomer_GetByFullName";//search customer by name

                SqlCommand cmd = new SqlCommand(result, conn);

                cmd.CommandType = CommandType.StoredProcedure;
                SqlParameter param1 = new SqlParameter();
                SqlParameter param2 = new SqlParameter();

                param1 = cmd.Parameters.Add("@FirstName", SqlDbType.NVarChar, 50);
                param2 = cmd.Parameters.Add("@LastName", SqlDbType.NVarChar, 50);

                param1.Direction = ParameterDirection.Input;
                param2.Direction = ParameterDirection.Input;

                param1.Value = firstName;
                param2.Value = lastName;

                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader();

                Console.WriteLine();
                Console.WriteLine("Customer ID | Perferred Store | First Name | Last Name ");
                while (reader.Read())
                {
                    Console.Write(reader[0].ToString());
                    Console.Write("     ");
                    Console.Write(reader[1].ToString());
                    Console.Write("      ");
                    Console.Write(reader[2].ToString());
                    Console.Write("      ");
                    Console.WriteLine(reader[3].ToString());
                }
                //Console.Read();

                //Close reader and connection
                reader.Close();
                conn.Close();
            }
예제 #5
0
            static void ProcessMenuSelectionR(string selection)
            {
                string result;
                int    storeID;

                SecretConfig  connStr = new SecretConfig();
                SqlConnection conn    = new SqlConnection(connStr.GetConnString());

                storeID = int.Parse(GetInput("Please enter the store number"));
                result  = "dbo.spOrders_GetAllByStore";

                //display all store orders

                SqlCommand cmd = new SqlCommand(result, conn);

                cmd.CommandType = CommandType.StoredProcedure;
                SqlParameter param1 = new SqlParameter();

                param1 = cmd.Parameters.Add("@StoreID", SqlDbType.Int);

                param1.Direction = ParameterDirection.Input;

                param1.Value = storeID;

                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader();

                Console.WriteLine();
                Console.WriteLine("Order ID | Date/Time Stamp | Customer ID | Total ");
                while (reader.Read())
                {
                    Console.Write(reader[0].ToString());
                    Console.Write("     ");
                    Console.Write(reader[1].ToString());
                    Console.Write("      ");
                    Console.Write(reader[2].ToString());
                    Console.Write("      ");
                    Console.WriteLine(reader[3].ToString());
                    Console.WriteLine("      ");
                }
                //Console.Read();

                //Close reader and connection
                reader.Close();
                conn.Close();
            }
예제 #6
0
        /// <summary>
        /// 環境変数をconfigに設定します
        /// </summary>
        /// <param name="config"></param>
        /// <param name="secret"></param>
        private static void ApplyEnvironments(GlobalConfig config, SecretConfig secret)
        {
            Console.WriteLine($"[{DateTime.Now}] 環境変数からconfig.json, secret.jsonの内容を更新します");
            Console.WriteLine($"[{DateTime.Now}] ヒント:docker実行の場合、永続化するためには/app/config.jsonをマウントしてください");
            var props = typeof(GlobalConfig).GetProperties();
            var envs  = Environment.GetEnvironmentVariables();

            foreach (DictionaryEntry env in envs)
            {
                var header = env.Key as string;
                var value  = env.Value as string;
                // 値がない
                if (string.IsNullOrWhiteSpace(header))
                {
                    continue;
                }
                // pu_をプレフィックスにしているか
                var key = header.Replace("PU_", "").Replace("pu_", "");
                if (header.Length == key.Length)
                {
                    continue;
                }
                // Discord Secretを書き直す
                if (key.Equals("DiscordToken"))
                {
                    Console.WriteLine($"[{DateTime.Now}] [Config<-Env] DiscordToken = XXXXXXXXXX");
                    secret.DiscordToken = value as string;
                }
                // GlobalConfigのメンバに当たるやつがいればそれを書き直す
                foreach (var prop in props)
                {
                    if (key.ToLower().Equals(prop.Name.ToLower()))
                    {
                        // 型変換が必要な場合がある。力技
                        object dst = null;
                        var    t   = prop.PropertyType;

                        if (t == typeof(string))
                        {
                            dst = value;
                        }
                        if (t == typeof(bool))
                        {
                            dst = bool.Parse(value);
                        }
                        if (t == typeof(int))
                        {
                            dst = int.Parse(value);
                        }
                        if (t == typeof(double))
                        {
                            dst = double.Parse(value);
                        }
                        if (t == typeof(ulong))
                        {
                            dst = ulong.Parse(value);
                        }
                        Console.WriteLine($"[{DateTime.Now}] [Config<-Env] {prop.Name} = {value}");
                        prop.SetValue(config, dst);
                    }
                }
            }
            config.ToJsonFile(GlobalConfig.PATH);
            Console.WriteLine($"[{DateTime.Now}] 適用終了");
        }
예제 #7
0
            static int ProcessMenuSelectionY(int orderNum)
            {
                int  prodQty;
                int  prodID;
                Menu pick = new Menu();

                pick.ShowProductMenu();
                prodID  = int.Parse(GetInput("Please enter the product number of the item you want."));
                prodQty = int.Parse(GetInput("How many do you want (0 to quit)? "));

                SecretConfig  connStr = new SecretConfig();
                SqlConnection conn    = new SqlConnection(connStr.GetConnString());

                string result2 = "dbo.spOrders_AddToOrder";

                SqlCommand cmd = new SqlCommand(result2, conn);

                cmd.CommandType = CommandType.StoredProcedure;
                SqlParameter param1 = new SqlParameter();
                SqlParameter param2 = new SqlParameter();
                SqlParameter param3 = new SqlParameter();

                param1 = cmd.Parameters.Add("@orderID", SqlDbType.Int);
                param2 = cmd.Parameters.Add("@ProductID", SqlDbType.Int);
                param3 = cmd.Parameters.Add("@ProductQty", SqlDbType.Int);

                param1.Direction = ParameterDirection.Input;
                param2.Direction = ParameterDirection.Input;
                param3.Direction = ParameterDirection.Input;

                param1.Value = orderNum;
                param2.Value = prodID;
                param3.Value = prodQty;

                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader();

                Console.WriteLine();
                Console.WriteLine("Order ID | Date/Time Stamp | Store ID | Customer ID |");
                while (reader.Read())
                {
                    Console.Write(reader[0].ToString());
                    Console.Write("     ");
                    Console.Write(reader[1].ToString());
                    Console.Write("      ");
                    Console.Write(reader[2].ToString());
                    Console.Write("      ");
                    Console.WriteLine(reader[3].ToString());
                    Console.WriteLine("      ");
                    Console.Write(reader[4].ToString());
                    //Console.WriteLine("      ");

                    /*Console.WriteLine(reader[5].ToString());
                    *  /*Console.Write(" ");
                    *  Console.WriteLine(reader[6].ToString());*/
                }
                int orderID = int.Parse(reader[0].ToString());

                //Console.Read();

                //Close reader and connection
                reader.Close();
                conn.Close();
                string selection = GetInput("Have more to buy? [y]");

                if (selection == "y")
                {
                    ProcessMenuSelectionY(orderID);
                }
                else if (prodQty == 0)
                {
                    return(0);
                }
                return(orderID);
            }
예제 #8
0
            //create an order
            static int ProcessMenuSelectionN(string selection)
            {
                string result;
                int    prodQty;
                int    prodID;
                Menu   pick = new Menu();

                string firstName = GetInput("Please enter the customer's firstname");
                string lastName  = GetInput("Please enter the customer's lastname");

                pick.ShowProductMenu();
                prodID  = int.Parse(GetInput("Please enter the product number of the item you want."));
                prodQty = int.Parse(GetInput("How many do you want (0 to quit)? "));

                SecretConfig  connStr = new SecretConfig();
                SqlConnection conn    = new SqlConnection(connStr.GetConnString());

                result = "dbo.spOrders_PlaceToStoreForCustomer";

                SqlCommand cmd = new SqlCommand(result, conn);

                cmd.CommandType = CommandType.StoredProcedure;
                SqlParameter param1 = new SqlParameter();
                SqlParameter param2 = new SqlParameter();
                SqlParameter param3 = new SqlParameter();
                SqlParameter param4 = new SqlParameter();

                param1 = cmd.Parameters.Add("@FirstName", SqlDbType.NVarChar, 50);
                param2 = cmd.Parameters.Add("@LastName", SqlDbType.NVarChar, 50);
                param3 = cmd.Parameters.Add("@ProductID", SqlDbType.Int);
                param4 = cmd.Parameters.Add("@ProductQty", SqlDbType.Int);

                param1.Direction = ParameterDirection.Input;
                param2.Direction = ParameterDirection.Input;
                param3.Direction = ParameterDirection.Input;
                param4.Direction = ParameterDirection.Input;

                param1.Value = firstName;
                param2.Value = lastName;
                param3.Value = prodID;
                param4.Value = prodID;

                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader();

                Console.WriteLine();
                //Console.WriteLine("Order ID | Date/Time Stamp | Store ID | Customer ID | Total ");
                while (reader.Read())
                {/**/
                    Console.Write(reader[0].ToString());
                    Console.Write("     ");
                    Console.Write(reader[1].ToString());
                    Console.Write("      ");
                    Console.Write(reader[2].ToString());
                    Console.Write("      ");
                    Console.WriteLine(reader[3].ToString());
                    //Console.WriteLine("      ");
                    //Console.Write(reader[4].ToString());
                    //Console.WriteLine("      ");
                    //Console.WriteLine(reader[5].ToString());

                    /*Console.Write(" ");
                     * Console.WriteLine(reader[6].ToString());*/
                }
                //int orderID=int.Parse(reader[0].ToString());
                //Console.Read();

                //Close reader and connection
                reader.Close();
                conn.Close();
                //selection = GetInput("Have more to buy? [y]");
                if (selection == "y")
                {
                    return(0);
                }
                return(0);
            }
예제 #9
0
        /*Stacey Joseph, Revature, Project 0
         * Store Implementation
         * C:\Revature\stacey-project0\CornNuggets\Program.cs
         */
        //Core functionality
        //1. add new Customer options: a --> m
        //2. display all order history of a customer options --> t
        //3. Search customers by name --> u
        //4. place orders to store locations for customers --> n
        //5. display all order history of a store --> r
        //6. display details of an order --> d

        static void Main(string[] args)
        {
            //set up the connection to the sql server
            SecretConfig connStr = new SecretConfig();


            //call start menu for add/search/view/exit options
            Menu     start    = new Menu();
            Customer patron   = new Customer();
            Store    location = new Store();
            Order    items    = new Order();

            //essential parameters
            string fname;
            string lname;


            //loop through menu options until exit
            string option;

            fname = start.GetInput("Enter your first name");
            lname = start.GetInput("Enter your last name");

            start.ShowBanner("Options");
            //start.ShowMainMenu();
            start.ShowAddMenu();
            start.ShowSearchMenu();
            start.ShowViewMenu();
            Console.WriteLine();
            do
            {
                option = start.GetInput($"Enter your menu choice {fname}: ");

                if (option == "t")
                {
                    ProcessMenuSelectionT(option);
                }
                else if (option == "m")
                {
                    string firstName = start.GetInput("Enter the new customer's first name");
                    string lastName  = start.GetInput("Enter the new customer's first name");
                    start.ShowStores();
                    string storeName = start.GetInput("Enter the new customer's perferred store name");

                    patron.AddCustomer(firstName, lastName, storeName);
                }
                else if (option == "u")
                {
                    ProcessMenuSelectionU(option);
                }
                else if (option == "r")
                {
                    ProcessMenuSelectionR(option);
                }
                else if (option == "d")
                {
                    ProcessMenuSelectionD(option);
                }
                else if (option == "n")
                {
                    ProcessMenuSelectionN(option);
                }
            }while(option != "e");

            Environment.Exit(0);
예제 #10
0
            static void ProcessMenuSelectionD(string selection)
            {
                string result;

                int orderID;

                orderID = int.Parse(GetInput("Please enter the order number"));

                SecretConfig  connStr = new SecretConfig();
                SqlConnection conn    = new SqlConnection(connStr.GetConnString());

                if (selection == "t")
                {
                    result = "dbo.spCustomers_DisplayOrdersByID";
                }                                                                //customer order history
                else if (selection == "m")
                {
                    result = "dbo.spCustomers_AddNew";
                }                                                         //add new customer
                else if (selection == "u")
                {
                    result = "dbo.spCustomer_GetByFullName";//search customer by name
                }
                else if (selection == "n")
                {
                    result = "dbo.spOrders_PlaceToStoreForCustomer";
                }                                                                       //create order
                else if (selection == "r")
                {
                    orderID = int.Parse(GetInput("Please enter the store number"));
                    result  = "dbo.spOrders_GetAllByStore";
                }//display all store orders
                else if (selection == "d")
                {
                    result = "dbo.spOrders_GetDetails";
                }                                                           //display order details
                else
                {
                    return;
                }
                SqlCommand cmd = new SqlCommand(result, conn);

                cmd.CommandType = CommandType.StoredProcedure;
                SqlParameter param1 = new SqlParameter();

                param1 = cmd.Parameters.Add("@orderID", SqlDbType.Int);


                param1.Direction = ParameterDirection.Input;

                param1.Value = orderID;

                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader();

                Console.WriteLine();
                Console.WriteLine("Order ID |  SubTotal | Prod ID | Date/Time Stamp ");
                while (reader.Read())
                {
                    Console.Write(reader[0].ToString());
                    Console.Write("     ");
                    Console.Write(reader[1].ToString());
                    Console.Write("      ");
                    Console.Write(reader[2].ToString());
                    Console.Write("      ");
                    Console.WriteLine(reader[3].ToString());
                    Console.WriteLine("     ");
                }
                //Console.Read();

                //Close reader and connection
                reader.Close();
                conn.Close();
            }
예제 #11
0
 public ShareController(ILogger <ShareController> logger, IOptions <SecretConfig> secretConfig)
 {
     _logger           = logger;
     this.secretConfig = secretConfig.Value;
     client            = new SiaSkynetClient();
 }