Пример #1
0
        /// <summary>
        /// Convert to List and sort
        /// </summary>
        /// <param name="items"></param>
        /// <returns></returns>
        private static List <RecycleBinItem> CovertToRecycleBinItemList(RecycleBinItemCollection items)
        {
            var recycleBinItems = items.ToList();

            recycleBinItems.Sort((x, y) =>
            {
                if (x.DeletedDate > y.DeletedDate)
                {
                    return(1);
                }
                if (x.DeletedDate < y.DeletedDate)
                {
                    return(-1);
                }
                return(-0);
            });
            return(recycleBinItems);
        }
Пример #2
0
        protected override void ExecuteCmdlet()
        {
            DefaultRetrievalExpressions = new Expression <Func <RecycleBinItem, object> >[] { r => r.Id, r => r.Title, r => r.ItemType, r => r.LeafName, r => r.DirName };
            if (ParameterSetName == ParameterSet_IDENTITY)
            {
                RecycleBinItem item = ClientContext.Site.RecycleBin.GetById(Identity.Id);

                ClientContext.Load(item, RetrievalExpressions);
                ClientContext.ExecuteQueryRetry();
                WriteObject(item);
            }
            else
            {
#if !SP2013
                if (ParameterSpecified(nameof(RowLimit)))
                {
                    RecycleBinItemState recycleBinStage;
                    switch (ParameterSetName)
                    {
                    case ParameterSet_FIRSTSTAGE:
                        recycleBinStage = RecycleBinItemState.FirstStageRecycleBin;
                        break;

                    case ParameterSet_SECONDSTAGE:
                        recycleBinStage = RecycleBinItemState.SecondStageRecycleBin;
                        break;

                    default:
                        recycleBinStage = RecycleBinItemState.None;
                        break;
                    }

                    RecycleBinItemCollection items = ClientContext.Site.GetRecycleBinItems(null, RowLimit, false, RecycleBinOrderBy.DeletedDate, recycleBinStage);
                    ClientContext.Load(items);
                    ClientContext.ExecuteQueryRetry();

                    List <RecycleBinItem> recycleBinItemList = items.ToList();
                    WriteObject(recycleBinItemList, true);
                }
                else
                {
                    ClientContext.Site.Context.Load(ClientContext.Site.RecycleBin, r => r.IncludeWithDefaultProperties(RetrievalExpressions));
                    ClientContext.Site.Context.ExecuteQueryRetry();

                    List <RecycleBinItem> recycleBinItemList = ClientContext.Site.RecycleBin.ToList();

                    switch (ParameterSetName)
                    {
                    case ParameterSet_FIRSTSTAGE:
                        WriteObject(
                            recycleBinItemList.Where(i => i.ItemState == RecycleBinItemState.FirstStageRecycleBin), true);
                        break;

                    case ParameterSet_SECONDSTAGE:
                        WriteObject(
                            recycleBinItemList.Where(i => i.ItemState == RecycleBinItemState.SecondStageRecycleBin),
                            true);
                        break;

                    default:
                        WriteObject(recycleBinItemList, true);
                        break;
                    }
                }
#else
                ClientContext.Site.Context.Load(ClientContext.Site.RecycleBin, r => r.IncludeWithDefaultProperties(RetrievalExpressions));
                ClientContext.Site.Context.ExecuteQueryRetry();

                List <RecycleBinItem> recycleBinItemList = ClientContext.Site.RecycleBin.ToList();

                switch (ParameterSetName)
                {
                case ParameterSet_FIRSTSTAGE:
                    WriteObject(
                        recycleBinItemList.Where(i => i.ItemState == RecycleBinItemState.FirstStageRecycleBin), true);
                    break;

                case ParameterSet_SECONDSTAGE:
                    WriteObject(
                        recycleBinItemList.Where(i => i.ItemState == RecycleBinItemState.SecondStageRecycleBin),
                        true);
                    break;

                default:
                    WriteObject(recycleBinItemList, true);
                    break;
                }
#endif
            }
        }