예제 #1
0
        /// <summary>
        ///   テーブル定義をPDF化する。
        /// </summary>
        /// <param name="list">テーブル定義リスト</param>
        /// <param name="filepath">PDFファイルパス</param>
        public static void GeneratePdf(List <DBTableDef> list, string filepath)
        {
            BaseFont baseFont = BaseFont.CreateFont(FontFile, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
            Font     lfont    = new Font(baseFont, 20, Font.NORMAL);
            Font     mfont    = new Font(baseFont, 12, Font.NORMAL);
            Font     sfont    = new Font(baseFont, 9, Font.NORMAL);

            using (Stream fs = FileUtil.BinaryWriter(filepath)) {
                Document  doc = new Document(PageSize.A4.Rotate());
                PdfWriter pw  = PdfWriter.GetInstance(doc, fs);
                doc.Open();

                foreach (DBTableDef tabledef in list)
                {
                    PdfPTable tbl    = new PdfPTable(3);
                    string[]  header = { "ヘッダ1", "ヘッダ2", "ヘッダ3" };
                    for (int i = 0; i < header.Length; i++)
                    {
                        PdfPCell cell = new PdfPCell(new Phrase(header[i], mfont));
                        tbl.AddCell(cell);
                    }
                    doc.Add(tbl);
                }
                doc.Close();
            }
        }
예제 #2
0
 /// <summary>
 ///   バックアップファイルを作成する
 /// </summary>
 /// <param name="filepath">ファイル名</param>
 /// <param name="db">DB接続</param>
 /// <param name="password">ZIPパスワード</param>
 /// <param name="aesEncryption">AES符号化を用いるかどうか</param>
 public void Backup(string filepath, DBCon db, string password = null, bool aesEncryption = false)
 {
     db.LOG_DEBUG("Creating backup file {0}", filepath);
     using (Stream sw = FileUtil.BinaryWriter(filepath)) {
         if (sw == null)
         {
             throw new IOException(String.Format("Can't open {0} for writing.", filepath));
         }
         Backup(sw, db, password, aesEncryption);
     }
 }
예제 #3
0
파일: HttpPage.cs 프로젝트: mtaneda/MACS
        private void FetchMultipartForm(HttpListenerRequest req)
        {
        #if FORMDEBUG
            Console.WriteLine("Entering FetchMultipartForm");
        #endif
            // まずboundary文字列を獲得する
            string boundary = null;
            foreach (string i in req.ContentType.Split(";".ToCharArray()))
            {
                string[] kv = i.Split("=".ToCharArray(), 2);
                if (kv.Length != 2)
                {
                    continue;
                }
                if (kv[0].Trim().ToLower() == "boundary")
                {
                    boundary = kv[1].Trim().Trim("\"".ToCharArray());
                }
            }
            if ((boundary == null) || (boundary == ""))
            {
                LOG_ERR("No boundary for multipart/form-data");
                return;
            }
        #if FORMDEBUG
            Console.WriteLine("boundary=" + boundary);
        #endif
            boundary = "--" + boundary;
            string finalboundary = boundary + "--";

            //Encoding enc = req.ContentEncoding; //クライアントは正しくContentEncodingを渡さない。
            Encoding       enc      = m_encoding;
            Decoder        dec      = enc.GetDecoder();
            byte[]         buf      = new byte[512];
            int            buflen   = 0;
            bool           inhead   = false;
            string         name     = null;
            StringBuilder  tmpvalue = null;
            HttpPostedFile tmpfile  = null;
        #if FORMDEBUG
            int n = 0;
        #endif
            int ch;
            try {
                // 入力をスキャン
                using (Stream sr = new BufferedStream(req.InputStream)) {
                    while ((ch = sr.ReadByte()) >= 0)
                    {
                #if FORMDEBUG
                        if (n >= 16)
                        {
                            Console.WriteLine();
                            n = 0;
                        }
                        Console.Write("[{0:X2}]", ch);
                        if ((ch >= 0x20) && (ch <= 0xfe))
                        {
                            Console.Write(Char.ConvertFromUtf32(ch));
                        }
                        else
                        {
                            Console.Write(' ');
                        }
                        n++;
                #endif

                        // ラインバッファに溜め込む
                        buf[buflen++] = (byte)ch;
                        if (buflen >= buf.Length)
                        {
                            // ラインバッファがいっぱい。
                            if (tmpvalue != null)
                            {
                                // 文字列受信中は部分デコードする。
                                char[] tmpchars    = new char[buflen];
                                int    tmpcharslen = dec.GetChars(buf, 0, buflen, tmpchars, 0, false);
                                tmpvalue.Append(tmpchars, 0, tmpcharslen);
                        #if FORMDEBUG
                                Console.WriteLine();
                                Console.WriteLine("Append {0}chars", tmpcharslen);
                        #endif
                                // TODO: あまりにも巨大なデータを受けた場合は入力スキャンを途中で止める事
                            }
                            else if (tmpfile != null)
                            {
                                // ファイル受信中は書き出す。
                                tmpfile.m_stream.Write(buf, 0, buflen);
                        #if FORMDEBUG
                                Console.WriteLine();
                                Console.WriteLine("Write {0}bytes to {1}", buflen, tmpfile.m_innerfilename);
                        #endif
                                // TODO: あまりにも巨大なファイルを受けた場合は入力スキャンを途中で止める事
                            }
                            buflen = 0;
                            continue;
                        }

                        if (ch == 0x0a) // ライン終端
                        {
                            try {
                                char[] tmpchars = new char[buflen];
                                int    tmpcharslen;
                                if ((buflen > 1) && (buf[buflen - 2] == 0x0d)) // LFの前にCRがあってもなくてもよいように。
                                {
                                    tmpcharslen = dec.GetChars(buf, 0, buflen - 2, tmpchars, 0, true);
                                }
                                else
                                {
                                    tmpcharslen = dec.GetChars(buf, 0, buflen - 1, tmpchars, 0, true);
                                }
                                dec = enc.GetDecoder(); // デコーダをリセットしておく
                                string line = new string(tmpchars, 0, tmpcharslen);
                        #if FORMDEBUG
                                Console.WriteLine();
                                Console.WriteLine("Line '" + line + "'");
                                n = 0;
                        #endif
                                if (inhead)
                                {
                                    // パートヘッダ中
                                    if (line == "")
                                    {
                                #if FORMDEBUG
                                        Console.WriteLine("Begin part body");
                                #endif
                                        inhead = false;
                                    }
                                    else if (line.StartsWith("content-disposition:", true, CultureInfo.InvariantCulture))
                                    {
                                        // 属性値取り出し
                                        foreach (string i in line.Split(";".ToCharArray()))
                                        {
                                            string[] kv = i.Split("=".ToCharArray(), 2);
                                            if (kv.Length != 2)
                                            {
                                                continue;
                                            }
                                            string k = kv[0].Trim().ToLower();
                                            switch (k)
                                            {
                                            case "name":
                                                name = kv[1].Trim().Trim("\"".ToCharArray());
                                                break;

                                            case "filename":
                                                tmpfile            = new HttpPostedFile();
                                                tmpfile.m_filename = kv[1].Trim().Trim("\"".ToCharArray());
                                                if (!Directory.Exists(m_server.TemporaryDirectory))
                                                {
                                                    Directory.CreateDirectory(m_server.TemporaryDirectory);
                                                }
                                                tmpfile.m_innerfilename = Path.Combine(m_server.TemporaryDirectory, TemporaryPrefix + m_rand.Next(0x7fffffff).ToString("X8"));
                                                tmpfile.m_stream        = FileUtil.BinaryWriter(tmpfile.m_innerfilename);
                                                if (tmpfile.m_stream == null)
                                                {
                                                    LOG_ERR(string.Format("Can't create '{0}'", tmpfile.m_innerfilename));
                                                    tmpfile = null;
                                                }
                                                break;
                                            }
                                        }
                                        if (tmpfile == null)
                                        {
                                            tmpvalue = new StringBuilder();
                                        }
                                #if FORMDEBUG
                                        Console.WriteLine("Fetch '{0}' part", name);
                                        if (tmpfile != null)
                                        {
                                            Console.WriteLine("Inner filename={0}", tmpfile.m_innerfilename);
                                        }
                                #endif
                                    }
                                    buflen = 0;
                                }
                                else if (tmpvalue != null)
                                {
                                    // フォーム要素値獲得中
                                    if ((line == boundary) || (line == finalboundary))
                                    {
                                        if (tmpvalue.Length > 0)
                                        {
                                            tmpvalue.Length--;
                                        }
                                        if (name == null)
                                        {
                                            name = "";
                                        }
                                        m_form.Add(name, tmpvalue.ToString());
                                #if FORMDEBUG
                                        Console.WriteLine("{0}='{1}'", name, tmpvalue.ToString());
                                #endif
                                        tmpvalue = null;
                                        buflen   = 0;
                                        inhead   = true;
                                    }
                                    else
                                    {
                                        tmpvalue.Append(line);
                                        tmpvalue.Append('\n');
                                        // TODO: あまりにも巨大なデータを受けた場合は入力スキャンを途中で止める事
                                    }
                                }
                                else if (tmpfile != null)
                                {
                                    // ファイル受信中
                                    if ((line == boundary) || (line == finalboundary))
                                    {
                                        if (tmpfile.m_stream.Length >= 2)
                                        {
                                            tmpfile.m_stream.SetLength(tmpfile.m_stream.Length - 2);
                                        }
                                        tmpfile.m_stream.Close();
                                        tmpfile.m_stream = null;
                                        if (name == null)
                                        {
                                            name = "";
                                        }
                                        m_fileform[name] = tmpfile;
                                #if FORMDEBUG
                                        Console.WriteLine("{0}='{1}', {2}bytes", name, tmpfile.FileName, new FileInfo(tmpfile.m_innerfilename).Length);
                                #endif
                                        tmpfile = null;
                                        buflen  = 0;
                                        inhead  = true;
                                    }
                                }
                                else
                                {
                                    if ((line == boundary) || (line == finalboundary))
                                    {
                                #if FORMDEBUG
                                        Console.WriteLine("Got boundary");
                                #endif
                                        buflen = 0;
                                        inhead = true;
                                    }
                                }
                            } catch (ArgumentException e) {
                        #if FORMDEBUG
                                Console.WriteLine(e.Message);
                        #endif
                                e.GetType();
                                // just ignore
                            }
                            // ファイル受信中は書き出す
                            if ((tmpfile != null) && (buflen > 0))
                            {
                        #if FORMDEBUG
                                Console.WriteLine("Write {0}bytes to {1}", buflen, tmpfile.m_innerfilename);
                        #endif
                                tmpfile.m_stream.Write(buf, 0, buflen);
                                // TODO: あまりにも巨大なデータを受けた場合は入力スキャンを途中で止める事
                            }
                            buflen = 0;
                        }
                    }
                }

            #if FORMDEBUG
                Console.WriteLine();
            #endif
            } finally {
            #if FORMDEBUG
                Console.WriteLine("Leaving FetchMultipartForm");
            #endif
                if (tmpvalue != null)
                {
                    tmpvalue = null;
                }
                if (tmpfile != null)
                {
                    tmpfile.Dispose();
                    tmpfile = null;
                }
            }
        }