internal void OnItemSaved(object sender, EventArgs args)
        {
            Assert.ArgumentNotNull(sender, "sender");
            Assert.ArgumentNotNull(args, "args");

            var sitecoreArgs = args as SitecoreEventArgs;

            if (sitecoreArgs == null)
            {
                return;
            }

            var arguments = new ItemSavedEventArgs((Item)sitecoreArgs.Parameters[0], (ItemChanges)sitecoreArgs.Parameters[1]);

            var item = arguments.Item;

            if (item == null)
            {
                return;
            }

            //Is Module Disabled at the config level?
            if (DynamicSiteSettings.Disabled)
            {
                return;
            }

            try
            {
                //Skip if current database doesn't keep content items.
                if (!Context.Database.HasContentItem)
                {
                    return;
                }

                //Reset Cache if Item is Dynamic Site.
                ResetDynamicSitesCache(item);

                //If Item being saved is the Dynamic Site Settings Item, Make Updates
                //Return otherwise.
                if (item.TemplateID != new ID(DynamicSiteSettingsItem.TemplateId))
                {
                    return;
                }

                //Get ItemChanges
                var itemChanges = arguments.Changes;

                //Do Base Template Updates to Activate Dynamic Sites
                DoBaseTemplateUpdates(item, itemChanges);
            }
            catch (NullReferenceException ne)
            {
                //Do nothing.
            }
            catch (Exception e)
            {
                Log.Error(String.Format("[DynamicSites] Error: {0} \r\n Stack: {1}", e.Message, e.StackTrace), e);
            }
        }
        private async void FolderChangeWatcher_ItemSavedOrDeletedAsync(ItemSavedEventArgs e)
        {
            try
            {
                if (_errorHandlingStrategy.ShouldPostponeSyncRun())
                {
                    return;
                }

                _pendingOutlookItems.AddOrUpdate(e.EntryId.EntryId, e.EntryId, (key, existingValue) => e.EntryId.Version > existingValue.Version ? e.EntryId : existingValue);
                if (s_logger.IsDebugEnabled)
                {
                    s_logger.Debug($"Partial sync:  '{_pendingOutlookItems.Count}' items pending after registering item '{e.EntryId.EntryId}' as pending sync item.");
                }
                await Task.Delay(_partialSyncDelay);

                using (_runLogger.LogStartSynchronizationRun())
                {
                    await RunAllPendingJobs();
                }
            }
            catch (Exception x)
            {
                s_logger.Error(null, x);
            }
        }
 private void FolderChangeWatcher_ItemSavedOrDeleted(object sender, ItemSavedEventArgs e)
 {
     try
     {
         _ensureSynchronizationContext();
         FolderChangeWatcher_ItemSavedOrDeletedAsync(e);
     }
     catch (Exception x)
     {
         s_logger.Error(null, x);
     }
 }
 private async void ItemChangeWatcherItemSavedOrDeleted(object sender, ItemSavedEventArgs e)
 {
     try
     {
         EnsureSynchronizationContext();
         await _scheduler.RunResponsibleSynchronizationProfiles(e.EntryId, e.FolderEntryId, e.FolderStoreId);
     }
     catch (Exception x)
     {
         ExceptionHandler.Instance.LogException(x, s_logger);
     }
 }
 private async void FolderChangeWatcher_ItemSavedOrDeletedAsync(ItemSavedEventArgs e)
 {
     try
     {
         _pendingOutlookItems.AddOrUpdate(e.EntryId.Id, e.EntryId, (key, existingValue) => e.EntryId.VersionHint > existingValue.VersionHint ? e.EntryId : existingValue);
         if (s_logger.IsDebugEnabled)
         {
             s_logger.Debug($"Partial sync:  '{_pendingOutlookItems.Count}' items pending after registering item '{e.EntryId}' as pending sync item.");
         }
         await Task.Delay(_partialSyncDelay);
         await RunAllPendingJobs();
     }
     catch (Exception x)
     {
         s_logger.Error(null, x);
     }
 }
Esempio n. 6
0
 private void ItemSavedNotification(object sender, ItemSavedEventArgs args)
 {
     this.VersionCreated = true;
     this.ToggleVisibilityOfControlsOnFinalLayoutTab(args.Item);
     SheerResponse.SetDialogValue(this.GetDialogResult());
 }
