public static string UpdateStaticTextDataSource(DesignerStaticTextDataSource ds)
        {
            string path = Directory.GetCurrentDirectory() + @"\DataSources\StaticText\" + ds.Name + ".bds";

            try
            {
                MemoryStream  Stream = new MemoryStream();
                XmlSerializer xml    = new XmlSerializer(typeof(DesignerStaticTextDataSource));
                //序列化对象
                xml.Serialize(Stream, ds);
                Stream.Position = 0;
                StreamReader sr  = new StreamReader(Stream);
                string       str = sr.ReadToEnd();
                //存到文件

                FileStream   fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                StreamWriter sw = new StreamWriter(fs); // 创建写入流
                sw.Write(str);
                sw.Close();
                sr.Dispose();
                Stream.Dispose();

                //注册该数据源
                DataSourceManager.Register(ds.Name, ds.DataSourceType, ds);
                return(path);
            }
            catch (Exception e)
            {
                throw new Exception("增加静态文本数据源时出错:" + e.Message);
            }
        }
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            DesignerDataSource ds      = null;
            TabItemEx          tabItem = MainTab.SelectedItem as TabItemEx;

            switch (tabItem.Header.ToString())
            {
            case "数据库":
                ds = new DesignerDataBaseDataSource();
                DataBaseDataSourceList.Add(ds as DesignerDataBaseDataSource);
                break;

            case "本地文件":
                throw new NotImplementedException();
                break;

            case "网络资源":
                throw new NotImplementedException();
                break;

            case "静态文本":
                ds = new DesignerStaticTextDataSource();
                StaticTextDataSourceList.Add(ds as DesignerStaticTextDataSource);
                break;

            default:
                throw new NotImplementedException();
            }
            this.SelectedItem = ds;
        }
        public static IEnumerable <DesignerStaticTextDataSource> GetStaticTextDataSources()
        {
            List <DesignerStaticTextDataSource> dss = new List <DesignerStaticTextDataSource>();
            string curDirPath = Directory.GetCurrentDirectory() + @"\DataSources\StaticText";

            //若不存在文件夹则先创建
            if (!Directory.Exists(curDirPath))
            {
                Directory.CreateDirectory(curDirPath);
            }
            DirectoryInfo di = new DirectoryInfo(curDirPath);

            FileInfo[] fis = di.GetFiles();
            try
            {
                foreach (FileInfo fi in fis)
                {
                    string ext = fi.Extension.ToLower();
                    if (ext.IndexOf("bds") == -1 && ext.IndexOf("xml") == -1)
                    {
                        continue;
                    }
                    else
                    {
                        string xml = File.ReadAllText(fi.FullName);
                        using (StringReader sr = new StringReader(xml))
                        {
                            XmlSerializer xmldes            = new XmlSerializer(typeof(DesignerStaticTextDataSource));
                            DesignerStaticTextDataSource ds = xmldes.Deserialize(sr) as DesignerStaticTextDataSource;
                            dss.Add(ds);
                        }
                    }
                }
                return(dss);
            }
            catch (Exception e)
            {
                throw new Exception("读取静态文本数据源时出错:" + e.Message);
            }
        }
 /// <summary>
 /// 执行静态文本数据源,返回字符串
 /// </summary>
 /// <param name="ds"></param>
 /// <returns></returns>
 private static string ExcuteStaticTextDataSource(DesignerStaticTextDataSource ds)
 {
     return(ds.Text);
 }