public Task Handle(BroadcastHtmlCacheMessage message, IMessageReceiveContext receiveContext,
                           IMessageReplyContext replyContext)
        {
            SiteContext siteContext = SiteContext.GetSite(message.SiteName);

            if (message.ToRemove)
            {
                if (!string.IsNullOrEmpty(message.HtmlCacheKey))
                {
                    foreach (var cacheKey in message.HtmlCacheKey.Split('|'))
                    {
                        CacheManager.GetHtmlCache(siteContext).RemoveKeysContaining(cacheKey);
                    }
                }
                else
                {
                    CacheManager.GetHtmlCache(siteContext).Clear();
                }
            }
            else
            {
                CacheManager.GetHtmlCache(siteContext).SetHtml(
                    message.HtmlCacheKey,
                    message.HtmlCacheResult);
            }


            return(Task.CompletedTask);
        }
        private string GetItemUrl(Item item, Site site, Language language)
        {
            UrlOptions defaultOptions = UrlOptions.DefaultOptions;

            defaultOptions.SiteResolving          = Settings.Rendering.SiteResolving;
            defaultOptions.Site                   = SiteContext.GetSite(site.Name);
            defaultOptions.AlwaysIncludeServerUrl = false;
            defaultOptions.LanguageEmbedding      = LanguageEmbedding.Always;
            if (language != null)
            {
                defaultOptions.Language = language;
            }
            string itemUrl         = LinkManager.GetItemUrl(item, defaultOptions);
            string serverUrlBySite = SitemapManagerConfiguration.GetServerUrlBySite(site.Name);

            if (serverUrlBySite.Contains("http://"))
            {
                serverUrlBySite = serverUrlBySite.Substring("http://".Length);
            }
            StringBuilder stringBuilder = new StringBuilder();

            if (!string.IsNullOrEmpty(serverUrlBySite))
            {
                if (!(itemUrl.Contains("://") || itemUrl.Contains("http")))
                {
                    stringBuilder.Append("http://");
                    stringBuilder.Append(serverUrlBySite);
                    stringBuilder.Append(itemUrl);
                }
                else
                {
                    if (itemUrl.StartsWith("http"))
                    {
                        itemUrl = itemUrl.Remove(0, 4);
                    }
                    stringBuilder.Append("http://");
                    stringBuilder.Append(serverUrlBySite);
                    if (itemUrl.IndexOf("/", 3) > 0)
                    {
                        stringBuilder.Append(itemUrl.Substring(itemUrl.IndexOf("/", 3)));
                    }
                }
            }
            else if (!string.IsNullOrEmpty(site.Properties["hostname"]))
            {
                stringBuilder.Append("http://");
                stringBuilder.Append(site.Properties["hostname"]);
                stringBuilder.Append(itemUrl);
            }
            else if (!itemUrl.Contains("://") || itemUrl.Contains("http"))
            {
                stringBuilder.Append(WebUtil.GetFullUrl(itemUrl));
            }
            else
            {
                stringBuilder.Append("http://");
                stringBuilder.Append(itemUrl);
            }
            return(stringBuilder.ToString());
        }
        protected virtual void AdjustOptions(SitecoreIndexableItem item)
        {
            if (!string.IsNullOrEmpty(Site))
            {
                var siteContext = SiteContext.GetSite(Site);
                if (siteContext == null)
                {
                    throw new Exception($"Site {Site} cannot be reached");
                }

                //we typically generate index on CM but site URLs in CM will not work for CD
                //replacing "targetHostName" is not good solution because it breaks PE in CM
                //"cdTargetHostName" site argument should solve that issue. Index uses it instead of targetHostName and PE continue using "targetHostName"
                var cmTargetHostName = siteContext.Properties["cdTargetHostName"];
                if (!String.IsNullOrWhiteSpace(cmTargetHostName))
                {
                    var props = new Sitecore.Collections.StringDictionary(ToDictionary(siteContext.SiteInfo.Properties));
                    props["targetHostName"] = cmTargetHostName;

                    var siteInfo = new SiteInfo(props);
                    siteContext = new SiteContext(siteInfo);
                }

                UrlOptions.Site = siteContext;
            }
        }
