Beispiel #1
0
        /// <summary>
        /// Validates the WITSML Store API request.
        /// </summary>
        /// <param name="providers">The capServer providers.</param>
        /// <exception cref="WitsmlException"></exception>
        public static void ValidateRequest(IEnumerable <ICapServerProvider> providers)
        {
            var context = WitsmlOperationContext.Current;

            _log.DebugFormat("Validating WITSML request for {0}", context.Request.ObjectType);

            ValidateUserAgent(WebOperationContext.Current);

            context.OptionsIn = OptionsIn.Parse(context.Request.Options);

            // Document version is derived from the input string so it needs to be decompressed before the below checks.
            context.RequestCompressed = ValidateCompressedInput(context.Request.Function, context.Request.Xml, context.OptionsIn);

            var xml = context.RequestCompressed ? CompressionUtil.DecompressRequest(context.Request.Xml) : context.Request.Xml;

            context.Document = ValidateInputTemplate(xml);

            var dataSchemaVersion = ObjectTypes.GetVersion(context.Document.Root);

            ValidateDataSchemaVersion(dataSchemaVersion);

            var capServerProvider = providers.FirstOrDefault(x => x.DataSchemaVersion == dataSchemaVersion);

            if (capServerProvider == null)
            {
                throw new WitsmlException(ErrorCodes.DataObjectNotSupported,
                                          "WITSML object type not supported: " + context.Request.ObjectType + "; Version: " + dataSchemaVersion);
            }

            capServerProvider.ValidateRequest();
            context.DataSchemaVersion = dataSchemaVersion;
        }
        public object GetClientData(object data, ref BitSet flag, LanguageContext languageContext)
        {
            byte[] serializedObject = null;
            try
            {
                switch (languageContext)
                {
                case LanguageContext.DOTNET:
                    serializedObject = SerializationUtil.SafeSerialize(data, _context.SerializationFormat, _context.SerializationContext, ref flag) as byte[];
                    break;
                }

                if (serializedObject != null && _context.CompressionEnabled)
                {
                    serializedObject = CompressionUtil.Compress(serializedObject, ref flag, _context.CompressionThreshold);
                }
                if (serializedObject != null)
                {
                    return(UserBinaryObject.CreateUserBinaryObject(serializedObject, _context.TransactionalPoolManager));
                }
            }
            catch (Exception ex)
            {
                if (_context.NCacheLog != null)
                {
                    if (_context.NCacheLog.IsErrorEnabled)
                    {
                        _context.NCacheLog.Error("ObjectDataFormatService.GetClientData()", ex.Message);
                    }
                }
            }
            return(data);
        }
Beispiel #3
0
        public void CreateBr(string brPath, bool useMin)
        {
            if (useMin)
            {
                RemoveChar();
            }
            var pyShow = GetPinyins();
            var dict   = BuildPinyinDict(pyShow);

            var outPy = BuildSingleWord(pyShow, dict);

            Directory.CreateDirectory(brPath);
            File.WriteAllBytes(brPath + "/pyIndex.txt.br", CompressionUtil.BrCompress(Encoding.UTF8.GetBytes(outPy)));
            if (useMin == false)
            {
                var outPy2 = BuildData20000(dict);
                File.WriteAllBytes(brPath + "/pyIndex2.txt.br", CompressionUtil.BrCompress(Encoding.UTF8.GetBytes(outPy2)));
            }
            var words = BuildMiniWords(pyShow, dict);

            var ls = new List <string>();

            foreach (var item in words)
            {
                var        str = item;
                List <int> pys = dict[str];
                foreach (var py in pys)
                {
                    str += "," + py.ToString("X");
                }
                ls.Add(str);
            }
            ls = ls.OrderBy(q => q).ToList();
            File.WriteAllBytes(brPath + "/pyWords.txt.br", CompressionUtil.BrCompress(Encoding.UTF8.GetBytes(string.Join("\n", ls))));
        }
        public static int[,] Import(string Name)
        {
            if (!File.Exists("VoxelPatterns/" + Name + ".vxp"))
            {
                return(null);
            }


            byte[] Data = null;
            try
            {
                Data = File.ReadAllBytes("VoxelPatterns/" + Name + ".vxp");
            }
            catch (IOException e)
            {
                Debug.WriteLine(e.Message);
            }

            int ByteCount = 0;

            int VX = BitConverter.ToInt32(Data, ByteCount);

            ByteCount += 4;
            int VY = BitConverter.ToInt32(Data, ByteCount);

            ByteCount += 4;

            int DataLength = BitConverter.ToInt32(Data, ByteCount);

            ByteCount += 4;

            return(CompressionUtil.UnPackToIntArray(VX, VY, Data, ByteCount, DataLength));
        }
