www.pudn.com > Fetion.rar > ImportExportManager.cs


namespace Imps.Client.Pc 
{ 
    using Imps.Client.Resource; 
    using Imps.Client.Utils; 
    using Imps.Client.Utils.Win32; 
    using System; 
    using System.Collections.Generic; 
    using System.Reflection; 
    using System.Text; 
 
    public class ImportExportManager : IImportExportManager 
    { 
        private ExportForm _exportFrom; 
        private List _exportPlugins; 
        private IFrameworkWindow _frameworkWin; 
        private ImportForm _importForm; 
        private List _importPlugins; 
        public static Encoding FileEncoding = Encoding.Default; 
 
        public ImportExportManager(IFrameworkWindow frameworkWin) 
        { 
            this._frameworkWin = frameworkWin; 
        } 
 
        public void Export() 
        { 
            if ((this._importForm != null) && !this._importForm.IsDisposed) 
            { 
                this._importForm.Close(); 
            } 
            if (this._frameworkWin.AccountManager.CurrentUser.ContactList.Contacts.Count == 0) 
            { 
                this._frameworkWin.UnifiedMessageBox.ShowInfo(this._frameworkWin.MainWindow, "没有联系人可以导出!"); 
            } 
            else if ((this._exportFrom == null) || this._exportFrom.IsDisposed) 
            { 
                this._exportFrom = new ExportForm(this._frameworkWin, this); 
                ControlHelper.ShowFormCenterOnParent(this._exportFrom, this._frameworkWin.MainWindow); 
            } 
            else 
            { 
                NativeMethods.ShowWindow(this._exportFrom.Handle, 9); 
            } 
        } 
 
        public List GetExportPlugins() 
        { 
            if (this._exportPlugins == null) 
            { 
                this._exportPlugins = new List(); 
                ImportExportPlugin item = new ImportExportPlugin(); 
                item.Name = "导出为普通文本文件(.csv)"; 
                item.TypeName = "Imps.Client.Pc.ExportContactsToCVS"; 
                item.Description = "导出为普通文本文件(.csv)"; 
                this._exportPlugins.Add(item); 
                item = new ImportExportPlugin(); 
                item.Name = string.Format("导出为{0}联系人文件(.fcl)", AppDictionary.ShortEnglishName); 
                item.TypeName = "Imps.Client.Pc.ExportContactsToXML"; 
                item.Description = string.Format("导出为{0}联系人文件(.fcl)", AppDictionary.ShortEnglishName); 
                this._exportPlugins.Add(item); 
            } 
            return this._exportPlugins; 
        } 
 
        public List GetImportPlugins() 
        { 
            if (this._importPlugins == null) 
            { 
                this._importPlugins = new List(); 
                ImportExportPlugin item = new ImportExportPlugin(); 
                item.Name = "从CSV文件导入联系人"; 
                item.TypeName = "Imps.Client.Pc.ImportContactsFromCSV"; 
                item.Description = "从包含有联系人信息的CSV文件中获取信息,并向对方发出添加好友的邀请。"; 
                this._importPlugins.Add(item); 
                item = new ImportExportPlugin(); 
                item.Name = string.Format("从{0}格式文件导入联系人", AppDictionary.ShortEnglishName); 
                item.TypeName = "Imps.Client.Pc.ImportContactsFromXML"; 
                item.Description = string.Format("从包含有联系人详细信息的{0}格式文件中获取信息,并向对方发出添加好友的邀请。", AppDictionary.ShortEnglishName); 
                this._importPlugins.Add(item); 
                item = new ImportExportPlugin(); 
                item.Name = "从Vcard文件导入联系人"; 
                item.TypeName = "Imps.Client.Pc.ImportContactsFromVcard"; 
                item.Description = "从Vcard文件中获取信息,并向对方发出添加好友的邀请。"; 
                this._importPlugins.Add(item); 
                item = new ImportExportPlugin(); 
                item.Name = "从Microsoft Office Outlook导入联系人"; 
                item.TypeName = "Imps.Client.Pc.ImportContactsFromOutlook"; 
                item.Description = "从Outlook中读取含有手机号码的联系人信息,并向对方发出添加好友的邀请。"; 
                this._importPlugins.Add(item); 
            } 
            return this._importPlugins; 
        } 
 
        public void Import() 
        { 
            if ((this._exportFrom != null) && !this._exportFrom.IsDisposed) 
            { 
                this._exportFrom.Close(); 
            } 
            if ((this._importForm == null) || this._importForm.IsDisposed) 
            { 
                this._importForm = new ImportForm(this._frameworkWin, this); 
                ControlHelper.ShowFormCenterOnParent(this._importForm, this._frameworkWin.MainWindow); 
            } 
            else 
            { 
                NativeMethods.ShowWindow(this._importForm.Handle, 9); 
            } 
        } 
 
        public class ImportExportPlugin 
        { 
            private string _assemblyName; 
            private string _description; 
            private object _importExportObject; 
            private string _name; 
            private string _type; 
 
            public string AssemblyName 
            { 
                get 
                { 
                    return this._assemblyName; 
                } 
                set 
                { 
                    this._assemblyName = value; 
                } 
            } 
 
            public string Description 
            { 
                get 
                { 
                    return this._description; 
                } 
                set 
                { 
                    this._description = value; 
                } 
            } 
 
            public object ImportExportObject 
            { 
                get 
                { 
                    if ((this._importExportObject == null) && (this._importExportObject == null)) 
                    { 
                        Assembly executingAssembly = null; 
                        if (this._assemblyName != null) 
                        { 
                            executingAssembly = Assembly.Load(this._assemblyName); 
                        } 
                        else 
                        { 
                            executingAssembly = Assembly.GetExecutingAssembly(); 
                        } 
                        if (executingAssembly != null) 
                        { 
                            Type type = executingAssembly.GetType(this._type); 
                            if (type != null) 
                            { 
                                this._importExportObject = Activator.CreateInstance(type); 
                            } 
                        } 
                    } 
                    return this._importExportObject; 
                } 
            } 
 
            public string Name 
            { 
                get 
                { 
                    return this._name; 
                } 
                set 
                { 
                    this._name = value; 
                } 
            } 
 
            public string TypeName 
            { 
                get 
                { 
                    return this._type; 
                } 
                set 
                { 
                    this._type = value; 
                } 
            } 
        } 
    } 
}