예제 #1
0
        /// <summary>
        ///     Refreshes all.
        /// </summary>
        /// <returns></returns>
        public string RefreshAll()
        {
            try
            {
                using (var epmData = new EPMData(Web.Site.ID))
                {
                    epmData.DeleteWork(Guid.Empty, -1);

                    epmData.Command =
                        "select timerjobuid from timerjobs where siteguid=@siteguid and listguid is null and jobtype=5";
                    epmData.AddParam("@siteguid", Web.Site.ID);

                    object result = epmData.ExecuteScalar(epmData.GetEPMLiveConnection);

                    Guid timerJobId = Guid.Empty;

                    if (result != null)
                    {
                        timerJobId = (Guid)result;
                    }
                    else
                    {
                        timerJobId = Guid.NewGuid();

                        epmData.Command =
                            "INSERT INTO TIMERJOBS (siteguid, jobtype, jobname, scheduletype, webguid, timerjobuid) VALUES (@siteguid, 5, 'Reporting Refresh All', 2, @webguid, @timerjobuid)";
                        epmData.AddParam("@siteguid", Web.Site.ID);
                        epmData.AddParam("@webguid", Web.ID);
                        epmData.AddParam("@timerjobuid", timerJobId);

                        epmData.ExecuteNonQuery(epmData.GetEPMLiveConnection);
                    }

                    if (timerJobId != Guid.Empty)
                    {
                        CoreFunctions.enqueue(timerJobId, 0, Web.Site);
                    }
                }

                return("<RefreshAll><Data/></RefreshAll>");
            }
            catch (APIException)
            {
                throw;
            }
            catch (Exception exception)
            {
                throw new APIException((int)Errors.RefreshAll, exception.GetBaseException().Message);
            }
        }
        public void RaisePostBackEvent(string sAction)
        {
            string param = sAction.Remove(sAction.LastIndexOf("_"));

            sAction = sAction.Substring(sAction.LastIndexOf("_") + 1);
            switch (sAction)
            {
            case "cleanup":
                CleanupLists(param);
                break;

            case "snapshot":
                SnapshotLists(param);
                break;

            case "delete":
                var reportBiz = new ReportBiz(SPContext.Current.Site.ID, SPContext.Current.Web.ID,
                                              reportingV2Enabled);
                var listId = new Guid(param);
                _DAO.Command = "SELECT TableName FROM RPTList WHERE RPTListID=@RPTListID";
                _DAO.AddParam("@RPTListID", param);
                string    sTableName = _DAO.ExecuteScalar(_DAO.GetClientReportingConnection).ToString();
                DataTable refTables  = reportBiz.GetReferencingTables(_DAO, sTableName);
                if (refTables.Rows.Count == 0)
                {
                    reportBiz.GetListBiz(new Guid(param)).Delete();
                }
                else
                {
                    SPUtility.Redirect("epmlive/ListMappings.aspx?delete=true&id=" + param + "&name=" + sTableName,
                                       SPRedirectFlags.RelativeToLayoutsPage, HttpContext.Current);
                }
                break;
            }
            SPUtility.Redirect("epmlive/ListMappings.aspx?", SPRedirectFlags.RelativeToLayoutsPage, HttpContext.Current);
        }
예제 #3
0
        private void CleanupListAfterFieldUpdate(EPMData DAO, string sList)
        {
            using (SPSite site = new SPSite(DAO.SiteId))
            {
                using (SPWeb web = site.RootWeb)
                {
                    Guid listID = DAO.GetListId(sList, web.ID);

                    //DELETE WORK
                    DAO.DeleteWork(listID, -1);
                    //END

                    DAO.Command =
                        "select timerjobuid from timerjobs where siteguid=@siteguid and listguid = @listguid and jobtype=6";
                    DAO.AddParam("@siteguid", site.ID.ToString());
                    DAO.AddParam("@listguid", listID.ToString());
                    object oResult = DAO.ExecuteScalar(DAO.GetEPMLiveConnection);

                    Guid timerjobuid = Guid.Empty;

                    if (oResult != null)
                    {
                        timerjobuid = (Guid)oResult;
                    }
                    else
                    {
                        timerjobuid = Guid.NewGuid();
                        DAO.Command =
                            "INSERT INTO TIMERJOBS (timerjobuid, siteguid, jobtype, jobname, scheduletype, webguid, listguid, jobdata) VALUES (@timerjobuid, @siteguid, 6, 'List Data Cleanup', 0, @webguid, @listguid, @jobdata)";
                        DAO.AddParam("@siteguid", site.ID.ToString());
                        DAO.AddParam("@webguid", web.ID.ToString());
                        DAO.AddParam("@listguid", listID.ToString());
                        DAO.AddParam("@jobdata", sList);
                        DAO.AddParam("@timerjobuid", timerjobuid);
                        DAO.ExecuteNonQuery(DAO.GetEPMLiveConnection);
                    }

                    if (timerjobuid != Guid.Empty)
                    {
                        EPMLiveCore.CoreFunctions.enqueue(timerjobuid, 0, site);
                    }
                }
            }
            //--End
        }