Exemple #4
0
        protected override bool Render(string cacheKey, TextWriter writer, RenderRenderingArgs args)
        {
            //Check if the Timeout key is in the cache key; if not, try the base/Sitecore version
            if (!cacheKey.Contains(Settings.TimeoutRenderingKey))
            {
                return(base.Render(cacheKey, writer, args));
            }

            //Check if the caching site exists; if not, try the base/Sitecore version
            SiteContext cachingSite = SiteContext.GetSite(Settings.CachingSite);

            if (cachingSite == null)
            {
                return(base.Render(cacheKey, writer, args));
            }

            //Check if an HTML cache exists for the caching site and that the HTML is present; if not, try the base/Sitecore version
            HtmlCache htmlCache = CacheManager.GetHtmlCache(cachingSite);
            string    html      = htmlCache?.GetHtml(cacheKey);

            if (html == null)
            {
                return(base.Render(cacheKey, writer, args));
            }

            //If everything is good, write the HTML from the cache
            writer.Write(html);

            return(true);
        }
        private static string GetFieldsJson(Item item, string contextSite)
        {
            var sb = new StringBuilder();

            sb.Append("{");
            var fieldDescriptors = new List <string>();
            var urlOptions       = new UrlOptions();

            urlOptions.AlwaysIncludeServerUrl = false;
            if (!string.IsNullOrEmpty(contextSite))
            {
                urlOptions.Site = SiteContext.GetSite(contextSite);
            }

            var url = LinkManager.GetItemUrl(item, urlOptions);

            url = url.Replace(" ", "%20");
            url = Settings.GetSetting("Sitecore.Flow.Actions.ServerUrl") + url;
            fieldDescriptors.Add($" \"ItemUrl\" : \"{url}\" ");

            foreach (Field field in item.Fields)
            {
                if (field.Name.StartsWith("__"))
                {
                    continue;
                }

                fieldDescriptors.Add($" \"{field.Name}\" : \"{HttpUtility.JavaScriptStringEncode(field.Value)}\" ");
            }

            sb.Append(fieldDescriptors.Aggregate((i, j) => i + "," + j));
            sb.Append("}");
            return(sb.ToString());
        }
 /// <summary>
 /// Initializes this instance.
 /// </summary>
 public static void Initialize()
 {
     using (new SiteContextSwitcher(SiteContext.GetSite(Configuration.DefaultSiteName)))
     {
         startItem     = Context.Site.StartItem.ToLower();
         virtualFolder = GetVirtualVolder();
     }
 }
Exemple #7
0
        private string GetItemUrl(Item item, Site site)
        {
            Sitecore.Links.UrlOptions options = Sitecore.Links.UrlOptions.DefaultOptions;

            options.SiteResolving          = Sitecore.Configuration.Settings.Rendering.SiteResolving;
            options.Site                   = SiteContext.GetSite(site.Name);
            options.AlwaysIncludeServerUrl = false;

            string url = Sitecore.Links.LinkManager.GetItemUrl(item, options);

            string serverUrl = SitemapManagerConfiguration.GetServerUrlBySite(site.Name);

            if (serverUrl.Contains("http://"))
            {
                serverUrl = serverUrl.Substring("http://".Length);
            }

            StringBuilder sb = new StringBuilder();

            if (!string.IsNullOrEmpty(serverUrl))
            {
                if (url.Contains("://") && !url.Contains("http"))
                {
                    sb.Append("http://");
                    sb.Append(serverUrl);
                    if (url.IndexOf("/", 3) > 0)
                    {
                        sb.Append(url.Substring(url.IndexOf("/", 3)));
                    }
                }
                else
                {
                    sb.Append("http://");
                    sb.Append(serverUrl);
                    sb.Append(url);
                }
            }
            else if (!string.IsNullOrEmpty(site.Properties["hostname"]))
            {
                sb.Append("http://");
                sb.Append(site.Properties["hostname"]);
                sb.Append(url);
            }
            else
            {
                if (url.Contains("://") && !url.Contains("http"))
                {
                    sb.Append("http://");
                    sb.Append(url);
                }
                else
                {
                    sb.Append(Sitecore.Web.WebUtil.GetFullUrl(url));
                }
            }

            return(sb.ToString());
        }