Beispiel #5
0
        public void WriteBr(string file)
        {
            var bytes = WritePinyinDat();

            Directory.CreateDirectory(Path.GetDirectoryName(file));
            File.WriteAllBytes(file, CompressionUtil.BrCompress(bytes));
        }
        protected RequestEntity GetRequestEntity(byte[] bytes)
        {
            using (var stream = new MemoryStream(bytes))
            {
                var reader = new BinaryReader(stream);

                var headerLen = reader.ReadInt32();
                stream.Seek(headerLen, SeekOrigin.Current);

                var compression = reader.ReadByte();

                var dataLen   = reader.ReadInt32();
                var dataBytes = reader.ReadBytes(dataLen);

                switch (compression)
                {
                case 1:
                    dataBytes = CompressionUtil.DecompressDef(dataBytes);
                    break;

                case 2:
                    dataBytes = CompressionUtil.DecompressLZ(dataBytes, false);
                    break;
                }

                var entity = SerializationUtil.Deserialize <RequestEntity>(dataBytes);
                return(entity);
            }
        }
Beispiel #7
0
        public WorldFile(byte[] Data)
        {
            int ByteCount = 0;

            LODID        = BitConverter.ToInt32(Data, ByteCount += 4);
            IDX          = BitConverter.ToInt32(Data, ByteCount += 4);
            IDY          = BitConverter.ToInt32(Data, ByteCount += 4);
            SX           = BitConverter.ToInt32(Data, ByteCount += 4);
            SY           = BitConverter.ToInt32(Data, ByteCount += 4);
            TerrainScale = BitConverter.ToSingle(Data, ByteCount += 4);

            int DataLength0 = BitConverter.ToInt32(Data, ByteCount += 4);
            int DataLength1 = BitConverter.ToInt32(Data, ByteCount += 4);
            int DataLength2 = BitConverter.ToInt32(Data, ByteCount += 4);
            int DataLength3 = BitConverter.ToInt32(Data, ByteCount += 4);
            int DataLength4 = BitConverter.ToInt32(Data, ByteCount += 4);
            int DataLength5 = BitConverter.ToInt32(Data, ByteCount += 4);
            int DataLength6 = BitConverter.ToInt32(Data, ByteCount += 4);
            int DataLength7 = BitConverter.ToInt32(Data, ByteCount += 4);

            MaterialMap          = CompressionUtil.UnPackToByteArray(SX + 1, SY + 1, Data, ByteCount += 4, DataLength1);
            SecondaryMaterialMap = CompressionUtil.UnPackToByteArray(SX + 1, SY + 1, Data, ByteCount += 4, DataLength0);
            DecalMaterialMap     = CompressionUtil.UnPackToByteArray(SX + 1, SY + 1, Data, ByteCount += 4, DataLength0);

            BlendAlphaMap = CompressionUtil.UnPackToByteArray(SX + 1, SY + 1, Data, ByteCount += 4, DataLength0);
            DecalAlphaMap = CompressionUtil.UnPackToByteArray(SX + 1, SY + 1, Data, ByteCount += 4, DataLength0);
        }
