Exemple #1
0
        public void execute(SPSite site, SPWeb web, string data)
        {
            EPMData epmdata = null;

            try
            {
                epmdata = new EPMData(site.ID);

                ProcessSecurity.ProcessSecurityGroups(site, epmdata.GetClientReportingConnection, data);
            }
            catch { }
            finally
            {
                if (epmdata != null)
                {
                    epmdata.Dispose();
                }
                if (web != null)
                {
                    web.Dispose();
                }
                if (site != null)
                {
                    site.Dispose();
                }
                data = null;
            }
        }
 public void TestInitialize()
 {
     _testEntity            = new ProcessSecurity();
     _testEntityPrivate     = new PrivateObject(_testEntity);
     _testEntityPrivateType = new PrivateType(typeof(ProcessSecurity));
     _shimsContext          = ShimsContext.Create();
     _adoShims = AdoShims.ShimAdoNetCalls();
     _spShims  = SharepointShims.ShimSharepointCalls();
 }
        internal static void InitializeProcessSecurity()
        {
            Exception       workerThreadException = null;
            ProcessSecurity security = new ProcessSecurity();
            Thread          thread   = new Thread(new ThreadStart(security.Initialize));

            security.exceptionNotification = (ExceptionNotification)Delegate.Combine(security.exceptionNotification, e => workerThreadException = e);
            thread.Start();
            thread.Join();
            if (workerThreadException != null)
            {
                throw workerThreadException;
            }
        }
        public void ProcessSecurityGroups_WhenSecurityTablesExistAndUsersStringIsEmpty_CreatesExecutesAndDisposesSqlCommand()
        {
            // Arrange
            const string expectedCommandText = "DELETE FROM RPTGROUPUSER where SITEID=@siteid";

            ShimProcessSecurity.SecurityTablesExistSqlConnection = _ => true;
            SetupProcessSecurityGroupsShims();

            // Act
            ProcessSecurity.ProcessSecurityGroups(_spShims.SiteShim.Instance, _adoShims.ConnectionShim.Instance, string.Empty);

            // Assert
            _adoShims.ShouldSatisfyAllConditions(
                () => _adoShims.IsCommandCreated(expectedCommandText).ShouldBeTrue(),
                () => _adoShims.IsCommandExecuted(expectedCommandText).ShouldBeTrue(),
                () => _adoShims.IsCommandDisposed(expectedCommandText).ShouldBeTrue());
        }
        internal static void InitializeProcessSecurity()
        {
            // Spawn off a separate thread to that does RevertToSelf and adjusts DACLs.
            // This is because RevertToSelf terminates client impersonation on the thread
            // that calls it. We do not want to change that on the current thread when 
            // the runtime is hosted inside ASP.net for example.
            Exception workerThreadException = null;
            ProcessSecurity processSecurity = new ProcessSecurity();
            Thread workerThread = new Thread(new ThreadStart(processSecurity.Initialize));

            processSecurity.exceptionNotification += delegate(Exception e)
            {
                workerThreadException = e;
            };

            workerThread.Start(); workerThread.Join();
            if (workerThreadException != null)
                throw workerThreadException;
        }
