Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
        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());
                }
            });
        }