示例#1
0
        /// <summary>
        /// Creates a populated AssemblerConfig from the app settings for the specified ID.
        /// If the assembler hasn't been configured yet, the default configuration object
        /// will be returned.
        /// </summary>
        /// <param name="settings">Settings object to pull the values from.</param>
        /// <param name="id">Assembler ID.</param>
        /// <returns>The AssemblerConfig.</returns>
        public static AssemblerConfig GetConfig(AppSettings settings, AssemblerInfo.Id id)
        {
            string cereal = settings.GetString(GetSettingName(id), null);

            if (string.IsNullOrEmpty(cereal))
            {
                IAssembler asm = AssemblerInfo.GetAssembler(id);
                return(asm.GetDefaultConfig());
            }

            JavaScriptSerializer ser = new JavaScriptSerializer();

            try {
                AssemblerConfig config = ser.Deserialize <AssemblerConfig>(cereal);
                if (config.ColumnWidths == null || config.ColumnWidths.Length != NUM_COLUMNS)
                {
                    throw new Exception("Bad column widths");
                }
                if (config.ExecutablePath == null)
                {
                    throw new Exception("Missing exe path");
                }
                return(config);
            } catch (Exception ex) {
                Debug.WriteLine("AssemblerConfig deserialization failed: " + ex.Message);
                return(null);
            }
        }