Exemple #8
0
        public string GetItemUrl(Item item, string siteName)
        {
            SiteContext site = SiteContext.GetSite(siteName);

            UrlOptions urlOptions = new UrlOptions {
                Site = site, LanguageEmbedding = LanguageEmbedding.Always
            };

            return("http://" + site.HostName + LinkManager.GetItemUrl(item, urlOptions));
        }
Exemple #9
0
        //
        // GET: /Admin/Site/Edit

        public ActionResult Edit(int id = 0)
        {
            SiteModel site = null;

            using (SiteContext context = new SiteContext())
            {
                site = context.GetSite(id);
            }
            return(View(site));
        }
Exemple #10
0
        public string Execute([NotNull] string databaseName, [NotNull] string itemId)
        {
            Assert.ArgumentNotNull(databaseName, nameof(databaseName));
            Assert.ArgumentNotNull(itemId, nameof(itemId));

            var database = Factory.GetDatabase(databaseName);

            if (database == null)
            {
                throw new Exception("Database not found");
            }

            var item = database.GetItem(itemId);

            if (item == null)
            {
                throw new Exception("Item not found");
            }

            var devices = database.GetItem(ItemIDs.DevicesRoot);

            if (devices == null)
            {
                return(string.Empty);
            }

            var writer = new StringWriter();
            var output = new XmlTextWriter(writer);

            output.WriteStartElement("urls");

            foreach (Item child in devices.Children)
            {
                var options = new UrlOptions
                {
                    Site                   = SiteContext.GetSite("website"),
                    AddAspxExtension       = true,
                    AlwaysIncludeServerUrl = true
                };

                var url = new UrlString(LinkManager.GetItemUrl(item, options));

                url["sc_device"] = child.Name;

                output.WriteStartElement("url");
                output.WriteAttributeString("url", url.ToString());
                output.WriteValue(child.Name);
                output.WriteEndElement();
            }

            output.WriteEndElement();

            return(writer.ToString());
        }
        private bool IsPublished(Item item)
        {
            SiteContext targetSiteContext = SiteContext.GetSite("website");

            using (var switcher = new SiteContextSwitcher(targetSiteContext))
            {
                // do something on the new site context
                var publishedItem = Context.Database.GetItem(item.ID);
                return(publishedItem != null);
            }
        }
        /// <summary>
        /// Gets the item URL.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns>item url</returns>
        public static string GetItemUrl(Item item)
        {
            if (item == null)
            {
                return(string.Empty);
            }

            using (new SiteContextSwitcher(SiteContext.GetSite(Configuration.DefaultSiteName)))
            {
                return(LinkManager.GetItemUrl(item, UrlOptions).ToLower());
            }
        }
Exemple #13
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        public static void Initialize()
        {
            using (new SiteContextSwitcher(SiteContext.GetSite("website")))
            {
                startItem     = Context.Site.StartItem.ToLower();
                virtualFolder = GetVirtualVolder();
            }

            urlOptions = new UrlOptions {
                LanguageEmbedding = LanguageEmbedding.Never, AddAspxExtension = true
            };
        }
