//public static void LoadCsvTable(string path) //{ // if(!Directory.Exists(path)) // { // throw new Exception("LoadCsvTable failed, path[" + path + "] has not existed!!!"); // } // DirectoryInfo dir = new DirectoryInfo(path); // FileInfo[] files = dir.GetFiles("*.csv", SearchOption.AllDirectories); // foreach(var f in files) // { // DataTable dt = new DataTable(f.ToString()); // dt = CsvHelper.csv2dt(f.FullName, 0, dt); // foreach(DataColumn c in dt.Columns) // { // int i = 0; // i++; // } // foreach (DataRow r in dt.Rows) // { // int i = 0; // i++; // } // } //} public static T ParseDataTable <T>(DataTable dt, int keyIdx) where T : class, ICsvDataTableReader, new() { if (null == dt) { return(null); } T ret = new T(); for (int i = 0; i < dt.Rows.Count; ++i) { DataRow row = dt.Rows[i]; IConvertible key = null; List <IConvertible> vals = new List <IConvertible>(); for (int k = 0; k < dt.Columns.Count; ++k) { if (k == keyIdx) { key = (IConvertible)row.ItemArray[k]; continue; } vals.Add((IConvertible)row.ItemArray[k]); } if (null == key || vals.Count <= 0) { LogSys.Error(Tag, "ParseDataTable<{0}> error, has not a key or values is empty!!!", typeof(T)); continue; } ret.PutValues(key, vals.ToArray()); } return(ret); }
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value) { try { IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (edSvc != null) { if (context.PropertyDescriptor.Name == "TextureName") { Material mat = (Material)value; IDictionaryEnumerator texs = MaterialManager.Instance.Textures; List <string> list = new List <string>(); string first = string.Empty; while (texs.MoveNext()) { DictionaryEntry entry = (DictionaryEntry)texs.Current; Texture tex = entry.Value as Texture; if (null == tex) { continue; } if (string.IsNullOrEmpty(first)) { first = tex.Name; } Label lbl = new Label(); lbl.Text = tex.Name; edSvc.DropDownControl(lbl); list.Add(tex.Name); } return(first); } } } catch (Exception ex) { LogSys.Error("TextureUITypeEditor", "TextureUITypeEditor Error : " + ex.Message); return(value); } return(value); }
void Download(object obj) { Stream myStream = null; HttpData data = null; try { string segment = obj as string; data = PopSend(); while (null != data) { //获取已经下载的长度 long pos = data.FS.Length; data.FS.Seek(pos, SeekOrigin.Current); //打开网络连接 HttpWebRequest myRequest = (HttpWebRequest)HttpWebRequest.Create(mRootWebURL + segment + data.FN); if (pos > 0) { myRequest.AddRange((int)pos); //设置Range值 } //向服务器请求,获得服务器的回应数据流 myStream = myRequest.GetResponse().GetResponseStream(); long totalLen = myStream.Length; //定义一个字节数据 byte[] btContent = new byte[512]; int intSize = 0; intSize = myStream.Read(btContent, 0, 512); while (intSize > 0) { data.FS.Write(btContent, 0, intSize); long nowLen = data.FS.Length; intSize = myStream.Read(btContent, 0, 512); if (null != OnProgress) { OnProgress(data, (float)((double)nowLen / (double)totalLen) * 100f); } //Thread.Sleep(0); } //关闭流 myStream.Close(); // 下一个 data.FS.Seek(0, SeekOrigin.Begin); //lock(FileOverLocker) //{ if (null != OnFileDownloadOvered) { OnFileDownloadOvered(data); } //} data = PopSend(); } if (null != OnDownloadOvered) { OnDownloadOvered(); } } catch (Exception e) { LogSys.Error(Tag, "SimpleDownload Exception:{0}", e); if (null != myStream) { myStream.Close(); } if (null != data && null != data.FS) { data.FS.Close(); } } }
public static DataTable csv2dt(string name, Stream s, int ni, int ti, int vi) { DataTable dt = new DataTable(name); using (StreamReader reader = new StreamReader(s, System.Text.Encoding.UTF8, false)) { int i = 0, lineIndex = 1; reader.Peek(); List <string> colNames = new List <string>(); List <Type> types = new List <Type>(); while (reader.Peek() > 0) { string str = reader.ReadLine(); string[] split = str.Split(','); if (split.Length <= 0) { LogSys.Error(Tag, "csv2dt failed! row[{0}] is empty!!!", lineIndex); continue; } if (lineIndex == ni) // name header col { colNames.AddRange(split); lineIndex++; continue; } else if (lineIndex == ti) // type header { foreach (string t in split) { Type tp = TypeQuery.GetTypeByString(t); if (null != tp) { types.Add(tp); } } } if (colNames.Count != types.Count) { throw new System.Exception("csv2dt failed! colcount[" + colNames.Count + "] != typecount[" + types.Count + "]"); } // add col if (dt.Columns.Count <= 0) { for (int c = 0; c < types.Count; ++c) { dt.Columns.Add(colNames[c], types[c]); } } if (lineIndex >= vi) // values { DataRow dr = dt.NewRow(); for (i = 0; i < split.Length; i++) { dr[i] = TypeQuery.Str2Value(split[i], types[i]); } dt.Rows.Add(dr); } lineIndex++; } } return(dt); }