private void convert_Click(Object sender, EventArgs e) { convert.Enabled = false; StorageType sourceType = (StorageType)Enum.Parse(typeof(StorageType), sourceStorageTypeCmb.Text); string sourceStr = sourceResultTxt.Text; StorageType targetType = (StorageType)Enum.Parse(typeof(StorageType), targetStorageCmb.Text); string targetStr = targetResultTxt.Text; Type[] patametersType = { typeof(String) }; Object[] sinvokeParameters = { sourceStr }; StorageTypeInfo[] sinfo = (StorageTypeInfo[])sourceType.GetType().GetField(sourceType.ToString()).GetCustomAttributes(typeof(StorageTypeInfo), false); Type st = Type.GetType(sinfo[0].Implementation, true); AbstractResultStorage sourceStorage = (AbstractResultStorage)st.GetConstructor(patametersType).Invoke(sinvokeParameters); Object[] tinvokeParameters = { targetStr }; StorageTypeInfo[] tinfo = (StorageTypeInfo[])targetType.GetType().GetField(targetType.ToString()).GetCustomAttributes(typeof(StorageTypeInfo), false); Type tt = Type.GetType(tinfo[0].Implementation, true); AbstractResultStorage targetStorage = (AbstractResultStorage)tt.GetConstructor(patametersType).Invoke(tinvokeParameters); List <ResearchResult> allResearchInfo = sourceStorage.LoadAllResearchInfo(); ResearchResult temp; foreach (ResearchResult r in allResearchInfo) { temp = sourceStorage.Load(r.ResearchID); targetStorage.Save(temp); } MessageBox.Show("Successfully converted from " + sourceStorageTypeCmb.Text + " to " + targetStorageCmb.Text + "."); convert.Enabled = true; }
/// <summary> /// Creates a storage of specified type using metadata information of enumeration value. /// </summary> /// <param name="st">Type of storage to create.</param> /// <param name="storageStr">Connection string or file path for data storage.</param> /// <returns>Newly created storage.</returns> private static AbstractResultStorage CreateStorage() { StorageType st = RandNetStatSettings.StorageType; string storageStr = null; switch (st) { case StorageType.XMLStorage: storageStr = RandNetStatSettings.XMLStorageDirectory; break; case StorageType.ExcelStorage: storageStr = RandNetStatSettings.ExcelStorageDirectory; break; default: break; } Type[] patametersType = { typeof(String) }; object[] invokeParameters = { storageStr }; StorageTypeInfo[] info = (StorageTypeInfo[])st.GetType().GetField(st.ToString()).GetCustomAttributes(typeof(StorageTypeInfo), false); Type t = Type.GetType(info[0].Implementation, true); return((AbstractResultStorage)t.GetConstructor(patametersType).Invoke(invokeParameters)); }
/// <summary> /// Creates a storage of specified type using metadata information of enumeration value. /// </summary> /// <param name="st">Type of storage to create.</param> /// <param name="storageStr">Connection string or file path for data storage.</param> /// <returns>Newly created storage.</returns> public static AbstractResultStorage CreateStorage(StorageType st, string storageStr) { Type[] patametersType = { typeof(String) }; object[] invokeParameters = { storageStr }; StorageTypeInfo[] info = (StorageTypeInfo[])st.GetType().GetField(st.ToString()).GetCustomAttributes(typeof(StorageTypeInfo), false); Type t = Type.GetType(info[0].Implementation, true); return (AbstractResultStorage)t.GetConstructor(patametersType).Invoke(invokeParameters); }
/// <summary> /// Creates a storage of specified type using metadata information of enumeration value. /// </summary> /// <param name="st">Type of storage to create.</param> /// <param name="storageStr">Connection String or file path for data storage.</param> /// <returns>Newly created storage.</returns> public static AbstractResultStorage CreateStorage(StorageType st, String storageStr) { Type[] patametersType = { typeof(String) }; Object[] invokeParameters = { storageStr }; StorageTypeInfo[] info = (StorageTypeInfo[])st.GetType().GetField(st.ToString()).GetCustomAttributes(typeof(StorageTypeInfo), false); Type t = Type.GetType(info[0].Implementation, true); return((AbstractResultStorage)t.GetConstructor(patametersType).Invoke(invokeParameters)); }