Пример #1
0
        //文字列形式から作成
        public static PluginManifest CreateByText(string text)
        {
            PluginManifest m = new PluginManifest();

            StructuredText s = new TextStructuredTextReader(new StringReader(text)).Read();

            if (s.Name == "manifest")
            {
                foreach (object manifestChild in s.Children)
                {
                    StructuredText assemblyEntryNode = manifestChild as StructuredText;
                    if (assemblyEntryNode != null)
                    {
                        PluginManifest.AssemblyEntry entry = m.AddAssembly(assemblyEntryNode.Name);
                        foreach (object assemblyEntryChild in assemblyEntryNode.Children)
                        {
                            StructuredText.Entry pluginEntry = assemblyEntryChild as StructuredText.Entry;
                            if (pluginEntry != null && pluginEntry.name == "plugin")
                            {
                                entry.AddPluginType(pluginEntry.value);
                            }
                        }
                    }
                }
            }

            return(m);
        }
Пример #2
0
        internal void LoadFrom(StructuredText node)
        {
            bool dirty       = false;
            int  child_index = 0;
            int  data_index  = 0;

            while (child_index < _children.Count)
            {
                IPreferenceItemBase   child     = (IPreferenceItemBase)_children[child_index];
                PreferenceFolder      ch_folder = child as PreferenceFolder;
                PreferenceFolderArray ch_array  = child as PreferenceFolderArray;
                PreferenceItem        ch_item   = child as PreferenceItem;
                PreferenceLooseNode   ch_loose  = child as PreferenceLooseNode;

                //TODO 以下の分岐汚すぎ、何とかする

                if (ch_folder != null)
                {
                    StructuredText ch_data = node.GetChildOrNull(data_index);                     //大抵はうまく整列しているので検索の手間を省く
                    if (ch_data == null || ch_data.Name != ch_folder.Id)
                    {
                        dirty   = true;
                        ch_data = node.FindChild(ch_folder.Id);
                    }
                    else
                    {
                        data_index++;
                    }

                    if (ch_data == null)
                    {
                        ch_folder.ResetValue();
                    }
                    else
                    {
                        ch_folder.LoadFrom(ch_data);
                    }
                }
                else if (ch_item != null)
                {
                    StructuredText.Entry ch_data = node.GetEntryOrNull(data_index);                     //大抵はうまく整列しているので検索の手間を省く
                    if (ch_data == null || ch_data.name != ch_item.Id)
                    {
                        dirty   = true;
                        ch_data = node.FindEntry(ch_item.Id);
                    }
                    else
                    {
                        data_index++;
                    }

                    if (ch_data == null)
                    {
                        ch_item.ResetValue();
                    }
                    else
                    {
                        ch_item.TryToParse(ch_data.value, PreferenceItem.ErrorMode.Reset);
                    }
                }
                else if (ch_array != null)
                {
                    ArrayList      ch_data = new ArrayList();
                    StructuredText t       = node.GetChildOrNull(data_index);
                    if (t == null || t.Name != ch_array.Id)
                    {
                        dirty = true;
                        ch_data.Clear();
                        ch_data.AddRange(node.FindMultipleNote(ch_array.Id));
                    }
                    else                       //最初の一つが合格だったら継続して読み続ける
                    {
                        data_index++;
                        while (t != null && t.Name == ch_array.Id)
                        {
                            ch_data.Add(t);
                            t = node.GetChildOrNull(data_index++);
                        }
                    }

                    ch_array.LoadFrom(ch_data);
                }
                else if (ch_loose != null)
                {
                    //TODO これはFolderのときと同じだ。まとめよう
                    StructuredText ch_data = node.GetChildOrNull(data_index);     //大抵はうまく整列しているので検索の手間を省く
                    if (ch_data == null || ch_data.Name != ch_loose.Id)
                    {
                        dirty   = true;
                        ch_data = node.FindChild(ch_loose.Id);
                    }
                    else
                    {
                        data_index++;
                    }

                    if (ch_data == null)
                    {
                        ch_loose.ResetValue();
                    }
                    else
                    {
                        ch_loose.LoadFrom(ch_data);
                    }
                }

                child_index++;                 //自分の子をステップ
            }

            //一度エラーなく読むことができていればdirtyはfalseのまま
            node.IsDirty = dirty;
        }