Esempio n. 1
0
        /// <summary>
        /// The create job.
        /// </summary>
        /// <param name="site">
        /// The site.
        /// </param>
        /// <param name="workItemType">
        /// The work item type.
        /// </param>
        /// <returns>
        /// The <see cref="Guid"/>.
        /// </returns>
        public Guid CreateJob(SPSite site, Guid workItemType)
        {
            var rootWeb = site.RootWeb;

            var workItemId = site.AddWorkItem(Guid.NewGuid(), DateTime.Now.ToUniversalTime(), workItemType, rootWeb.ID, site.ID, 1, false, Guid.Empty, Guid.Empty, rootWeb.CurrentUser.ID, null, string.Empty, Guid.Empty, false);
            return workItemId;
        }
Esempio n. 2
0
        public void Log(string message, LogLevel level)
        {
            var logText = string.Format("[{0}]\t{1} - {2}", level, DateTime.Now, message);

            try
            {
                SPSite site = _runtime.IronHive.Site;

                site.AddWorkItem(Guid.NewGuid(),
                                 DateTime.UtcNow,
                                 IronLogWorkItemJobDefinition.WorkItemGuid,
                                 site.RootWeb.ID,
                                 site.ID,
                                 1,
                                 false,
                                 site.RootWeb.GetList(site.RootWeb.ServerRelativeUrl + "/" + IronConstant.IronLogsListPath).ID,
                                 Guid.Empty,
                                 site.SystemAccount.ID,
                                 null,
                                 logText,
                                 Guid.Empty
                                 );
            }
            catch
            {
            }
        }
Esempio n. 3
0
        private static void CreateReloadCacheTimer(SPSite currentSite, SPWeb currentWeb, string cmd)
        {
            string cmdParameters = currentWeb.Url + "-#####-" + cmd;

            currentSite.AddWorkItem(Guid.Empty, DateTime.Now.ToUniversalTime(), new Guid(WorkItemId), currentWeb.ID,
                                    currentWeb.ID, 1, false, Guid.Empty, Guid.Empty, currentWeb.CurrentUser.ID, null, cmdParameters, Guid.Empty);
        }
Esempio n. 4
0
        /// <summary>
        /// An item was added.
        /// </summary>
        public override void ItemAdded(SPItemEventProperties properties)
        {
            Guid siteId = properties.SiteId;
            Guid webId  = properties.Web.ID;
            Guid listId = properties.ListId;
            int  itemId = properties.ListItemId;
            //var context = SPContext.GetContext(properties.Web);
            Guid itemUniqueId  = properties.ListItem.UniqueId;
            int  currentUserId = properties.CurrentUserId;

            SPSecurity.RunWithElevatedPrivileges(() =>
            {
                using (SPSite site = new SPSite(siteId))
                {
                    site.AddWorkItem(Guid.NewGuid(),
                                     DateTime.Now.ToUniversalTime(),
                                     SubWorkItemJob.WorkItemTypeId,
                                     webId,
                                     listId,
                                     itemId,
                                     true,
                                     itemUniqueId,
                                     itemUniqueId,
                                     currentUserId,
                                     null,
                                     "Pass this message to the timer job.",
                                     Guid.Empty);
                }
            });
        }
Esempio n. 5
0
        private void CreateWorkItem(SPWebEventProperties properties, string fullClass, string fullAssembly)
        {
            Guid   siteId      = properties.SiteId;
            Guid   webId       = properties.WebId;
            string _modulename = fullClass;
            string _assembly   = fullAssembly;


            SPSecurity.RunWithElevatedPrivileges(() =>
            {
                using (SPSite site = new SPSite(siteId))
                {
                    site.AddWorkItem(
                        Guid.NewGuid(),
                        DateTime.Now.ToUniversalTime(),
                        WebSiteControllerModuleWorkItem.WorkItemTypeId,
                        webId,
                        siteId,
                        1,
                        true,
                        Guid.Empty,
                        Guid.Empty,
                        site.SystemAccount.ID,
                        null,
                        _modulename + ";" + _assembly,
                        Guid.Empty
                        );
                }
            });
        }
Esempio n. 6
0
        /// <summary>
        /// The create job.
        /// </summary>
        /// <param name="site">
        /// The site.
        /// </param>
        /// <param name="workItemType">
        /// The work item type.
        /// </param>
        /// <returns>
        /// The <see cref="Guid"/>.
        /// </returns>
        public Guid CreateJob(SPSite site, Guid workItemType)
        {
            var rootWeb = site.RootWeb;

            var workItemId = site.AddWorkItem(Guid.NewGuid(), DateTime.Now.ToUniversalTime(), workItemType, rootWeb.ID, site.ID, 1, false, Guid.Empty, Guid.Empty, rootWeb.CurrentUser.ID, null, string.Empty, Guid.Empty, false);

            return(workItemId);
        }
Esempio n. 7
0
 private static void AddCleanupWorkitemAux(SPSite site, SPWeb web, Guid listId)
 {
     site.AddWorkItem(
         new Guid(), DateTime.UtcNow, Constants.WorkItemType,
         web.ID, listId, -1,
         true, new Guid(), web.ID,
         web.CurrentUser.ID, null, null, new Guid());
 }
