Exemplo n.º 1
0
 public static ExporterSetting GetSetting()
 {
     if (s_ExporterSetting == null)
     {
         lock (s_SyncObj)
         {
             if (s_ExporterSetting == null)
             {
                 string tmpPath = ConfigurationManager.AppSettings["FileExporterConfigPath"];
                 if (tmpPath == null || tmpPath.Trim().Length <= 0)
                 {
                     tmpPath = Config_File_Path;
                 }
                 else if (!tmpPath.Contains(':')) // 说明配得相对路径
                 {
                     tmpPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, tmpPath);
                 }
                 ExporterSetting tmp = new ExporterSetting();
                 if (File.Exists(tmpPath))
                 {
                     XmlDocument x = new XmlDocument();
                     x.Load(tmpPath);
                     XmlNode node = x.SelectSingleNode("//fileExporter");
                     tmp.Default     = GetNodeAttribute(node, "default");
                     tmp.Expiry      = GetNodeAttribute(node, "expiry");
                     tmp.BaseFolder  = GetNodeAttribute(node, "baseFolder");
                     tmp.VirtualPath = GetNodeAttribute(node, "virtualPath");
                     string max = GetNodeAttribute(node, "maxRowCountLimit");
                     int    limit;
                     if (int.TryParse(max, out limit) && limit > 0)
                     {
                         tmp.MaxRowCountLimit = limit;
                     }
                     XmlNode[] list = GetChildrenNodes(node, "add");
                     tmp.FileExporterList = new Dictionary <string, string>(list.Length * 2);
                     foreach (XmlNode n in list)
                     {
                         tmp.FileExporterList.Add(GetNodeAttribute(n, "name"), GetNodeAttribute(n, "type"));
                     }
                 }
                 else
                 {
                     tmp.FileExporterList = new Dictionary <string, string>(0);
                 }
                 s_ExporterSetting = tmp;
             }
         }
     }
     return(s_ExporterSetting);
 }
Exemplo n.º 2
0
        public static IFileExport CreateExporter(string exporterName)
        {
            ExporterSetting setting = FileExporterConfig.GetSetting();

            if (setting != null && exporterName != null && exporterName.Trim().Length > 0)
            {
                if (setting.FileExporterList.ContainsKey(exporterName))
                {
                    string typeName = setting.FileExporterList[exporterName];
                    if (typeName != null && typeName.Length > 0)
                    {
                        Type type = Type.GetType(typeName, true);
                        return((IFileExport)Activator.CreateInstance(type));
                    }
                }
                if (setting.Default != null && setting.Default.Length > 0 && setting.FileExporterList.ContainsKey(setting.Default))
                {
                    CreateExporter(setting.Default);
                }
            }
            return(new ExcelFileExporter());
        }