/// <summary> /// Synchronize local zone with remote store /// </summary> public Zone Synchronize(IZoneComponent zcomp) { bool success; Zone zone = new Zone(); //Check for the existence of the zone zone.LocalPath = Path.Combine(TestConfig.LocalZonePath, m_prefix+zcomp.GetZoneID().ToString()); zone.ZoneID = zcomp.GetZoneID(); if (Directory.Exists(zone.LocalPath)) success = UpdateZone(zcomp); else success = CreateZone(zcomp); if (success) { return zone; } else { m_logger.Log("Zone synchro FAILED", TestLogger.LogType.ERROR); return null; } }
protected bool UpdateZone(IZoneComponent eval) { DataSet zonedesc = new DataSet(); string dpath = Path.Combine(TestConfig.LocalZonePath, m_prefix + eval.GetZoneID().ToString()); string xmlpath = Path.Combine(dpath, ZONE_FILE); if (!File.Exists(xmlpath) || true) { Directory.Delete(dpath, true); return CreateZone(eval); } else { zonedesc.ReadXml(xmlpath); DateTime localmod = new DateTime(Convert.ToInt64(zonedesc.Tables["Export"].Rows[0]["Mod"])); DateTime zonemod = eval.GetZoneModified(); //If zone is modified, blow it away and get it again if (zonemod > localmod) { Directory.Delete(dpath, true); return CreateZone(eval); } else ClearZone(dpath); } return true; }
protected bool CreateZone(IZoneComponent eval) { FileSystem fs = new FileSystem(m_ident); DataSet desc = new DataSet(); //Create initial zone directory string zpath = Path.Combine(TestConfig.LocalZonePath, m_prefix + eval.GetZoneID().ToString()); Directory.CreateDirectory(zpath); //Export the zone files into local store IExternalSink zdir = new OSFileSystemSink(); zdir.CreateSink(""); try { desc = fs.ExportData(zpath, fs.GetFile(eval.GetZoneID()), zdir, false); //Write XML descriptor desc.Tables["Export"].Rows[0]["Mod"] = eval.GetZoneModified().Ticks; desc.WriteXml(Path.Combine(zpath, ZONE_FILE)); m_logger.Log("Zone retrieved successfully"); } catch (FileOperationException e) { m_logger.Log("File error: " + e.Message, TestLogger.LogType.ERROR); zdir.CloseSink(); return false; } catch (DataAccessException er) { m_logger.Log("Data error: " + er.Message, TestLogger.LogType.ERROR); zdir.CloseSink(); return false; } catch (Exception e) { m_logger.Log("Unexpected error: " + e.Message, TestLogger.LogType.ERROR); m_logger.Log("Trace: " + e.StackTrace, TestLogger.LogType.ERROR); zdir.CloseSink(); return false; } return true; }