Esempio n. 8
0
        /// <summary>
        /// Binds to selected row and sends the id cell (0) to
        /// Utils.DeleteEntry for deletion based in the entryID
        /// </summary>
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            pnl_wait.Attributes["style"] = "";
            Button      btn    = (Button)sender;
            GridViewRow grdRow = (GridViewRow)btn.Parent.Parent;

            Guid id = new Guid(grdRow.Cells[0].Text);

            SPSite site = SPContext.Current.Site;

            SPSecurity.RunWithElevatedPrivileges(() =>
            {
                try
                {
                    Guid siteId = site.ID;
                    Guid webId  = SPContext.Current.Web.ID;
                    int itemId  = SPContext.Current.ItemId;

                    WebSiteControllerRule rule = WebSiteControllerConfig.GetRule(site.WebApplication, id);

                    using (SPSite wsite = new SPSite(siteId))
                    {
                        site.AddWorkItem(
                            Guid.NewGuid(),
                            DateTime.Now.ToUniversalTime(),
                            WebSiteControllerRuleWorkItem.WorkItemTypeId,
                            webId,
                            siteId,
                            itemId,
                            true,
                            rule.Id,
                            Guid.Empty,
                            site.SystemAccount.ID,
                            null,
                            string.Empty,
                            Guid.Empty
                            );
                    }

                    /*
                     * rule.Delete();
                     * rule.Unprovision();
                     * rule.Uncache();
                     */
                }
                catch (Exception ex)
                {
                    SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                    //ex.ToString();
                }
            });

            Response.Redirect(Request.RawUrl, true);
        }
Esempio n. 9
0
        private void CreateWorkItem(SPWeb web, string fullClass, string fullAssembly)
        {
            //SPSite tsite = properties.Feature.Parent as SPSite;

            Guid   siteId      = web.Site.ID;
            Guid   webId       = web.ID;
            string _modulename = fullClass;
            string _assembly   = fullAssembly;


            SPSecurity.RunWithElevatedPrivileges(() =>
            {
                using (SPSite site = new SPSite(siteId))
                {
                    site.AddWorkItem(
                        Guid.NewGuid(),
                        DateTime.Now.ToUniversalTime(),
                        WebSiteControllerModuleWorkItem.WorkItemTypeId,
                        webId,
                        siteId,
                        1,
                        true,
                        Guid.Empty,
                        Guid.Empty,
                        site.SystemAccount.ID,
                        null,
                        _modulename + ";" + _assembly,
                        Guid.Empty
                        );
                }
            });

            try
            {
                WebSiteControllerModuleWorkItem WebSiteControllerModuleJob = new WebSiteControllerModuleWorkItem(WebSiteControllerModuleWorkItem.WorkItemJobDisplayName + "HomePage", web.Site.WebApplication);
                SPOneTimeSchedule oneTimeSchedule = new SPOneTimeSchedule(DateTime.Now);

                WebSiteControllerModuleJob.Schedule = oneTimeSchedule;
                WebSiteControllerModuleJob.Update();
            }
            catch (Exception ex)
            {
                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                //ex.ToString();
            }
        }
Esempio n. 10
0
        private void CreateWorkItem()
        {
            Guid siteId = SPContext.Current.Site.ID;
            Guid webId  = SPContext.Current.Web.ID;

            SPSecurity.RunWithElevatedPrivileges(() =>
            {
                using (SPSite site = new SPSite(siteId))
                {
                    site.AddWorkItem(
                        Guid.NewGuid(),
                        DateTime.Now.ToUniversalTime(),
                        WebSiteControllerModuleWorkItem.WorkItemTypeId,
                        webId,
                        siteId,
                        1,
                        true,
                        _guid,
                        Guid.Empty,
                        site.SystemAccount.ID,
                        null,
                        _modulename + ";" + _assembly,
                        Guid.Empty
                        );

                    SPJobDefinitionCollection jobs = site.WebApplication.JobDefinitions;

                    foreach (SPJobDefinition job in jobs)
                    {
                        if (job.Name == WebSiteControllerModuleWorkItem.WorkItemJobDisplayName)
                        {
                            DateTime next = job.Schedule.NextOccurrence(job.LastRunTime);
                            _seconds      = next.Second.ToString();

                            break;
                        }
                    }

                    //SPJobDefinition job = site.WebApplication.JobDefinitions[WebSiteControllerModuleWorkItem.WorkItemJobDisplayName];
                    //job.RunNow();
                }
            });
        }
