Пример #1
0
        public List <T> GetObjectChunkUploadClassList <T>(string chunkKeyCurrentComplete, List <T> listEntity) where T : class
        {
            List <T> result = new List <T>();

            if (listEntity == null)
            {
                if (!string.IsNullOrEmpty(chunkKeyCurrentComplete))
                {
                    string[] checkChunk = chunkKeyCurrentComplete.ToString().Split("_");
                    string   key1       = string.Empty;
                    string   key2       = string.Empty;
                    if (checkChunk.Count() > 1)
                    {
                        key1 = checkChunk[0];
                        key2 = checkChunk[1];
                        if (key2.ToString().ToLower().Contains("complete"))
                        {
                            string[] checkChunkDetail = key2.ToString().Split("|");
                            int      maxCount         = 0;
                            if (checkChunkDetail.Count() > 1)
                            {
                                maxCount = Convert.ToInt32(checkChunkDetail[1]);
                                ChunkDataInfo dataInfo = new ChunkDataInfo
                                {
                                    ChunkKey      = key1,
                                    ChunkMaxCount = maxCount
                                };
                                ChunkDataResult resultTemp = CompressObject.GetInstance.ChunkDataUploadSvrVerify(dataInfo);
                                result = CompressObject.GetInstance.ConvertChunkDataResultToList <T>(resultTemp);
                            }
                        }
                    }
                }
            }
            result = listEntity;
            return(result);
        }
Пример #2
0
 public byte[] GetObjectChunkUploadByte(string chunkKeyCurrentComplete, byte[] bite)
 {
     byte[] result = null;
     if (bite == null)
     {
         if (!string.IsNullOrEmpty(chunkKeyCurrentComplete))
         {
             string[] checkChunk = chunkKeyCurrentComplete.ToString().Split("_");
             string   key1       = string.Empty;
             string   key2       = string.Empty;
             if (checkChunk.Count() > 1)
             {
                 key1 = checkChunk[0];
                 key2 = checkChunk[1];
                 if (key2.ToString().ToLower().Contains("complete"))
                 {
                     string[] checkChunkDetail = key2.ToString().Split("|");
                     int      maxCount         = 0;
                     if (checkChunkDetail.Count() > 1)
                     {
                         maxCount = Convert.ToInt32(checkChunkDetail[1]);
                         ChunkDataInfo dataInfo = new ChunkDataInfo
                         {
                             ChunkKey      = key1,
                             ChunkMaxCount = maxCount
                         };
                         ChunkDataResult resultTemp = CompressObject.GetInstance.ChunkDataUploadSvrVerify(dataInfo);
                         result = CompressObject.GetInstance.ConvertChunkDataResultToByteArray(resultTemp);
                     }
                 }
             }
         }
     }
     result = bite;
     return(result);
 }
Пример #3
0
        public ChunkDataResult ChunkDataUploadSvrVerify(ChunkDataInfo chunk)
        {
            // if you want to call this methode... just make sure all your loop ChunkDataUploadSvrAsync has been finished
            ChunkDataResult dataResult = new ChunkDataResult();

            string chunkKey   = chunk.ChunkKey;
            int    chunkCount = chunk.ChunkMaxCount;

            byte[]           byteData  = null;
            List <ChunkData> listChunk = new List <ChunkData>();
            int    tryTimes            = 0;
            int    maxTryTimes         = 6;// max 1 minute for waiting
            string tempForByte         = string.Empty;

            while (true)
            {
                tryTimes++;
                for (int i = 0; i < chunkCount; i++)
                {
                    object obj = cacher.GetValue(chunkKey + "_" + (i + 1).ToString());
                    if (obj != null)
                    {
                        listChunk.Add((ChunkData)obj);
                    }
                    else
                    {
                        string a = string.Empty;
                    }
                }
                if (listChunk.Count == chunkCount)
                {
                    break;
                }
                if (tryTimes == maxTryTimes)
                {
                    break;
                }
                listChunk = new List <ChunkData>();
                Task.Delay(10000);
            }
            if (listChunk.Count > 0)
            {
                string strChunked64Base = string.Empty;//it's str64base
                var    makna            = listChunk.OrderBy(a => a.ChunkCurrent).ToList();
                foreach (var item in listChunk.OrderBy(a => a.ChunkCurrent).ToList())
                {
                    strChunked64Base = strChunked64Base + item.DataChunk;
                }
                if (!string.IsNullOrEmpty(strChunked64Base))
                {
                    tempForByte = this.DeCompressedData(strChunked64Base);
                    //  var sshasil = Newtonsoft.Json.JsonConvert.DeserializeObject<List<RFIDTagStorage_Testing>>(sss);
                    byteData = Convert.FromBase64String(strChunked64Base);
                }
                dataResult.FileNameWithExt = listChunk[0].FileName;
                dataResult.DataChunk       = tempForByte;
            }


            return(dataResult);
        }
Пример #4
0
            private void ParseData(string fileName)
            {
                using (var reader = new FileReader(fileName))
                {
                    reader.SetByteOrder(true);

                    //Now for the chunk table. It basically has 2 sections.
                    //One is for files
                    //The second contains the data

                    List <ChunkFileInfo> fileChunks = new List <ChunkFileInfo>();

                    reader.SeekBegin(FileTableOffset);
                    for (int i = 0; i < NumFileEntries; i++)
                    {
                        ChunkDataInfo chunk = new ChunkDataInfo();
                        DataChunks.Add(chunk);

                        byte chunkFlags = reader.ReadByte();
                        byte unk        = reader.ReadByte(); //1
                        chunk.Type   = (SectionMagic)reader.ReadUInt16();
                        chunk.Size   = reader.ReadUInt32();
                        chunk.Offset = reader.ReadUInt32();

                        if (chunkFlags == 0x12)
                        {
                            chunk.BlockIndex = 0;
                        }
                        if (chunkFlags == 0x25)
                        {
                            chunk.BlockIndex = 1;
                        }
                        if (chunkFlags == 2)
                        {
                            chunk.BlockIndex = 2;
                        }
                        if (chunkFlags == 0x42)
                        {
                            chunk.BlockIndex = 3;
                        }
                        if (chunkFlags == 3)
                        {
                            chunk.BlockIndex = 0;
                        }
                    }

                    while (reader.Position <= reader.BaseStream.Length - 12)
                    {
                        ChunkDataInfo chunk = new ChunkDataInfo();
                        DataChunks.Add(chunk);

                        byte chunkFlags = reader.ReadByte();
                        byte unk        = reader.ReadByte(); //1
                        chunk.Type   = (SectionMagic)reader.ReadUInt16();
                        chunk.Size   = reader.ReadUInt32();
                        chunk.Offset = reader.ReadUInt32();

                        byte blockFlag = (byte)(chunkFlags >> 4);
                        if (blockFlag < 7)
                        {
                            chunk.BlockIndex = (sbyte)blockFlag;
                        }

                        /*    Console.WriteLine($"chunkFlags { chunkFlags }");
                         *  Console.WriteLine($"unk { unk }");
                         *  Console.WriteLine($"Type { chunk.Type }");
                         *  Console.WriteLine($"Offset { chunk.Offset }");
                         *  Console.WriteLine($"Size { chunk.Size }");*/
                    }

                    return;
                }
            }