Esempio n. 1
0
        private bool IsMatch(string path, IDriveItem driveItem)
        {
            string fullName = driveItem.FullName;

            if (path.Contains("*"))
            {
                WildcardPattern pattern = new WildcardPattern(path, WildcardOptions.IgnoreCase);
                return(pattern.IsMatch(fullName));
            }

            return(string.Equals(fullName, path, StringComparison.OrdinalIgnoreCase));
        }
Esempio n. 2
0
        private async Task <IDriveItem> UploadFile(byte[] byteArray, IReportBodyDetails reportDetails, string fileName, ITurnContext context, CancellationToken cancellationToken)
        {
            using (var stream = new MemoryStream(byteArray))
            {
                stream.Position = 0;
                stream.Flush();
                IDriveItem file =
                    await graphClient.UploadFileInPersonalOneDrive(() => context.GetUserTokenAsync(this.connectionName, cancellationToken), stream, fileName);

                return(file);
            }
        }
Esempio n. 3
0
        private IEnumerable <IDriveItem> GetChildItems(IDriveItem item, ReturnContainers returnContainers = ReturnContainers.ReturnMatchingContainers)
        {
            IEnumerable <IDriveItem> childItems = ((IContainer)item).GetChildItems(DynamicParameters);
            bool useFilter = !string.IsNullOrEmpty(Filter);

            if (useFilter)
            {
                WildcardPattern pattern             = new WildcardPattern(Filter, WildcardOptions.IgnoreCase);
                bool            returnAllContainers = returnContainers == ReturnContainers.ReturnAllContainers;
                return(childItems.Where(i => (returnAllContainers && i is Container) || pattern.IsMatch(i.Name)));
            }
            return(childItems);
        }
Esempio n. 4
0
        public static Activity GetPersonalFileCard(IDriveItem file, string text)
        {
            var card = new FileInfoCard()
            {
                FileType = Path.GetExtension(file.FileName).Replace(".", string.Empty),
                UniqueId = file.UniqueId,
            };
            var attachment = card.ToAttachment(file.FileName, file.ContentUrl);
            var message    = MessageFactory.Text(Resources.Strings.DialogReportReadyMessage);

            message.Attachments.Add(attachment);
            return(message);
        }
Esempio n. 5
0
        protected override bool HasChildItems(string path)
        {
            if (PathIsDrive(path))
            {
                TraceDebug($"HasChildItems.path: \"{path}\" Path is drive. return true;");
                return(true);
            }

            IDriveItem item        = GetItemValue(path);
            bool       hasChildren = item is IContainer;

            TraceDebug($"HasChildItems.path: \"{path}\" return {hasChildren};");
            return(hasChildren);
        }
Esempio n. 6
0
        protected override bool ItemExists(string path)
        {
            if (PathIsDrive(path))
            {
                TraceDebug($"ItemExists.path: \"{path}\" Path is drive. return true;");
                return(true);
            }

            IDriveItem item       = GetItemValue(path);
            bool       itemExists = item != null;

            TraceDebug($"ItemExists.path: \"{path}\" return {itemExists};");
            return(itemExists);
        }
Esempio n. 7
0
        protected override string GetChildName(string path)
        {
            if (PathIsDrive(path))
            {
                TraceDebug($"GetChildName.path: {path} path is drive so returning path, which was received.");
                return(string.Empty);
            }

            path = MakeAbsolutePath(path);

            IDriveItem item = GetItemValue(path);

            TraceDebug($"GetChildName.path: {path} is not the drive, so returning: {item.Name}");
            return(item.Name);
        }
Esempio n. 8
0
        protected override void GetChildNames(string path, ReturnContainers returnContainers)
        {
            IDriveItem item = GetItemValue(path);

            if (item is IContainerItem)
            {
                TraceDebug($"GetChildNames.path: \"{path}\" GetChildItems.returnContainers: \"{returnContainers}\" return without doing anything, item is file info;");
                return;
            }

            foreach (IDriveItem child in GetChildItems(item, returnContainers))
            {
                bool isContainer = child is IContainer;

                TraceDebug($"GetChildNames.path: \"{path}\" GetChildItems.returnContainers: \"{returnContainers}\"  WriteItemObject(child.Name, child.FullName, isContainer) child.Name: {child.Name} child.FullName: {child.FullName} isContainer: {isContainer};");
                WriteItemObject(child.Name, child.FullName, isContainer);
            }
        }
