コード例 #1
0
        void newtag_box_KeyDown(object sender, KeyEventArgs e)
        {
            String tb_text = ((TextBox)sender).Text;

            if (e.KeyCode == Keys.Return)
            {
                e.SuppressKeyPress = true; //to stop beep
                /////

                if (tb_text.Trim() == "")
                {
                    ((TextBox)sender).Text = newtagtb_defaulttext;
                    image.Focus();
                    return;
                }

                // calling data layer to add this tag

                //now checking that we don't have this tag already

                for (int i = 0; i < imageholder.tags.Count; i++)
                {
                    if (imageholder.tags[i].tag_string == tb_text) //this tag is already there, no need to add
                    {
                        MessageBox.Show("This tag is already added. Please change relevence");
                        //it would be nice if we ask user that whether instead he would like to increment relevence of tag
                        return;
                    }
                }


                //Debug.WriteLine("add a new tag");
                NOPSAImageTagHolder newtag = new NOPSAImageTagHolder();
                //NOTICE THE LINE BELOW
                // here we are setting tag's id to tag itself because server can automatically convert from tag-> tag_id and right now we don't know what id will server assign this.
                newtag.tag_id        = tb_text; //
                newtag.tag_relevence = "1";     //this is default set by server
                newtag.tag_string    = tb_text; //
                //we don't and can't know tag_id ... so there must a method on the server where we can incr/ dec relevence based of tag string rather than id
                imageholder.tags.Add(newtag);

                trash_tag_scrollbar();
                //loadimage();
                loadtags();

                //despatch new tag to server (using communication manager)
                this.cm.addtag(imageholder.img_id, tb_text);
            }
        }
コード例 #2
0
 //simple binary sort
 void sorttags()
 {
     for (int i = 0; i < this.imageholder.tags.Count; i++)
     {
         for (int j = i + 1; j < this.imageholder.tags.Count; j++)
         {
             if (Int32.Parse(this.imageholder.tags[i].tag_relevence) < Int32.Parse(this.imageholder.tags[j].tag_relevence))
             {
                 NOPSAImageTagHolder temp = this.imageholder.tags[i];
                 this.imageholder.tags[i] = this.imageholder.tags[j];
                 this.imageholder.tags[j] = temp;
             }
         }
     }
 }
