Example #1
0
        public void checkout()
        {
            Utility utility = new Utility();
            HttpContext postedContext = HttpContext.Current;
            HttpFileCollection Files = postedContext.Request.Files;
            string serverKey = utility.Decode((string)postedContext.Request.Form["serverKey"]);

            if (serverKey == utility.GetSettings("Server Key"))
            {
                 string imgName = utility.Decode((string)postedContext.Request.Form["imgName"]);
                 string direction = utility.Decode((string)postedContext.Request.Form["direction"]);
                 string mac = utility.Decode((string)postedContext.Request.Form["mac"]);

                 string result = null;
                 try
                 {
                      using (NpgsqlConnection conn = new NpgsqlConnection(Utility.DBString))
                      {
                           NpgsqlCommand cmd = new NpgsqlCommand("client_checkout", conn);
                           cmd.CommandType = CommandType.StoredProcedure;
                           cmd.Parameters.Add(new NpgsqlParameter("@mac", mac));
                           conn.Open();
                           result = cmd.ExecuteScalar() as string;
                      }

                      Task task = new Task();
                      string pxeHostMac = "01-" + mac.ToLower().Replace(':', '-');
                      task.CleanPxeBoot(pxeHostMac);

                      if (direction == "pull")
                      {
                           string xferMode = utility.GetSettings("Image Transfer Mode");
                           if (xferMode != "udp+http" && xferMode != "smb" && xferMode != "smb+http")
                           {
                                Utility.MoveFolder(utility.GetSettings("Image Hold Path") + imgName, utility.GetSettings("Image Store Path") + imgName);
                                if ((Directory.Exists(utility.GetSettings("Image Store Path") + imgName)) && (!Directory.Exists(utility.GetSettings("Image Hold Path") + imgName)))
                                {
                                     try
                                     {
                                          Directory.CreateDirectory(utility.GetSettings("Image Hold Path") + imgName); // for next upload
                                          result = "Success";
                                     }
                                     catch (Exception ex)
                                     {
                                          Logger.Log(ex.Message);
                                          result = "Could Not Recreate Directory,  You Must Create It Before You Can Upload Again";
                                     }

                                }
                                else
                                     result = "Could Not Move Image From Hold To Store.  You Must Do It Manually.";
                           }
                      }

                 }
                 catch (Exception ex)
                 {
                      result = "Could Not Check Out.  Check The Exception Log For More Info";
                      Logger.Log(ex.ToString());
                 }

                 HttpContext.Current.Response.Write(result);
            }
            else
            {
                 Logger.Log("Incorrect Key For Client Checkout Was Provided");
            }
        }