Ejemplo n.º 1
0
 public WebDavDb(Kernel kernel, string nameTag)
 {
     NameTag   = nameTag;
     _fileName = string.Format("{0}\\webdav.{1}.db", kernel.ProgDir(), Util.SwapChar(':', '-', nameTag));
     //ファイルからの読み込み
     if (File.Exists(_fileName))
     {
         using (var sr = new StreamReader(_fileName, Encoding.GetEncoding("Shift_JIS"))) {
             while (true)
             {
                 string str = sr.ReadLine();
                 if (str == null)
                 {
                     break;
                 }
                 var oneWebDavDb = new OneWebDavDb(Inet.TrimCrlf(str));
                 if (oneWebDavDb.Uri != "")
                 {
                     _ar.Add(oneWebDavDb);
                 }
             }
             sr.Close();
         }
     }
 }
Ejemplo n.º 2
0
        //本文中のsummaryリクエストの件名の確認
        void TestSummaryLines(int start, int end, Mail mail)
        {
            var lines = new List <string>();
            var bufs  = mail.GetBody();

            if (bufs.Length > 0)
            {
                foreach (var buf in Inet.GetLines(bufs))
                {
                    lines.Add(Encoding.ASCII.GetString(buf));
                }
            }
            if (end == -1)
            {
                Assert.AreEqual(lines.Count(), 0);
            }
            else
            {
                for (int i = 0; i < end - start + 1; i++)
                {
                    var s = string.Format("[{0}:{1:D5}]TITLE\r\n", init.MlAddr.Name, i + start);
                    Assert.AreEqual(lines[i], s);
                }
            }
        }
Ejemplo n.º 3
0
        public void APOP認証成功(InetKind inetKind)
        {
            //setUp
            var cl       = CreateClient(inetKind);
            var expected = "+OK user1 has 0 message (0 octets).\r\n";

            //exercise
            var challengeStr = Inet.TrimCrlf(cl.StringRecv(3, this)).Split(' ')[5];
            var result       = (new MD5CryptoServiceProvider()).ComputeHash(Encoding.ASCII.GetBytes(challengeStr + "user1"));
            var sb           = new StringBuilder();

            for (int i = 0; i < 16; i++)
            {
                sb.Append(string.Format("{0:x2}", result[i]));
            }
            cl.StringSend("APOP user1 " + sb.ToString());
            var actual = cl.StringRecv(3, this);

            //verify
            Assert.That(actual, Is.EqualTo(expected));



            //tearDown
            cl.StringSend("QUIT");
            cl.Close();
        }
Ejemplo n.º 4
0
        //TODO RecvCmdのパラメータ形式を変更するが、これは、後ほど、Web,Ftp,SmtpのServerで使用されているため影響がでる予定
        //コマンド取得
        //コネクション切断などエラーが発生した時はnullが返される
        protected Cmd recvCmd(SockTcp sockTcp)
        {
            if (sockTcp.SockState != sock.SockState.Connect)
            {
                //切断されている
                return(null);
            }
            var recvbuf = sockTcp.LineRecv(Timeout, this);

            //切断された場合
            if (recvbuf == null)
            {
                return(null);
            }

            //受信待機中の場合
            if (recvbuf.Length == 0)
            {
                //Ver5.8.5 Java fix
                //return new Cmd("", "", "");
                return(new Cmd("waiting", "", "")); //待機中の場合、そのことが分かるように"waiting"を返す
            }

            //CRLFの排除
            recvbuf = Inet.TrimCrlf(recvbuf);

            //String str = new String(recvbuf, Charset.forName("Shift-JIS"));
            var str = Encoding.GetEncoding("Shift-JIS").GetString(recvbuf);

            if (str == "")
            {
                return(new Cmd("", "", ""));
            }
            //受信行をコマンドとパラメータに分解する(コマンドとパラメータは1つ以上のスペースで区切られている)
            String cmdStr   = null;
            String paramStr = null;

            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == ' ')
                {
                    if (cmdStr == null)
                    {
                        cmdStr = str.Substring(0, i);
                    }
                }
                if (cmdStr == null || str[i] == ' ')
                {
                    continue;
                }
                paramStr = str.Substring(i);
                break;
            }
            if (cmdStr == null)
            {
                //パラメータ区切りが見つからなかった場合
                cmdStr = str; //全部コマンド
            }
            return(new Cmd(str, cmdStr, paramStr));
        }
