示例#1
0
        private static int RunUploadOption(UploadOption upload)
        {
            Console.WriteLine("开始上传");

            if (string.IsNullOrEmpty(upload.File))
            {
                Console.WriteLine("上传的文件不能为空");
            }

            if (!File.Exists(upload.File))
            {
                Console.WriteLine("上传的文件不存在" + Path.GetFullPath(upload.File));
            }

            try
            {
                using (var fileStream = new FileStream(Path.GetFullPath(upload.File), FileMode.Open))
                {
                    string fileSha = Shafile.GetFile(fileStream);

                    Upload(fileStream, fileSha, Url + "/api/GairKetemRairsems/UploadPackage").Wait();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(0);
        }
示例#2
0
        private static async Task Donwload(DownloadOption downloadOption)
        {
            var url        = Url + "/api/GairKetemRairsems/Download";
            var httpClient = new HttpClient();

            var kebunerNeefunadrow = new KebunerNeefunadrow()
            {
                Name    = downloadOption.Package,
                Version = downloadOption.Version
            };

            var json = JsonConvert.SerializeObject(kebunerNeefunadrow);

            var stringContent = new StringContent(json);

            stringContent.Headers.ContentType.MediaType = "application/json";

            var response = await httpClient.PostAsync(url, stringContent);

            var drehereposorrasCorxoustesaiyairal = await response.Content.ReadAsStringAsync();

            var chilusterfaVocerjoulel =
                JsonConvert.DeserializeObject <GemurboostatelnearseRurallnawrear>(drehereposorrasCorxoustesaiyairal);

            if (chilusterfaVocerjoulel == null)
            {
                Console.WriteLine("找不到可以下载的文件");
                return;
            }

            url = Url + chilusterfaVocerjoulel.File;
            var  file = Path.GetTempFileName();
            bool hawqelciyaihearKemladairheejaywer = false;

            using (var stream = new FileStream(file, FileMode.Open))
            {
                await(await httpClient.GetStreamAsync(url)).CopyToAsync(stream);
                if (Shafile.GetFile(stream) == chilusterfaVocerjoulel.Sha)
                {
                    stream.Seek(0, SeekOrigin.End);
                    hawqelciyaihearKemladairheejaywer = true;
                }
                else
                {
                    Console.WriteLine("校验不通过");
                    return;
                }
            }

            if (hawqelciyaihearKemladairheejaywer)
            {
                Console.WriteLine("下载成功");

                Console.WriteLine("开始移动文件");

                var fileName = downloadOption.Package + chilusterfaVocerjoulel.Version + ".zip";
                File.Copy(file, Path.Combine(downloadOption.Output, fileName));
                Console.WriteLine("下载完成");
            }
        }
示例#3
0
        private static async void LaizanadesoDinesebe()
        {
            var url = "http://localhost:5000/api/GairKetemRairsems/Download";

            var kebunerNeefunadrow = new KebunerNeefunadrow()
            {
                Name    = "lindexi",
                Version = new Version("1.3.0").ToString()
            };

            var httpClient = new HttpClient();

            var json = JsonConvert.SerializeObject(kebunerNeefunadrow);

            var stringContent = new StringContent(json);

            stringContent.Headers.ContentType.MediaType = "application/json";

            var response = await httpClient.PostAsync(url, stringContent);

            var drehereposorrasCorxoustesaiyairal = await response.Content.ReadAsStringAsync();

            var chilusterfaVocerjoulel =
                JsonConvert.DeserializeObject <GemurboostatelnearseRurallnawrear>(drehereposorrasCorxoustesaiyairal);

            url = "http://localhost:5000" + chilusterfaVocerjoulel.File;
            var file = Path.GetTempFileName();

            using (var stream = new FileStream(file, FileMode.Open))
            {
                await(await httpClient.GetStreamAsync(url)).CopyToAsync(stream);
                if (Shafile.GetFile(stream) == chilusterfaVocerjoulel.Sha)
                {
                    stream.Seek(0, SeekOrigin.End);
                }
            }
        }
示例#4
0
        private static void SenairjerecisBelnear()
        {
            var lirbehereTadriDruwhemLoser = new Package()
            {
                Name    = "lindexi",
                Version = "1.0",
                RequirementMaxVersion = new Version(1, 5, 1).ToString(),
                RequirementMinVersion = new Version(1, 3, 0).ToString(),
                Author = "lindexi",
                File   = "1.dll"
            };

            if (!Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                               "HemfaKarecelRisvenaStishorrorjoo", "File")))
            {
                Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                                       "HemfaKarecelRisvenaStishorrorjoo", "File"));
            }

            var file = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                                 "HemfaKarecelRisvenaStishorrorjoo", "Package.xml"));

            using (var fileStream = file.Create())
                using (var stream = new StreamWriter(fileStream))
                {
                    using (var xmlWriter = XmlWriter.Create(stream, new XmlWriterSettings()
                    {
                        Encoding = Encoding.UTF8,
                        NewLineChars = "    ",
                        NewLineHandling = NewLineHandling.Replace,
                        Indent = true,
                        IndentChars = "\n",
                    }))
                    {
                        var xmlSerializer = new XmlSerializer(typeof(Package));
                        xmlSerializer.Serialize(xmlWriter, lirbehereTadriDruwhemLoser);
                    }
                }

            File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                           "HemfaKarecelRisvenaStishorrorjoo", "File", "1.dll"), "林德熙逗比");

            if (File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                         "ChemtowNalltruTusiwurhel.zip")))
            {
                File.Delete(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                         "ChemtowNalltruTusiwurhel.zip"));
            }

            ZipFile.CreateFromDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                                     "HemfaKarecelRisvenaStishorrorjoo"), Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                                                                                       "ChemtowNalltruTusiwurhel.zip"));

            file = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                             "ChemtowNalltruTusiwurhel.zip"));

            using (var fileStream = file.OpenRead())
            {
                string fileSha = Shafile.GetFile(fileStream);

                Upload(fileStream, fileSha, "http://localhost:5000/api/GairKetemRairsems/UploadPackage").Wait();
            }
        }