예제 #4
0
        private bool HasForeignKey(EPMData DAO, string tableName, string columnName)
        {
            bool hasForeignKey = false;

            try
            {
                DAO.Command = "SELECT DISTINCT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE " +
                              "WHERE TABLE_NAME = '" + tableName + "' AND COLUMN_NAME = '" + columnName + "' AND CONSTRAINT_NAME LIKE 'FK_%'";

                object result = DAO.ExecuteScalar(DAO.GetClientReportingConnection);
                if (result != null)
                {
                    hasForeignKey = true;
                }
                return(hasForeignKey);
            }
            catch (Exception)
            {
                return(hasForeignKey);
            }
        }
예제 #5
0
        private void DeleteCheck()
        {
            var     reportBiz = new ReportBiz(SPContext.Current.Site.ID);
            EPMData _DAO      = new EPMData(SPContext.Current.Site.ID);

            _DAO.Command = "SELECT TableName FROM RPTList WHERE RPTListID=@RPTListID";
            _DAO.AddParam("@RPTListID", _listId);
            string    sTableName = _DAO.ExecuteScalar(_DAO.GetClientReportingConnection).ToString();
            DataTable refTables  = reportBiz.GetReferencingTables(_DAO, sTableName);

            if (refTables.Rows.Count == 0)
            {
                output = "true";
                //reportBiz.GetListBiz(new Guid(Request["List"])).Delete();
            }
            else
            {
                string sLists = GetRefLists(refTables, _DAO);
                //SPUtility.Redirect("epmlive/ListMappings.aspx?delete=true&id=" + param + "&name=" + sTableName, SPRedirectFlags.RelativeToLayoutsPage, HttpContext.Current);
                output = "false," + sLists;
            }
        }
예제 #6
0
        private bool DeleteList(SPListEventProperties properties)
        {
            bool isSuccessful = true;
            var  reportBiz    = new ReportBiz(properties.SiteId);
            Guid listId       = properties.ListId;
            var  DAO          = new EPMData(properties.SiteId);

            DAO.Command = "SELECT TableName FROM RPTList WHERE RPTListID=@RPTListID";
            DAO.AddParam("@RPTListID", listId);
            string sTableName = string.Empty;

            try
            {
                sTableName = DAO.ExecuteScalar(DAO.GetClientReportingConnection).ToString();
                DataTable refTables = reportBiz.GetReferencingTables(DAO, sTableName);
                if (refTables.Rows.Count == 0)
                {
                    reportBiz.GetListBiz(listId).Delete();
                }
                else
                {
                    isSuccessful = false;
                    DAO.LogStatus(listId.ToString(), sTableName,
                                  "Database table delete attempt: Unable to delete " + sTableName + ".",
                                  sTableName + " is referenced by other tables.", 2, 5, Guid.NewGuid().ToString());
                    //Logged in the RefreshAll event log.
                }
            }
            catch (Exception ex)
            {
                DAO.LogStatus(listId.ToString(), sTableName,
                              "Database table delete attempt: Unable to delete " + sTableName + ". " + ex.Message, ex.StackTrace,
                              2, 5, Guid.NewGuid().ToString()); //Logged in the RefreshAll event log.
            }
            reportBiz = null;
            DAO.Dispose();
            return(isSuccessful);
        }
