コード例 #1
0
        public Folder(string name, string path, ErrorState errorState)
        {
            Name       = name;
            Path       = path;
            ErrorState = errorState;

            Contents.Clear();
            System.IO.Directory.GetFiles(Path).ToList().ForEach(x => Contents.Add(System.IO.Path.GetFileName(x)));
            _watcher          = new FileSystemWatcher(Path);
            _watcher.Created += (sender, e) =>
            {
                App.Current.Dispatcher.Invoke(delegate
                {
                    Contents.Add(e.Name);
                });
            };

            _watcher.Deleted += (sender, e) =>
            {
                if (!Contents.Any(x => x == e.Name))
                {
                    return;
                }

                App.Current.Dispatcher.Invoke(delegate
                {
                    Contents.Remove(e.Name);
                });
            };
            _watcher.EnableRaisingEvents = true;
        }
コード例 #2
0
ファイル: HtmlTag.cs プロジェクト: JackHerring/HtmlBuilders
        /// <summary>
        ///   Renders and returns the HTML tag by using the specified render mode.
        /// </summary>
        /// <param name="tagRenderMode">
        ///   The render mode. If this parameter is not specified, the <see cref="TagRenderMode" /> that was specified with the
        ///   <see cref="Render" /> method will be used.
        ///   If the <see cref="Render" /> method was never called for this <see cref="HtmlTag" />, the
        ///   <see cref="TagRenderMode" /> will default to <see cref="TagRenderMode.Normal" />
        ///   <br /><strong>IMPORTANT: </strong> When using <see cref="TagRenderMode.StartTag" /> or
        ///   <see cref="TagRenderMode.EndTag" />,
        ///   the <see cref="Contents" /> of this <see cref="HtmlTag" /> will not be rendered.
        ///   This is because when you have more than 1 content element, it does not make sense to only render the start or end
        ///   tags. Since the API exposes the
        ///   <see cref="Contents" /> and <see cref="Children" /> separately, the responsibility is then with the developer to
        ///   render the HTML as he or she wishes.
        ///   However, when using <see cref="TagRenderMode.Normal" /> (or passing no parameters, since
        ///   <see cref="TagRenderMode.Normal" /> is the default value),
        ///   the <see cref="Contents" /> <strong> will</strong> be taken into account since there can't be any confusion as to
        ///   what the expected HTML output would be.
        ///   You can specify <see cref="TagRenderMode" /> for this <see cref="HtmlTag" /> (or any of its <see cref="Children" /> )
        ///   by using the <see cref="Render" /> method.
        /// </param>
        /// <returns>The rendered HTML tag by using the specified render mode</returns>
        /// <exception cref="InvalidOperationException">
        ///   When <see cref="TagRenderMode.SelfClosing" /> is used but the
        ///   <see cref="HtmlTag" /> is not empty. (The <see cref="Contents" /> are not empty)
        /// </exception>
        public IHtmlString ToHtml(TagRenderMode?tagRenderMode = null)
        {
            tagRenderMode = tagRenderMode ?? _tagRenderMode ?? TagRenderMode.Normal;
            var stringBuilder = new StringBuilder();

            switch (tagRenderMode)
            {
            case TagRenderMode.StartTag:
                stringBuilder.Append(_tagBuilder.ToString(TagRenderMode.StartTag));
                break;

            case TagRenderMode.EndTag:
                stringBuilder.Append(_tagBuilder.ToString(TagRenderMode.EndTag));
                break;

            case TagRenderMode.SelfClosing:
                if (Contents.Any())
                {
                    throw new InvalidOperationException(
                              "Cannot render this tag with the self closing TagRenderMode because this tag has inner contents: " + this);
                }
                stringBuilder.Append(_tagBuilder.ToString(TagRenderMode.SelfClosing));
                break;

            default:
                stringBuilder.Append(_tagBuilder.ToString(TagRenderMode.StartTag));
                foreach (var content in Contents)
                {
                    stringBuilder.Append(content.ToHtml());
                }
                stringBuilder.Append(_tagBuilder.ToString(TagRenderMode.EndTag));
                break;
            }
            return(MvcHtmlString.Create(stringBuilder.ToString()));
        }
