public FamilyMonitorViewModel(FamilyMonitorModel model, string message) { Message = message; Model = model; Close = new RelayCommand <Window>(OnClose); Cancel = new RelayCommand <Window>(OnCancel); WindowLoaded = new RelayCommand <Window>(OnWindowLoaded); WindowShown = new RelayCommand <Window>(OnWindowShown); Title = "Mission Control - Family Publish v." + Assembly.GetExecutingAssembly().GetName().Version; }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uiApp = commandData.Application; var doc = uiApp.ActiveUIDocument.Document; Log.AppendLog(LogMessageType.INFO, "Started"); try { // (Konrad) We are gathering information about the addin use. This allows us to // better maintain the most used plug-ins or discontiue the unused ones. AddinUtilities.PublishAddinLog( new AddinLog("MissionControl-PublishFamilyData", commandData.Application.Application.VersionNumber)); var pathName = doc.PathName; if (string.IsNullOrEmpty(pathName)) { Log.AppendLog(LogMessageType.ERROR, "Path is Empty. File was not saved yet."); var dialog = new FamilyMonitorView { DataContext = new FamilyMonitorViewModel(null, "...establish a connection to Mission Control for unsaved files."), CancelButton = { Visibility = Visibility.Collapsed } }; dialog.ShowDialog(); return(Result.Failed); } var centralPath = FileInfoUtil.GetCentralFilePath(doc); if (string.IsNullOrEmpty(centralPath)) { Log.AppendLog(LogMessageType.ERROR, "Could not get Central Path."); var dialog = new FamilyMonitorView { DataContext = new FamilyMonitorViewModel(null, "...get a Central File Path. Only Workshared projects can be added to Mission Control."), CancelButton = { Visibility = Visibility.Collapsed } }; dialog.ShowDialog(); return(Result.Failed); } if (!MissionControlSetup.Projects.ContainsKey(centralPath) || !MissionControlSetup.Configurations.ContainsKey(centralPath) || !MissionControlSetup.FamilyData.ContainsKey(centralPath)) { Log.AppendLog(LogMessageType.ERROR, "No Config Found."); var dialog = new FamilyMonitorView { DataContext = new FamilyMonitorViewModel(null, "...find your project in Mission Control database. Please make sure that it was added."), CancelButton = { Visibility = Visibility.Collapsed } }; dialog.ShowDialog(); return(Result.Failed); } uiApp.Application.FailuresProcessing += FailureProcessing; var familiesId = MissionControlSetup.FamilyData[centralPath].Id; var model = new FamilyMonitorModel(doc, MissionControlSetup.Configurations[centralPath], MissionControlSetup.Projects[centralPath], familiesId, centralPath); var viewModel = new FamilyMonitorViewModel(model, "...make this any faster. Hang in there!") { ExecuteFamilyPublish = true }; var view = new FamilyMonitorView { DataContext = viewModel, CloseButton = { Visibility = Visibility.Collapsed } }; var unused = new WindowInteropHelper(view) { Owner = Process.GetCurrentProcess().MainWindowHandle }; view.ShowDialog(); } catch (Exception ex) { Log.AppendLog(LogMessageType.EXCEPTION, ex.Message); } uiApp.Application.FailuresProcessing -= FailureProcessing; Log.AppendLog(LogMessageType.INFO, "Ended"); return(Result.Succeeded); }