示例#1
0
        public async Task CopyFile()
        {
            if (!File.Exists(sourcePath))
            {
                //download from LOD
                using (WebClient wc = new WebClient())
                {
                    string filename = Path.GetFileName(destinationPath);
                    //wc.DownloadFile(new Uri(lodmp3path + filename), destinationPath);

                    var request = (HttpWebRequest)WebRequest.Create(lodmp3path + filename);
                    request.Method = "GET";
                    using (var response = await request.GetResponseAsync())
                    {
                        if ((response as HttpWebResponse).StatusCode == HttpStatusCode.OK)
                        {
                            using (var responseStream = response.GetResponseStream())
                            {
                                using (var fileToDownload = new System.IO.FileStream(sourcePath, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite))
                                {
                                    await responseStream.CopyToAsync(fileToDownload);

                                    WorkerLogger.WriteLog("downloaded from " + lodmp3path + filename + " to " + sourcePath);
                                }
                            }
                        }
                        else
                        {
                            //file not found on WebServer
                            WorkerLogger.WriteLog("file not found on " + lodmp3path + filename);
                        }
                    }
                }
            }

            if (File.Exists(sourcePath))
            {
                using (Stream source = File.Open(sourcePath, FileMode.Open))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(destinationPath));
                    using (Stream destination = File.Create(destinationPath))
                    {
                        await source.CopyToAsync(destination).ConfigureAwait(false);

                        WorkerLogger.WriteLog("copied " + sourcePath + " to " + destinationPath);
                    }
                }
            }
            else
            {
                //file not found on Server
                WorkerLogger.WriteLog("[ERROR] file not found on " + sourcePath);
            }
        }
示例#2
0
        private static void finishWork()
        {
            // WorkerLogger.WriteLog("transfered " + _counter.ToString() + " files"); ;
            string res = "transfered: ";

            foreach (var ic in _counterDic)
            {
                res += Environment.NewLine + "Type: " + ic.Key + " # " + ic.Value;
            }
            WorkerLogger.WriteLog(res);
            WorkerLogger.CloseLog();
            _isWorking = false;
            _counterDic.Clear();
        }
示例#3
0
        public async Task MoveFile()
        {
            if (File.Exists(sourcePath))
            {
                using (Stream source = File.Open(sourcePath, FileMode.Open))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(destinationPath));
                    using (Stream destination = File.Create(destinationPath))
                    {
                        await source.CopyToAsync(destination).ConfigureAwait(false);

                        WorkerLogger.WriteLog("moved " + sourcePath + " to " + destinationPath);
                    }
                }
                File.Delete(sourcePath);
            }
            else
            {
                WorkerLogger.WriteLog("[ERROR] file not found on " + sourcePath);
            }
        }