Ejemplo n.º 1
0
        public void SavePlayer()
        {
            var health = HealthManager.Export();
            var inv    = Inventory.GetBytes();
            var buffer = new DataBuffer(new byte[0]);

            ConsoleFunctions.WriteInfoLine("Position Saving... (X: " + KnownPosition.X + " Y: " + KnownPosition.Y + " Z: " + KnownPosition.Z + " Yaw: " + KnownPosition.Yaw + " Pitch: " + KnownPosition.Pitch + " OnGround: " + KnownPosition.OnGround + ")");
            buffer.WriteDouble(KnownPosition.X);
            buffer.WriteDouble(KnownPosition.Y);
            buffer.WriteDouble(KnownPosition.Z);
            buffer.WriteFloat(KnownPosition.Yaw);
            buffer.WriteFloat(KnownPosition.Pitch);
            buffer.WriteBool(KnownPosition.OnGround);
            buffer.WriteVarInt((int)Gamemode);
            buffer.WriteVarInt(health.Length);
            foreach (var b in health)
            {
                buffer.WriteByte(b);
            }
            buffer.WriteVarInt(inv.Length);
            foreach (var b in inv)
            {
                buffer.WriteByte(b);
            }
            buffer.WriteBool(IsOperator);

            var data = buffer.ExportWriter;

            data = FileCompression.Compress(data);
            var savename = Server.ServerSettings.OnlineMode ? Uuid : Username;

            File.WriteAllBytes("Players/" + savename + ".pdata", data);
        }
Ejemplo n.º 2
0
        public void CompressTest1()
        {
            var               fileNames = new List <FileInfo>();
            string            filePath  = Environment.CurrentDirectory + "\\";
            IEnumerable <int> nums      = Enumerable.Range(1, 20);

            foreach (int i in nums)
            {
                string       fileName     = filePath + i + ".txt";
                var          fileInfo     = new FileInfo(fileName);
                StreamWriter streamWriter = fileInfo.CreateText();
                streamWriter.WriteLine(i.ToString());
                streamWriter.Flush();
                streamWriter.Close();
                fileNames.Add(fileInfo);
            }

            string zipFileName      = Environment.CurrentDirectory + "\\" + "outData.zip";
            string password         = "******";
            int?   compressionLevel = 9;
            int?   sleepTimer       = 200;
            bool   expected         = true;
            bool   actual;

            actual = FileCompression.Compress(fileNames, zipFileName, password, compressionLevel, sleepTimer);
            Assert.AreEqual(expected, actual);

            var file = new FileInfo(zipFileName);

            Assert.IsTrue(file.Exists);
        }
