private void DoAdvancedSearch()
        {
            // This is our final searchcondition that we'll create the search folder from
            SearchCondition finalSearchCondition = null;

            // This is Prop1 + prop2 search condition... if the user didn't specify one of the properties,
            // we can just use the one property/value they specify...if they do, then we can do the and/or operation
            SearchCondition combinedPropSearchCondition = null;

            // Because we are doing the search on a background thread,
            // we can't access the UI controls from that thread.
            // Invoke from the main UI thread and get the values
            string prop1TextBox_Text   = string.Empty;
            string prop2TextBox_Text   = string.Empty;
            string prop1ComboBox_Value = string.Empty;
            string prop2ComboBox_Value = string.Empty;
            SearchConditionOperation prop1ConditionOperation = SearchConditionOperation.ValueContains;
            SearchConditionOperation prop2ConditionOperation = SearchConditionOperation.ValueContains;
            string prop1prop2OperationComboBox_Value         = string.Empty;
            string comboBoxDateCreated_Value = string.Empty;
            int    prop1prop2OperationComboBox_SelectedIndex = 0;
            bool   dateSelected          = false;
            List <ShellContainer> scopes = new List <ShellContainer>();

            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(
                                  delegate()
            {
                prop1TextBox_Text                         = prop1TextBox.Text;
                prop1TextBox_Text                         = prop1TextBox.Text;
                prop1ComboBox_Value                       = prop1ComboBox.SelectedItem.ToString();
                prop2ComboBox_Value                       = prop2ComboBox.SelectedItem.ToString();
                prop1ConditionOperation                   = GetConditionOperation(prop1OperationComboBox);
                prop2ConditionOperation                   = GetConditionOperation(prop2OperationComboBox);
                prop1prop2OperationComboBox_Value         = prop1prop2OperationComboBox.SelectedItem.ToString();
                prop1prop2OperationComboBox_SelectedIndex = prop1prop2OperationComboBox.SelectedIndex;
                comboBoxDateCreated_Value                 = comboBoxDateCreated.SelectedItem.ToString();
                dateSelected = (comboBoxDateCreated.SelectedItem != dateCreatedNone);

                foreach (StackPanel sp in locationsListBox.Items)
                {
                    if (sp.Tag is ShellContainer)
                    {
                        scopes.Add((ShellContainer)sp.Tag);
                    }
                }
            }));

            // If we have a valid first property/value, then create a search condition
            if (!string.IsNullOrEmpty(prop1TextBox_Text))
            {
                SearchCondition prop1Condition = SearchConditionFactory.CreateLeafCondition(
                    GetSearchProperty(prop1ComboBox_Value),
                    prop1TextBox_Text,
                    prop1ConditionOperation);

                // After creating the first condition, see if we need to create a second leaf condition
                if (prop1prop2OperationComboBox_SelectedIndex != 0 &&
                    !(string.IsNullOrEmpty(prop2TextBox_Text)))
                {
                    SearchCondition prop2Condition = SearchConditionFactory.CreateLeafCondition(
                        GetSearchProperty(prop2ComboBox_Value),
                        prop2TextBox_Text,
                        prop2ConditionOperation);

                    // Create our combined search condition AND or OR
                    if (prop1prop2OperationComboBox.SelectedIndex == 1)
                    {
                        combinedPropSearchCondition = SearchConditionFactory.CreateAndOrCondition(
                            SearchConditionType.And,
                            false, prop1Condition, prop2Condition);
                    }
                    else
                    {
                        combinedPropSearchCondition = SearchConditionFactory.CreateAndOrCondition(
                            SearchConditionType.Or,
                            false, prop1Condition, prop2Condition);
                    }
                }
                else
                {
                    combinedPropSearchCondition = prop1Condition;
                }
            }
            else
            {
                return; // no search text entered
            }
            // Get the date condition
            if (dateSelected)
            {
                SearchCondition dateCreatedCondition = SearchConditionFactory.CreateLeafCondition(
                    SystemProperties.System.DateCreated,
                    ParseDate(((ComboBoxItem)comboBoxDateCreated.SelectedItem).Tag.ToString(), DateTime.Now),
                    SearchConditionOperation.GreaterThan);

                // If we have a property based search condition, create an "AND" search condition from these 2
                if (combinedPropSearchCondition != null)
                {
                    finalSearchCondition = SearchConditionFactory.CreateAndOrCondition(SearchConditionType.And,
                                                                                       false, combinedPropSearchCondition, dateCreatedCondition);
                }
                else
                {
                    finalSearchCondition = dateCreatedCondition;
                }
            }
            else
            {
                finalSearchCondition = combinedPropSearchCondition;
            }


            ShellSearchFolder searchFolder = new ShellSearchFolder(finalSearchCondition, scopes.ToArray());

            //
            List <SearchItem> items = new List <SearchItem>();

            try
            {
                // Because we cannot pass ShellObject or IShellItem (native interface)
                // across multiple threads, creating a helper object and copying the data we need from the ShellObject
                foreach (ShellObject so in searchFolder)
                {
                    // For each of our ShellObject,
                    // create a SearchItem object
                    // We will bind these items to the ListView
                    SearchItem item = new SearchItem();
                    item.Name = so.Name;

                    // We must freeze the ImageSource before passing across threads
                    BitmapSource thumbnail = so.Thumbnail.MediumBitmapSource;
                    thumbnail.Freeze();
                    item.Thumbnail = thumbnail;

                    item.Authors     = so.Properties.System.Author.Value;
                    item.Title       = so.Properties.System.Title.Value;
                    item.Keywords    = so.Properties.System.Keywords.Value;
                    item.Copyright   = so.Properties.System.Copyright.Value;
                    item.TotalPages  = so.Properties.System.Document.PageCount.Value.HasValue ? so.Properties.System.Document.PageCount.Value.Value : 0;
                    item.Rating      = so.Properties.System.SimpleRating.Value.HasValue ? (int)so.Properties.System.SimpleRating.Value.Value : 0;
                    item.ParsingName = so.ParsingName;

                    items.Add(item);
                }

                // Invoke the search on the main thread

                Dispatcher.Invoke(
                    System.Windows.Threading.DispatcherPriority.Normal,
                    new Action(
                        delegate()
                {
                    MainWindow.UpdateSearchItems(items);
                }
                        ));
            }
            finally
            {
                // TODO - dispose other

                finalSearchCondition.Dispose();
                finalSearchCondition = null;

                searchFolder.Dispose();
                searchFolder = null;
            }
        }
