Ejemplo n.º 1
0
        public List <string> getSiteCollectionsInWebApp(string WebAppName)
        {
            List <string> SiteCollNames = new List <string>();

            SPWebServiceCollection webServices = new SPWebServiceCollection(SPFarm.Local);

            foreach (SPWebService webService in webServices)
            {
                SPWebApplicationCollection webappcoll = webService.WebApplications;
                foreach (SPWebApplication webApp in webappcoll)
                {
                    if (webApp.Name == WebAppName)
                    {
                        SPSiteCollection sitecoll = webApp.Sites;
                        foreach (SPSite Site in sitecoll)
                        {
                            SiteCollNames.Add(Site.Url);
                            Site.Dispose();
                        }
                        return(SiteCollNames);
                    }
                }
            }
            return(SiteCollNames);
        }
        private bool IsFeatureActivatedInAnyWebApp(SPWebApplication thisWebApplication, Guid thisFeatureId)
        {
            // Indicates whether the feature is activated for any other web application in the
            // SharePoint farm.

            // Attempt to access the Web service associated with the content application.
            SPWebService webService = SPWebService.ContentService;

            if (webService == null)
            {
                throw new ApplicationException("Cannot access the Web service associated with the content application.");
            }

            // Iterate through the collection of web applications. If this feature is
            // activated for any web application other than the current web application,
            // return true; otherwise, return false.
            SPWebApplicationCollection webApps = webService.WebApplications;

            foreach (SPWebApplication webApp in webApps)
            {
                if (webApp != thisWebApplication)
                {
                    if (webApp.Features[thisFeatureId] != null)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 3
0
        public void startTimerTest()
        {
            using (SPEmulators.SPEmulationContext ctx = new SPEmulators.SPEmulationContext(SPEmulators.IsolationLevel.Fake))
            {
                int opencon  = 0;
                int closecon = 0;
                ShimSqlConnection.AllInstances.Open = (instance) =>
                {
                    opencon++;
                };
                ShimSqlConnection.AllInstances.Close = (instance) =>
                {
                    closecon++;
                };

                ShimProcessorBase.GetWebApplications = () =>
                {
                    SPWebApplicationCollection webapp = new SPWebApplicationCollection(new SPWebService());
                    webapp.Add(new ShimSPWebApplication());
                    webapp.Add(new ShimSPWebApplication());
                    return(webapp);
                };

                TimerRunner tr = new TimerRunner();
                tr.startTimer();
                Thread.Sleep(60000);
                tr.stopTimer();
                Thread.Sleep(3000);
            }
        }
Ejemplo n.º 4
0
        // get all WebApplications availble on current WFE machine
        public List <string> getAvailableWebAppsOnMachine()
        {
            List <string> WebNames = new List <string>();

            SPWebServiceCollection webServices = new SPWebServiceCollection(SPFarm.Local);

            foreach (SPWebService webService in webServices)
            {
                SPWebApplicationCollection webappcoll = webService.WebApplications;
                foreach (SPWebApplication webApp in webappcoll)
                {
                    // only include the data web apps not configuration (central admin)
                    if (!webApp.IsAdministrationWebApplication)
                    {
                        WebNames.Add(webApp.Name);
                    }
                    //url = webApp.GetResponseUri(SPUrlZone.Default).AbsoluteUri);
                }
            }

            // sort + reverse so that sharepoint-80 is shown first
            WebNames.Sort();
            WebNames.Reverse();
            return(WebNames);
        }
        public override void RunTask(CancellationToken token)
        {
            try
            {
                SPWebApplicationCollection _webcolections = GetWebApplications();
                foreach (SPWebApplication webApp in _webcolections)
                {
                    var maxThreads = MaxThreads;
                    if (maxThreads <= 0)
                    {
                        continue;
                    }

                    string sConn = EPMLiveCore.CoreFunctions.getConnectionString(webApp.Id);
                    if (sConn != "")
                    {
                        using (SqlConnection cn = new SqlConnection(sConn))
                        {
                            try
                            {
                                cn.Open();
                                var processed = ProcessTimesheetQueue(maxThreads, sConn, cn, token);
                                if (processed > 0)
                                {
                                    logMessage("HTBT", "PRCS", $"Requested {maxThreads} Queued {processed} jobs, running threads: {RunningThreads}");
                                }
                                else if (RunningThreads == 0)
                                {
                                    using (SqlCommand cmd = new SqlCommand(@";
                                                with oldestAborted as 
                                                (select TOP 1 * from tsqueue where status = 3 and result = 'errors' order by dtstarted)
                                                update oldestAborted set status=0,queue=CAST((TRY_PARSE(SUBSTRING(QUEUE, 1, 1) AS INT) - 1) AS nvarchar(1)) + '-' +  @servername
                                                ", cn))
                                    {
                                        cmd.CommandType = CommandType.Text;
                                        cmd.Parameters.AddWithValue("@servername", Environment.MachineName);
                                        cmd.ExecuteNonQuery();
                                    }
                                }

                                using (var cmd1 = new SqlCommand("delete from TSqueue where DateAdd(day, 1, dtfinished) < GETDATE()", cn))
                                {
                                    cmd1.ExecuteNonQuery();
                                }
                            }
                            catch (Exception ex) when(!(ex is OperationCanceledException))
                            {
                                logMessage("ERR", "RUNT", ex.ToString());
                            }
                        }
                    }
                }
            }
            catch (Exception ex) when(!(ex is OperationCanceledException))
            {
                logMessage("ERR", "RUN", ex.Message);
            }
        }
 private void PopulateTreeViewForWebApps(TreeNodeCollection treeNodes, SPWebApplicationCollection webApps)
 {
     foreach (SPWebApplication application in webApps)
     {
         WebApplicationInfo webAppInfo     = new WebApplicationInfo(application, false);
         ExtendedTreeNode   webAppTreeNode = ExtendedTreeNode.AddNewExtendedTreeNode(treeNodes, webAppInfo.ToString(), true, webAppInfo);
         webAppTreeNode.TreeNodePopulate += new ExtendedTreeNode.TreeNodeEventHandler(WebAppTreeNode_TreeNodePopulate);
     }
 }
Ejemplo n.º 7
0
        public static SPWebApplicationCollection GetAllWebApps()
        {
            // all the content WebApplications
            SPWebApplicationCollection     webapps      = SPWebService.ContentService.WebApplications;
            SPAdministrationWebApplication centralAdmin = SPAdministrationWebApplication.Local;

            webapps.Add(centralAdmin);
            return(webapps);
        }
 private void PopulateTreeViewForWebApps(TreeNodeCollection treeNodes, SPWebApplicationCollection webApps)
 {
     foreach (SPWebApplication application in webApps)
     {
         WebApplicationInfo webAppInfo     = new WebApplicationInfo(application, false);
         ExtendedTreeNode   webAppTreeNode = ExtendedTreeNode.AddNewExtendedTreeNode(treeNodes, webAppInfo.ToString(), true, webAppInfo);
         webAppTreeNode.Checked           = (((application.IsAdministrationWebApplication || webAppInfo.IsSRP) && InstallConfiguration.SuggestDeploymentToCentralAdminWebApplication) || ((!(application.IsAdministrationWebApplication || webAppInfo.IsSRP)) && InstallConfiguration.SuggestDeploymentToAllContentWebApplications));
         webAppTreeNode.TreeNodePopulate += new ExtendedTreeNode.TreeNodeEventHandler(WebAppTreeNode_TreeNodePopulate);
     }
 }
Ejemplo n.º 9
0
        public static void ListarApps()
        {
            SPWebApplicationCollection coleccionesapps = SPWebService.ContentService.WebApplications;

            if (coleccionesapps.Count != null)
            {
                foreach (var spwWebApp in coleccionesapps)
                {
                    Console.WriteLine(spwWebApp.ApplicationPool.Name);
                }
            }
        }
Ejemplo n.º 10
0
        private void FindFeatureActivations()
        {
            //first, Look in Farm
            try
            {
                CheckFarm();
            }
            catch (Exception exc)
            {
                OnException(exc,
                            "Exception checking farm"
                            );
            }

            // check all web apps and everything under
            SPWebApplicationCollection webApplicationCollection = SPWebService.ContentService.WebApplications;

            foreach (SPWebApplication webApp in webApplicationCollection)
            {
                try
                {
                    CheckWebApp(webApp);
                    if (stopAtFirstHit && activationsFound > 0)
                    {
                        return;
                    }
                }
                catch (Exception exc)
                {
                    OnException(exc,
                                "Exception checking webapp: " + LocationInfo.SafeGetWebAppUrl(webApp)
                                );
                }

                try
                {
                    // check all sites and everything under
                    EnumerateWebAppSites(webApp);
                    if (stopAtFirstHit && activationsFound > 0)
                    {
                        return;
                    }
                }
                catch (Exception exc)
                {
                    OnException(exc,
                                "Exception enumerating sites of webapp: " + LocationInfo.SafeGetWebAppUrl(webApp)
                                );
                }
            }
            return;
        }
Ejemplo n.º 11
0
        public override IEnumerable <SPDGWebApplication> GetWebApplications()
        {
            List <SPDGWebApplication> webApps = new List <SPDGWebApplication>();

            runAs(() =>
            {
                SPWebService spWebService             = SPWebService.ContentService;
                SPWebApplicationCollection webAppColl = spWebService.WebApplications;
                webApps = webAppColl.Select(x => new SPDGWebApplication()
                {
                    Id = x.Id, Name = x.Name
                }).ToList();
            });
            return(webApps);
        }
        private static int ProcessAllFeaturesInFarm(SPWebService farm, IEnumerable <Guid> featureIds, SPFeatureScope scope, bool activate, bool force, out Exception exception)
        {
            var processingCounter = 0;

            exception = null;

            if (farm == null)
            {
                exception = new ArgumentNullException("farm is null");
                return(processingCounter);
            }
            try
            {
                if (scope == SPFeatureScope.Farm || scope == SPFeatureScope.ScopeInvalid)
                {
                    processingCounter += ProcessAllFarmFeaturesInFarm(farm, featureIds, activate, force, out exception);
                }

                if (scope != SPFeatureScope.Farm)
                {
                    SPWebApplicationCollection webApps = FarmRead.GetWebApplicationsContent();

                    if (webApps != null && webApps.Count > 0)
                    {
                        foreach (SPWebApplication wa in webApps)
                        {
                            processingCounter += ProcessAllFeaturesInWebApp(wa, featureIds, scope, activate, force, out exception);
                        }
                    }

                    webApps = FarmRead.GetWebApplicationsAdmin();
                    if (webApps != null && webApps.Count > 0)
                    {
                        foreach (SPWebApplication wa in webApps)
                        {
                            processingCounter += ProcessAllFeaturesInWebApp(wa, featureIds, scope, activate, force, out exception);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            return(processingCounter);
        }
Ejemplo n.º 13
0
        public static IEnumerable <Location> ToLocations(this SPWebApplicationCollection spLocations, string parentId)
        {
            if (spLocations == null)
            {
                // todo log error
                return(null);
            }

            var locations = new List <Location>();

            foreach (SPWebApplication spl in spLocations)
            {
                var l = spl.ToLocation(parentId);
                locations.Add(l);
            }

            return(locations);
        }
Ejemplo n.º 14
0
        public override bool InitializeTask()
        {
            if (!base.InitializeTask())
            {
                return(false);
            }

            logMessage("INIT", "STMR", "Clearing Queue");
            SPWebApplicationCollection _webcolections = GetWebApplications();

            foreach (SPWebApplication webApp in _webcolections)
            {
                var sConn = EPMLiveCore.CoreFunctions.getConnectionString(webApp.Id);
                if (sConn != "")
                {
                    using (var cn = new SqlConnection(sConn))
                    {
                        try
                        {
                            cn.Open();
                            using (var cmd = new SqlCommand("update queue set status = 0, queueserver=NULL where status = 1 and DATEDIFF(HH,dtstarted,getdate()) > 24", cn))
                            {
                                cmd.ExecuteNonQuery();
                            }
                            using (var cmd1 = new SqlCommand("update queue set status = 0, queueserver=NULL where status = 1 and queueserver=@servername", cn))
                            {
                                cmd1.Parameters.Clear();
                                cmd1.Parameters.AddWithValue("@servername", System.Environment.MachineName);
                                cmd1.ExecuteNonQuery();
                            }
                        }
                        catch
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
        public override bool InitializeTask()
        {
            if (!base.InitializeTask())
            {
                return(false);
            }

            SPWebApplicationCollection _webcolections = GetWebApplications();

            foreach (SPWebApplication webApp in _webcolections)
            {
                var sConn = EPMLiveCore.CoreFunctions.getConnectionString(webApp.Id);
                if (sConn != "")
                {
                    using (var cn = new SqlConnection(sConn))
                    {
                        try
                        {
                            cn.Open();
                            using (var cmd = new SqlCommand("update TSqueue set status = 0, queue = NULL where DATEDIFF(HH,DTSTARTED,getdate()) > 24 and (status = 1 OR STATUS = 2)", cn))
                            {
                                cmd.ExecuteNonQuery();
                            }
                            using (var cmd1 = new SqlCommand("update TSqueue set status = 0, queue = NULL where (queue=@servername OR QUEUE like '%-' + @servername) and (status = 1 OR STATUS = 2)", cn))
                            {
                                cmd1.Parameters.Clear();
                                cmd1.Parameters.AddWithValue("@servername", System.Environment.MachineName);
                                cmd1.ExecuteNonQuery();
                            }
                        }
                        catch (Exception exe) { logMessage("ERR", "RUN", exe.Message); }
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 16
0
        private bool IsFeatureActivatedInAnyWebApp(SPWebApplication thisWebApplication, Guid thisFeatureId)
        {
            SPWebService webService = SPWebService.ContentService;

            if (webService == null)
            {
                throw new ApplicationException("Cannot access ContentService");
            }

            SPWebApplicationCollection webApps = webService.WebApplications;

            foreach (SPWebApplication webApp in webApps)
            {
                if (webApp != thisWebApplication)
                {
                    if (webApp.Features[thisFeatureId] != null)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 17
0
        public override void RunTask(CancellationToken token)
        {
            try
            {
                SPWebApplicationCollection _webcolections = GetWebApplications();
                foreach (SPWebApplication webApp in _webcolections)
                {
                    string sConn = EPMLiveCore.CoreFunctions.getConnectionString(webApp.Id);
                    if (sConn != "")
                    {
                        using (SqlConnection cn = new SqlConnection(sConn))
                        {
                            try
                            {
                                cn.Open();
                                if (queueJobs)
                                {
                                    DateTime newRun = DateTime.Now;
                                    if (newRun.Minute < lastRun.Minute)
                                    {
                                        using (SqlCommand cmd = new SqlCommand("spQueueTimerJobs", cn))
                                        {
                                            cmd.CommandType = System.Data.CommandType.StoredProcedure;
                                            cmd.ExecuteNonQuery();
                                        }
                                    }
                                    lastRun = newRun.AddHours(1).AddMinutes(-newRun.Minute - 1);
                                }
                                using (SqlCommand cmd = new SqlCommand("spTimerGetQueue", cn))
                                {
                                    cmd.CommandType = CommandType.StoredProcedure;
                                    cmd.Parameters.AddWithValue("@servername", System.Environment.MachineName);
                                    cmd.Parameters.AddWithValue("@maxthreads", MaxThreads);
                                    cmd.Parameters.AddWithValue("@minPriority", highPriority? 0:10);
                                    cmd.Parameters.AddWithValue("@maxPriority", highPriority? 10:99);

                                    DataSet ds = new DataSet();
                                    using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                                    {
                                        da.Fill(ds);
                                        int processed = 0;
                                        foreach (DataRow dr in ds.Tables[0].Rows)
                                        {
                                            RunnerData rd = new RunnerData();
                                            rd.cn = sConn;
                                            rd.dr = dr;

                                            if (StartProcess(rd))
                                            {
                                                using (SqlCommand cmd1 = new SqlCommand("UPDATE queue set status=1, dtstarted = GETDATE() where queueuid=@id", cn))
                                                {
                                                    cmd1.Parameters.Clear();
                                                    cmd1.Parameters.AddWithValue("@id", dr["queueuid"].ToString());
                                                    cmd1.ExecuteNonQuery();
                                                }
                                                processed++;
                                            }

                                            token.ThrowIfCancellationRequested();
                                        }
                                        if (processed > 0)
                                        {
                                            logMessage("HTBT", "PRCS", "Processed " + processed + " jobs");
                                        }
                                    }
                                }
                            }
                            catch (Exception ex) when(!(ex is OperationCanceledException))
                            {
                                logMessage("ERR", "RUNT", ex.ToString());
                            }
                        }
                    }
                }
            }
            catch (Exception ex) when(!(ex is OperationCanceledException))
            {
                logMessage("ERR", "RUNT", ex.ToString());
            }
        }
Ejemplo n.º 18
0
        private static SPWebApplication FindWebApplication(WebApplicationDefinition definition, SPWebApplicationCollection webApps)
        {
            var existingWebApp = webApps.FirstOrDefault(w =>
            {
                var webAppUri = w.GetResponseUri(SPUrlZone.Default);

                return(webAppUri.Port == definition.Port);
            });

            return(existingWebApp);
        }
        public override void RunTask(CancellationToken token)
        {
            try
            {
                SPWebApplicationCollection _webcolections = GetWebApplications();
                foreach (SPWebApplication webApp in _webcolections)
                {
                    string sConn = EPMLiveCore.CoreFunctions.getConnectionString(webApp.Id);
                    if (sConn != "")
                    {
                        using (SqlConnection cn = new SqlConnection(sConn))
                        {
                            try
                            {
                                cn.Open();
                                using (SqlCommand cmd = new SqlCommand("spINTGetQueue", cn))
                                {
                                    cmd.CommandType = CommandType.StoredProcedure;
                                    cmd.Parameters.AddWithValue("@servername", System.Environment.MachineName);
                                    DataSet ds = new DataSet();
                                    using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                                    {
                                        da.Fill(ds);
                                        int processed = 0;
                                        foreach (DataRow dr in ds.Tables[0].Rows)
                                        {
                                            RunnerData rd = new RunnerData();
                                            rd.cn = sConn;
                                            rd.dr = dr;
                                            if (StartProcess(rd))
                                            {
                                                using (SqlCommand cmd1 = new SqlCommand("UPDATE INT_EVENTS set status=1 where INT_EVENT_ID=@id", cn))
                                                {
                                                    cmd1.Parameters.Clear();
                                                    cmd1.Parameters.AddWithValue("@id", dr["INT_EVENT_ID"].ToString());
                                                    cmd1.ExecuteNonQuery();
                                                }
                                                processed++;
                                            }
                                            token.ThrowIfCancellationRequested();
                                        }
                                        if (processed > 0)
                                        {
                                            logMessage("HTBT", "PRCS", "Processed " + processed + " jobs");
                                        }

                                        using (SqlCommand cmd2 = new SqlCommand("delete from INT_EVENTS where DateAdd(day, 1, EVENT_TIME) < GETDATE()", cn))
                                        {
                                            cmd.ExecuteNonQuery();
                                        }
                                    }
                                }
                            }
                            catch (Exception ex) when(!(ex is OperationCanceledException))
                            {
                                logMessage("ERR", "RUNT", ex.Message);
                            }
                        }
                    }
                }
            }
            catch (Exception ex) when(!(ex is OperationCanceledException))
            {
                logMessage("ERR", "RUNT", ex.Message);
            }
        }
 private void PopulateTreeViewForWebApps(TreeNodeCollection treeNodes, SPWebApplicationCollection webApps)
 {
     foreach (SPWebApplication application in webApps)
       {
     WebApplicationInfo webAppInfo = new WebApplicationInfo(application, false);
     ExtendedTreeNode webAppTreeNode = ExtendedTreeNode.AddNewExtendedTreeNode(treeNodes, webAppInfo.ToString(), true, webAppInfo);
     webAppTreeNode.TreeNodePopulate += new ExtendedTreeNode.TreeNodeEventHandler(WebAppTreeNode_TreeNodePopulate);
       }
 }
Ejemplo n.º 21
0
        public override void RunTask(CancellationToken token)
        {
            try
            {
                SPWebApplicationCollection _webcolections = GetWebApplications();
                foreach (SPWebApplication webApp in _webcolections)
                {
                    string sConn = EPMLiveCore.CoreFunctions.getConnectionString(webApp.Id);
                    if (sConn != "")
                    {
                        using (var cn = new SqlConnection(sConn))
                        {
                            try
                            {
                                cn.Open();

                                using (var cmd = new SqlCommand("spSecGetQueue", cn))
                                {
                                    cmd.CommandType = CommandType.StoredProcedure;
                                    cmd.Parameters.AddWithValue("@servername", System.Environment.MachineName);
                                    cmd.Parameters.AddWithValue("@maxthreads", MaxThreads);

                                    var ds = new DataSet();
                                    using (var da = new SqlDataAdapter(cmd))
                                    {
                                        da.Fill(ds);
                                        if (ds.Tables.Count > 0)
                                        {
                                            int processed = 0;
                                            foreach (DataRow dr in ds.Tables[0].Rows)
                                            {
                                                var rd = new RunnerData {
                                                    cn = sConn, dr = dr
                                                };

                                                if (StartProcess(rd))
                                                {
                                                    using (var cmd1 = new SqlCommand("UPDATE ITEMSEC set status=2 where ITEM_SEC_ID=@id", cn))
                                                    {
                                                        cmd1.Parameters.Clear();
                                                        cmd1.Parameters.AddWithValue("@id", dr["ITEM_SEC_ID"].ToString());
                                                        cmd1.ExecuteNonQuery();
                                                    }
                                                    processed++;
                                                }

                                                token.ThrowIfCancellationRequested();
                                            }
                                            if (processed > 0)
                                            {
                                                logMessage("HTBT", "PRCS", "Processed " + processed + " jobs");
                                            }
                                        }
                                    }
                                }
                            }
                            catch (Exception ex) when(!(ex is OperationCanceledException))
                            {
                                logMessage("ERR", "RUN", ex.Message);
                            }
                        }
                    }
                }
            }
            catch (Exception ex) when(!(ex is OperationCanceledException))
            {
                logMessage("ERR", "RUN", ex.Message);
            }
        }
        public override void RunTask(CancellationToken token)
        {
            try
            {
                SPWebApplicationCollection _webapplication = GetWebApplications();
                foreach (SPWebApplication webApp in _webapplication)
                {
                    SPSite  site  = null;
                    SPWeb   web   = null;
                    DataSet ds    = new DataSet();
                    string  sConn = EPMLiveCore.CoreFunctions.getConnectionString(webApp.Id);
                    if (sConn != "")
                    {
                        using (SqlConnection cn = new SqlConnection(sConn))
                        {
                            try
                            {
                                cn.Open();

                                using (SqlCommand cmd = new SqlCommand("delete from PERSONALIZATIONS where FK in (select ID from NOTIFICATIONS where DATEADD(mm, 1, CreatedAt) < GETDATE())", cn))
                                {
                                    cmd.ExecuteNonQuery();
                                }

                                using (SqlCommand cmd1 = new SqlCommand("delete from NOTIFICATIONS where DATEADD(mm, 1, CreatedAt) < GETDATE()", cn))
                                {
                                    cmd1.ExecuteNonQuery();
                                }

                                using (var cmd2 = new SqlCommand("spNotificationGetQueue", cn))
                                {
                                    cmd2.CommandType = CommandType.StoredProcedure;
                                    cmd2.Parameters.AddWithValue("@servername", System.Environment.MachineName);

                                    using (SqlDataAdapter da = new SqlDataAdapter(cmd2))
                                    {
                                        da.Fill(ds);

                                        Guid siteid    = Guid.Empty;;
                                        int  processed = 0;
                                        foreach (DataRow dr in ds.Tables[0].Rows)
                                        {
                                            try
                                            {
                                                Guid newsiteid = new Guid(dr["siteid"].ToString());

                                                if (newsiteid != siteid)
                                                {
                                                    if (site != null)
                                                    {
                                                        web.Close();
                                                        site.Close();
                                                    }
                                                    site = new SPSite(newsiteid);
                                                    web  = site.OpenWeb();
                                                }

                                                string body    = dr["Message"].ToString();
                                                string subject = dr["Title"].ToString();

                                                SPUser fromUser = web.SiteUsers.GetByID(int.Parse(dr["createdby"].ToString()));
                                                SPUser toUser   = web.SiteUsers.GetByID(int.Parse(dr["userid"].ToString()));

                                                if (toUser.Email != "")
                                                {
                                                    if (dr["createdby"].ToString() == "1073741823")
                                                    {
                                                        EmailSystem.SendFullEmail(body, subject, true, fromUser, toUser);
                                                    }
                                                    else
                                                    {
                                                        EmailSystem.SendFullEmail(body, subject, false, fromUser, toUser);
                                                    }
                                                }
                                            }
                                            catch (Exception ex)
                                            {
                                                logMessage("ERR", "NOTIFICATIONS", ex.Message);
                                            }

                                            using (SqlCommand cmd3 = new SqlCommand("spNSetBit", cn))
                                            {
                                                cmd3.CommandType = CommandType.StoredProcedure;
                                                cmd3.Parameters.AddWithValue("@FK", dr["FK"].ToString());
                                                cmd3.Parameters.AddWithValue("@userid", dr["userid"].ToString());
                                                cmd3.Parameters.AddWithValue("@index", 1);
                                                cmd3.Parameters.AddWithValue("@val", 1);
                                                cmd3.ExecuteNonQuery();
                                            }
                                            processed++;
                                            token.ThrowIfCancellationRequested();
                                        }
                                        if (processed > 0)
                                        {
                                            logMessage("HTBT", "PRCS", "Processed " + processed + " jobs");
                                        }
                                    }
                                }
                            }
                            catch (Exception ex) when(!(ex is OperationCanceledException))
                            {
                                logMessage("ERR", "RUNT", ex.Message);
                            }
                            finally
                            {
                                if (site != null)
                                {
                                    web.Close();
                                    site.Close();
                                }
                                ds.Dispose();
                            }
                        }
                    }
                }
            }
            catch (Exception ex) when(!(ex is OperationCanceledException))
            {
                logMessage("ERR", "RUNT", ex.Message);
            }
        }