/// <summary> /// Registers available configuration based on Central Model path match. /// </summary> private static void ApplyConfiguration(Document doc) { try { var centralPath = FileInfoUtil.GetCentralFilePath(doc); var config = MissionControlSetup.Configurations[centralPath]; var launchSockets = false; foreach (var updater in config.Updaters) { if (!updater.IsUpdaterOn) { continue; } if (string.Equals(updater.UpdaterId, AppCommand.Instance.DoorUpdaterInstance.UpdaterGuid.ToString(), StringComparison.OrdinalIgnoreCase)) { // (Konrad) We need to register updaters from within Revit context. // That's why we are running this in the Idling Event. AppCommand.EnqueueTask(app => { AppCommand.Instance.DoorUpdaterInstance.Register(doc, updater); }); } else if (string.Equals(updater.UpdaterId, AppCommand.Instance.DtmUpdaterInstance.UpdaterGuid.ToString(), StringComparison.OrdinalIgnoreCase)) { ProcessTriggerRecords(centralPath); AppCommand.EnqueueTask(app => { AppCommand.Instance.DtmUpdaterInstance.Register(doc, updater); }); DTMTool.DtmSynchOverrides.CreateReloadLatestOverride(); DTMTool.DtmSynchOverrides.CreateSynchToCentralOverride(); } else if (string.Equals(updater.UpdaterId, Properties.Resources.LinkUnloadTrackerGuid, StringComparison.OrdinalIgnoreCase)) { AppCommand.EnqueueTask(LinkUnloadMonitor.LinkUnloadMonitor.CreateLinkUnloadOverride); } else if (string.Equals(updater.UpdaterId, Properties.Resources.SheetsTrackerGuid, StringComparison.OrdinalIgnoreCase)) { ProcessSheets(ActionType.CheckIn, doc, centralPath); launchSockets = true; } else if (string.Equals(updater.UpdaterId, Properties.Resources.HealthReportTrackerGuid, StringComparison.OrdinalIgnoreCase)) { // (Konrad) These are read-only methods so they don't need to run in Revit context. ProcessModels(ActionType.CheckIn, doc, centralPath); ProcessWorksets(ActionType.CheckIn, doc, centralPath); #if RELEASE2015 || RELEASE2016 || RELEASE2017 // (Konrad) We are not going to process warnings here. #else ProcessWarnings(ActionType.CheckIn, doc, centralPath); #endif ProcessFamilies(centralPath); ProcessStyle(doc, centralPath); ProcessLinks(doc, centralPath); ProcessViews(doc, centralPath); ProcessGroups(doc, centralPath); launchSockets = true; } } // (Konrad) This tool will reset Shared Parameters Location to one specified in Mission Control if (config.GetType().GetProperty("sharedParamMonitor") != null && config.SharedParamMonitor.IsMonitorOn) { if (File.Exists(config.SharedParamMonitor.FilePath)) { doc.Application.SharedParametersFilename = config.SharedParamMonitor.FilePath; } else { Log.AppendLog(LogMessageType.ERROR, "Failed to reset Shared Parameter location. Could not find file specified."); } } if (launchSockets) { // (Konrad) in order not to become out of synch with the database we need a way // to communicate live updates from the database to task assistant/communicator var socket = new MissionControlSocket(doc); socket.Start(); AppCommand.Socket = socket; } // Publish user/machine info to be used by Zombie var userInfo = new UserItem { User = Environment.UserName.ToLower(), Machine = Environment.MachineName }; if (!ServerUtilities.Post(userInfo, "users/add", out ResponseCreated unused1)) { Log.AppendLog(LogMessageType.ERROR, "Failed to publish User/Machine Data."); } } catch (Exception ex) { Log.AppendLog(LogMessageType.EXCEPTION, ex.Message); } }
/// <summary> /// Submits request to create new sheet. /// </summary> /// <param name="app"></param> private void CreateSheet(UIApplication app) { var doc = app.ActiveUIDocument.Document; CentralPath = FileInfoUtil.GetCentralFilePath(doc); IsUpdatingSheet = true; app.Application.FailuresProcessing += FailureProcessing; using (var trans = new Transaction(doc, "CreateSheet")) { trans.Start(); try { ViewSheet sheet; if (SheetTask.IsPlaceholder) { sheet = ViewSheet.CreatePlaceholder(doc); } else { // TODO: This should be exposed to user in Mission Control. var titleblock = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).FirstOrDefault(x => x.Category.Name == "Title Blocks"); if (titleblock == null) { IsUpdatingSheet = false; Messenger.Default.Send(new SheetTaskCompletedMessage { Completed = false, Message = "Could not find a valid TitleBlock.", CentralPath = CentralPath }); return; } sheet = ViewSheet.Create(doc, titleblock.Id); } sheet.get_Parameter(BuiltInParameter.SHEET_NUMBER)?.Set(SheetTask.Number); sheet.get_Parameter(BuiltInParameter.SHEET_NAME)?.Set(SheetTask.Name); // (Konrad) We can set this here and pick up in the UI before sending off to MongoDB. var newSheetItem = new SheetItem(sheet, CentralPath) { Tasks = SheetItem.Tasks, CollectionId = SheetItem.CollectionId, Id = SheetItem.Id, IsNewSheet = true // this was overriden to false by default constructor }; SheetItem = newSheetItem; trans.Commit(); IsUpdatingSheet = false; } catch (Exception e) { trans.RollBack(); IsUpdatingSheet = false; Log.AppendLog(LogMessageType.EXCEPTION, "Failed to create sheet."); Messenger.Default.Send(new SheetTaskCompletedMessage { Completed = false, Message = e.Message, CentralPath = CentralPath }); } } // (Konrad) We don't want Revit to keep triggering this even when we are not processing updates. app.Application.FailuresProcessing -= FailureProcessing; }
/// <summary> /// Submits edits to a sheet. /// </summary> /// <param name="app"></param> private void UpdateSheet(UIApplication app) { var doc = app.ActiveUIDocument.Document; CentralPath = FileInfoUtil.GetCentralFilePath(doc); IsUpdatingSheet = true; app.Application.FailuresProcessing += FailureProcessing; var view = doc.GetElement(SheetItem.UniqueId) as ViewSheet; if (view != null) { if (WorksharingUtils.GetCheckoutStatus(doc, view.Id) == CheckoutStatus.OwnedByOtherUser) { IsUpdatingSheet = false; Messenger.Default.Send(new SheetTaskCompletedMessage { Completed = false, Message = "Element owned by another user. Try reloading latest.", CentralPath = CentralPath }); return; } using (var trans = new Transaction(doc, "UpdateSheet")) { trans.Start(); var action = "update"; try { if (SheetTask.IsDeleted) { action = "delete"; doc.Delete(view.Id); } else { view.get_Parameter(BuiltInParameter.SHEET_NUMBER)?.Set(SheetTask.Number); view.get_Parameter(BuiltInParameter.SHEET_NAME)?.Set(SheetTask.Name); } trans.Commit(); IsUpdatingSheet = false; } catch (Exception e) { trans.RollBack(); IsUpdatingSheet = false; Log.AppendLog(LogMessageType.EXCEPTION, "Failed to " + action + " sheet."); Messenger.Default.Send(new SheetTaskCompletedMessage { Completed = false, Message = e.Message, CentralPath = CentralPath }); } } } // (Konrad) We don't want Revit to keep triggering this even when we are not processing updates. app.Application.FailuresProcessing -= FailureProcessing; }
/// <summary> /// /// </summary> /// <param name="data"></param> public void Execute(UpdaterData data) { try { var doc = data.GetDocument(); if (data.GetModifiedElementIds().Count > 0) { var doorId = data.GetModifiedElementIds().First(); var doorInstance = doc.GetElement(doorId) as FamilyInstance; bool isV2Door = null != doorInstance.Symbol.LookupParameter(v2ParamName); string pullParamName = isV2Door ? v2pullParamName : v1pullParamName; string pushParamName = isV2Door ? v2pushParamName : v1pushParamName; string typeNameContains = isV2Door ? v2clearanceTypeName : v1clearanceTypeName; if (null != doorInstance) { var pushParameter = doorInstance.LookupParameter(pushParamName); if (null != pushParameter) { if (data.IsChangeTriggered(doorId, Element.GetChangeTypeParameter(pushParameter))) { var pushValue = pushParameter.AsValueString(); if (!pushValue.Contains(typeNameContains)) { DoorFailure.IsDoorFailed = true; DoorFailure.FailingDoorId = doorId; DoorFailure.CurrentDoc = doc; FailureProcessor.IsFailureFound = true; var dr = MessageBox.Show(pushValue + " is not a correct value for the parameter " + pushParamName, "Invalid Door Parameter.", MessageBoxButton.OK, MessageBoxImage.Information); } } } var pullParameter = doorInstance.LookupParameter(pullParamName); if (null != pullParameter) { if (data.IsChangeTriggered(doorId, Element.GetChangeTypeParameter(pullParameter))) { var pullValue = pullParameter.AsValueString(); if (!pullValue.Contains(typeNameContains)) { DoorFailure.IsDoorFailed = true; DoorFailure.FailingDoorId = doorId; FailureProcessor.IsFailureFound = true; var dr = MessageBox.Show(pullValue + " is not a correct value for the parameter " + pullParamName, "Invalid Door Parameter.", MessageBoxButton.OK, MessageBoxImage.Information); } } } var caParameter = doorInstance.LookupParameter(stateCAParamName); if (null != caParameter) { if (data.IsChangeTriggered(doorId, Element.GetChangeTypeParameter(caParameter))) { var centralPath = FileInfoUtil.GetCentralFilePath(doc); if (MissionControlSetup.Projects.ContainsKey(centralPath)) { var project = MissionControlSetup.Projects[centralPath]; if (project.Address.State == "CA") { caParameter.Set(1); } else { caParameter.Set(0); } } } } } } else if (data.GetAddedElementIds().Count > 0) { var doorId = data.GetAddedElementIds().First(); var doorInstance = doc.GetElement(doorId) as FamilyInstance; if (null != doorInstance) { var caParameter = doorInstance.LookupParameter(stateCAParamName); if (null != caParameter) { var centralPath = FileInfoUtil.GetCentralFilePath(doc); if (MissionControlSetup.Projects.ContainsKey(centralPath)) { var project = MissionControlSetup.Projects[centralPath]; if (project.Address.State == "CA") { caParameter.Set(1); } else { caParameter.Set(0); } } } } } } catch (Exception ex) { Log.AppendLog(LogMessageType.EXCEPTION, ex.Message); } }
/// <summary> /// /// </summary> /// <returns></returns> public ObservableCollection <DimensionWrapper> CollectDimensionOverrides() { var dInstances = new FilteredElementCollector(_doc) .OfClass(typeof(Dimension)) .WhereElementIsNotElementType() .Cast <Dimension>(); // (Konrad) There is a user override in Configuration that controls what dimension overrides are ignored var centralPath = FileInfoUtil.GetCentralFilePath(_doc); var config = MissionControlSetup.Configurations.ContainsKey(centralPath) ? MissionControlSetup.Configurations[centralPath] : null; var dimensionValueCheck = new List <string> { "EQ" }; //defaults if (config != null) { dimensionValueCheck = config.Updaters.First(x => string.Equals(x.UpdaterId, Properties.Resources.HealthReportTrackerGuid, StringComparison.OrdinalIgnoreCase)).UserOverrides.DimensionValueCheck.Values; } var units = _doc.GetUnits(); var dims = new List <DimensionWrapper>(); foreach (var d in dInstances) { if (d.NumberOfSegments == 0) { if (string.IsNullOrEmpty(d.ValueOverride)) { continue; } // dim w/ zero segments dims.Add(new DimensionWrapper(d) { DimensionId = d.Id, OwnerViewType = d.ViewSpecific ? ((View)_doc.GetElement(d.OwnerViewId)).ViewType.ToString() : string.Empty, OwnerViewId = d.OwnerViewId, #if RELEASE2021 ValueString = UnitFormatUtils.Format(units, d.DimensionType.GetSpecTypeId(), (double)d.Value, false), #else ValueString = UnitFormatUtils.Format(units, d.DimensionType.UnitType, (double)d.Value, false, false), #endif IsValueOverrideHuge = EvaluateValueOverride(d.ValueOverride, d.Value), IsVisible = !dimensionValueCheck.Any(d.ValueOverride.Contains), IsFiltered = dimensionValueCheck.Any(d.ValueOverride.Contains) }); } else { // dim w/ multiple segments foreach (DimensionSegment s in d.Segments) { // not every segment has to be overriden if (string.IsNullOrEmpty(s.ValueOverride)) { continue; } dims.Add(new DimensionWrapper(s) { DimensionId = d.Id, OwnerViewType = d.ViewSpecific ? ((View)_doc.GetElement(d.OwnerViewId)).ViewType.ToString() : string.Empty, OwnerViewId = d.OwnerViewId, #if RELEASE2021 ValueString = UnitFormatUtils.Format(units, d.DimensionType.GetSpecTypeId(), (double)s.Value, false), #else ValueString = UnitFormatUtils.Format(units, d.DimensionType.UnitType, (double)s.Value, false, false), #endif IsValueOverrideHuge = EvaluateValueOverride(s.ValueOverride, s.Value), IsVisible = !dimensionValueCheck.Any(s.ValueOverride.Contains), IsFiltered = dimensionValueCheck.Any(s.ValueOverride.Contains) }); } } } return(new ObservableCollection <DimensionWrapper>(dims)); }
/// <summary> /// /// </summary> /// <param name="doc"></param> /// <param name="stylesId"></param> public void PublishData(Document doc, string stylesId) { try { _doc = doc; #region Text Note Type stats var textTypes = new FilteredElementCollector(doc) .OfClass(typeof(TextNoteType)) .ToDictionary(x => x.Id.IntegerValue, x => new Tuple <Element, int>(x, 0)); var textInstances = new FilteredElementCollector(doc) .OfClass(typeof(TextNote)) .WhereElementIsNotElementType(); foreach (var t in textInstances) { var key = t.GetTypeId().IntegerValue; if (textTypes.ContainsKey(key)) { // increment instance count textTypes[key] = new Tuple <Element, int>(textTypes[key].Item1, textTypes[key].Item2 + 1); } } var textStats = textTypes.Select(x => new TextNoteTypeInfo(x.Value.Item1) { Instances = x.Value.Item2 }) .ToList(); #endregion #region Dimension Type stats var dimTypes = new FilteredElementCollector(doc) .OfClass(typeof(DimensionType)) .Cast <DimensionType>() .Where(x => !string.IsNullOrEmpty(x.get_Parameter(BuiltInParameter.SYMBOL_NAME_PARAM).AsString())) .ToDictionary(x => x.Id.IntegerValue, x => new Tuple <DimensionType, int>(x, 0)); var dimInstances = new FilteredElementCollector(doc) .OfClass(typeof(Dimension)) .WhereElementIsNotElementType() .Cast <Dimension>(); // (Konrad) There is a user override in Configuration that controls what dimension overrides are ignored var centralPath = FileInfoUtil.GetCentralFilePath(doc); var config = MissionControlSetup.Configurations.ContainsKey(centralPath) ? MissionControlSetup.Configurations[centralPath] : null; var dimensionValueCheck = new List <string> { "EQ" }; //defaults if (config != null) { dimensionValueCheck = config.Updaters.First(x => string.Equals(x.UpdaterId, Properties.Resources.HealthReportTrackerGuid, StringComparison.OrdinalIgnoreCase)).UserOverrides.DimensionValueCheck.Values; } var units = _doc.GetUnits(); var dimSegmentStats = new List <DimensionSegmentInfo>(); foreach (var d in dimInstances) { var key = d.GetTypeId().IntegerValue; if (dimTypes.ContainsKey(key)) { // increment instance count dimTypes[key] = new Tuple <DimensionType, int>(dimTypes[key].Item1, dimTypes[key].Item2 + 1); } if (d.NumberOfSegments == 0) { if (string.IsNullOrEmpty(d.ValueOverride)) { continue; } if (dimensionValueCheck.Any(d.ValueOverride.Contains)) { continue; } // dim w/ zero segments dimSegmentStats.Add(new DimensionSegmentInfo(d) { #if RELEASE2021 ValueString = UnitFormatUtils.Format(units, d.DimensionType.GetSpecTypeId(), (double)d.Value, false), #else ValueString = UnitFormatUtils.Format(units, d.DimensionType.UnitType, (double)d.Value, false, false), #endif OwnerViewType = d.ViewSpecific ? ((View)doc.GetElement(d.OwnerViewId)).ViewType.ToString() : string.Empty, OwnerViewId = d.OwnerViewId.IntegerValue }); } else { // dim w/ multiple segments foreach (DimensionSegment s in d.Segments) { if (string.IsNullOrEmpty(s.ValueOverride)) { continue; } if (dimensionValueCheck.Any(s.ValueOverride.Contains)) { continue; } dimSegmentStats.Add(new DimensionSegmentInfo(s) { #if RELEASE2021 ValueString = UnitFormatUtils.Format(units, d.DimensionType.GetSpecTypeId(), (double)d.Value, false), #else ValueString = UnitFormatUtils.Format(units, d.DimensionType.UnitType, (double)d.Value, false, false), #endif OwnerViewType = d.ViewSpecific ? ((View)doc.GetElement(d.OwnerViewId)).ViewType.ToString() : string.Empty, OwnerViewId = d.OwnerViewId.IntegerValue }); } } } var dimStats = dimTypes.Select(x => new DimensionTypeInfo(x.Value.Item1) { Instances = x.Value.Item2 }) .ToList(); #endregion #region Line Style stats //TODO: Finish this out. #endregion var stylesStats = new StylesDataItem { User = Environment.UserName.ToLower(), TextStats = textStats, DimStats = dimStats, DimSegmentStats = dimSegmentStats }; if (!ServerUtilities.Post(stylesStats, "styles/" + stylesId + "/stylestats", out StylesDataItem unused)) { Log.AppendLog(LogMessageType.ERROR, "Failed to publish Styles Data."); } } catch (Exception e) { Log.AppendLog(LogMessageType.EXCEPTION, e.Message); } }
//public const string BaseUrlLocal = "http://localhost:8080"; public MissionControlSocket(Document doc) { _alive = false; _t = new Thread(() => { try { var centralPath = FileInfoUtil.GetCentralFilePath(doc); var options = new IO.Options { IgnoreServerCertificateValidation = true, AutoConnect = true, ForceNew = true, Upgrade = false }; options.Transports = ImmutableList.Create <string>(WebSocket.NAME); _socket = IO.Socket(BaseUrlLocal, options); _socket.On(Quobject.SocketIoClientDotNet.Client.Socket.EVENT_CONNECT, () => { _socket.Emit("room", centralPath.ToLower()); Log.AppendLog(LogMessageType.INFO, "Connected to Mission Control socket."); Log.AppendLog(LogMessageType.INFO, "Joined Room: " + centralPath.ToLower()); }); _socket.On(Quobject.SocketIoClientDotNet.Client.Socket.EVENT_DISCONNECT, () => { Log.AppendLog(LogMessageType.INFO, "Disconnected from Mission Control socket."); }); _socket.On(Quobject.SocketIoClientDotNet.Client.Socket.EVENT_CONNECT_TIMEOUT, () => { Log.AppendLog(LogMessageType.INFO, "Mission Control socket connection timed out."); }); #region Family Tasks _socket.On("task_deleted", body => { if (body != null) { var data = JObject.FromObject(body); var deletedIds = data.Property("deletedIds") != null ? data["deletedIds"].ToObject <List <string> >() : new List <string>(); var familyName = data.Property("familyName") != null ? data["familyName"].ToObject <string>() : string.Empty; if (!deletedIds.Any() || string.IsNullOrEmpty(familyName)) { return; } Messenger.Default.Send(new FamilyTaskDeletedMessage { FamilyName = familyName, DeletedIds = deletedIds }); } else { Log.AppendLog(LogMessageType.ERROR, "task_deleted: Data was null!"); } }); _socket.On("familyTask_added", body => { if (body != null) { var data = JObject.FromObject(body); var familyName = data.Property("familyName") != null ? data["familyName"].ToObject <string>() : string.Empty; var task = data.Property("task") != null ? data["task"].ToObject <FamilyTask>() : null; if (string.IsNullOrEmpty(familyName) || task == null) { return; } // (Konrad) We want to filter out tasks that don't belong to us or to this model. // We can use "collectionId" to identify the model since that is tied to centralPath. if (!string.Equals(task.AssignedTo, Environment.UserName, StringComparison.CurrentCultureIgnoreCase)) { return; } Messenger.Default.Send(new FamilyTaskAddedMessage { FamilyName = familyName, Task = task }); } else { Log.AppendLog(LogMessageType.ERROR, "familyTask_added: Data was null!"); } }); _socket.On("familyTask_updated", body => { if (body != null) { var data = JObject.FromObject(body); var familyName = data.Property("familyName") != null ? data["familyName"].ToObject <string>() : string.Empty; var task = data.Property("task") != null ? data["task"].ToObject <FamilyTask>() : null; if (task == null || string.IsNullOrEmpty(familyName)) { return; } Messenger.Default.Send(new FamilyTaskUpdatedMessage { FamilyName = familyName, Task = task }); } else { Log.AppendLog(LogMessageType.ERROR, "familyTask_updated: Data was null!"); } }); #endregion #region Sheet Tasks _socket.On("sheetTask_added", body => { if (body != null) { var data = JObject.FromObject(body); var sheetsData = data.Property("body") != null ? data["body"].ToObject <SheetData>() : null; var sheetId = data.Property("sheetId") != null ? data["sheetId"].ToObject <string>() : string.Empty; var taskId = data.Property("taskId") != null ? data["taskId"].ToObject <string>() : string.Empty; if (sheetsData == null || string.IsNullOrEmpty(sheetId) || string.IsNullOrEmpty(taskId)) { return; } var sheet = sheetsData.Sheets.FirstOrDefault(x => string.Equals(x.Id, sheetId, StringComparison.Ordinal)); var task = sheet?.Tasks.FirstOrDefault(x => string.Equals(x.Id, taskId, StringComparison.Ordinal)); // (Konrad) We want to filter out tasks that don't belong to us or to this model. // We can use "collectionId" to identify the model since that is tied to centralPath. if (task == null || !string.Equals(task.AssignedTo, Environment.UserName, StringComparison.OrdinalIgnoreCase)) { return; } Messenger.Default.Send(new SheetsTaskAddedMessage { Sheet = sheet, Task = task, CentralPath = centralPath }); } else { Log.AppendLog(LogMessageType.ERROR, "sheetTask_added: Data was null!"); } }); _socket.On("sheetTask_updated", body => { if (body != null) { var data = JObject.FromObject(body); var sheetsData = data.Property("body") != null ? data["body"].ToObject <SheetData>() : null; var sheetId = data.Property("sheetId") != null ? data["sheetId"].ToObject <string>() : string.Empty; var taskId = data.Property("taskId") != null ? data["taskId"].ToObject <string>() : string.Empty; if (sheetsData == null || string.IsNullOrEmpty(sheetId) || string.IsNullOrEmpty(taskId)) { return; } var sheet = sheetsData.Sheets.FirstOrDefault(x => string.Equals(sheetId, x.Id, StringComparison.Ordinal)); var task = sheet?.Tasks.FirstOrDefault(x => string.Equals(x.Id, taskId, StringComparison.Ordinal)); if (task == null) { return; } Messenger.Default.Send(new SheetsTaskUpdatedMessage { Sheet = sheet, Task = task, CentralPath = centralPath }); } else { Log.AppendLog(LogMessageType.ERROR, "sheetTask_updated: Data was null!"); } }); _socket.On("sheetTask_deleted", body => { if (body != null) { var data = JObject.FromObject(body); var sheetId = data.Property("sheetId") != null ? data["sheetId"].ToObject <string>() : string.Empty; var deletedIds = data.Property("deletedIds") != null ? data["deletedIds"].ToObject <List <string> >() : new List <string>(); if (string.IsNullOrEmpty(sheetId) || !deletedIds.Any()) { return; } Messenger.Default.Send(new SheetsTaskDeletedMessage { SheetId = sheetId, DeletedIds = deletedIds, CentralPath = centralPath }); } else { Log.AppendLog(LogMessageType.ERROR, "sheetTask_deleted: Data was null!"); } }); _socket.On("sheetTask_sheetsAdded", body => { if (body != null) { var data = JObject.FromObject(body); var sheetsData = data.Property("body") != null ? data["body"].ToObject <SheetData>() : null; var sheetsIds = data.Property("sheetIds") != null ? data["sheetIds"].ToObject <List <string> >() : new List <string>(); if (sheetsData == null || !sheetsIds.Any()) { return; } Messenger.Default.Send(new SheetTaskSheetsCreatedMessage { Sheets = sheetsData.Sheets.Where(x => sheetsIds.Contains(x.Id)).ToList(), CentralPath = centralPath }); } else { Log.AppendLog(LogMessageType.ERROR, "sheetTask_sheetsAdded: Data was null!"); } }); _socket.On("sheetTask_sheetDeleted", body => { if (body != null) { var data = JObject.FromObject(body); var sheetId = data.Property("sheetId") != null ? data["sheetId"].ToObject <string>() : string.Empty; var deletedIds = data.Property("deletedIds") != null ? data["deletedIds"].ToObject <List <string> >() : new List <string>(); if (string.IsNullOrEmpty(sheetId) || !deletedIds.Any()) { return; } Messenger.Default.Send(new SheetTaskSheetDeletedMessage { SheetId = sheetId, DeletedIds = deletedIds, CentralPath = centralPath }); } else { Log.AppendLog(LogMessageType.ERROR, "sheetTask_sheetDeleted: Data was null!"); } }); #endregion while (_alive) { Thread.Sleep(100); } } catch (ThreadInterruptedException) { _socket.Disconnect(); Log.AppendLog(LogMessageType.ERROR, "Socket was canceled. Most likely because Document was closed."); } catch (Exception e) { Log.AppendLog(LogMessageType.ERROR, e.Message); } }) { IsBackground = true, Priority = ThreadPriority.BelowNormal }; }
public void Execute(UpdaterData data) { try { Document doc = data.GetDocument(); if (data.GetModifiedElementIds().Count > 0) { ElementId doorId = data.GetModifiedElementIds().First(); FamilyInstance doorInstance = doc.GetElement(doorId) as FamilyInstance; if (null != doorInstance) { #if RELEASE2013 || RELEASE2014 Parameter pushParameter = doorInstance.get_Parameter(pushParamName); #elif RELEASE2015 || RELEASE2016 Parameter pushParameter = doorInstance.LookupParameter(pushParamName); #endif if (null != pushParameter) { if (data.IsChangeTriggered(doorId, Element.GetChangeTypeParameter(pushParameter))) { string pushValue = pushParameter.AsValueString(); if (!pushValue.Contains("Approach")) { DoorFailure.IsDoorFailed = true; DoorFailure.FailingDoorId = doorId; FailureProcessor.IsFailureFound = true; MessageBoxResult dr = MessageBox.Show(pushValue + " is not a correct value for the parameter " + pushParamName, "Invalid Door Parameter.", MessageBoxButton.OK, MessageBoxImage.Information); } } } #if RELEASE2013 || RELEASE2014 Parameter pullParameter = doorInstance.get_Parameter(pullParamName); #elif RELEASE2015 || RELEASE2016 Parameter pullParameter = doorInstance.LookupParameter(pullParamName); #endif if (null != pullParameter) { if (data.IsChangeTriggered(doorId, Element.GetChangeTypeParameter(pullParameter))) { string pullValue = pullParameter.AsValueString(); if (!pullValue.Contains("Approach")) { DoorFailure.IsDoorFailed = true; DoorFailure.FailingDoorId = doorId; FailureProcessor.IsFailureFound = true; MessageBoxResult dr = MessageBox.Show(pullValue + " is not a correct value for the parameter " + pullParamName, "Invalid Door Parameter.", MessageBoxButton.OK, MessageBoxImage.Information); } } } #if RELEASE2013 || RELEASE2014 Parameter caParameter = doorInstance.get_Parameter(stateCAParamName); #elif RELEASE2015 || RELEASE2016 Parameter caParameter = doorInstance.LookupParameter(stateCAParamName); #endif if (null != caParameter) { if (data.IsChangeTriggered(doorId, Element.GetChangeTypeParameter(caParameter))) { string centralPath = FileInfoUtil.GetCentralFilePath(doc); if (AppCommand.Instance.ProjectDictionary.ContainsKey(centralPath)) { Project project = AppCommand.Instance.ProjectDictionary[centralPath]; if (project.address.state == "CA") { caParameter.Set(1); } else { caParameter.Set(0); } } } } } } else if (data.GetAddedElementIds().Count > 0) { ElementId doorId = data.GetAddedElementIds().First(); FamilyInstance doorInstance = doc.GetElement(doorId) as FamilyInstance; if (null != doorInstance) { #if RELEASE2013 || RELEASE2014 Parameter caParameter = doorInstance.get_Parameter(stateCAParamName); #elif RELEASE2015 || RELEASE2016 Parameter caParameter = doorInstance.LookupParameter(stateCAParamName); #endif if (null != caParameter) { string centralPath = FileInfoUtil.GetCentralFilePath(doc); if (AppCommand.Instance.ProjectDictionary.ContainsKey(centralPath)) { Project project = AppCommand.Instance.ProjectDictionary[centralPath]; if (project.address.state == "CA") { caParameter.Set(1); } else { caParameter.Set(0); } } } } } } catch (Exception ex) { LogUtil.AppendLog("DoorUpdater-Execute:" + ex.Message); } }
/// <summary> /// /// </summary> /// <param name="doc"></param> /// <param name="pUpdater"></param> public void RefreshTriggers(Document doc, ProjectUpdater pUpdater) { try { var centralPath = FileInfoUtil.GetCentralFilePath(doc); var configId = ""; if (MissionControlSetup.Configurations.ContainsKey(centralPath)) { configId = MissionControlSetup.Configurations[centralPath].Id; } UpdaterRegistry.RemoveDocumentTriggers(_updaterId, doc); var elementsToDelete = _reportingElements.Where(x => x.CentralPath == centralPath).ToList(); if (elementsToDelete.Any()) { foreach (var eInfo in elementsToDelete) { _reportingElements.Remove(eInfo); } } foreach (var trigger in pUpdater.CategoryTriggers) { if (!trigger.IsEnabled) { continue; } var catFilter = new ElementCategoryFilter(_catDictionary[trigger.CategoryName]); UpdaterRegistry.AddTrigger(_updaterId, catFilter, Element.GetChangeTypeAny()); UpdaterRegistry.AddTrigger(_updaterId, catFilter, Element.GetChangeTypeElementAddition()); UpdaterRegistry.AddTrigger(_updaterId, catFilter, Element.GetChangeTypeElementDeletion()); switch (trigger.CategoryName) { case "Grids": { GridUtils.CollectGridExtents(doc, centralPath); if (GridUtils.gridParameters.ContainsKey(centralPath)) { foreach (var paramId in GridUtils.gridParameters[centralPath]) { UpdaterRegistry.AddTrigger(_updaterId, catFilter, Element.GetChangeTypeParameter(paramId)); } } var elements = new FilteredElementCollector(doc) .WherePasses(catFilter) .WhereElementIsNotElementType() .ToElements(); foreach (var element in elements) { var reportingInfo = new ReportingElementInfo( configId, UpdaterGuid.ToString(), centralPath, trigger.CategoryName, trigger.Description, element.Id, element.UniqueId); _reportingElements.Add(reportingInfo); } } break; case "Views": { var viewTemplates = new FilteredElementCollector(doc) .WherePasses(catFilter) .WhereElementIsNotElementType() .Cast <View>() .Where(x => x.IsTemplate) .ToList(); if (viewTemplates.Any()) { foreach (var view in viewTemplates) { var reportingInfo = new ReportingElementInfo( configId, UpdaterGuid.ToString(), centralPath, trigger.CategoryName, trigger.Description, view.Id, view.UniqueId); _reportingElements.Add(reportingInfo); } } } break; default: { var elements = new FilteredElementCollector(doc) .WherePasses(catFilter) .WhereElementIsNotElementType() .ToElements(); foreach (var element in elements) { var reportingInfo = new ReportingElementInfo( configId, UpdaterGuid.ToString(), centralPath, trigger.CategoryName, trigger.Description, element.Id, element.UniqueId); _reportingElements.Add(reportingInfo); } } break; } } } catch (Exception ex) { Log.AppendLog(LogMessageType.EXCEPTION, ex.Message); } }
public void RefreshTriggers(Document doc, ProjectUpdater pUpdater) { try { string centralPath = FileInfoUtil.GetCentralFilePath(doc); string configId = ""; if (AppCommand.Instance.ConfigDictionary.ContainsKey(centralPath)) { configId = AppCommand.Instance.ConfigDictionary[centralPath]._id; } UpdaterRegistry.RemoveDocumentTriggers(updaterId, doc); var elementsToDelete = from eInfo in reportingElements where eInfo.CentralPath == centralPath select eInfo; if (elementsToDelete.Count() > 0) { List <ReportingElementInfo> elementsInfo = elementsToDelete.ToList(); foreach (ReportingElementInfo eInfo in elementsInfo) { reportingElements.Remove(eInfo); } } foreach (CategoryTrigger trigger in pUpdater.CategoryTriggers) { if (trigger.isEnabled) { ElementCategoryFilter catFilter = new ElementCategoryFilter(catDictionary[trigger.categoryName]); UpdaterRegistry.AddTrigger(updaterId, catFilter, Element.GetChangeTypeAny()); UpdaterRegistry.AddTrigger(updaterId, catFilter, Element.GetChangeTypeElementAddition()); UpdaterRegistry.AddTrigger(updaterId, catFilter, Element.GetChangeTypeElementDeletion()); if (trigger.categoryName == "Grids") { GridUtils.CollectGridExtents(doc, centralPath); if (GridUtils.gridParameters.ContainsKey(centralPath)) { foreach (ElementId paramId in GridUtils.gridParameters[centralPath]) { UpdaterRegistry.AddTrigger(updaterId, catFilter, Element.GetChangeTypeParameter(paramId)); } } FilteredElementCollector collector = new FilteredElementCollector(doc); List <Element> elements = collector.WherePasses(catFilter).WhereElementIsNotElementType().ToElements().ToList(); foreach (Element element in elements) { ReportingElementInfo reportingInfo = new ReportingElementInfo(configId, updaterGuid.ToString(), centralPath, trigger.categoryName, trigger.description, element.Id, element.UniqueId); reportingElements.Add(reportingInfo); } } else if (trigger.categoryName == "Views") { FilteredElementCollector collector = new FilteredElementCollector(doc); List <View> views = collector.WherePasses(catFilter).WhereElementIsNotElementType().ToElements().Cast <View>().ToList(); var viewTemplates = from view in views where view.IsTemplate select view; if (viewTemplates.Count() > 0) { foreach (Element view in viewTemplates) { ReportingElementInfo reportingInfo = new ReportingElementInfo(configId, updaterGuid.ToString(), centralPath, trigger.categoryName, trigger.description, view.Id, view.UniqueId); reportingElements.Add(reportingInfo); } } } else { FilteredElementCollector collector = new FilteredElementCollector(doc); List <Element> elements = collector.WherePasses(catFilter).WhereElementIsNotElementType().ToElements().ToList(); foreach (Element element in elements) { ReportingElementInfo reportingInfo = new ReportingElementInfo(configId, updaterGuid.ToString(), centralPath, trigger.categoryName, trigger.description, element.Id, element.UniqueId); reportingElements.Add(reportingInfo); } } } } } catch (Exception ex) { string message = ex.Message; LogUtil.AppendLog("DTMUpdater-RefreshTriggers:" + ex.Message); } }