コード例 #1
0
 private void MacroNode_StateChanged(object sender, EventArgs e)
 {
     State = ChildNodes
             .Where(childNode => childNode.CheckState != CheckState.Unchecked)
             .Aggregate(MacroActionState.Unknown, (actionState, childNode) =>
                        childNode.State > actionState ? childNode.State : actionState);
 }
コード例 #2
0
        /// <summary>
        /// Prepare multiple offline files to share with other app.
        /// </summary>
        /// <returns>Boolean value indicating if all went well or not.</returns>
        public async Task <bool> MultipleShare()
        {
            int count = ChildNodes.Count(n => n.IsMultiSelected);

            if (count < 1)
            {
                return(false);
            }

            List <StorageFile> storageItems = new List <StorageFile>(count);

            foreach (var node in ChildNodes.Where(n => n.IsMultiSelected))
            {
                if (node == null || node.IsFolder)
                {
                    continue;
                }

                StorageFile selectedNode = await StorageFile.GetFileFromPathAsync(node.NodePath);

                storageItems.Add(selectedNode);
            }

            if (storageItems == null || storageItems.Count < 1)
            {
                return(false);
            }

            DialogService.ShowShareMediaTask(storageItems);

            this.IsMultiSelectActive = false;

            return(true);
        }
コード例 #3
0
ファイル: TagNode.cs プロジェクト: zoujiaqing/BBCodeParser
        internal override string ToHtml(
            Dictionary <string, string> securitySubstitutions,
            Dictionary <string, string> aliasSubstitutions,
            Func <Node, bool> filter = null,
            Func <Node, string, string> filterAttributeValue = null)
        {
            var attributeValue = filterAttributeValue == null
                ? AttributeValue
                : filterAttributeValue(this, AttributeValue);
            var result = new StringBuilder(Tag.GetOpenHtml(attributeValue), ChildNodes.Count + 2);

            foreach (var childNode in ChildNodes.Where(n => filter == null || filter(n)))
            {
                if (Tag is CodeTag)
                {
                    result.Append(childNode.ToBb(securitySubstitutions));
                }
                else if (Tag is PreformattedTag)
                {
                    result.Append(childNode.ToHtml(securitySubstitutions, null, filter));
                }
                else if (!(Tag is ListTag) || !(childNode is TextNode))
                {
                    result.Append(childNode.ToHtml(securitySubstitutions, aliasSubstitutions, filter));
                }
            }

            if (Tag.RequiresClosing)
            {
                result.Append(Tag.GetCloseHtml(attributeValue));
            }

            return(result.ToString());
        }
コード例 #4
0
ファイル: TagNode.cs プロジェクト: zoujiaqing/BBCodeParser
        internal override string ToText(
            Dictionary <string, string> securitySubstitutions,
            Dictionary <string, string> aliasSubstitutions,
            Func <Node, bool> filter = null,
            Func <Node, string, string> filterAttributeValue = null
            )
        {
            var result = new StringBuilder(ChildNodes.Count);

            foreach (var childNode in ChildNodes.Where(n => filter == null || filter(n)))
            {
                if (Tag is CodeTag)
                {
                    result.Append(childNode.ToBb(securitySubstitutions, filter, filterAttributeValue));
                }
                else if (Tag is PreformattedTag)
                {
                    result.Append(childNode.ToText(securitySubstitutions, null, filter, filterAttributeValue));
                }
                else
                {
                    result.Append(childNode.ToText(securitySubstitutions, aliasSubstitutions, filter,
                                                   filterAttributeValue));
                }
            }

            return(result.ToString());
        }
コード例 #5
0
        /// <summary>
        /// Prepare multiple offline files to share with other app.
        /// </summary>
        /// <returns>Boolean value indicating if all went well or not.</returns>
        public async Task <bool> MultipleShare()
        {
            try
            {
                int count = ChildNodes.Count(n => n.IsMultiSelected);
                if (count < 1)
                {
                    LogService.Log(MLogLevel.LOG_LEVEL_INFO, "No items selected for share.");
                    return(false);
                }

                List <StorageFile> storageItems = new List <StorageFile>(count);
                if (storageItems == null)
                {
                    throw new ArgumentNullException("storageItems", "Error creating the selected items list for share.");
                }

                foreach (var node in ChildNodes.Where(n => n.IsMultiSelected))
                {
                    if (node == null || node.IsFolder)
                    {
                        continue;
                    }

                    StorageFile selectedNode = await StorageFile.GetFileFromPathAsync(node.NodePath);

                    storageItems.Add(selectedNode);
                }

                if (storageItems.Count < 1)
                {
                    LogService.Log(MLogLevel.LOG_LEVEL_INFO, "No items selected for share.");
                    return(false);
                }

                DialogService.ShowShareMediaTask(storageItems);

                this.IsMultiSelectActive = false;

                return(true);
            }
            catch (Exception e)
            {
                LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Failed to share items from MEGA.", e);

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    new CustomMessageDialog(
                        AppMessages.AM_ShareFromMegaFailed_Title.ToUpper(),
                        AppMessages.AM_ShareFromMegaFailed_Message,
                        App.AppInformation,
                        MessageDialogButtons.Ok).ShowDialog();
                });

                return(false);
            }
        }
