public void QueueDequeue_Three() { var queue = new ChangeQueue(); queue.Queue(new FileChange(ChangeAction.None, "1", 10)); queue.Queue(new FileChange(ChangeAction.None, "2", 10)); queue.Queue(new FileChange(ChangeAction.None, "3", 10)); Assert.IsTrue(queue.Count == 3); for (var xx = 0; xx < queue.Count; xx++) { Assert.IsTrue((xx + 1).ToString() == queue[xx].File); } FileChange change; change = queue.Dequeue(); Assert.IsTrue(change.File == "1"); Assert.IsTrue(queue.Count == 2); change = queue.Dequeue(); Assert.IsTrue(change.File == "2"); Assert.IsTrue(queue.Count == 1); change = queue.Dequeue(); Assert.IsTrue(change.File == "3"); Assert.IsTrue(queue.Count == 0); }
private void WriteAppToLog(ChangeQueue change, IShareFileReference builder) { if (this.LoggerBuilder == null) { return; } this.EatException(() => { var sb = new StringBuilder(); sb.AppendLine(); sb.AppendFormat("app {0} action : {1}, at {2};", builder.Builder.Name, change.ToAction(), DateTime.Now.ToString()); if (builder.Reference.IsNotNullOrEmpty()) { sb.AppendFormat("the share files ["); var sname = string.Empty; foreach (var r in builder.Reference) { if (r == null) { continue; } sb.AppendLine(); sb.AppendFormat("{0}", r.Name); } sb.AppendLine(); sb.AppendFormat("] are using the app {0} file;", builder.Builder.Name); } this.LoggerBuilder.Invoke().Build(typeof(ConfigurationWatcher)).Info(sb.ToString()); }); }
public void QueueDequeue_QueueReplacement() { var queue = new ChangeQueue(); queue.Queue(new FileChange(ChangeAction.None, "1", 10)); queue.Queue(new FileChange(ChangeAction.None, "2", 10)); queue.Queue(new FileChange(ChangeAction.None, "3", 10)); queue.Queue(new FileChange(ChangeAction.None, "1", 10)); Assert.IsTrue(queue.Count == 3); Assert.IsTrue(queue[0].File == "2"); Assert.IsTrue(queue[1].File == "3"); Assert.IsTrue(queue[2].File == "1"); }
/// <summary> /// Convert a Rhino.Render.ChangeQueue.Light to a CyclesLight /// </summary> /// <param name="changequeue"></param> /// <param name="light"></param> /// <param name="view"></param> /// <param name="gamma"></param> /// <returns></returns> internal CyclesLight ConvertLight(ChangeQueue changequeue, Light light, ViewInfo view, float gamma) { if (changequeue != null && view != null) { if (light.Data.LightStyle == LightStyle.CameraDirectional) { ChangeQueue.ConvertCameraBasedLightToWorld(changequeue, light, view); } } var cl = ConvertLight(light.Data, gamma); cl.Id = light.Id; if (light.ChangeType == Light.Event.Deleted) { cl.Strength = 0; } return cl; }
/// <summary> /// Convert a Rhino.Render.ChangeQueue.Light to a CyclesLight /// </summary> /// <param name="changequeue"></param> /// <param name="light"></param> /// <param name="view"></param> /// <param name="gamma"></param> /// <returns></returns> internal CyclesLight ConvertLight(ChangeQueue changequeue, Light light, ViewInfo view, float gamma) { if (changequeue != null && view != null) { if (light.Data.LightStyle == LightStyle.CameraDirectional) { ChangeQueue.ConvertCameraBasedLightToWorld(changequeue, light, view); } } var cl = ConvertLight(light.Data, gamma); cl.Id = light.Id; if (light.ChangeType == Light.Event.Deleted) { cl.Strength = 0; } return(cl); }
/// <summary> /// 处理app级 /// </summary> /// <param name="change"></param> /// <param name="outsideEncoding"></param> private void HandleAppFile(ChangeQueue change, Encoding outsideEncoding = null) { var oldFile = change.OldFullName == null ? null : new FileInfo(change.OldFullName); var newFile = change.FullName == null ? null : new FileInfo(change.FullName); if (newFile != null && !this.CanRefresh(newFile)) { return; } switch (change.Action) { //新加 case 0: { IShareFileReference newBuilder = null; switch (newFile.Extension.ToLower()) { case ".json": { var fileInfo = new ConfigFileInfo() { File = newFile, Encoding = outsideEncoding ?? Encoding.UTF8 }; var builder = new JsonConfigurationBuilder(this.shareConfiguration, fileInfo, this.keyValueFinder) { }.Build(); if (this.appConfiguration.Any(ta => ta.Builder.Name == builder.Name)) { } else { this.appConfiguration.Add(builder); } newBuilder = builder; } break; case ".conf": { var fileInfo = new ConfigFileInfo() { File = newFile, Encoding = outsideEncoding }; var builder = new XmlConfigurationBuilder(this.shareConfiguration, fileInfo, this.keyValueFinder) { }.Build(); if (this.appConfiguration.Any(ta => ta.Builder.Name == builder.Name)) { } else { this.appConfiguration.Add(builder); } newBuilder = builder; } break; } if (!change.PathChanged && !this.fileWather.ContainsKey(newFile.FullName)) { var watcher = new Never.IO.FileWatcher(newFile) { EnableRaisingEvents = true }; this.fileWather.Add(newFile.FullName, watcher); this.moreTimeLimit.Add(newFile.FullName, DateTime.Now); watcher.Created += AppWatcher_Created; watcher.Changed += AppWatcher_Changed; watcher.Deleted += AppWatcher_Deleted; watcher.Renamed += AppWatcher_Renamed; } this.EatException(() => { this.OnAppFileChanged?.Invoke(this, new ConfigurationWatcherEventArgs() { Builders = new[] { newBuilder.Builder } }); }); this.WriteAppToLog(change, newBuilder); } break; //修改 case 1: { var oldBuilder = this.appConfiguration.FirstOrDefault(ta => ta.Builder.File.File.FullName == newFile.FullName); oldBuilder.Builder.Rebuild(this.shareConfiguration); this.EatException(() => { this.OnAppFileChanged?.Invoke(this, new ConfigurationWatcherEventArgs() { Builders = new[] { oldBuilder.Builder } }); }); this.WriteAppToLog(change, oldBuilder); } break; //重命名 case 2: { var oldBuilder = this.appConfiguration.FirstOrDefault(ta => ta.Builder.File.File.FullName == oldFile.FullName); var refence = default(IConfigurationBuilder); switch (oldBuilder.Builder.FileType) { case ConfigFileType.Json: { var fileInfo = new ConfigFileInfo() { File = newFile, Encoding = oldBuilder.Builder.File.Encoding }; var newBuilder = new JsonConfigurationBuilder(this.shareConfiguration, fileInfo, this.keyValueFinder) { }.Build(); this.appConfiguration.Remove(oldBuilder); this.appConfiguration.Add(newBuilder); refence = newBuilder; } break; case ConfigFileType.Xml: { var fileInfo = new ConfigFileInfo() { File = newFile, Encoding = oldBuilder.Builder.File.Encoding }; var newBuilder = new XmlConfigurationBuilder(this.shareConfiguration, fileInfo, this.keyValueFinder) { }.Build(); this.appConfiguration.Remove(oldBuilder); this.appConfiguration.Add(newBuilder); refence = newBuilder; } break; } if (!change.PathChanged && this.fileWather.ContainsKey(oldFile.FullName)) { var watcher = this.fileWather[oldFile.FullName]; watcher.Path = System.IO.Path.GetDirectoryName(newFile.FullName); watcher.Filter = newFile.Name; } if (refence != null) { this.EatException(() => { this.OnAppFileRenamed?.Invoke(this, new ConfigurationWatcherEventArgs() { Builders = new[] { refence } }); }); } this.WriteAppToLog(change, refence as IShareFileReference); } break; //删除 case 3: { var oldBuilder = this.appConfiguration.FirstOrDefault(ta => ta.Builder.File.File.FullName == oldFile.FullName); this.appConfiguration.Remove(oldBuilder); if (!change.PathChanged && this.fileWather.ContainsKey(oldFile.FullName)) { this.fileWather[oldFile.FullName].Dispose(); this.fileWather.Remove(oldFile.FullName); } this.EatException(() => { this.OnAppFileDeleted?.Invoke(this, new ConfigurationWatcherEventArgs() { Builders = new[] { oldBuilder.Builder } }); }); this.WriteAppToLog(change, oldBuilder); } break; } }
/// <summary> /// 处理share级 /// </summary> /// <param name="change"></param> /// <param name="outsideEncoding"></param> private void HandleShareFile(ChangeQueue change, Encoding outsideEncoding = null) { var oldFile = change.OldFullName == null ? null : new FileInfo(change.OldFullName); var newFile = change.FullName == null ? null : new FileInfo(change.FullName); if (newFile != null && !this.CanRefresh(newFile)) { return; } switch (change.Action) { //新加 case 0: { var shareBuilder = new ShareConfigurationBuilder(new ConfigFileInfo() { File = newFile, Encoding = outsideEncoding ?? Encoding.UTF8 }); if (this.ShareFileEventHandler != null) { shareBuilder.OnBuilding += this.ShareFileEventHandler; } shareBuilder.Build(); switch (shareBuilder.FileType) { case ConfigFileType.Json: { if (this.shareConfiguration.Any(ta => ta.JsonShareFile.Name == shareBuilder.JsonShareFile.Name)) { } else { this.shareConfiguration.Add(shareBuilder); } } break; case ConfigFileType.Xml: { if (this.shareConfiguration.Any(ta => ta.XmlShareFile.Name == shareBuilder.XmlShareFile.Name)) { } else { this.shareConfiguration.Add(shareBuilder); } } break; } if (!change.PathChanged && !this.fileWather.ContainsKey(newFile.FullName)) { var watcher = new Never.IO.FileWatcher(shareBuilder.File) { EnableRaisingEvents = true }; this.fileWather.Add(shareBuilder.File.FullName, watcher); this.moreTimeLimit.Add(shareBuilder.File.FullName, DateTime.Now); watcher.Created += ShareWatcher_Created; watcher.Changed += ShareWatcher_Changed; watcher.Deleted += ShareWatcher_Deleted; watcher.Renamed += ShareWatcher_Renamed; } this.WriteShareToLog(change, shareBuilder, null); } break; //修改 case 1: { var oldBuilder = this.shareConfiguration.FirstOrDefault(ta => ta.File.FullName == newFile.FullName).Rebuild(); //引起引用文件的修改,先找出相应的引用,找到后等新的builder替换成功后再更新引用文件里面的引用 var refences = new List <IShareFileReference>(); foreach (var b in new[] { oldBuilder.JsonShareFile, oldBuilder.XmlShareFile }) { if (b == null) { continue; } foreach (var app in this.appConfiguration) { if (app.Reference.IsNotNullOrEmpty() && app.Reference.Any(ta => ta.Name.IsEquals(b.Name))) { refences.Add(app); continue; } } } if (refences.IsNotNullOrEmpty()) { refences.UseForEach(ta => ta.Builder.Rebuild(this.shareConfiguration)); this.EatException(() => { this.OnShareFileChanged?.Invoke(this, new ConfigurationWatcherEventArgs() { Builders = refences.Select(ta => ta.Builder) }); }); } this.WriteShareToLog(change, oldBuilder, refences); } break; //重命名 case 2: { var oldBuilder = this.shareConfiguration.FirstOrDefault(ta => ta.File.FullName == oldFile.FullName); var newBuilder = new ShareConfigurationBuilder(new ConfigFileInfo() { File = newFile, Encoding = oldBuilder.Encoding }); //引起引用文件的修改,先找出相应的引用,找到后等新的builder替换成功后再更新引用文件里面的引用 var refences = new List <IShareFileReference>(); foreach (var b in new[] { oldBuilder.JsonShareFile, oldBuilder.XmlShareFile }) { if (b == null) { continue; } foreach (var app in this.appConfiguration) { if (app.Reference.IsNotNullOrEmpty() && app.Reference.Any(ta => ta.Name.IsEquals(b.Name))) { refences.Add(app); continue; } } } this.shareConfiguration.Remove(oldBuilder); this.shareConfiguration.Add(newBuilder.Build(oldBuilder)); oldBuilder = null; if (!change.PathChanged) { if (this.fileWather.ContainsKey(oldFile.FullName)) { var watcher = this.fileWather[oldFile.FullName]; watcher.Path = System.IO.Path.GetDirectoryName(newFile.FullName); watcher.Filter = newFile.Name; } } if (refences.IsNotNullOrEmpty()) { refences.UseForEach(ta => ta.Builder.Rebuild(this.shareConfiguration)); this.EatException(() => { this.OnShareFileRenamed?.Invoke(this, new ConfigurationWatcherEventArgs() { Builders = refences.Select(ta => ta.Builder) }); }); } this.WriteShareToLog(change, newBuilder, refences); } break; //删除 case 3: { var oldBuilder = this.shareConfiguration.FirstOrDefault(ta => ta.File.FullName == oldFile.FullName); //引起引用文件的修改,先找出相应的引用,找到后等新的builder替换成功后再更新引用文件里面的引用 var refences = new List <IShareFileReference>(); foreach (var b in new[] { oldBuilder.JsonShareFile, oldBuilder.XmlShareFile }) { if (b == null) { continue; } foreach (var app in this.appConfiguration) { if (app.Reference.IsNotNullOrEmpty() && app.Reference.Any(ta => ta.Name.IsEquals(b.Name))) { refences.Add(app); continue; } } } if (!change.PathChanged) { if (this.fileWather.ContainsKey(oldFile.FullName)) { this.fileWather[oldFile.FullName].Dispose(); this.fileWather.Remove(oldFile.FullName); } } this.shareConfiguration.Remove(oldBuilder); if (refences.IsNotNullOrEmpty()) { refences.UseForEach(ta => ta.Builder.Rebuild(this.shareConfiguration)); this.EatException(() => { this.OnShareFileDeleted?.Invoke(this, new ConfigurationWatcherEventArgs() { Builders = refences.Select(ta => ta.Builder) }); }); } this.WriteShareToLog(change, oldBuilder, refences); oldBuilder.Dispose(); } break; } }