Ejemplo n.º 5
0
        //コマンドに対する応答
        override public void Recv(string cmdStr, string buffer)
        {
            if (cmdStr.IndexOf("Cmd-View") == 0)
            {
                //string[] tmp = cmdStr.Split('-');
                //string user = tmp[2];
                //string uid = tmp[3];
                string tmpFileName = Path.GetTempFileName() + ".eml";
                _tmpFileList.Add(tmpFileName);

                byte[] buf = Inet.ToBytes(buffer);
                using (var bw = new BinaryWriter(new FileStream(tmpFileName, FileMode.Create, FileAccess.Write))) {
                    bw.Write(buf);
                    bw.Flush();
                    bw.Close();
                }
                System.Diagnostics.Process.Start(tmpFileName);
            }
            else if (cmdStr.IndexOf("Cmd-Delete") == 0)
            {
                //string[] tmp = cmdStr.Split('-');
                //string user = tmp[2];
                //string uid = tmp[3];
                if (buffer == "running")
                {
                    Msg.Show(MsgKind.Error, Kernel.IsJp() ? "SMTPサーバの起動中は、メールの削除はできません" : "In start of a SMTP server, there is not elimination of an email");
                }
                else if (buffer == "success")
                {
                    FuncRefresh();//最新の状態に更新する
                }
            }
        }
Ejemplo n.º 6
0
        protected override string ConnectJob(SockTcp client, SockTcp server, List <byte[]> clientBuf)
        {
            //最初のグリーティングメッセージ取得
            var buf = server.LineRecv(Timeout, this);

            if (buf == null)
            {
                return(null);//タイムアウト
            }
            //EHLO送信
            server.LineSend(clientBuf[0]);
            clientBuf.RemoveAt(0);

            //「250 OK」が返るまで読み飛ばす
            while (IsLife())
            {
                buf = server.LineRecv(Timeout, this);
                if (buf == null)
                {
                    return(null);//タイムアウト
                }
                var str = Inet.TrimCrlf(Encoding.ASCII.GetString(buf));
                if (str.ToUpper().IndexOf("250 ") == 0)
                {
                    return(str);
                }
            }
            return(null);
        }
Ejemplo n.º 7
0
        //TODO RecvCmd�̃p�����[�^�`����ύX���邪�A����́A��قǁAWeb,Ftp,Smtp��Server�Ŏg�p����Ă��邽�߉e�����ł�\��
        //�R�}���h�擾
        //�R�l�N�V�����ؒf�ȂǃG���[��������������null���Ԃ����
        protected Cmd recvCmd(SockTcp sockTcp)
        {
            if (sockTcp.SockState != sock.SockState.Connect)
            {
                //�ؒf����Ă���
                return(null);
            }
            var recvbuf = sockTcp.LineRecv(Timeout, this);

            //�ؒf���ꂽ�ꍇ
            if (recvbuf == null)
            {
                return(null);
            }

            //��M�ҋ@���̏ꍇ
            if (recvbuf.Length == 0)
            {
                //Ver5.8.5 Java fix
                //return new Cmd("", "", "");
                return(new Cmd("waiting", "", "")); //�ҋ@���̏ꍇ�A���̂��Ƃ�������悤��"waiting"��Ԃ�
            }

            //CRLF�̔r��
            recvbuf = Inet.TrimCrlf(recvbuf);

            //String str = new String(recvbuf, Charset.forName("Shift-JIS"));
            var str = Encoding.GetEncoding("Shift-JIS").GetString(recvbuf);

            if (str == "")
            {
                return(new Cmd("", "", ""));
            }
            //��M�s��R�}���h�ƃp�����[�^�ɕ������i�R�}���h�ƃp�����[�^�͂P�ˆȏ�̃X�y�[�X�ŋ�؂��Ă���j
            String cmdStr   = null;
            String paramStr = null;

            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == ' ')
                {
                    if (cmdStr == null)
                    {
                        cmdStr = str.Substring(0, i);
                    }
                }
                if (cmdStr == null || str[i] == ' ')
                {
                    continue;
                }
                paramStr = str.Substring(i);
                break;
            }
            if (cmdStr == null)
            {
                //�p�����[�^��؂肪���‚���Ȃ������ꍇ
                cmdStr = str; //�S���R�}���h
            }
            return(new Cmd(str, cmdStr, paramStr));
        }
