Ejemplo n.º 1
0
        private bool sendDownloadedWorkFilesList(List<MyFile> downloadedList)
        {
            MyFiles files = new MyFiles();
            files.Files = downloadedList;
            XmlSerializer srlzr = new XmlSerializer(files.GetType());
            string filelist = "";
            var memoryStream = new MemoryStream();

            using (StreamWriter writer = new StreamWriter(memoryStream, System.Text.Encoding.UTF8))
            {
                srlzr.Serialize(writer, files);

                memoryStream.Seek(0, SeekOrigin.Begin);
                var streamReader = new StreamReader(memoryStream, System.Text.Encoding.UTF8);
                filelist = streamReader.ReadToEnd();
            }

            this.form.addToLog("sending download file list to http://" + this.settings.Url);
            using (WebClient wb = new WebClient())
            {
                var data = new NameValueCollection();
                data["api"] = this.settings.ApiKey.Trim();
                data["action"] = "delete_downloaded_work_files";
                data["filelist"] = filelist;

                byte[] response = null;
                try
                {
                    response = wb.UploadValues(this.settings.FullUrl, "POST", data);
                }
                catch
                {
                    this.form.addToLog("some errors");
                    return false;
                }

                var res = Encoding.UTF8.GetString(response);
                string[] result = res.Split(':');
                if (result[0] == "downloaded_work_files_deleted")
                {
                    string[] deletedFiles = result[1].Split('_');
                    this.form.addToLog("delete downloaded work files:" + deletedFiles[0] + " of " + deletedFiles[1]);
                    return true;
                }
            }

            this.form.addToLog("wrong params");
            return false;
        }
Ejemplo n.º 2
0
        private List<MyFile> getLoadedWorkList()
        {
            MyFiles result = new MyFiles();
            if (!File.Exists("ignorelist.txt"))
            {
                return result.Files;
            }

            TextReader reader = new StreamReader("ignorelist.txt");

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(MyFiles));
                result = (MyFiles)serializer.Deserialize(reader);
                this.form.addToLog("ignore list readed");
            }
            catch (Exception e)
            {
                this.form.addToLog("error: " + e.Message);
            }
            finally
            {
                reader.Close();
            }

            return result.Files;
        }