Esempio n. 11
0
        private void CreateWorkItem(SPWebEventProperties properties)
        {
            Guid   siteId = properties.SiteId;
            Guid   webId  = properties.WebId;
            string url    = properties.ServerRelativeUrl;

            if (url.StartsWith("/"))
            {
                url = url.Remove(0, 1);
            }

            bool disabled = false;
            WebSiteControllerPrincipalType principalType = WebSiteControllerPrincipalType.None;
            bool   appliesToSSL = true;
            int    sequence     = 1;
            String pricipal     = string.Empty;

            StringBuilder builder = new StringBuilder();

            builder.Append(url + ";");
            builder.Append(disabled.ToString() + ";");
            builder.Append(appliesToSSL.ToString() + ";");
            builder.Append(sequence.ToString() + ";");
            builder.Append(principalType.ToString() + ";");
            builder.Append(pricipal + ";");
            builder.Append("#");

            builder.Append(String.Format("{0}:{1};", "OriginalUrl", url + "/default.aspx"));

            string full = builder.ToString();

            Guid itemGuid = new Guid("386577D9-0777-4AD3-A90A-C240D8B0A49E");
            int  item     = -1;

            SPSecurity.RunWithElevatedPrivileges(() =>
            {
                using (SPSite site = new SPSite(siteId))
                {
                    site.AddWorkItem(
                        Guid.NewGuid(),
                        DateTime.Now.ToUniversalTime(),
                        WebSiteControllerRuleWorkItem.WorkItemTypeId,
                        webId,
                        siteId,
                        item,
                        true,
                        itemGuid,
                        Guid.Empty,
                        site.SystemAccount.ID,
                        null,
                        builder.ToString(),
                        Guid.Empty
                        );
                }
            });

            SPJobDefinitionCollection jobs = properties.Web.Site.WebApplication.JobDefinitions;
            int _seconds = 0;

            foreach (SPJobDefinition job in jobs)
            {
                if (job.Name == WebSiteControllerRuleWorkItem.WorkItemJobDisplayName)
                {
                    DateTime next = job.Schedule.NextOccurrence(job.LastRunTime);
                    _seconds = next.Millisecond;
                    break;
                }
            }

            //System.Threading.Thread.Sleep(_seconds);
        }
        private void CreateWorkItem(WebSiteControllerRule rule, string url)
        {
            Guid siteId = SPContext.Current.Site.ID;
            Guid webId  = SPContext.Current.Web.ID;

            if (url.StartsWith("/"))
            {
                url = url.TrimStart('/');
            }

            StringBuilder builder = new StringBuilder();

            builder.Append(SPContext.Current.Web.ServerRelativeUrl + ";");
            builder.Append(rule.IsDisabled.ToString() + ";");
            builder.Append(rule.AppliesToSsl.ToString() + ";");
            builder.Append(rule.Sequence.ToString() + ";");
            builder.Append(rule.PrincipalType + ";");
            builder.Append(rule.Principal + ";");
            builder.Append("#");
            builder.Append(String.Format("{0}:{1};", "OriginalUrl", "/" + url));

            int item = 2;

            SPSecurity.RunWithElevatedPrivileges(() =>
            {
                using (SPSite site = new SPSite(siteId))
                {
                    site.AddWorkItem(
                        Guid.NewGuid(),
                        DateTime.Now.ToUniversalTime(),
                        WebSiteControllerRuleWorkItem.WorkItemTypeId,
                        webId,
                        siteId,
                        item,
                        true,
                        rule.Id,
                        Guid.Empty,
                        site.SystemAccount.ID,
                        null,
                        builder.ToString(),
                        Guid.Empty
                        );
                }
            });

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(siteId))//, SPUserToken.SystemAccount))
                {
                    try
                    {
                        WebSiteControllerRuleWorkItem WebSiteControllerModuleJob = new WebSiteControllerRuleWorkItem(WebSiteControllerRuleWorkItem.WorkItemJobDisplayName + "HomePage", site.WebApplication);
                        SPOneTimeSchedule oneTimeSchedule = new SPOneTimeSchedule(DateTime.Now);

                        WebSiteControllerModuleJob.Schedule = oneTimeSchedule;
                        WebSiteControllerModuleJob.Update();
                    }
                    catch { };
                }
            });
        }
        private void CreateWorkItem(string url)
        {
            Guid siteId = SPContext.Current.Site.ID;
            Guid webId  = SPContext.Current.Web.ID;

            bool disabled = false;
            WebSiteControllerPrincipalType principalType = WebSiteControllerPrincipalType.None;
            bool   appliesToSSL = true;
            int    sequence     = 1;
            String pricipal     = string.Empty;

            StringBuilder builder = new StringBuilder();

            builder.Append(SPContext.Current.Web.ServerRelativeUrl + ";");
            builder.Append(disabled.ToString() + ";");
            builder.Append(appliesToSSL.ToString() + ";");
            builder.Append(sequence.ToString() + ";");
            builder.Append(principalType.ToString() + ";");
            builder.Append(pricipal + ";");
            builder.Append("#");

            builder.Append(String.Format("{0}:{1};", "OriginalUrl", url));

            string full = builder.ToString();

            SemanticModule           mod  = new SemanticModule();
            IWebSiteControllerModule imod = null;// WebSiteControllerConfig.GetModule(web.Site.WebApplication, mod.RuleType);

            while (imod == null)
            {
                System.Threading.Thread.Sleep(1000);
                try
                {
                    imod = WebSiteControllerConfig.GetModule(SPContext.Current.Site.WebApplication, mod.RuleType);
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
            }


            int item = -1;

            SPSecurity.RunWithElevatedPrivileges(() =>
            {
                using (SPSite site = new SPSite(siteId))
                {
                    site.AddWorkItem(
                        Guid.NewGuid(),
                        DateTime.Now.ToUniversalTime(),
                        WebSiteControllerRuleWorkItem.WorkItemTypeId,
                        webId,
                        siteId,
                        item,
                        true,
                        imod.Id,
                        Guid.Empty,
                        site.SystemAccount.ID,
                        null,
                        builder.ToString(),
                        Guid.Empty
                        );
                }
            });

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(siteId))//, SPUserToken.SystemAccount))
                {
                    try
                    {
                        WebSiteControllerRuleWorkItem WebSiteControllerModuleJob = new WebSiteControllerRuleWorkItem(WebSiteControllerRuleWorkItem.WorkItemJobDisplayName + "HomePage", site.WebApplication);
                        SPOneTimeSchedule oneTimeSchedule = new SPOneTimeSchedule(DateTime.Now);

                        WebSiteControllerModuleJob.Schedule = oneTimeSchedule;
                        WebSiteControllerModuleJob.Update();
                    }
                    catch { };
                }
            });
        }
