Example #1
0
        internal List <ContentCommandBase.ContentHolder> GetContentReaders(string[] readerPaths, CmdletProviderContext currentCommandContext)
        {
            Collection <PathInfo> pathInfos = this.ResolvePaths(readerPaths, false, true, currentCommandContext);
            List <ContentCommandBase.ContentHolder> contentHolders = new List <ContentCommandBase.ContentHolder>();

            foreach (PathInfo pathInfo in pathInfos)
            {
                Collection <IContentReader> reader = null;
                try
                {
                    string path = WildcardPattern.Escape(pathInfo.Path);
                    if (currentCommandContext.SuppressWildcardExpansion)
                    {
                        path = pathInfo.Path;
                    }
                    reader = base.InvokeProvider.Content.GetReader(path, currentCommandContext);
                }
                catch (PSNotSupportedException pSNotSupportedException1)
                {
                    PSNotSupportedException pSNotSupportedException = pSNotSupportedException1;
                    base.WriteError(new ErrorRecord(pSNotSupportedException.ErrorRecord, pSNotSupportedException));
                    continue;
                }
                catch (DriveNotFoundException driveNotFoundException1)
                {
                    DriveNotFoundException driveNotFoundException = driveNotFoundException1;
                    base.WriteError(new ErrorRecord(driveNotFoundException.ErrorRecord, driveNotFoundException));
                    continue;
                }
                catch (ProviderNotFoundException providerNotFoundException1)
                {
                    ProviderNotFoundException providerNotFoundException = providerNotFoundException1;
                    base.WriteError(new ErrorRecord(providerNotFoundException.ErrorRecord, providerNotFoundException));
                    continue;
                }
                catch (ItemNotFoundException itemNotFoundException1)
                {
                    ItemNotFoundException itemNotFoundException = itemNotFoundException1;
                    base.WriteError(new ErrorRecord(itemNotFoundException.ErrorRecord, itemNotFoundException));
                    continue;
                }
                if (reader == null || reader.Count <= 0 || reader.Count != 1 || reader[0] == null)
                {
                    continue;
                }
                ContentCommandBase.ContentHolder contentHolder = new ContentCommandBase.ContentHolder(pathInfo, reader[0], null);
                contentHolders.Add(contentHolder);
            }
            return(contentHolders);
        }
        internal List <ContentCommandBase.ContentHolder> GetContentWriters(string[] writerPaths, CmdletProviderContext currentCommandContext)
        {
            Collection <PathInfo> pathInfos = base.ResolvePaths(writerPaths, true, false, currentCommandContext);
            List <ContentCommandBase.ContentHolder> contentHolders = new List <ContentCommandBase.ContentHolder>();

            foreach (PathInfo pathInfo in pathInfos)
            {
                Collection <IContentWriter> writer = null;
                try
                {
                    writer = base.InvokeProvider.Content.GetWriter(pathInfo.Path, currentCommandContext);
                }
                catch (PSNotSupportedException pSNotSupportedException1)
                {
                    PSNotSupportedException pSNotSupportedException = pSNotSupportedException1;
                    base.WriteError(new ErrorRecord(pSNotSupportedException.ErrorRecord, pSNotSupportedException));
                    continue;
                }
                catch (DriveNotFoundException driveNotFoundException1)
                {
                    DriveNotFoundException driveNotFoundException = driveNotFoundException1;
                    base.WriteError(new ErrorRecord(driveNotFoundException.ErrorRecord, driveNotFoundException));
                    continue;
                }
                catch (ProviderNotFoundException providerNotFoundException1)
                {
                    ProviderNotFoundException providerNotFoundException = providerNotFoundException1;
                    base.WriteError(new ErrorRecord(providerNotFoundException.ErrorRecord, providerNotFoundException));
                    continue;
                }
                catch (ItemNotFoundException itemNotFoundException1)
                {
                    ItemNotFoundException itemNotFoundException = itemNotFoundException1;
                    base.WriteError(new ErrorRecord(itemNotFoundException.ErrorRecord, itemNotFoundException));
                    continue;
                }
                if (writer == null || writer.Count <= 0 || writer.Count != 1 || writer[0] == null)
                {
                    continue;
                }
                ContentCommandBase.ContentHolder contentHolder = new ContentCommandBase.ContentHolder(pathInfo, null, writer[0]);
                contentHolders.Add(contentHolder);
            }
            return(contentHolders);
        }