Exemple #6
0
        public void execute(SPSite site, SPWeb web, string data)
        {
            sbErrors = new StringBuilder();
            EPMData   epmdata     = null;
            Hashtable hshMessages = null;
            SPWeb     rootWeb     = null;

            try
            {
                hshMessages = new Hashtable();

                #region Process security

                try
                {
                    totalCount = site.AllWebs.Count;
                    epmdata    = new EPMData(site.ID);
                    epmdata.LogStatus("", "", "Reporting Refresh  Collect Job", "Reporting refresh process started.", 2, 3, Convert.ToString(JobUid));
                    try
                    {
                        epmdata.LogStatus("", "", "Reporting Refresh  Collect Job", string.Format("Started processing security groups for site: {0}", site.Url), 2, 3, Convert.ToString(JobUid));
                        ProcessSecurity.ProcessSecurityGroups(site, epmdata.GetClientReportingConnection, "");
                        sbErrors.Append("Completed processing security groups for site: " + site.Url + ".</br>");
                        epmdata.LogStatus("", "", "Reporting Refresh  Collect Job", string.Format("Completed processing security groups for site: {0}", site.Url), 2, 3, Convert.ToString(JobUid));
                    }
                    catch (Exception ex)
                    {
                        var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message;

                        bErrors = true;
                        sbErrors.Append("<font color=\"red\">Error processing security on site: " + site.Url + ". Error: " + message + "</font><br>");
                        epmdata.LogStatus("", "", "Reporting Refresh  Collect Job", string.Format("Error processing security on site: {0}. Error: {1}", site.Url, message), 2, 3, Convert.ToString(JobUid));
                    }

                    if (string.IsNullOrEmpty(data))
                    {
                        //try
                        //{
                        //    data = epmdata.GetListNames();
                        //}
                        //catch (Exception exData)
                        //{
                        //    bErrors = true;
                        //    sErrors += "<font color=\"red\">Error while retrieving list names: " + exData.Message + "</font><br>";
                        //}

                        try
                        {
                            epmdata.LogStatus("", "", "Reporting Refresh Collect Job", string.Format("Started updating reporting settings for site: {0}.", site.Url), 2, 3, Convert.ToString(JobUid));
                            setRPTSettings(epmdata, site);
                            epmdata.LogStatus("", "", "Reporting Refresh Collect Job", string.Format("Completed updating reporting settings for site: {0}.", site.Url), 2, 3, Convert.ToString(JobUid));
                        }
                        catch (Exception ex)
                        {
                            var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message;

                            bErrors = true;
                            sbErrors.Append("<font color=\"red\">Error Updating RPTSettings: " + message + "</font><br>");
                            epmdata.LogStatus("", "", "Reporting Refresh Collect Job", string.Format("Updating reporting settings failed for site: {0}. ,Error {1}", site.Url, message), 2, 3, Convert.ToString(JobUid));
                        }
                    }
                }
                catch (Exception ex)
                {
                    bErrors = true;
                    sbErrors.Append("<font color=\"red\">Error Updating base: " + ex.Message + "</font><br>");
                    epmdata.LogStatus("", "", "Reporting Refresh Collect Job", string.Format("Updating reporting settings failed for site: {0}. ,Error {1}", site.Url, ex.Message), 2, 3, Convert.ToString(JobUid));
                }

                #endregion

                #region History

                //try
                //{
                //    data = epmdata.UpdateListNames(data);
                //}
                //catch (Exception ex)
                //{
                //    bErrors = true;
                //    sErrors += "<font color=\"red\">Error Updating List Names: " + ex.Message + "</font><br>";
                //}

                // TODO: We need to make sure this doesn't break anything!!!!
                //foreach (SPWeb w in site.AllWebs)
                //{
                //    // IGNORE SPDispose 130 error, web is being disposed
                //    try
                //    {
                //        List<string> allLists = new List<string>(data.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
                //        List<SPList> allSpLists = new List<SPList>();
                //        foreach (string l in allLists)
                //        {
                //            SPList list = w.Lists.TryGetList(l);
                //            if (list == null ||
                //                list.Title == "Work Hours" ||
                //                list.Title == "Resources")
                //            {
                //                continue;
                //            }

                //            if (list != null)
                //            {
                //                allSpLists.Add(list);
                //            }
                //        }
                //        ProcessSecurity.ProcessSecurityOnRefreshAll(w, allSpLists, epmdata.GetClientReportingConnection);
                //        if (w != null)
                //        {
                //            w.Dispose();
                //        }
                //    }
                //    catch
                //    {
                //        if (w != null)
                //        {
                //            w.Dispose();
                //        }
                //    }
                //}

                #endregion

                #region Process TimeSheet Data

                try
                {
                    string err = "";
                    bool   consolidationdone     = false;
                    bool   reportingRefreshBatch = false;

                    epmdata.LogStatus("", "", "Reporting Refresh Collect Job Process TimeSheet Data", string.Format("Starting Process TimeSheet Data for site: {0}.", site.Url), 2, 3, Convert.ToString(JobUid));
                    bool.TryParse(EPMLiveCore.CoreFunctions.getConfigSetting(web, "epmliveconsolidation"), out consolidationdone);
                    bool.TryParse(EPMLiveCore.CoreFunctions.getConfigSetting(web, "epmlivereportingrefreshbatch"), out reportingRefreshBatch);
                    bool bErrorRefreshTimesheet = false;
                    if (reportingRefreshBatch)
                    {
                        int pageSize = 0;
                        int.TryParse(EPMLiveCore.CoreFunctions.getConfigSetting(web, "epmliverepotingrefreshbatchpagesize"), out pageSize);
                        bErrorRefreshTimesheet = epmdata.RefreshTimesheetBatch(out err, base.JobUid, pageSize);
                    }
                    else
                    {
                        bErrorRefreshTimesheet = epmdata.RefreshTimesheets(out err, base.JobUid, consolidationdone);
                    }
                    if (bErrorRefreshTimesheet)
                    {
                        bErrors = true;
                        sbErrors.Append("<font color=\"red\">Error Processing Timesheets: " + err + "</font><br>");
                        epmdata.LogStatus("", "", "Reporting Refresh Collect Job Process TimeSheet Data", string.Format("Process TimeSheet Data failed for site: {0}. Error {1}", site.Url, err), 2, 3, Convert.ToString(JobUid));
                    }

                    else
                    {
                        sbErrors.Append("Processed Timesheets<br>");
                        epmdata.LogStatus("", "", "Reporting Refresh Collect Job Process TimeSheet Data", string.Format("Completed timeSheet data processing for site: {0}", site.Url), 2, 3, Convert.ToString(JobUid));
                    }
                }
                catch (Exception ex)
                {
                    var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message;

                    bErrors = true;
                    sbErrors.Append("<font color=\"red\">Error Processing Timesheets: " + message + "</font><br>");
                    epmdata.LogStatus("", "", "Reporting Refresh Collect Job Process TimeSheet Data", string.Format("Process TimeSheet Data failed for site: {0}. Error {1}", site.Url, message), 2, 3, Convert.ToString(JobUid));
                }

                #endregion

                #region Process PFE Data

                try
                {
                    if (site.Features[new Guid("158c5682-d839-4248-b780-82b4710ee152")] != null)
                    {
                        epmdata.LogStatus("", "", "Reporting Refresh Collect Job Process PFE Data", string.Format("Processing PFE Data for site: {0}", site.Url), 2, 3, Convert.ToString(JobUid));
                        rootWeb = site.RootWeb;

                        string basePath   = CoreFunctions.getConfigSetting(rootWeb, "epkbasepath");
                        string ppmId      = CoreFunctions.getConfigSetting(rootWeb, "ppmpid");
                        string ppmCompany = CoreFunctions.getConfigSetting(rootWeb, "ppmcompany");
                        string ppmDbConn  = CoreFunctions.getConfigSetting(rootWeb, "ppmdbconn");

                        Assembly assemblyInstance =
                            Assembly.Load(
                                "PortfolioEngineCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5");
                        Type   thisClass   = assemblyInstance.GetType("PortfolioEngineCore.WEIntegration.WEIntegration");
                        object classObject = Activator.CreateInstance(thisClass,
                                                                      new object[] { basePath, site.WebApplication.ApplicationPool.Username, ppmId, ppmCompany, ppmDbConn, false });

                        MethodInfo m       = thisClass.GetMethod("ExecuteReportExtract");
                        var        message =
                            (string)
                            m.Invoke(classObject,
                                     new object[]
                        {
                            "<ExecuteReportExtract><Params /><Data><ReportExtract Connection=\"" +
                            getReportingConnection(web) + "\" Execute=\"1\" /></Data></ExecuteReportExtract>"
                        });

                        sbErrors.Append("Processed PfE Reporting: " + message + "<br>");
                        epmdata.LogStatus("", "", "Reporting Refresh Collect Job Process PFE Data", string.Format("Completed Processing PFE Data for site: {0}", site.Url), 2, 3, Convert.ToString(JobUid));
                    }
                }
                catch (Exception ex)
                {
                    var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message;

                    bErrors = true;
                    sbErrors.Append("<font color=\"red\">Error Processing PfE Reporting: " + message + "</font><br>");
                    epmdata.LogStatus("", "", "Reporting Refresh Collect Job Process PFE Data", string.Format("Error Processing PfE Reporting for site: {0} Error {1}", site.Url, message), 2, 3, Convert.ToString(JobUid));
                }

                #endregion Process PFE Data



                #region Clean Data

                try
                {
                    string errMsg = string.Empty;
                    epmdata.LogStatus("", "", "Reporting Refresh Collect Job DataScrubber CleanTables", string.Format("Started DataScrubber.CleanTables for site: {0}", site.Url), 2, 3, Convert.ToString(JobUid));
                    bool bErrorCleanTables = DataScrubber.CleanTables(site, epmdata, base.JobUid, ref errMsg);
                    if (bErrorCleanTables)
                    {
                        bErrors = true;
                        sbErrors.Append("<font color=\"red\">Error while cleaning tables: " + errMsg + "</font><br>");
                        epmdata.LogStatus("", "", "Reporting Refresh Collect Job DataScrubber CleanTables", string.Format("Error while cleaning tables for site: {0} error {1}", site.Url, errMsg), 2, 3, Convert.ToString(JobUid));
                    }
                    else
                    {
                        epmdata.LogStatus("", "", "Reporting Refresh Collect Job DataScrubber CleanTables", string.Format("Completed DataScrubber.CleanTables for site: {0}", site.Url), 2, 3, Convert.ToString(JobUid));
                    }
                }
                catch (Exception ex)
                {
                    var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message;

                    bErrors = true;
                    sbErrors.Append("<font color=\"red\">Error while cleaning tables: " + message + "</font><br>");
                    epmdata.LogStatus("", "", "Reporting Refresh Collect Job DataScrubber CleanTables", string.Format("Error while cleaning tables for site: {0} error {1}", site.Url, message), 2, 3, Convert.ToString(JobUid));
                }

                #endregion

                #region Update Status Field

                try
                {
                    if (string.IsNullOrEmpty(data))
                    {
                        DataSet ds = null;
                        try
                        {
                            ds = new DataSet();
                            using (var cmd1 = new SqlCommand("SELECT TABLENAME FROM RPTList", epmdata.GetClientReportingConnection))
                            {
                                epmdata.LogStatus("", "", "Reporting Refresh Collect Job Update Status Field", string.Format("Started Update Status Field for site: {0} ,SQL  (SELECT TABLENAME FROM RPTList) ", site.Url), 2, 3, Convert.ToString(JobUid));
                                using (SqlDataAdapter da = new SqlDataAdapter(cmd1))
                                {
                                    da.Fill(ds);

                                    foreach (DataRow dr in ds.Tables[0].Rows)
                                    {
                                        using (var cmd2 = new SqlCommand("spUpdateStatusFields", epmdata.GetClientReportingConnection))
                                        {
                                            cmd2.CommandType = CommandType.StoredProcedure;
                                            cmd2.Parameters.AddWithValue("@listtable", dr[0].ToString());
                                            cmd2.ExecuteNonQuery();
                                            epmdata.LogStatus("", "", "Reporting Refresh Collect Job Update Status Field", string.Format("Executing  store procedure spUpdateStatusFields '{0}'", dr[0].ToString()), 2, 3, Convert.ToString(JobUid));
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message;

                            bErrors = true;
                            sbErrors.Append("<font color=\"red\">Error updating status fields: " + message + "</font><br>");
                            epmdata.LogStatus("", "", "Reporting Refresh Collect Job Update Status Field", string.Format("Error updating status fields: for site {0},error {1} ", site.Url, message), 2, 3, Convert.ToString(JobUid));
                        }
                        finally
                        {
                            if (ds != null)
                            {
                                ds.Dispose();
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            foreach (string sList in data.Split(','))
                            {
                                if (sList != "")
                                {
                                    DataSet ds   = null;
                                    SPList  list = null;
                                    try
                                    {
                                        list = web.Lists[sList];

                                        ds = new DataSet();
                                        using (var cmd1 = new SqlCommand("SELECT TABLENAME FROM RPTList where listid=@listid", epmdata.GetClientReportingConnection))
                                        {
                                            epmdata.LogStatus("", "", "Reporting Refresh Collect Job Update Status Field", string.Format("SELECT TABLENAME FROM RPTList where listid={0} ", list.ID), 2, 3, Convert.ToString(JobUid));
                                            cmd1.Parameters.AddWithValue("@listid", list.ID);
                                            using (SqlDataAdapter da = new SqlDataAdapter(cmd1))
                                            {
                                                da.Fill(ds);

                                                using (var cmd2 = new SqlCommand("spUpdateStatusFields", epmdata.GetClientReportingConnection))
                                                {
                                                    cmd2.CommandType = CommandType.StoredProcedure;
                                                    cmd2.Parameters.AddWithValue("@listtable", ds.Tables[0].Rows[0][0].ToString());
                                                    cmd2.ExecuteNonQuery();
                                                    epmdata.LogStatus("", "", "Reporting Refresh Collect Job Update Status Field", string.Format("Executed spUpdateStatusFields '{0}' ", Convert.ToString(ds.Tables[0].Rows[0][0])), 2, 3, Convert.ToString(JobUid));
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message;

                                        bErrors = true;
                                        sbErrors.Append("<font color=\"red\">Error updating status fields (" + sList + "): " + message + "</font><br>");
                                        epmdata.LogStatus("", "", "Reporting Refresh Collect Job Update Status Field", string.Format("Error updating status fields ({0}) Error {1}", sList, message), 2, 3, Convert.ToString(JobUid));
                                    }
                                    finally
                                    {
                                        if (ds != null)
                                        {
                                            ds.Dispose();
                                        }
                                        list = null;
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message;

                            bErrors = true;
                            sbErrors.Append("<font color=\"red\">Error updating status fields: " + message + "</font><br>");
                            epmdata.LogStatus("", "", "Reporting Refresh Collect Job Update Status Field", string.Format("Error updating status fields Error {0}", message), 2, 3, Convert.ToString(JobUid));
                        }
                    }

                    foreach (string list in data.Split(','))
                    {
                        if (list != "")
                        {
                            try
                            {
                                using (var cmd2 = new SqlCommand("spUpdateStatusFields", epmdata.GetClientReportingConnection))
                                {
                                    cmd2.CommandType = CommandType.StoredProcedure;
                                    cmd2.Parameters.AddWithValue("@listtable", list);
                                    cmd2.ExecuteNonQuery();
                                    epmdata.LogStatus("", "", "Reporting Refresh Collect Job Update Status Field", string.Format("Executed spUpdateStatusFields '{0}'", list), 2, 3, Convert.ToString(JobUid));
                                }
                            }
                            catch (Exception ex)
                            {
                                var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message;

                                bErrors = true;
                                sbErrors.Append("<font color=\"red\">Error running schedule field update for (" + list + "): " + message + "</font><br>");
                                epmdata.LogStatus("", "", "Reporting Refresh Collect Job Update Status Field", string.Format("Error running schedule field update for ({0}) error {1}.", list, message), 2, 3, Convert.ToString(JobUid));
                            }

                            if (!hshMessages.Contains(list))
                            {
                                hshMessages.Add(list, "");
                            }
                        }
                    }

                    sbErrors.Append("<br>Updated Status Fields<br>");
                    epmdata.LogStatus("", "", "Reporting Refresh Collect Job Update Status Field", string.Format("Complete  running Updated Status Fields"), 2, 3, Convert.ToString(JobUid));
                }
                catch (Exception ex)
                {
                    var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                    bErrors = true;
                    sbErrors.Append("<font color=\"red\">Error running schedule field update: " + message + "</font><br>");
                    epmdata.LogStatus("", "", "Reporting Refresh Collect Job Update Status Field", string.Format("Error running schedule field update: {0}", message), 2, 3, Convert.ToString(JobUid));
                }

                #endregion

                #region Clear Cache

                try
                {
                    epmdata.LogStatus("", "", "Reporting Refresh Collect Job Clear Cache", string.Format("Started Cleaning cache for site : {0}", site.Url), 2, 3, Convert.ToString(JobUid));
                    CacheStore.Current.RemoveSafely(web.Url, new CacheStoreCategory(web).Navigation);
                    epmdata.LogStatus("", "", "Reporting Refresh Collect Job Clear Cache", string.Format("Completed Cleaning cache for site : {0}", site.Url), 2, 3, Convert.ToString(JobUid));
                }
                catch (Exception ex)
                {
                    var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message;

                    bErrors = true;
                    sbErrors.Append("<font color=\"red\">Clear Cache Error: " + message + "</font><br>");
                    epmdata.LogStatus("", "", "Reporting Refresh Collect Job Clear Cache", string.Format("Cleaning Cache Failed for site : {0} error {1}", site.Url, message), 2, 3, Convert.ToString(JobUid));
                }

                #endregion
            }
            catch (Exception ex)
            {
                var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message;

                bErrors = true;
                sbErrors.Append("<font color=\"red\">General Execute Error: " + message + "</font><br>");
                epmdata.LogStatus("", "", "Reporting Refresh Collect Job", string.Format("General Execute Error for site : {0} error {1}", site.Url, message), 2, 3, Convert.ToString(JobUid));
            }
            finally
            {
                sErrors  = sbErrors.ToString();
                sbErrors = null;
                //Already calling from TimerClass
                //finishJob();
                hshMessages = null;
                if (epmdata != null)
                {
                    epmdata.Dispose();
                }
                if (web != null)
                {
                    web.Dispose();
                }
                if (rootWeb != null)
                {
                    rootWeb.Dispose();
                }
                if (site != null)
                {
                    site.Dispose();
                }
                data = null;
            }
        }
Exemple #7
0
 public static extern IntPtr OpenProcess([In] ProcessSecurity dwDesiredAccess,
                                         [In, MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, [In] int dwProcessId);
 internal static void InitializeProcessSecurity()
 {
     Exception workerThreadException = null;
     ProcessSecurity security = new ProcessSecurity();
     Thread thread = new Thread(new ThreadStart(security.Initialize));
     security.exceptionNotification = (ExceptionNotification) Delegate.Combine(security.exceptionNotification, e => workerThreadException = e);
     thread.Start();
     thread.Join();
     if (workerThreadException != null)
     {
         throw workerThreadException;
     }
 }