Exemple #14
0
        /// <summary>
        /// Gets the item URL.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns>item url</returns>
        public static string GetItemUrl(Item item)
        {
            if (item == null)
            {
                return(string.Empty);
            }

            using (new SiteContextSwitcher(SiteContext.GetSite("website")))
            {
                return(LinkManager.GetItemUrl(item, urlOptions).ToLower());
            }
        }
        public virtual void RaiseEvent(object state)
        {
            using (new SiteContextSwitcher(SiteContext.GetSite("shell")))
            {
                var databaseName = state.ToString();
                EventManager.RaiseEvent(new SerializationFinishedEvent());
                Database database = Factory.GetDatabase(databaseName, false);

                database?.RemoteEvents.Queue.QueueEvent(new SerializationFinishedEvent());
            }

            Log.Info($"Job ended: Raise deserialization complete async ({typeof(SendSerializationCompleteEvent).FullName})", this);
        }
Exemple #16
0
        private static string GetItemUrl(Item item, SiteInfo site)
        {
            using (new SiteContextSwitcher(SiteContext.GetSite(site.Name)))
            {
                var urlOptions = LinkManager.GetDefaultUrlBuilderOptions();

                urlOptions.AlwaysIncludeServerUrl = true;
                urlOptions.ShortenUrls            = true;
                urlOptions.SiteResolving          = true;

                return(LinkManager.GetItemUrl(item, urlOptions));
            }
        }
Exemple #17
0
        private string GetItemUrl(Item item, bool addAspxExtension, Site site)
        {
            UrlOptions options = new UrlOptions
            {
                SiteResolving          = Settings.Rendering.SiteResolving,
                AddAspxExtension       = addAspxExtension,
                Site                   = SiteContext.GetSite(site.Name),
                LanguageEmbedding      = LanguageEmbedding.Never,
                AlwaysIncludeServerUrl = false
            };
            string itemUrl = LinkManager.GetItemUrl(item, options);

            return(GetUrl(itemUrl, site));
        }
Exemple #18
0
        private static void UpdateUrlField([NotNull] SiteDefinition sitemapArgs, [NotNull] Item item)
        {
            var options = UrlOptions.DefaultOptions;

            options.AlwaysIncludeServerUrl = false;
            options.Site              = SiteContext.GetSite(sitemapArgs.SiteName);
            options.UseDisplayName    = sitemapArgs.UseDisplayName;
            options.LanguageEmbedding = sitemapArgs.EmbedLanguage ? LanguageEmbedding.Always : LanguageEmbedding.Never;

            using (new EditContext(item))
            {
                item[sitemapArgs.SitemapUrlFieldName] = sitemapArgs.LeftPart + LinkManager.GetItemUrl(item, options);
            }
        }
 protected virtual string GetLoginPage(SiteContext site)
 {
     if (site != null)
     {
         if (site.DisplayMode == DisplayMode.Normal)
         {
             return(site.LoginPage);
         }
         SiteContext context = SiteContext.GetSite("shell");
         if (context != null)
         {
             return(context.LoginPage);
         }
     }
     return(string.Empty);
 }
Exemple #20
0
        public static string GetUrl(Item item)
        {
            var defaultOptions = UrlOptions.DefaultOptions;
            var siteInfo       = SiteHelper.GetSiteInfo(item);

            defaultOptions.Site = SiteContext.GetSite(siteInfo != null ? siteInfo.Name : "shell");

            var urlString = new UrlString(LinkManager.GetItemUrl(item, defaultOptions));

            urlString["sc_database"] = Client.ContentDatabase.Name;
            urlString["sc_duration"] = "temporary";
            urlString["sc_itemid"]   = item.ID.ToString();
            urlString["sc_lang"]     = item.Language.Name;
            urlString["sc_webedit"]  = "0";
            return(urlString.ToString());
        }