예제 #7
0
        private bool IsUpdateRequire(EPMData DAO, SPListEventProperties properties, string tableName, string columnName)
        {
            if (properties.Field.Type.Equals(SPFieldType.Lookup))
            {
                string fieldType = properties.Field.TypeAsString;
                try
                {
                    DAO.Command = "SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" + tableName + "' AND COLUMN_NAME = '" + columnName + "'";
                    string result = Convert.ToString(DAO.ExecuteScalar(DAO.GetClientReportingConnection));

                    if ((result.Equals("ntext", StringComparison.InvariantCultureIgnoreCase) && fieldType.Equals("Lookup", StringComparison.InvariantCultureIgnoreCase)) ||
                        result.Equals("int", StringComparison.InvariantCultureIgnoreCase) && fieldType.Equals("LookupMulti", StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(true);
                    }
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            return(false);
        }
예제 #8
0
        public bool AddTimerJob(SPWeb web, int iTime, int iScheduleType, string days, bool runNow)
        {
            SqlConnection con    = null;
            bool          passed = true;

            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    Guid timerjobuid = Guid.Empty;
                    if (_DAO == null)
                    {
                        _DAO = new EPMData(web.Site.ID);
                    }

                    _DAO.Command = "select timerjobuid from timerjobs where siteguid=@siteguid and jobtype=8";
                    _DAO.AddParam("@siteguid", web.Site.ID.ToString());
                    object oResult = _DAO.ExecuteScalar(_DAO.GetEPMLiveConnection);

                    if (oResult != null)
                    {
                        timerjobuid  = (Guid)oResult;
                        _DAO.Command = "UPDATE TIMERJOBS SET runtime = @runtime, scheduleType = @scheduletype, days = @days WHERE jobtype=8";
                        _DAO.AddParam("@runtime", iTime);
                        _DAO.AddParam("@scheduletype", iScheduleType);
                        _DAO.AddParam("@days", days);
                        _DAO.ExecuteNonQuery(_DAO.GetEPMLiveConnection);
                    }
                    else
                    {
                        timerjobuid  = Guid.NewGuid();
                        _DAO.Command = "INSERT INTO TIMERJOBS (timerjobuid,jobname,siteguid,webguid,listguid,jobtype,enabled,runtime,scheduletype,days,jobdata,lastqueuecheck,parentjobuid) VALUES (@timerjobuid,@jobname,@siteguid,@webguid,NULL,@jobtype,@enabled,@runtime,@scheduletype,@days,@jobdata,@lastqueuecheck,@parentjobuid)";
                        _DAO.AddParam("@timerjobuid", timerjobuid);
                        _DAO.AddParam("@jobname", "EPMLiveADSync");
                        _DAO.AddParam("@siteguid", web.Site.ID.ToString());
                        _DAO.AddParam("@webguid", web.Site.RootWeb.ID.ToString());
                        _DAO.AddParam("@jobtype", 8);
                        _DAO.AddParam("@enabled", true);
                        _DAO.AddParam("@runtime", iTime);
                        _DAO.AddParam("@scheduletype", iScheduleType);
                        _DAO.AddParam("@days", days);
                        _DAO.AddParam("@jobdata", web.Site.RootWeb.Url);
                        _DAO.AddParam("@lastqueuecheck", DBNull.Value);
                        _DAO.AddParam("@parentjobuid", DBNull.Value);
                        _DAO.ExecuteNonQuery(_DAO.GetEPMLiveConnection);
                    }

                    if (runNow && timerjobuid != Guid.Empty)
                    {
                        EPMLiveCore.CoreFunctions.enqueue(timerjobuid, 0);
                    }
                });
            }
            catch (Exception ex)
            {
                passed = false;
                _ExecutionLogs.Add("     ERROR -- Location: AddTimerJob() -- Message: " + ex.Message);
                _hasErrors = true;
            }
            finally
            {
                _DAO.Dispose();
            }
            return(passed);
        }
