private static bool TryUpdateTaskRelations(TaskImportManager taskImportManager, CustomFieldDataSet.CustomFieldsRow jiraTaskIdCustomField, IDictionary <int, IEnumerable <int> > jiraTaskRelations) { var taskRelationsUpdater = new TaskRelationsUpdater(jiraTaskIdCustomField); try { ProjectDataSet projectDataSet; if (!taskImportManager.TryGetProjectDataSet(out projectDataSet)) { Console.WriteLine(taskImportManager.GetAllErrors()); return(false); } Guid projectId; var projectDataSetToAdd = taskRelationsUpdater.UpdateRelations(projectDataSet, jiraTaskRelations, out projectId); taskImportManager.MakeChangesInProjectServer(projectId, projectDataSetToAdd, projectDataSet); return(true); } catch (Exception) { Console.WriteLine(taskImportManager.GetAllErrors()); return(false); } }
private static void AddOrUpdateTasks(TaskImportManager taskImportManager, IEnumerable <JiraTaskDto> jiraTaskDtos, CustomFieldDataSet.CustomFieldsRow jiraTaskIdCustomField, CustomFieldDataSet.CustomFieldsRow jiraProjectIdCustomField, CustomFieldDataSet.CustomFieldsRow jiraProjectNameCustomField) { var projectDataSetToAdd = new ProjectDataSet(); ProjectDataSet projectDataSetToUpdate; if (!taskImportManager.TryGetProjectDataSet(out projectDataSetToUpdate)) { Console.WriteLine(taskImportManager.GetAllErrors()); } Guid projectId; var projectTasks = projectDataSetToUpdate.GetExistingTasksByJiraKeys(jiraTaskIdCustomField, out projectId); foreach (var taskDto in jiraTaskDtos) { ProjectDataSet.TaskRow taskRow; if (!projectTasks.TryGetValue(taskDto.Id, out taskRow)) { projectDataSetToAdd.AddNewTask(projectId, jiraProjectIdCustomField.MD_PROP_UID, jiraProjectNameCustomField.MD_PROP_UID, jiraTaskIdCustomField.MD_PROP_UID, taskDto); } else { projectDataSetToUpdate.UpdateTask(projectId, taskRow.TASK_UID, jiraProjectIdCustomField.MD_PROP_UID, jiraProjectNameCustomField.MD_PROP_UID, jiraTaskIdCustomField.MD_PROP_UID, taskDto); } } taskImportManager.MakeChangesInProjectServer(projectId, projectDataSetToAdd, projectDataSetToUpdate); }
public bool TryReadCustomFields(out CustomFieldDataSet.CustomFieldsRow jiraProjectIdCustomField, out CustomFieldDataSet.CustomFieldsRow jiraProjectNameCustomField, out CustomFieldDataSet.CustomFieldsRow jiraTaskIdCustomField) { using (var customFieldsClient = _psiServiceClientFactory.CreateCustomFieldsClient()) { var customFieldDataSet = customFieldsClient.ReadCustomFields(string.Empty, false); jiraProjectIdCustomField = customFieldDataSet.CustomFields.SingleOrDefault(x => x.MD_PROP_NAME == JiraProjectId); jiraProjectNameCustomField = customFieldDataSet.CustomFields.SingleOrDefault(x => x.MD_PROP_NAME == JiraProjectName); jiraTaskIdCustomField = customFieldDataSet.CustomFields.SingleOrDefault(x => x.MD_PROP_NAME == JiraTaskId); if (jiraProjectIdCustomField != null && jiraProjectNameCustomField != null && jiraTaskIdCustomField != null) { return(true); } _errorsContainer.AppendFormat("Custom fields {0} and/or {1} and/or {2} cannot be found", JiraProjectId, JiraProjectName, jiraTaskIdCustomField); return(false); } }
public void CreateProject(string pwaOrigem, string pwaDestino, Guid projectUid) { try { SvcProject.ProjectClient clientProjectOrigem = new SvcProject.ProjectClient(Binding, endPointAdress(pwaOrigem, "/_vti_bin/psi/Workflow.asmx")); clientProjectOrigem.ClientCredentials.Windows.ClientCredential = new NetworkCredential(this.User, this.PassWord, this.Domain); SvcProject.ProjectClient clientProjectDestino = new SvcProject.ProjectClient(Binding, endPointAdress(pwaDestino, "/_vti_bin/psi/Workflow.asmx")); clientProjectDestino.ClientCredentials.Windows.ClientCredential = new NetworkCredential(this.User, this.PassWord, this.Domain); SvcProject.ProjectDataSet dsProject = clientProjectOrigem.ReadProject(projectUid, SvcProject.DataStoreEnum.PublishedStore); SvcProject.ProjectDataSet dsProjectDestino = new SvcProject.ProjectDataSet(); //var projectType = GetEnterpriseProjectTypeList(pwaDestino); var PROJ_UID = Guid.NewGuid(); //informações do projeto foreach (SvcProject.ProjectDataSet.ProjectRow oRow in dsProject.Project.Rows) { SvcProject.ProjectDataSet.ProjectRow oRowDestino = dsProjectDestino.Project.NewProjectRow(); oRowDestino.PROJ_TYPE = (int)PSLibrary.Project.ProjectType.Project; oRowDestino.PROJ_UID = PROJ_UID; oRowDestino.PROJ_NAME = oRow.PROJ_NAME; oRowDestino.WPROJ_DESCRIPTION = oRow.WPROJ_DESCRIPTION; //if (oRow.IsPROJ_PROP_MANAGERNull() || oRow.PROJ_PROP_MANAGER.Length == 0) // oRowDestino.SetPROJ_PROP_MANAGERNull(); //else // oRowDestino.PROJ_PROP_MANAGER = oRow.PROJ_PROP_MANAGER; if (oRow.IsPROJ_PROP_TITLENull() || oRow.PROJ_PROP_TITLE.Length == 0) { oRowDestino.SetPROJ_PROP_TITLENull(); } else { oRowDestino.PROJ_PROP_TITLE = oRow.PROJ_PROP_TITLE; } if (oRow.IsPROJ_PROP_SUBJECTNull() || oRow.PROJ_PROP_SUBJECT.Length == 0) { oRowDestino.SetPROJ_PROP_SUBJECTNull(); } else { oRowDestino.PROJ_PROP_SUBJECT = oRow.PROJ_PROP_SUBJECT; } dsProjectDestino.Project.AddProjectRow(oRowDestino); } DataSet dsCustomField = this.GetCustomfields(pwaDestino, false); DataSet dsLookupTableDestino = this.GetLookupTable(pwaDestino); DataSet dsLookupTableOrigem = this.GetLookupTable(pwaOrigem); /// informações custom fields do projeto foreach (SvcProject.ProjectDataSet.ProjectCustomFieldsRow oRow in dsProject.ProjectCustomFields.Rows) { SvcProject.ProjectDataSet.ProjectCustomFieldsRow oRowDestino = dsProjectDestino.ProjectCustomFields.NewProjectCustomFieldsRow(); CustomFieldDataSet.CustomFieldsRow oRowCustomFieldDestino = (CustomFieldDataSet.CustomFieldsRow)dsCustomField.Tables[0].Select(string.Format("MD_PROP_ID = '{0}'", oRow.MD_PROP_ID)).SingleOrDefault(); if (!oRowCustomFieldDestino.IsMD_PROP_FORMULANull()) { continue; } foreach (DataColumn itemColumn in dsProject.ProjectCustomFields.Columns) { if (!dsProjectDestino.ProjectCustomFields.Columns.Contains(itemColumn.ToString())) { continue; } //if (itemColumn.ColumnName.Equals("CUSTOM_FIELD_UID ")) //{ // oRowDestino[itemColumn.ToString()] = Guid.NewGuid(); // continue; //} if (itemColumn.ColumnName.Equals("PROJ_UID")) { oRowDestino[itemColumn.ToString()] = PROJ_UID; continue; } if (itemColumn.ColumnName.Equals("MD_PROP_ID")) { oRowDestino[itemColumn.ToString()] = oRowCustomFieldDestino.MD_PROP_ID; continue; } if (itemColumn.ColumnName.Equals("MD_PROP_UID")) { oRowDestino[itemColumn.ToString()] = oRowCustomFieldDestino.MD_PROP_UID; continue; } if (itemColumn.ColumnName.Equals("CODE_VALUE") && oRow[itemColumn.ToString()] != null && oRow[itemColumn.ToString()].ToString().Length > 0) { LookupTableDataSet.LookupTableTreesRow ltTreesRowOrigem = (LookupTableDataSet.LookupTableTreesRow)dsLookupTableOrigem.Tables[2].Select(string.Format("LT_STRUCT_UID = '{0}'", oRow[itemColumn.ToString()])).SingleOrDefault(); LookupTableDataSet.LookupTableTreesRow ltTreesRowDestino = (LookupTableDataSet.LookupTableTreesRow)dsLookupTableDestino.Tables[2].Select(string.Format("LT_VALUE_FULL = '{0}'", ltTreesRowOrigem.LT_VALUE_FULL)).FirstOrDefault(); oRowDestino[itemColumn.ToString()] = ltTreesRowDestino.LT_STRUCT_UID; continue; } if (oRow[itemColumn.ToString()] != null && !itemColumn.ReadOnly && oRow[itemColumn.ToString()].ToString().Length > 0) { oRowDestino[itemColumn.ToString()] = oRow[itemColumn.ToString()]; } } dsProjectDestino.ProjectCustomFields.AddProjectCustomFieldsRow(oRowDestino); } /////informações das task do projeto foreach (SvcProject.ProjectDataSet.TaskRow oRow in dsProject.Task.Rows) { SvcProject.ProjectDataSet.TaskRow oRowDestino = dsProjectDestino.Task.NewTaskRow(); foreach (DataColumn itemColumn in dsProject.Task.Columns) { if (!dsProjectDestino.Task.Columns.Contains(itemColumn.ToString())) { continue; } if (itemColumn.ColumnName.Equals("PROJ_UID")) { oRowDestino[itemColumn.ToString()] = PROJ_UID; continue; } if (itemColumn.ToString().Equals("TASK_UID")) { oRowDestino[itemColumn.ToString()] = Guid.NewGuid(); continue; } if (itemColumn.ToString().Equals("TASK_OUTLINE_LEVEL")) { continue; } if (oRow[itemColumn.ToString()] != null) // && !itemColumn.ReadOnly) { oRowDestino[itemColumn.ToString()] = oRow[itemColumn.ToString()]; } } dsProjectDestino.Task.AddTaskRow(oRowDestino); } /////informações customfields da task //foreach (SvcProject.ProjectDataSet.TaskCustomFieldsRow oRow in dsProject.TaskCustomFields.Rows) //{ // SvcProject.ProjectDataSet.TaskCustomFieldsRow oRowDestino = dsProjectDestino.TaskCustomFields.NewTaskCustomFieldsRow(); // foreach (DataColumn itemColumn in dsProject.TaskCustomFields.Columns) // { // if (!dsProjectDestino.TaskCustomFields.Columns.Contains(itemColumn.ToString())) // continue; // if (oRow[itemColumn.ToString()] != null && !itemColumn.ReadOnly) // oRowDestino[itemColumn.ToString()] = oRow[itemColumn.ToString()]; // } // dsProjectDestino.TaskCustomFields.AddTaskCustomFieldsRow(oRowDestino); //} var createJobUid = Guid.NewGuid(); clientProjectDestino.QueueCreateProject(createJobUid, dsProjectDestino, false); var publishJobUid = Guid.NewGuid(); clientProjectDestino.QueuePublish(publishJobUid, PROJ_UID, true, string.Empty); } catch (Exception ex) { throw ex; } }
public TaskRelationsUpdater(CustomFieldDataSet.CustomFieldsRow jiraTaskIdCustomField) { _jiraTaskIdCustomField = jiraTaskIdCustomField; }
public static IDictionary <int, ProjectDataSet.TaskRow> GetExistingTasksByJiraKeys(this ProjectDataSet projectDataSet, CustomFieldDataSet.CustomFieldsRow jiraTaskIdCustomField, out Guid projectId) { projectId = projectDataSet.Project.Single().PROJ_UID; return((from task in projectDataSet.Task join customField in projectDataSet.TaskCustomFields.Where(x => x.MD_PROP_UID == jiraTaskIdCustomField.MD_PROP_UID) on task.TASK_UID equals customField.TASK_UID select new { JiraTaskId = customField != null ? int.Parse(customField.TEXT_VALUE) : 0, Task = task }) .ToDictionary(x => x.JiraTaskId, x => x.Task)); }
protected void Page_Load(object sender, EventArgs e) { //if (!SPContext.Current.Web.Users[HttpContext.Current.User.Identity.Name].IsSiteAdmin) //if (!SPContext.Current.Web.Users[SPContext.Current.Web.CurrentUser.LoginName].IsSiteAdmin) if (!SPContext.Current.Web.UserIsSiteAdmin) { Response.Redirect(SPContext.Current.Site.Url + "/_layouts/accessdenied.aspx"); } //Guid siteGuid = SPContext.Current.Site.ID; SPSecurity.RunWithElevatedPrivileges(delegate() { try { if (!IsPostBack) { using (var connection = new SqlConnection(EPMLiveCore.CoreFunctions.getConnectionString(SPContext.Current.Site.WebApplication.Id))) { connection.Open(); if (Request[TypeParameter] == Type1 || Request[TypeParameter] == Type2) { if (Request["pj"] == Type1) { using (var command = new SqlCommand("SELECT fieldname,displayname from customfields where fieldcategory=@type and pjvisible=0 order by displayname", connection)) { command.Parameters.AddWithValue("@type", Request[TypeParameter]); using (var adapter = new SqlDataAdapter(command)) { var dataSet = new DataSet(); adapter.Fill(dataSet); ListBox1.DataSource = dataSet.Tables[0]; ListBox1.DataTextField = "displayname"; ListBox1.DataValueField = "fieldname"; ListBox1.DataBind(); } } } else { using (var command = new SqlCommand("SELECT fieldname,displayname from customfields where fieldcategory=@type and visible=0 order by displayname", connection)) { command.Parameters.AddWithValue("@type", Request[TypeParameter]); using (var adapter = new SqlDataAdapter(command)) { var dataSet = new DataSet(); adapter.Fill(dataSet); ListBox1.DataSource = dataSet.Tables[0]; ListBox1.DataTextField = "displayname"; ListBox1.DataValueField = "fieldname"; ListBox1.DataBind(); } } } } else if (Request[TypeParameter] == "3") { string modifier = ""; if (Request["pj"] == Type1) { modifier = " pjvisible = 1"; } else { modifier = " visible = 1"; } CustomFields cf = new CustomFields(); cf.Url = SPContext.Current.Site.Url + "/_vti_bin/PSI/customfields.asmx"; cf.UseDefaultCredentials = true; CustomFieldDataSet dsF = cf.ReadCustomFieldsByEntity(new Guid(PSLibrary.EntityCollection.Entities.TaskEntity.UniqueId)); for (int i = 0; i < dsF.CustomFields.Count; i++) { CustomFieldDataSet.CustomFieldsRow customField = dsF.CustomFields[i]; using (var command = new SqlCommand("SELECT fieldname from customfields where fieldname=@fieldname and " + modifier, connection)) { command.Parameters.AddWithValue("@fieldname", customField.MD_PROP_ID.ToString()); using (var reader = command.ExecuteReader()) { if (!reader.Read()) { var table = string.Empty; try { table = customField.MD_LOOKUP_TABLE_UID.ToString(); } catch (Exception ex) { SystemTrace.WriteLine(ex.ToString()); } var cfData = string.Empty; var choice = "CHOICE"; if (table == string.Empty) { choice = ((PSLibrary.PropertyType)customField.MD_PROP_TYPE_ENUM).ToString(); } if (customField.IsMD_PROP_FORMULANull()) { cfData = $"{customField.MD_PROP_ID}#{choice}#{customField.MD_PROP_UID_SECONDARY}#{customField.MD_PROP_UID_SECONDARY}"; } else { cfData = customField.MD_PROP_ID + "#" + choice + "#" + customField.MD_PROP_UID_SECONDARY + "#"; } var listItem = new ListItem(customField.MD_PROP_NAME, cfData); ListBox1.Items.Add(listItem); } } } } } else if (Request[TypeParameter] == "4") { string modifier = string.Empty; if (Request["pj"] == Type1) { modifier = " pjvisible = 1"; } else { modifier = " visible = 1"; } var cf = new CustomFields(); cf.Url = SPContext.Current.Site.Url + "/_vti_bin/PSI/customfields.asmx"; cf.UseDefaultCredentials = true; CustomFieldDataSet dsF = cf.ReadCustomFieldsByEntity(new Guid(PSLibrary.EntityCollection.Entities.ProjectEntity.UniqueId)); for (int i = 0; i < dsF.CustomFields.Count; i++) { CustomFieldDataSet.CustomFieldsRow customField = dsF.CustomFields[i]; using (var command = new SqlCommand("SELECT fieldname from customfields where fieldname=@fieldname and " + modifier, connection)) { command.Parameters.AddWithValue("@fieldname", customField.MD_PROP_ID.ToString()); using (var reader = command.ExecuteReader()) { if (!reader.Read()) { var table = string.Empty; try { table = customField.MD_LOOKUP_TABLE_UID.ToString(); } catch (Exception ex) { SystemTrace.WriteLine(ex.ToString()); } var cfData = string.Empty; if (table == string.Empty) { cfData = customField.MD_PROP_ID + "#" + ((PSLibrary.PropertyType)customField.MD_PROP_TYPE_ENUM).ToString() + "##"; } else { cfData = customField.MD_PROP_ID + "#CHOICE##"; } var listItem = new ListItem(customField.MD_PROP_NAME, cfData); ListBox1.Items.Add(listItem); } } } } } } } } catch (Exception ex) { Response.Write(ex.Message); SystemTrace.WriteLine(ex.ToString()); } }); }