Beispiel #1
0
        public void Read_AttrMapping()
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, 0x09,
                0x73, 0x69, 0x6c, 0x6c,
                0x79, 0x70, 0x72, 0x6f,
                0x67, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x02,
                0x00, 0x00, 0x00, 0x04,
                0x6c, 0x69, 0x73, 0x70,
                0x00, 0x00, 0x00, 0x04,
                0x6a, 0x6f, 0x68, 0x6e,
                0x00, 0x00, 0x00, 0x06,
                0x28, 0x71, 0x75, 0x69,
                0x74, 0x29, 0x00, 0x00);

            ReadBuilder builder = new ReadBuilder()
                                  //.Map<CompleteFile>(CompleteFile.Read)
                                  //.Map<FileType>(FileType.Read)
            ;
            Reader r = builder.Create(s);

            CompleteFile result = r.Read <CompleteFile>();

            Assert.AreEqual(12 * 4, s.Position);
            Assert.IsNotNull(result);

//        0      00 00 00 09     ....     -- length of filename = 9
//        4      73 69 6c 6c     sill     -- filename characters
//        8      79 70 72 6f     ypro     -- ... and more characters ...
//       12      67 00 00 00     g...     -- ... and 3 zero-bytes of fill
            Assert.AreEqual("sillyprog", result.FileName);
//       16      00 00 00 02     ....     -- filekind is EXEC = 2
            Assert.AreEqual(FileKind.Exec, result.Type.Type);
            Assert.IsNull(result.Type.Creator);
//       20      00 00 00 04     ....     -- length of interpretor = 4
//       24      6c 69 73 70     lisp     -- interpretor characters
            Assert.AreEqual("lisp", result.Type.Interpretor);
//       28      00 00 00 04     ....     -- length of owner = 4
//       32      6a 6f 68 6e     john     -- owner characters
            Assert.AreEqual("john", result.Owner);
//       36      00 00 00 06     ....     -- length of file data = 6
//       40      28 71 75 69     (qui     -- file data bytes ...
//       44      74 29 00 00     t)..     -- ... and 2 zero-bytes of fill
            Assert.IsNotNull(result.Data);
            Assert.AreEqual(6, result.Data.Length);
            Assert.AreEqual(0x28, result.Data[0]);
            Assert.AreEqual(0x29, result.Data[5]);
        }
Beispiel #2
0
        void DownLoadComplete()
        {
            if (File.Exists(TempFile))
            {
                if (File.Exists(CompleteFile))
                {
                    File.Delete(CompleteFile);
                }

                try
                {
                    if (CheckMD5())
                    {
                        int    tindex         = CompleteFile.LastIndexOf('/');
                        string tcompletePagth = CompleteFile.Substring(0, tindex);

                        if (!Directory.Exists(tcompletePagth))
                        {
                            Directory.CreateDirectory(tcompletePagth);
                        }
                        File.Move(TempFile, CompleteFile);
                        IsCompleteDownLoad = true;
                        Error = null;
                    }
                    else
                    {
                        File.Delete(TempFile);
                        Error = string.Format("[URL] = {0},[Error] = Check MD5 fail.MD5 = {1},tempMd5 = {2}", SourceURL, MD5String, tempMD5);
                    }
                }
                catch (System.Exception error)
                {
                    Error = string.Format("[URL] = {0},[Error] = Check MD5 fail.MD5 = {1},error = {2}", SourceURL, MD5String, error.Message);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(Error))
                {
                    Error = string.Format("[URL] = {0},[Error] = file Can not found .MD5 = {1},tempfile = {2}", SourceURL, MD5String, TempFile);
                }
            }
        }
