コード例 #1
0
ファイル: SharingNodeObserver.cs プロジェクト: y1027/sensenet
        protected override void OnNodeDeletedPhysically(object sender, NodeEventArgs e)
        {
            base.OnNodeDeletedPhysically(sender, e);

            SharingHandler.OnContentDeleted(e?.SourceNode);

            // if there are sharing groups that should be deleted
            var sharingGroupIds = e?.GetCustomData(SharingGroupIdsCustomDataKey) as int[];

            if (sharingGroupIds?.Any() ?? false)
            {
                //TODO: if the list is too big, postpone deleting the groups
                // using a local task management API.

                System.Threading.Tasks.Task.Run(() =>
                {
                    try
                    {
                        using (new SystemAccount())
                        {
                            Parallel.ForEach(sharingGroupIds.Select(Node.LoadNode).Where(n => n != null),
                                             new ParallelOptions {
                                MaxDegreeOfParallelism = 4
                            },
                                             group => group.ForceDelete());
                        }
                    }
                    catch (System.Exception ex)
                    {
                        SnLog.WriteException(ex, "Error during deleting sharing groups.");
                    }
                });
            }
        }