Exemple #21
0
        protected static void GetWebsiteScripts(GetMediaStreamPipelineArgs args, ID targetItemId)
        {
            string targetItemUrl;
            string site = string.IsNullOrEmpty(args.Options.CustomOptions["site"])
                              ? "website"
                              : args.Options.CustomOptions["site"];

            using (new SiteContextSwitcher(SiteContext.GetSite(site)))
            {
                var item = Sitecore.Context.Database.GetItem(targetItemId);
                if (item == null)
                {
                    return;
                }

                var options = new UrlOptions();
                options.LanguageEmbedding      = LanguageEmbedding.Never;
                options.AlwaysIncludeServerUrl = true;
                targetItemUrl = LinkManager.GetItemUrl(item, options);
            }

            var    fileName   = string.Format("SplitShot_{0}.png", ID.NewID);
            string tempPath   = HttpContext.Current.Server.MapPath("/temp");
            string serverPath = HttpContext.Current.Server.MapPath("/App_Data/SplitShot");
            string arguments  = string.Format(" rasterize.js \"{0}\" {1}\\{2}", targetItemUrl, tempPath, fileName);
            var    psi        = new System.Diagnostics.ProcessStartInfo(string.Format("{0}\\phantomjs.exe", serverPath), arguments)
            {
                UseShellExecute        = false,
                RedirectStandardOutput = true,
                RedirectStandardInput  = true,
                RedirectStandardError  = true,
                WorkingDirectory       = serverPath
            };

            var process = System.Diagnostics.Process.Start(psi);

            process.WaitForExit();

            var stream = new MemoryStream();

            AddFileToStream(stream, "/temp/" + fileName);

            args.OutputStream = new MediaStream(stream, "png", args.MediaData.MediaItem);
        }
        public static string GetItemUrl(Item item, SiteContext site)
        {
            Sitecore.Links.UrlOptions options = Sitecore.Links.UrlOptions.DefaultOptions;

            options.SiteResolving          = Sitecore.Configuration.Settings.Rendering.SiteResolving;
            options.Site                   = SiteContext.GetSite(site.Name);
            options.AlwaysIncludeServerUrl = false;

            string url = Sitecore.Links.LinkManager.GetItemUrl(item, options);

            var serverUrl = (new SitemapManagerConfiguration(site.Name)).ServerUrl;

            StringBuilder sb = new StringBuilder();

            if (!string.IsNullOrEmpty(serverUrl))
            {
                if (!serverUrl.Contains("http://") && !serverUrl.Contains("https://"))
                {
                    serverUrl = string.Format("https://{0}", serverUrl);
                }
                sb.Append(serverUrl);
                sb.Append(url);
            }
            else if (!string.IsNullOrEmpty(site.Properties["hostname"]))
            {
                sb.Append("https://");
                sb.Append(site.Properties["hostname"]);
                sb.Append(url);
            }
            else
            {
                if (url.Contains("://") && !url.Contains("http"))
                {
                    sb.Append("https://");
                    sb.Append(url);
                }
                else
                {
                    sb.Append(Sitecore.Web.WebUtil.GetFullUrl(url));
                }
            }

            return(sb.ToString());
        }
