private void Deserialize(string clientName) { IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream(string.Format("{0}\\Campaign.bin", clientName), FileMode.Open, FileAccess.Read, FileShare.Read); campaign = (DataCampaign)formatter.Deserialize(stream); stream.Close(); }
static public async Task <string[]> SynchronizeFiles(string url, string clientName) { try { string response = GetResponse(url, clientName); DataCampaign item = JsonConvert.DeserializeObject <DataCampaign>(response); string[] fileEntries = Directory.GetFiles(clientName); List <string> filesToDownload = new List <string>(); List <string> filesOnServer = new List <string>(); DirectoryInfo di = new DirectoryInfo(clientName); if (!di.Exists) { Directory.CreateDirectory(clientName); } if (item.data.found == true) { foreach (Items it in item.data.playlist.items) { filesOnServer.Add(it.url); } } else { foreach (string fileOnDisk in fileEntries) { File.Delete(fileOnDisk); } } //pliki do pobrania if (fileEntries.Length > 0 && filesOnServer.Count > 0) { foreach (string fileOnServer in filesOnServer) { foreach (string fileOnDisk in fileEntries) { if (fileOnServer.Contains(Path.GetFileName(fileOnDisk))) { break; } if (fileOnDisk == fileEntries.Last()) { filesToDownload.Add(fileOnServer); } } } //usuwanie zbednych plikow foreach (string fileOnDisk in fileEntries) { foreach (string fileOnServer in filesOnServer) { if (fileOnDisk.Contains(Path.GetFileName(fileOnServer))) { break; } if (fileOnServer == filesOnServer.Last()) { File.Delete(fileOnDisk); } } } } else { if (filesOnServer != null) { filesToDownload = filesOnServer.ToList <string>(); } } if (filesToDownload.Count > 0) { await Downloader(filesToDownload, clientName); } if (item.data.found == true) { Serialize(item, clientName); return(new string[] { item.data.campaign.start, item.data.campaign.end }); } return(new string[] { "01-01-2017", "01-01-2018" }); } catch (JsonReaderException) { MessageBox.Show("Wystąpił bład podczas pobierania danych."); return(new string[] { "01-01-2017", "01-01-2018" }); } catch (IOException) { MessageBox.Show("Wystąpił problem podczas synchoronizacji danych."); return(new string[] { "01-01-2017", "01-01-2018" }); } }