/// <summary> 反转表文件 </summary>
    public void Rollback(string files)
    {
        List <string> fileNames = new List <string>(files.Split(';'));

        while (fileNames.Remove(""))
        {
        }
        if (fileNames.Count == 0)
        {
            Logger.info("请选择要转换的文件");
            return;
        }
        Progress.Count = fileNames.Count;
        int Count = 0;

        for (int i = 0; i < fileNames.Count; ++i)
        {
            Progress.Current = (i + 1);
            try {
                byte[] buffer = FileUtil.GetFileBuffer(fileNames[i]);
                try { buffer = GZipUtil.Decompress(buffer); } catch (System.Exception) { }
                TableReader reader = new TableReader(buffer);
                Rollback_impl(reader, fileNames[i]);
                reader.Close();
                Count++;
            } catch (System.Exception ex) {
                throw new Exception(string.Format("{0} 文件出错\r\n{1}", fileNames[i], ex.ToString()));
            }
        }
        if (Count > 0)
        {
            Logger.warn("转换结束");
        }
    }
Esempio n. 2
0
        private void btnGZipUtil_Click(object sender, EventArgs e)
        {
            //压缩解压缩文本内容
            string zippedContent = GZipUtil.Compress("wuhuacong");
            string original      = GZipUtil.Decompress(zippedContent);

            GZipUtil.Compress(Application.StartupPath, Application.StartupPath, "cityroad.zip");
            GZipUtil.Decompress(Application.StartupPath, Path.Combine(Application.StartupPath, "cityroad"), "cityroad.zip");

            MessageDxUtil.ShowTips("操作完成");
        }