Ejemplo n.º 8
0
        string UrlDecode(string s)
        {
            //Ver5.9.0
            try{
                var enc = Inet.GetUrlEncoding(s);
                var b   = new List <byte>();
                for (var i = 0; i < s.Length; i++)
                {
                    switch (s[i])
                    {
                    case '%':
                        b.Add((byte)int.Parse(s[++i].ToString() + s[++i].ToString(), NumberStyles.HexNumber));
                        break;

                    case '+':
                        b.Add(0x20);
                        break;

                    default:
                        b.Add((byte)s[i]);
                        break;
                    }
                }
                return(enc.GetString(b.ToArray(), 0, b.Count));
            } catch (Exception ex) {
                //Ver5.9.0
                _logger.Set(LogKind.Error, null, 0, string.Format("Exception ex.Message={0} [WebServer.Request.UrlDecode({1})]", ex.Message, s));
                return(s);
            }
        }
Ejemplo n.º 9
0
 //接続
 public bool Connect()
 {
     if (Status != SmtpClientStatus.Idle)
     {
         SetLastError("Connect() Status != Idle");
         return(false);
     }
     if (_ip.InetKind == InetKind.V4)
     {
         _sockTcp = Inet.Connect(new Kernel(), _ip, _port, _sec + 3, null);
     }
     else
     {
         _sockTcp = Inet.Connect(new Kernel(), _ip, _port, _sec + 3, null);
     }
     if (_sockTcp.SockState == SockState.Connect)
     {
         //220受信
         if (!RecvStatus(220))
         {
             return(false);
         }
         Status = SmtpClientStatus.Helo;
         return(true);
     }
     SetLastError("Faild in SmtpClient Connect()");
     return(false);
 }
Ejemplo n.º 10
0
        //元メールを添付して管理者へ送る
        public bool AttachToAmdin(Mail orgMail, string subject, MlEnvelope mlEnvelope)
        {
            //メール生成
            var mail = new Mail();

            mail.AppendLine(Encoding.ASCII.GetBytes("\r\n"));//区切り行(ヘッダ終了)
            mail.AddHeader("subject", subject);
            mail.AppendLine(Encoding.ASCII.GetBytes(subject + "\r\n"));
            mail.AppendLine(Encoding.ASCII.GetBytes("\r\n"));
            mail.AppendLine(Encoding.ASCII.GetBytes("Original mail as follows:\r\n"));
            mail.AppendLine(Encoding.ASCII.GetBytes("\r\n"));
            //オリジナルメールの添付
            var body = Inet.GetLines(orgMail.GetBytes());

            foreach (var buf in body)
            {
                mail.AppendLine(Encoding.ASCII.GetBytes("  "));//行頭に空白を追加
                mail.AppendLine(buf);
            }

            //宛先設定 from<->To from = mailDaemon
            mail.ConvertHeader("from", _mlAddr.Admin.ToString());
            //配送
            return(SendAllAdmin(mlEnvelope.ChangeFrom(_mlAddr.Admin), mail));
        }