Beispiel #3
0
        public void Write_AttrMapping()
        {
            CompleteFile cf = new CompleteFile();

            cf.FileName         = "sillyprog";
            cf.Type             = new FileType();
            cf.Type.Type        = FileKind.Exec;
            cf.Type.Interpretor = "lisp";
            cf.Owner            = "john";
            cf.Data             = new byte[] { 0x28, 0x71, 0x75, 0x69, 0x74, 0x29 };

            ByteWriter s = new ByteWriter();

            WriteBuilder b = new WriteBuilder()
                             //.Map<CompleteFile>(CompleteFile.Write)
                             //.Map<FileType>(FileType.Write)
            ;
            Writer w = b.Create(s);

            w.Write <CompleteFile>(cf);

            byte[] expected = new byte[]
            {
                0x00, 0x00, 0x00, 0x09,
                0x73, 0x69, 0x6c, 0x6c,
                0x79, 0x70, 0x72, 0x6f,
                0x67, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x02,
                0x00, 0x00, 0x00, 0x04,
                0x6c, 0x69, 0x73, 0x70,
                0x00, 0x00, 0x00, 0x04,
                0x6a, 0x6f, 0x68, 0x6e,
                0x00, 0x00, 0x00, 0x06,
                0x28, 0x71, 0x75, 0x69,
                0x74, 0x29, 0x00, 0x00
            };

            Assert.AreEqual(expected, s.ToArray());
        }
        private void downloadCallback(string url, string filename, object obj)
        {
            var file_seg = (EmiliaFileSegment)obj;

            CompleteFile?.Invoke(null, file_seg);
            dispatcher_dictionary[file_seg.SeriesIndex].CompleteFile.Invoke(file_seg);

            lock (complete_lock)
            {
                int article_status = downloaded_count_dictionary[file_seg.SeriesIndex][file_seg.ArticleIndex] += 1;
                check_dictionary[file_seg.SeriesIndex][file_seg.ArticleIndex][file_seg.Index] = true;

                // 아티클 다운로드 완료
                if (article_status == series_dictionary[file_seg.SeriesIndex].Articles[file_seg.ArticleIndex].Files.Count)
                {
                    int series_status = downloaded_articles_count_dictionary[file_seg.SeriesIndex] += 1;
                    dispatcher_dictionary[file_seg.SeriesIndex].CompleteArticle.Invoke(series_dictionary[file_seg.SeriesIndex].Articles[file_seg.ArticleIndex]);
                    CompleteArticle?.Invoke(null, series_dictionary[file_seg.SeriesIndex].Articles[file_seg.ArticleIndex]);

                    // 시리즈 다운로드 완료
                    if (series_status == series_dictionary[file_seg.SeriesIndex].Articles.Count)
                    {
                        dispatcher_dictionary[file_seg.SeriesIndex].CompleteSeries();
                        CompleteSeries?.Invoke(null, series_dictionary[file_seg.SeriesIndex]);
                    }
                }
            }

            lock (add_lock)
            {
                remain_contents--;
                if (remain_contents == 0 && DownloadComplete != null)
                {
                    DownloadComplete.Invoke(null, null);
                }
            }
        }
Beispiel #5
0
        static void Issue167()
        {
            var completeFile = new CompleteFile
            {
                DataSource = "DataSource",
                DataType   = 1,
                Samples    = new Samples
                {
                    Samples1 = new List <Data>
                    {
                        new Data
                        {
                            Prop00     = 0,
                            Prop01     = "Prop01",
                            Properties = new Properties
                            {
                                Prop10 = 1,
                                Prop11 = 2,
                            }
                        },
                        new Data
                        {
                            Prop00     = 0,
                            Prop01     = "Prop01",
                            Properties = new Properties
                            {
                                Prop10 = 1,
                                Prop11 = 2,
                            }
                        },
                        new Data
                        {
                            Prop00     = 0,
                            Prop01     = "Prop01",
                            Properties = new Properties
                            {
                                Prop10 = 1,
                                Prop11 = 2,
                            }
                        },
                    },
                    Samples2 = new List <Data>
                    {
                        new Data
                        {
                            Prop00     = 0,
                            Prop01     = "Prop01",
                            Properties = new Properties
                            {
                                Prop10 = 1,
                                Prop11 = 2,
                            }
                        },
                        new Data
                        {
                            Prop00     = 0,
                            Prop01     = "Prop01",
                            Properties = new Properties
                            {
                                Prop10 = 1,
                                Prop11 = 2,
                            }
                        },
                        new Data
                        {
                            Prop00     = 0,
                            Prop01     = "Prop01",
                            Properties = new Properties
                            {
                                Prop10 = 1,
                                Prop11 = 2,
                            }
                        },
                    },
                    Samples3 = new List <Data>
                    {
                        new Data
                        {
                            Prop00     = 0,
                            Prop01     = "Prop01",
                            Properties = new Properties
                            {
                                Prop10 = 1,
                                Prop11 = 2,
                            }
                        },
                        new Data
                        {
                            Prop00     = 0,
                            Prop01     = "Prop01",
                            Properties = new Properties
                            {
                                Prop10 = 1,
                                Prop11 = 2,
                            }
                        },
                        new Data
                        {
                            Prop00     = 0,
                            Prop01     = "Prop01",
                            Properties = new Properties
                            {
                                Prop10 = 1,
                                Prop11 = 2,
                            }
                        },
                    },
                    Sample4 = new Data
                    {
                        Prop00     = 0,
                        Prop01     = "Prop01",
                        Properties = new Properties
                        {
                            Prop10 = 1,
                            Prop11 = 2,
                        }
                    },
                }
            };

            StringBuilder json = new StringBuilder();

            using (var w = new ChoJSONWriter <CompleteFile>(json)
                   )
            {
                w.Write(completeFile);
            }

            json.Print();

            using (var r = ChoJSONReader <CompleteFile> .LoadText(json.ToString())
                           .UseJsonSerialization()
                   )
            {
                using (var w = new ChoParquetWriter("CompleteFile.parquet")
                       )
                {
                    w.Write(r.Select(rec1 => rec1.FlattenToDictionary()));
                }

                //using (var w = new ChoParquetWriter<CompleteFile>("CompleteFile.parquet")
                //    .WithField(f => f.Samples, valueConverter: o => "x", fieldType: typeof(string))
                //    )
                //{
                //    w.Write(r); //.Select(rec1 => rec1.Flatten().ToDictionary()));
                //}
            }
        }