Пример #2
0
        private void VideoImgSearch_Load(object sender, EventArgs e)
        {
            this.lstSearch.ThumbnailSize = new Size(130, 138);
            this.lstSearch.SetRenderer(new ImageListViewRenderers.XPRenderer());

            this.txtScore.Text    = _AlertScore.ToString();
            this.btnSearch.Click += delegate
            {
                if (m_searchCondition != null)
                {
                    m_searchCondition.Dispose();
                }

                Image searchImg = (Image)this.pictureBox1.Image.Clone();
                m_searchCondition = new SearchCondition("FaceTest", searchImg);

                this.lstSearch.SuspendLayout();
                this.lstSearch.Items.Clear();
                // Resume layout logic.
                this.lstSearch.ResumeLayout(true);

                int lret = SearchImage();
                if (lret == -1)
                {
                    MessageBox.Show("人脸图像搜索出现异常!", "提示");
                }
                else if (lret == -2)
                {
                    MessageBox.Show("人脸图像检测出现异常!", "提示");
                }
                else if (lret == -3)
                {
                    MessageBox.Show("人脸图像没有人脸!", "提示");
                }
                else if (lret == -4)
                {
                    MessageBox.Show("没有符合结果!", "提示");
                }
            };

            this.btnSelect.Click += delegate
            {
                string selFile = BaseCommon.SelectFile();
                if (string.IsNullOrEmpty(selFile))
                {
                    return;
                }

                if (this.pictureBox1.Image != null)
                {
                    this.pictureBox1.Image.Dispose();
                }

                Image img = Image.FromFile(selFile);
                this.pictureBox1.Image = img;
            };

            this.btnAddLibrary.Click += delegate
            {
                string number     = ConvertHelper.DateTimeToStamp().ToString();
                byte[] imgdisplay = ImageHelper.BitmapToByteArray(this.pictureBox1.Image);

                PersonManager frm = new PersonManager(imgdisplay, number);
                frm.ShowDialog();
            };
        }