Exemple #1
0
        //public static IRQ_VPLDocInfo_Json CreateBy(IRQ_VPLDocInfo vpldoc) {
        //    IRQ_VPLDocInfo_Json docjs = new IRQ_VPLDocInfo_Json();
        //    docjs.CopyFrom(vpldoc);
        //    return docjs;
        //}

        public static string ToJson(IRQ_VPLDocInfo_Json vpldoc)
        {
            string js = SimpleJsonEx.SimpleJson.SerializeObject(vpldoc);

            return(js);
        }
Exemple #2
0
        public static IRQ_VPLDocInfo_Json LoadFromJson(string vpldoc_json)
        {
            IRQ_VPLDocInfo_Json doc = SimpleJsonEx.SimpleJson.DeserializeObject <IRQ_VPLDocInfo_Json>(vpldoc_json);

            return(doc);
        }
Exemple #3
0
        public static void Main(string[] args)
        {
            //测试序列化

            List <IRQ_VPLDocInfo_Json> vpldocjsons = new List <IRQ_VPLDocInfo_Json>();

            for (int i = 0; i < 1; i++)
            {
                IRQ_VPLDocInfo_Json docjs = new IRQ_VPLDocInfo_Json();
                docjs.Author                 = "me_" + i.ToString();
                docjs.CodeType               = VPL_CodeType.CSharp;
                docjs.CreateDate             = DateTime.Now;
                docjs.Description            = "";
                docjs.IsCodeMode             = false;
                docjs.IsNoRobotMode          = true;
                docjs.LastUpdate             = DateTime.Now;
                docjs.NoRobotMode_LastPlatId = "";
                docjs.OnCloudSvr             = false;
                docjs.PackageUniqueId        = "";
                docjs.PackageVersion         = "2.0";
                docjs.Source                 = IRQ_FileDocSource.User;
                docjs.Ver = "2.0";
                vpldocjsons.Add(docjs);
            }
            string docJsonStr = SimpleJsonEx.SimpleJson.SerializeObject(vpldocjsons);

            using (FileStream fs = new FileStream("test_array.json", FileMode.OpenOrCreate, FileAccess.Write)) {
                using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) {
                    sw.Write(docJsonStr);
                }
            }
            //反序列化
            string docJosnStr2 = "";

            using (StreamReader sr = new StreamReader("test_array.json", Encoding.UTF8)) {
                docJosnStr2 = sr.ReadToEnd();
            }
            List <IRQ_VPLDocInfo_Json> redocJsons = SimpleJsonEx.SimpleJson.DeserializeObject <List <IRQ_VPLDocInfo_Json> >(docJosnStr2);

            char[]      invalid1     = Path.GetInvalidFileNameChars();
            char[]      invalid2     = Path.GetInvalidPathChars();
            List <char> invalidChars = new List <char>();

            invalidChars.AddRange(invalid1);
            for (int i = 0; i < invalid2.Length; i++)
            {
                if (invalidChars.Contains(invalid2[i]) == false)
                {
                    invalidChars.Add(invalid2[i]);
                }
            }
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < invalidChars.Count; i++)
            {
                sb.Append(string.Format("{0}", (int)invalidChars[i]));
                if (i != invalidChars.Count - 1)
                {
                    sb.Append(",");
                }
            }
            string chars = sb.ToString();

            Console.WriteLine(chars);
            // "'\"','<','>','|','\0','','','','','','','\a','\b','\t','\n','\v','\f','\r','','','','','','','','','','','','','','','','','','',':','*','?','\\','/'"
            int timestart = Environment.TickCount;

            ResourceService.Init();
            // Stopwatch swRead = new Stopwatch();
            // swRead.Start();
            // IFilePackerStrategy urobot = ResourceService.GetLib(IRQ_FileType.Robot);
            //byte[] strInfo= urobot.OpenFile("kaka/1.png");
            //urobot.DelDir("kaka");
            //swRead.Stop();
            //Console.WriteLine("end:"+swRead.ElapsedMilliseconds.ToString()+" ms");

            //return;
            //
            //增加文件
            IFileSysPackerStrategy fps   = ResourceService.GetLib(IRQ_FileType.TempLeadInRes);
            FileStream             fsadd = new FileStream("mypack.data.zip", FileMode.Open, FileAccess.Read);

            byte[] buf_add = new byte[fsadd.Length];
            fsadd.Read(buf_add, 0, buf_add.Length);
            fsadd.Close();
            fps.Packer.BeginUpdate(fps);
            if (fps.FileExists("/test/mypack.data.zip"))
            {
                byte[] testReadBuf = fps.OpenFile("/test/mypack.data.zip");
                fps.DelFile("/test/mypack.data.zip");
            }
            fps.AddFile("/test/mypack.data.zip", buf_add, DateTime.Now);       //addfile
            fps.AddFile("/test/dir2/mypack2.data.zip", buf_add, DateTime.Now); //addfile
            fps.UpdateFile("/test/dir2/mypack2.data.zip", new byte[] { 1, 2, 3, 4 }, DateTime.Now);
            fps.AddFile("/test2/mypack.data.zip", buf_add, DateTime.Now);      //addfile
            fps.RenameFile("/test2/mypack.data.zip", "/test2/mypack2.data.zip");
            fps.RenameDir("test", "test3");
            List <string> getDirs = new List <string>();

            fps.GetDirs(out getDirs);
            fps.Clean();

            fps.AddFile("/test3/mypack.data.zip", buf_add, FileEntryInfo.DateTimeFromStr_STC("2016-01-01 12:12:12")); //addfile
            fps.AddFile("/test4/mypack.data.zip", buf_add, DateTime.Now);                                             //addfile
            getDirs = new List <string>();
            fps.GetDirs(out getDirs);
            DateTime      dtupdate  = fps.GetUpdateDate("test3/mypack.data.zip");
            List <string> filenames = new List <string>();
            int           totalSize = 0;

            fps.GetFiles("test3", out filenames, out totalSize);
            fps.DelDir("test3");
            fps.RenameDir("test4", "test");

            fps.Packer.EndUpdate(fps, true);
            Console.WriteLine("耗时:" + (Environment.TickCount - timestart).ToString() + " ms");
            Console.Read();
            return;

            string SCRATCH_FILES_PATH = "ziptest";
            //
            {
                //test
                //CompressionType.LZMA    10次 34175ms 242k
                //CompressionType.PPMd    10次 68678ms 319k
                //CompressionType.Deflate 10次 3006ms 428k
                //CompressionType.BZip2 10次 10103ms 335k
                //CompressionType.GZip not support
                //CompressionType.Rar  not support
                //CompressionType.BCJ2 not support
                //CompressionType.BCJ not support
                Stopwatch sw = new Stopwatch();
                sw.Start();
                //for (int i = 0; i < 10; i++) {
                using (var archive = ZipArchive.Create()) {
                    DirectoryInfo di = new DirectoryInfo(SCRATCH_FILES_PATH);
                    foreach (var fi in di.GetFiles())
                    {
                        archive.AddEntry(fi.Name, fi.OpenRead(), true);
                    }
                    FileStream fs_scratchPath = new FileStream("compresstimetest.zip", FileMode.OpenOrCreate, FileAccess.Write);
                    archive.SaveTo(fs_scratchPath, CompressionType.Deflate);
                    fs_scratchPath.Close();
                }
                //break;
                //}
                sw.Stop();
                Console.WriteLine("10time (ms):" + sw.ElapsedMilliseconds.ToString());
            }

            string scratchPath = "ziptest.zip";

            using (var archive = ZipArchive.Create()) {
                DirectoryInfo di = new DirectoryInfo(SCRATCH_FILES_PATH);
                foreach (var fi in di.GetFiles())
                {
                    archive.AddEntry(fi.Name, fi.OpenRead(), true);
                }
                FileStream fs_scratchPath = new FileStream(scratchPath, FileMode.OpenOrCreate, FileAccess.Write);
                archive.SaveTo(fs_scratchPath, CompressionType.LZMA);
                fs_scratchPath.Close();
                //archive.AddAllFromDirectory(SCRATCH_FILES_PATH);
                //archive.SaveTo(scratchPath, CompressionType.Deflate);
                using (FileStream fs = new FileStream("ziphead.zip", FileMode.OpenOrCreate, FileAccess.ReadWrite)) {
                    MyHead mh       = new MyHead();
                    byte[] headData = mh.Create();
                    fs.Write(headData, 0, headData.Length);
                    //
                    SharpCompress.IO.OffsetStream ofs = new IO.OffsetStream(fs, fs.Position);
                    archive.SaveTo(ofs, CompressionType.Deflate);
                }
            }
            //write my zipfile with head data
            using (FileStream fs = new FileStream("mypack.data.zip", FileMode.Create, FileAccess.ReadWrite, FileShare.Read)) {
                MyHead mh       = new MyHead();
                byte[] headData = mh.Create();
                fs.Write(headData, 0, headData.Length);
                using (FileStream fs2 = new FileStream(scratchPath, FileMode.Open, FileAccess.Read)) {
                    byte[] buf = new byte[1024];
                    int    rc  = 0;
                    while ((rc = fs2.Read(buf, 0, buf.Length)) > 0)
                    {
                        fs.Write(buf, 0, rc);
                    }
                }
            }
            //
            //read my zip file with head
            //
            using (FileStream fs = new FileStream("mypack.data.zip", FileMode.Open, FileAccess.Read, FileShare.Read)) {
                byte[] buf    = new byte[1024];
                int    offset = fs.Read(buf, 0, buf.Length);
                System.Diagnostics.Debug.Assert(offset == 1024);
                //fs.Position = 0L;
                SharpCompress.IO.OffsetStream substream = new SharpCompress.IO.OffsetStream(fs, offset);
                ZipArchive zip = ZipArchive.Open(substream, Options.KeepStreamsOpen);//cann't read
                //ZipArchive zip = ZipArchive.Open(fs, Options.None); //will throw exption
                //ZipArchive zip = ZipArchive.Open(fs, Options.KeepStreamsOpen);//cann't read

                foreach (ZipArchiveEntry zf in zip.Entries)
                {
                    Console.WriteLine(zf.Key);
                    //bug:the will not none in zipfile
                }

                int jjj = 0;
                jjj++;
            }
        }