Esempio n. 9
0
        protected IDriveItem GetItemValue(string path)
        {
            if (string.IsNullOrEmpty(path) || (null != PSDriveInfo && string.Equals(PSDriveInfo.Root, path, StringComparison.OrdinalIgnoreCase)))
            {
                return(DriveContent);
            }

            path = EnsureDriveIsRooted(path);
            path = path.TrimEnd('\\');

            IDriveItem item = DriveContent.GetItemValue(path);

            if (null == item)
            {
                TraceDebug($"GetItemValue: path \"{path}\" not found.");
            }

            return(item);
        }
Esempio n. 10
0
        private async Task <IDriveItem> UploadReportAsync(ITurnContext context, IReportBodyDetails reportDetails, byte[] reportBytes, ReportFormatType format, CancellationToken cancellationToken)
        {
            IDriveItem file       = null;
            var        folderName = string.IsNullOrEmpty(reportsFolderName) ? string.Empty : (reportsFolderName + "/");
            var        fileName   = $"{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}_history_report";

            var reportBytesToUpload = reportBytes;

            switch (format)
            {
            case ReportFormatType.TXT:
            {
                fileName = $"{fileName}_.txt";
                break;
            }

            case ReportFormatType.JSON:
            {
                fileName = $"{fileName}_.json";
                break;
            }

            case ReportFormatType.HTML:
            {
                fileName = $"{fileName}_.html";
                break;
            }

            case ReportFormatType.PDF:
            {
                fileName = $"{fileName}_.pdf";
                break;
            }
            }

            file = await UploadFile(reportBytesToUpload, reportDetails, $"{folderName}{fileName}", context, cancellationToken);

            file.FileName = fileName;
            return(file);
        }
Esempio n. 11
0
        protected override void GetItem(string path)
        {
            if (PathIsDrive(path))
            {
                TraceDebug($"GetItem.path: \"{path}\" WriteItemObject(PSDriveInfo, path, true)");
                WriteItemObject(PSDriveInfo, path, true);
                return;
            }

            IDriveItem item = GetItemValue(path);

            if (item == null)
            {
                WriteError(new ErrorRecord(new ArgumentException($"The item at the path \"{path}\" does not exist. Get-Item failed."), "GetItem", ErrorCategory.InvalidArgument, path));
                return;
            }

            bool isContainer = item is IContainer;

            TraceDebug($"GetItem.path: \"{path}\" WriteItemObject(item, path, true) Item.path: {item.FullName}");
            WriteItemObject(item, item.FullName, isContainer);
        }
Esempio n. 12
0
        protected override void RemoveItem(string path, bool recurse)
        {
            TraceDebug($"RemoveItem.path: \"{path}\" recurse: \"{recurse}\"");

            if (recurse)
            {
                WriteError(new ErrorRecord(new NotSupportedException("Remove-Item -Recurse switch not supported."), "RemoveItemRecurseNotSupported", ErrorCategory.NotImplemented, path));
                return;
            }

            IDriveItem item = GetItemValue(path);

            if (null == item)
            {
                string message = $"The item at the path \"{path}\" not found, Remove-Item failed.";
                WriteError(new ErrorRecord(new ItemNotFoundException(message), "RemoveItemItemNotFound", ErrorCategory.InvalidOperation, path));
                return;
            }

            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            item.RemoveItem(recurse);
        }
Esempio n. 13
0
        protected override void GetChildItems(string path, bool recurse)
        {
            IDriveItem item = GetItemValue(path);

            if (!(item is IContainer))
            {
                TraceDebug($"GetChildItems.path: \"{path}\" GetChildItems.recurse: \"{recurse}\" return without doing anything, item is not a container.");
                return;
            }

            foreach (IDriveItem child in GetChildItems(item))
            {
                bool isContainer = child is IContainer;

                TraceDebug($"GetChildItems.path: \"{path}\" GetChildItems.recurse: \"{recurse}\" WriteItemObject(child.Name, child.FullName, isContainer); child.Name: {child.Name} child.FullName: {child.FullName} isContainer: {isContainer}");
                WriteItemObject(child, child.FullName, isContainer);

                if (isContainer && recurse)
                {
                    GetChildItems(child.FullName, recurse);
                }
            }
        }