Esempio n. 14
0
        private void CreateWorkItem(SPWebEventProperties properties, string pagename, string url)
        {
            Guid siteId = properties.SiteId;
            Guid webId  = properties.WebId;

            bool disabled = false;
            WebSiteControllerPrincipalType principalType = WebSiteControllerPrincipalType.None;
            bool   appliesToSSL = true;
            int    sequence     = 1;
            String pricipal     = string.Empty;

            StringBuilder builder = new StringBuilder();

            builder.Append(properties.Web.ServerRelativeUrl + url + ";");
            builder.Append(disabled.ToString() + ";");
            builder.Append(appliesToSSL.ToString() + ";");
            builder.Append(sequence.ToString() + ";");
            builder.Append(principalType.ToString() + ";");
            builder.Append(pricipal + ";");
            builder.Append("#");

            builder.Append(String.Format("{0}:{1};", "OriginalUrl", properties.Web.ServerRelativeUrl + pagename));

            string full = builder.ToString();

            IWebSiteControllerModule imod = null;
            SPSite parentsite             = new SPSite(properties.SiteId);

            while (imod == null)
            {
                System.Threading.Thread.Sleep(1000);
                try
                {
                    imod = WebSiteControllerConfig.GetModule(parentsite.WebApplication, "Hemrika.SharePoint.WebSite.Modules.SemanticModule.SemanticModule");
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
            }

            int item = -1;

            SPSecurity.RunWithElevatedPrivileges(() =>
            {
                using (SPSite site = new SPSite(siteId))
                {
                    site.AddWorkItem(
                        Guid.NewGuid(),
                        DateTime.Now.ToUniversalTime(),
                        WebSiteControllerRuleWorkItem.WorkItemTypeId,
                        webId,
                        siteId,
                        item,
                        true,
                        imod.Id,
                        Guid.Empty,
                        site.SystemAccount.ID,
                        null,
                        builder.ToString(),
                        Guid.Empty
                        );
                }
            });
        }
Esempio n. 15
0
        /// <summary>
        /// Creates an ExportJob and schedules the WorkItem for the timer job that processes the exports.
        /// </summary>
        /// <param name="domainUid">The DominUid for the map being exported</param>
        /// <param name="rootMapUid">The RootMapUid for the map being exported</param>
        /// <param name="exportProperties">The export properties for the export</param>
        /// <param name="mapType">The map type (schema) for the map being exported</param>
        /// <param name="exportType">The output format for the export</param>
        /// <returns>The ExportJob that was created</returns>
        public ExportJobResponse CreateExportJob(Guid domainUid, Guid rootMapUid, IDictionary <string, string> exportProperties, MapType mapType, ExportType exportType)
        {
            ExportJobResponse response = new ExportJobResponse();

            try
            {
                Guid   webID       = SPContext.Current.Web.ID;
                Guid   siteID      = SPContext.Current.Site.ID;
                SPUser currentUser = null;
                using (SPSite site = new SPSite(siteID))
                {
                    using (SPWeb web = site.OpenWeb(webID))
                    {
                        if (web != null)
                        {
                            currentUser = web.CurrentUser;
                        }
                    }
                }
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    int userId         = -1;
                    SPList exportsList = null;
                    int listItemIdNum  = -1;

                    using (SPSite site = new SPSite(siteID))
                    {
                        using (SPWeb web = site.OpenWeb(webID))
                        {
                            if (web != null)
                            {
                                if (currentUser == null)
                                {
                                    //The current user shouldn't be null, it should have been resolved outside of this RunWithElevatedPrivileges delegate
                                    currentUser = web.CurrentUser;
                                }
                                if (currentUser != null)
                                {
                                    userId = currentUser.ID;

                                    exportsList = web.TryGetList(web.GetServerRelativeListUrlPrefix() + "GlymaExports"); //TODO get the name from a constant
                                    if (exportsList != null)
                                    {
                                        //the text payload will contain the properties serialized into a simple XML format
                                        ExportPropertiesDictionary serializableDict = new ExportPropertiesDictionary(exportProperties);
                                        string textPayload = serializableDict.ConvertToXml();

                                        Guid workItemId = Guid.NewGuid(); // Create a unique id for the work item and export job
                                        listItemIdNum   = CreateExportJobListEntry(exportsList, domainUid, rootMapUid, mapType, exportType, workItemId, textPayload, userId);

                                        // if the list item was created then create the export job, if it wasn't it was because an export
                                        // for this particular root map of this type was already scheduled (changing the properties doesn't have effect)
                                        if (listItemIdNum != -1)
                                        {
                                            site.AddWorkItem(workItemId,                                            //gWorkItemId - A Guid that identifies the work item
                                                             DateTime.Now.ToUniversalTime(),                        //schdDateTime - represents a time in universal time for when the work item should take place
                                                             GlymaExportWorkItemTimerJob.WorkItemTypeId,            //gWorkItemType - this must be the GUID used in the GlymaExportWorkItemTimerJob
                                                             web.ID,                                                //gWebId - The identifier of the web containing the list
                                                             exportsList.ID,                                        //gParentId - The list ID
                                                             listItemIdNum,                                         //nItemId - The list item ID number
                                                             true,                                                  //fSetWebId - true to set the Web identifier
                                                             exportsList.Items.GetItemById(listItemIdNum).UniqueId, //gItemGuid - The unique identifier of the list item
                                                             domainUid,                                             //gBatchId - A Guid context identifier for the work item engine
                                                             userId,                                                //nUserId - SPUser ID number
                                                             null,                                                  //rgbBinaryPayload - not used
                                                             textPayload,                                           //strTextPayload
                                                             Guid.Empty);                                           //gProcessingId - needs to be Guid.Empty

                                            ExportJob scheduledJob = new ExportJob();
                                            scheduledJob.Created   = (DateTime)exportsList.Items.GetItemById(listItemIdNum)[SPBuiltInFieldId.Created];
                                            scheduledJob.CreatedBy = new GlymaUser()
                                            {
                                                Name = currentUser.Name
                                            };
                                            scheduledJob.Id                 = workItemId;
                                            scheduledJob.IsCurrent          = true;
                                            scheduledJob.Status             = ExportStatus.Scheduled;
                                            scheduledJob.Type               = exportType;
                                            scheduledJob.MapType            = mapType;
                                            scheduledJob.ExportProperties   = exportProperties;
                                            scheduledJob.PercentageComplete = 0;
                                            response.ExportJob              = scheduledJob;
                                        }
                                        else
                                        {
                                            //already scheduled so throw an exception to be handled with an error
                                            throw new Exception(string.Format("A scheduled export job already exists for the Glyma map: DomainUid: {0}, RootMapUid: {1}, Export Type: {2}, Map Type: {3}",
                                                                              domainUid.ToString(), rootMapUid.ToString(), exportType.ToString(), mapType.ToString()));
                                        }
                                    }
                                    else
                                    {
                                        throw new Exception("Failed to find the Glyma Exports list.");
                                    }
                                }
                                else
                                {
                                    throw new Exception("The current user was not able to be determined.");
                                }
                            }
                            else
                            {
                                throw new Exception("The SPSite and/or the SPWeb were null.");
                            }
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                ExportError error = new ExportError()
                {
                    ErrorMessage = "Failed to create the Glyma map export job."
                };
                throw new FaultException <ExportError>(error, ex.ToString());
            }

            return(response);
        }
Esempio n. 16
0
        private void CreateWorkItem(SPWeb web)//, HttpStatusCode code)
        {
            Guid siteId = web.Site.ID;
            Guid webId  = web.ID;

            bool disabled = false;
            WebSiteControllerPrincipalType principalType = WebSiteControllerPrincipalType.None;
            bool   appliesToSSL = true;
            int    sequence     = 1;
            String pricipal     = string.Empty;

            StringBuilder builder = new StringBuilder();

            builder.Append("/;");
            builder.Append(disabled.ToString() + ";");
            builder.Append(appliesToSSL.ToString() + ";");
            builder.Append(sequence.ToString() + ";");
            builder.Append(principalType.ToString() + ";");
            builder.Append(pricipal + ";");
            builder.Append("#");

            string value = new JavaScriptSerializer().Serialize(this);

            builder.Append(String.Format("{0}:{1};", "GateKeeper", Encryption.Encrypt(value)));
            //builder.Append(value);

            string full = builder.ToString();

            GateKeeperModule         mod  = new GateKeeperModule();
            IWebSiteControllerModule imod = null;  //WebSiteControllerConfig.GetModule(web.Site.WebApplication, mod.RuleType);

            while (imod == null)
            {
                try
                {
                    imod = WebSiteControllerConfig.GetModule(web.Site.WebApplication, mod.RuleType);
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
                System.Threading.Thread.Sleep(1000);
            }

            Guid itemGuid = _guid;
            int  item     = 0;

            if (itemGuid.Equals(Guid.Empty))
            {
                itemGuid = mod.Id;
                item     = -1;
            }
            else
            {
                item = 2;
            }

            SPSecurity.RunWithElevatedPrivileges(() =>
            {
                using (SPSite site = new SPSite(siteId))
                {
                    site.AddWorkItem(
                        Guid.NewGuid(),
                        DateTime.Now.ToUniversalTime(),
                        WebSiteControllerRuleWorkItem.WorkItemTypeId,
                        webId,
                        siteId,
                        item,
                        true,
                        itemGuid,
                        Guid.Empty,
                        site.SystemAccount.ID,
                        null,
                        builder.ToString(),
                        Guid.Empty
                        );
                }
            });
        }
Esempio n. 17
0
        /// <summary>
        /// Creates an ExportJob and schedules the WorkItem for the timer job that processes the exports.
        /// </summary>
        /// <param name="domainUid">The DominUid for the map being exported</param>
        /// <param name="rootMapUid">The RootMapUid for the map being exported</param>
        /// <param name="exportProperties">The export properties for the export</param>
        /// <param name="mapType">The map type (schema) for the map being exported</param>
        /// <param name="exportType">The output format for the export</param>
        /// <returns>The ExportJob that was created</returns>
        public ExportJobResponse CreateExportJob(Guid domainUid, Guid rootMapUid, IDictionary<string, string> exportProperties, MapType mapType, ExportType exportType)
        {
            ExportJobResponse response = new ExportJobResponse();

            try
            {
                Guid webID = SPContext.Current.Web.ID;
                Guid siteID = SPContext.Current.Site.ID;
                SPUser currentUser = null;
                using (SPSite site = new SPSite(siteID)) 
                {
                    using (SPWeb web = site.OpenWeb(webID))
                    {
                        if (web != null)
                        {
                            currentUser = web.CurrentUser;
                        }
                    }
                }
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    int userId = -1;
                    SPList exportsList = null;
                    int listItemIdNum = -1;
                    
                    using (SPSite site = new SPSite(siteID)) 
                    {
                        using (SPWeb web = site.OpenWeb(webID))
                        {
                            if (web != null)
                            {
                                if (currentUser == null)
                                {
                                    //The current user shouldn't be null, it should have been resolved outside of this RunWithElevatedPrivileges delegate
                                    currentUser = web.CurrentUser;
                                }
                                if (currentUser != null)
                                {
                                    userId = currentUser.ID;

                                    exportsList = web.TryGetList(web.GetServerRelativeListUrlPrefix() + "GlymaExports"); //TODO get the name from a constant
                                    if (exportsList != null)
                                    {

                                        //the text payload will contain the properties serialized into a simple XML format
                                        ExportPropertiesDictionary serializableDict = new ExportPropertiesDictionary(exportProperties);
                                        string textPayload = serializableDict.ConvertToXml();

                                        Guid workItemId = Guid.NewGuid(); // Create a unique id for the work item and export job
                                        listItemIdNum = CreateExportJobListEntry(exportsList, domainUid, rootMapUid, mapType, exportType, workItemId, textPayload, userId);

                                        // if the list item was created then create the export job, if it wasn't it was because an export
                                        // for this particular root map of this type was already scheduled (changing the properties doesn't have effect)
                                        if (listItemIdNum != -1)
                                        {
                                            site.AddWorkItem(workItemId, //gWorkItemId - A Guid that identifies the work item
                                                DateTime.Now.ToUniversalTime(), //schdDateTime - represents a time in universal time for when the work item should take place
                                                GlymaExportWorkItemTimerJob.WorkItemTypeId, //gWorkItemType - this must be the GUID used in the GlymaExportWorkItemTimerJob
                                                web.ID, //gWebId - The identifier of the web containing the list
                                                exportsList.ID, //gParentId - The list ID
                                                listItemIdNum, //nItemId - The list item ID number
                                                true, //fSetWebId - true to set the Web identifier
                                                exportsList.Items.GetItemById(listItemIdNum).UniqueId, //gItemGuid - The unique identifier of the list item
                                                domainUid, //gBatchId - A Guid context identifier for the work item engine
                                                userId, //nUserId - SPUser ID number
                                                null, //rgbBinaryPayload - not used
                                                textPayload, //strTextPayload
                                                Guid.Empty); //gProcessingId - needs to be Guid.Empty

                                            ExportJob scheduledJob = new ExportJob();
                                            scheduledJob.Created = (DateTime)exportsList.Items.GetItemById(listItemIdNum)[SPBuiltInFieldId.Created];
                                            scheduledJob.CreatedBy = new GlymaUser() { Name = currentUser.Name };
                                            scheduledJob.Id = workItemId;
                                            scheduledJob.IsCurrent = true;
                                            scheduledJob.Status = ExportStatus.Scheduled;
                                            scheduledJob.Type = exportType;
                                            scheduledJob.MapType = mapType;
                                            scheduledJob.ExportProperties = exportProperties;
                                            scheduledJob.PercentageComplete = 0;
                                            response.ExportJob = scheduledJob;
                                        }
                                        else
                                        {
                                            //already scheduled so throw an exception to be handled with an error
                                            throw new Exception(string.Format("A scheduled export job already exists for the Glyma map: DomainUid: {0}, RootMapUid: {1}, Export Type: {2}, Map Type: {3}",
                                                domainUid.ToString(), rootMapUid.ToString(), exportType.ToString(), mapType.ToString()));
                                        }
                                    }
                                    else
                                    {
                                        throw new Exception("Failed to find the Glyma Exports list.");
                                    }
                                }
                                else
                                {
                                    throw new Exception("The current user was not able to be determined.");
                                }
                            }
                            else
                            {
                                throw new Exception("The SPSite and/or the SPWeb were null.");
                            }
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                ExportError error = new ExportError() { ErrorMessage = "Failed to create the Glyma map export job." };
                throw new FaultException<ExportError>(error, ex.ToString());
            }

            return response;
        }
        private void CreateWorkItem()
        {
            Guid siteId = SPContext.Current.Site.ID;
            Guid webId  = SPContext.Current.Web.ID;

            WebSiteControllerRuleControl control = (WebSiteControllerRuleControl)FindControlRecursive(this.Master, "moduleControl");

            string url = this.pageTextBox.Text;

            if (_SimpleView)
            {
                url = control.DefaultUrl;
            }

            bool disabled     = this.disabledCheckBox.Checked;
            bool appliesToSSL = this.appliesToSslCheckBox.Checked;
            int  sequence     = Convert.ToInt32(this.sequenceTextBox.Text, CultureInfo.CurrentCulture);
            WebSiteControllerPrincipalType principalType = WebSiteControllerPrincipalType.None;
            String pricipal = this.principalTextBox.Text;

            if (!String.IsNullOrEmpty(this.principalTextBox.Text))
            {
                principalType = (WebSiteControllerPrincipalType)Enum.Parse(typeof(WebSiteControllerPrincipalType), this.principalTypeList.SelectedValue);
            }

            Hashtable properties = null;

            if (control != null)
            {
                properties = control.Properties;
            }

            StringBuilder builder = new StringBuilder();

            builder.Append(url + ";");
            builder.Append(disabled.ToString() + ";");
            builder.Append(appliesToSSL.ToString() + ";");
            builder.Append(sequence.ToString() + ";");
            builder.Append(principalType.ToString() + ";");
            builder.Append(pricipal + ";");
            builder.Append("#");

            foreach (DictionaryEntry prop in properties)
            {
                builder.Append(String.Format("{0}:{1};", prop.Key, prop.Value));
            }

            Guid itemGuid = _guid;
            int  item     = 0;

            if (itemGuid.Equals(Guid.Empty))
            {
                itemGuid = _module.Id;
                item     = -1;
            }
            else
            {
                item = 2;
            }

            if (_event == "Delete")
            {
                item = 1;
            }

            SPSecurity.RunWithElevatedPrivileges(() =>
            {
                using (SPSite site = new SPSite(siteId))
                {
                    site.AddWorkItem(
                        Guid.NewGuid(),
                        DateTime.Now.ToUniversalTime(),
                        WebSiteControllerRuleWorkItem.WorkItemTypeId,
                        webId,
                        siteId,
                        item,
                        true,
                        itemGuid,
                        Guid.Empty,
                        site.SystemAccount.ID,
                        null,
                        builder.ToString(),
                        Guid.Empty
                        );

                    SPJobDefinitionCollection jobs = site.WebApplication.JobDefinitions;

                    foreach (SPJobDefinition job in jobs)
                    {
                        if (job.Name == WebSiteControllerRuleWorkItem.WorkItemJobDisplayName)
                        {
                            DateTime next = job.Schedule.NextOccurrence(job.LastRunTime);
                            _seconds      = next.Second.ToString();
                            break;
                        }
                    }

                    //SPJobDefinition job = site.WebApplication.JobDefinitions[WebSiteControllerRuleWorkItem.WorkItemJobDisplayName];
                    //job.RunNow();
                }
            });
        }
Esempio n. 19
0
        private void CreateWorkItem(string url)
        {
            Guid siteId = SPContext.Current.Site.ID;
            Guid webId  = SPContext.Current.Web.ID;

            bool disabled = false;
            WebSiteControllerPrincipalType principalType = WebSiteControllerPrincipalType.None;
            bool   appliesToSSL = true;
            int    sequence     = 1;
            String pricipal     = string.Empty;

            StringBuilder builder = new StringBuilder();

            builder.Append(url + ";");
            builder.Append(disabled.ToString() + ";");
            builder.Append(appliesToSSL.ToString() + ";");
            builder.Append(sequence.ToString() + ";");
            builder.Append(principalType.ToString() + ";");
            builder.Append(pricipal + ";");
            builder.Append("#");

            builder.Append(String.Format("{0}:{1};", "OriginalUrl", _url));

            string full = builder.ToString();

            SemanticModule           mod  = new SemanticModule();
            IWebSiteControllerModule imod = null;// WebSiteControllerConfig.GetModule(web.Site.WebApplication, mod.RuleType);

            while (imod == null)
            {
                System.Threading.Thread.Sleep(1000);
                try
                {
                    imod = WebSiteControllerConfig.GetModule(SPContext.Current.Site.WebApplication, mod.RuleType);
                }
                catch (Exception ex)
                {
                    SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                    //ex.ToString();
                }
            }


            int item = -1;

            SPSecurity.RunWithElevatedPrivileges(() =>
            {
                using (SPSite site = new SPSite(siteId))
                {
                    site.AddWorkItem(
                        Guid.NewGuid(),
                        DateTime.Now.ToUniversalTime(),
                        WebSiteControllerRuleWorkItem.WorkItemTypeId,
                        webId,
                        siteId,
                        item,
                        true,
                        imod.Id,
                        Guid.Empty,
                        site.SystemAccount.ID,
                        null,
                        builder.ToString(),
                        Guid.Empty
                        );
                }

                SPJobDefinitionCollection jobs = SPContext.Current.Site.WebApplication.JobDefinitions;

                foreach (SPJobDefinition job in jobs)
                {
                    if (job.Name == WebSiteControllerRuleWorkItem.WorkItemJobDisplayName)
                    {
                        try
                        {
                            DateTime next = job.Schedule.NextOccurrence(job.LastRunTime);
                            _seconds      = next.Second;
                            break;
                        }
                        catch (Exception ex)
                        {
                            SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                            //ex.ToString();
                        }
                    }
                }
            });
        }
        private void CreateWorkItem(SPWeb web, string pagename, string url)
        {
            Guid siteId = web.Site.ID;
            Guid webId  = web.ID;

            if (url.StartsWith("/"))
            {
                url = url.TrimStart('/');
            }

            bool disabled = false;
            WebSiteControllerPrincipalType principalType = WebSiteControllerPrincipalType.None;
            bool   appliesToSSL = true;
            int    sequence     = 1;
            String pricipal     = string.Empty;

            StringBuilder builder = new StringBuilder();

            builder.Append(url + ";");
            builder.Append(disabled.ToString() + ";");
            builder.Append(appliesToSSL.ToString() + ";");
            builder.Append(sequence.ToString() + ";");
            builder.Append(principalType.ToString() + ";");
            builder.Append(pricipal + ";");
            builder.Append("#");

            if (url.EndsWith("/"))
            {
                builder.Append(String.Format("{0}:{1};", "OriginalUrl", url + pagename + ".aspx"));
            }
            else
            {
                builder.Append(String.Format("{0}:{1};", "OriginalUrl", url + ".aspx"));
            }


            string full = builder.ToString();

            SemanticModule           mod  = new SemanticModule();
            IWebSiteControllerModule imod = null;

            while (imod == null)
            {
                try
                {
                    imod = WebSiteControllerConfig.GetModule(web.Site.WebApplication, mod.RuleType);
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
                System.Threading.Thread.Sleep(1000);
            }


            int item = -1;

            SPSecurity.RunWithElevatedPrivileges(() =>
            {
                using (SPSite site = new SPSite(siteId))
                {
                    site.AddWorkItem(
                        Guid.NewGuid(),
                        DateTime.Now.ToUniversalTime(),
                        WebSiteControllerRuleWorkItem.WorkItemTypeId,
                        webId,
                        siteId,
                        item,
                        true,
                        imod.Id,
                        Guid.Empty,
                        site.SystemAccount.ID,
                        null,
                        builder.ToString(),
                        Guid.Empty
                        );
                }
            });
        }
Esempio n. 21
0
        private void CreateErrorWorkItem(SPWeb web, HttpStatusCode code)
        {
            try
            {
                Guid siteId = web.Site.ID;
                Guid webId  = web.ID;

                bool disabled = false;
                WebSiteControllerPrincipalType principalType = WebSiteControllerPrincipalType.None;
                bool   appliesToSSL = true;
                int    sequence     = 1;
                String pricipal     = string.Empty;

                StringBuilder builder = new StringBuilder();
                builder.Append("Error/" + code.ToString() + ".aspx;");
                builder.Append(disabled.ToString() + ";");
                builder.Append(appliesToSSL.ToString() + ";");
                builder.Append(sequence.ToString() + ";");
                builder.Append(principalType.ToString() + ";");
                builder.Append(pricipal + ";");
                builder.Append("#");

                builder.Append(String.Format("{0}:{1};", "ErrorPage", "Error/" + code.ToString() + ".aspx;"));
                builder.Append(String.Format("{0}:{1};", "ErrorCode", ((int)code).ToString()));


                string full = builder.ToString();

                ErrorModule mod = new ErrorModule();
                IWebSiteControllerModule imod = null;  //WebSiteControllerConfig.GetModule(web.Site.WebApplication, mod.RuleType);

                while (imod == null)
                {
                    System.Threading.Thread.Sleep(1000);
                    try
                    {
                        imod = WebSiteControllerConfig.GetModule(web.Site.WebApplication, mod.RuleType);
                    }
                    catch (Exception ex)
                    {
                        SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                        //ex.ToString();
                    }
                }

                //Guid itemGuid = new Guid("17A3219B-049F-4056-9566-37590122BE8E");
                int item = -1;

                SPSecurity.RunWithElevatedPrivileges(() =>
                {
                    using (SPSite site = new SPSite(siteId))
                    {
                        site.AddWorkItem(
                            Guid.NewGuid(),
                            DateTime.Now.ToUniversalTime(),
                            WebSiteControllerRuleWorkItem.WorkItemTypeId,
                            webId,
                            siteId,
                            item,
                            true,
                            imod.Id,
                            Guid.Empty,
                            site.SystemAccount.ID,
                            null,
                            builder.ToString(),
                            Guid.Empty
                            );
                    }
                });

                try
                {
                    WebSiteControllerRuleWorkItem WebSiteControllerModuleJob = new WebSiteControllerRuleWorkItem(WebSiteControllerRuleWorkItem.WorkItemJobDisplayName + code.ToString(), web.Site.WebApplication);
                    SPOneTimeSchedule             oneTimeSchedule            = new SPOneTimeSchedule(DateTime.Now);

                    WebSiteControllerModuleJob.Schedule = oneTimeSchedule;
                    WebSiteControllerModuleJob.Update();
                }
                catch (Exception ex)
                {
                    SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                    //ex.ToString();
                }
            }
            catch (Exception ex)
            {
                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
            }
        }
        private void CreateWorkItem(SPWeb web, string pagename, string url)
        {
            Guid siteId = web.Site.ID;
            Guid webId  = web.ID;
            //string url = properties.ServerRelativeUrl;

            /*
             * if (url.StartsWith("/"))
             * {
             *  url = url.TrimStart('/');
             * }
             */

            bool disabled = false;
            WebSiteControllerPrincipalType principalType = WebSiteControllerPrincipalType.None;
            bool   appliesToSSL = true;
            int    sequence     = 1;
            String pricipal     = string.Empty;

            StringBuilder builder = new StringBuilder();

            builder.Append(url + ";");
            builder.Append(disabled.ToString() + ";");
            builder.Append(appliesToSSL.ToString() + ";");
            builder.Append(sequence.ToString() + ";");
            builder.Append(principalType.ToString() + ";");
            builder.Append(pricipal + ";");
            builder.Append("#");

            //builder.Append(String.Format("{0}:{1};", "OriginalUrl", url));
            //string full = builder.ToString();

            if (url.EndsWith("/"))
            {
                if (!pagename.EndsWith(".aspx"))
                {
                    builder.Append(String.Format("{0}:{1};", "OriginalUrl", pagename + ".aspx"));
                }
                else
                {
                    builder.Append(String.Format("{0}:{1};", "OriginalUrl", pagename));
                }
            }
            else
            {
                if (!url.EndsWith(".aspx"))
                {
                    builder.Append(String.Format("{0}:{1};", "OriginalUrl", url + pagename + ".aspx"));
                }
                else
                {
                    builder.Append(String.Format("{0}:{1};", "OriginalUrl", url + pagename));
                }
            }

            string full = builder.ToString();

            //Guid itemGuid = new Guid("386577D9-0777-4AD3-A90A-C240D8B0A49E");
            SemanticModule           mod  = new SemanticModule();
            IWebSiteControllerModule imod = null;// WebSiteControllerConfig.GetModule(web.Site.WebApplication, mod.RuleType);

            while (imod == null)
            {
                System.Threading.Thread.Sleep(1000);
                try
                {
                    imod = WebSiteControllerConfig.GetModule(web.Site.WebApplication, mod.RuleType);
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
            }


            int item = -1;

            SPSecurity.RunWithElevatedPrivileges(() =>
            {
                using (SPSite site = new SPSite(siteId))
                {
                    site.AddWorkItem(
                        Guid.NewGuid(),
                        DateTime.Now.ToUniversalTime(),
                        WebSiteControllerRuleWorkItem.WorkItemTypeId,
                        webId,
                        siteId,
                        item,
                        true,
                        imod.Id,
                        Guid.Empty,
                        site.SystemAccount.ID,
                        null,
                        builder.ToString(),
                        Guid.Empty
                        );
                }
            });

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(siteId, SPUserToken.SystemAccount))
                {
                    try
                    {
                        WebSiteControllerRuleWorkItem WebSiteControllerModuleJob = new WebSiteControllerRuleWorkItem(WebSiteControllerRuleWorkItem.WorkItemJobDisplayName + "HomePage", site.WebApplication);
                        SPOneTimeSchedule oneTimeSchedule = new SPOneTimeSchedule(DateTime.Now);

                        WebSiteControllerModuleJob.Schedule = oneTimeSchedule;
                        WebSiteControllerModuleJob.Update();
                    }
                    catch { };
                }

                /*
                 * if (SPContext.Current != null)
                 * {
                 *  SPJobDefinitionCollection jobs = SPContext.Current.Site.WebApplication.JobDefinitions;
                 *
                 *  int _seconds = 0;
                 *
                 *  foreach (SPJobDefinition job in jobs)
                 *  {
                 *      if (job.Name == WebSiteControllerRuleWorkItem.WorkItemJobDisplayName)
                 *      {
                 *          DateTime next = job.Schedule.NextOccurrence(job.LastRunTime);
                 *          _seconds = next.Second;
                 *          break;
                 *      }
                 *  }
                 * }
                 */
            });

            /*
             * SPSecurity.RunWithElevatedPrivileges(() =>
             * {
             *  using (SPSite site = new SPSite(siteId))
             *  {
             *      site.AddWorkItem(
             *          Guid.NewGuid(),
             *          DateTime.Now.ToUniversalTime(),
             *          WebSiteControllerRuleWorkItem.WorkItemTypeId,
             *          webId,
             *          siteId,
             *          item,
             *          true,
             *          imod.Id,
             *          Guid.Empty,
             *          site.SystemAccount.ID,
             *          null,
             *          builder.ToString(),
             *          Guid.Empty
             *          );
             *
             *      try
             *      {
             *
             *          WebSiteControllerRuleWorkItem WebSiteControllerModuleJob = new WebSiteControllerRuleWorkItem(WebSiteControllerRuleWorkItem.WorkItemJobDisplayName + "HomePage", site.WebApplication);
             *          SPOneTimeSchedule oneTimeSchedule = new SPOneTimeSchedule(DateTime.Now);
             *
             *          WebSiteControllerModuleJob.Schedule = oneTimeSchedule;
             *          WebSiteControllerModuleJob.Update();
             *      }
             *      catch (Exception ex)
             *      {
             *          SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
             *          //ex.ToString();
             *      }
             *
             *  }
             *
             *  SPJobDefinitionCollection jobs = SPContext.Current.Site.WebApplication.JobDefinitions;
             *
             *  int _seconds = 0;
             *
             *  foreach (SPJobDefinition job in jobs)
             *  {
             *      if (job.Name == WebSiteControllerRuleWorkItem.WorkItemJobDisplayName)
             *      {
             *          DateTime next = job.Schedule.NextOccurrence(job.LastRunTime);
             *          _seconds = next.Second;
             *          break;
             *      }
             *  }
             * });
             */
        }