コード例 #6
0
        internal override string ToBb(
            Dictionary <string, string> securitySubstitutions,
            Func <Node, bool> filter = null,
            Func <Node, string, string> filterAttributeValue = null)
        {
            var result = new StringBuilder(ChildNodes.Count);

            foreach (var childNode in ChildNodes.Where(n => filter == null || filter(n)))
            {
                result.Append(childNode.ToBb(securitySubstitutions, filter, filterAttributeValue));
            }

            return(result.ToString());
        }
コード例 #7
0
        private void RemoveOrRubbish(int count)
        {
            var helperList = new List <IMegaNode>(count);

            helperList.AddRange(ChildNodes.Where(n => n.IsMultiSelected));

            Task.Run(async() =>
            {
                WaitHandle[] waitEventRequests = new WaitHandle[count];

                int index = 0;

                foreach (var node in helperList)
                {
                    waitEventRequests[index] = new AutoResetEvent(false);
                    await node.RemoveAsync(true, (AutoResetEvent)waitEventRequests[index]);
                    index++;
                }

                WaitHandle.WaitAll(waitEventRequests);

                Deployment.Current.Dispatcher.BeginInvoke(() => ProgressService.SetProgressIndicator(false));

                if (this.CurrentDisplayMode == DriveDisplayMode.RubbishBin)
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        new CustomMessageDialog(
                            AppMessages.MultiRemoveSucces_Title,
                            String.Format(AppMessages.MultiRemoveSucces, count),
                            App.AppInformation,
                            MessageDialogButtons.Ok).ShowDialog();
                    });
                }
                else
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        new CustomMessageDialog(
                            AppMessages.MultiMoveToRubbishBinSucces_Title,
                            String.Format(AppMessages.MultiMoveToRubbishBinSucces, count),
                            App.AppInformation,
                            MessageDialogButtons.Ok).ShowDialog();
                    });
                }
            });

            this.IsMultiSelectActive = false;
        }
コード例 #8
0
        public TreeContainer Add(string key)
        {
            var child = ChildNodes.Where(x => x.Key == key).FirstOrDefault();

            if (child != null)
            {
                return(child);
            }

            var newChild = new TreeContainer(key);

            ChildNodes.Add(newChild);

            return(newChild);
        }
コード例 #9
0
ファイル: XMLTree.cs プロジェクト: mstrperson/Xml
        public SimpleXmlTag this[string tag, string attribute, string value]
        {
            get
            {
                foreach (SimpleXmlTag xmlTag in ChildNodes.Where(node => node.TagName.Equals(tag)))
                {
                    if (xmlTag[attribute].Equals(value))
                    {
                        return(xmlTag);
                    }
                }

                return(null);
            }
        }
コード例 #10
0
        private void MultipleRemoveItems(int count)
        {
            var helperList = new List <IOfflineNode>(count);

            helperList.AddRange(ChildNodes.Where(n => n.IsMultiSelected));

            Task.Run(async() =>
            {
                WaitHandle[] waitEventRequests = new WaitHandle[count];

                int index = 0;

                foreach (var node in helperList)
                {
                    waitEventRequests[index] = new AutoResetEvent(false);
                    await node.RemoveAsync(true, (AutoResetEvent)waitEventRequests[index]);
                    index++;
                }

                WaitHandle.WaitAll(waitEventRequests);

                String parentNodePath = Path.GetDirectoryName(this.FolderRootNode.NodePath);

                String sfoRootPath = Path.Combine(ApplicationData.Current.LocalFolder.Path,
                                                  AppResources.DownloadsDirectory.Replace("\\", ""));

                // Check if the previous folders of the path are empty and
                // remove from the offline and the DB on this case
                while (String.Compare(parentNodePath, sfoRootPath) != 0)
                {
                    var folderPathToRemove = parentNodePath;
                    parentNodePath         = ((new DirectoryInfo(parentNodePath)).Parent).FullName;

                    if (FolderService.IsEmptyFolder(folderPathToRemove))
                    {
                        Deployment.Current.Dispatcher.BeginInvoke(() => GoFolderUp());
                        FolderService.DeleteFolder(folderPathToRemove);
                        SavedForOffline.DeleteNodeByLocalPath(folderPathToRemove);
                    }
                }

                Deployment.Current.Dispatcher.BeginInvoke(() => ProgressService.SetProgressIndicator(false));

                Refresh();
            });

            this.IsMultiSelectActive = false;
        }
