public static List <BigData> Parse(string sid, string time, string bigdeal) { List <BigData> list = new List <BigData>(); bigdeal = bigdeal.Replace("-", ",-").Replace("+", ",+"); bigdeal = bigdeal.StartsWith(",") ? bigdeal.Substring(1, bigdeal.Length - 1) : bigdeal; string[] bigs = bigdeal.Split(','); foreach (string b in bigs) { string type = b.StartsWith("+") ? "B" : "S"; string code = MyBase64.UnCompressNumber(b.Substring(1, b.Length - 1)).ToString(); for (int j = 0; j < (14 - code.Length); j++) { code = "0" + code; } list.Add( new BigData() { sid = sid, shares = int.Parse(code.Substring(0, 3)), minutes = int.Parse(code.Substring(3, 3)), rateToOpen = int.Parse(code.Substring(6, 4).StartsWith("0") ? "-" + code.Substring(7, 3) : code.Substring(7, 3)), rateToChange = int.Parse(code.Substring(10, 4).StartsWith("0") ? "-" + code.Substring(11, 3) : code.Substring(11, 3)), time = BizCommon.ParseToDate(time), type = type }); } return(list); }
static void Main(string[] args) { string address = @"D:\CS\Texts\"; string[] nameOfFile = new string[] { "fet.txt", "heart.txt", "zelen.txt" }; char[] alph = new char[33] { 'а', 'б', 'в', 'г', 'ґ', 'д', 'е', 'є', 'ж', 'з', 'и', 'і', 'ї', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ь', 'ю', 'я' }; Console.OutputEncoding = System.Text.Encoding.UTF8; for (int f = 0; f < nameOfFile.Length; f++) { Console.WriteLine("{0} encoded with the use of Base64\n", nameOfFile[f]); string text = System.IO.File.ReadAllText(address + nameOfFile[f], Encoding.UTF8); byte[] arr = Encoding.UTF8.GetBytes(text); MyBase64 encoder = new MyBase64(arr); Console.WriteLine(encoder.Encode()); Console.WriteLine(); Console.ReadKey(); } }
public void Test(string testData, string expected) { byte[] decoded = MyBase64.Decode(testData); string decodedString = Encoding.UTF8.GetString(decoded); Assert.Equal(expected, decodedString); }
public void Test(string testData, string expected) { byte[] b = Encoding.UTF8.GetBytes(testData); string encoded = MyBase64.Encode(b); Assert.Equal(expected, encoded); }
static void Main(string[] args) { string dir_address = @"D:\UNIV\Comp_Sys\lab_1\"; string[] file_name = new string[] { "scp_1.txt.bz2", "brake_2.txt.bz2", "rick_3.txt.bz2" }; char[] alphabet = new char[33] { 'а', 'б', 'в', 'г', 'ґ', 'д', 'е', 'є', 'ж', 'з', 'и', 'і', 'ї', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ь', 'ю', 'я' }; Console.OutputEncoding = System.Text.Encoding.UTF8; for (int f = 0; f < file_name.Length; f++) { Console.WriteLine("{0} закодовано у Base64\n", file_name[f]); string text = System.IO.File.ReadAllText(dir_address + file_name[f], Encoding.UTF8); byte[] array = Encoding.UTF8.GetBytes(text); MyBase64 encoder = new MyBase64(array); Console.WriteLine(encoder.Encode()); Console.WriteLine(); Console.ReadKey(); } }
/// <summary> /// 保存大单的具体情况 /// </summary> /// <param name="sid"></param> /// <param name="date"></param> /// <param name="stream"></param> /// <param name="bigs"></param> /// <param name="lastupdate"></param> /// <returns></returns> public static List <BasicData> ReadCsvByReader(string sid, string date, TextReader stream, decimal[] bigs, DateTime lastupdate) { int index = 0; //bigs = null; //bigs = new decimal[1]; //bigs[0] = 1000M; List <BasicData> list = new List <BasicData>(); BasicData[] array = new BasicData[bigs.Length]; if (date.Length != 10) { throw new Exception("time format is wrong -" + date); } string time = date; DateTime t = new DateTime(Int32.Parse(time.Substring(0, 4)), Int32.Parse(time.Substring(5, 2)), Int32.Parse(time.Substring(8, 2))); //处理过了就忽略 if (t < lastupdate.AddDays(1)) { return(null); } Dictionary <decimal, string> temp = new Dictionary <decimal, string>(); for (int j = 0; j < bigs.Length; j++) { array[j] = new BasicData(); array[j].big = (int)bigs[j]; array[j].time = t; array[j].sid = sid; array[j].c_type = "d"; temp[bigs[j]] = ""; } // open the file "data.csv" which is a CSV file with headers using (CsvReader csv = new CsvReader(stream, true)) { //颠倒记录 IEnumerable <string[]> hi = csv.Reverse <string[]>(); decimal current; decimal open = 0, close = 0, high = 0, low = 0; string extstring = ""; foreach (String[] record in hi) { string price_str = record[1]; string change_str = record[2]; string share_str = record[3]; string type_str = record[5]; string time_str = record[0]; try { Decimal price = Decimal.Parse(price_str.IndexOf("\0") > 0 ? price_str.Remove(price_str.IndexOf("\0")) : price_str); Double share = Double.Parse(share_str.IndexOf("\0") > 0 ? share_str.Remove(share_str.IndexOf("\0")) : share_str); //count close,open,low,high current = price; if (index == 0) { open = current; high = current; low = current; } if (high < current) { high = current; } if (low > current) { low = current; } close = current; index++; for (int k = 0; k < bigs.Length; k++) { int fieldCount = csv.FieldCount; string[] headers = csv.GetFieldHeaders(); array[k].open = open; array[k].close = close; array[k].high = high; array[k].low = low; array[k].totalshare += share; array[k].totalmoney += Decimal.Multiply(price, (Decimal)share); if (Int32.Parse(share_str) >= bigs[k]) { //15位编码编码, //第1位买单1卖单0 //后3位股数(百手) //后3位时间数(相对于9:25的分钟数) //后4位位股价(1正0负,后三位是相对开盘的万分比 //后4位,股价变化(1正0负,后3位是万分比) //Console.WriteLine(time_str + ": " + share + " " + type_str); string code = ""; if (type_str == "S") { //string code = "-" + MyBase64.CompressNumber(long.Parse(p(share) + p1(time_str) + p2(current, open))); if (bigs[k] > 0) { code = p(share) + p1(time_str) + RateToOpen(current, open) + RateToBefore(decimal.Parse(change_str), current); code = MyBase64.CompressNumber(long.Parse(code)); code = "-" + code; temp[bigs[k]] += code; } array[k].sellshare += share; array[k].sellmoney += Decimal.Multiply(price, (Decimal)share); } if (type_str == "B") { if (bigs[k] > 0) { //string code = "-" + MyBase64.CompressNumber(long.Parse(p(share) + p1(time_str) + p2(current, open))); code = p(share) + p1(time_str) + RateToOpen(current, open) + RateToBefore(decimal.Parse(change_str), current); //Console.WriteLine(code); code = MyBase64.CompressNumber(long.Parse(code)); code = "+" + code; temp[bigs[k]] += code; } array[k].buyshare += share; array[k].buymoney += Decimal.Multiply(price, (Decimal)share); } array[k].bigdetail = temp[bigs[k]]; //Console.WriteLine(array[k].bigdetail); } } } catch { StockLog.Log.Error(sid + " import fail"); } } } for (int j = 0; j < bigs.Length; j++) { list.Add(array[j]); } return(list); }