Ejemplo n.º 11
0
 //接続
 public bool Connect()
 {
     if (Status != PopClientStatus.Idle)
     {
         SetLastError("Connect() Status != Idle");
         return(false);
     }
     if (_ip.InetKind == InetKind.V4)
     {
         _sockTcp = Inet.Connect(_kernel, _ip, _port, _sec + 3, null);
     }
     else
     {
         _sockTcp = Inet.Connect(_kernel, _ip, _port, _sec + 3, null);
     }
     if (_sockTcp.SockState == SockState.Connect)
     {
         //+OK受信
         if (!RecvStatus())
         {
             return(false);
         }
         Status = PopClientStatus.Authorization;
         return(true);
     }
     SetLastError("Faild in PopClient Connect()");
     return(false);
 }
Ejemplo n.º 12
0
        public void ConnectTest_V4からV4へのプロキシ()
        {
            //setUp
            //ダミーWebサーバ
            const int webPort = 778;
            var       webRoot = string.Format("{0}\\public_html", srcDir);
            var       tsWeb   = new TsWeb(webPort, webRoot);//Webサーバ起動

            var cl = Inet.Connect(new Kernel(), new Ip(IpKind.V4Localhost), 8888, 10, null);

            cl.Send(Encoding.ASCII.GetBytes("GET http://127.0.0.1:778/index.html HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n"));

            //exercise
            var lines = Inet.RecvLines(cl, 3, this);

            //verify
            Assert.That(lines.Count, Is.EqualTo(9));
            Assert.That(lines[0], Is.EqualTo("HTTP/1.1 200 OK"));
            Assert.That(lines[1], Is.EqualTo("Transfer-Encoding: chunked"));
            Assert.That(lines[2], Is.EqualTo("Server: Microsoft-HTTPAPI/2.0"));

            Assert.That(lines[4], Is.EqualTo(""));
            Assert.That(lines[5], Is.EqualTo("3"));
            Assert.That(lines[6], Is.EqualTo("123"));
            Assert.That(lines[7], Is.EqualTo("0"));
            Assert.That(lines[8], Is.EqualTo(""));


            //tearDown
            tsWeb.Dispose();//Webサーバ停止
        }
Ejemplo n.º 13
0
        private void Ehlo(SockTcp cl)
        {
            var localPort = cl.LocalAddress.Port; //なぜかローカルのポートアドレスは1つ小さい

            //バナー
            const string bannerStr = "220 localhost SMTP BlackJumboDog ";

            Assert.That(cl.StringRecv(3, this).Substring(0, 33), Is.EqualTo(bannerStr));

            //EHLO
            cl.StringSend("EHLO 1");
            var lines = Inet.RecvLines(cl, 4, this);

            var str = string.Format("250-localhost Helo 127.0.0.1[127.0.0.1:{0}], Pleased to meet you.", localPort);

            if (cl.LocalAddress.Address.ToString() == "::1")
            {
                str = string.Format("250-localhost Helo ::1[[::1]:{0}], Pleased to meet you.", localPort);
            }
            Assert.That(lines[0], Is.EqualTo(str));
            Assert.That(lines[1], Is.EqualTo("250-8BITMIME"));
            Assert.That(lines[2], Is.EqualTo("250-SIZE=5000"));
            Assert.That(lines[3], Is.EqualTo("250-AUTH LOGIN PLAIN CRAM-MD5"));
            Assert.That(lines[4], Is.EqualTo("250 HELP"));
        }
Ejemplo n.º 14
0
 public void SetUp()
 {
     //クライアント起動
     _v4Cl = Inet.Connect(new Kernel(), new Ip(IpKind.V4Localhost), 21, 10, null);
     _v6Cl = Inet.Connect(new Kernel(), new Ip(IpKind.V6Localhost), 21, 10, null);
     //クライアントの接続が完了するまで、少し時間がかかる
     //Thread.Sleep(10);
 }
Ejemplo n.º 15
0
        public CategoryPage(CategoryViewModel viewModel)
        {
            InitializeComponent();

            BindingContext = this.viewModel = viewModel;

            Inet = new Inet(Navigation, viewModel.LoadItemsCommand);
        }