Exemple #23
0
        public virtual void RaiseEvent(object state)
        {
            using (new SiteContextSwitcher(SiteContext.GetSite("shell")))
            {
                var databaseName = state.ToString();
                EventManager.RaiseEvent(new SerializationFinishedEvent());
                Database database = Factory.GetDatabase(databaseName, false);

                var remoteEvents = database?.RemoteEvents;
                if (remoteEvents == null)
                {
                    Log.Warn("Remote Events not configured for this instance. SerializationFinishedEvent is not raised.", this);
                    return;
                }

                var remoteEventsType = remoteEvents.GetType();

                // Pre 9.3, you could access the Queue property
                // 9.3+ you need to access the EventQueue property

                // All of this in the Sitecore.Data.Eventing.DatabaseRemoteEvents

                // Try for 9.3 (some versions of 9.x also has this property)
                var eventQueue = remoteEventsType?.GetProperty("EventQueue", BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance);
                if (eventQueue == null)
                {
                    // Try for v.Prev
                    eventQueue = remoteEventsType?.GetProperty("Queue", BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance);
                }

                if (eventQueue == null)
                {
                    Log.Error("Cannot locate Queue/EventQueue property on [Database].RemoteEvents. SerializationFinishedEvent is not raised.", this);
                    return;
                }
                var eventQueueInstance = eventQueue.GetValue(remoteEvents);

                eventQueue?.GetType()?.GetMethod("QueueEvent")?.Invoke(eventQueueInstance, new object[] { new SerializationFinishedEvent() });
            }

            Log.Info($"Job ended: Raise deserialization complete async ({typeof(SendSerializationCompleteEvent).FullName})", this);
        }
        public static string GetUrlForContextSite(this Item item)
        {
            var sites = SiteContextFactory.Sites
                        .Where(s => !string.IsNullOrWhiteSpace(s.RootPath) &
                               item.Paths.Path.StartsWith(s.RootPath, StringComparison.OrdinalIgnoreCase))
                        .OrderByDescending(s => s.RootPath.Length).ToList();

            SiteInfo siteInfo = sites.FirstOrDefault();
            var      site     = SiteContext.GetSite(siteInfo.Name);

            using (var siteContextSwitcher = new SiteContextSwitcher(site))
            {
                var urlOptions = LinkManager.GetDefaultUrlOptions();
                urlOptions.AlwaysIncludeServerUrl = true;
                urlOptions.ShortenUrls            = true;
                urlOptions.SiteResolving          = true;
                return(LinkManager.GetItemUrl(item, urlOptions));
            }
            return(string.Empty);
        }
        private string GetItemUrl(Item item, Site site)
        {
            Sitecore.Links.UrlOptions options = Sitecore.Links.UrlOptions.DefaultOptions;

            options.SiteResolving          = Sitecore.Configuration.Settings.Rendering.SiteResolving;
            options.Site                   = SiteContext.GetSite(site.Name);
            options.AlwaysIncludeServerUrl = false;

            string serverUrl = SitemapManagerConfiguration.GetServerUrlBySite(site.Name);
            string itemUrl   = Sitecore.Links.LinkManager.GetItemUrl(item, options);

            if (itemUrl.StartsWith("http"))
            {
                return(itemUrl);
            }
            else
            {
                return(string.Format("{0}{1}", serverUrl, itemUrl));
            }
        }
Exemple #26
0
        protected override void AddHtmlToCache(string cacheKey, string html, RenderRenderingArgs args)
        {
            //Check if the Timeout key is in the cache key; if not, try the base/Sitecore version
            if (!cacheKey.Contains(Settings.TimeoutRenderingKey))
            {
                base.AddHtmlToCache(cacheKey, html, args);
                return;
            }

            //Check if the Timeout value is present and a valid TimeSpan; if not, try the base/Sitecore version
            bool timeoutValue = TimeSpan.TryParse(args.Rendering.RenderingItem.InnerItem[Settings.TimeoutRenderingParam], out _);

            if (!timeoutValue)
            {
                base.AddHtmlToCache(cacheKey, html, args);
                return;
            }

            //Check if the caching site exists; if not, try the base/Sitecore version
            SiteContext cachingSite = SiteContext.GetSite(Settings.CachingSite);

            if (cachingSite == null)
            {
                base.AddHtmlToCache(cacheKey, html, args);
                return;
            }

            //Check if the HTML cache is available in the caching site; if not, try the base/Sitecore version
            HtmlCache htmlCache = CacheManager.GetHtmlCache(cachingSite);

            if (htmlCache == null)
            {
                base.AddHtmlToCache(cacheKey, html, args);
                return;
            }

            //If everything is good, set the timeout based on the rendering parameter and put the HTML in the caching site
            TimeSpan timeout = GetTimeout(args);

            htmlCache.SetHtml(cacheKey, html, timeout);
        }