Esempio n. 7
0
        private void RaiseItemSaved(T @object)
        {
            var args = new ItemSavedEventArgs <T>(@object);

            ItemSaved?.Invoke(this, args);
        }
 private void ItemSavedNotification(object sender, ItemSavedEventArgs args)
 {
     Assert.ArgumentNotNull(sender, "sender");
     Assert.ArgumentNotNull(args, "args");
     Item folder = this.ContentEditorDataContext.GetFolder();
     if (Settings.ContentEditor.ClassicFrameEventPropagation || ((folder != null) && ((folder.ID == args.Item.ID) || (folder.ID == args.Item.ParentID))))
     {
         SheerResponse.Eval("scContent.postMessage(\"" + ("notification:itemsaved(item=" + GetUri(args.Item) + ")") + "\")");
     }
     UpdateGutter(args.Item);
 }
Esempio n. 9
0
        public void Start()
        {
            try
            {
                Sitecore.Diagnostics.Log.Info("MongoOplogCacheClearer: Starting", this);
                var client            = new MongoClient(_connectionString);
                var server            = client.GetServer();
                var mappingDatabase   = server.GetDatabase(_mongoDatabase);
                var mappingCollection = mappingDatabase.GetCollection(_mappingCollection);

                //run a query against the oplog with a tailable cursor, which will block until new records are created
                var mongoDatabase   = server.GetDatabase(LOCAL);
                var opLog           = mongoDatabase.GetCollection(OPLOG);
                var queryCollection = string.Format("{0}.{1}", _mongoDatabase, _mongoCollection);
                var queryDoc        = new QueryDocument("ns", queryCollection);
                var query           = opLog.Find(queryDoc)
                                      .SetFlags(QueryFlags.AwaitData | QueryFlags.NoCursorTimeout | QueryFlags.TailableCursor);
                var cursor = new MongoCursorEnumerator <BsonDocument>(query);
                while (true)
                {
                    if (cursor.MoveNext())
                    {
                        var document = cursor.Current;
                        if (document["op"].AsString == "d")
                        {
                            //get the deleted document
                            document = document["o"].AsBsonDocument;

                            //TODO: on delete, delete from the mapping collection as well?
                        }
                        else if (document["op"].AsString == "u")
                        {
                            //get the updated document
                            document = document["o2"].AsBsonDocument;
                        }
                        else
                        {
                            continue;
                        }
                        var objectId = document["_id"].AsObjectId;

                        //look in our mapping table for the associated sitecore item id
                        var mapping = mappingCollection.FindOne(new QueryDocument("mongoId", objectId.ToString()));
                        if (mapping == null)
                        {
                            continue;
                        }
                        var id = Sitecore.Data.ShortID.Parse(mapping["sitecoreId"].AsString).ToID();

                        //clear caches for all configured databases, simulate item save
                        foreach (var database in _databases)
                        {
                            var item = database.GetItem(id);
                            if (item == null)
                            {
                                continue;
                            }
                            Sitecore.Diagnostics.Log.Info(
                                string.Format("MongoOplogCacheClearer: Product {0}://{1} updated", database.Name, id), this);
                            database.Caches.ItemCache.RemoveItem(id);
                            database.Caches.DataCache.RemoveItemInformation(id);
                            database.Engines.DataEngine.RaiseSavedItem(item, true);
                            var args = new ItemSavedEventArgs(item);
                            Sitecore.Events.Event.RaiseItemSaved(this, args);
                            //TODO: Something to cause reindex in web, new indexing strategy?
                            //TODO: Clear HTML cache?
                        }
                    }
                    else if (cursor.IsDead)
                    {
                        //TODO: restart mechanism?
                        Sitecore.Diagnostics.Log.Info("MongoOplogCacheClearer: Dead", this);
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                Sitecore.Diagnostics.Log.Error("Exception starting MongoDb oplog monitoring", e, this);
            }
        }
        public void Start()
        {
            try
            {
                Sitecore.Diagnostics.Log.Info("MongoOplogCacheClearer: Starting", this);
                var client = new MongoClient(_connectionString);
                var server = client.GetServer();
                var mappingDatabase = server.GetDatabase(_mongoDatabase);
                var mappingCollection = mappingDatabase.GetCollection(_mappingCollection);

                //run a query against the oplog with a tailable cursor, which will block until new records are created
                var mongoDatabase = server.GetDatabase(LOCAL);
                var opLog = mongoDatabase.GetCollection(OPLOG);
                var queryCollection = string.Format("{0}.{1}", _mongoDatabase, _mongoCollection);
                var queryDoc = new QueryDocument("ns", queryCollection);
                var query = opLog.Find(queryDoc)
                                .SetFlags(QueryFlags.AwaitData | QueryFlags.NoCursorTimeout | QueryFlags.TailableCursor);
                var cursor = new MongoCursorEnumerator<BsonDocument>(query);
                while (true)
                {
                    if (cursor.MoveNext())
                    {
                        var document = cursor.Current;
                        if (document["op"].AsString == "d")
                        {
                            //get the deleted document
                            document = document["o"].AsBsonDocument;

                            //TODO: on delete, delete from the mapping collection as well?
                        }
                        else if (document["op"].AsString == "u")
                        {
                            //get the updated document
                            document = document["o2"].AsBsonDocument;
                        }
                        else
                        {
                            continue;
                        }
                        var objectId = document["_id"].AsObjectId;

                        //look in our mapping table for the associated sitecore item id
                        var mapping = mappingCollection.FindOne(new QueryDocument("mongoId", objectId.ToString()));
                        if (mapping == null)
                        {
                            continue;
                        }
                        var id = Sitecore.Data.ShortID.Parse(mapping["sitecoreId"].AsString).ToID();

                        //clear caches for all configured databases, simulate item save
                        foreach (var database in _databases)
                        {
                            var item = database.GetItem(id);
                            if (item == null)
                            {
                                continue;
                            }
                            Sitecore.Diagnostics.Log.Info(
                                string.Format("MongoOplogCacheClearer: Product {0}://{1} updated", database.Name, id), this);
                            database.Caches.ItemCache.RemoveItem(id);
                            database.Caches.DataCache.RemoveItemInformation(id);
                            database.Engines.DataEngine.RaiseSavedItem(item, true);
                            var args = new ItemSavedEventArgs(item);
                            Sitecore.Events.Event.RaiseItemSaved(this, args);
                            //TODO: Something to cause reindex in web, new indexing strategy?
                            //TODO: Clear HTML cache?
                        }
                    }
                    else if (cursor.IsDead)
                    {
                        //TODO: restart mechanism?
                        Sitecore.Diagnostics.Log.Info("MongoOplogCacheClearer: Dead", this);
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                Sitecore.Diagnostics.Log.Error("Exception starting MongoDb oplog monitoring", e, this);
            }
        }
        internal void OnItemSaved(object sender, EventArgs args)
        {
            Assert.ArgumentNotNull(sender, "sender");
            Assert.ArgumentNotNull(args, "args");

            var sitecoreArgs = args as SitecoreEventArgs;
            if (sitecoreArgs == null) return;

            var arguments = new ItemSavedEventArgs((Item)sitecoreArgs.Parameters[0], (ItemChanges)sitecoreArgs.Parameters[1]);
            
            var item = arguments.Item;
            if (item == null) return;

            //Is Module Disabled at the config level?
            if (DynamicSiteSettings.Disabled) return;

            try
            {
                //Skip if current database doesn't keep content items.
                if (!Context.Database.HasContentItem) return;

                //Reset Cache if Item is Dynamic Site.
                ResetDynamicSitesCache(item);

                //If Item being saved is the Dynamic Site Settings Item, Make Updates
                //Return otherwise.
                if (item.TemplateID != new ID(DynamicSiteSettingsItem.TemplateId)) return;

                //Get ItemChanges
                var itemChanges = arguments.Changes;

                //Do Base Template Updates to Activate Dynamic Sites
                DoBaseTemplateUpdates(item, itemChanges);
            }
            catch (NullReferenceException ne)
            {
                //Do nothing. 
            }
            catch (Exception e)
            {
                Log.Error(String.Format("[DynamicSites] Error: {0} \r\n Stack: {1}",e.Message,e.StackTrace),e);
            }
        }
 private void ItemSavedNotification(object sender, ItemSavedEventArgs args)
 {
     VersionCreated = true;
     ToggleVisibilityOfControlsOnFinalLayoutTab(args.Item);
     SheerResponse.SetDialogValue(GetDialogResult());
 }