Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of <see cref="ErrorSafeCommand"/>.
 /// </summary>
 /// <param name="source">The source command.</param>
 public ErrorSafeCommand(ICommand source)
 {
     _source = source;
     _scalar = new ErrorSafeScalar <Unit>(
         fun(() => _source.Execute(_parameter)),
         () => default(Unit)
         );
 }
Beispiel #2
0
        private async void button2_ClickAsync(object sender, EventArgs e)
        {
            string text = textBox2.Text;

            if (!new IsBlank(text).Value() && !new IsBlank(_location).Value())
            {
                IText pattern;
                if (text.Contains('.'))
                {
                    pattern = new Text(text);
                }
                else
                {
                    pattern =
                        new Text(
                            new LowerText(
                                new TrimmedText(text)
                                ).String() + '*'
                            );
                }
                var items =
                    new ErrorSafeScalar <string[]>(() =>
                                                   Directory.GetFileSystemEntries(
                                                       _location,
                                                       pattern.String(),
                                                       SearchOption.AllDirectories
                                                       ),
                                                   () => array <string>()
                                                   );
                label1.Text = "the search is being run...";
                var result = items.Value();
                label1.Text = string.Empty;
                if (!items.HasErrors())
                {
                    //populate list box
                    if (result.Any())
                    {
                        string[] source = array(items.Value().Distinct());
                        _results = source;
                        listView1.Items.Clear();

                        ImageList il = new ImageList();
                        foreach (var item in source)
                        {
                            il.Images.Add(
                                new Icon(
                                    Icon.ExtractAssociatedIcon(item),
                                    new Size(60, 60)
                                    )
                                );
                        }

                        listView1.LargeImageList = il;

                        for (int i = 0; i < source.Length; i++)
                        {
                            listView1.Items.Add(new ListViewItem()
                            {
                                ImageIndex = i,
                                Text       = Path.GetFileName(source[i])
                            });
                        }
                    }
                }
                else
                {
                    await Message(items.Errors().FirstOrDefault()?.Message, TimeSpan.FromSeconds(15)).ConfigureAwait(false);
                }
            }
        }