Beispiel #1
0
        //  public bool postHopAddition(hoplist hopaddition)
        //  {
        //      RegistryKey adsfa = Registry.CurrentUser.OpenSubKey("SOFTWARE/Brewmeister");
        //      string dataurl = GetDataProvider();
        //      var client = new RestClient(dataurl);
        //      RestRequest request = new RestRequest();
        //      if (hopaddition.id == "")
        //      {
        //          request = new RestRequest("/hopaddition/", Method.POST);
        //      } else {
        //          request = new RestRequest("/hopaddition/" + hopaddition.id, Method.POST);
        //      }
        //      request.RequestFormat = DataFormat.Json;
        //      request.AddHeader("Content-type", "application/json");
        //      request.AddJsonBody(
        //      new
        //      {
        //          recipeID = hopaddition.recipeID,
        //          hopID = hopaddition.hopID,
        //          amount = hopaddition.amount,
        //          type = hopaddition.type,
        //          time = hopaddition.time
        //      });
        //
        //      IRestResponse response = client.Execute(request);
        //      return true;
        //  }

        //   public string postFermentableAddition(fermentablelist fermentableAddition)
        //   {
        //       RegistryKey adsfa = Registry.CurrentUser.OpenSubKey("SOFTWARE/Brewmeister");
        //       string dataurl = GetDataProvider();
        //       var client = new RestClient(dataurl);
        //       RestRequest request = new RestRequest();
        //       string returnable = "";
        //       if (fermentableAddition.id == null)
        //       {
        //           request = new RestRequest("/fermentableaddition/", Method.POST);
        //           returnable = "false";
        //       }
        //       else
        //       {
        //           request = new RestRequest("/fermentableaddition/" + fermentableAddition.id, Method.POST);
        //           returnable = fermentableAddition.id;
        //       }
        //       request.RequestFormat = DataFormat.Json;
        //       request.AddHeader("Content-type", "application/json");
        //       request.AddJsonBody(
        //       new
        //       {
        //           recipeID = fermentableAddition.recipeID,
        //           fermentableID = fermentableAddition.fermentableID,
        //           fermentable = fermentableAddition.fermentable,
        //           use = "Mash",
        //           weight = fermentableAddition.weight
        //       });
        //
        //       IRestResponse response = client.Execute(request);
        //       return returnable;
        //   }

        //     public bool postYeastAddition(yeastlist yeastAddition)
        //     {
        //         RegistryKey adsfa = Registry.CurrentUser.OpenSubKey("SOFTWARE/Brewmeister");
        //         string dataurl = GetDataProvider();
        //         var client = new RestClient(dataurl);
        //         RestRequest request = new RestRequest();
        //         if (yeastAddition.ID == null)
        //         {
        //             request = new RestRequest("/yeastaddition/", Method.POST);
        //         }
        //         else
        //         {
        //             request = new RestRequest("/yeastaddition/" + yeastAddition.ID, Method.POST);
        //         }
        //         request.RequestFormat = DataFormat.Json;
        //         request.AddHeader("Content-type", "application/json");
        //         request.AddJsonBody(
        //         new
        //         {
        //             recipeID = yeastAddition.recipeID,
        //             yeastID = yeastAddition.yeastID
        //         });
        //
        //         IRestResponse response = client.Execute(request);
        //         return true;
        //     }

        //     public bool postAdjunctAddition(adjunctList adjunctAddition)
        //     {
        //         RegistryKey adsfa = Registry.CurrentUser.OpenSubKey("SOFTWARE/Brewmeister");
        //         string dataurl = GetDataProvider();
        //         var client = new RestClient(dataurl);
        //         RestRequest request = new RestRequest();
        //         if (adjunctAddition.id == null)
        //         {
        //             request = new RestRequest("/adjunctaddition/", Method.POST);
        //         }
        //         else
        //         {
        //             request = new RestRequest("/adjunctaddition/" + adjunctAddition.id, Method.POST);
        //         }
        //         request.RequestFormat = DataFormat.Json;
        //         request.AddHeader("Content-type", "application/json");
        //         request.AddJsonBody(
        //         new
        //         {
        //             recipeID = adjunctAddition.recipeID,
        //             adjunctID = adjunctAddition.adjunctID,
        //             amount = adjunctAddition.amount,
        //             unit = adjunctAddition.unit,
        //             time = adjunctAddition.time,
        //             timeUnit = adjunctAddition.timeUnit,
        //             type = adjunctAddition.type
        //         });
        //
        //         IRestResponse response = client.Execute(request);
        //         return true;
        //     }
        public recipeResponse postRecipe(recipe2 recipe)
        {
            RegistryKey adsfa   = Registry.CurrentUser.OpenSubKey("SOFTWARE/Brewmeister");
            string      dataurl = GetDataProvider();
            var         client  = new RestClient(dataurl);
            RestRequest request = new RestRequest();

            if (recipe.idString == null)
            {
                recipe.id          = new id();
                recipe.recipeStats = new RecipeStatistics();
                request            = new RestRequest("/beernet/recipe/", Method.POST);
            }
            else
            {
                request = new RestRequest("/beernet/recipe/" + recipe.idString, Method.POST);
            }
            request.RequestFormat = DataFormat.Json;
            request.AddHeader("Content-type", "application/json");
            request.AddJsonBody(recipe);
            IRestResponse  response   = client.Execute(request);
            recipeResponse returnable = JsonConvert.DeserializeObject <recipeResponse>(response.Content);

            return(returnable);
        }
