protected void Page_Load(object sender, EventArgs e)
        {
            EPMLiveEnterprise.ProjectWorkspaceSynch pws = new ProjectWorkspaceSynch(SPContext.Current.Site.ID, SPContext.Current.Web.Url, new Guid(), SPContext.Current.Web.CurrentUser.LoginName);
            pws.processProjectCenter();
            pws.processTaskCenter();

            Page.RegisterStartupScript("Alert", "<script language=\"javascript\">alert('All fields have been synchronize');location.href='../settings.aspx';</script>");
        }
        private string ProcessSite(
            SPSite site,
            int siteCount,
            SqlConnection connection,
            Guid timerJobGuid,
            string siteGuidValue,
            string username,
            double percentageFactor)
        {
            var resultBuilder = new StringBuilder();

            resultBuilder.Append($"Site: {site.RootWeb.Title} ({site.Url})<br>");

            var counter   = 0d;
            var percent   = 0d;
            var totalWebs = (double)site.AllWebs.Count;

            foreach (SPWeb web in site.AllWebs)
            {
                resultBuilder.Append($"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Web: {web.Title} ({web.Url})<br>");

                var projWorkspaceSync = new ProjectWorkspaceSynch(new Guid(siteGuidValue), web.Url, Guid.Empty, username);
                projWorkspaceSync.processProjectCenter();
                projWorkspaceSync.processTaskCenter();
                counter++;

                var newPercent = (counter / totalWebs / siteCount + percentageFactor) * 100;
                if (newPercent >= percent + 5)
                {
                    percent = newPercent;

                    var commandText = string.Format(CmdTextUpdatePercentageTemplate, newPercent, timerJobGuid);
                    using (var command = new SqlCommand(commandText, connection))
                    {
                        command.ExecuteNonQuery();
                    }
                }
            }

            return(resultBuilder.ToString());
        }
        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);
            }
        }