public string VerifyPDPExist(string pwaOrigem, string pwaDestino, Guid EPT_UID) { SvcWorkflow.WorkflowClient clientWorkflowOrigem = new SvcWorkflow.WorkflowClient(Binding, endPointAdress(pwaOrigem, "/_vti_bin/psi/Workflow.asmx")); clientWorkflowOrigem.ClientCredentials.Windows.ClientCredential = new NetworkCredential(this.User, this.PassWord, this.Domain); SvcWorkflow.WorkflowClient clientWorkflowDestino = new SvcWorkflow.WorkflowClient(Binding, endPointAdress(pwaDestino, "/_vti_bin/psi/Workflow.asmx")); clientWorkflowDestino.ClientCredentials.Windows.ClientCredential = new NetworkCredential(this.User, this.PassWord, this.Domain); SvcWorkflow.WorkflowDataSet dsEnterpriseOrigem = clientWorkflowOrigem.ReadEnterpriseProjectType(EPT_UID); SvcWorkflow.WorkflowDataSet dsEnterpriseDestino = clientWorkflowDestino.ReadEnterpriseProjectTypeList(); string PDPs = string.Empty; foreach (DataRow item in dsEnterpriseOrigem.EnterpriseProjectTypePDPs.Rows) { var oRowPDP = dsEnterpriseDestino.EnterpriseProjectTypePDPs.Select(string.Format("PDP_NAME = '{0}'", item["PDP_NAME"].ToString())).FirstOrDefault(); if (oRowPDP == null) { PDPs += item["PDP_NAME"].ToString() + ","; } } if (PDPs.Length == 0) { return(string.Empty); } return(PDPs.Substring(0, PDPs.Length - 1)); }
/// <summary> /// Busca lista WorkFlowDataSet /// </summary> /// <param name="pwaUrl">url do pwa</param> /// <returns></returns> public SvcWorkflow.WorkflowDataSet GetEnterpriseProjectTypeList(string pwaUrl) { //SvcProject.ProjectClient clientProject = new SvcProject.ProjectClient(Binding, endPointAdress(pwaUrl, "/_vti_bin/psi/Project.asmx")); SvcWorkflow.WorkflowClient clientWorkflow = new SvcWorkflow.WorkflowClient(Binding, endPointAdress(pwaUrl, "/_vti_bin/psi/Workflow.asmx")); clientWorkflow.ClientCredentials.Windows.ClientCredential = new NetworkCredential(this.User, this.PassWord, this.Domain); //clientLogin.ClientCredentials.Windows.ClientCredential = new NetworkCredential(this.User, this.PassWord, this.Domain); return(clientWorkflow.ReadEnterpriseProjectTypeList()); }
// Set the PSI client endpoints programmatically; don't use app.config. public static bool SetClientEndpointsProg(string pwaUrl) { const int MAXSIZE = int.MaxValue; const string SVC_ROUTER = "/_vti_bin/PSI/ProjectServer.svc"; bool isHttps = pwaUrl.ToLower().StartsWith("https"); bool result = true; BasicHttpBinding binding = null; try { if (isHttps) { // Create a binding for HTTPS.TimesheetL binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); } else { // Create a binding for HTTP. binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly); } binding.Name = "basicHttpConf"; binding.MessageEncoding = WSMessageEncoding.Text; binding.CloseTimeout = new TimeSpan(00, 05, 00); binding.OpenTimeout = new TimeSpan(00, 05, 00); binding.ReceiveTimeout = new TimeSpan(00, 05, 00); binding.SendTimeout = new TimeSpan(00, 05, 00); binding.TextEncoding = System.Text.Encoding.UTF8; // If the TransferMode is buffered, the MaxBufferSize and // MaxReceived MessageSize must be the same value. binding.TransferMode = TransferMode.Buffered; binding.MaxBufferSize = MAXSIZE; binding.MaxReceivedMessageSize = MAXSIZE; binding.MaxBufferPoolSize = MAXSIZE; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm; binding.GetType().GetProperty("ReaderQuotas").SetValue(binding, XmlDictionaryReaderQuotas.Max, null); // The endpoint address is the ProjectServer.svc router for all public PSI calls. EndpointAddress address = new EndpointAddress(pwaUrl + SVC_ROUTER); adminClient = new SvcAdmin.AdminClient(binding, address); adminClient.ChannelFactory.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; adminClient.ChannelFactory.Credentials.Windows.AllowNtlm = true; projectClient = new SvcProject.ProjectClient(binding, address); projectClient.ChannelFactory.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; projectClient.ChannelFactory.Credentials.Windows.AllowNtlm = true; queueSystemClient = new SvcQueueSystem.QueueSystemClient(binding, address); queueSystemClient.ChannelFactory.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; queueSystemClient.ChannelFactory.Credentials.Windows.AllowNtlm = true; resourceClient = new SvcResource.ResourceClient(binding, address); resourceClient.ChannelFactory.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; resourceClient.ChannelFactory.Credentials.Windows.AllowNtlm = true; lookupTableClient = new SvcLookupTable.LookupTableClient(binding, address); lookupTableClient.ChannelFactory.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; lookupTableClient.ChannelFactory.Credentials.Windows.AllowNtlm = true; customFieldsClient = new SvcCustomFields.CustomFieldsClient(binding, address); customFieldsClient.ChannelFactory.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; customFieldsClient.ChannelFactory.Credentials.Windows.AllowNtlm = true; calendarClient = new SvcCalendar.CalendarClient(binding, address); calendarClient.ChannelFactory.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; calendarClient.ChannelFactory.Credentials.Windows.AllowNtlm = true; archiveClient = new SvcArchive.ArchiveClient(binding, address); archiveClient.ChannelFactory.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; archiveClient.ChannelFactory.Credentials.Windows.AllowNtlm = true; pwaClient = new SvcStatusing.StatusingClient(binding, address); pwaClient.ChannelFactory.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; pwaClient.ChannelFactory.Credentials.Windows.AllowNtlm = true; timesheetClient = new SvcTimeSheet.TimeSheetClient(binding, address); timesheetClient.ChannelFactory.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; timesheetClient.ChannelFactory.Credentials.Windows.AllowNtlm = true; queueClient = new SvcQueueSystem.QueueSystemClient(binding, address); queueClient.ChannelFactory.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; queueClient.ChannelFactory.Credentials.Windows.AllowNtlm = true; workFlowClient = new SvcWorkflow.WorkflowClient(binding, address); workFlowClient.ChannelFactory.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; workFlowClient.ChannelFactory.Credentials.Windows.AllowNtlm = true; } catch (Exception ex) { result = false; } return result; }
public void CreateEnterpriseProjectType(string pwaOrigem, string pwaDestino, string nameProjecType, Guid Uid) { //SvcWorkflow.WorkflowDataSet.EnterpriseProjectTypeDataTable dt = new SvcWorkflow.WorkflowDataSet.EnterpriseProjectTypeDataTable(); try { SvcWorkflow.WorkflowClient clientWorkflowOrigem = new SvcWorkflow.WorkflowClient(Binding, endPointAdress(pwaOrigem, "/_vti_bin/psi/Workflow.asmx")); clientWorkflowOrigem.ClientCredentials.Windows.ClientCredential = new NetworkCredential(this.User, this.PassWord, this.Domain); SvcWorkflow.WorkflowClient clientWorkflowDestino = new SvcWorkflow.WorkflowClient(Binding, endPointAdress(pwaDestino, "/_vti_bin/psi/Workflow.asmx")); clientWorkflowDestino.ClientCredentials.Windows.ClientCredential = new NetworkCredential(this.User, this.PassWord, this.Domain); SvcWorkflow.WorkflowDataSet dsEnterpriseOrigem = clientWorkflowOrigem.ReadEnterpriseProjectType(Uid); SvcWorkflow.WorkflowDataSet dsEnterpriseDestino = new SvcWorkflow.WorkflowDataSet(); SvcWorkflow.WorkflowDataSet dsEnterpriseDestino2 = clientWorkflowDestino.ReadEnterpriseProjectTypeList(); //SvcWorkflow.WorkflowDataSet.EnterpriseProjectTypePDPsDataTable dtPDP = clientWorkflowOrigem.read Guid ENTERPRISE_PROJECT_TYPE_UID = Guid.Empty; foreach (SvcWorkflow.WorkflowDataSet.EnterpriseProjectTypeRow itemEnterprise in dsEnterpriseOrigem.EnterpriseProjectType.Rows) { SvcWorkflow.WorkflowDataSet.EnterpriseProjectTypeRow oRow = dsEnterpriseDestino.EnterpriseProjectType.NewEnterpriseProjectTypeRow(); foreach (DataColumn itemColumn in dsEnterpriseOrigem.EnterpriseProjectType.Columns) { if (!dsEnterpriseDestino.EnterpriseProjectType.Columns.Contains(itemColumn.ToString())) { continue; } if (itemColumn.ToString().Equals("WORKFLOW_ASSOCIATION_UID") || itemColumn.ToString().Equals("WORKFLOW_ASSOCIATION_NAME")) { continue; } var dnsEquals = GetDnsName(pwaOrigem) == GetDnsName(pwaDestino); if (nameProjecType.Length > 0 && itemColumn.ToString().Equals("ENTERPRISE_PROJECT_TYPE_NAME")) { oRow[itemColumn.ToString()] = nameProjecType; continue; } if (itemColumn.ToString().Equals("ENTERPRISE_PROJECT_TYPE_UID")) { ENTERPRISE_PROJECT_TYPE_UID = Guid.Parse(itemEnterprise[itemColumn.ToString()].ToString()); } if (itemColumn.ToString().Equals("ENTERPRISE_PROJECT_TYPE_UID") && dnsEquals) { ENTERPRISE_PROJECT_TYPE_UID = Guid.NewGuid(); oRow[itemColumn.ToString()] = ENTERPRISE_PROJECT_TYPE_UID; continue; } if (itemColumn.ToString().Equals("ENTERPRISE_PROJECT_WORKSPACE_TEMPLATE_NAME")) { oRow[itemColumn.ToString()] = "ProjectSite#0"; continue; } if (itemColumn.ToString().Equals("ENTERPRISE_PROJECT_TYPE_IMAGE_URL")) { oRow[itemColumn.ToString()] = string.Format("/_layouts/15/inc/{0}/images/CenterNormalProject.png", GetPwaName(pwaDestino).Replace("/", string.Empty)); continue; } //EnterpriseProjectTypeInvalidWorkspaceTemplateName if (itemEnterprise[itemColumn.ToString()] != null && !itemColumn.ReadOnly) { oRow[itemColumn.ToString()] = itemEnterprise[itemColumn.ToString()]; } } dsEnterpriseDestino.EnterpriseProjectType.AddEnterpriseProjectTypeRow(oRow); //dsWorkflow.EnterpriseProjectType.AddEnterpriseProjectTypeRow(oRow); } foreach (SvcWorkflow.WorkflowDataSet.EnterpriseProjectTypePDPsRow itemPDPs in dsEnterpriseOrigem.EnterpriseProjectTypePDPs.Rows) { SvcWorkflow.WorkflowDataSet.EnterpriseProjectTypePDPsRow oRowPDP = dsEnterpriseDestino.EnterpriseProjectTypePDPs.NewEnterpriseProjectTypePDPsRow(); foreach (DataColumn itemColumn in dsEnterpriseOrigem.EnterpriseProjectTypePDPs.Columns) { if (itemColumn.ToString().Equals("PDP_UID")) { continue; } if (itemColumn.ToString().Equals("PDP_NAME")) { var oDataRow = dsEnterpriseDestino2.EnterpriseProjectTypePDPs.Select(string.Format("PDP_NAME = '{0}'", itemPDPs[itemColumn.ToString()])).FirstOrDefault(); if (oDataRow != null) { oRowPDP["PDP_UID"] = oDataRow["PDP_UID"]; } else { var oDataRow2 = dsEnterpriseDestino2.EnterpriseProjectTypePDPs.Select().FirstOrDefault(); oRowPDP["PDP_UID"] = oDataRow2["PDP_UID"]; } } if (itemColumn.ToString().Equals("ENTERPRISE_PROJECT_TYPE_UID")) { oRowPDP[itemColumn.ToString()] = ENTERPRISE_PROJECT_TYPE_UID; continue; } if (itemPDPs[itemColumn.ToString()] != null && !itemColumn.ReadOnly) { oRowPDP[itemColumn.ToString()] = itemPDPs[itemColumn.ToString()]; } } dsEnterpriseDestino.EnterpriseProjectTypePDPs.AddEnterpriseProjectTypePDPsRow(oRowPDP); } //dsWorkflow.EnterpriseProjectType.AcceptChanges(); //dsWorkflow.EnterpriseProjectTypePDPs.AcceptChanges(); clientWorkflowDestino.CreateEnterpriseProjectType(dsEnterpriseDestino); } catch (SoapException ex) { string errMess = ""; // Pass the exception to the PSClientError constructor to // get all error information. PSLibrary.PSClientError psiError = new PSLibrary.PSClientError(ex); PSLibrary.PSErrorInfo[] psiErrors = psiError.GetAllErrors(); for (int j = 0; j < psiErrors.Length; j++) { errMess += psiErrors[j].ErrId.ToString() + "\n"; } errMess += "\n" + ex.Message.ToString(); MessageBox.Show(errMess); // Send error string to console or message box. } catch (Exception ex) { throw ex; } }