Ejemplo n.º 3
0
        public void ExportData(HttpContext context)
        {
            List <UserExportInfo> lu = JsonDeserialize <List <UserExportInfo> >(Common.GetRequest("userInfoList"));
            List <string>         ls = JsonDeserialize <List <string> >(Common.GetRequest("amountNameList"));

            for (int i = 0; i < ls.Count; i++)         //外循环是循环的次数
            {
                for (int j = ls.Count - 1; j > i; j--) //内循环是 外循环一次比较的次数
                {
                    if (ls[i] == ls[j])
                    {
                        ls.RemoveAt(j);
                    }
                }
            }
            List <FileInfo> li = new List <FileInfo>();
            //string AUserID = "110,108";
            string fileName;
            string path;

            for (int i = 0; i < ls.Count; i++)
            {
                List <UserExportInfo> luTemp = lu.Where(m => m.AmountName == ls[i]).ToList();
                string        aae            = lu[i].AnswerID.ToString();
                StringBuilder builder;
                FileInfo      file;
                StreamWriter  sw;
                GetToWord(luTemp, out fileName, out path, out builder, out file, out sw);
                sw.Write(builder);
                sw.Close();
                li.Add(file);
            }
            fileName = DateTime.Now.ToString("yyyyMMddhhmm") + "_Download.zip";//重新赋值为zip文件名称
            path     = context.Server.MapPath("~/xls_down/" + fileName + ".xls");
            try
            {
                FileCompression.Compress(li, path, 5, 5);//压缩
                context.Response.ContentType = "application/zip";
                FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
                //Byte[] bytes = new Byte[fs.Length];
                fs.Close();

                MemoryStream ms    = new MemoryStream();
                FileStream   file  = new FileStream(path, FileMode.Open, FileAccess.Read);
                byte[]       bytes = new byte[file.Length];
                file.Read(bytes, 0, (int)file.Length);
                ms.Write(bytes, 0, (int)file.Length);
                file.Close();
                ms.Close();
                context.Response.Write(ms.GetBuffer());
                HttpContext.Current.ApplicationInstance.CompleteRequest();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Ejemplo n.º 4
0
 public override void SaveChunks(string folder)
 {
     lock (ChunkCache)
     {
         foreach (var i in ChunkCache.Values.ToArray())
         {
             File.WriteAllBytes(_folder + "/" + i.X + "." + i.Z + ".cfile", FileCompression.Compress(i.Export()));
         }
     }
 }
        public void Export()
        {
            List <UserExportInfo> lu = JsonDeserialize <List <UserExportInfo> >(Common.GetRequest("userInfoList"));
            List <string>         ls = JsonDeserialize <List <string> >(Common.GetRequest("amountNameList"));

            for (int i = 0; i < ls.Count; i++)         //外循环是循环的次数
            {
                for (int j = ls.Count - 1; j > i; j--) //内循环是 外循环一次比较的次数
                {
                    if (ls[i] == ls[j])
                    {
                        ls.RemoveAt(j);
                    }
                }
            }
            List <FileInfo> li = new List <FileInfo>();
            //string AUserID = "110,108";
            string fileName = "";
            string path     = "";

            for (int i = 0; i < ls.Count; i++)
            {
                List <UserExportInfo> luTemp = lu.Where(m => m.AmountName == ls[i]).ToList();
                string        aae            = lu[i].AnswerID.ToString();
                StringBuilder builder;
                FileInfo      file;
                StreamWriter  sw;
                GetToWord(luTemp, out fileName, out path, out builder, out file, out sw, li.Count + 1);
                sw.Write(builder);
                sw.Close();
                li.Add(file);
            }
            fileName = DateTime.Now.ToString("yyyyMMddhhmm") + "_Download.zip"; //重新赋值为zip文件名称
            path     = Server.MapPath("~/xls_down/" + fileName + ".xls");
            FileCompression.Compress(li, path, 5, 5);                           //压缩
            Response.Clear();
            Response.Buffer      = true;
            this.EnableViewState = false;
            Response.Charset     = "utf-8";
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
            Response.ContentType = "application/octet-stream";
            Response.WriteFile(path);
            Response.Flush();
            Response.Close();
            Response.End();
        }
Ejemplo n.º 6
0
        public void CompressTest()
        {
            string       fileName     = Environment.CurrentDirectory + "\\" + "TestFile.txt";
            var          fileInfo     = new FileInfo(fileName);
            StreamWriter streamWriter = fileInfo.CreateText();

            streamWriter.WriteLine("AAAAA");
            streamWriter.Flush();
            streamWriter.Close();

            string zipFileName = Environment.CurrentDirectory + "\\" + "TestFile.zip";
            string password    = "******";
            bool   expected    = true;
            bool   actual;

            actual = FileCompression.Compress(fileInfo, zipFileName, password, null);
            Assert.AreEqual(expected, actual);

            fileInfo = new FileInfo(zipFileName);
            Assert.IsTrue(fileInfo.Exists);
        }
Ejemplo n.º 7
0
        public void HttpPostDataTest()
        {
            var fileName   = System.Environment.CurrentDirectory + "\\upload.xml";
            var zipName    = System.Environment.CurrentDirectory + "\\upload.zip";
            var license    = "71C304D6-6E75-2370-0B49-8794CE8452D9";
            var fileInfo   = new FileInfo(fileName);
            var fileStream = fileInfo.AppendText();

            fileStream.WriteLine(@"<?xml version=""1.0""?>");
            fileStream.WriteLine(@"<DemandForce licenseKey=""71C304D6-6E75-2370-0B49-8794CE8452D9"" dFLinkVersion=""3.7.119"" >");
            fileStream.WriteLine(@"<Business>");
            fileStream.WriteLine(@"    <Customer id=""7"" parentId=""7"" provider=""3"" firstVisit=""2009-08-04T07:26:05Z"" insuranceType=""Other"">");
            fileStream.WriteLine(@"      <Demographics firstName=""Maria"" lastName=""Cintron"" gender=""2"" birthday=""1984-04-01T00:00:00Z"" />");
            fileStream.WriteLine(@"    </Customer>");
            fileStream.WriteLine(@"</Business>");
            fileStream.WriteLine(@"</DemandForce>");
            fileStream.Flush();
            fileStream.Close();

            FileCompression.Compress(fileInfo, zipName, license, null);

            var  zipInfo = new FileInfo(zipName);
            long size    = zipInfo.Length;

            var url          = "https://dflink.sandbox.demandforced3.com/upload/1.0/xml.jsp";
            var timeOut      = 30 * 1000;
            var fileKeyName  = "upload";
            var filePathName = zipName;
            NameValueCollection stringDict = new NameValueCollection();

            stringDict.Add("user", "*****@*****.**");
            stringDict.Add("pass", string.Empty);
            stringDict.Add("license", license);

            string actual = HttpUtils.PostFormData(url, timeOut, fileKeyName, filePathName, stringDict);

            Assert.IsTrue(actual.Contains("zip with size of " + size.ToString() + " bytes.  BusinessId ="));
        }
        protected void btn_import_07_click(object sender, EventArgs e)
        {
            //try
            //{

            List <UserExportInfo> lu = JsonDeserialize <List <UserExportInfo> >(Request["userInfoList"]);
            List <string>         ls = JsonDeserialize <List <string> >(Request["amountNameList"]);

            for (int i = 0; i < ls.Count; i++)         //外循环是循环的次数
            {
                for (int j = ls.Count - 1; j > i; j--) //内循环是 外循环一次比较的次数
                {
                    if (ls[i] == ls[j])
                    {
                        ls.RemoveAt(j);
                    }
                }
            }
            List <FileInfo> li = new List <FileInfo>();
            //string AUserID = "110,108";
            string fileName = "";
            string path     = "";

            for (int i = 0; i < ls.Count; i++)
            {
                List <UserExportInfo> luTemp = lu.Where(m => m.AmountName == ls[i]).ToList();
                string        aae            = lu[i].AnswerID.ToString();
                StringBuilder builder        = new StringBuilder();
                FileInfo      file           = null;
                StreamWriter  sw;
                if (ls[i].IndexOf("Rutter儿童行为问卷") > -1)
                {
                    GetToWordS(luTemp, out fileName, out path, out builder, out file, out sw);
                }
                else
                {
                    GetToWord(luTemp, out fileName, out path, out builder, out file, out sw, li.Count + 1);
                }
                sw.Write(builder);
                sw.Close();
                li.Add(file);
            }
            fileName = DateTime.Now.ToString("yyyyMMddhhmm") + "_Download.zip"; //重新赋值为zip文件名称
            path     = Server.MapPath("~/xls_down/" + fileName + ".xls");
            FileCompression.Compress(li, path, 5, 5);                           //压缩
            Response.Clear();
            Response.Buffer      = true;
            this.EnableViewState = false;
            Response.Charset     = "utf-8";
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
            Response.ContentType = "application/octet-stream";
            Response.WriteFile(path);
            Response.Flush();
            //Response.Close();
            HttpContext.Current.Response.End();
            //}
            //catch (Exception ex)
            //{
            //    Response.End();

            //}
            //finally
            //{
            //    HttpContext.Current.Response.End();
            //}
        }
Ejemplo n.º 9
0
 private bool SaveChunk(ChunkColumn chunk)
 {
     File.WriteAllBytes(_folder + "/" + chunk.X + "." + chunk.Z + ".cfile", FileCompression.Compress(chunk.Export()));
     return(true);
 }