コード例 #3
0
ファイル: QMarker.cs プロジェクト: gbin-org/USFMToolsSharp
        public override bool TryInsert(Marker input)
        {
            if (input is VMarker && Contents.Any(m => m is VMarker))
            {
                return(false);
            }

            return(base.TryInsert(input));
        }
コード例 #4
0
ファイル: Barrier.cs プロジェクト: cschladetsch/FPV-GR
        /// <inheritdoc />
        public override void Post()
        {
            base.Post();

            if (Contents.Any(t => t.Active))
            {
                return;
            }

            if (Additions.Count == 0)
            {
                Complete();
            }
        }
コード例 #5
0
        private void OnShowContents()
        {
            IsContentVisible = !IsContentVisible;

            if (Contents.Any())
            {
                return;
            }

            var dir = Path.Combine(Directory.GetCurrentDirectory(), "downloads");

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            try
            {
                var filePath = Path.Combine(dir, Asset.Name);

                // download
                GitHubUtils.DownloadAssets(App.Settings, Asset.Url, filePath);

                // verify
                if (!File.Exists(filePath))
                {
                    StatusBarManager.StatusLabel.Text = "Could not retrieve contents of the Asset!";
                    return;
                }

                using (var zip = ZipFile.Open(filePath, ZipArchiveMode.Read))
                {
                    foreach (var asset in zip.Entries)
                    {
                        Contents.Add(new AssetViewModel(new AssetObject {
                            Name = asset.Name
                        })
                        {
                            IsContent = true
                        });
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
コード例 #6
0
ファイル: TagContent.cs プロジェクト: i-e-b/T.g
        /// <summary>
        /// Create a duplicate tag, recursively cloning any contents
        /// </summary>
        [NotNull] public TagContent Clone()
        {
            var dup = new TagContent {
                Properties = Properties,
                IsEmpty    = IsEmpty,
                Tag        = Tag,
                Text       = Text
            };

            if (Contents != null && Contents.Any())
            {
                dup.Contents = Contents.Select(c => c?.Clone()).ToList();
            }
            return(dup);
        }
コード例 #7
0
        public void LoadBook(int bookId, bool append = false)
        {
            var epubBook = bookModel.OpenBook(bookId);

            Contents    = Contents.AddRange(bookModel.GetChapters(epubBook));
            images      = images.AddRange(epubBook.Content.Images.ToDictionary(imageFile => imageFile.Key, imageFile => imageFile.Value.Content));
            styleSheets = styleSheets.AddRange(epubBook.Content.Css.ToDictionary(cssFile => cssFile.Key, cssFile => cssFile.Value.Content));
            fonts       = fonts.AddRange(epubBook.Content.Fonts.ToDictionary(fontFile => fontFile.Key, fontFile => fontFile.Value.Content));

            selectChapterCommand   = null;
            selectedChapter        = null;
            selectedChapterContent = null;
            if (Contents.Any())
            {
                SelectChapter(Contents.First());
            }
        }
コード例 #8
0
ファイル: HtmlTag.cs プロジェクト: fabiau/HtmlBuilders
        public void WriteTo(TextWriter writer, HtmlEncoder encoder)
        {
            var tagBuilder = new TagBuilder(_tagName)
            {
                TagRenderMode = _tagRenderMode ?? TagRenderMode.Normal
            };

            foreach (var attribute in _attributes)
            {
                tagBuilder.Attributes.Add(attribute);
            }
            switch (tagBuilder.TagRenderMode)
            {
            case TagRenderMode.StartTag:
                tagBuilder.RenderStartTag().WriteTo(writer, encoder);
                break;

            case TagRenderMode.EndTag:
                tagBuilder.RenderEndTag().WriteTo(writer, encoder);
                break;

            case TagRenderMode.SelfClosing:
                if (Contents.Any())
                {
                    throw new InvalidOperationException(
                              "Cannot render this tag with the self closing TagRenderMode because this tag has inner contents: " + this);
                }

                tagBuilder.RenderSelfClosingTag().WriteTo(writer, encoder);
                break;

            default:
                tagBuilder.RenderStartTag().WriteTo(writer, encoder);

                foreach (var content in Contents)
                {
                    content.WriteTo(writer, encoder);
                }

                tagBuilder.RenderEndTag().WriteTo(writer, encoder);
                break;
            }
        }
コード例 #9
0
ファイル: DynamicTableView.cs プロジェクト: tbm0115/Consoul
        /// <summary>
        /// Uses the dynamic property references to build the TableView
        /// </summary>
        public bool Build()
        {
            if (propertyReferences.Count <= 0)
            {
                Consoul.Write("Table Headers are not defined. Cannot build table without them.", ConsoleColor.Red);
                Consoul.Wait();
                return(false);
            }
            _table         = new TableView(RenderOptions);
            _table.Headers = propertyReferences.Keys.ToList();
            _table.QueryYieldsNoResults += _table_QueryYieldsNoResults;

            if (Contents?.Any() == true)
            {
                Contents.ForEach(o => Append(o));
            }

            return(true);
        }
コード例 #10
0
ファイル: Bottle.cs プロジェクト: essenbee/essenbee-bot
        public override bool Interact(string verb, IAdventurePlayer player)
        {
            verb = verb.ToLower();
            var interaction = Interactions.FirstOrDefault(c => c.IsMatch(verb) && c.ShouldExecute());

            if (interaction != null)
            {
                if (interaction.Verbs.Contains("fill"))
                {
                    if (!player.Inventory.GetItems().Any(x => x.ItemId.Equals(ItemId)))
                    {
                        var msg = new Display($"You are not carrying a bottle!");
                        msg.Do(player);
                        return(true);
                    }

                    if (!player.CurrentLocation.WaterPresent)
                    {
                        var msg = new Display("There is no water here!");
                        msg.Do(player);
                        return(true);
                    }

                    if (Contents.Any(c => c.ItemId.Equals(Item.PintOfWater)))
                    {
                        var msg = new Display("The bottle is already full!");
                        msg.Do(player);
                        return(true);
                    }
                }

                foreach (var action in interaction.RegisteredInteractions)
                {
                    action.Do(player, this);
                }

                return(true);
            }

            return(false);
        }
コード例 #11
0
        public void AddContent(string contentId, string description, string variantTypeValueId)
        {
            if (Contents.Any(x => x.VariantValue.VariantTypeValueId == (VariantTypeValueId)variantTypeValueId))
            {
                return;
            }

            if (Contents.Any(x => x.ProductContentId == contentId))
            {
                return;
            }

            ApplyChange(
                new Events.V1.ContentAddedToProduct(ProductId.Id,
                                                    contentId,
                                                    description,
                                                    variantTypeValueId,
                                                    (int)Enums.ProductContentStatus.Draft,
                                                    (int)Enums.VariantType.Color)
                );
        }
コード例 #12
0
        public void Write(bool clearConsole = true)
        {
            RenderOptions.Normalize(Contents);

            if (clearConsole)
            {
                Console.Clear(); // Clear view
            }
            CurrentRow           = 0;
            HorizontalLineString = new string(RenderOptions.Lines.HorizontalCharacter, (int)RenderOptions.MaximumTableWidth);
            VerticalLineString   = RenderOptions.Lines.VerticalCharacter.ToString();

            Append(Headers);

            if (Contents?.Any() == true)
            {
                foreach (IEnumerable <string> row in Contents)
                {
                    Append(row);
                }
            }
        }
コード例 #13
0
ファイル: Rucksack.cs プロジェクト: Videogamers0/SDV-ItemBags
        public override bool TryRemoveInvalidItems(IList <Item> Target, int ActualTargetCapacity)
        {
            //  Remove items that the bag isn't capable of storing
            bool ChangesMade = base.TryRemoveInvalidItems(Target, ActualTargetCapacity);

            //  Remove items until it's contents are using no more than NumSlots # of slots
            int SlotsInUse = Contents.Sum(x => GetNumSlots(x.Stack));

            while (SlotsInUse > NumSlots && SlotsInUse > 0 && Contents.Any())
            {
                Object ToRemove = Contents.Last();

                //  Reduce the quantity of the item by just enough so that it takes up 1 less Slot
                int CurrentQty = ToRemove.Stack;
                int DesiredQty = CurrentQty % MaxStackSize == 0 ?
                                 CurrentQty - MaxStackSize :
                                 CurrentQty - CurrentQty % MaxStackSize;
                int DecreaseAmt = CurrentQty - DesiredQty;

                if (MoveFromBag(ToRemove, DecreaseAmt, out int MovedQty, false, Target, ActualTargetCapacity))
                {
                    ChangesMade = true;
                }
コード例 #14
0
        public int Prompt(string message = "", ConsoleColor?color = null, bool allowEmpty = false, bool clearConsole = true)
        {
            if (Contents?.Any() == false)
            {
                return(-1);
            }

            var prevRenderOptionChoice = RenderOptions.IncludeChoices;

            RenderOptions.IncludeChoices = true;

            int selection = -1;

            do
            {
                Write(clearConsole);
                if (!string.IsNullOrEmpty(message))
                {
                    Consoul.Write("HELP ME!", Console.BackgroundColor);
                    Consoul.Write(message, color ?? ConsoulLibrary.RenderOptions.PromptColor);
                }
                if (allowEmpty)
                {
                    Consoul.Write("Press Enter to continue", ConsoulLibrary.RenderOptions.SubnoteColor);
                }

                string input = Consoul.Read();
                if (string.IsNullOrEmpty(input) && allowEmpty)
                {
                    selection = Contents.Count + 1;
                    break;
                }
                if (input.Contains("="))
                {
                    Dictionary <int, List <int> > matches = new Dictionary <int, List <int> >();
                    string[] queries = input.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string queryInput in queries)
                    {
                        string[] queryParts = queryInput.Split('=');
                        if (queryParts.Length == 2)
                        {
                            int columnIndex = Headers.IndexOf(queryParts[0]);
                            if (columnIndex >= 0)
                            {
                                if (!matches.ContainsKey(columnIndex))
                                {
                                    matches.Add(columnIndex, new List <int>());
                                }
                                for (int i = 0; i < Contents.Count; i++)
                                {
                                    if (Contents[i][columnIndex] == queryParts[1])
                                    {
                                        matches[columnIndex].Add(i);
                                    }
                                }
                            }
                            else
                            {
                                raiseQueryYieldsNoResults($"Invalid Header reference! Could not find Header '{queryParts[0]}'.", input);
                            }
                        }
                        else
                        {
                            raiseQueryYieldsNoResults("Query-based selection not formatted correctly. Must be in {Header Name}={Value} format", input);
                        }
                    }

                    List <int> results = new List <int>();
                    for (int i = 0; i < Contents.Count; i++)
                    {
                        if (matches.All(o => o.Value.Contains(i)))
                        {
                            results.Add(i);
                        }
                    }

                    if (results.Count == 1)
                    {
                        selection = results.First() + 1; // selection is expected as one-based
                    }
                    else if (results.Count > 1)
                    {
                        raiseQueryYieldsNoResults("Invalid Query! Query yielded multiple results. Try a more refined search.", input);
                    }
                    else if (results.Count == 0)
                    {
                        raiseQueryYieldsNoResults("Invalid Query! Query yielded no results.", input);
                    }
                }
                else if (!int.TryParse(input, out selection) || selection <= 0 || selection > Contents.Count)
                {
                    Consoul.Write("Invalid selection!", ConsoleColor.Red);
                    Consoul.Wait();
                    selection = -1;
                }
            } while (selection < 0);

            if (selection > Contents.Count)
            {
                selection = 0;
            }

            RenderOptions.IncludeChoices = prevRenderOptionChoice;

            return(selection - 1);
        }
コード例 #15
0
ファイル: Cell.cs プロジェクト: Clarksj4/TurnThang
 /// <summary>
 /// Checks whether this cell is occupied by anything of
 /// the given type.
 /// </summary>
 public bool IsOccupied <T>()
 {
     return(Contents.Any(c => c is T && c != null));
 }
コード例 #16
0
ファイル: Cell.cs プロジェクト: Clarksj4/TurnThang
 /// <summary>
 /// Checks whether this cell is occupied by aything.
 /// </summary>
 public bool IsOccupied()
 {
     return(Contents.Any(c => c != null));
 }