Beispiel #2
0
 private void newBeerToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (var newBeer = new New_Beer())
     {
         var     result    = newBeer.ShowDialog();;
         recipe2 newRecipe = new recipe2();
         if (result == DialogResult.OK)
         {
             newRecipe.name        = newBeer.BeerName;
             newRecipe.style       = newBeer.BeerStyle;
             newRecipe.description = newBeer.BeerDescription;
             APIHandler handler = new APIHandler();
             // handler.postRecipe(newRecipe);
         }
     }
 }
Beispiel #3
0
        public recipe2 loadRecipe(string currentRecipeKey)
        {
            RegistryKey adsfa      = Registry.CurrentUser.OpenSubKey("SOFTWARE/Brewmeister");
            recipe2     returnable = new recipe2();
            string      dataurl    = GetDataProvider();
            // if (adsfa.GetValue("DataProvider").ToString() == "True")
            // {
            string recipeURL = dataurl + "/beernet/recipe/" + currentRecipeKey;
            //  string fermentableURL = dataurl + "/fermentableaddition?recipeID=" + currentRecipeKey + "&include=fermentable";
            //  string hopURL = dataurl + "/hopaddition?recipeID=" + currentRecipeKey + "&include=hop";
            //  string yeastURL = dataurl + "/yeastaddition?recipeID=" + currentRecipeKey + "&include=yeast";
            //  string adjunctURL = dataurl + "/adjunctaddition?recipeID=" + currentRecipeKey + "&include=adjunct";

            List <fermentablelist> fermentableList = new List <fermentablelist>();
            List <hoplist>         hopList         = new List <hoplist>();
            List <yeastlist>       yeastList       = new List <yeastlist>();
            List <adjunctList>     adjunctList     = new List <adjunctList>();

            string json = new WebClient().DownloadString(recipeURL);

            returnable = JsonConvert.DeserializeObject <recipe2>(json);
            //  json = new WebClient().DownloadString(fermentableURL);
            //   fermentableList = JsonConvert.DeserializeObject<List<fermentablelist>>(json);
            //   json = new WebClient().DownloadString(hopURL);
            //   hopList = JsonConvert.DeserializeObject<List<hoplist>>(json);
            //   json = new WebClient().DownloadString(yeastURL);
            //   yeastList = JsonConvert.DeserializeObject<List<yeastlist>>(json);
            //   json = new WebClient().DownloadString(adjunctURL);
            //   adjunctList = JsonConvert.DeserializeObject<List<adjunctList>>(json);
            //   returnable.fermentables = fermentableList;
            //   returnable.hops = hopList;
            //   returnable.yeasts = yeastList;
            //   returnable.adjuncts = adjunctList;
            int i = 1;

            adsfa = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE/Brewmeister", RegistryKeyPermissionCheck.ReadWriteSubTree);
            adsfa.SetValue("LastOpenedRecipe", currentRecipeKey);

            //   }
            //   else
            //   {
            //       //I do not like this.
            //   }


            return(returnable);
        }
Beispiel #4
0
        private void viewRecipesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            View_Recipes recipeViewer = new View_Recipes();
            APIHandler   handler      = new APIHandler();

            //recipeViewer.dataurl = dataurl;
            recipeViewer.ShowDialog();
            string currentRecipeKey = recipeViewer.currentSelectedRecipe;

            if (currentRecipeKey != null)
            {
                currentRecipe = null;
                currentRecipe = handler.loadRecipe(currentRecipeKey);
                populateGrids();
                RefreshStatistics();
            }
        }
