Exemple #1
0
        private SocialMediaData CleanSocialMediaValue(SocialMediaData socialMediaData)
        {
            if (socialMediaData.Value.ToLower().Contains("facebook") && !socialMediaData.Value.ToLower().Contains("share"))
            {
                if (socialMediaData.Value.Contains(","))
                {
                    socialMediaData.Value = socialMediaData.Value.Split(',')[1];
                }
            }
            else
            {
                socialMediaData.Value = string.Empty;
            }

            if (socialMediaData.Value.Contains("|"))
            {
                socialMediaData.Value = socialMediaData.Value.Split('|')[1];
            }

            return(socialMediaData);
        }
Exemple #2
0
        public void Facebook_ParseSocialMedia_Output()
        {
            Dictionary <string, SocialMediaData> socialEntries = new Dictionary <string, SocialMediaData>();

            string line;
            string filePath = Path.Combine(Utility.ComponentBaseFolder + "\\Logs", "Crawl_SocialMedia.rpt");

            StreamReader file = new StreamReader(filePath);

            while ((line = file.ReadLine()) != null)
            {
                if (!line.StartsWith("-"))
                {
                    try
                    {
                        SocialMediaData smd = new SocialMediaData();
                        if (line.Length > 255)
                        {
                            smd.Value = line.Substring(0, 255).Trim();
                            if (line.Length > 277)
                            {
                                smd.DomainID = Convert.ToInt32(line.Substring(257, 15));
                                if (line.Length > 406)
                                {
                                    smd.DomainName = line.Substring(278, 128).Trim();
                                    smd.ShopperID  = Convert.ToInt32(line.Substring(407, line.Length - 407));
                                }
                            }
                        }

                        SocialMediaData cleaned = CleanSocialMediaValue(smd);
                        string          key     = cleaned.Value + cleaned.ShopperID.ToString();

                        if (!socialEntries.ContainsKey(key))
                        {
                            socialEntries.Add(key, cleaned);
                        }
                    }
                    catch (Exception e)
                    {
                        //skip line for now
                    }
                }
            }


            file.Close();


            string logFile = Path.Combine(Utility.ComponentBaseFolder + "\\Logs", "Crawl_SocialMedia.csv");

            try
            {
                using (System.IO.StreamWriter file2 = new System.IO.StreamWriter(logFile, true))
                {
                    foreach (SocialMediaData s in socialEntries.Values)
                    {
                        if (s.Value != string.Empty && s.DomainID != 0 && s.ShopperID != 0)
                        {
                            file2.WriteLine(s.ToCommaString());
                        }
                    }
                }
            }
            catch (Exception) { }
        }