Beispiel #8
0
        private static ResponseEntity GetResponseEntity(byte[] bytes)
        {
            using (var stream = new MemoryStream(bytes))
            {
                var reader      = new BinaryReader(stream);
                var compression = reader.ReadByte();

                var dataLen   = reader.ReadInt32();
                var dataBytes = reader.ReadBytes(dataLen);

                switch (compression)
                {
                case 1:
                    dataBytes = CompressionUtil.DecompressDef(dataBytes);
                    break;

                case 2:
                    dataBytes = CompressionUtil.DecompressLZ(dataBytes, false);
                    break;
                }

                var responseEntity = SerializationUtil.Deserialize <ResponseEntity>(dataBytes);
                return(responseEntity);
            }
        }
Beispiel #9
0
        public IActionResult VerifyCode()
        {
            #region 防止网页后退--禁止缓存
            Response.Headers.Add("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
            Response.Headers.Add("Pragma", "no-cache");                                   // HTTP 1.0.
            Response.Headers.Add("Expires", "-1");                                        // Proxies.
            #endregion

            Random r    = new Random();
            string code = r.Next(10000, 100000).ToString();
            SetSession(SessionSetting.AdminLoginCode, code);
            VerifyCode vimg = new VerifyCode();
            vimg.FontSize = 30;
            var bytes           = vimg.CreateImageBytes(code);
            var AcceptEncodings = Request.Headers["Accept-Encoding"].ToString().Replace(" ", "").Split(',');
            if (AcceptEncodings.Contains("br"))
            {
                Response.Headers["Content-Encoding"] = "br";
                bytes = CompressionUtil.BrCompress(bytes, true);
            }
            else if (AcceptEncodings.Contains("gzip"))
            {
                Response.Headers["Content-Encoding"] = "gzip";
                bytes = CompressionUtil.GzipCompress(bytes, true);
            }
            return(File(bytes, "image/jpg"));
        }
Beispiel #10
0
 /// <summary>
 /// Send action (byte[]) to connected clients
 /// </summary>
 /// <param name="server"></param>
 /// <param name="action">action code</param>
 /// <param name="data">data to send to connected clients</param>
 /// <param name="compression">compress data using GZIP if set to true</param>
 public static void SendAllAction(this EasyTcpServer server, int action, byte[] data = null, bool compression = false)
 {
     if (compression && data != null)
     {
         data = CompressionUtil.Compress(data);
     }
     server.SendAll(BitConverter.GetBytes(action), data);
 }
Beispiel #11
0
 /// <summary>
 /// Send data (byte[]) to connected clients
 /// </summary>
 /// <param name="server"></param>
 /// <param name="data">data to send to connected clients</param>
 /// <param name="compression">compress data using GZIP if set to true</param>
 public static void SendAll(this EasyTcpServer server, byte[] data, bool compression = false)
 {
     if (compression)
     {
         data = CompressionUtil.Compress(data);
     }
     server.SendAll(dataArray: data);
 }
Beispiel #12
0
 /// <summary>
 /// Send data to remote host
 /// </summary>
 /// <param name="client"></param>
 /// <param name="data">data to send to remote host</param>
 /// <param name="compression">compress data using deflate if set to true</param>
 public static void Send(this EasyTcpClient client, byte[] data, bool compression = false)
 {
     if (compression)
     {
         data = CompressionUtil.Compress(data);
     }
     client.Protocol.SendMessage(client, data);
 }
Beispiel #13
0
 /// <summary>
 /// Send action to remote host
 /// </summary>
 /// <param name="client"></param>
 /// <param name="action">action code</param>
 /// <param name="data">data to send to remote host</param>
 /// <param name="compression">compress data using deflate if set to true</param>
 public static void SendAction(this EasyTcpClient client, int action, byte[] data = null, bool compression = false)
 {
     if (compression && data != null)
     {
         data = CompressionUtil.Compress(data);
     }
     client.Send(BitConverter.GetBytes(action), data);
 }
Beispiel #14
0
 /// <summary>
 /// Send data (byte[]) to the remote host
 /// </summary>
 /// <param name="client"></param>
 /// <param name="data">data to send to server</param>
 /// <param name="compression">compress data using GZIP if set to true</param>
 public static void Send(this EasyTcpClient client, byte[] data, bool compression = false)
 {
     if (compression)
     {
         data = CompressionUtil.Compress(data);
     }
     SendMessage(client?.BaseSocket, CreateMessage(data));
 }
        public void TestStringToBytesCompressed()
        {
            const string a            = "abcd";
            var          bytes        = a.GetBytes();
            var          compressed   = CompressionUtil.Compress(bytes);
            var          decompressed = CompressionUtil.Decompress(compressed);

            Assert.AreEqual(a, StringExtensions.GetString(decompressed));
        }
Beispiel #16
0
        private void checkIfRomsArePresent(string[] pArchivePaths, ref Dictionary <string, HootRomCheckStruct[]> pHootSet,
                                           string pSetArchiveName, bool pIncludeSubDirectories)
        {
            ArrayList archiveContents;

            string[] setArchiveSplitParameters = { "," };
            string[] setArchiveNames           = pSetArchiveName.Split(setArchiveSplitParameters, StringSplitOptions.RemoveEmptyEntries);

            foreach (string path in pArchivePaths)
            {
                if (Directory.Exists(path))
                {
                    string[] archiveFiles;
                    string   archiveName;

                    foreach (string splitArchiveName in setArchiveNames)
                    {
                        archiveName = splitArchiveName;

                        // add .zip if needed for split archives
                        if (!archiveName.EndsWith(".zip"))
                        {
                            archiveName = archiveName + ".zip";
                        }

                        if (pIncludeSubDirectories)
                        {
                            archiveFiles = Directory.GetFiles(path, archiveName, SearchOption.AllDirectories);
                        }
                        else
                        {
                            archiveFiles = Directory.GetFiles(path, archiveName, SearchOption.TopDirectoryOnly);
                        }

                        if (archiveFiles.Length > 1)
                        {
                            this.progressStruct.Clear();
                            this.progressStruct.GenericMessage = String.Format("WARNING: Multiple copies of {0} found, results may be inaccurate", pSetArchiveName);
                            ReportProgress(this.progress, this.progressStruct);
                        }

                        foreach (string file in archiveFiles)
                        {
                            archiveContents = new ArrayList(CompressionUtil.GetUpperCaseFileList(file));

                            for (int i = 0; i < pHootSet[pSetArchiveName].Length; i++)
                            {
                                if (archiveContents.Contains(pHootSet[pSetArchiveName][i].RomName.Replace('/', Path.DirectorySeparatorChar).ToUpper()))
                                {
                                    pHootSet[pSetArchiveName][i].IsPresent = true;
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #17
0
        private static void DoPacking(ExportImportJob exportJob, string dbName)
        {
            var exportFileArchive = Path.Combine(ExportFolder, exportJob.Directory, Constants.ExportZipDbName);
            var folderOffset      = exportFileArchive.IndexOf(Constants.ExportZipDbName, StringComparison.Ordinal);

            File.Delete(CompressionUtil.AddFileToArchive(dbName, exportFileArchive, folderOffset)
                ? dbName
                : exportFileArchive);
        }
Beispiel #18
0
 /// <summary>
 /// Send data (byte[]) to remote host. Then wait and return the reply
 /// </summary>
 /// <param name="client"></param>
 /// <param name="data">data to send to remote host</param>
 /// <param name="timeout">maximum time to wait for a reply, if time expired this function returns null</param>
 /// <param name="compression">compress data using GZIP if set to true</param>
 /// <returns>received reply</returns>
 public static Message SendAndGetReply(this EasyTcpClient client, byte[] data, TimeSpan?timeout = null,
                                       bool compression = false)
 {
     if (compression)
     {
         data = CompressionUtil.Compress(data);
     }
     return(client.SendAndGetReply(timeout, data));
 }
Beispiel #19
0
 /// <summary>
 /// Send action (byte[]) to remote host. Then wait and return the reply
 /// </summary>
 /// <param name="client"></param>
 /// <param name="action">action code</param>
 /// <param name="data">data to send to remote host</param>
 /// <param name="timeout">maximum time to wait for a reply, if time expired this function returns null</param>
 /// <param name="compression">compress data using GZIP if set to true</param>
 /// <returns>received reply</returns>
 public static Message SendActionAndGetReply(this EasyTcpClient client, int action, byte[] data = null,
                                             TimeSpan?timeout = null, bool compression = false)
 {
     if (compression && data != null)
     {
         data = CompressionUtil.Compress(data);
     }
     return(client.SendAndGetReply(timeout, BitConverter.GetBytes(action), data));
 }
        private void ProcessImportModulePackages(ImportDto importDto)
        {
            var packageZipFile = $"{Globals.ApplicationMapPath}{Constants.ExportFolder}{this.exportImportJob.Directory.TrimEnd('\\', '/')}\\{Constants.ExportZipPackages}";
            var tempFolder     = $"{Path.GetDirectoryName(packageZipFile)}\\{DateTime.Now.Ticks}";

            if (File.Exists(packageZipFile))
            {
                CompressionUtil.UnZipArchive(packageZipFile, tempFolder);
                var exportPackages = this.Repository.GetAllItems <ExportPackage>().ToList();

                this.CheckPoint.TotalItems = this.CheckPoint.TotalItems <= 0 ? exportPackages.Count : this.CheckPoint.TotalItems;
                if (this.CheckPointStageCallback(this))
                {
                    return;
                }

                if (this.CheckPoint.Stage == 0)
                {
                    try
                    {
                        foreach (var exportPackage in exportPackages)
                        {
                            this.ProcessImportModulePackage(exportPackage, tempFolder, importDto.CollisionResolution);

                            this.CheckPoint.ProcessedItems++;
                            this.CheckPoint.Progress = this.CheckPoint.ProcessedItems * 100.0 / exportPackages.Count;
                            if (this.CheckPointStageCallback(this))
                            {
                                break;
                            }
                        }

                        this.CheckPoint.Stage++;
                        this.CheckPoint.Completed = true;
                    }
                    finally
                    {
                        this.CheckPointStageCallback(this);
                        try
                        {
                            FileSystemUtils.DeleteFolderRecursive(tempFolder);
                        }
                        catch (Exception)
                        {
                            // ignore
                        }
                    }
                }
            }
            else
            {
                this.CheckPoint.Completed = true;
                this.CheckPointStageCallback(this);
                this.Result.AddLogEntry("PackagesFileNotFound", "Packages file not found. Skipping packages import", ReportLevel.Warn);
            }
        }
Beispiel #21
0
        private static void Compression(string file)
        {
            var bytes = File.ReadAllBytes(file);
            var bs    = CompressionUtil.GzipCompress(bytes);

            Directory.CreateDirectory("dict");
            File.WriteAllBytes("dict\\" + file + ".z", bs);

            var bs2 = CompressionUtil.BrCompress(bytes);

            File.WriteAllBytes("dict\\" + file + ".br", bs2);
        }
        public byte[] Serialize(object obj)
        {
            var data = SerializerFactory.Serializer(obj);

            if (data.Length > 1024 * 1 * 1024)
            {
                return(ByteUtil.Combine(CompressedBytes, CompressionUtil.Compress(data)));
            }
            else
            {
                return(ByteUtil.Combine(UnCompressedBytes, data));
            }
        }
Beispiel #23
0
        private static string UnPackDatabase(string folderPath)
        {
            var dbName = Path.Combine(folderPath, Constants.ExportDbName);

            if (File.Exists(dbName))
            {
                return(dbName);
            }
            var zipDbName = Path.Combine(folderPath, Constants.ExportZipDbName);

            CompressionUtil.UnZipFileFromArchive(Constants.ExportDbName, zipDbName, folderPath, false);
            return(dbName);
        }
Beispiel #24
0
        public static T Deserialize <T>(byte[] compressedBytes)
        {
            // TODO: should not use ecs specific compressor when extracted
            var decompressedBytes  = CompressionUtil.Decompress(compressedBytes);
            var serializedString   = Encoding.UTF8.GetString(decompressedBytes);
            var deserializedObject = JsonConvert.DeserializeObject <T>(serializedString,
                                                                       new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.All
            });

            return(deserializedObject);
        }
Beispiel #25
0
        private static void DoUnPacking(ExportImportJob importJob)
        {
            var extractFolder = Path.Combine(ExportFolder, importJob.Directory);
            var dbName        = Path.Combine(extractFolder, Constants.ExportDbName);

            if (File.Exists(dbName))
            {
                return;
            }
            var zipDbName = Path.Combine(extractFolder, Constants.ExportZipDbName);

            CompressionUtil.UnZipFileFromArchive(Constants.ExportDbName, zipDbName, extractFolder, false);
        }
Beispiel #26
0
        private void WriteBr(string outFile, Dictionary <string, string> ts)
        {
            List <string> list = new List <string>();

            foreach (var item in ts)
            {
                list.Add($"{item.Key}\t{item.Value}");
            }
            var str = string.Join("\n", list);

            File.WriteAllBytes(outFile, CompressionUtil.BrCompress(Encoding.UTF8.GetBytes(str)));
            //File.WriteAllText(outFile, str, Encoding.UTF8);
        }
Beispiel #27
0
        // TODO: candidate for move to playgen.photon
        // extend messsage deserialization to support configurable serializeration handlers per message type?

        public static byte[] Serialize(object content)
        {
            var serialziedString = JsonConvert.SerializeObject(content,
                                                               Formatting.None,
                                                               new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.All
            });

            var bytes           = Encoding.UTF8.GetBytes(serialziedString);
            var compressedBytes = CompressionUtil.Compress(bytes);

            return(compressedBytes);
        }
Beispiel #28
0
        private JSONDocument DeserializeDocument(byte[] data)
        {
            var stream = new ClusteredMemoryStream(data);
            int header = stream.ReadByte();

            if ((header & (long)PersistenceBits.Compressed) == (decimal)PersistenceBits.Compressed)
            {
                stream = CompressionUtil.Decompress(stream);
            }
            var document = JSONDocument.Deserialize(stream);// CompactBinaryFormatter.Deserialize(stream, string.Empty);

            stream.Dispose();
            return(document as JSONDocument);
        }
Beispiel #29
0
        private void WriteDataSetToXml(string reportOutPutPath, string fileName, DataSet dsReportDate)
        {
            string filePath = Path.Combine(reportOutPutPath, fileName);

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            MemoryStream ms = new MemoryStream();

            dsReportDate.WriteXml(ms);

            File.WriteAllBytes(filePath, CompressionUtil.CompressZipFile(ms.ToArray(), Path.GetFileNameWithoutExtension(fileName) + ".xml"));
        }
Beispiel #30
0
 public static void CompressMZipEnc(afh.Application.Log log)
 {
     log.WriteLine("gzcomp.cs を圧縮中 ...");
     //System.IO.Stream sread=System.IO.File.OpenRead(@"compress-test\gzcomp.cs");
     //System.IO.Stream swrite=System.IO.File.OpenWrite(@"compress-test\gzcomp.cs.mwg");
     //System.IO.Stream sread=System.IO.File.OpenRead(@"compress-test\test.txt");
     //System.IO.Stream swrite=System.IO.File.OpenWrite(@"compress-test\test.txt.mwg");
     System.IO.Stream sread  = System.IO.File.OpenRead(@"compress-test\target.htm");
     System.IO.Stream swrite = System.IO.File.OpenWrite(@"compress-test\target.mwg");
     System.IO.Stream comp   = CompressionUtil.MZipCompress(sread);
     afh.File.StreamUtil.PassAll(swrite, comp);
     swrite.Close();
     comp.Close();
     sread.Close();
 }