Esempio n. 14
0
        public IDriveItem GetItemValue(string path)
        {
            List <IDriveItem> childItems = GetChildItems(null).ToList();

            foreach (IDriveItem childItem in childItems)
            {
                if (IsMatch(path, childItem))
                {
                    return(childItem);
                }

                bool pathIsInCurrentBranch = path.StartsWith(childItem.FullName, StringComparison.OrdinalIgnoreCase);
                if (pathIsInCurrentBranch)
                {
                    IDriveItem item = (childItem as IContainer)?.GetItemValue(path);
                    if (item != null)
                    {
                        return(item);
                    }
                }
            }

            return(null);
        }
Esempio n. 15
0
        protected override bool IsValidPath(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                WriteDebug($"IsValidPath.path: {path} is empty returning false;");
                return(false);
            }

            string modifiedPath = path;

            modifiedPath = EnsureDriveIsRooted(modifiedPath);
            int num    = modifiedPath.IndexOf(':');
            int length = modifiedPath.IndexOf(':', num + 1);

            if (length > 0)
            {
                modifiedPath = modifiedPath.Substring(0, length);
            }

            bool isAbsolutePath = modifiedPath.Contains(":");

            if (!isAbsolutePath)
            {
                WriteDebug($"IsValidPath.path: {path}, modified path: {modifiedPath} is not an absolute path, returning false;");
                return(false);
            }

            IDriveItem info = GetItemValue(modifiedPath);

            if (info == null)
            {
                WriteDebug($"IsValidPath.path: {path} not found IDriveItem.");
            }

            return(true);
        }
Esempio n. 16
0
        protected override object InvokeDefaultActionDynamicParameters(string path)
        {
            IDriveItem item = GetItemValue(path);

            return(item.InvokeDefaultActionDynamicParameters());
        }
Esempio n. 17
0
        protected override void InvokeDefaultAction(string path)
        {
            IDriveItem item = GetItemValue(path);

            item.InvokeDefaultAction(DynamicParameters);
        }
Esempio n. 18
0
        protected override bool IsItemContainer(string path)
        {
            IDriveItem item = GetItemValue(path);

            return(item is IContainer);
        }
Esempio n. 19
0
        public void Update(IDriveItem item)
        {
            this.Id = item.Id;
            this.Name = item.Name;
            this.CreatedDateTime = item.CreatedDateTime.HasValue ? item.CreatedDateTime.Value.DateTime : (DateTime?)null;
            this.LastModifiedDateTime = item.LastModifiedDateTime.HasValue ? item.LastModifiedDateTime.Value.DateTime : (DateTime?)null;
            this.WebUrl = item.WebUrl;
            
            //var createdByid = item.CreatedBy?.User?.Id;
            //this.CreatedByUser = createdByid != null ? UserViewModel.GetUser(createdByid, null) : UserViewModel.Empty;

            //var lastModifiedById = item.LastModifiedBy?.User?.Id;
            //this.LastModifiedByUser = lastModifiedById != null ? UserViewModel.GetUser(lastModifiedById, null) : UserViewModel.Empty;

            FileInfo fi = new FileInfo(this.Name);
             
            this.FileExtension = fi.Extension;
            this.FileExtensionIcon = ImageHelper.GetImageExtensions(fi.Extension);
            this.FileExtensionIconColor = new SolidColorBrush(ImageHelper.GetFileExtensionColor(fi.Extension));

            this.FriendlyName = this.Name.Replace(this.FileExtension, "");

            this.FriendlyExtensionName = ImageHelper.GetDocumentType(fi.Extension);

            if (this.CreatedDateTime.HasValue)
                this.CreatedDateTime = this.CreatedDateTime.Value.ToLocalTime();

            if (this.LastModifiedDateTime.HasValue)
                this.LastModifiedDateTime = this.LastModifiedDateTime.Value.ToLocalTime();
        }