public static void PublishFromContext(IZetboxContext ctx, IPackageProvider s, string[] ownerModules) { using (Log.DebugTraceMethodCall("PublishFromContext")) { Log.InfoFormat("Starting Publish for Modules {0}", string.Join(", ", ownerModules)); Log.Debug("Loading modulelist"); var moduleList = GetModules(ctx, ownerModules); WriteStartDocument(s, ctx, new Zetbox.App.Base.Module[] { ctx.GetQuery <Zetbox.App.Base.Module>().First(m => m.Name == "ZetboxBase"), ctx.GetQuery <Zetbox.App.Base.Module>().First(m => m.Name == "GUI"), }); var propNamespaces = new string[] { "Zetbox.App.Base", "Zetbox.App.GUI" }; foreach (var module in moduleList) { Log.DebugFormat("Publishing objects for module {0}", module.Name); var objects = PackagingHelper.GetMetaObjects(ctx, module); Stopwatch watch = new Stopwatch(); watch.Start(); int counter = 0; foreach (var obj in objects) { ExportObject(s, obj, propNamespaces); counter++; if (watch.ElapsedMilliseconds > 1000) { watch.Reset(); watch.Start(); Log.DebugFormat("{0:n0}% finished", (double)counter / (double)objects.Count * 100.0); } } Log.Debug("100% finished"); } Log.Info("Export finished"); } }
public static void Deploy(IZetboxContext ctx, params IPackageProvider[] providers) { if (ctx == null) { throw new ArgumentNullException("ctx"); } if (providers == null) { throw new ArgumentNullException("providers"); } using (Log.InfoTraceMethodCall("Deploy")) { Log.InfoFormat("Starting Deployment from {0}", string.Join(", ", providers.Select(p => p.ToString()).ToArray())); try { // TODO: Das muss ich z.Z. machen, weil die erste Query eine Entity Query ist und noch nix geladen wurde.... var testObj = ctx.GetQuery <Zetbox.App.Base.ObjectClass>().FirstOrDefault(); Debug.WriteLine(testObj != null ? testObj.ToString() : String.Empty); } catch { // Ignore } Dictionary <Guid, IPersistenceObject> currentObjects = new Dictionary <Guid, IPersistenceObject>(); Log.Info("Loading namespaces"); var names = providers.SelectMany(p => LoadModuleNames(p)).Distinct().ToList(); if (names.Count == 0) { throw new InvalidOperationException("No modules found in import file"); } foreach (var name in names) { Log.InfoFormat("Prefetching objects for {0}", name); var module = ctx.GetQuery <Zetbox.App.Base.Module>().FirstOrDefault(m => m.Name == name); if (module != null) { foreach (var obj in PackagingHelper.GetMetaObjects(ctx, module)) { currentObjects[((Zetbox.App.Base.IExportable)obj).ExportGuid] = obj; } } else { Log.InfoFormat("Found new Module '{0}' in XML", name); } } providers.ForEach(p => p.RewindData()); Dictionary <Guid, IPersistenceObject> importedObjects = new Dictionary <Guid, IPersistenceObject>(); Log.Info("Loading"); foreach (var p in providers) { var reader = p.Reader; // Find Root Element while (reader.Read() && reader.NodeType != XmlNodeType.Element && reader.LocalName != "ZetboxPackaging" && reader.NamespaceURI != "http://dasz.at/Zetbox") { ; } // Read content while (reader.Read()) { if (reader.NodeType != XmlNodeType.Element) { continue; } var obj = ImportElement(ctx, currentObjects, p); if (obj == null) { throw new InvalidOperationException("Invalid import format: ImportElement returned NULL"); } importedObjects[((IExportableInternal)obj).ExportGuid] = obj; } } Log.Info("Reloading References"); foreach (var obj in importedObjects.Values) { obj.ReloadReferences(); } var objectsToDelete = currentObjects.Where(p => !importedObjects.ContainsKey(p.Key)); Log.InfoFormat("Deleting {0} objects marked for deletion", objectsToDelete.Count()); foreach (var pairToDelete in objectsToDelete) { ctx.Delete(pairToDelete.Value); } Log.Info("Deployment finished"); } }