Ejemplo n.º 16
0
        public MasterPage()
        {
            InitializeComponent();

            BindingContext = this.viewModel = new MasterViewModel();

            Inet = new Inet(Navigation, viewModel.LoadItemsCommand);
        }
Ejemplo n.º 17
0
        void TcpTunnel(SockTcp tcpObj)
        {
            var     client = tcpObj;
            SockTcp server = null;

            //***************************************************************
            // �T�[�o�Ƃ̐ڑ�
            //***************************************************************
            {
                var port = _targetPort;

                //var ipList = new List<Ip>{new Ip(_targetServer)};
                //if (ipList[0].ToString() == "0.0.0.0") {
                //    ipList = Kernel.DnsCache.Get(_targetServer);
                //    if(ipList.Count==0){
                //        Logger.Set(LogKind.Normal,null,4,string.Format("{0}:{1}",_targetServer,_targetPort));
                //        goto end;
                //    }
                //}
                var ipList = Kernel.GetIpList(_targetServer);
                if (ipList.Count == 0)
                {
                    Logger.Set(LogKind.Normal, null, 4, string.Format("{0}:{1}", _targetServer, _targetPort));
                    goto end;
                }
                foreach (var ip in ipList)
                {
                    server = Inet.Connect(Kernel, ip, port, Timeout, null);
                    if (server != null)
                    {
                        break;
                    }
                }
                if (server == null)
                {
                    Logger.Set(LogKind.Normal, server, 5, string.Format("{0}:{1}", _targetServer, _targetPort));
                    goto end;
                }
            }
            Logger.Set(LogKind.Normal, server, 6, string.Format("TCP {0}:{1} - {2}:{3}", client.RemoteHostname, client.RemoteAddress.Port, _targetServer, _targetPort));

            //***************************************************************
            // �p�C�v
            //***************************************************************
            var tunnel = new Tunnel(Logger, (int)Conf.Get("idleTime"), Timeout);

            tunnel.Pipe(server, client, this);
end:
            if (client != null)
            {
                client.Close();
            }
            if (server != null)
            {
                server.Close();
            }
        }
Ejemplo n.º 18
0
        public void Init2(byte[] buf)
        {
            var lines = Inet.GetLines(buf);

            foreach (var l in lines)
            {
                AppendLine(l);
            }
        }
Ejemplo n.º 19
0
        public void trimCrlf_byte配列(byte[] buf, byte[] expended)
        {
            var actual = Inet.TrimCrlf(buf);

            Assert.AreEqual(actual.Length, expended.Length);
            for (int i = 0; i < actual.Length; i++)
            {
                Assert.AreEqual(actual[i], expended[i]);
            }
        }
Ejemplo n.º 20
0
        //クライアントの生成
        SockTcp CreateClient(InetKind inetKind)
        {
            int port = 8110;

            if (inetKind == InetKind.V4)
            {
                return(Inet.Connect(new Kernel(), new Ip(IpKind.V4Localhost), port, 10, null));
            }
            return(Inet.Connect(new Kernel(), new Ip(IpKind.V6Localhost), port, 10, null));
        }
Ejemplo n.º 21
0
        //クライアントの生成
        SockTcp CreateClient(InetKind inetKind)
        {
            const int port = 8825; //ウイルススキャンにかかるため25を避ける

            if (inetKind == InetKind.V4)
            {
                return(Inet.Connect(new Kernel(), new Ip(IpKind.V4Localhost), port, 10, null));
            }
            return(Inet.Connect(new Kernel(), new Ip(IpKind.V6Localhost), port, 10, null));
        }
Ejemplo n.º 22
0
        public PricePage(Work work)
        {
            InitializeComponent();

            BindingContext = this.viewModel = new PriceViewModel(work);

            Work = work;

            Inet = new Inet(Navigation, viewModel.LoadItemsCommand);
        }
