コード例 #1
0
 //Method to add an object of type hashtag to the observable collection hashList
 public static void addHash(hashtag hashlist)
 {
     hashtagList.Add(hashlist);
 }
コード例 #2
0
        private denuncia ConvertDenunciaToDaoDenuncia(Denuncia denuncia)
        {
            denuncia daoDenuncia = new AppCode.denuncia();

            if (denuncia.id != null)
            {
                daoDenuncia.id = Convert.ToInt32(denuncia.id);
            }
            daoDenuncia.titulo    = denuncia.titulo;
            daoDenuncia.descricao = denuncia.descricao;
            daoDenuncia.situacao  = denuncia.situacao;
            try { daoDenuncia.data = Convert.ToDateTime(denuncia.data); }
            catch { }
            daoDenuncia.categoria_animal     = denuncia.categoria_animal;
            daoDenuncia.tipo_animal          = denuncia.tipo_animal;
            daoDenuncia.endereco             = denuncia.endereco;
            daoDenuncia.endereco_latitude    = denuncia.endereco_latitude;
            daoDenuncia.endereco_longitude   = denuncia.endereco_longitude;
            daoDenuncia.denunciante_email    = denuncia.denunciante_email;
            daoDenuncia.denunciante_telefone = denuncia.denunciante_telefone;
            daoDenuncia.id_dispositivo       = denuncia.id_dispositivo;

            if (denuncia.hashtag != null)
            {
                List <hashtag> hashtags = new List <hashtag>();
                foreach (Hashtag h in denuncia.hashtag)
                {
                    hashtag hash = new hashtag();
                    if (h.id != null)
                    {
                        hash.id = Convert.ToInt32(h.id);
                    }
                    hash.id_denuncia = h.id_denuncia;
                    hash.hashtag1    = h.hashtag;

                    hashtags.Add(hash);
                }
                daoDenuncia.hashtag = hashtags;
            }
            if (denuncia.midia != null)
            {
                List <midia> midias = new List <midia>();
                foreach (Midia m in denuncia.midia)
                {
                    midia midia = new midia();
                    if (m.id != null)
                    {
                        midia.id = Convert.ToInt32(m.id);
                    }
                    midia.id_denuncia = m.id_denuncia;
                    midia.sequencia   = m.sequencia;
                    midia.tipo_midia  = m.tipo_midia;
                    try { midia.arquivo = Convert.FromBase64String(m.arquivo); }
                    catch { }
                    midias.Add(midia);
                }
                daoDenuncia.midia = midias;
            }
            if (denuncia.retorno != null)
            {
                List <retorno> retornos = new List <retorno>();
                foreach (Retorno r in denuncia.retorno)
                {
                    retorno retorno = new retorno();
                    if (r.id != null)
                    {
                        retorno.id = Convert.ToInt32(r.id);
                    }
                    retorno.id_denuncia = r.id_denuncia;
                    try { retorno.data = Convert.ToDateTime(r.data); }
                    catch { }
                    retorno.descricao = r.descricao;
                    retorno.entidade  = r.entidade;
                    retornos.Add(retorno);
                }
                daoDenuncia.retorno = retornos;
            }

            return(daoDenuncia);
        }
コード例 #3
0
        private void tweetsubmit_Click(object sender, RoutedEventArgs e)
        {
            //Creates a new instance of the tweet class.
            Tweet tweet = new Tweet();

            tweet.messageHeader = ((MainWindow)Application.Current.MainWindow).tweetid.messageHeader;
            tweet.twitterId     = tweetsender.Text;
            tweet.messageText   = tweetmsg.Text;

            //creates a new instance of the methods class.
            Methods load = new Methods();
            //loads in all of the abreviations using the loadCsvFile method from within the methods class to the list abbreviations.
            List <string> abbreviations = load.loadCsvFile("textwords.csv");
            //Creates the string abrev which turns the list abbreviations to array and joins the abbreviations by comma.
            string abrev = string.Join(",", abbreviations.ToArray());
            //creates a new list of type string split which splits the string abrev by comma creating a list in which each instance is one abbreviation.
            List <string> split = abrev.Split(',').ToList();
            //creates a list input which contatins the sms message text split by null
            List <string> input = new List <string>(tweet.messageText.Split(null));
            //creates a new list contating all the values of the obesrvable collection hashList.
            List <hashtag> hashlist = Methods.hashtagList.ToList <hashtag>();
            hashtag        hash_tag = new hashtag();
            mentions       mention  = new mentions();
            int            counter1 = input.Count;
            int            counter2 = split.Count;

            tweetlstbox.Items.Clear();
            Methods.trendingList.Clear();

            if (tweet.twitterId.Length > 16)

            {
                MessageBox.Show("Invalid Twitter id please enter an id thats 16 characters or less, Invalid");
            }
            for (int i = 0; i < tweet.messageText.Length; i++)
            {
                if (counter1 == i)
                {
                    break;
                }
                for (int j = 0; j < split.Count; j++)
                {
                    if (counter2 == j)
                    {
                        break;
                    }
                    //checks to see if the current word is an abbreviation that needs to be expanded and if it is it expands it in the required format.
                    if (split[j].Equals(input[i]))
                    {
                        string original = input[i];
                        string word     = split[j + 1];
                        word     = "<" + word + ">";
                        input[i] = original + word;
                        j        = -1;
                        j++;
                    }
                }

                //checks to see if the current word is a mention or a hastag by checking the first char in each word.
                if (input[i].ToCharArray()[0] == '@')
                {
                    mention.Mention = input[i];
                    Methods.mentionList.Add(mention);
                }

                if (input[i].ToCharArray()[0] == '#')
                {
                    hash_tag.hashTags = input[i];
                    hashlist.Add(hash_tag);
                }
            }


            List <string> strings = hashlist.Select(c => c.hashTags).ToList();
            //creates a new dictionary called trending of type string, int.
            Dictionary <string, int> trending = new Dictionary <string, int>();


            //this method calculates the trending list by checking if the trending list contains the hashtag, if not it will be added with the count of 1, if not it will add 1 to the count of the hashtag.
            foreach (string hashtag in strings)
            {
                if (!trending.ContainsKey(hashtag))
                {
                    trending.Add(hashtag, 1);
                }
                else
                {
                    int count = 0;
                    trending.TryGetValue(hashtag, out count);
                    trending.Remove(hashtag);
                    trending.Add(hashtag, count + 1);
                }
            }

            foreach (KeyValuePair <string, int> entry in trending)
            {
                tweetlstbox.Items.Add(entry.Key + "  " + entry.Value);
                //adds the current hashtags and there values to the list trendingList.
                Methods.trendingList.Add(entry.Key + "  " + entry.Value);
            }



            //creates a new instance of the tweet class.
            Tweet serealise = new Tweet();

            serealise.messageHeader = ((MainWindow)Application.Current.MainWindow).tweetid.messageHeader;
            serealise.twitterId     = tweetsender.Text;
            serealise.messageText   = string.Join(" ", input.ToArray());

            //appends the searlise object to the JSON file "output.json"
            using (StreamWriter writer = File.AppendText(@"output.json"))
            {
                JsonSerializer serializer = new JsonSerializer();
                serializer.Serialize(writer, serealise);
            }


            //adds the object hash_tag to the observable collection hashList using the addHash method.
            Methods.addHash(hash_tag);
        }