コード例 #11
0
        public bool RemoveEntity(Entity entity)
        {
            if (HasChild && ChildNodes.Where(n => n.AABB.IsIntersectWithPoint(entity.Pos)).Any(n => n.RemoveEntity(entity)))
            {
                var entities = GetEntities().ToList();

                if (entities.Count <= MaxCount)
                {
                    Entities.AddRange(entities);
                    ChildNodes = new OctantNode[0];
                }

                return(true);
            }
            else
            {
                return(Entities.Remove(entity));
            }
        }
コード例 #12
0
        public override ISyntaxToken FindToken(SourceLocation position, bool descendIntoTrivia = false)
        {
            if (FullSourceRange.End == position)
            {
                var compilationUnit = this as CompilationUnitSyntax;
                if (compilationUnit != null)
                {
                    return(compilationUnit.EndOfFileToken);
                }
            }

            if (!FullSourceRange.Contains(position))
            {
                throw new ArgumentOutOfRangeException(nameof(position));
            }

            var children = ChildNodes.Where(nodeOrToken => nodeOrToken.FullSourceRange.Contains(position));

            Debug.Assert(children.Any());

            var child = children.First();

            if (!child.IsToken)
            {
                return(((SyntaxNode)child).FindToken(position, descendIntoTrivia));
            }

            var token = (SyntaxToken)child;

            if (descendIntoTrivia)
            {
                var triviaStructure = token.LeadingTrivia.Concat(token.TrailingTrivia)
                                      .FirstOrDefault(t => t is StructuredTriviaSyntax && t.FullSourceRange.Contains(position));

                if (triviaStructure != null)
                {
                    return(triviaStructure.FindToken(position, true));
                }
            }

            return(token);
        }
コード例 #13
0
        public TreeNode FindNode(object obj)
        {
            if (Feature == null)
            {
                return(this);
            }
            var featureValue = (Feature.Selector as LambdaExpression).Compile().DynamicInvoke(obj);

            if (Feature.Type == FeatureType.Discrete)
            {
                return(ChildNodes.Where(x => (x.Key as DiscreteFeatureValue).Value.Equals(featureValue))
                       .Select(x => x.Value.FindNode(obj))
                       .FirstOrDefault());
            }
            return(ChildNodes
                   .Where(x => (x.Key as ContiniousFeatureValue).From.CompareTo(featureValue as IComparable) <= 0)
                   .Where(x => (x.Key as ContiniousFeatureValue).To.CompareTo(featureValue as IComparable) > 0)
                   .Select(x => x.Value.FindNode(obj))
                   .FirstOrDefault());
        }
コード例 #14
0
        public bool SelectMultipleItemsForMove()
        {
            int count = ChildNodes.Count(n => n.IsMultiSelected);

            if (count < 1)
            {
                return(false);
            }

            SelectedNodes.Clear();

            foreach (var node in ChildNodes.Where(n => n.IsMultiSelected))
            {
                node.DisplayMode = NodeDisplayMode.SelectedForCopyOrMove;
                SelectedNodes.Add(node);
            }

            this.IsMultiSelectActive = false;
            this.PreviousDisplayMode = this.CurrentDisplayMode;
            this.CurrentDisplayMode  = DriveDisplayMode.CopyOrMoveItem;

            return(true);
        }
コード例 #15
0
ファイル: TagNode.cs プロジェクト: zoujiaqing/BBCodeParser
        internal override string ToBb(
            Dictionary <string, string> securitySubstitutions,
            Func <Node, bool> filter = null,
            Func <Node, string, string> filterAttributeValue = null)
        {
            var attributeValue = filterAttributeValue == null
                ? AttributeValue
                : filterAttributeValue(this, AttributeValue);
            var result = new StringBuilder(Tag.WithAttribute && !string.IsNullOrEmpty(attributeValue)
                    ? $@"[{Tag.Name}=""{attributeValue}""]"
                    : $@"[{Tag.Name}]", ChildNodes.Count + 2);

            foreach (var childNode in ChildNodes.Where(n => filter == null || filter(n)))
            {
                result.Append(childNode.ToBb(securitySubstitutions, filter, filterAttributeValue));
            }

            if (Tag.RequiresClosing)
            {
                result.Append($@"[/{Tag.Name}]");
            }

            return(result.ToString());
        }
