Esempio n. 1
0
        public void HandleWSSUpdate(Microsoft.Office.Project.Server.Library.PSContextInfo contextInfo, string acceptdecline, Guid assnid, Guid projectid)
        {
            try
            {
                string thenotes = "";

                SPSite site = new SPSite(contextInfo.SiteGuid);

                Guid   trackingGuid = Guid.NewGuid();
                string lcid         = "1033";
                StatusingDerived.SetImpersonationContext(true, contextInfo.UserName, contextInfo.UserGuid, trackingGuid, contextInfo.SiteGuid, lcid);
                StatusingDerived statusing = new StatusingDerived();
                statusing.Url = site.Url + "/_vti_bin/psi/statusing.asmx";

                WebSvcStatusing.StatusingDataSet ds = statusing.ReadStatus(assnid, DateTime.MinValue, DateTime.MaxValue);

                //Guid userguid = new Guid(ds.Tables[0].Rows[0]["RES_UID"].ToString());

                DataTable dt     = ds.Tables["Tasks"];
                string    taskid = "";
                foreach (DataRow dr in dt.Rows)
                {
                    taskid = dr["Task_Published_UID"].ToString();
                    break;
                }

                WebSvcStatusing.StatusApprovalDataSet statusingDs2 = statusing.ReadStatusApprovalsInProcess(contextInfo.UserGuid);
                WebSvcStatusing.StatusApprovalDataSet.StatusApprovalsRow[] statusingRow = (WebSvcStatusing.StatusApprovalDataSet.StatusApprovalsRow[])statusingDs2.Tables[0].Select("ASSN_UID = '" + assnid + "'");

                if (statusingRow.Length > 0)
                {
                    string impersonateuser = GetWindowsAccountByResGUID(statusingRow[0].RES_UID.ToString(), contextInfo, site.Url);

                    //impersonate
                    Guid   trackingGuid2 = Guid.NewGuid();
                    string lcid2         = "1033";
                    StatusingDerived.SetImpersonationContext(true, impersonateuser, statusingRow[0].RES_UID, trackingGuid2, contextInfo.SiteGuid, lcid2);
                    //StatusingDerived statusing2 = new StatusingDerived();
                    //statusing2.Url = site.Url + "/_vti_bin/psi/statusing.asmx";
                    WebSvcStatusing.AssnHistoryDataSet statusingDs4             = statusing.ReadAssignmentHistory(statusingRow[0].ASSN_TRANS_UID, WebSvcStatusing.AssnHistoryItemType.SingleTransaction);
                    WebSvcStatusing.AssnHistoryDataSet.HistoryRow[] historyRows = (WebSvcStatusing.AssnHistoryDataSet.HistoryRow[])statusingDs4.Tables[0].Select("ASSN_TRANS_UID = '" + statusingRow[0].ASSN_TRANS_UID + "'");

                    foreach (WebSvcStatusing.AssnHistoryDataSet.HistoryRow row in historyRows)
                    {
                        if ((int)row.ASSN_TRANS_COMMENT_TYPE_ENUM == 1 || (int)row.ASSN_TRANS_COMMENT_TYPE_ENUM == 2) //1=Accepted, 2=Rejected
                        {
                            thenotes = row.ASSN_TRANS_COMMENT.ToString();

                            string publishSiteUrl = RetrieveWebURL(projectid.ToString(), contextInfo.SiteGuid);

                            SPSite mySite = new SPSite(contextInfo.SiteGuid);

                            int indSlash = publishSiteUrl.IndexOf("/", 9);
                            publishSiteUrl = publishSiteUrl.Substring(indSlash);

                            SPWeb myWeb = mySite.OpenWeb(publishSiteUrl);
                            //Impersonate the Project Manager
                            SPUser user = myWeb.AllUsers[getResourceUsername(mySite.Url, getProjectOwner(mySite.Url, projectid))];

                            SPUserToken token = user.UserToken;
                            //reopen the web with the new user credentials
                            mySite = new SPSite(mySite.ID, token);

                            myWeb = mySite.OpenWeb(publishSiteUrl);

                            myWeb.AllowUnsafeUpdates = true;
                            SPList  taskList    = myWeb.Lists["Task Center"];
                            SPQuery queryFilter = new SPQuery();

                            queryFilter.Query = "<Where><Eq><FieldRef Name='taskuid'/><Value Type='Text'><![CDATA[" + taskid + "." + assnid.ToString() + "]]></Value></Eq></Where>";

                            Guid CommentsFieldId = taskList.Fields.GetFieldByInternalName("Publisher_x0020_Approval_x0020_C").Id;
                            Guid StatusFieldId   = taskList.Fields.GetFieldByInternalName("Publisher_x0020_Approval_x0020_S").Id;

                            foreach (SPListItem item in taskList.GetItems(queryFilter))
                            {
                                item[CommentsFieldId] = thenotes;
                                item[StatusFieldId]   = acceptdecline;
                                item.Update();
                            }

                            myWeb.Close();
                            mySite.Close();
                        }
                    }
                }
            }
            catch (System.Web.Services.Protocols.SoapException ex1)
            {
                string logEntry = "Soap Error: " + ex1.Message + ex1.Detail;
                ErrorTrap(3001, logEntry);
            }
            catch (Exception ex)
            {
                string logEntry = "Error: " + ex.Message + ex.StackTrace;
                ErrorTrap(3000, logEntry);
            }
        }
        private void UpdatePublisherCheckPercentCompleteFive(int pubType, DateTime dtStart)
        {
            if (dtStart == null)
            {
                throw new ArgumentNullException(nameof(dtStart));
            }

            using (var pubSite = new SPSite(publishSiteUrl))
            {
                mySiteToPublish = pubSite.OpenWeb();

                pCf = new CustomFields
                {
                    Url = $"{mySite.Url}/_vti_bin/psi/customfields.asmx",
                    UseDefaultCredentials = true
                };
                cfDs = new CustomFieldDataSet();

                psiLookupTable = new LookupTable
                {
                    Url = $"{mySite.Url}/_vti_bin/psi/lookuptable.asmx",
                    UseDefaultCredentials = true
                };

                pResource = new Resource
                {
                    Url = $"{mySite.Url}/_vti_bin/psi/resource.asmx",
                    UseDefaultCredentials = true
                };

                pService = new Project
                {
                    Url = $"{mySite.Url}/_vti_bin/psi/project.asmx",
                    UseDefaultCredentials = true
                };

                Statusing = new Statusing
                {
                    Url = $"{mySite.Url}/_vti_bin/psi/statusing.asmx",
                    UseDefaultCredentials = true
                };

                pWssInterop = new WssInterop
                {
                    Url = $"{mySite.Url}/_vti_bin/psi/wssinterop.asmx",
                    UseDefaultCredentials = true
                };

                linkProjectWss();

                var          trackingGuid = Guid.NewGuid();
                const string Lcid         = "1033";
                StatusingDerived.SetImpersonationContext(true, contextInfo.UserName, contextInfo.UserGuid, trackingGuid, contextInfo.SiteGuid, Lcid);

                workspaceSynch = new ProjectWorkspaceSynch(mySiteGuid, publishSiteUrl, projectGuid, contextInfo.UserName);
                workspaceSynch.setUpGroups();
                workspaceSynch.processTaskCenter();
                workspaceSynch.processProjectCenter();
                workspaceSynch.processResources();

                using (var sqlCommand1 = new SqlCommand(
                           "UPDATE publishercheck set percentcomplete=5,laststatusdate=getdate() where projectguid=@projectguid",
                           cn))
                {
                    sqlCommand1.Parameters.AddWithValue("@projectguid", eventArgs.ProjectGuid);
                    sqlCommand1.ExecuteNonQuery();
                }

                loadFields();

                LoadCurrentTasks(pubType, dtStart);
            }
        }