Ejemplo n.º 23
0
        //�s�lj��@\r\n��܂ނ܂܂Œlj�����
        //�w�b�_�Ɩ{���̋�؂����‚������Areturn true;
        public bool AppendLine(byte[] data)
        {
            if (_isHeader)  //�w�b�_�lj�
            {
                var str = Encoding.ASCII.GetString(data);

                //Ver6.1.3 �����ȃw�b�_�s�������ꍇ�A�w�b�_��I���Ƃ݂Ȃ�
                var isEspecially = false;
                //if (str != "\r\n" && str.IndexOf(':') == -1) {
                //Ver6.1.4
                //if (str != "\r\n" && str.IndexOf(' ')!=0 && str.IndexOf(':') == -1) {
                //Ver6.1.5
                if (str != "\r\n" && str.IndexOf(' ') != 0 && str.IndexOf('\t') != 0 && str.IndexOf(':') == -1)
                {
                    isEspecially = true;
                    str          = "\r\n";
                }


                if (str == "\r\n")  //�w�b�_�I��
                //�����s�ɂ܂�����w�b�_��P�s�ɂ܂Ƃ߂�
                {
                    foreach (string t in _lines)
                    {
                        if (t[0] == ' ' || t[0] == '\t')
                        {
                            var buf = _header[_header.Count - 1];
                            //Ver5.9.6
                            //buf = Inet.TrimCrlf(buf) + " " + t.Substring(1);
                            buf = Inet.TrimCrlf(buf) + "\r\n" + t.Substring(0);
                            _header[_header.Count - 1] = buf;
                        }
                        else
                        {
                            _header.Add(t);
                        }
                    }
                    _lines    = null;
                    _isHeader = false;//�w�b�_�s�I��

                    //Ver6.1.3 �����ȃw�b�_�s�������ꍇ�A�w�b�_��I���Ƃ݂Ȃ�
                    if (isEspecially)
                    {
                        _body.Add(data);
                    }
                    return(true);
                }
                _lines.Add(str);
            }
            else
            {
                _body.Add(data);
            }
            return(false);
        }