コード例 #16
0
 /// <summary>Find sub elements with a predicate.</summary>
 /// <param name="predicate">The predicate to filter with.</param>
 /// <returns>A enumerable of elements.</returns>
 public virtual IEnumerable <TElement> Nodes(Func <TElement, bool> predicate)
 {
     return(ChildNodes.Where(predicate));
 }
コード例 #17
0
        public async void MultipleDownload(String downloadPath = null)
        {
            if (this.Type == ContainerType.FolderLink)
            {
                this.SelectedNodes = App.LinkInformation.SelectedNodes;
            }
            else
            {
                this.SelectedNodes = ChildNodes.Where(n => n.IsMultiSelected).ToList();
            }

            if (this.SelectedNodes.Count < 1)
            {
                return;
            }

            // Only 1 Folder Picker can be open at 1 time
            if (this.AppInformation.PickerOrAsyncDialogIsOpen)
            {
                return;
            }

            #if WINDOWS_PHONE_80
            if (!SettingsService.LoadSetting <bool>(SettingsResources.QuestionAskedDownloadOption, false))
            {
                var result = await DialogService.ShowOptionsDialog(AppMessages.QuestionAskedDownloadOption_Title,
                                                                   AppMessages.QuestionAskedDownloadOption,
                                                                   new[]
                {
                    new DialogButton(AppMessages.QuestionAskedDownloadOption_YesButton, () =>
                    {
                        SettingsService.SaveSetting(SettingsResources.ExportImagesToPhotoAlbum, true);
                    }),
                    new DialogButton(AppMessages.QuestionAskedDownloadOption_NoButton, () =>
                    {
                        SettingsService.SaveSetting(SettingsResources.ExportImagesToPhotoAlbum, false);
                    })
                });

                if (result == MessageDialogResult.CancelNo)
                {
                    return;
                }

                SettingsService.SaveSetting(SettingsResources.QuestionAskedDownloadOption, true);
            }
            #elif WINDOWS_PHONE_81
            if (downloadPath == null)
            {
                if (!await FolderService.SelectDownloadFolder())
                {
                    return;
                }
                else
                {
                    downloadPath = AppService.GetSelectedDownloadDirectoryPath();
                }
            }
            #endif

            ProgressService.SetProgressIndicator(true, ProgressMessages.PrepareDownloads);

            // Give the app the time to display the progress indicator
            await Task.Delay(5);

            // First count the number of downloads before proceeding to the transfers.
            int downloadCount = 0;
            foreach (var node in SelectedNodes)
            {
                var folderNode = node as FolderNodeViewModel;
                if (folderNode != null)
                {
                    downloadCount += NodeService.GetRecursiveNodes(this.MegaSdk, AppInformation, folderNode).Count;
                }
                else
                {
                    downloadCount++;
                }
            }

            if (!await AppService.DownloadLimitCheck(downloadCount))
            {
                ProgressService.SetProgressIndicator(false);
                return;
            }

            foreach (var node in SelectedNodes)
            {
                node.Download(TransfersService.MegaTransfers, downloadPath);
            }

            ProgressService.SetProgressIndicator(false);

            this.IsMultiSelectActive = false;
        }
コード例 #18
0
 private IEnumerable <StatementGrammarNode> GetChildNodes(Func <StatementGrammarNode, bool> filter = null)
 {
     return(Type == NodeType.Terminal
                         ? EmptyArray
                         : ChildNodes.Where(n => filter == null || filter(n)).SelectMany(n => Enumerable.Repeat(n, 1).Concat(n.GetChildNodes(filter))));
 }
コード例 #19
0
 //------------------------------------------------------------------------------
 /// <summary>
 /// List of Leaf Nodes
 /// </summary>
 //------------------------------------------------------------------------------
 public List <T> GetLeafNodes()
 {
     return(ChildNodes.Where(x => x.IsLeaf).ToList());
 }
コード例 #20
0
 public IEnumerable <(Entity e, float)> TimeToCollide(Vector3 pos, Vector3 velocity, float range = 0)
 {
     return(ChildNodes.Where(n => n.AABB.IsIntersectWithRay(pos, velocity)).SelectMany(n => n.TimeToCollide(pos, velocity, range))
            .Concat(Entities.Select(e => (e, new Sphere(e.Pos, range).CalculateTimeToIntersectWithRay(pos, velocity)))));
 }
コード例 #21
0
 /// <summary>Find sub elements with a given name.</summary>
 /// <param name="name">The name to search for.</param>
 /// <returns>A enumerable of elements.</returns>
 public virtual IEnumerable <TElement> Nodes(string name)
 {
     return(ChildNodes.Where(n => n.Name == name));
 }