public ResourceSyncher(Guid siteId)
        {
            siteGuid = siteId;
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(siteGuid))
                {
                    pCf     = new WebSvcCustomFields.CustomFields();
                    pCf.Url = site.Url + "/_vti_bin/psi/customfields.asmx";
                    pCf.UseDefaultCredentials = true;
                    cfDs = new WebSvcCustomFields.CustomFieldDataSet();
                    cfDs = pCf.ReadCustomFieldsByEntity(resEntity);

                    psiLookupTable     = new WebSvcLookupTables.LookupTable();
                    psiLookupTable.Url = site.Url + "/_vti_bin/psi/lookuptable.asmx";
                    psiLookupTable.UseDefaultCredentials = true;

                    pResource     = new WebSvcResource.Resource();
                    pResource.Url = site.Url + "/_vti_bin/psi/resource.asmx";
                    pResource.UseDefaultCredentials = true;

                    //SPSecurity.RunWithElevatedPrivileges(delegate()
                    //{

                    cn = new SqlConnection(EPMLiveCore.CoreFunctions.getConnectionString(site.WebApplication.Id));
                    cn.Open();

                    //});
                }
            });
        }
Example #2
0
        public ProjectWorkspaceSynch(Guid projectSiteGuid, string webUrl, Guid projectGuid, string username)
        {
            try
            {
                _username = username;

                mySite = new SPSite(projectSiteGuid);
                mySite.AllowUnsafeUpdates = true;

                cn = new SqlConnection(EPMLiveCore.CoreFunctions.getConnectionString(mySite.WebApplication.Id));
                cn.Open();

                mySiteToPublish = new SPSite(webUrl);
                myWebToPublish  = mySiteToPublish.OpenWeb();
                myWebToPublish.AllowUnsafeUpdates = true;

                pCf     = new WebSvcCustomFields.CustomFields();
                pCf.Url = mySite.Url + "/_vti_bin/psi/customfields.asmx";
                pCf.UseDefaultCredentials = true;

                psiLookupTable     = new WebSvcLookupTables.LookupTable();
                psiLookupTable.Url = mySite.Url + "/_vti_bin/psi/lookuptable.asmx";
                psiLookupTable.UseDefaultCredentials = true;

                psiProject     = new WebSvcProject.Project();
                psiProject.Url = mySite.Url + "/_vti_bin/psi/project.asmx";
                psiProject.UseDefaultCredentials = true;

                psiResource     = new WebSvcResource.Resource();
                psiResource.Url = mySite.Url + "/_vti_bin/psi/resource.asmx";
                psiResource.UseDefaultCredentials = true;

                projectUid = projectGuid;
            }
            catch (Exception ex)
            {
                myLog.WriteEntry("Error Loading Workspace Synch: " + ex.Message + ex.StackTrace, EventLogEntryType.Error, 401);
            }
        }
        private void loadEnterpriseFields()
        {
            Guid siteGuid = SPContext.Current.Site.ID;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = SPContext.Current.Site)
                {
                    try
                    {
                        WebSvcCustomFields.CustomFields cf = new WebSvcCustomFields.CustomFields();
                        cf.Url = SPContext.Current.Site.Url + "/_vti_bin/PSI/customfields.asmx";
                        cf.UseDefaultCredentials = true;

                        WebSvcCustomFields.CustomFieldDataSet dsF = cf.ReadCustomFieldsByEntity(new Guid(PSLibrary.EntityCollection.Entities.TaskEntity.UniqueId));

                        ddlAssignedToField.Items.Add(new ListItem("[Not Specified]", ""));
                        ddlTimesheet.Items.Add(new ListItem("[Select Field]", ""));
                        ddlTimesheetHours.Items.Add(new ListItem("[Select Field]", ""));

                        foreach (DataRow dr in dsF.Tables[0].Select("MD_PROP_TYPE_ENUM = 21"))
                        {
                            ListItem li = new ListItem(dr["MD_PROP_NAME"].ToString(), dr["MD_PROP_UID"].ToString());
                            ddlAssignedToField.Items.Add(li);
                        }

                        foreach (DataRow dr in dsF.Tables[0].Select("MD_PROP_TYPE_ENUM = 15"))
                        {
                            ListItem li = new ListItem(dr["MD_PROP_NAME"].ToString(), dr["MD_PROP_ID"].ToString());
                            ddlTimesheetHours.Items.Add(li);
                        }

                        foreach (DataRow dr in dsF.Tables[0].Select("MD_PROP_TYPE_ENUM = 17"))
                        {
                            ListItem li = new ListItem(dr["MD_PROP_NAME"].ToString(), dr["MD_PROP_UID"].ToString());
                            ddlTimesheet.Items.Add(li);
                        }

                        ddlTimesheetHours.Items.Add(new ListItem("Actual Work", "251658250"));

                        using (var connection = new SqlConnection(CoreFunctions.getConnectionString(site.WebApplication.Id)))
                        {
                            connection.Open();

                            using (var command = new SqlCommand("SELECT config_value FROM ECONFIG where config_name='AssignedToField'", connection))
                                using (var reader = command.ExecuteReader())
                                {
                                    if (reader.Read())
                                    {
                                        ddlAssignedToField.SelectedValue = reader.GetString(0);
                                    }
                                }

                            using (var command = new SqlCommand("SELECT config_value FROM ECONFIG where config_name='TimesheetField'", connection))
                                using (var reader = command.ExecuteReader())
                                {
                                    if (reader.Read())
                                    {
                                        ddlTimesheet.SelectedValue = reader.GetString(0);
                                    }
                                }

                            using (var command = new SqlCommand("SELECT config_value FROM ECONFIG where config_name='TimesheetHoursField'", connection))
                                using (var reader = command.ExecuteReader())
                                {
                                    if (reader.Read())
                                    {
                                        ddlTimesheetHours.SelectedValue = reader.GetString(0);
                                    }
                                }

                            using (var command = new SqlCommand("SELECT config_value FROM ECONFIG where config_name='LockSynch'", connection))
                                using (var reader = command.ExecuteReader())
                                {
                                    if (reader.Read())
                                    {
                                        chkLockSynch.Checked = bool.Parse(reader.GetString(0));
                                    }
                                }

                            using (var command = new SqlCommand("SELECT config_value FROM ECONFIG where config_name='ForceWS'", connection))
                                using (var reader = command.ExecuteReader())
                                {
                                    if (reader.Read())
                                    {
                                        chkForceWS.Checked = bool.Parse(reader.GetString(0));
                                    }
                                }

                            using (var command = new SqlCommand("SELECT config_value FROM ECONFIG where config_name='ValidTemplates'", connection))
                                using (var reader = command.ExecuteReader())
                                {
                                    if (reader.Read())
                                    {
                                        loadTemplates(reader.GetString(0));
                                    }
                                    else
                                    {
                                        loadTemplates(string.Empty);
                                    }
                                }

                            using (var command = new SqlCommand("SELECT config_value FROM ECONFIG where config_name='CrossSite'", connection))
                                using (var reader = command.ExecuteReader())
                                {
                                    if (reader.Read())
                                    {
                                        chkCrossSite.Checked = bool.Parse(reader.GetString(0));
                                    }
                                }

                            using (var command = new SqlCommand("SELECT config_value FROM ECONFIG where config_name='DefaultURL'", connection))
                                using (var reader = command.ExecuteReader())
                                {
                                    if (reader.Read())
                                    {
                                        txtDefaultURL.Text = reader.GetString(0);
                                    }
                                }

                            using (var command = new SqlCommand("SELECT config_value FROM ECONFIG where config_name='ConnectedURLs'", connection))
                                using (var reader = command.ExecuteReader())
                                {
                                    if (reader.Read())
                                    {
                                        txtUrls.Text = reader.GetString(0);
                                    }
                                }
                        }

                        lblError.Visible = false;

                        WebSvcEvents.Events events = new EPMLiveEnterprise.WebSvcEvents.Events();
                        events.Url = SPContext.Current.Site.Url + "/_vti_bin/psi/events.asmx";
                        events.UseDefaultCredentials = true;

                        WebSvcEvents.EventHandlersDataSet ds = events.ReadEventHandlerAssociations();

                        if (ds.EventHandlers.Select("EventId = 53 and name = 'EPMLivePublisher'").Length <= 0)
                        {
                            lblProjectPublished.Text = "Not Installed";
                        }
                        else
                        {
                            lblProjectPublished.Text = "Installed";
                        }

                        if (ds.EventHandlers.Select("EventId = 133 and name = 'EPMLiveStatusing'").Length <= 0)
                        {
                            lblStatusingApplied.Text = "Not Installed";
                        }
                        else
                        {
                            lblStatusingApplied.Text = "Installed";
                        }

                        if (ds.EventHandlers.Select("EventId = 95 and name = 'EPMLiveResUpdated'").Length <= 0)
                        {
                            lblResUpdated.Text = "Not Installed";
                        }
                        else
                        {
                            lblResUpdated.Text = "Installed";
                        }

                        if (ds.EventHandlers.Select("EventId = 89 and name = 'EPMLiveResCreated'").Length <= 0)
                        {
                            lblResCreated.Text = "Not Installed";
                        }
                        else
                        {
                            lblResCreated.Text = "Installed";
                        }

                        if (ds.EventHandlers.Select("EventId = 92 and name = 'EPMLiveResDeleting'").Length <= 0)
                        {
                            lblResDeleted.Text = "Not Installed";
                        }
                        else
                        {
                            lblResDeleted.Text = "Installed";
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message.Contains("401"))
                        {
                            lblError.Text    = "Error: 401 Unauthorized<br>This usually means the service account that is current running your SharePoint Application Pool does not have access to the Project Server Site.";
                            lblError.Visible = true;
                        }
                        else
                        {
                            Response.Write("Error: " + ex.Message + "<br>Current User: " + HttpContext.Current.User.Identity.Name);
                        }
                    }
                }
            });
        }