public void DeleteFirstTimerJob(SPWeb web)
 {
     try
     {
         SPJobDefinition objFirstTimerJob = web.Site.WebApplication.JobDefinitions["$safeprojectname$ First Timer Job"];
         if (objFirstTimerJob != null)
         {
             objFirstTimerJob.Delete();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
            protected static void RemoveExistingJob(SPSolution solution)
            {
                if (solution.JobStatus == SPRunningJobStatus.Initialized)
                {
                    throw new InstallException(res.DoubleDeployment);
                }

                SPJobDefinition jobDefinition = GetSolutionJob(solution);

                if (jobDefinition != null)
                {
                    jobDefinition.Delete();
                    Thread.Sleep(500);
                }
            }
コード例 #3
0
ファイル: Installer.cs プロジェクト: keutmann/wspbuilder
        /// <summary>
        /// Kills previously scheduled jobs for a solution
        /// </summary>
        /// <param name="solution">solution to kill jobs on</param>
        private void KillRunningJobs(SPSolution solution)
        {
            if (solution == null)
            {
                return;
            }

            try
            {
                if (solution.JobExists)
                {
                    // is the job already running
                    if (solution.JobStatus == SPRunningJobStatus.Initialized)
                    {
                        throw new Exception("A deployment job already running for this solution.");
                    }

                    // find the running job
                    SPJobDefinition definition = null;
                    foreach (SPJobDefinition jobdefs in SPFarm.Local.TimerService.JobDefinitions)
                    {
                        if ((jobdefs.Title != null) && jobdefs.Title.Contains(solution.Name))
                        {
                            definition = jobdefs;
                            break;
                        }
                    }

                    if (definition != null)
                    {
                        definition.Delete();    // kill if it was found
                        Thread.Sleep(1000);     // give it time to delete
                    }
                }
            }
            catch (Exception ee)
            {
                throw new Exception("Error while trying to kill running jobs.", ee);
            }
        }
コード例 #4
0
        public void DeleteIfExistJob()
        {
            // THE ORIGINAL VALUE OF REMOTE ADMINISTRATOR
            var remoteAdministratorAccessDenied = SPWebService.ContentService.RemoteAdministratorAccessDenied;

            try
            {
                // SET THE REMOTE ADMINISTATOR ACCESS DENIED FALSE
                SPWebService.ContentService.RemoteAdministratorAccessDenied = false;
                // delete the custom timer job if it exists

                SPJobDefinition existsJob = WebApplication.JobDefinitions.SingleOrDefault(x => x.Name.Equals(_jobName));
                if (existsJob != null)
                {
                    existsJob.Delete();
                }
            }
            finally
            {
                // SET THE REMOTE ADMINISTATOR ACCESS DENIED BACK WHAT
                // IT WAS
                SPWebService.ContentService.RemoteAdministratorAccessDenied = remoteAdministratorAccessDenied;
            }
        }
コード例 #5
0
        private void CreateJobs_DocIcons(DocIconType docType, string key, string value, string editText, string openControl, bool delete)
        {
            if (webApp != null)
            {
                string serviceName = "WSS_Administration";
                SPFarm farm        = SPFarm.Local;

                WebSiteDocItemModifier docJob = null;

                foreach (SPService service in farm.Services)
                {
                    if (service.Name == serviceName)
                    {
                        docJob = new WebSiteDocItemModifier(service, docType, key, value, editText, openControl, delete);

                        SPJobDefinition def = service.GetJobDefinitionByName(docJob.Name);
                        if (def != null)
                        {
                            def.Delete();
                        }

                        break;
                    }
                }

                docJob.Schedule = new SPOneTimeSchedule(DateTime.Now);
                docJob.Title    = string.Format("Modify {0} Icon for Mapping {1} in {2} section.", value, key, docType.ToString());
                docJob.Update();
                DateTime runtime;
                DateTime.TryParse(docJob.LastRunTime.ToString(), out runtime);
                while (runtime != null && (runtime == DateTime.MinValue || runtime == DateTime.MaxValue))
                {
                    DateTime.TryParse(docJob.LastRunTime.ToString(), out runtime);
                }
            }
        }