Ejemplo n.º 1
0
        public override void SaveToSource(ParameterSetting setting, ObjectField[] fields)
        {
            sjon.UpdateFieldItems(setting, fields);
            var jsontxt = sjon.Serialize();

            SaveConfigTxt(jsonfile, jsontxt);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 保存资源
 /// </summary>
 public abstract void SaveToSource(ParameterSetting setting, ObjectField[] fields);
Ejemplo n.º 3
0
        /// <summary>
        /// 保存资源
        /// </summary>
        public override void SaveToSource(ParameterSetting setting, ObjectField[] fields)
        {
            foreach (var field in fields)
            {
                var thin  = field.Type.GetTypeInfoN();
                var value = field.GetValue(setting);
                var name  = field.Name;
                if (thin.IsArray || thin.IsIList)
                {
                    var values = (IList)value;
                    var nodes  = appSettings.SelectNodes("add[@key='" + name + "']").ToArray <XmlNode>();
                    if (nodes.Length > 0)
                    {
                        //先删除以前的
                        RemoveSummary(nodes[0]);
                        foreach (var node in nodes)
                        {
                            appSettings.RemoveChild(node);
                        }
                    }
                    if (values != null && values.Count > 0)
                    {
                        for (var i = 0; i < values.Count; i++)
                        {
                            var item = values[i];
                            AddSetting(field, item);
                        }
                    }
                }
                else
                {
                    var node = appSettings.SelectSingleNode("add[@key='" + name + "']");
                    if (node == null)
                    {
                        AddSetting(field, value);
                    }
                    else
                    {
                        updateSetting(field, value, node);
                    }
                }
            }
            if (appSettings != null)
            {
                if (xmlFile.IsEmpty())
                {
                    xmlFile = NRails.Util.EnvH.EntryPath + ".config";
                }
                var    restart = 3;
                byte[] bytes   = null;
Start:
                try
                {
                    using (var stream = new MemoryStream())
                    {
                        appSettings.OwnerDocument.Save(stream);
                        stream.Flush();
                        bytes = stream.ToArray();
                        SaveConfigTxt(xmlFile, Encs.UTF8.GetString(bytes));
                    }
                } catch (Exception ex)
                {
                    if (restart-- > 0)
                    {
                        goto Start;
                    }
                    throw ex.CreateNew();
                }
            }
        }