コード例 #3
0
        private void parse()
        {
            if (this.xml.Contains("notice message"))
            {
                return;                                      //REMOVE NOTICE MESSAGE FROM API
            }
            else if (this.xml.Contains("<code>") && !this.xml.Contains("900"))
            {
                //Debug.WriteLine("XML code error: " + this.xml.ToString());
                return;
            }

            List <String> suggestions = new List <String>();
            String        source      = "";

            List <NOPSAImageHolder>    images   = new List <NOPSAImageHolder>();
            List <NOPSAImageTagHolder> img_tags = new List <NOPSAImageTagHolder>(); //dont forget to empty it after a 'round'

            //bool issearch = false;

            bool img_start = false;
            bool tag_start = false;

            String img_id        = "";
            String img_rights    = "";
            String img_holder    = "";
            String img_url       = "";
            String img_creator   = "";
            String img_height    = "";
            String img_width     = "";
            String img_prirority = "";

            String tag_id        = "";
            String tag_relevence = "";
            String tag_string    = "";

            //Debug.WriteLine(this.xml);
            using (XmlReader reader = XmlReader.Create(new StringReader(this.xml)))
            {
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:     // The node is an element.
                        //Debug.Write("<" + reader.Name);
                        //Debug.WriteLine(">");
                        if (reader.Name == "source")     // true for suggest
                        {
                            String recieved_name = reader["name"];
                            if (recieved_name != null && !recieved_name.Equals(""))
                            {
                                //Debug.WriteLine("suggest recieved name isnt null '" + recieved_name + "'");
                                source = recieved_name;
                            }
                            //Debug.WriteLine("its suggestion " + reader["name"]); // only true for suggesiton
                        }
                        else if (reader.Name == "search")     // true for search
                        {
                            String recieved_name = reader["source"];
                            if (recieved_name != null && !recieved_name.Equals(""))
                            {
                                //Debug.WriteLine("search recieved name isnt null " + recieved_name);
                                source = recieved_name;
                            }
                        }
                        else if (reader.Name == "suggestion")         // its suggestion element
                        {
                            String temp = reader.ReadString().Trim(); //suggestion text
                            //Debug.WriteLine("temp: " + temp);
                            suggestions.Add(temp);
                        }
                        else if (reader.Name == "image")     // its search->image element
                        {
                            //Debug.WriteLine("starting image");
                            img_start = true;            //so that other tags inside <image> can know that its their turn (not of someone with same name but outside <image>)
                        }
                        else if (reader.Name == "id")    // currently multile tags start with id
                        {
                            if (img_start && !tag_start) // it must be related to <image>
                            {
                                img_id = reader.ReadString().Trim();
                            }
                            if (img_start && tag_start)     // it must be related to <image>..<tag>HERE</tag></image>
                            {
                                tag_id = reader.ReadString().Trim();
                            }
                        }
                        else if (reader.Name == "rights")
                        {
                            if (img_start)
                            {
                                img_rights = reader.ReadString().Trim();
                            }
                        }
                        else if (reader.Name == "image_holder")
                        {
                            if (img_start)
                            {
                                img_holder = reader.ReadString().Trim();
                            }
                        }
                        else if (reader.Name == "url")
                        {
                            if (img_start)
                            {
                                img_url = reader.ReadString().Trim();
                            }
                        }
                        else if (reader.Name == "creator")
                        {
                            if (img_start)
                            {
                                img_creator = reader.ReadString().Trim();
                            }
                        }
                        else if (reader.Name == "height")
                        {
                            if (img_start)
                            {
                                img_height = reader.ReadString().Trim();
                            }
                        }
                        else if (reader.Name == "width")
                        {
                            if (img_start)
                            {
                                img_width = reader.ReadString().Trim();
                            }
                        }
                        else if (reader.Name == "prirority")
                        {
                            if (img_start)
                            {
                                img_prirority = reader.ReadString().Trim();
                            }
                        }
                        else if (reader.Name == "tag")
                        {
                            if (img_start)
                            {
                                tag_start = true;     // telling others that tag has started
                                //Debug.WriteLine("its tag");
                            }
                        }
                        else if (reader.Name == "relevancy")
                        {
                            if (img_start && tag_start)
                            {
                                tag_relevence = reader.ReadString().Trim();
                            }
                        }
                        else if (reader.Name == "string")
                        {
                            if (img_start && tag_start)
                            {
                                tag_string = reader.ReadString().Trim();
                            }
                        }
                        break;

                    case XmlNodeType.Text:     //Display the text in each element.
                        //Debug.WriteLine(reader.Value);
                        break;

                    case XmlNodeType.EndElement:     //Display the end of the element.
                        //Debug.Write("</" + reader.Name);
                        //Debug.WriteLine(">");
                        if (reader.Name == "image")     // its search->image element
                        {
                            //Debug.WriteLine("ending image");
                            img_start = false;
                            //now put image in container

                            /*
                             * Debug.WriteLine("img_id: " + img_id);
                             * Debug.WriteLine("img_rights: " + img_rights);
                             * Debug.WriteLine("img_holder: " + img_holder);
                             * Debug.WriteLine("img_url: " + img_url);
                             * Debug.WriteLine("img_creator: " + img_creator);
                             * Debug.WriteLine("img_height: " + img_height);
                             * Debug.WriteLine("img_width: " + img_width);
                             * Debug.WriteLine("img_prirority: " + img_prirority);
                             */
                            NOPSAImageHolder temp_img = new NOPSAImageHolder();
                            temp_img.img_source    = source;
                            temp_img.img_id        = img_id;
                            temp_img.img_rights    = img_rights;
                            temp_img.img_holder    = img_holder;
                            temp_img.img_url       = img_url;
                            temp_img.img_creator   = img_creator;
                            temp_img.img_height    = img_height;
                            temp_img.img_width     = img_width;
                            temp_img.img_prirority = img_prirority;

                            temp_img.tags = img_tags;
                            img_tags      = new List <NOPSAImageTagHolder>();

                            images.Add(temp_img);

                            Debug.WriteLine("this is cm, source: " + source + " , url: " + img_url);
                        }
                        else if (reader.Name == "tag")
                        {
                            if (img_start)
                            {
                                tag_start = false;
                                //Debug.WriteLine("its tag closing");

                                NOPSAImageTagHolder temp_tag_holder = new NOPSAImageTagHolder();
                                temp_tag_holder.tag_id        = tag_id;
                                temp_tag_holder.tag_relevence = tag_relevence;
                                temp_tag_holder.tag_string    = tag_string;

                                //Debug.WriteLine("id: "+tag_id);
                                //Debug.WriteLine("relevence: "+tag_relevence);
                                //Debug.WriteLine("string: " + tag_string);

                                img_tags.Add(temp_tag_holder);
                            }
                        }

                        break;
                    }
                }
            }

            //Debug.WriteLine("some data processed");
            if (suggestions.Count != 0) // so it means the returned xml was from a suggestions query
            {
                Suggest_Data.sources.Add(source);
                Suggest_Data.suggestions.Add(suggestions);

                suc.ActiveControl.Invoke((MethodInvoker) delegate
                {
                    // runs on UI thread
                    suc.update_suggestions();
                });
            }
            else if (images.Count != 0)
            {
                //Debug.WriteLine("images arnt zero");
                Search_Data.sources.Add(source);
                Search_Data.images.Add(images);

                //WE MAY RUN SOME SHUFFLING ALGO HERE
                if (suc.InvokeRequired)
                {
                    suc.ActiveControl.Invoke(new MethodInvoker(delegate
                    {
                        suc.update_images();
                    }));
                }
                else
                {
                    suc.update_images();
                }

                /*
                 * suc.ActiveControl.Invoke((MethodInvoker)delegate
                 * {
                 *  // runs on UI thread
                 *  suc.update_images();
                 * });
                 */
            }
            source = ""; //not required but helps in debugging
        }