Example #3
0
		internal List<ContentCommandBase.ContentHolder> GetContentWriters(string[] writerPaths, CmdletProviderContext currentCommandContext)
		{
			Collection<PathInfo> pathInfos = base.ResolvePaths(writerPaths, true, false, currentCommandContext);
			List<ContentCommandBase.ContentHolder> contentHolders = new List<ContentCommandBase.ContentHolder>();
			foreach (PathInfo pathInfo in pathInfos)
			{
				Collection<IContentWriter> writer = null;
				try
				{
					writer = base.InvokeProvider.Content.GetWriter(pathInfo.Path, currentCommandContext);
				}
				catch (PSNotSupportedException pSNotSupportedException1)
				{
					PSNotSupportedException pSNotSupportedException = pSNotSupportedException1;
					base.WriteError(new ErrorRecord(pSNotSupportedException.ErrorRecord, pSNotSupportedException));
					continue;
				}
				catch (DriveNotFoundException driveNotFoundException1)
				{
					DriveNotFoundException driveNotFoundException = driveNotFoundException1;
					base.WriteError(new ErrorRecord(driveNotFoundException.ErrorRecord, driveNotFoundException));
					continue;
				}
				catch (ProviderNotFoundException providerNotFoundException1)
				{
					ProviderNotFoundException providerNotFoundException = providerNotFoundException1;
					base.WriteError(new ErrorRecord(providerNotFoundException.ErrorRecord, providerNotFoundException));
					continue;
				}
				catch (ItemNotFoundException itemNotFoundException1)
				{
					ItemNotFoundException itemNotFoundException = itemNotFoundException1;
					base.WriteError(new ErrorRecord(itemNotFoundException.ErrorRecord, itemNotFoundException));
					continue;
				}
				if (writer == null || writer.Count <= 0 || writer.Count != 1 || writer[0] == null)
				{
					continue;
				}
				ContentCommandBase.ContentHolder contentHolder = new ContentCommandBase.ContentHolder(pathInfo, null, writer[0]);
				contentHolders.Add(contentHolder);
			}
			return contentHolders;
		}
Example #4
0
        private bool ScanForwardsForTail(ContentCommandBase.ContentHolder holder, CmdletProviderContext currentContext)
        {
            FileSystemContentReaderWriter reader = holder.Reader as FileSystemContentReaderWriter;
            Queue <object> objs        = new Queue <object>();
            IList          lists       = null;
            ErrorRecord    errorRecord = null;

            do
            {
                try
                {
                    lists = reader.ReadWithoutWaitingChanges(this.ReadCount);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    CommandsCommon.CheckForSevereException(this, exception);
                    ProviderInvocationException providerInvocationException = new ProviderInvocationException("ProviderContentReadError", SessionStateStrings.ProviderContentReadError, holder.PathInfo.Provider, holder.PathInfo.Path, exception);
                    MshLog.LogProviderHealthEvent(base.Context, holder.PathInfo.Provider.Name, providerInvocationException, Severity.Warning);
                    errorRecord = new ErrorRecord(providerInvocationException.ErrorRecord, providerInvocationException);
                    break;
                }
                if (lists == null || lists.Count <= 0)
                {
                    continue;
                }
                foreach (object obj in lists)
                {
                    if (objs.Count == this.Tail)
                    {
                        objs.Dequeue();
                    }
                    objs.Enqueue(obj);
                }
            }while (lists != null && lists.Count > 0);
            if (objs.Count > 0)
            {
                int count = 0;
                if (this.ReadCount <= (long)0 || this.ReadCount >= (long)objs.Count && this.ReadCount != (long)1)
                {
                    count = objs.Count;
                    ArrayList arrayLists = new ArrayList();
                    while (objs.Count > 0)
                    {
                        arrayLists.Add(objs.Dequeue());
                    }
                    base.WriteContentObject(arrayLists.ToArray(), (long)count, holder.PathInfo, currentContext);
                }
                else
                {
                    if (this.ReadCount != (long)1)
                    {
                        while ((long)objs.Count >= this.ReadCount)
                        {
                            ArrayList arrayLists1 = new ArrayList();
                            int       num         = 0;
                            while ((long)num < this.ReadCount)
                            {
                                arrayLists1.Add(objs.Dequeue());
                                num++;
                                count++;
                            }
                            base.WriteContentObject(arrayLists1.ToArray(), (long)count, holder.PathInfo, currentContext);
                        }
                        int count1 = objs.Count;
                        if (count1 > 0)
                        {
                            ArrayList arrayLists2 = new ArrayList();
                            while (count1 > 0)
                            {
                                arrayLists2.Add(objs.Dequeue());
                                count1--;
                                count++;
                            }
                            base.WriteContentObject(arrayLists2.ToArray(), (long)count, holder.PathInfo, currentContext);
                        }
                    }
                    else
                    {
                        while (objs.Count > 0)
                        {
                            int num1 = count;
                            count = num1 + 1;
                            base.WriteContentObject(objs.Dequeue(), (long)num1, holder.PathInfo, currentContext);
                        }
                    }
                }
            }
            if (errorRecord == null)
            {
                return(true);
            }
            else
            {
                base.WriteError(errorRecord);
                return(false);
            }
        }