public class FsnBizNet
    {
        private static int count;
        public static int parseInt(IList<string> list)
        {
            int value = Convert.ToInt32(list[count + 1] + list[count], 2);
            count += 2;
            return value;
        }
        public static string parseString(IList<string> list)
        {
            string value = list[count + 3] + list[count + 2] + list[count + 1] + list[count];
            count += 4;
            return value;
        }
        public static List<string> readFileToBit(string filepath)
        {
            FileStream @in = new FileStream(filepath, FileMode.Open);
            List<string> list = new List<string>();
            long left = @in.Length;//文件大小
            byte[] buffer = new byte[1024];
            int start = 0;//读取位置
            int length = 0; //实际返回结果长度
            while (left > 0)
            {
                @in.Position = start;
                length = 0;
                if (left < buffer.Length)
                    length = @in.Read(buffer, 0, Convert.ToInt32(left));
                else
                    length = @in.Read(buffer, 0, buffer.Length);
                if (length == 0)
                {
                    break;
                }
                start = start + length;
                left = left - length;
                for (int i = 0; i < length; i++)
                {
                    string s = Convert.ToString(buffer[i] | 256, 2);
                    s = s.Substring(s.Length - 8);
                    list.Add(s);
                }
            }
            @in.Close();
            return list;
        }
        public static SnoHead getHead(IList<string> list)
        {
            count = 0;
            FsnBizNet f = new FsnBizNet();
            SnoHead sh = new FsnBizNet.SnoHead(f);
            int[] headStart = new int[4];
            for (int i = 0; i < 4; i++)
            {
                headStart[i] = parseInt(list);
            }
            sh.HeadStart = headStart;
            int[] headString = new int[6];
            for (int i = 0; i < 6; i++)
            {
                headString[i] = parseInt(list);
            }
            sh.HeadString = headString;
            long counter = parseInt(list) + (parseInt(list) << 8);
            sh.Counter = counter;
            int[] headEnd = new int[4];
            for (int i = 0; i < 4; i++)
            {
                headEnd[i] = parseInt(list);
            }
            sh.HeadEnd = headEnd;
            return sh;
        }
        public static IDictionary getSnoExpImg(IList<string> list)
        {
            count = 0;
            IDictionary map = new Hashtable();
            // 设置日期时间
            int data = parseInt(list);
            int time = parseInt(list);
            int y = data >> 9;
            int m = (data - (y << 9)) >> 5;
            int d = data - (y << 9) - (m << 5);
            int hh = time >> 11;
            int mm = (time - (hh << 11)) >> 5;
            int ss = (time - (hh << 11) - (mm << 5)) << 1;
            map["DateTime"] = y + 1980 + "-" + m + "-" + d + " " + hh + ":" + mm + ":" + ss;
            // 设置货币真、假、残和旧币标志
            map["TfFlag"] = parseInt(list);
            // 设置货币错误码(3个)
            string errorCode = "";
            for (int i = 0; i < 3; i++)
            {
                int code = parseInt(list);
                if (code < 13 && code > 0)
                {
                    errorCode += code + ",";
                }
            }
            if ("1".Equals(map["TfFlag"]))
            {
                errorCode = errorCode.Substring(0, errorCode.LastIndexOf(","));
            }
            else
            {
                errorCode = "0";
            }
            map["ErrorCode"] = errorCode;
            // 设置币种标志(4个)
            string moneyFlag = "";
            for (int i = 0; i < 4; i++)
            {
                int flag = parseInt(list);
                if (flag != 0)
                {
                    moneyFlag += (char)flag;
                }
            }
            map["MoneyFlag"] = moneyFlag;
            // 设置年版或版本号标志
            int ver = parseInt(list);
            if (ver == 0)
            {
                ver = 1990;
            }
            if (ver == 1)
            {
                ver = 1999;
            }
            if (ver == 2)
            {
                ver = 2005;
            }
            if (ver == 9999)
            {
                ver = 0;
            }
            map["Ver"] = ver;
            // 设置币值
            map["Valuta"] = parseInt(list);
            // 设置冠字号位数
            map["CharNum"] = parseInt(list);
            // 设置冠字号(12个)
            string no = "";
            for (int i = 0; i < 12; i++)
            {
                int No = parseInt(list);
                if (No != 0)
                {
                    no += (char)No;
                }
            }
            map["Sno"] = no;
            // 设置机具编号(24个)
            string machineSNo = "";
            for (int i = 0; i < 24; i++)
            {
                int Msno = parseInt(list);
                if (Msno != 0)
                {
                    machineSNo += (char)Msno;
                }
            }
            map["MachineSno"] = machineSNo;
            // 设置冠字号保留字
            map["Reserve1"] = parseInt(list);
            return map;
        }
        public static Bitmap getSnoImg(IList<string> list)
        {
            count = 0;
            int num = parseInt(list);
            int height = parseInt(list);
            int width = parseInt(list);
            int Reserve2 = parseInt(list);
            // 根据读取的信息创建图像缓冲区
            Brush bruch = Brushes.White;
            Bitmap image = new Bitmap(width * num, height, PixelFormat.Format32bppRgb);
            System.Drawing.Graphics g = Graphics.FromImage(image);
            g.FillRectangle(bruch, 0, 0, width * num, height);
            g.Dispose();
            int i = 0;
            while (list.Count - count > 0 && i < width * num)
            {
                string s = parseString(list);
                for (int j = 0; j < height && j < s.Length; j++)
                {
                    if (s[j] == '1')
                    {
                         int colorvalue =Convert.ToInt32(0x000000);
                         image.SetPixel(i, j, Color.FromArgb(colorvalue));
                    }
                }
                i++;
            }
            return image;
        }
        public static List<IDictionary> readFile(string path)
        {
            // bit-list
            List<string> listBit = readFileToBit(path);
            // 头文件
            SnoHead sh = getHead(listBit.GetRange(0, 32-0));
            // 冠字号信息条数
            long counter = sh.Counter;
            // 根据冠字号头文件判断是否存在图像,得出一条冠字号信息包含的byte数
            int size = sh.HeadString[2] != 0x2D ? 1644 : 100;
            if (counter * size + 32 == listBit.Count)
            {
                //string imagePath = Thread.CurrentThread.ContextClassLoader.getResource("").Path.Substring(1).Replace("%20", " ");
                string imagePath = AppDomain.CurrentDomain.BaseDirectory.Substring(0).Replace("%20", " ");
                imagePath = Path.Combine(imagePath,"image");
                List<IDictionary> list = new List<IDictionary>();
                for (int i = 0; i < counter; i++)
                {
                    //listBit.ToArray().
                    IDictionary map = getSnoExpImg(listBit.GetRange(i * size + 32, i * size + 132 - (i * size + 32)));
                    if (size != 100)
                    {
                        Bitmap imageSno = getSnoImg(listBit.GetRange(i * size + 132, (i + 1) * size - (i * size + 132)));
                        imageSno.Save(Path.Combine(imagePath,i + ".bmp"), ImageFormat.Bmp);
                        map["ImageSno"] = "image/" + i + ".bmp";
                    }
                    else
                    {
                        map["ImageSno"] = null;
                    }
                    list.Add(map);
                }
                return list;
            }
            return null;
        }
        public class SnoHead
        {
            private readonly FsnBizNet outerInstance;
            public SnoHead(FsnBizNet outerInstance)
            {
                this.outerInstance = outerInstance;
            }
            internal int[] headStart;
            internal int[] headString;
            internal long counter;
            internal int[] HeadEnd_Renamed;
            public virtual int[] HeadStart
            {
                get
                {
                    return headStart;
                }
                set
                {
                    this.headStart = value;
                }
            }
            public virtual int[] HeadString
            {
                get
                {
                    return headString;
                }
                set
                {
                    this.headString = value;
                }
            }
            public virtual long Counter
            {
                get
                {
                    return counter;
                }
                set
                {
                    this.counter = value;
                }
            }
            public virtual int[] HeadEnd
            {
                get
                {
                    return HeadEnd_Renamed;
                }
                set
                {
                    HeadEnd_Renamed = value;
                }
            }
        }
    }

