示例#1
0
文件: IPC.cs 项目: eikoyoneki/haggle
        public int AddInterest(Haggle.Attribute a)
        {
            IntPtr nameAnsi  = Utility.StringToAnsiIntPtr(a.GetName());
            IntPtr valueAnsi = Utility.StringToAnsiIntPtr(a.GetValue());

            int ret = UnmanagedAddInterest(this.handle, nameAnsi, valueAnsi);

            Memory.LocalFree(nameAnsi);
            Memory.LocalFree(valueAnsi);
            return(ret);
        }
示例#2
0
        private void menuItem2_Click(object sender, EventArgs e)
        {
            if (interestListView.Focused)
            {
                // Remove interest attribute
                for (int i = 0; i < interestListView.SelectedIndices.Count; i++)
                {
                    int    index     = interestListView.SelectedIndices[i];
                    string attrvalue = interestListView.Items[index].Text;
                    Debug.WriteLine("remove : " + attrvalue + " at index " + index);

                    // Separate value and weight
                    string[] avw = attrvalue.Split(':');

                    Haggle.Attribute a = new Haggle.Attribute("Picture", avw[0]);

                    if (!delInterestList.Contains(a))
                    {
                        if (addInterestList.Contains(a))
                        {
                            addInterestList.Remove(a);
                        }
                        else
                        {
                            delInterestList.Add(a);
                        }
                        interestListView.Items.RemoveAt(index);
                        menuItem1.Text = "Done";
                    }
                }
            }
            else if (interestTextBox.Text.Length > 0)
            {
                ParseInterestTextBox();
            }
        }
示例#3
0
        private void ParseInterestTextBox()
        {
            // 1. Get the input text in texbox1 and add to interest.
            // 2. Update listview
            string[] strArray = interestTextBox.Text.Split(',');
            interestTextBox.Text = "";
            int num = 0;

            if (strArray.Length == 0)
            {
                return;
            }
            interestListView.BeginUpdate();

            foreach (string str in strArray)
            {
                bool   canAdd  = true;
                string trimstr = str.TrimEnd();

                if (trimstr.Length == 0)
                {
                    continue;
                }

                // Check that this attribute doesn't already exist:
                for (int i = 0; i < interestListView.Items.Count && canAdd; i++)
                {
                    string   attrvalue = interestListView.Items[i].Text;
                    string[] avw       = attrvalue.Split(':');

                    if (Equals(avw[0], trimstr))
                    {
                        canAdd = false;
                    }
                }

                if (canAdd)
                {
                    Haggle.Attribute a = new Haggle.Attribute("Picture", trimstr, 1);

                    if (!delInterestList.Contains(a))
                    {
                        // Add weight to string

                        trimstr += ":" + 1;
                        //trimstr += ":" + trackBarWeight.Value;

                        ListViewItem lvi = new ListViewItem(trimstr);
                        interestListView.Items.Add(lvi);
                        addInterestList.Add(a);
                        delInterestList.Remove(a);
                        num++;
                    }
                }
            }

            interestListView.EndUpdate();

            if (num > 0)
            {
                menuItem1.Text = "Done";
            }
        }
示例#4
0
        private void ParseInterestTextBox()
        {
            // 1. Get the input text in texbox1 and add to interest.
                        // 2. Update listview
                        string[] strArray = interestTextBox.Text.Split(',');
                        interestTextBox.Text = "";
                        int num = 0;

                        if (strArray.Length == 0)
                        {
                                return;
                        }
                        interestListView.BeginUpdate();

                        foreach (string str in strArray)
                        {
                                bool canAdd = true;
                                string trimstr = str.TrimEnd();

                                if (trimstr.Length == 0)
                                        continue;

                                // Check that this attribute doesn't already exist:
                                for (int i = 0; i < interestListView.Items.Count && canAdd; i++)
                                {
                                    string attrvalue = interestListView.Items[i].Text;
                                    string[] avw = attrvalue.Split(':');

                                    if (Equals(avw[0], trimstr))
                                        canAdd = false;
                                }

                                if (canAdd)
                                {
                                    Haggle.Attribute a = new Haggle.Attribute("Picture", trimstr, 1);

                                    if (!delInterestList.Contains(a))
                                    {
                                        // Add weight to string

                                        trimstr += ":" + 1;
                                        //trimstr += ":" + trackBarWeight.Value;

                                        ListViewItem lvi = new ListViewItem(trimstr);
                                        interestListView.Items.Add(lvi);
                                        addInterestList.Add(a);
                                        delInterestList.Remove(a);
                                        num++;
                                    }
                                }
                        }

                        interestListView.EndUpdate();

                        if (num > 0)
                                menuItem1.Text = "Done";
        }
示例#5
0
        private void menuItem2_Click(object sender, EventArgs e)
        {
            if (interestListView.Focused)
                        {
                                // Remove interest attribute
                                for (int i = 0; i < interestListView.SelectedIndices.Count; i++)
                                {
                                        int index = interestListView.SelectedIndices[i];
                                        string attrvalue = interestListView.Items[index].Text;
                                        Debug.WriteLine("remove : " + attrvalue + " at index " + index);

                                        // Separate value and weight
                                        string[] avw = attrvalue.Split(':');

                                        Haggle.Attribute a = new Haggle.Attribute("Picture", avw[0]);

                                        if (!delInterestList.Contains(a))
                                        {
                                            if (addInterestList.Contains(a))
                                            {
                                                addInterestList.Remove(a);
                                            }
                                            else
                                            {
                                                delInterestList.Add(a);
                                            }
                                            interestListView.Items.RemoveAt(index);
                                            menuItem1.Text = "Done";
                                        }
                                }
                        } else if (interestTextBox.Text.Length > 0)
                        {
                                ParseInterestTextBox();
                        }
        }