예제 #1
0
        public ActionResult OnPost()
        {
            base.Init();

            JsonResult result = new JsonResult("Error saving preset file.");

            MemoryStream stream = new MemoryStream();

            Request.Body.CopyTo(stream);
            stream.Position = 0;
            using (StreamReader reader = new StreamReader(stream)) {
                string requestBody = reader.ReadToEnd();
                if (requestBody.Length > 0)
                {
                    SavePresetFileForm spff = JsonConvert.DeserializeObject <SavePresetFileForm>(requestBody);
                    if (spff != null)
                    {
                        string settingPropertiesPath = PTMagicBasePath + Constants.PTMagicPathPresets + Path.DirectorySeparatorChar + spff.SettingName + Path.DirectorySeparatorChar + spff.FileName;
                        if (System.IO.File.Exists(settingPropertiesPath))
                        {
                            try {
                                System.IO.File.WriteAllText(settingPropertiesPath, spff.FileContent);
                            } catch { }
                        }
                    }
                }
            }

            return(result);
        }
예제 #2
0
        public ActionResult OnPost()
        {
            base.Init();

            Response.StatusCode = (int)HttpStatusCode.InternalServerError;
            JsonResult result = new JsonResult("Error saving preset file.");

            MemoryStream stream = new MemoryStream();

            Request.Body.CopyTo(stream);
            stream.Position = 0;
            using (StreamReader reader = new StreamReader(stream)) {
                string requestBody = reader.ReadToEnd();
                if (requestBody.Length > 0)
                {
                    SavePresetFileForm spff = JsonConvert.DeserializeObject <SavePresetFileForm>(requestBody);
                    if (spff != null)
                    {
                        spff.FileName = spff.FileName.Replace(".PROPERTIES", ".properties");
                        string settingPropertiesPath = PTMagicBasePath + Constants.PTMagicPathPresets + Path.DirectorySeparatorChar + spff.SettingName + Path.DirectorySeparatorChar + spff.FileName;
                        if (System.IO.File.Exists(settingPropertiesPath))
                        {
                            try {
                                System.IO.File.WriteAllText(settingPropertiesPath, spff.FileContent);
                                Response.StatusCode = (int)HttpStatusCode.OK;
                                result = new JsonResult("Settings saved to file " + spff.FileName + " in " + PTMagicBasePath + Constants.PTMagicPathPresets + Path.DirectorySeparatorChar + spff.SettingName + Path.DirectorySeparatorChar);
                                Log.DoLogDebug("Settings saved to file " + spff.FileName + " in " + PTMagicBasePath + Constants.PTMagicPathPresets + Path.DirectorySeparatorChar + spff.SettingName + Path.DirectorySeparatorChar);
                            } catch (Exception ex) {
                                Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                                result = new JsonResult("Error saving preset file:" + ex.Message);
                                Log.DoLogError("Error saving preset file:" + ex.Message);
                            }
                        }
                        else
                        {
                            Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                            result = new JsonResult("Error saving preset file: " + settingPropertiesPath + " not found!");
                            Log.DoLogError("Error saving preset file: " + settingPropertiesPath + " not found!");
                        }
                    }
                }
            }

            return(result);
        }