public static BrokerExchangeInfo Parse(string xml) { var doc = new XmlDocument(); doc.LoadXml(xml); var nodes = doc.SelectNodes("objects/object"); var configuration = new BrokerExchangeInfo{Files = new List<FileItem>()}; if (nodes != null) foreach (XmlNode node in nodes) { var fi = new FileItem(); configuration.Files.Add(fi); foreach (XmlNode childNode in node.ChildNodes) { switch (childNode.Name) { case "id": fi.Id = string.IsNullOrEmpty(childNode.InnerText) ? new int?() : int.Parse(childNode.InnerText); break; case "file": fi.FilePath = string.IsNullOrEmpty(childNode.InnerText) ? string.Empty : childNode.InnerText; break; case "updated-at": fi.UpdatedAt = string.IsNullOrEmpty(childNode.InnerText) ? new DateTime?() : DateTime.SpecifyKind(DateTime.Parse(childNode.InnerText), DateTimeKind.Utc); break; case "last-received-at": fi.LastReceivedAt = string.IsNullOrEmpty(childNode.InnerText) ? new DateTime?() : DateTime.SpecifyKind(DateTime.Parse(childNode.InnerText), DateTimeKind.Utc); break; case "enabled": fi.Enabled = string.IsNullOrEmpty(childNode.InnerText) ? false : bool.Parse(childNode.InnerText); break; case "upload-destinations": var destNodes = childNode.SelectNodes("upload-destination"); fi.Exchanges = ParseDestinations(destNodes); break; default: break; } } } return configuration; }
private bool UploadFile(FileItem fileItem) { if (fileItem == null) throw new ArgumentNullException("fileItem"); if (fileItem.Id == null) { EventService.SendMessage("This file wasn't properly added to system: {0}", fileItem.FilePath); return false; } var observedFileCkSum = Util.ComputeFileCheckSum(fileItem.FilePath); if (!fileItem.HasChanged && fileItem.Id != null) { fileItem.HasChanged = !observedFileCkSum.Equals(fileItem.FileCheckSum); if (!fileItem.HasChanged) return false; } var holdFileCheckSum = fileItem.FileCheckSum; var holdNotificationUploadKey = fileItem.NotificationUploadKey; var holdFileUploadkey = fileItem.FileUploadkey; // fileItem.FileCheckSum = observedFileCkSum; fileItem.NotificationUploadKey = Util.CreateUploaderKey(ApiToken, fileItem.FilePath); fileItem.FileUploadkey = Util.CreateUploaderFileKey(fileItem.NotificationUploadKey, fileItem.FilePath); try { fileItem.FileCheckSum = AmazonS3Service.PutBucketItem(fileItem.FileUploadkey, Properties.Settings.Default.AmazonBucketName, fileItem.FilePath, ServerConfigProgress); } catch (Exception) { fileItem.FileCheckSum = holdFileCheckSum; fileItem.NotificationUploadKey = holdNotificationUploadKey; fileItem.FileUploadkey = holdFileUploadkey; return false; } return true; }