Beispiel #5
0
        private void newRecipeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // using (var newBeer = new New_Beer())
            // {
            //     var result = newBeer.ShowDialog(); ;
            //     recipe2 newRecipe = new recipe2();
            //     if (result == DialogResult.OK)
            //     {
            //         newRecipe.name = newBeer.BeerName;
            //         newRecipe.style = newBeer.BeerStyle;
            //         newRecipe.description = newBeer.BeerDescription;
            //         APIHandler handler = new APIHandler();
            //      //   handler.postRecipe(newRecipe);
            //     }
            // }

            currentRecipe       = new recipe2();
            BeerNameBox.Text    = "";
            descriptionBox.Text = "";
            populateGrids();
            RefreshStatistics();
            updateStyleSliders();
            BeerNameBox.Focus();
        }
Beispiel #6
0
        private void loadRecipe()
        {
            //load recipe
            //http://rest.unacceptable.beer:2403/recipe?id=decef696bf3f7806&include=fullrecipe

            string     jsonurl = dataurl + "/recipe?id=" + currentRecipeKey + "&include=fullrecipe";
            string     json    = new WebClient().DownloadString(jsonurl);
            APIHandler handler = new APIHandler();

            currentRecipe = handler.loadRecipe(currentRecipeKey);
            //currentRecipe = JsonConvert.DeserializeObject<recipe2>(json);
            int i = 1;

            //currentRecipe.name = rootObject.name;

            //var objects = JArray.Parse(json);
            //int i = 0;
            //foreach (JObject root in objects)
            //{
            //    foreach (KeyValuePair<String, JToken> recipeFromJson in root)
            //    {
            //        switch (recipeFromJson.Key)
            //        {
            //            case "name":
            //                currentRecipe.name = (String)recipeFromJson.Value;
            //                break;
            //            case "style":
            //                currentRecipe.style = (String)recipeFromJson.Value;
            //                break;
            //            case "description":
            //                currentRecipe.description = (String)recipeFromJson.Value;
            //                break;
            //            case "abv":
            //                currentRecipe.abv = (float)recipeFromJson.Value;
            //                break;
            //            case "ibu":
            //                currentRecipe.ibu = (float)recipeFromJson.Value;
            //                break;
            //            case "fg":
            //                currentRecipe.fg = (float)recipeFromJson.Value;
            //                break;
            //            case "og":
            //                currentRecipe.og = (float)recipeFromJson.Value;
            //                break;
            //            case "srm":
            //                currentRecipe.srm = (float)recipeFromJson.Value;
            //                break;
            //            case "version":
            //                currentRecipe.version = (float)recipeFromJson.Value;
            //                break;
            //            case "parentRecipe":
            //                currentRecipe.parentRecipe = (String)recipeFromJson.Value;
            //                break;
            //            case "clonedFrom":
            //                currentRecipe.clonedFrom = (String)recipeFromJson.Value;
            //                break;
            //            case "hidden":
            //                currentRecipe.hidden = (String)recipeFromJson.Value;
            //                break;
            //            case "id":
            //                currentRecipe.key = (String)recipeFromJson.Value;
            //                break;
            //        }
            //    }
            //}

            //load fermentables
            //jsonurl = dataurl + "/fermentableaddition?recipeid=" + currentRecipeKey;
            //if there's only one hop this might break
            //json = new WebClient().DownloadString(jsonurl);
            //objects = JArray.Parse(json);
            //i = 0;
            //foreach (JObject root in objects)
            //{
            //    foreach (KeyValuePair<String, JToken> recipeFromJson in root)
            //    {
            //        switch (recipeFromJson.Key)
            //        {
            //            case "name":
            //                currentRecipe.name = (String)recipeFromJson.Value;
            //                break;
            //        }
            //    }
            //}
            //load hops

            //load yeasts

            //load adjuncts
            RegistryKey adsfa = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE/Brewmeister", RegistryKeyPermissionCheck.ReadWriteSubTree);

            adsfa.SetValue("LastOpenedRecipe", currentRecipeKey);
        }