fsn文件解析(C#)的更多相关文章

  1. CocosStudio文件解析工具CsdAnalysis

    起因 因为工作需要,所以需要使用CocosStudio来制作界面动画什么的.做完了发现需要找里边对象的时候会有很长一串代码,感觉不是很爽.之前写OC代码的时候可以吧程序中的对象指针跟编辑器中的对象相对 ...

  2. 通过正则表达式实现简单xml文件解析

    这是我通过正则表达式实现的xml文件解析工具,有些XHTML文件中包含特殊符号,暂时还无法正常使用. 设计思路:常见的xml文件都是单根树结构,工具的目的是通过递归的方式将整个文档树装载进一个Node ...

  3. 八、Android学习第七天——XML文件解析方法(转)

    (转自:http://wenku.baidu.com/view/af39b3164431b90d6c85c72f.html) 八.Android学习第七天——XML文件解析方法 XML文件:exten ...

  4. phpcms V9 首页模板文件解析

    在了解了<phpcms V9 URL访问解析>之后,我们已经知道首页最终执行的是content模块下index控制器的init方法. 下面, 我们逐步分析过程如下: 第一.首页默认执行的是 ...

  5. (转)AVI文件格式解析+AVI文件解析工具

    AVI文件解析工具下载地址:http://download.csdn.net/detail/zjq634359531/7556659 AVI(Audio Video Interleaved的缩写)是一 ...

  6. itextSharp 附pdf文件解析

    一.PdfObject: pdf对象 ,有9种,对象是按照对象内涵来分的,如果按照对象的使用规则来说,对象又分为间接对象和直接对象.间接对象是PDF中最常用的对象,如前面对象集合里面的,所有对象都是间 ...

  7. 《热血传奇2》wix、wil文件解析Java实现

    在百度上搜索java+wil只有iteye上一篇有丁点儿内容,不过他说的是错的!或者说是不完整的,我个人认为我对于热血传奇客户端解析还是有一定研究的,请移步: <JMir——Java版热血传奇2 ...

  8. paper 37 : WINCE的BIB文件解析

    WINCE的BIB文件解析 BIB的全称为Binary Image Builder,在Wince编译过程中的最后MakeImage阶段会用到BIB文件,BIB文件的作用是指示构建系统如何构建二进制映像 ...

  9. 如何让你的Apache支持include文件解析和支持shtml的相关配置

    源地址:http://www.itokit.com/2011/0430/65992.html Apache支持include文件解析shtml首先要应该修改Apache配置文件httpd.conf . ...

随机推荐

  1. 修改HTTPD.CONF中的DocumentRoot,出现 You don't have permission to access /??? on this server.

    apache 2.4 修改/conf/extra/httpd-vhosts.conf <VirtualHost _default_:80> DocumentRoot '${SRVROOT} ...

  2. HP T505恢复出厂系统

    1.制作usb启动U盘. ------ 从HP网站上下载,或者找供应商提供 2.按F11,从U盘启动进去,会自动执行安装,等待完成即可以.

  3. JavaScript:substr vs substring vs slice

    参考文章: JavaScript取子串方法slice,substr,substring对比表

  4. sumoselect插件

    由于项目需要,研究了下sumoselect插件,接下来简单介绍下sumoselect. 在百度上搜索“sumoselect.js”,查到的网页基本上都有对sumoselect的基本介绍,如下: 简单介 ...

  5. C# xpath

    XPath最通俗的教程(ZZ)   以下是本人找到的最完整最易懂的XPath教程,不敢私藏,拿出来与大家分享.帮我点旁边的google广告呀. 实例 1基本的XPath语法类似于在一个文件系统中定位文 ...

  6. GTC China 2016观感

    上周二在北京参加了GTC China 2016,最大的感受就是一个字,“冷”!黄教主一如既往坚持机车皮夹克装,9月中旬的北京还没有那么的冷啊,感觉全场的空调简直是为他而开...好的,以上吐槽完毕,接着 ...

  7. WIN32服务程序(一):创建服务

    MSDN中有安装服务的例子Installing a Service(可点击进入),我们这里的创建服务,和MSDN里的例子基本上是一样的.这里做一些简单的说明: 打开控制面板,管理工具,服务.我们看到的 ...

  8. 读取手机上所有应用程序并显示(APP)

    pd = ProgressDialog.show(getActivity(), "请稍候..", "正在收集软件信息...", true,false); Thr ...

  9. Qt qtextstream读取文件

    今天发现一个很有用的类:qtextstream 这个类可以以文件句柄为构造函数 然后用readAll函数返回一个QString的字符串

  10. JS中this的值到底为何?

    之前很久的时间,因为研究不深,对于this的值一直模模糊糊,不是很清楚,最近有空做了一些研究,终于彻底弄明白了this到底为何物. 首先, 先抛出一个定论:”在Javascript中,this关键字永 ...