예제 #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            _DAO = new EPMData(SPContext.Current.Site.ID);
            string action       = Request["Action"];
            Guid   timerjobguid = Guid.NewGuid();

            //DataTable dtResults;

            if (action != null && action == "SnapshotAll")
            {
                try
                {
                    //Local Testing -- Start
                    //_DAO.SnapshotLists(timerjobguid, _DAO.GetListNames());
                    //dtResults = _DAO.GetSnapshotResults(timerjobguid);
                    // -- END

                    //PROD -- Start
                    string sListIDs = _DAO.GetAllListIDs();
                    using (SPSite site = SPContext.Current.Site)
                    {
                        using (SPWeb web = SPContext.Current.Web)
                        {
                            _DAO.Command =
                                "INSERT INTO TIMERJOBS (timerjobuid, siteguid, jobtype, jobname, scheduletype, webguid, jobdata) VALUES (@timerjobuid,@siteguid, 7, 'Reporting Snapshot All', 0, @webguid, @jobdata)";
                            _DAO.AddParam("@timerjobuid", timerjobguid);
                            _DAO.AddParam("@siteguid", site.ID.ToString());
                            _DAO.AddParam("@webguid", web.ID.ToString());
                            _DAO.AddParam("@jobdata", sListIDs);
                            _DAO.ExecuteNonQuery(_DAO.GetEPMLiveConnection);
                        }
                        CoreFunctions.enqueue(timerjobguid, 0);
                    }
                    //END
                }
                catch (Exception ex)
                {
                    _DAO.LogStatus(string.Empty, string.Empty, "Process: SnapshotAll - " + ex.Message, ex.StackTrace, 2,
                                   9, string.Empty);
                    Response.Write("Error: " + ex.Message);
                    return;
                }
                SPUtility.Redirect("epmlive/ListMappings.aspx", SPRedirectFlags.RelativeToLayoutsPage,
                                   HttpContext.Current);
            }
            else if (action != null && action == "CleanupAll")
            {
                //Local Testing -- Start
                //string sListNames = _DAO.GetListNames();
                //DataTable dtWebResults = null;
                //timerjobguid = new Guid();
                //DataTable dtListResults = new RefreshLists().InitializeResultsDT(sListNames);

                //if (sListNames != string.Empty)
                //{
                //    RefreshLists oListRefresh = null;
                //    foreach (SPWeb web in SPContext.Current.Site.AllWebs)
                //    {
                //        oListRefresh = new RefreshLists(web, sListNames);
                //        oListRefresh.StartRefresh(timerjobguid, out dtWebResults);
                //        dtWebResults.TableName = web.ServerRelativeUrl;
                //        oListRefresh.AppendStatus(web.Name, web.ServerRelativeUrl, dtListResults, dtWebResults);
                //    }
                //    oListRefresh.SaveResults(dtListResults, timerjobguid);
                //}
                // -- End

                //PROD -- Start
                using (SPSite site = SPContext.Current.Site)
                {
                    using (SPWeb web = SPContext.Current.Web)
                    {
                        //DELETE WORK
                        _DAO.DeleteWork(Guid.Empty, -1);
                        //END

                        _DAO.Command =
                            "select timerjobuid from timerjobs where siteguid=@siteguid and listguid is null and jobtype=6";
                        _DAO.AddParam("@siteguid", site.ID.ToString());
                        object oResult     = _DAO.ExecuteScalar(_DAO.GetEPMLiveConnection);
                        Guid   timerjobuid = Guid.Empty;

                        if (oResult != null)
                        {
                            timerjobuid = (Guid)oResult;
                        }
                        else
                        {
                            timerjobuid  = Guid.NewGuid();
                            _DAO.Command =
                                "INSERT INTO TIMERJOBS (siteguid, jobtype, jobname, scheduletype, webguid, timerjobuid) VALUES (@siteguid, 6, 'List Data Cleanup', 2, @webguid, @timerjobuid)";
                            _DAO.AddParam("@siteguid", site.ID.ToString());
                            _DAO.AddParam("@webguid", web.ID.ToString());
                            _DAO.AddParam("@timerjobuid", timerjobuid);
                            _DAO.ExecuteNonQuery(_DAO.GetEPMLiveConnection);
                        }

                        if (timerjobuid != Guid.Empty)
                        {
                            CoreFunctions.enqueue(timerjobuid, 0);
                        }
                    }
                }
                // -- END
                SPUtility.Redirect("epmlive/ListMappings.aspx", SPRedirectFlags.RelativeToLayoutsPage,
                                   HttpContext.Current);
            }
        }