/// <summary> /// This function is used to sync WWT layers into the workbook instance and /// then set the flag IsNotInSync for the layer deleted in WWT. /// </summary> /// <param name="workbookMap"> /// Parent container. /// </param> /// <param name="groups"> /// Collection of WWT groups. /// </param> private static void SyncWWTLayers(this WorkbookMap workbookMap, ICollection <Group> groups) { if (workbookMap != null) { // 1. Append all WWT layer which are not there in the LocalLayers. foreach (Group group in groups) { AddWWTLayers(workbookMap, group); } // 2. Clean up all local layer in the current workbook map. workbookMap.LocalLayerMaps.ForEach( layer => { // 2.a. If the local layer is deleted in WWT, then set the IsNotInSync flag to true. if (!WWTManager.IsValidLayer(layer.LayerDetails.ID, groups)) { layer.IsNotInSync = true; } // 2.b. If the group (reference frame/ Layer Group) is deleted in WWT, then set the IsDeleted flag in Group to true. UpdateGroupStatus(layer.LayerDetails.Group, groups); }); } }
/// <summary> /// This function is used to update the status of the groups. /// </summary> /// <param name="group"> /// Instance of the group which has to be updated. /// </param> /// <param name="wwtGroups"> /// List of WWT groups. /// </param> private static void UpdateGroupStatus(Group group, ICollection <Group> wwtGroups) { group.IsDeleted = !WWTManager.IsValidGroup(group, wwtGroups); if (group.Parent != null) { UpdateGroupStatus(group.Parent, wwtGroups); } }
/// <summary> /// DoWork event handler for the check updates background worker /// This is run asynchronously /// </summary> /// <param name="sender">Check updates worker</param> /// <param name="e">Do work event args</param> private void OnCheckUpdatesWorkerDoWork(object sender, DoWorkEventArgs e) { string downloadUrl = WWTManager.CheckForUpdates(); if (!string.IsNullOrEmpty(downloadUrl)) { e.Result = downloadUrl; } }
public void IsValidGroupNegativeTest() { // Use WWTMockRequest in WWTManager so that all calls to WWT API will succeed. Globals_Accessor.wwtManager = new WWTManager(new WWTMockRequest()); Globals_Accessor.TargetMachine = new TargetMachine(Constants.Localhost); Group group = new Group("Insat", GroupType.ReferenceFrame, new Group("Earth", GroupType.ReferenceFrame, null)); ICollection <Group> wwtGroups = WWTManager_Accessor.GetAllWWTGroups(true); bool expected = false; bool actual; actual = WWTManager.IsValidGroup(group, wwtGroups); Assert.AreEqual(expected, actual); }
/// <summary> /// Sets the machine IP if the machine address is valid in following scenarios /// 1. WWT is running /// 2. It has version more than base version /// </summary> /// <param name="machineAddresses">Collection of IP address for the name provided</param> /// <param name="machineName">Machine display name</param> private void SetMachineIPIfValid(Collection <IPAddress> machineAddresses, string machineName) { if (machineAddresses != null && machineAddresses.Count > 0) { int count = 0; foreach (IPAddress machineAddress in machineAddresses) { try { count++; // Checks if the machine is valid and latest WWT running on it. if (WWTManager.IsValidMachine(machineAddress.ToString(), false)) { MachineIP = machineAddress; DisplayValue = machineName; break; } } catch (CustomException ex) { switch (ex.ErrorCode) { case ErrorCodes.Code100001: // If the error code is for WWT not running and is the last IP address in the loop // then throw exception else continue with the looping if (count == machineAddresses.Count) { throw new CustomException(ex.HasCustomMessage ? ex.Message : Properties.Resources.DefaultErrorMessage, ex, true); } else { continue; } case ErrorCodes.Code100003: case ErrorCodes.Code100005: case ErrorCodes.Code100002: // If WWT is running on the machine but it not latest version then throw the exception { throw new CustomException(ex.HasCustomMessage ? ex.Message : Properties.Resources.DefaultErrorMessage, ex, true); } default: break; } } } } }
public void UploadDataInWWTTest() { // Use WWTMockRequest in WWTManager so that all calls to WWT API will succeed. Globals_Accessor.wwtManager = new WWTManager(new WWTMockRequest()); Globals_Accessor.TargetMachine = new TargetMachine(Constants.Localhost); string[] data = new string[] { "TestData\r\n" }; string layerId = "3f0cfda2-7319-4190-8f5e-99778a04ca3d"; bool isConsumeException = true; bool expected = true; bool actual; actual = WWTManager.UploadDataInWWT(layerId, data, isConsumeException); Assert.AreEqual(expected, actual); }
private void OnCaptureViewpointButtonClick(object sender, RibbonControlEventArgs e) { try { Utility.IsWWTInstalled(); WWTManager.IsValidMachine(Common.Globals.TargetMachine.MachineIP.ToString(), false); Perspective perspective = WWTManager.GetCameraView(); if (perspective != null) { var dialog = new CaptureViewpoint(); System.Windows.Interop.WindowInteropHelper helper = new System.Windows.Interop.WindowInteropHelper(dialog); helper.Owner = (IntPtr)ThisAddIn.ExcelApplication.Hwnd; perspective.Name = Resources.DefaultViewpointText; var viewModel = new ViewpointViewModel(perspective); viewModel.IsButtonEnabled = true; viewModel.RequestClose += new EventHandler(dialog.OnRequestClose); dialog.DataContext = viewModel; dialog.ShowDialog(); // WPF dialog does not have dialog result if (dialog.DialogResult.HasValue && dialog.DialogResult.Value) { if (!string.IsNullOrWhiteSpace(perspective.Name)) { // Fire it only when valid value set this.GetViewpointClicked.OnFire(perspective, new EventArgs()); } } viewModel.RequestClose -= new EventHandler(dialog.OnRequestClose); dialog.Close(); } } catch (CustomException ex) { Ribbon.ShowError(ex.HasCustomMessage ? ex.Message : Resources.LayerOperationError); } catch (Exception exception) { Logger.LogException(exception); Ribbon.ShowError(Resources.DefaultErrorMessage); } }
/// <summary> /// This function is used to Add WWT layers. /// </summary> /// <param name="workbookMap"> /// Parent container. /// </param> /// <param name="group"> /// Group in which the layer is present. /// </param> private static void AddWWTLayers(WorkbookMap workbookMap, Group group) { foreach (string layerID in group.LayerIDs) { if (!workbookMap.Exists(layerID)) { Layer wwtLayer = WWTManager.GetLayerDetails(layerID, group, true); if (wwtLayer != null) { workbookMap.AllLayerMaps.Add(new LayerMap(wwtLayer)); } } } foreach (Group child in group.Children) { AddWWTLayers(workbookMap, child); } }
/// <summary> /// Sets the machine IP if the machine address is valid in following scenarios /// 1. WWT is running /// 2. It has version more than base version /// </summary> /// <param name="machineAddress">Machine Address</param> /// <param name="displayName">Machine display name</param> private void SetMachineIPIfValid(IPAddress machineAddress, string displayName) { if (machineAddress != null) { try { // Checks if the machine is valid and latest WWT running on it. if (WWTManager.IsValidMachine(machineAddress.ToString(), false)) { MachineIP = machineAddress; DisplayValue = displayName; } } catch (CustomException ex) { throw new CustomException(ex.HasCustomMessage ? ex.Message : Properties.Resources.DefaultErrorMessage, ex, true); } } }
private void btnGetLocation_Click(object sender, RibbonControlEventArgs e) { try { Utility.IsWWTInstalled(); WWTManager.IsValidMachine(Common.Globals.TargetMachine.MachineIP.ToString(), false); WorkflowController.Instance.UpdateCurrentLocation(); } catch (CustomException ex) { Ribbon.ShowError(ex.HasCustomMessage ? ex.Message : Resources.LayerOperationError); } catch (Exception exception) { Logger.LogException(exception); Ribbon.ShowError(Resources.DefaultErrorMessage); } }
/// <summary> /// This function is used to Load all WWT layers on the load of a workbook. /// This function performs the following operations: /// 1. Remove all WWT only layers. /// 2. On load of a workbook, no layers are connected with WWT. /// 3. Insert and update deleted WWT Layers. /// </summary> /// <param name="workbookMap"> /// Parent container. /// </param> internal static void LoadWWTLayers(this WorkbookMap workbookMap) { if (workbookMap != null) { LayerMap selectedLayerMap = workbookMap.SelectedLayerMap; // 1. Remove all WWT only layers. workbookMap.RemoveWWTLayers(); ICollection <Group> groups = WWTManager.GetAllWWTGroups(true); // 2. On load of a workbook, no layers are connected with WWT. workbookMap.LocalInWWTLayerMaps.ForEach( layer => { // 2.a. Set IsNotInSync. layer.IsNotInSync = true; // 2.b. Update all group references. Group group = SearchGroup(layer.LayerDetails.Group.Name, layer.LayerDetails.Group.Path, groups); if (group != null) { layer.LayerDetails.Group = group; } else { layer.LayerDetails.Group.IsDeleted = true; } }); // 3. Synchronize WWT Layers workbookMap.SyncWWTLayers(groups); // 4. Set the Selected layer map to null if the Selected WWT layer was deleted in WWT. // If the selected layer is WWT layer/is localInWWT which is not deleted, this will be selected while if (selectedLayerMap != null && selectedLayerMap.MapType == LayerMapType.WWT && !workbookMap.Exists(selectedLayerMap.LayerDetails.ID)) { workbookMap.SelectedLayerMap = null; } } }
/// <summary> /// This function is used to refresh the layer drop down with the latest layers from WWT. /// This function performs the following operations: /// 1. Remove all WWT only layers. /// 2. Insert and update deleted WWT Layers. /// 3. Set the Selected layer map to null if the Selected WWT layer was deleted in WWT. /// </summary> /// <param name="workbookMap"> /// Parent container. /// </param> internal static void RefreshLayers(this WorkbookMap workbookMap) { if (workbookMap != null) { LayerMap selectedLayerMap = workbookMap.SelectedLayerMap; ICollection <Group> groups = WWTManager.GetAllWWTGroups(true); // 1. Remove all WWT only layers. workbookMap.RemoveWWTLayers(); // 2. Insert and update deleted WWT Layers workbookMap.SyncWWTLayers(groups); // 3. Set the Selected layer map to null if the Selected WWT layer was deleted in WWT. // If the selected layer is WWT layer/is localInWWT which is not deleted, this will be selected while if (selectedLayerMap != null && selectedLayerMap.MapType == LayerMapType.WWT && !workbookMap.Exists(selectedLayerMap.LayerDetails.ID)) { workbookMap.SelectedLayerMap = null; } } }
private void OnDownloadLinkWorkerDoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { try { Uri downloadUri = new Uri(this.downloadLink); // Ensure that the temp directory exists if (!Directory.Exists(Path.GetTempPath())) { Directory.CreateDirectory(Path.GetTempPath()); } // Gets the filename from Uri and appends it with temp path. string localFilePath = Path.Combine(Path.GetTempPath(), downloadUri.Segments[downloadUri.Segments.Length - 1]); if (WWTManager.DownloadFile(downloadUri, localFilePath)) { e.Result = string.Format(CultureInfo.InvariantCulture, localFilePath, Path.GetTempPath()); } } catch (ArgumentNullException ex) { Logger.LogException(ex); } catch (FormatException ex) { Logger.LogException(ex); } catch (System.Security.SecurityException ex) { Logger.LogException(ex); } catch (Exception exception) { Logger.LogException(exception); } }
/// <summary> /// Implementation for the BackgroundWorker which will be syncing the layer properties. /// </summary> /// <param name="sender">Background Worker</param> /// <param name="e">BackgroundWorker event arguments</param> private void OnPropertyChangeNotifierDoWork(object sender, DoWorkEventArgs e) { try { e.Result = false; int layerVersion = WWTManager.CreateLayerNotification(this.LayerDetails.ID, this.LayerDetails.Version, this.cancellationTokenSource.Token); WorkbookMap parentWorkbookMap = WorkflowController.Instance.GetWorkbookMapForLayerMap(this); // Rebuild the Layer Details view model/Custom Task Pane if the layer's properties are updated in WWT. if (layerVersion > LayerDetails.Version) { if (IsPropertyChangedFromCode) { LayerDetails.Version = layerVersion; } else { // Get the current properties of the layer from WWT. Layer layerDetails = WWTManager.GetLayerDetails(LayerDetails.ID, LayerDetails.Group, true); if (layerDetails != null) { LayerDetails = layerDetails; // Update the received latest properties to the LayerMap. this.UpdateLayerMapProperties(LayerDetails); // Save the workbook map to the workbook which it belongs to. this.SaveWorkbookMap(); if (parentWorkbookMap != null && parentWorkbookMap.SelectedLayerMap == this) { // This will update the custom task pane. e.Result = true; } } } } else if (layerVersion == -1) { // In case if the layer is deleted or WWT is closed, layerVersion will be returned as -1. // In case of Timeout, layers current version will be returned which is expected in case of no update to the layer properties. // Setting not in sync will stop the notification as well. IsNotInSync = true; if (parentWorkbookMap != null && parentWorkbookMap.SelectedLayerMap == this) { if (MapType == LayerMapType.WWT) { // If current layer map is of type WWT and it is selected in layer dropdown, make sure the selection is removed. parentWorkbookMap.SelectedLayerMap = null; } // This will update the custom task pane. e.Result = true; } } } catch (Exception ex) { Logger.LogException(ex); } }
/// <summary> /// Set MappedColumnData based on Layer details /// </summary> internal void SetMappedColumnType() { if (this.LayerDetails != null && !string.IsNullOrEmpty(this.LayerDetails.ID)) { this.HeaderRowData = WWTManager.GetLayerHeader(this.LayerDetails.ID); MappedColumnType = new Collection <ColumnType>(); // Get all mapped columns first for (int count = 0; count < this.HeaderRowData.Count; count++) { MappedColumnType.Add(ColumnType.None); } if (this.LayerDetails.LatColumn > Microsoft.Research.Wwt.Excel.Common.Constants.DefaultColumnIndex && MappedColumnType.Count > this.LayerDetails.LatColumn) { MappedColumnType[this.LayerDetails.LatColumn] = ColumnType.Lat; } if (this.LayerDetails.LngColumn > Microsoft.Research.Wwt.Excel.Common.Constants.DefaultColumnIndex && MappedColumnType.Count > this.LayerDetails.LngColumn) { MappedColumnType[this.LayerDetails.LngColumn] = ColumnType.Long; } if (this.LayerDetails.GeometryColumn > Microsoft.Research.Wwt.Excel.Common.Constants.DefaultColumnIndex && MappedColumnType.Count > this.LayerDetails.GeometryColumn) { MappedColumnType[this.LayerDetails.GeometryColumn] = ColumnType.Geo; } if (this.LayerDetails.ColorMapColumn > Microsoft.Research.Wwt.Excel.Common.Constants.DefaultColumnIndex && MappedColumnType.Count > this.LayerDetails.ColorMapColumn) { MappedColumnType[this.LayerDetails.ColorMapColumn] = ColumnType.Color; } if (this.LayerDetails.AltColumn > Microsoft.Research.Wwt.Excel.Common.Constants.DefaultColumnIndex && MappedColumnType.Count > this.LayerDetails.AltColumn) { switch (this.LayerDetails.AltType) { case AltType.Altitude: MappedColumnType[this.LayerDetails.AltColumn] = ColumnType.Alt; break; case AltType.Depth: MappedColumnType[this.LayerDetails.AltColumn] = ColumnType.Depth; break; case AltType.Distance: MappedColumnType[this.LayerDetails.AltColumn] = ColumnType.Distance; break; } } if (this.LayerDetails.StartDateColumn > Microsoft.Research.Wwt.Excel.Common.Constants.DefaultColumnIndex && MappedColumnType.Count > this.LayerDetails.StartDateColumn) { MappedColumnType[this.LayerDetails.StartDateColumn] = ColumnType.StartDate; } if (this.LayerDetails.EndDateColumn > Microsoft.Research.Wwt.Excel.Common.Constants.DefaultColumnIndex && MappedColumnType.Count > this.LayerDetails.EndDateColumn) { MappedColumnType[this.LayerDetails.EndDateColumn] = ColumnType.EndDate; } if (this.LayerDetails.RAColumn > Microsoft.Research.Wwt.Excel.Common.Constants.DefaultColumnIndex && MappedColumnType.Count > this.LayerDetails.RAColumn) { MappedColumnType[this.LayerDetails.RAColumn] = ColumnType.RA; } if (this.LayerDetails.DecColumn > Microsoft.Research.Wwt.Excel.Common.Constants.DefaultColumnIndex && MappedColumnType.Count > this.LayerDetails.DecColumn) { MappedColumnType[this.LayerDetails.DecColumn] = ColumnType.Dec; } if (this.LayerDetails.XAxis > Microsoft.Research.Wwt.Excel.Common.Constants.DefaultColumnIndex && MappedColumnType.Count > this.LayerDetails.XAxis) { MappedColumnType[this.LayerDetails.XAxis] = ColumnType.X; } if (this.LayerDetails.YAxis > Microsoft.Research.Wwt.Excel.Common.Constants.DefaultColumnIndex && MappedColumnType.Count > this.LayerDetails.YAxis) { MappedColumnType[this.LayerDetails.YAxis] = ColumnType.Y; } if (this.LayerDetails.ZAxis > Microsoft.Research.Wwt.Excel.Common.Constants.DefaultColumnIndex && MappedColumnType.Count > this.LayerDetails.ZAxis) { MappedColumnType[this.LayerDetails.ZAxis] = ColumnType.Z; } if (this.LayerDetails.ReverseXAxis && this.LayerDetails.XAxis > Microsoft.Research.Wwt.Excel.Common.Constants.DefaultColumnIndex && MappedColumnType.Count > this.LayerDetails.XAxis) { MappedColumnType[this.LayerDetails.XAxis] = ColumnType.ReverseX; } if (this.LayerDetails.ReverseYAxis && this.LayerDetails.YAxis > Microsoft.Research.Wwt.Excel.Common.Constants.DefaultColumnIndex && MappedColumnType.Count > this.LayerDetails.YAxis) { MappedColumnType[this.LayerDetails.YAxis] = ColumnType.ReverseY; } if (this.LayerDetails.ReverseZAxis && this.LayerDetails.ZAxis > Microsoft.Research.Wwt.Excel.Common.Constants.DefaultColumnIndex && MappedColumnType.Count > this.LayerDetails.ZAxis) { MappedColumnType[this.LayerDetails.ZAxis] = ColumnType.ReverseZ; } // Sets size column mapping SetMappingOnSizeColumn(); } }