Esempio n. 3
0
        public static IdKeyData RouterReceive(this RouterSocket socket)
        {
            IdKeyData    ikd = new IdKeyData();
            NetMQMessage msg = socket.ReceiveMultipartMessage();

            ikd.Id  = msg[0].ConvertToString(); //socket.Options.Identity
            ikd.Key = msg[2].ConvertToString();
            byte[] zipData = msg[3].Buffer;
            ikd.Data = GZipUtil.Decompress(zipData);

            return(ikd);
        }
 void ReceivedAudio(byte[] buffer)
 {
     try
     {
         if (soundPlayer != null)
         {
             soundPlayer.Write(GZipUtil.Decompress(buffer));
         }
     }
     catch (Exception)
     { }
 }
        void ReceivedVideoCallback(object obj)
        {
            object[] objs = (object[])obj;
            AdHocDesktop_TcpCommand command = (AdHocDesktop_TcpCommand)objs[0];

            byte[] buffer = (byte[])objs[1];
            lock (this)
            {
                if (command == AdHocDesktop_TcpCommand.StreamingCamera)
                {
                    using (Bitmap drawImage = ImageUtil.ByteToBitmap(buffer))
                    {
                        using (Graphics g = videoPanel.CreateGraphics())
                        {
                            g.DrawImage(drawImage, new Rectangle(new Point(0, 0), videoPanel.Size));
                        }
                    }
                }
                else
                {
                    try
                    {
                        byte[] image = null;

                        if (previousBuffer == null)
                        {
                            previousBuffer = GZipUtil.Decompress(buffer);
                            image          = previousBuffer;
                        }
                        else
                        {
                            byte[] currentBuffer = GZipUtil.Decompress(buffer);
                            image = ImageUtil.RecompareImage(previousBuffer, currentBuffer);
                        }
                        using (Bitmap drawImage = ImageUtil.ByteToBitmap(image))//, width, height, width * 3, PixelFormat.Format24bppRgb))
                        {
                            using (Graphics g = videoPanel.CreateGraphics())
                            {
                                g.DrawImage(drawImage, new Rectangle(new Point(0, 0), videoPanel.Size));
                            }
                        }

                        previousBuffer = null;
                        previousBuffer = image;
                        image          = null;
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
        /// <summary>
        /// 选择并加载.backup备份数据库文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 无损加载数据库ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (CanReadMdfFile() == false)
            {
                database.ResetConnection();
            }

            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Filter = "备份文件 (*.backup)|*.backup|所有文件 (*.*)|*.*";
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                GZipUtil.Decompress(new FileInfo(fileDialog.FileName), Properties.Resources.MdfFilename);
                MessageBox.Show("无损备份文件加载成功!", "加载成功", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Esempio n. 7
0
        void SendStreaming(AdHocDesktop_TcpClient client, byte[] buffer, AdHocDesktop_TcpCommand command)
        {
            bandwidthInput += (buffer == null ? 0 : buffer.Length);
            List <AdHocDesktop_TcpClient> groups = groupTable[client.Identifier];

            for (int i = 0; i < groups.Count; i++)
            {
                if (!groups[i].IsConnected)
                {
                    groups.RemoveAt(i);
                    i--;
                }
            }
            for (int i = 0; i < groups.Count; i++)
            {
                AdHocDesktop_TcpClient dest = groups[i];
                if (winceClients.Contains(dest.Identifier))
                {
                    Size size = new Size(240, 180);
                    if (command == AdHocDesktop_TcpCommand.StreamingCamera)
                    {
                        using (Bitmap b = ImageUtil.ByteToBitmap(buffer))
                        {
                            buffer = ImageUtil.ResizeBitmapToJpegByte(b, size);
                        }
                    }
                    else if (command == AdHocDesktop_TcpCommand.StreamingScreen)
                    {
                        using (Bitmap b = ImageUtil.ByteToBitmap(GZipUtil.Decompress(buffer)))
                        {
                            buffer = GZipUtil.Compress(ImageUtil.ResizeBitmapToByte(b, size));
                        }
                    }
                }
                dest.Send(new AdHocDesktop_TcpObject(command, client.Identifier, dest.Identifier, buffer));
                bandwidthOutput += (buffer == null ? 0 : buffer.Length);
            }
        }
Esempio n. 8
0
        public static void Load(Action <World> onComplete)
        {
            string path     = WorldStateSavePath;
            World  toReturn = null;

            if (File.Exists(path))
            {
                string data = GZipUtil.Decompress(File.ReadAllBytes(path)).Trim();
                try
                {
                    WorldState worldState = Newtonsoft.Json.JsonConvert.DeserializeObject <WorldState>(data);
                    Debug.Log($"loaded saved WorldState, seed: {worldState.seed}");
                    toReturn = new World(worldState);
                }
                catch
                {
                    Debug.LogError("could not deserialize saved world state data");
                    onComplete?.Invoke(null);
                }
            }
            else
            {
                Debug.LogFormat($"Could not find file at {path}, so it will be created");

                // check to make sure the directory exists before trying to write a file to it
                if (!Directory.Exists(Application.streamingAssetsPath))
                {
                    Directory.CreateDirectory(Application.streamingAssetsPath);
                }

                WorldState worldState = new WorldState(UnityEngine.Random.Range(int.MinValue, int.MaxValue));
                toReturn = new World(worldState);
            }

            toReturn.Save();
            onComplete(toReturn);
        }
Esempio n. 9
0
        public static FullRouteIPInfoCache CreateFromDownload(string url)
        {
            FullRouteIPInfoCache ret = new FullRouteIPInfoCache();

            ret.TimeStamp = DateTime.Now;

            // Download CSV
            WebRequest  req = HttpWebRequest.Create(url);
            WebResponse res = req.GetResponse();

            try
            {
                Stream stream = res.GetResponseStream();
                try
                {
                    byte[] rawData = Util.ReadAllFromStream(stream);
                    byte[] data    = GZipUtil.Decompress(rawData);

                    Csv csv = new Csv(new Buf(data));
                    foreach (CsvEntry?ce in csv.Items)
                    {
                        if (ce != null && ce.Count >= 7)
                        {
                            FullRouteIPInfoEntry e = new FullRouteIPInfoEntry();

                            e.From = Str.StrToUInt(ce[2]);
                            e.To   = Str.StrToUInt(ce[3]);
                            //e.Registry = ce[2];
                            //e.Assigned = Str.StrToUInt(ce[3]);
                            e.Country2 = ce[5];
                            //e.Country3 = ce[5];
                            e.CountryFull = DeleteSemi(ce[6]);

                            if (e.From != 0 && e.To != 0)
                            {
                                ret.EntryList.Add(e);
                            }
                        }
                    }

                    ret.EntryList.Sort();

                    if (ret.EntryList.Count <= 70000)
                    {
                        throw new ApplicationException("ret.EntryList.Count <= 70000");
                    }
                }
                finally
                {
                    stream.Close();
                }
            }
            finally
            {
                res.Close();
            }

            ret.build_country_code_to_name_db();

            return(ret);
        }