protected List <Synchronization> Read(string path, Type syncClass) { List <Synchronization> syncs = new List <Synchronization>(); List <SyncItem> allItems = new List <SyncItem>(); Synchronization sync = Activator.CreateInstance(syncClass) as Synchronization; SyncItem item = null; bool captureError = false; bool captureSyncHeader = false; foreach (string line in ReadFiles(path)) { if (captureSyncHeader) { Regex regex = new Regex("^{\"FailedItemsRetryCount(.*)\"ServerId\":\"(.*?)\""); Match match = regex.Match(line); if (match.Success) { sync.serverId = match.Groups[2].Value; } captureSyncHeader = false; } else if (line.StartsWith("---------------------------------------")) { item = null; captureError = false; } else if (line.Contains("] Sync task ") && line.EndsWith(" execution started with the following settings:")) { captureSyncHeader = true; } else if (line.Contains("] Immediate sync requested by ")) { sync = Activator.CreateInstance(syncClass) as Synchronization; syncs.Add(sync); } else if (sync.IsNewItem(line)) { item = sync.NewItem(line); if (sync != null) { sync.AddItem(item); } allItems.Add(item); } else if (line.StartsWith("Item information: ") && item != null) { item.SetId(line); } else if (item != null && (line.StartsWith("Error details:") || captureError)) { item.AddError(line); captureError = true; } } if (syncs.Count == 0) { syncs.Add(sync); } return(syncs); }
public SitefinitySupport.Logs.Synchronization ReadRemote(string serverId) { SiteSyncConfig config = Config.Get <SiteSyncConfig>(); var servers = config.ReceivingServers; var server = servers.Values.Where(s => s.ServerId == serverId).FirstOrDefault(); if (server == null && servers.Values.Count == 1) { server = servers.Values.First(); } if (server == null) { return(null); } string URL = server.ServerAddress; var credentials = new NetworkCredential(server.UserName, server.Password); ShellHttpClient client = new ShellHttpClient(URL, credentials); client.AddHeader(new MediaTypeWithQualityHeaderValue("application/json")); client.Call(); string data = client.getResponse(); JavaScriptSerializer JSserializer = new JavaScriptSerializer(); //deserialize to your class List <SitefinitySupport.Logs.SyncItem> items = JSserializer.Deserialize <List <SitefinitySupport.Logs.SyncItem> >(data); SitefinitySupport.Logs.Synchronization sync = new SitefinitySupport.Logs.Synchronization(); sync.items = items; return(sync); /* var handler = new HttpClientHandler { Credentials = credentials }; * * HttpClient client = new HttpClient(handler); * client.BaseAddress = new Uri(URL); * * // Add an Accept header for JSON format. * client.DefaultRequestHeaders.Accept.Add( * new MediaTypeWithQualityHeaderValue("application/json")); * * // List data response. * HttpResponseMessage response = client.GetAsync("api/shellservice").Result; // Blocking call! * * if (response.IsSuccessStatusCode) * { * // Parse the response body. Blocking! * string data = response.Content.ReadAsStringAsync().Result; * JavaScriptSerializer JSserializer = new JavaScriptSerializer(); * //deserialize to your class * List<SitefinitySupport.Logs.SyncItem> items = JSserializer.Deserialize<List<SitefinitySupport.Logs.SyncItem>>(data); * * SitefinitySupport.Logs.Synchronization sync = new SitefinitySupport.Logs.Synchronization(); * sync.items = items; * * return sync; * } * else * { * return null; * } * */ }