private void CloseDisconnect(StreamWriter streamWriter, out FinalStatusEnum Status) { this.ProgressUpdate(this, new ProgressArgs() { ErrorText = "", Progress = 0, Status = ItemProgress.ProcessStatusEnum.Processing, TaskNum = 3 }); streamWriter.WriteLine("Closing and Disconnecting."); try { //Disconnect from Jama this._jamaClient = null; //Disconnect from Spira. if (this._spiraClient != null) { this._spiraClient.Connection_Disconnect(); this._spiraClient.Close(); } } catch (Exception ex) { streamWriter.WriteLine(ex.Message); } this.ProgressUpdate(this, new ProgressArgs() { ErrorText = "", Progress = 0, Status = ItemProgress.ProcessStatusEnum.Success, TaskNum = 3 }); Status = FinalStatusEnum.OK; }
/// <summary> /// Processes a Jama item, taking care of the associated attachments, comments, etc. /// </summary> /// <param name="jamaItem">The item to process.</param> private FinalStatusEnum ProcessItem(StreamWriter streamWriter, JamaItem jamaItem) { FinalStatusEnum retStatus = FinalStatusEnum.OK; try { //We ignore the Defects, Issue, Task, Risk and Change Request items if (jamaItem.ItemTypeId.HasValue) { if (jamaItem.ItemTypeId == 14 || (jamaItem.ItemTypeId >= 16 && jamaItem.ItemTypeId <= 19 || jamaItem.ItemTypeId == (int)JamaProjectInfo.Type.Bug || jamaItem.ItemTypeId == (int)JamaProjectInfo.Type.ChangeRequest)) { return(FinalStatusEnum.OK); } } int?ExistingMapped = GetLinkedNumber(jamaItem); //See if we have a mapping entry if (ExistingMapped.HasValue) { //Get the mapped requirement. SpiraSoapService.RemoteRequirement existingReq = this._spiraClient.Requirement_RetrieveById(ExistingMapped.Value); //If it no longer exists, just ignore (user needs to clear the mappings if they want to reimport) if (existingReq != null) { //Update the requirement from the Jama item SpiraSoapService.RemoteRequirement newReq = this.GenerateOrUpdateRequirement(jamaItem, existingReq); //Update the requirement this._spiraClient.Requirement_Update(newReq); } else { //Could not find requirement and it was mapped. retStatus = FinalStatusEnum.Warning; } } else { //Create the requirement. SpiraSoapService.RemoteRequirement newReq = this.GenerateOrUpdateRequirement(jamaItem, null); //Get parent's ID. If it is null, ignore this requirement because the parent // folder was deleted. (We should always have a root, because of the RootReq // or the root folder.) int?ParentID = GetParentLinkedNumber(jamaItem); if (ParentID.HasValue) { //Insert new Requirement. if (ParentID == -1) { //HACK: Force it to root. newReq = this._spiraClient.Requirement_Create1(newReq, -100); } else { newReq = this._spiraClient.Requirement_Create2(newReq, ParentID); } this.SetLinkedNumber(jamaItem, this._SpiraProject.ProjectNum, newReq.RequirementId.Value); } else { //Could not find requirement's parent, and it was mapped. retStatus = FinalStatusEnum.Warning; } } if (ProcessThread.WantCancel) { return(FinalStatusEnum.Error); } } catch (Exception ex) { streamWriter.WriteLine("Unable to complete import: " + ex.Message); retStatus = FinalStatusEnum.Error; } return(retStatus); }
/// <summary>The main processing function.</summary> /// <param name="ErrorMsg">Error message in case an error happens.</param> /// <returns>Boolean on status of import.</returns> private bool ProcessImport(StreamWriter streamWriter, out FinalStatusEnum Status) { Status = FinalStatusEnum.OK; this.ProgressUpdate(this, new ProgressArgs() { ErrorText = "", Progress = -1, Status = ItemProgress.ProcessStatusEnum.Processing, TaskNum = 2 }); streamWriter.WriteLine("Starting Import..."); try { //Load the mapping data this._requirementDataMapping = new RequirementDataMapping(); this._releaseDataMapping = new ReleaseDataMapping(); //See if we've been asked to clear the saved mapping data if (this._SpiraProject.RootReq == -1) { this._requirementDataMapping.Clear(); this._releaseDataMapping.Clear(); } else { //Get the list of Releases in the Jama project JamaProject jamaProject = this._jamaClient.GetProject(this._JamaProject.ProjectNum); if (jamaProject != null) { //Store the project short name this._projectShortName = jamaProject.ProjectKey; List <JamaRelease> jamaReleases = this._jamaClient.GetReleases(jamaProject.Id); //Import the releases into SpiraTeam if (jamaReleases != null) { foreach (JamaRelease jamaRelease in jamaReleases) { if (ProcessThread.WantCancel) { break; } FinalStatusEnum thisRun = this.ProcessRelease(streamWriter, jamaRelease); if (Status != FinalStatusEnum.Error && thisRun == FinalStatusEnum.Error) { Status = thisRun; } if (Status == FinalStatusEnum.OK && thisRun == FinalStatusEnum.Warning) { Status = thisRun; } } } } //Get the list of items in the Jama project in batches of 25 int startItem = 1; List <JamaItem> jamaItems = null; //Store the list of jama project ids and item ids so that we can track deletes later List <JamaProjectItemEntry> jamaEntries = new List <JamaProjectItemEntry>(); do { jamaItems = this._jamaClient.GetItemsForProject(this._JamaProject.ProjectNum, startItem, REQUEST_PAGE_SIZE); //Import the items into SpiraTeam if (jamaItems != null) { foreach (JamaItem jamaItem in jamaItems) { if (ProcessThread.WantCancel) { break; } FinalStatusEnum thisRun = this.ProcessItem(streamWriter, jamaItem); if (Status != FinalStatusEnum.Error && thisRun == FinalStatusEnum.Error) { Status = thisRun; } if (Status == FinalStatusEnum.OK && thisRun == FinalStatusEnum.Warning) { Status = thisRun; } //Also add to the list so that we can check for deletes afterwards jamaEntries.Add(new JamaProjectItemEntry(jamaItem.ProjectId, jamaItem.Id)); } } startItem += REQUEST_PAGE_SIZE; }while (jamaItems != null && jamaItems.Count > 0 && !ProcessThread.WantCancel); //See if we want to delete items in Spira that are not in Jama if (Properties.Settings.Default.DeleteItemInSpiraIfMissing) { //See if we have at least v3.1 of SpiraTest, since only that supports deletes RemoteVersion remoteVersion = this._spiraClient.System_GetProductVersion(); if (remoteVersion != null) { string versionNumber = remoteVersion.Version; string[] versionComponents = versionNumber.Split('.'); int majorVersion = 0; if (!Int32.TryParse(versionComponents[0], out majorVersion)) { majorVersion = 0; } int minorVersion = 0; if (versionComponents.Length > 1) { if (!Int32.TryParse(versionComponents[1], out minorVersion)) { minorVersion = 0; } } //We need at least v3.1 if (majorVersion > 3 || (majorVersion == 3 && minorVersion >= 1)) { //Now see if we have any mapped requirements that are no longer in Jama if (this._requirementDataMapping.Rows != null) { for (int i = 0; i < this._requirementDataMapping.Rows.Count; i++) { RequirementMappingData.RequirementMappingRow mappingRow = this._requirementDataMapping.Rows[i]; //See that entry exists in the list of items, if not, delete from Spira and mappings if (!jamaEntries.Any(je => je.ItemId == mappingRow.JamaItemId && je.ProjectId == mappingRow.JamaProjectId)) { DeleteSpiraRequirement(streamWriter, mappingRow); } } } } } } } //Save the mapping data this._requirementDataMapping.Save(); this._releaseDataMapping.Save(); if (Status == FinalStatusEnum.Error) { string ErrorMsg = ""; if (ProcessThread.WantCancel) { ErrorMsg = App.CANCELSTRING; } this.ProgressUpdate(this, new ProgressArgs() { ErrorText = ErrorMsg, Progress = -1, Status = ItemProgress.ProcessStatusEnum.Error, TaskNum = 2 }); return(false); } else { this.ProgressUpdate(this, new ProgressArgs() { ErrorText = "", Progress = -1, Status = ItemProgress.ProcessStatusEnum.Success, TaskNum = 2 }); return(true); } } catch (Exception exception) { //Handle all exceptions streamWriter.WriteLine("Error: " + exception.Message); this.ProgressUpdate(this, new ProgressArgs() { ErrorText = exception.Message, Progress = -1, Status = ItemProgress.ProcessStatusEnum.Error, TaskNum = 2 }); return(false); } }
/// <summary> /// Processes a Jama release, importing into SpiraTeam if necessary /// </summary> /// <param name="jamaRelease">The jama release</param> /// <returns></returns> private FinalStatusEnum ProcessRelease(StreamWriter streamWriter, JamaRelease jamaRelease) { FinalStatusEnum retStatus = FinalStatusEnum.OK; try { //Insert/update the release in SpiraTeam //See if the item is already mapped to an item in Spira int jamaReleaseId = (int)jamaRelease.Id; int jamaProjectId = this._JamaProject.ProjectNum; ReleaseMappingData.ReleaseMappingRow dataRow = this._releaseDataMapping.GetFromJamaId(jamaProjectId, jamaReleaseId); if (dataRow == null) { //We need to insert a new release RemoteRelease remoteRelease = new RemoteRelease(); if (String.IsNullOrEmpty(jamaRelease.Name)) { remoteRelease.Name = "Unknown (Null)"; } else { remoteRelease.Name = jamaRelease.Name; } if (!String.IsNullOrEmpty(jamaRelease.Name) && jamaRelease.Name.Length <= 10) { //If we have a release name that is short enough, use it for the version number //otherwise let Spira auto-generate it remoteRelease.VersionNumber = jamaRelease.Name; } else { //Currently "" denotes that we need to create a new version number //in future versions of the API it should also support passing null remoteRelease.VersionNumber = ""; } remoteRelease.Description = jamaRelease.Description; remoteRelease.ReleaseStatusId = (jamaRelease.Active) ? (int)SpiraProject.ReleaseStatusEnum.Planned : (int)SpiraProject.ReleaseStatusEnum.Completed; remoteRelease.ReleaseTypeId = (int)SpiraProject.ReleaseTypeEnum.MajorRelease; if (jamaRelease.ReleaseDate.HasValue) { //We assume that the release lasts 1-month by default remoteRelease.StartDate = jamaRelease.ReleaseDate.Value.AddMonths(-1).Date; remoteRelease.EndDate = jamaRelease.ReleaseDate.Value.Date; } else { //Just create a start/end date based on the current date remoteRelease.StartDate = DateTime.UtcNow.Date; remoteRelease.EndDate = DateTime.UtcNow.AddMonths(1).Date; } //Create the release remoteRelease = this._spiraClient.Release_Create(remoteRelease, null); this._releaseDataMapping.Add( this._SpiraProject.ProjectNum, remoteRelease.ReleaseId.Value, jamaProjectId, jamaReleaseId ); } else { //We need to update an existing release (we leave the dates alone) int spiraReleaseId = dataRow.SpiraReleaseId; RemoteRelease remoteRelease = this._spiraClient.Release_RetrieveById(spiraReleaseId); if (remoteRelease == null) { //Could not find release and it was mapped. retStatus = FinalStatusEnum.Warning; } else { //Update the release in Spira if (!String.IsNullOrEmpty(jamaRelease.Name)) { remoteRelease.Name = jamaRelease.Name; if (jamaRelease.Name.Length <= 10) { //If we have a release name that is short enough, use it for the version number //otherwise let Spira auto-generate it remoteRelease.VersionNumber = jamaRelease.Name; } } remoteRelease.Description = jamaRelease.Description; remoteRelease.Active = jamaRelease.Active; this._spiraClient.Release_Update(remoteRelease); } } if (ProcessThread.WantCancel) { return(FinalStatusEnum.Error); } } catch (Exception ex) { streamWriter.WriteLine("Unable to complete import: " + ex.Message); retStatus = FinalStatusEnum.Error; } return(retStatus); }
private bool ConnectToSpira(StreamWriter streamWriter, out FinalStatusEnum Status) { Status = FinalStatusEnum.OK; this.ProgressUpdate(this, new ProgressArgs() { ErrorText = "", Progress = -1, Status = ItemProgress.ProcessStatusEnum.Processing, TaskNum = 1 }); streamWriter.WriteLine("Connecting to Spira."); this._spiraClient = new SpiraSoapService.SoapServiceClient(); this._spiraClient.Endpoint.Address = new EndpointAddress(this._SpiraProject.ServerURL + SpiraProject.URL_APIADD); BasicHttpBinding httpBinding = (BasicHttpBinding)this._spiraClient.Endpoint.Binding; WcfUtils.ConfigureBinding(httpBinding, this._spiraClient.Endpoint.Address.Uri); //Try connecting. try { bool CanConnect = this._spiraClient.Connection_Authenticate2(this._SpiraProject.UserName, this._SpiraProject.UserPass, Properties.Resources.Global_ApplicationName); if (CanConnect && !ProcessThread.WantCancel) { //Try connecting to the project, now. if (this._spiraClient.Connection_ConnectToProject(this._SpiraProject.ProjectNum) && !ProcessThread.WantCancel) { //Do they have a root requirement set? Verify it exists. if (this._SpiraProject.RootReq > 0 && !ProcessThread.WantCancel) { this._RootReq = this._spiraClient.Requirement_RetrieveById(this._SpiraProject.RootReq); if (this._RootReq == null) { string ErrorMsg = "Could not access root requirement RQ" + this._SpiraProject.RootReq.ToString(); this.ProgressUpdate(this, new ProgressArgs() { ErrorText = ErrorMsg, Progress = -1, Status = ItemProgress.ProcessStatusEnum.Error, TaskNum = 1 }); return(false); } } else { if (ProcessThread.WantCancel) { this.ProgressUpdate(this, new ProgressArgs() { ErrorText = App.CANCELSTRING, Progress = -1, Status = ItemProgress.ProcessStatusEnum.Error, TaskNum = 1 }); return(false); } } } else { string ErrorMsg = ""; if (ProcessThread.WantCancel) { ErrorMsg = App.CANCELSTRING; } else { ErrorMsg = "Could not access specified SpiraTeam project."; } this.ProgressUpdate(this, new ProgressArgs() { ErrorText = ErrorMsg, Progress = -1, Status = ItemProgress.ProcessStatusEnum.Error, TaskNum = 1 }); return(false); } } else { string ErrorMsg = ""; if (ProcessThread.WantCancel) { ErrorMsg = App.CANCELSTRING; } else { ErrorMsg = "Unable to log into the system."; } this.ProgressUpdate(this, new ProgressArgs() { ErrorText = ErrorMsg, Progress = -1, Status = ItemProgress.ProcessStatusEnum.Error, TaskNum = 1 }); return(false); } this.ProgressUpdate(this, new ProgressArgs() { ErrorText = "", Progress = -1, Status = ItemProgress.ProcessStatusEnum.Success, TaskNum = 1 }); return(true); } catch (Exception ex) { //Log error. streamWriter.WriteLine("Unable to log into SpiraTeam Server: " + ex.Message); string ErrorMsg = "Unable to log into the system:" + Environment.NewLine + ex.Message; this.ProgressUpdate(this, new ProgressArgs() { ErrorText = ErrorMsg, Progress = -1, Status = ItemProgress.ProcessStatusEnum.Error, TaskNum = 1 }); return(false); } }
private bool ConnectToJama(StreamWriter streamWriter, out FinalStatusEnum Status) { Status = FinalStatusEnum.OK; this.ProgressUpdate(this, new ProgressArgs() { ErrorText = "", Progress = -1, Status = ItemProgress.ProcessStatusEnum.Processing, TaskNum = 0 }); streamWriter.WriteLine("Connecting to Jama."); this._jamaClient = new JamaManager(this._JamaProject.ServerURL, this._JamaProject.UserName, this._JamaProject.UserPass); //Try connecting. try { bool CanConnect = this._jamaClient.TestConnection(); if (CanConnect && !ProcessThread.WantCancel) { //Try connecting to the project, now. if (this._jamaClient.GetProject(this._JamaProject.ProjectNum) != null && !ProcessThread.WantCancel) { if (ProcessThread.WantCancel) { this.ProgressUpdate(this, new ProgressArgs() { ErrorText = App.CANCELSTRING, Progress = -1, Status = ItemProgress.ProcessStatusEnum.Error, TaskNum = 0 }); return(false); } } else { string ErrorMsg = ""; if (ProcessThread.WantCancel) { ErrorMsg = App.CANCELSTRING; } else { ErrorMsg = "Could not access specified Jama Contour project."; } this.ProgressUpdate(this, new ProgressArgs() { ErrorText = ErrorMsg, Progress = -1, Status = ItemProgress.ProcessStatusEnum.Error, TaskNum = 0 }); return(false); } } else { string ErrorMsg = ""; if (ProcessThread.WantCancel) { ErrorMsg = App.CANCELSTRING; } else { ErrorMsg = "Unable to log into the system."; } this.ProgressUpdate(this, new ProgressArgs() { ErrorText = ErrorMsg, Progress = -1, Status = ItemProgress.ProcessStatusEnum.Error, TaskNum = 0 }); return(false); } this.ProgressUpdate(this, new ProgressArgs() { ErrorText = "", Progress = -1, Status = ItemProgress.ProcessStatusEnum.Success, TaskNum = 0 }); return(true); } catch (Exception ex) { //Log error. streamWriter.WriteLine("Unable to log into Jama Contour Server: " + ex.Message); string ErrorMsg = "Unable to log into the system:" + Environment.NewLine + ex.Message; this.ProgressUpdate(this, new ProgressArgs() { ErrorText = ErrorMsg, Progress = -1, Status = ItemProgress.ProcessStatusEnum.Error, TaskNum = 0 }); return(false); } }