/// <summary> /// Downloads and installs a DarkRift version. /// </summary> /// <param name="version">The version to be installed</param> /// <param name="tier">The tier</param> /// <param name="platform">The platform</param> /// <param name="downloadDirectory">The directory to download the release to</param> /// <returns>True if installed successfully otherwise false</returns> public bool DownloadVersionTo(string version, ServerTier tier, string platform, string downloadDirectory) { string stagingPath = fileUtility.GetTempFileName(); string uri = $"/DarkRift2/Releases/{version}/{tier}/{platform}/"; if (tier == ServerTier.Pro) { string invoiceNumber = invoiceManager.GetInvoiceNumber(); if (invoiceNumber == null) { Console.Error.WriteLine(Output.Red($"You must provide an invoice number in order to download Pro DarkRift releases.")); return(false); } uri += $"?invoice={invoiceNumber}"; } try { webClientUtility.DownloadFile(uri, stagingPath); } catch (WebException e) { Console.Error.WriteLine(Output.Red($"Could not download DarkRift {version} - {tier} (.NET {platform}):\n\t{e.Message}")); return(false); } Console.WriteLine($"Extracting package..."); try { fileUtility.ExtractZipTo(stagingPath, downloadDirectory); } catch (Exception) { // Make sure we don't leave a partial install if (fileUtility.DirectoryExists(downloadDirectory)) { fileUtility.Delete(downloadDirectory); } throw; } finally { fileUtility.Delete(stagingPath); } Console.WriteLine(Output.Green($"Successfully downloaded DarkRift {version} - {tier} (.NET {platform}).")); return(true); }
public void WriteConversations(string sender, IList <FacebookConversation> conversations, string outputDirectory, IFileUtility fileUtility) { // Clean up the conversations which seem to be with a single person to include the sender. foreach (var conversation in conversations) { if (conversation.Participants.Count < 2 && conversation.Participants.First() != sender) { conversation.Participants.Add(sender); } } foreach (var conversationGroup in conversations.GroupBy(g => g.Participants.OrderBy(o => o).Aggregate((a, b) => a.Trim() + b.Trim()))) { var conversationList = conversationGroup.ToList(); var serializedConversation = JsonConvert.SerializeObject(conversationList); var filePath = Path.Combine(outputDirectory, (conversationList.First().Participants.Take(5).Aggregate((a, b) => a + "-" + b)).Replace("/", "-").Replace(":", "-").Replace("facebook.com", string.Empty)); if (fileUtility.Exists(filePath)) { fileUtility.Delete(filePath); } fileUtility.WriteAllText(filePath, serializedConversation); } }
public void Delete(string filename) { _fileUtility.Delete(filename); }