Exemple #27
0
        public static string GetItemUrl(Item item, SiteContext site)
        {
            var options = Sitecore.Links.UrlOptions.DefaultOptions;

            options.SiteResolving          = Sitecore.Configuration.Settings.Rendering.SiteResolving;
            options.Site                   = SiteContext.GetSite(site.Name);
            options.AlwaysIncludeServerUrl = false;

            var url = Sitecore.Links.LinkManager.GetItemUrl(item, options);


            var serverUrl = (new SitemapManagerConfiguration(site.Name)).ServerUrl;
            var protocol  = SitemapManagerConfiguration.IsHttps ? "https://" : "http://";

            if (serverUrl.Contains(protocol))
            {
                serverUrl = serverUrl.Substring(protocol.Length);
            }

            var sb = new StringBuilder();

            if (!string.IsNullOrEmpty(serverUrl))
            {
                sb.Append(protocol);
                sb.Append(serverUrl);
                sb.Append(url);
            }
            else if (!string.IsNullOrEmpty(site.Properties["hostname"]))
            {
                sb.Append(protocol);
                sb.Append(site.Properties["hostname"]);
                sb.Append(url);
            }
            else
            {
                sb.Append(Sitecore.Web.WebUtil.GetFullUrl(url));
            }

            return(sb.ToString());
        }
Exemple #28
0
        public override object ComputeFieldValue(IIndexable indexable)
        {
            var indexableItem = indexable as SitecoreIndexableItem;
            var item          = (Item)indexableItem;

            if (item?.Fields[Sitecore.FieldIDs.LayoutField] == null)
            {
                return(null);
            }

            var urlOptions = new UrlOptions
            {
                LowercaseUrls     = true,
                EncodeNames       = true,
                LanguageEmbedding = LanguageEmbedding.Always,
                Language          = item.Language,
                ShortenUrls       = true,
                Site = SiteContext.GetSite(SiteName)
            };

            return(LinkManager.GetItemUrl(item, urlOptions));
        }
        public override void Process(BuildPackageArgs args)
        {
            if (this.AbortIfErrorsDetected(args))
            {
                return;
            }

            if (args.PackageFiles.Entries.Count > 0)
            {
                args.Package.Sources.Add(args.PackageFiles);
            }

            if (args.PackageItems.Entries.Count > 0 || args.PackageSources.Sources.Count > 0)
            {
                args.Package.Sources.Add(args.PackageSources);
            }

            args.Package.SaveProject = true;

            try
            {
                this.Log.Debug("Generating package '" + args.PackageFilePath + "'...", this);

                using (new SiteContextSwitcher(SiteContext.GetSite("shell")))
                    using (new DatabaseSwitcher(Database.GetDatabase("core")))
                        using (var writer = new PackageWriter(args.PackageFilePath))
                        {
                            var context = Sitecore.Install.Serialization.IOUtils.SerializationContext;
                            writer.Initialize(Installer.CreateInstallationContext());
                            PackageGenerator.GeneratePackage(args.Package, writer);
                        }
            }
            catch (Exception ex)
            {
                args.Errors.Add(ex.GetType().Name, ex.Message);
                this.Log.Error("Error generating package '" + args.PackageFilePath + "'", ex, this);
            }
        }
        public virtual void RaiseEvent(object state)
        {
            using (new SiteContextSwitcher(SiteContext.GetSite("shell")))
            {
                var databaseName = state.ToString();
                EventManager.RaiseEvent(new SerializationFinishedEvent());
                Database database = Factory.GetDatabase(databaseName, false);

                var remoteEvents     = database?.RemoteEvents;
                var remoteEventsType = remoteEvents.GetType();
                var eventQueue       = remoteEventsType.GetProperties().FirstOrDefault(property => property.GetType().GetMethod("QueueEvent") != null);
                if (eventQueue == null)
                {
                    Log.Error("Cannot find property with 'QueueEvent' method. SerializationFinishedEvent is not rised.", this);
                    return;
                }
                var eventQueueInstance = eventQueue.GetValue(remoteEvents);

                eventQueue?.GetType()?.GetMethod("QueueEvent")?.Invoke(eventQueueInstance, new object[] { new SerializationFinishedEvent() });
            }

            Log.Info($"Job ended: Raise deserialization complete async ({typeof(SendSerializationCompleteEvent).FullName})", this);
        }