Example #1
0
        public void UpdateContentType()
        {
            _containsNodeOrBrowserFiles = false;

            // Iterate through all of the javascript files in a directory to determine whether
            // the build actions are Content, Compile, or a mix of the two.
            var fileNodesEnumerator       = this.EnumNodesOfType <NodejsFileNode>().GetEnumerator();
            FolderContentType contentType = FolderContentType.None;

            while (fileNodesEnumerator.MoveNext())
            {
                if (!fileNodesEnumerator.Current.Url.EndsWith(".js", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                var properties = fileNodesEnumerator.Current.NodeProperties as IncludedFileNodeProperties;
                if (properties != null)
                {
                    _containsNodeOrBrowserFiles = true;
                    switch (properties.BuildAction)
                    {
                    case prjBuildAction.prjBuildActionContent:
                        contentType |= FolderContentType.Browser;
                        break;

                    case prjBuildAction.prjBuildActionCompile:
                        contentType |= FolderContentType.Node;
                        break;
                    }

                    if (contentType == FolderContentType.Mixed)
                    {
                        break;
                    }
                }
            }

            // If there are no relevant javascript files in the folder, then fall back to
            // the parent type. This enables us to provide good defaults in the event that
            // an item is added to the directory later.
            var parent = this.Parent as NodejsFolderNode;

            if (contentType == FolderContentType.None)
            {
                // Set as parent content type
                if (parent != null)
                {
                    contentType = parent.ContentType;
                }
            }

            _contentType = contentType;
            ProjectMgr.ReDrawNode(this, UIHierarchyElement.Caption);

            // Update the caption of the parent folder accordingly
            if (parent != null)
            {
                parent.UpdateContentType();
            }
        }
        /// <summary>
        /// Recursively lists the items in a folder that have a certain suffix (wildcards are not supported).
        /// without having to return them all at once via an array.
        /// This is useful if there are a very large number of files in a folder.
        /// </summary>
        /// <param name="folderName">The name of a folder.</param>
        /// <param name="fileSuffix">
        /// A file suffix to match, or "" or null to match all files.
        /// This is used only for files; if folders are being returned, all folders are returned regardless of their suffixes.
        /// </param>
        /// <param name="contentType">Type of the content to be returned.</param>
        /// <returns>An enumerator for all the items.</returns>

        private static IEnumerable <FolderItem> recursiveFolderContents
        (
            string folderName,
            string fileSuffix,
            FolderContentType contentType
        )
        {
            bool wantAllFiles = string.IsNullOrEmpty(fileSuffix);

            foreach (FolderItem item in FolderContents(folderName, null, FolderContentType.FilesAndFolders))
            {
                if (item.IsFolder)  // Visit all items in subfolders.
                {
                    foreach (FolderItem recursedItem in recursiveFolderContents(item.Name, fileSuffix, contentType))
                    {
                        yield return(recursedItem);
                    }

                    if (contentType != FolderContentType.FilesOnly)
                    {
                        yield return(item);
                    }
                }
                else  // It's a file.
                {
                    if (contentType != FolderContentType.FoldersOnly)
                    {
                        if (wantAllFiles || string.Equals(Path.GetExtension(item.Name), fileSuffix, StringComparison.CurrentCultureIgnoreCase))
                        {
                            yield return(item);
                        }
                    }
                }
            }
        }
 public TModel GetByFullPath(string name, string path, FolderContentType type)
 {
     if (!IsFolderContentExist(name, path, type))
     {
         return(default(TModel));
     }
     return(ReadJson(CreateJsonPath(name, path, type)));
 }
 public void Delete(string name, string path, FolderContentType type)
 {
     if (!FileManager.Exists(CreateJsonPath(name, path, type)))
     {
         return;
     }
     FileManager.Delete(CreateJsonPath(name, path, type));
 }
Example #5
0
 public FolderContent(string name, string path, FolderContentType type)
 {
     Name             = name;
     Path             = path;
     Type             = type;
     CreationTime     = $"{DateTime.Now:G}";
     ModificationTime = $"{DateTime.Now:G}";
 }
 private string CreateJsonPath(string name, string path, FolderContentType type)
 {
     ConvertNameAndPathToLower(name, path, out var lowerName, out var lowerPath);
     lowerPath = lowerPath.Replace('/', '\\');
     return
         (string.IsNullOrEmpty(path) ?
          $"{_constance.BaseFolderPath}\\{lowerName}{type.ToString()}.json" :
          $"{_constance.BaseFolderPath}\\{lowerPath}\\{lowerName}{type.ToString()}.json");
 }
Example #7
0
 public FolderContent(string name, string path, FolderContentType type, string creationTime, string modificationTime, long size)
 {
     Name             = name;
     Path             = path;
     Type             = type;
     CreationTime     = creationTime;
     ModificationTime = modificationTime;
     Size             = size;
 }
        public void UpdateContentType() {
            var oldContentType = _contentType;
            _contentType = FolderContentType.None;
            var parent = Parent as NodejsFolderNode;
            _containsNodeOrBrowserFiles = false;

            if (ItemNode.IsExcluded || ItemNode.Url.Contains(NodejsConstants.NodeModulesFolder)) {
                _contentType = FolderContentType.None;
            } else {
                // Iterate through all of the javascript files in a directory to determine whether
                // the build actions are Content, Compile, or a mix of the two.
                var nodejsFileNodes = EnumNodesOfType<NodejsFileNode>();
                FolderContentType contentType = FolderContentType.None;
                foreach (var fileNode in nodejsFileNodes) {
                    if (!fileNode.Url.EndsWith(".js", StringComparison.OrdinalIgnoreCase)) {
                        continue;
                    }

                    var properties = fileNode.NodeProperties as IncludedFileNodeProperties;
                    if (properties != null) {
                        _containsNodeOrBrowserFiles = true;
                        switch (properties.BuildAction) {
                            case prjBuildAction.prjBuildActionContent:
                                contentType |= FolderContentType.Browser;
                                break;
                            case prjBuildAction.prjBuildActionCompile:
                                contentType |= FolderContentType.Node;
                                break;
                        }

                        if (contentType == FolderContentType.Mixed) {
                            break;
                        }
                    }
                }

                // If there are no relevant javascript files in the folder, then fall back to
                // the parent type. This enables us to provide good defaults in the event that
                // an item is added to the directory later.
                if (contentType == FolderContentType.None) {
                    // Set as parent content type 
                    if (parent != null) {
                        contentType = parent.ContentType;
                    }
                }

                _contentType = contentType;
                ProjectMgr.ReDrawNode(this, UIHierarchyElement.Caption);
            }

            // Update the caption of the parent folder accordingly
            if (parent != null && _contentType != oldContentType) {
                parent.UpdateContentType();
            }
        }
        public async Task <List <AttachmentBase> > GetAllAttachmentsAsync(FolderContentType folderContentType, string itemId)
        {
            // Get all attachments of the specified item.
            // The property of the item to get is very limited.

            Uri URL;

            List <AttachmentBase> result = new List <AttachmentBase>();

            switch (folderContentType)
            {
            case FolderContentType.Message:
            case FolderContentType.MsgFolderRoot:
            case FolderContentType.Drafts:
                URL = Util.UseMicrosoftGraphInMailboxViewer ? new Uri($"https://graph.microsoft.com/v1.0/me/messages/{itemId}/attachments/?$Top=1000&$select=Id,Name,ContentType") : new Uri($"https://outlook.office.com/api/v2.0/me/messages/{itemId}/attachments/?$Top=1000&$select=Id,Name,ContentType");
                break;

            case FolderContentType.Calendar:
                URL = Util.UseMicrosoftGraphInMailboxViewer? new Uri($"https://graph.microsoft.com/v1.0/me/events/{itemId}/attachments/?$Top=1000&$select=Id,Name,ContentType") : new Uri($"https://outlook.office.com/api/v2.0/me/events/{itemId}/attachments/?$Top=1000&$select=Id,Name,ContentType");
                break;

            case FolderContentType.Task:
                URL = Util.UseMicrosoftGraphInMailboxViewer ? new Uri($"https://graph.microsoft.com/beta/me/outlook/tasks/{itemId}/attachments/?$Top=1000&$select=Id,Name,ContentType") : new Uri($"https://outlook.office.com/api/v2.0/me/tasks/{itemId}/attachments/?$Top=1000&$select=Id,Name,ContentType");
                break;

            case FolderContentType.Contact:
            // contact item (Contact API) does not have attachment.
            default:
                return(new List <AttachmentBase>());
            }

            try
            {
                string stringResponse = await SendGetRequestAsync(URL);

                var jsonResponse = (JObject)JsonConvert.DeserializeObject(stringResponse);
                var attachments  = (JArray)jsonResponse.GetValue("value");

                foreach (var item in attachments)
                {
                    var serializedObject = new AttachmentBase(JsonConvert.SerializeObject(item));
                    result.Add(serializedObject);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(result);
        }
Example #10
0
 /// <summary>
 /// Append a label denoting browser-side code, node, or both depending on the content type
 /// 
 /// </summary>
 /// <param name="folderName"></param>
 /// <param name="contentType"></param>
 /// <returns></returns>
 public static string AppendLabel(string folderName, FolderContentType contentType) {
     switch (contentType) {
         case FolderContentType.Browser:
             folderName += " (browser)";
             break;
         case FolderContentType.Node:
             folderName += " (node)";
             break;
         case FolderContentType.Mixed:
             folderName += " (node, browser)";
             break;
     }
     return folderName;
 }
        private bool CanAcquire(string name, string path, FolderContentType folderContentType)
        {
            foreach (var list in _concurrentOperationToFolderContent.Values)
            {
                if (list.Any(fc =>
                             fc.Path == path &&
                             fc.Name == name &&
                             fc.Type == folderContentType))
                {
                    return(false);
                }
            }

            return(true);
        }
        public async Task <Dictionary <string, string> > GetAttachmentAsync(FolderContentType folderContentType, string itemId, string attachmentId)
        {
            // Get the specified item.

            Uri URL;

            switch (folderContentType)
            {
            case FolderContentType.Message:
            case FolderContentType.MsgFolderRoot:
            case FolderContentType.Drafts:
                URL = Util.UseMicrosoftGraphInMailboxViewer ? new Uri("https://graph.microsoft.com/beta/me/messages/" + itemId + "/attachments/" + attachmentId) : new Uri("https://outlook.office.com/api/v2.0/me/messages/" + itemId + "/attachments/" + attachmentId);
                break;

            case FolderContentType.Calendar:
                URL = Util.UseMicrosoftGraphInMailboxViewer ? new Uri("https://graph.microsoft.com/beta/me/events/" + itemId + "/attachments/" + attachmentId) : new Uri("https://outlook.office.com/api/v2.0/me/events/" + itemId + "/attachments/" + attachmentId);
                break;

            case FolderContentType.Task:
                URL = Util.UseMicrosoftGraphInMailboxViewer ? new Uri("https://graph.microsoft.com/beta/me/outlook/tasks/" + itemId + "/attachments/" + attachmentId) : new Uri("https://outlook.office.com/api/v2.0/me/tasks/" + itemId + "/attachments/" + attachmentId);
                break;

            default:
                throw new Exception("FolderContentType must be Message, MsgFolderRoot, Drafts, Calendar or Task.");
            }

            string stringResponse = "";

            try
            {
                stringResponse = await SendGetRequestAsync(URL);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            var jsonResponse = (JObject)JsonConvert.DeserializeObject(stringResponse);

            Dictionary <string, string> result = new Dictionary <string, string>();

            foreach (var item in jsonResponse)
            {
                result.Add(item.Key, item.Value.Value <string>());
            }

            return(result);
        }
Example #13
0
        /// <summary>
        /// Append a label denoting browser-side code, node, or both depending on the content type
        ///
        /// </summary>
        /// <param name="folderName"></param>
        /// <param name="contentType"></param>
        /// <returns></returns>
        public static string AppendLabel(string folderName, FolderContentType contentType)
        {
            switch (contentType)
            {
            case FolderContentType.Browser:
                folderName += " (browser)";
                break;

            case FolderContentType.Node:
                folderName += " (node)";
                break;

            case FolderContentType.Mixed:
                folderName += " (node, browser)";
                break;
            }
            return(folderName);
        }
        public async Task <string> GetAttachmentRawContentAsync(FolderContentType folderContentType, string itemId, string attachmentId)
        {
            // Get the raw contents of the specified attachment.

            if (!Util.UseMicrosoftGraphInMailboxViewer)
            {
                throw new NotImplementedException();
            }

            Uri URL;

            switch (folderContentType)
            {
            case FolderContentType.Message:
            case FolderContentType.MsgFolderRoot:
            case FolderContentType.Drafts:
                URL = new Uri("https://graph.microsoft.com/v1.0/me/messages/" + itemId + "/attachments/" + attachmentId + "/$value");
                break;

            case FolderContentType.Calendar:
                URL = new Uri("https://graph.microsoft.com/v1.0/me/events/" + itemId + "/attachments/" + attachmentId + "/$value");
                break;

            case FolderContentType.Task:
                URL = new Uri("https://graph.microsoft.com/beta/me/outlook/tasks/" + itemId + "/attachments/" + attachmentId + "/$value");
                break;

            default:
                throw new Exception("FolderContentType must be Message, MsgFolderRoot, Drafts, Calendar or Task.");
            }

            string stringResponse = "";

            try
            {
                stringResponse = await SendGetRequestAsync(URL);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(stringResponse);
        }
        /// <summary>
        /// Recursively lists the items in a folder that have a certain suffix (wildcards are not supported).
        /// without having to return them all at once via an array.
        /// This is useful if there are a very large number of files in a folder.
        /// </summary>
        /// <param name="folderName">The name of a folder.</param>
        /// <param name="fileSuffix">
        /// A file suffix to match, or "" or null to match all files.
        /// This is used only for files; if folders are being returned, all folders are returned regardless of their suffixes.
        /// </param>
        /// <param name="contentType">Type of the content to be returned.</param>
        /// <returns>An enumerator for all the items.</returns>

        public static IEnumerable <FolderItem> RecursiveFolderContents
        (
            string folderName,
            string fileSuffix,
            FolderContentType contentType
        )
        {
            if (string.IsNullOrEmpty(folderName))
            {
                throw new ArgumentNullException("folderName");
            }

            if (!string.IsNullOrEmpty(fileSuffix))
            {
                if (fileSuffix[0] != '.')
                {
                    fileSuffix = "." + fileSuffix;
                }
            }

            return(recursiveFolderContents(folderName, fileSuffix, contentType));
        }
 public void CreateOrUpdate(object obj, string name, string path, FolderContentType type)
 {
     WriteJson(obj, CreateJsonPath(name, path, type));
 }
 private bool IsFolderContentExist(string name, string path, FolderContentType type)
 {
     return(FileManager.Exists(CreateJsonPath(name, path, type)));
 }
        /// <summary>
        /// Lists the items in a folder that match a specification, without having to return them all at once via an array.
        /// This is useful if there are a very large number of files in a folder.
        /// </summary>
        /// <param name="folderName">The name of a folder.</param>
        /// <param name="itemSpec">
        /// An item spec which may contain wildcards or which can be "", null, "*" or "*.*" for all items.
        /// </param>
        /// <param name="contentType">Type of the content to be returned.</param>
        /// <returns>An enumerator for all the items.</returns>

        public static IEnumerable <FolderItem> FolderContents(string folderName, string itemSpec, FolderContentType contentType)
        {
            if (string.IsNullOrEmpty(folderName))
            {
                throw new ArgumentNullException("folderName");
            }

            if (!Directory.Exists(folderName))
            {
                //throw new DirectoryNotFoundException("Directory not found: " + folderName);
            }

            string spec;

            if (string.IsNullOrEmpty(itemSpec))
            {
                spec = Path.Combine(folderName, "*");
            }
            else
            {
                spec = Path.Combine(folderName, itemSpec);
            }

            WIN32_FIND_DATA findData;

            using (SafeFindHandle findHandle = FindFirstFile(spec, out findData))
            {
                if (!findHandle.IsInvalid)
                {
                    do
                    {
                        if ((findData.cFileName != ".") && (findData.cFileName != ".."))  // Ignore special "." and ".." folders.
                        {
                            switch (contentType)
                            {
                            case FolderContentType.FilesAndFolders:
                            {
                                if ((findData.dwFileAttributes & FileAttributes.Directory) == 0)
                                {
                                    filecnt++;
                                }
                                else
                                {
                                    dircnt++;
                                }
                                yield return(new FolderItem(findData, folderName));

                                break;
                            }

                            case FolderContentType.FilesOnly:
                            {
                                if ((findData.dwFileAttributes & FileAttributes.Directory) == 0)
                                {
                                    filecnt++;
                                    yield return(new FolderItem(findData, folderName));
                                }

                                break;
                            }

                            case FolderContentType.FoldersOnly:
                            {
                                if ((findData.dwFileAttributes & FileAttributes.Directory) != 0)
                                {
                                    dircnt++;
                                    yield return(new FolderItem(findData, folderName));
                                }

                                break;
                            }

                            default:
                            {
                                throw new ArgumentOutOfRangeException("contentType", contentType, "contentType is not one of the allowed values.");
                            }
                            }
                        }
                    }while (FindNextFile(findHandle, out findData));
                }
                else
                {
                    Debug.WriteLine("Cannot find files in " + spec, "Dmr.Common.IO.FileSystem.FolderContents()");
                }
            }
        }