Beispiel #7
0
        /*
         * Sets all the f*****g shit for the grids and shit.
         * */
        public Recipe_Creator()
        {
            APIHandler handler = new APIHandler();

            //List<fermentable2> fermentableList = handler.getFermentables();
            //DataGridViewComboBoxColumn maltColumn = new DataGridViewComboBoxColumn();
            //maltColumn.DataSource = fermentableList;
            //maltColumn.DisplayMember = "name";
            // maltColumn.ValueMember = "id";
            //currentRecipe = currentRecipeFromMainScreen;
            //Malt Grid Stuff
            InitializeComponent();
            //MaltGrid.Columns.Add(maltColumn);
            MaltGrid.Columns.Add("Name", "Name");
            MaltGrid.Columns[0].ReadOnly = true;
            MaltGrid.Columns.Add("Weight", "Weight");
            MaltGrid.Columns.Add("PPG", "PPG");
            MaltGrid.Columns[2].ReadOnly = true;
            MaltGrid.Columns.Add("Color", "Color");
            MaltGrid.Columns[3].ReadOnly = true;
            DataGridViewCheckBoxColumn ExtractColumn = new DataGridViewCheckBoxColumn();

            ExtractColumn.ReadOnly   = true;
            ExtractColumn.Name       = "Extract";
            ExtractColumn.HeaderText = "Extract";
            MaltGrid.Columns.Add(ExtractColumn);
            MaltGrid.Columns[0].Width   = 150;
            MaltGrid.Columns[1].Width   = 50;
            MaltGrid.Columns[2].Width   = 50;
            MaltGrid.Columns[3].Width   = 50;
            MaltGrid.Columns[4].Width   = 50;
            KitEfficiencyBox.Text       = "" + KitEfficiency;
            IntoFermenterVolumeBox.Text = "" + IntoFermenterVolume;

            //Hop Grid Stuff
            HopGrid.Columns.Add("Name", "Name");
            HopGrid.Columns[0].ReadOnly = true;
            DataGridViewComboBoxColumn typeColumn = new DataGridViewComboBoxColumn();

            typeColumn.Name = "Type";
            typeColumn.Items.Add("Boil");
            typeColumn.Items.Add("Dry Hop");
            typeColumn.Items.Add("Whirlpool");
            typeColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
            HopGrid.Columns.Add(typeColumn);
            //HopGrid.Columns.Add("Type", "Type");
            HopGrid.Columns.Add("Amount", "Amount");
            HopGrid.Columns.Add("AAU", "AAU");
            HopGrid.Columns[3].ReadOnly = true;
            HopGrid.Columns.Add("Time", "Time");
            HopGrid.Columns[0].Width = 150;
            HopGrid.Columns[1].Width = 100;
            HopGrid.Columns[2].Width = 50;
            HopGrid.Columns[3].Width = 50;
            HopGrid.Columns[4].Width = 50;

            //Yeast Grid Stuff
            YeastGrid.Columns.Add("Lab", "Lab");
            YeastGrid.Columns[0].ReadOnly = true;
            YeastGrid.Columns.Add("Product", "Product");
            YeastGrid.Columns[1].ReadOnly = true;
            YeastGrid.Columns.Add("Attenuation", "Attenuation");
            YeastGrid.Columns[2].ReadOnly = true;
            YeastGrid.Columns[0].Width    = 100;
            YeastGrid.Columns[1].Width    = 100;
            YeastGrid.Columns[2].Width    = 100;
            RefreshStatistics();

            //Other Ingredients Grid Stuff
            OtherIngredientsGrid.Columns.Add("Name", "Name");
            OtherIngredientsGrid.Columns.Add("Amount", "Amount");
            OtherIngredientsGrid.Columns.Add("Unit", "Unit");
            OtherIngredientsGrid.Columns.Add("Time", "Time");
            OtherIngredientsGrid.Columns.Add("TimeUnit", "TimeUnit");
            OtherIngredientsGrid.Columns.Add("Type", "Type");


            RegistryKey adsfa = Registry.CurrentUser.OpenSubKey("SOFTWARE/Brewmeister");

            if (adsfa != null)
            {
                if (adsfa.GetValue("DataProvider").ToString() == "True")
                {
                    dataurl = "" + adsfa.GetValue("BeerNetAddress");
                }
                else
                {
                    dataurl = "" + adsfa.GetValue("DeploydAddress");
                }
                string currentRecipeKey = "" + adsfa.GetValue("LastOpenedRecipe");
                try
                {
                    //LastOpenedFileLocation = "" + adsfa.GetValue("LastOpenedFileLocation");
                    //openFile(LastOpenedFileLocation);
                    adsfa.Close();
                    currentRecipe = handler.loadRecipe(currentRecipeKey);
                    populateGrids();
                    RefreshStatistics();
                }
                catch (Exception esdjjs)
                {
                }
            }
            else
            {
                API_URL_Settings settings = new API_URL_Settings();
                settings.ShowDialog();
                dataurl = settings.restAPIURL;
                adsfa   = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("SOFTWARE/Brewmeister");
                adsfa.SetValue("dataurl", dataurl);
                adsfa.SetValue("LastOpenedRecipe", "");
                adsfa.Close();
            }

            //  populateGrids();
            //  RefreshStatistics();
            //  updateStyleSliders();
        }