Ejemplo n.º 24
0
        public bool Data(Mail mail)
        {
            //トランザクションでない場合エラー
            if (Status != SmtpClientStatus.Transaction)
            {
                SetLastError("Data() Status != Transaction");
                return(false);
            }
            //DATA送信
            if (!SendCmd("DATA"))
            {
                return(false);
            }
            //354受信
            if (!RecvStatus(354))
            {
                return(false);
            }
            var lines = Inet.GetLines(mail.GetBytes());

            foreach (var l in lines)
            {
                //ドットのみの行の場合、ドットを追加する
                if (l.Length == 3 && l[0] == '.' && l[1] == '\r' && l[2] == '\n')
                {
                    var buf = new byte[1] {
                        l[0]
                    };
                    _sockTcp.Send(buf);
                }
                if (l.Length != _sockTcp.Send(l))
                {
                    SetLastError(String.Format("Faild in SmtpClient Data()"));
                    ConfirmConnect();//接続確認
                    return(false);
                }
            }
            //最終行が改行で終わっているかどうかの確認
            var last = lines[lines.Count - 1];

            if (last.Length < 2 || last[last.Length - 2] != '\r' || last[last.Length - 1] != '\n')
            {
                SendCmd("");//改行を送る
            }
            if (!SendCmd("."))
            {
                return(false);
            }
            //250受信
            if (!RecvStatus(250))
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 25
0
        private bool JobPort(Session session, String param, FtpCmd ftpCmd)
        {
            String resStr = "500 command not understood:";

            Ip  ip   = null;
            int port = 0;

            if (ftpCmd == FtpCmd.Eprt)
            {
                var tmpBuf = param.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                if (tmpBuf.Length == 3)
                {
                    port = Convert.ToInt32(tmpBuf[2]);
                    try{
                        ip = new Ip(tmpBuf[1]);
                    } catch (ValidObjException) {
                        ip = null;
                    }
                }
                if (ip == null)
                {
                    resStr = "501 Illegal EPRT command.";
                }
            }
            else
            {
                var tmpBuf = param.Split(',');
                if (tmpBuf.Length == 6)
                {
                    try{
                        ip = new Ip(tmpBuf[0] + "." + tmpBuf[1] + "." + tmpBuf[2] + "." + tmpBuf[3]);
                    } catch (ValidObjException) {
                        ip = null;
                    }
                    port = Convert.ToInt32(tmpBuf[4]) * 256 + Convert.ToInt32(tmpBuf[5]);
                }
                if (ip == null)
                {
                    resStr = "501 Illegal PORT command.";
                }
            }
            if (ip != null)
            {
                Thread.Sleep(10);
                var sockData = Inet.Connect(Kernel, ip, port, Timeout, null);
                if (sockData != null)
                {
                    resStr = string.Format("200 {0} command successful.", ftpCmd.ToString().ToUpper());
                }
                session.SockData = sockData;
            }
            session.StringSend(resStr);
            return(true);
        }
Ejemplo n.º 26
0
        //データ取得(内部データは、初期化される)
        public bool Recv(Logger logger, SockTcp sockTcp, int timeout, ILife iLife)
        {
            _logger = logger;
            //int limit = 3600;//文字数制限
            var str = sockTcp.AsciiRecv(timeout, iLife);

            if (str == null)
            {
                return(false);
            }
            return(Interpretation(Inet.TrimCrlf(str)));
        }
Ejemplo n.º 27
0
        //�t�@�C������̎擾
        public bool Read(string fileName)
        {
            //���݂̓�e����ׂĔj�����ēǂݒ���
            _header.Clear();
            _body.Clear();
            _body = new List <byte[]>();

            if (File.Exists(fileName))
            {
                var tmpBuf = new byte[0];
                using (var br = new BinaryReader(new FileStream(fileName, FileMode.Open))) {
                    var info = new FileInfo(fileName);
                    while (true)
                    {
                        var len = info.Length - tmpBuf.Length;
                        if (len <= 0)
                        {
                            break;
                        }
                        if (len > 65535)
                        {
                            len = 65535;
                        }
                        var tmp = br.ReadBytes((int)len);
                        tmpBuf = Bytes.Create(tmpBuf, tmp);
                    }
                    br.Close();

                    var lines = Inet.GetLines(tmpBuf);
                    var head  = true;
                    foreach (byte[] line in lines)
                    {
                        if (head)
                        {
                            var str = Encoding.ASCII.GetString(line);
                            if (str == "\r\n")
                            {
                                head = false;
                                continue;
                            }
                            _header.Add(str);
                        }
                        else
                        {
                            _body.Add(line);
                        }
                    }
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 28
0
        public WorkMastersPage(Work work)
        {
            InitializeComponent();

            Repair = new Repair()
            {
                Work = work, CityId = work.CityId, Options = new List <Option>()
            };

            BindingContext = this.viewModel = new WorkMastersViewModel(work);

            Inet = new Inet(Navigation, viewModel.LoadItemsCommand);
        }
Ejemplo n.º 29
0
        //受信時の処理
        protected override byte[] Assumption(byte[] buf, ILife iLife)
        {
            var resultBuf = new byte[0];

            //一度に複数行分のデータが来る場合が有るので、行単位に分割して処理する
            var lines = Inet.GetLines(buf);

            foreach (var l in lines)
            {
                resultBuf = Bytes.Create(resultBuf, AssumptionLine(l, iLife));
            }
            return(resultBuf);
        }
Ejemplo n.º 30
0
        public Header(byte[] buf)
        {
            _ar = new List <OneHeader>();

            //\r\n��r�������s�P�ʂɉ��H����
            var lines = from b in Inet.GetLines(buf) select Inet.TrimCrlf(b);

            var key = "";

            foreach (byte[] val in lines.Select(line => GetKeyVal(line, ref key)))
            {
                Append(key, val);
            }
        }