protected override void OnShown(EventArgs e) { base.OnShown(e); if (this.state != ReloaderState.RecoverFromRestart) { this.OnBeforeBeginReload(); this.state = ReloaderState.ReloadPlugins; } //this.owner.MainContextControl.Context.MakeCurrent(null); this.progressTimer.Start(); this.owner.SetTaskbarOverlayIcon(GeneralResCache.IconCog, GeneralRes.TaskBarOverlay_ReloadCorePlugin_Desc); this.workerInterface = new WorkerInterface(); this.workerInterface.MainForm = this.owner; this.workerInterface.ReloadDone = new List <string>(); if (this.state != ReloaderState.RecoverFromRestart) { this.workerInterface.ReloadSched = new List <string>(this.reloadSchedule); } else { this.workerInterface.RecoverMode = true; } this.worker = new Thread(WorkerThreadProc); this.worker.Start(this.workerInterface); this.state = ReloaderState.ReloadPlugins; }
private static void RestoreTemporaryData(WorkerInterface workInterface, Stream strScene, Stream strData) { StreamReader strDataReader = new StreamReader(strData); string scenePath = strDataReader.ReadLine(); workInterface.MainForm.Invoke((Action)(() => workInterface.TempScene = Resource.Load <Scene>(strScene, scenePath))); if (!workInterface.TempScene.IsRuntimeResource) { // Register the reloaded Scene in the ContentProvider, if it wasn't just a temporary one. workInterface.MainForm.Invoke((Action)(() => ContentProvider.AddContent(scenePath, workInterface.TempScene))); } }
public void DoWork(object sender, DoWorkEventArgs e) { // This method will run on a thread other than the UI thread. // Be sure not to manipulate any Windows Forms controls created // on the UI thread from this method. startTime = DateTime.Now; WorkerInterface workerInput = (WorkerInterface)e.Argument; DoCompare(workerInput.familyTree1, workerInput.familyTree2, progressReporter); trace.TraceInformation("CompareTreeWorker::DoWork(" + ")" + DateTime.Now); }
private static void PerformFullRestart(WorkerInterface workInterface) { bool debug = System.Diagnostics.Debugger.IsAttached; // Close old form and wait for it to be closed workInterface.Shutdown = true; workInterface.MainForm.Invoke(new CloseMainFormDelegate(CloseMainForm), workInterface.MainForm); while (workInterface.MainForm.Visible) { Thread.Sleep(20); } Process newEditor = Process.Start(Application.ExecutablePath, "recover" + (debug ? " debug" : "")); }
private static void SaveTemporaryData(WorkerInterface workInterface, Stream strScene, Stream strData) { StreamWriter strDataWriter = new StreamWriter(strData); strDataWriter.WriteLine(Scene.CurrentPath); strDataWriter.Flush(); workInterface.MainForm.Invoke((Action) delegate() { // Save all persistent data workInterface.MainForm.Invoke((Action)DualityEditorApp.SaveAllProjectData); workInterface.MainForm.Invoke((Action)(() => Scene.Current.Save(strScene))); }); workInterface.Progress += 0.4f; }
private static void PerformRuntimeReload(WorkerInterface workInterface) { List <CorePlugin> initSchedule = new List <CorePlugin>(); Logs.Editor.Write("Reloading core plugins..."); Logs.Editor.PushIndent(); int count = workInterface.ReloadSchedule.Count; while (workInterface.ReloadSchedule.Count > 0) { string curPath = workInterface.ReloadSchedule[0]; Logs.Editor.Write("{0}...", curPath); Logs.Editor.PushIndent(); { CorePlugin plugin = workInterface.MainForm.Invoke((Func <string, CorePlugin>)DualityApp.PluginManager.ReloadPlugin, curPath) as CorePlugin; if (plugin != null) { initSchedule.Add(plugin); } workInterface.Progress += 0.10f / (float)count; } Logs.Editor.PopIndent(); Thread.Sleep(20); string xmlDocFile = curPath.Replace(".dll", ".xml"); if (File.Exists(xmlDocFile)) { workInterface.MainForm.Invoke((Action <string>)HelpSystem.LoadXmlCodeDoc, xmlDocFile); } workInterface.ReloadSchedule.RemoveAt(0); workInterface.ReloadDone.Add(curPath); workInterface.Progress += 0.05f / (float)count; } Logs.Editor.PopIndent(); Logs.Editor.Write("Initializing reloaded core plugins..."); Logs.Editor.PushIndent(); foreach (CorePlugin plugin in initSchedule) { Logs.Editor.Write("{0}...", plugin.AssemblyName); Logs.Editor.PushIndent(); workInterface.MainForm.Invoke((Action <CorePlugin>)DualityApp.PluginManager.InitPlugin, plugin); workInterface.Progress += 0.05f / (float)count; Logs.Editor.PopIndent(); } Logs.Editor.PopIndent(); }
private static void WorkerThreadProc(object args) { WorkerInterface workInterface = args as WorkerInterface; bool fullRestart = false; try { // Reload plugins the regular way. PerformPluginReload(workInterface, ref fullRestart); } catch (Exception e) { // If we failed for an unknown reason, let's try a full restart instead. if (!fullRestart) { Log.Editor.WriteError("Failed reloading plugins during runtime: {0}", Log.Exception(e)); Log.Editor.Write("Trying full restart..."); if (File.Exists(DualityApp.LogfilePath)) { // Save the old logfile, in case someone wants to know what happened. File.Copy( DualityApp.LogfilePath, Path.GetFileNameWithoutExtension(DualityApp.LogfilePath) + "_reloadfailure" + Path.GetExtension(DualityApp.LogfilePath), true); } try { // Try again, with a forced full restart fullRestart = true; PerformPluginReload(workInterface, ref fullRestart); } catch (Exception e2) { // Failed anyway? Log the error and stop. Log.Editor.WriteError(Log.Exception(e2)); workInterface.Error = e2; } } // If even a full restart has failed, log the error and stop right there. else { Log.Editor.WriteError(Log.Exception(e)); workInterface.Error = e; } } }
private static void WorkerThreadProc(object args) { WorkerInterface workInterface = args as WorkerInterface; workInterface.Error = null; workInterface.Progress = 0.0f; try { // All work is performed here. if (!workInterface.parent.MainThreadRequired) { var taskEnumerator = workInterface.Task(workInterface).GetEnumerator(); while (taskEnumerator.MoveNext()) { } } // All work is actually performed in the main thread. else { // Wait a little so the main thread has time for drawing the GUI. Thread.Sleep(20); // Perform task on the main thread - which is necessary because OpenGL and friends don't like multithreading. // In order to keep the GUI updated, the task is split into chunks. After each chunk, GUI events can be processed. var taskEnumerator = workInterface.Task(workInterface).GetEnumerator(); DateTime lastCheck = DateTime.Now; while ((bool)workInterface.TargetForm.Invoke((Func <bool>)taskEnumerator.MoveNext)) { TimeSpan lastTime = DateTime.Now - lastCheck; // Wait a little so the main thread has time for drawing the GUI. if (lastTime.TotalMilliseconds > 1000.0f) { Thread.Sleep(20); lastCheck = DateTime.Now; } } } // Assume the task finished completely workInterface.Progress = 1.0f; } catch (Exception e) { Log.Editor.WriteError("Failed to perform task: {0}", Log.Exception(e)); workInterface.Error = e; } }
protected override void OnShown(EventArgs e) { base.OnShown(e); this.targetForm.SetTaskbarOverlayIcon(GeneralResCache.IconCog, this.taskCaption); this.workerInterface = new WorkerInterface(); this.workerInterface.parent = this; this.workerInterface.TargetForm = this.targetForm; this.workerInterface.Task = this.task; this.workerInterface.Data = this.data; this.worker = new Thread(WorkerThreadProc); this.worker.Start(this.workerInterface); this.progressTimer.Start(); }
private static void RestoreTemporaryData(WorkerInterface workInterface, Stream strScene, Stream strData) { StreamReader strDataReader = new StreamReader(strData); // Read back current scene path, account for Write/ReadLine transforming // null values into an empty string. string scenePath = strDataReader.ReadLine(); if (string.IsNullOrEmpty(scenePath)) { scenePath = null; } workInterface.MainForm.Invoke((Action)(() => workInterface.TempScene = Resource.Load <Scene>(strScene, scenePath))); if (!workInterface.TempScene.IsRuntimeResource) { // Register the reloaded Scene in the ContentProvider, if it wasn't just a temporary one. workInterface.MainForm.Invoke((Action)(() => ContentProvider.AddContent(scenePath, workInterface.TempScene))); } }
private static void PerformRuntimeReload(WorkerInterface workInterface) { int count = workInterface.ReloadSchedule.Count; while (workInterface.ReloadSchedule.Count > 0) { string curPath = workInterface.ReloadSchedule[0]; workInterface.MainForm.Invoke((Action <string>)DualityApp.ReloadPlugin, curPath); workInterface.Progress += 0.15f / (float)count; Thread.Sleep(20); string xmlDocFile = curPath.Replace(".dll", ".xml"); if (File.Exists(xmlDocFile)) { workInterface.MainForm.Invoke((Action <string>)HelpSystem.LoadXmlCodeDoc, xmlDocFile); } workInterface.ReloadSchedule.RemoveAt(0); workInterface.ReloadDone.Add(curPath); workInterface.Progress += 0.05f / (float)count; } }
private static void WorkerThreadProc(object args) { WorkerInterface workInterface = args as WorkerInterface; bool fullRestart = false; //workInterface.MainForm.MainContextControl.MakeCurrent(); try { PerformPluginReload(ref workInterface, ref fullRestart); } catch (Exception e) { if (fullRestart) { Log.Editor.WriteError(Log.Exception(e)); workInterface.Error = e; } // If we failed before but it wasn't a full restart, let's try this. else { Log.Editor.WriteError("Failed reloading plugins on the fly: {0}", Log.Exception(e)); Log.Editor.Write("Trying full restart..."); if (File.Exists(DualityApp.LogfilePath)) { File.Copy( DualityApp.LogfilePath, Path.GetFileNameWithoutExtension(DualityApp.LogfilePath) + "_reloadfailure" + Path.GetExtension(DualityApp.LogfilePath), true); } fullRestart = true; try { PerformPluginReload(ref workInterface, ref fullRestart); } catch (Exception e2) { Log.Editor.WriteError(Log.Exception(e2)); workInterface.Error = e2; } } } //workInterface.MainForm.MainContextControl.Context.MakeCurrent(null); }
private static void WorkerThreadProc(object args) { WorkerInterface workInterface = args as WorkerInterface; bool fullRestart = false; try { // Reload plugins the regular way. PerformPluginReload(workInterface, ref fullRestart); } catch (Exception e) { // If we failed for an unknown reason, let's try a full restart instead. if (!fullRestart) { Logs.Editor.WriteError("Failed reloading plugins during runtime: {0}", LogFormat.Exception(e)); Logs.Editor.Write("Trying full restart..."); try { // Try again, with a forced full restart fullRestart = true; PerformPluginReload(workInterface, ref fullRestart); } catch (Exception e2) { // Failed anyway? Log the error and stop. Logs.Editor.WriteError(LogFormat.Exception(e2)); workInterface.Error = e2; } } // If even a full restart has failed, log the error and stop right there. else { Logs.Editor.WriteError(LogFormat.Exception(e)); workInterface.Error = e; } } }
public void DoWorkLoadFile(object sender, DoWorkEventArgs e) { // This method will run on a thread other than the UI thread. // Be sure not to manipulate any Windows Forms controls created // on the UI thread from this method. startTime = DateTime.Now; WorkerInterface workerInput = (WorkerInterface)e.Argument; foreach (DuplicateTreeItems itemPair in matches.itemList) { IndividualClass person1 = null, person2 = null; person1 = workerInput.familyTree1.GetIndividual(itemPair.item1); person2 = workerInput.familyTree2.GetIndividual(itemPair.item2); if ((person1 != null) && (person2 != null)) { resultReporterFunction(CreateListItem(workerInput.familyTree1, person1, workerInput.familyTree2, person2)); } } trace.TraceInformation("CompareTreeWorker::DoWork(" + ")" + DateTime.Now); }
public CompareTreeWorker( object sender, SavedMatches matches, AsyncWorkerProgress progress, FamilyTreeStoreBaseClass familyTree1, FamilyTreeStoreBaseClass familyTree2, ReportCompareResult resultReporter) { trace = new TraceSource("CompareTreeWorker", SourceLevels.All); resultReporterFunction = resultReporter; progressReporter = progress; this.matches = matches; backgroundWorker = new BackgroundWorker(); backgroundWorker.WorkerReportsProgress = true; if (matches == null) { backgroundWorker.DoWork += new DoWorkEventHandler(DoWork); } else { backgroundWorker.DoWork += new DoWorkEventHandler(DoWorkLoadFile); } backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(Completed); backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(ProgressChanged); WorkerInterface workerInterface = new WorkerInterface(); workerInterface.familyTree1 = familyTree1; workerInterface.familyTree2 = familyTree2; backgroundWorker.RunWorkerAsync(workerInterface); }
private static void SaveTemporaryData(WorkerInterface workInterface, Stream strScene, Stream strData) { StreamWriter strDataWriter = new StreamWriter(strData); strDataWriter.WriteLine(Scene.CurrentPath); strDataWriter.Flush(); workInterface.MainForm.Invoke((Action)delegate() { // Save all persistent data DualityEditorApp.SaveAllProjectData(); Scene.Current.Save(strScene); }); workInterface.Progress += 0.4f; }
private static void RestoreTemporaryData(WorkerInterface workInterface, Stream strScene, Stream strData) { StreamReader strDataReader = new StreamReader(strData); string scenePath = strDataReader.ReadLine(); workInterface.TempScene = Resource.Load<Scene>(strScene, scenePath); if (!workInterface.TempScene.IsRuntimeResource) { // Register the reloaded Scene in the ContentProvider, if it wasn't just a temporary one. ContentProvider.AddContent(scenePath, workInterface.TempScene); } }
private static void PerformRuntimeReload(WorkerInterface workInterface) { int count = workInterface.ReloadSchedule.Count; while (workInterface.ReloadSchedule.Count > 0) { string curPath = workInterface.ReloadSchedule[0]; workInterface.MainForm.Invoke((Action<string>)DualityApp.ReloadPlugin, curPath); workInterface.Progress += 0.15f / (float)count; Thread.Sleep(20); string xmlDocFile = curPath.Replace(".dll", ".xml"); if (File.Exists(xmlDocFile)) { workInterface.MainForm.Invoke((Action<string>)HelpSystem.LoadXmlCodeDoc, xmlDocFile); } workInterface.ReloadSchedule.RemoveAt(0); workInterface.ReloadDone.Add(curPath); workInterface.Progress += 0.05f / (float)count; } }
protected override void OnShown(EventArgs e) { base.OnShown(e); if (this.state != ReloaderState.RecoverFromRestart) { this.OnBeforeBeginReload(); this.state = ReloaderState.ReloadPlugins; } //this.owner.MainContextControl.Context.MakeCurrent(null); this.progressTimer.Start(); this.owner.SetTaskbarOverlayIcon(GeneralResCache.IconCog, GeneralRes.TaskBarOverlay_ReloadCorePlugin_Desc); this.workerInterface = new WorkerInterface(); this.workerInterface.MainForm = this.owner; this.workerInterface.ReloadDone = new List<string>(); if (this.state != ReloaderState.RecoverFromRestart) this.workerInterface.ReloadSchedule = new List<string>(this.reloadSchedule); else this.workerInterface.RecoverMode = true; this.worker = new Thread(WorkerThreadProc); this.worker.Start(this.workerInterface); this.state = ReloaderState.ReloadPlugins; }
private static void PerformPluginReload(WorkerInterface workInterface, ref bool fullRestart) { Stream strScene; Stream strData; string tempDir = Path.Combine(Path.GetTempPath(), "Duality"); string tempScenePath = Path.Combine(tempDir, "ReloadPluginBackup" + Scene.FileExt); string tempDataPath = Path.Combine(tempDir, "ReloadPluginBackup.dat"); if (!Directory.Exists(tempDir)) Directory.CreateDirectory(tempDir); if (!workInterface.RecoverMode) { // No full restart scheduled? Well, check if it should be! fullRestart = fullRestart || RequiresFullRestart(workInterface.ReloadSchedule); // If a full restart is required, store temp data in files. if (fullRestart) { strScene = File.Create(tempScenePath); strData = File.Create(tempDataPath); } // If not, just use memory. else { strScene = new MemoryStream(1024 * 1024 * 10); strData = new MemoryStream(512); } // Save temporary data to restore it later Log.Editor.Write("Saving data..."); SaveTemporaryData(workInterface, strScene, strData); Thread.Sleep(20); // If required, perform a full editor system restart if (fullRestart) { strScene.Close(); strData.Close(); PerformFullRestart(workInterface); return; } // Reload things at runtime, if possible else { Log.Editor.Write("Reloading core plugins..."); Log.Editor.PushIndent(); { PerformRuntimeReload(workInterface); } Log.Editor.PopIndent(); strScene.Seek(0, SeekOrigin.Begin); strData.Seek(0, SeekOrigin.Begin); } } else { strScene = File.OpenRead(tempScenePath); strData = File.OpenRead(tempDataPath); workInterface.Progress = 0.6f; } // Reload data Log.Editor.Write("Restoring data..."); RestoreTemporaryData(workInterface, strScene, strData); strScene.Close(); strData.Close(); workInterface.Progress = 1.0f; workInterface.Finished = true; }
private static void PerformPluginReload(WorkerInterface workInterface, ref bool fullRestart) { Stream strScene; Stream strData; string tempDir = Path.Combine(Path.GetTempPath(), "Duality"); string tempScenePath = Path.Combine(tempDir, "ReloadPluginBackup" + Resource.GetFileExtByType <Scene>()); string tempDataPath = Path.Combine(tempDir, "ReloadPluginBackup.dat"); if (!Directory.Exists(tempDir)) { Directory.CreateDirectory(tempDir); } if (!workInterface.RecoverMode) { // No full restart scheduled? Well, check if it should be! fullRestart = fullRestart || RequiresFullRestart(workInterface.ReloadSchedule); // If a full restart is required, store temp data in files. if (fullRestart) { strScene = File.Create(tempScenePath); strData = File.Create(tempDataPath); } // If not, just use memory. else { strScene = new MemoryStream(1024 * 1024 * 10); strData = new MemoryStream(512); } // Save temporary data to restore it later Logs.Editor.Write("Saving data..."); SaveTemporaryData(workInterface, strScene, strData); Thread.Sleep(20); // If required, perform a full editor system restart if (fullRestart) { strScene.Close(); strData.Close(); PerformFullRestart(workInterface); return; } // Reload things at runtime, if possible else { PerformRuntimeReload(workInterface); strScene.Seek(0, SeekOrigin.Begin); strData.Seek(0, SeekOrigin.Begin); } } else { strScene = File.OpenRead(tempScenePath); strData = File.OpenRead(tempDataPath); workInterface.Progress = 0.6f; } // Reload data Logs.Editor.Write("Restoring data..."); RestoreTemporaryData(workInterface, strScene, strData); strScene.Close(); strData.Close(); workInterface.Progress = 1.0f; workInterface.Finished = true; }
private static void PerformPluginReload(ref WorkerInterface workInterface, ref bool fullRestart) { Stream strScene; Stream strData; if (!workInterface.RecoverMode) { // No full restart scheduled? Well, check if it should be! if (!fullRestart) { fullRestart = workInterface.ReloadSched.Any(asmFile => asmFile.EndsWith(".editor.dll", StringComparison.InvariantCultureIgnoreCase) || !DualityApp.IsLeafPlugin(asmFile)); } if (fullRestart) { if (!Directory.Exists("Temp")) Directory.CreateDirectory("Temp"); strScene = File.Create(@"Temp\_reloadPluginData_Scene.tmp"); strData = File.Create(@"Temp\_reloadPluginData_Data.tmp"); } else { strScene = new MemoryStream(1024 * 1024 * 10); strData = new MemoryStream(512); } // Save current data Log.Editor.Write("Saving data..."); StreamWriter strDataWriter = new StreamWriter(strData); strDataWriter.WriteLine(Scene.CurrentPath); strDataWriter.Flush(); workInterface.MainForm.Invoke((Action)delegate() { try { // Save all data DualityEditorApp.SaveAllProjectData(); Scene.Current.Save(strScene); } catch (Exception e) { Log.Editor.WriteError("Error saving current Data backup: {0}", Log.Exception(e)); } }); workInterface.Progress += 0.4f; Thread.Sleep(20); if (!fullRestart) { // Reload core plugins Log.Editor.Write("Reloading core plugins..."); Log.Editor.PushIndent(); int count = workInterface.ReloadSched.Count; while (workInterface.ReloadSched.Count > 0) { workInterface.MainForm.Invoke((Action<string>)DualityApp.ReloadPlugin, workInterface.ReloadSched[0]); workInterface.Progress += 0.15f / (float)count; Thread.Sleep(20); string xmlDocFile = workInterface.ReloadSched[0].Replace(".dll", ".xml"); if (File.Exists(xmlDocFile)) { workInterface.MainForm.Invoke((Action<string>)HelpSystem.LoadXmlCodeDoc, xmlDocFile); } workInterface.ReloadSched.RemoveAt(0); workInterface.Progress += 0.05f / (float)count; } Log.Editor.PopIndent(); strScene.Seek(0, SeekOrigin.Begin); strData.Seek(0, SeekOrigin.Begin); } else { strScene.Close(); strData.Close(); bool debug = System.Diagnostics.Debugger.IsAttached; // Close old form and wait for it to be closed workInterface.Shutdown = true; workInterface.MainForm.Invoke(new CloseMainFormDelegate(CloseMainForm), workInterface.MainForm); while (workInterface.MainForm.Visible) { Thread.Sleep(20); } Process newEditor = Process.Start(Application.ExecutablePath, "recover" + (debug ? " debug" : "")); return; } } else { strScene = File.OpenRead(@"Temp\_reloadPluginData_Scene.tmp"); strData = File.OpenRead(@"Temp\_reloadPluginData_Data.tmp"); workInterface.Progress = 0.6f; } // Reload data Log.Editor.Write("Restoring data..."); StreamReader strDataReader = new StreamReader(strData); string scenePath = strDataReader.ReadLine(); workInterface.TempScene = Resource.LoadResource<Scene>(strScene, scenePath); strScene.Close(); strData.Close(); workInterface.Progress = 1.0f; workInterface.Finished = true; }
private static void PerformPluginReload(ref WorkerInterface workInterface, ref bool fullRestart) { Stream strScene; Stream strData; string tempDir = Path.Combine(Path.GetTempPath(), "Duality"); string tempScenePath = Path.Combine(tempDir, "ReloadPluginBackup" + Scene.FileExt); string tempDataPath = Path.Combine(tempDir, "ReloadPluginBackup.dat"); if (!Directory.Exists(tempDir)) Directory.CreateDirectory(tempDir); if (!workInterface.RecoverMode) { // No full restart scheduled? Well, check if it should be! if (!fullRestart) { // If there is any editor plugin to be reloaded, we need a full restart. if (workInterface.ReloadSched.Any(asmFile => asmFile.EndsWith(".editor.dll", StringComparison.InvariantCultureIgnoreCase))) { fullRestart = true; } // If any plugin dependency needs to be reloaded, do a full restart. Due to the way, bindings between // different assemblies are resolved, it is impossible to prevent any plugin from still binding the old // version of the dependency in question. Any source code referring to the disposed dependency may // result in undefined behavior. A full restart is necessary. else if (workInterface.ReloadSched.Any(asmFile => DualityApp.IsDependencyPlugin(asmFile))) { fullRestart = true; } } if (fullRestart) { strScene = File.Create(tempScenePath); strData = File.Create(tempDataPath); } else { strScene = new MemoryStream(1024 * 1024 * 10); strData = new MemoryStream(512); } // Save current data Log.Editor.Write("Saving data..."); StreamWriter strDataWriter = new StreamWriter(strData); strDataWriter.WriteLine(Scene.CurrentPath); strDataWriter.Flush(); workInterface.MainForm.Invoke((Action)delegate() { // Save all data DualityEditorApp.SaveAllProjectData(); Scene.Current.Save(strScene); }); workInterface.Progress += 0.4f; Thread.Sleep(20); if (!fullRestart) { // Reload core plugins Log.Editor.Write("Reloading core plugins..."); Log.Editor.PushIndent(); int count = workInterface.ReloadSched.Count; while (workInterface.ReloadSched.Count > 0) { string curPath = workInterface.ReloadSched[0]; workInterface.MainForm.Invoke((Action<string>)DualityApp.ReloadPlugin, curPath); workInterface.Progress += 0.15f / (float)count; Thread.Sleep(20); string xmlDocFile = curPath.Replace(".dll", ".xml"); if (File.Exists(xmlDocFile)) { workInterface.MainForm.Invoke((Action<string>)HelpSystem.LoadXmlCodeDoc, xmlDocFile); } workInterface.ReloadSched.RemoveAt(0); workInterface.ReloadDone.Add(curPath); workInterface.Progress += 0.05f / (float)count; } Log.Editor.PopIndent(); strScene.Seek(0, SeekOrigin.Begin); strData.Seek(0, SeekOrigin.Begin); } else { strScene.Close(); strData.Close(); bool debug = System.Diagnostics.Debugger.IsAttached; // Close old form and wait for it to be closed workInterface.Shutdown = true; workInterface.MainForm.Invoke(new CloseMainFormDelegate(CloseMainForm), workInterface.MainForm); while (workInterface.MainForm.Visible) { Thread.Sleep(20); } Process newEditor = Process.Start(Application.ExecutablePath, "recover" + (debug ? " debug" : "")); return; } } else { strScene = File.OpenRead(tempScenePath); strData = File.OpenRead(tempDataPath); workInterface.Progress = 0.6f; } // Reload data Log.Editor.Write("Restoring data..."); StreamReader strDataReader = new StreamReader(strData); string scenePath = strDataReader.ReadLine(); workInterface.TempScene = Resource.Load<Scene>(strScene, scenePath); if (!workInterface.TempScene.IsRuntimeResource) { // Register the reloaded Scene in the ContentProvider, if it wasn't just a temporary one. ContentProvider.AddContent(scenePath, workInterface.TempScene); } strScene.Close(); strData.Close(); workInterface.Progress = 1.0f; workInterface.Finished = true; }
private static void PerformRuntimeReload(WorkerInterface workInterface) { List<CorePlugin> initSchedule = new List<CorePlugin>(); Log.Editor.Write("Reloading core plugins..."); Log.Editor.PushIndent(); int count = workInterface.ReloadSchedule.Count; while (workInterface.ReloadSchedule.Count > 0) { string curPath = workInterface.ReloadSchedule[0]; Log.Editor.Write("{0}...", curPath); Log.Editor.PushIndent(); CorePlugin plugin = workInterface.MainForm.Invoke((Func<string,CorePlugin>)DualityApp.ReloadPlugin, curPath) as CorePlugin; if (plugin != null) initSchedule.Add(plugin); workInterface.Progress += 0.10f / (float)count; Log.Editor.PopIndent(); Thread.Sleep(20); string xmlDocFile = curPath.Replace(".dll", ".xml"); if (File.Exists(xmlDocFile)) { workInterface.MainForm.Invoke((Action<string>)HelpSystem.LoadXmlCodeDoc, xmlDocFile); } workInterface.ReloadSchedule.RemoveAt(0); workInterface.ReloadDone.Add(curPath); workInterface.Progress += 0.05f / (float)count; } Log.Editor.PopIndent(); Log.Editor.Write("Initializing reloaded core plugins..."); Log.Editor.PushIndent(); foreach (CorePlugin plugin in initSchedule) { Log.Editor.Write("{0}...", plugin.AssemblyName); Log.Editor.PushIndent(); workInterface.MainForm.Invoke((Action<CorePlugin>)DualityApp.InitPlugin, plugin); workInterface.Progress += 0.05f / (float)count; Log.Editor.PopIndent(); } Log.Editor.PopIndent(); }
private void CreateButtons() { GameObject g = null; float offsety = -2.4f; float offsetx = 3.81f; productPane = transform.Find("Products/ProductsPane"); entertainmentPane = transform.Find("Entertainment/EntertainmentPane"); servicePane = transform.Find("Services/ServicesPane"); softwarePane = transform.Find("Software/SoftwarePane"); marketingPane = transform.Find("Marketing/MarketingPane"); workersPane = transform.Find("Workers/WorkersPane"); Vector3 topLeft = new Vector3(-8f, 1.3f, 0f); Vector3 piScale = new Vector3(.62f, .62f, 1f); int size = 5; int numberPerColumn = size; for (int i = 0; i < xml.products.Count; i++) { Product item = xml.products[i]; g = Instantiate(Resources.Load("ProductionInterface", typeof(GameObject))) as GameObject; g.transform.parent = productPane; ProductionInterface pi = g.GetComponent <ProductionInterface>(); pi.item = item; pi.product = item; pi.border.GetComponent <MeshRenderer>().material.color = GenerateIncrementedColor(productColor, i, xml.products.Count); pi.border.transform.Find("Edge").gameObject.GetComponent <MeshRenderer>().material.color = new Color(productColor.r * colorEdgeAdjustment, productColor.g * colorEdgeAdjustment, productColor.b * colorEdgeAdjustment, 1f); productsList.Add(pi); float marketingOffsetY = -1.8f; float marketingOffsetx = 3.5f; int col = i % 5; int row = i / 5; g.transform.localPosition = topLeft + new Vector3(col * offsetx, row * offsety, 0f); g.transform.localScale = piScale; } for (int i = 0; i < xml.entertainments.Count; i++) { Entertainment item = xml.entertainments[i]; g = Instantiate(Resources.Load("ProductionInterface", typeof(GameObject))) as GameObject; g.transform.parent = entertainmentPane; ProductionInterface pi = g.GetComponent <ProductionInterface>(); pi.item = item; pi.entertainment = item; pi.border.GetComponent <MeshRenderer>().material.color = GenerateIncrementedColor(entertainmentColor, i, xml.products.Count); pi.border.transform.Find("Edge").gameObject.GetComponent <MeshRenderer>().material.color = new Color(entertainmentColor.r * colorEdgeAdjustment, entertainmentColor.g * colorEdgeAdjustment, entertainmentColor.b * colorEdgeAdjustment, 1f); entertainmentList.Add(pi); float entertainmentOffsetY = -3.3f; float entertainmentOffsetX = 4.7f; int col = i % 4; int row = i / 4; // topLeft = new Vector3(-7f, 1.3f, 0f); // piScale = new Vector3(.8f, .8f, 1f); g.transform.localPosition = new Vector3(-7.7f, 1f, 0f) + new Vector3(col * entertainmentOffsetX, row * entertainmentOffsetY, 0f); g.transform.localScale = new Vector3(.75f, .75f, 1f); } for (int i = 0; i < xml.softwares.Count; i++) { Software item = xml.softwares[i]; g = Instantiate(Resources.Load("ProductionInterface", typeof(GameObject))) as GameObject; g.transform.parent = softwarePane; ProductionInterface pi = g.GetComponent <ProductionInterface>(); pi.border.GetComponent <MeshRenderer>().material.color = GenerateIncrementedColor(softwareColor, i, xml.products.Count);; pi.border.transform.Find("Edge").gameObject.GetComponent <MeshRenderer>().material.color = new Color(softwareColor.r * colorEdgeAdjustment, softwareColor.g * colorEdgeAdjustment, softwareColor.b * colorEdgeAdjustment, 1f); pi.item = item; pi.software = item; softwareList.Add(pi); float softwareOffsetY = -3.3f; float softwareOffsetX = 4.7f; int col = i % 4; int row = i / 4; // piScale = new Vector3(.8f, .8f, 1f); g.transform.localPosition = new Vector3(-7.7f, 1f, 0f) + new Vector3(col * softwareOffsetX, row * softwareOffsetY, 0f); g.transform.localScale = new Vector3(.75f, .75f, 1f); } for (int i = 0; i < xml.services.Count; i++) { Service item = xml.services[i]; g = Instantiate(Resources.Load("ProductionInterface", typeof(GameObject))) as GameObject; g.transform.parent = servicePane; ProductionInterface pi = g.GetComponent <ProductionInterface>(); pi.item = item; pi.service = item; pi.border.GetComponent <MeshRenderer>().material.color = GenerateIncrementedColor(serviceColor, i, xml.products.Count);; pi.border.transform.Find("Edge").gameObject.GetComponent <MeshRenderer>().material.color = new Color(serviceColor.r * colorEdgeAdjustment, serviceColor.g * colorEdgeAdjustment, serviceColor.b * colorEdgeAdjustment, 1f); servicesList.Add(pi); // float marketingOffsetY = -1.8f; // float marketingOffsetx = 3.5f; int col = i % 5; int row = i / 5; int imod = i % size; g.transform.localPosition = topLeft + new Vector3(col * offsetx, row * offsety, 0f); g.transform.localScale = piScale; } for (int i = 0; i < xml.workers.Count; i++) { Worker xmlWorker = xml.workers[i]; g = Instantiate(Resources.Load("WorkerInterface", typeof(GameObject))) as GameObject; switch (xmlWorker.discipline) { case "products": g.transform.parent = workersPane.Find("ProductWorkers"); break; case "marketing": g.transform.parent = workersPane.Find("MarketingWorkers"); break; case "entertainment": g.transform.parent = workersPane.Find("EntertainmentWorkers"); break; case "software": g.transform.parent = workersPane.Find("SoftwareWorkers"); break; case "services": g.transform.parent = workersPane.Find("ServicesWorkers"); break; default: break; } WorkerInterface wi = g.GetComponent <WorkerInterface>(); wi.worker = xmlWorker; workersList.Add(wi); float workerOffset = -1.15f; g.transform.localPosition = new Vector3(0f, (g.transform.parent.childCount - 1) * workerOffset, 0f); g.transform.localScale = new Vector3(1.05f, 1.05f, 1f); } for (int i = 0; i < xml.marketingTools.Count; i++) { MarketingTool item = xml.marketingTools[i]; g = Instantiate(Resources.Load("MarketingInterface", typeof(GameObject))) as GameObject; g.transform.parent = marketingPane; MarketingInterface mi = g.GetComponent <MarketingInterface>(); mi.marketing = item; // mi.border.GetComponent<MeshRenderer>().material.color = GenerateIncrementedColor(marketingColor, i, xml.products.Count);; // mi.border.transform.Find("Edge").gameObject.GetComponent<MeshRenderer>().material.color = new Color(marketingColor.r * colorEdgeAdjustment, marketingColor.g * colorEdgeAdjustment, marketingColor.b * colorEdgeAdjustment, 1f); marketingList.Add(mi); float marketingOffsetY = -1.8f; float marketingOffsetx = 3.8f; int col = i % 5; int row = i / 5; // int imod = i % size; // topLeft = new Vector3(-7.2f, 1.5f, -2f); g.transform.localPosition = new Vector3(-7.7f, 1.5f, 0f) + new Vector3(col * marketingOffsetx, row * marketingOffsetY, 0f); g.transform.localScale = new Vector3(1.3f, 1.3f, 1f); } }
private static void PerformPluginReload(ref WorkerInterface workInterface, ref bool fullRestart) { Stream strScene; Stream strData; string tempDir = Path.Combine(Path.GetTempPath(), "Duality"); string tempScenePath = Path.Combine(tempDir, "ReloadPluginBackup" + Scene.FileExt); string tempDataPath = Path.Combine(tempDir, "ReloadPluginBackup.dat"); if (!Directory.Exists(tempDir)) { Directory.CreateDirectory(tempDir); } if (!workInterface.RecoverMode) { // No full restart scheduled? Well, check if it should be! if (!fullRestart) { fullRestart = workInterface.ReloadSched.Any(asmFile => asmFile.EndsWith(".editor.dll", StringComparison.InvariantCultureIgnoreCase) || !DualityApp.IsLeafPlugin(asmFile)); } if (fullRestart) { strScene = File.Create(tempScenePath); strData = File.Create(tempDataPath); } else { strScene = new MemoryStream(1024 * 1024 * 10); strData = new MemoryStream(512); } // Save current data Log.Editor.Write("Saving data..."); StreamWriter strDataWriter = new StreamWriter(strData); strDataWriter.WriteLine(Scene.CurrentPath); strDataWriter.Flush(); workInterface.MainForm.Invoke((Action) delegate() { // Save all data DualityEditorApp.SaveAllProjectData(); Scene.Current.Save(strScene); }); workInterface.Progress += 0.4f; Thread.Sleep(20); if (!fullRestart) { // Reload core plugins Log.Editor.Write("Reloading core plugins..."); Log.Editor.PushIndent(); int count = workInterface.ReloadSched.Count; while (workInterface.ReloadSched.Count > 0) { string curPath = workInterface.ReloadSched[0]; workInterface.MainForm.Invoke((Action <string>)DualityApp.ReloadPlugin, curPath); workInterface.Progress += 0.15f / (float)count; Thread.Sleep(20); string xmlDocFile = curPath.Replace(".dll", ".xml"); if (File.Exists(xmlDocFile)) { workInterface.MainForm.Invoke((Action <string>)HelpSystem.LoadXmlCodeDoc, xmlDocFile); } workInterface.ReloadSched.RemoveAt(0); workInterface.ReloadDone.Add(curPath); workInterface.Progress += 0.05f / (float)count; } Log.Editor.PopIndent(); strScene.Seek(0, SeekOrigin.Begin); strData.Seek(0, SeekOrigin.Begin); } else { strScene.Close(); strData.Close(); bool debug = System.Diagnostics.Debugger.IsAttached; // Close old form and wait for it to be closed workInterface.Shutdown = true; workInterface.MainForm.Invoke(new CloseMainFormDelegate(CloseMainForm), workInterface.MainForm); while (workInterface.MainForm.Visible) { Thread.Sleep(20); } Process newEditor = Process.Start(Application.ExecutablePath, "recover" + (debug ? " debug" : "")); return; } } else { strScene = File.OpenRead(tempScenePath); strData = File.OpenRead(tempDataPath); workInterface.Progress = 0.6f; } // Reload data Log.Editor.Write("Restoring data..."); StreamReader strDataReader = new StreamReader(strData); string scenePath = strDataReader.ReadLine(); workInterface.TempScene = Resource.Load <Scene>(strScene, scenePath); if (!workInterface.TempScene.IsRuntimeResource) { // Register the reloaded Scene in the ContentProvider, if it wasn't just a temporary one. ContentProvider.AddContent(scenePath, workInterface.TempScene); } strScene.Close(); strData.Close(); workInterface.Progress = 1.0f; workInterface.Finished = true; }