Пример #1
0
        internal List<Hashtable> GetData(Context context, Expression where, ListSelect fieldNames)
        {
            List<Hashtable> list = new List<Hashtable>();

            foreach (FBPost item in GetData())
            {
                if (item.Filter(context, where))
                {
                    Hashtable ht = new Hashtable();
                    foreach (Select field in fieldNames)
                        ht[field.Alias] = field.Field.Calculate(context);
                    list.Add(ht);
                }
            }

            return list;
        }
Пример #2
0
 public CinarDataReader(List<Hashtable> list, ListSelect fieldNames, List<Type> fieldTypes)
 {
     this.currentIndex = -1;
     this.list = list;
     this.fieldNames = fieldNames;
     this.fieldTypes = fieldTypes;
 }
Пример #3
0
        internal List<Hashtable> GetData(Context context, Expression where, ListSelect fieldNames)
        {
            List<Hashtable> list = new List<Hashtable>();

            var client = new Pop3Client(userName, password, server);
            client.OpenInbox();
            while (client.NextEmail())
            {
                POP3Item item = new POP3Item(client.ReadAsMailMessage());
                if (item.Filter(context, where))
                {
                    Hashtable ht = new Hashtable();
                    foreach (Select field in fieldNames)
                        ht[field.Alias] = field.Field.Calculate(context);//context.Variables[fieldName];
                    list.Add(ht);
                }
            }
            client.CloseConnection();

            return list;
        }
Пример #4
0
        internal List<Hashtable> GetData(Context context, Expression where, ListSelect fieldNames)
        {
            List<SocialMediaItem> items = new List<SocialMediaItem>();

            if (source == "All" || source.IndexOf("Facebook", StringComparison.InvariantCultureIgnoreCase) > -1)
                foreach (FBPost item in new FacebookProvider(query).GetData())
                    items.Add(new SocialMediaItem(item));
            if (source == "All" || source.IndexOf("Twitter", StringComparison.InvariantCultureIgnoreCase) > -1)
                foreach (Tweet item in new TwitterProvider(query, lang, page).GetData())
                    items.Add(new SocialMediaItem(item));
            if (source == "All" || source.IndexOf("Youtube", StringComparison.InvariantCultureIgnoreCase) > -1)
                foreach (RSSItem item in new YoutubeProvider(query).GetData())
                    items.Add(new SocialMediaItem(item));
            if (source == "All" || source.IndexOf("FriendFeed", StringComparison.InvariantCultureIgnoreCase) > -1)
                foreach (FriendFeedItem item in new FriendFeedProvider(query, lang).GetData())
                    items.Add(new SocialMediaItem(item));
            if (source == "All" || source.IndexOf("DailyMotion", StringComparison.InvariantCultureIgnoreCase) > -1)
                foreach (DailyMotionItem item in new DailyMotionProvider(query, lang).GetData())
                    items.Add(new SocialMediaItem(item));

            List<Hashtable> list = new List<Hashtable>();

            foreach (SocialMediaItem item in items)
            {
                if (item.Filter(context, where))
                {
                    Hashtable ht = new Hashtable();
                    foreach (Select field in fieldNames)
                        ht[field.Alias] = field.Field.Calculate(context);
                    list.Add(ht);
                }
            }

            return list;
        }
Пример #5
0
        internal List<Hashtable> GetData(Context context, Expression where, ListSelect fieldNames)
        {
            List<Hashtable> list = new List<Hashtable>();

            foreach (CSVItem item in File.ReadAllText(path).Split('\n').Select(line => new CSVItem(line.Split(seperator))))
            {
                if (item.Filter(context, where))
                {
                    Hashtable ht = new Hashtable();
                    foreach (Select field in fieldNames)
                        ht[field.Alias] = field.Field.Calculate(context);//context.Variables[fieldName];
                    list.Add(ht);
                }
            }

            return list;
        }
Пример #6
0
        internal List<Hashtable> GetData(Context context, Expression where, ListSelect fieldNames)
        {
            List<Hashtable> list = getFileList(context, where, fieldNames, path);

            return list;
        }
Пример #7
0
 private List<Hashtable> getFileList(Context context, Expression where, ListSelect fieldNames, string dirPath)
 {
     List<Hashtable> list = new List<Hashtable>();
     DirectoryInfo di = new DirectoryInfo(dirPath);
     foreach (FileSystemInfo fi in di.GetDirectories())
     {
         FileItem item = new FileItem(fi);
         if (item.Filter(context, where))
         {
             Hashtable ht = new Hashtable();
             foreach (Select field in fieldNames)
                 ht[field.Alias] = field.Field.Calculate(context);//context.Variables[fieldName];
             list.Add(ht);
             if (recursive)
                 list.AddRange(getFileList(context, where, fieldNames, fi.FullName));
         }
     }
     foreach (FileSystemInfo fi in di.GetFiles())
     {
         FileItem item = new FileItem(fi);
         if (item.Filter(context, where))
         {
             Hashtable ht = new Hashtable();
             foreach (Select field in fieldNames)
                 ht[field.Alias] = field.Field.Calculate(context);//context.Variables[fieldName];
             list.Add(ht);
         }
     }
     return list;
 }
Пример #8
0
        internal List<Hashtable> GetData(Context context, Expression where, ListSelect fieldNames)
        {
            List<Hashtable> list = new List<Hashtable>();

            SyndicationFeed s = new SyndicationFeed();
            using (XmlTextReader reader = new XmlTextReader(url))
            {
                SyndicationFeed client = SyndicationFeed.Load(reader);

                foreach (SyndicationItem rItem in client.Items)
                {
                    RSSItem item = new RSSItem(rItem);
                    if (item.Filter(context, where))
                    {
                        Hashtable ht = new Hashtable();
                        foreach (Select field in fieldNames)
                            ht[field.Alias] = field.Field.Calculate(context);//context.Variables[fieldName];
                        list.Add(ht);
                    }
                }

                return list;
            }
        }
Пример #9
0
        internal List<Hashtable> GetData(Join join, Expression where, ListSelect fieldNames)
        {
            List<Hashtable> list = new List<Hashtable>();

            switch (join.TableName.ToLowerInvariant())
            {
                case "information_schema.tables":
                    {
                        list.Add(new Hashtable() { { "table_name", "Rss" }, { "table_type", "table" } });
                        list.Add(new Hashtable() { { "table_name", "Pop3" }, { "table_type", "table" } });
                        list.Add(new Hashtable() { { "table_name", "File" }, { "table_type", "table" } });
                        list.Add(new Hashtable() { { "table_name", "Facebook" }, { "table_type", "table" } });
                        list.Add(new Hashtable() { { "table_name", "Twitter" }, { "table_type", "table" } });
                        list.Add(new Hashtable() { { "table_name", "Youtube" }, { "table_type", "table" } });
                        list.Add(new Hashtable() { { "table_name", "SocialMedia" }, { "table_type", "table" } });
                        list.Add(new Hashtable() { { "table_name", "Yahoo" }, { "table_type", "table" } });
                        list.Add(new Hashtable() { { "table_name", "FriendFeed" }, { "table_type", "table" } });
                        list.Add(new Hashtable() { { "table_name", "DailyMotion" }, { "table_type", "table" } });
                        list.Add(new Hashtable() { { "table_name", "CSV" }, { "table_type", "table" } });
                        break;
                    }
                case "information_schema.columns":
                    {
                        list.AddRange(getColumnsOf(typeof(RSSItem), "Rss", where, fieldNames));
                        list.AddRange(getColumnsOf(typeof(POP3Item), "Pop3", where, fieldNames));
                        list.AddRange(getColumnsOf(typeof(FileItem), "File", where, fieldNames));
                        list.AddRange(getColumnsOf(typeof(FBPost), "Facebook", where, fieldNames));
                        list.AddRange(getColumnsOf(typeof(Tweet), "Twitter", where, fieldNames));
                        list.AddRange(getColumnsOf(typeof(RSSItem), "Youtube", where, fieldNames));
                        list.AddRange(getColumnsOf(typeof(SocialMediaItem), "SocialMedia", where, fieldNames));
                        list.AddRange(getColumnsOf(typeof(YahooResultItem), "Yahoo", where, fieldNames));
                        list.AddRange(getColumnsOf(typeof(FriendFeedItem), "FriendFeed", where, fieldNames));
                        list.AddRange(getColumnsOf(typeof(DailyMotionItem), "DailyMotion", where, fieldNames));
                        list.AddRange(getColumnsOf(typeof(CSVItem), "CSV", where, fieldNames));
                        break;
                    }
                case "file":
                    {
                        if (!join.CinarTableOptions.ContainsKey("Path") || !join.CinarTableOptions.ContainsKey("Recursive"))
                            throw new Exception("Provide file path. Exp: select .. from FILE(Path='c:\\...', Recursive=false)");
                        string path = Convert.ToString(join.CinarTableOptions["Path"].Calculate(this));
                        bool recursive = Convert.ToBoolean(join.CinarTableOptions["Recursive"].Calculate(this));
                        FileProvider fileProvider = new FileProvider(path, recursive);
                        list.AddRange(fileProvider.GetData(this, where, fieldNames));
                        break;
                    }
                case "pop3":
                    {
                        if (!join.CinarTableOptions.ContainsKey("Server") || !join.CinarTableOptions.ContainsKey("UserName") || !join.CinarTableOptions.ContainsKey("Password"))
                            throw new Exception("Provide mail settings. Exp: select .. from POP3(Server='', UserName='', Password='')");
                        string server = (string)join.CinarTableOptions["Server"].Calculate(this);
                        string userName = (string)join.CinarTableOptions["UserName"].Calculate(this);
                        string password = (string)join.CinarTableOptions["Password"].Calculate(this);
                        POP3Provider pop3Provider = new POP3Provider(server, userName, password);
                        list.AddRange(pop3Provider.GetData(this, where, fieldNames));
                        break;
                    }
                case "rss":
                    {
                        if (!join.CinarTableOptions.ContainsKey("Url"))
                            throw new Exception("Provide url. Exp: select .. from RSS(Url='http://...')");
                        string url = (string)join.CinarTableOptions["Url"].Calculate(this);
                        RSSProvider rssProvider = new RSSProvider(url);
                        list.AddRange(rssProvider.GetData(this, where, fieldNames));
                        break;
                    }
                case "facebook":
                    {
                        if (!join.CinarTableOptions.ContainsKey("Query"))
                            throw new Exception("Provide query. Exp: select .. from Facebook(Query='...')");
                        string query = (string)join.CinarTableOptions["Query"].Calculate(this);
                        FacebookProvider fbProvider = new FacebookProvider(query);
                        list.AddRange(fbProvider.GetData(this, where, fieldNames));
                        break;
                    }
                case "twitter":
                    {
                        string query2 = "", lang = "";
                        int page = 1;
                        if (join.CinarTableOptions.ContainsKey("Query"))
                        {
                            query2 = (string)join.CinarTableOptions["Query"].Calculate(this);
                            if (join.CinarTableOptions.ContainsKey("Lang"))
                                lang = (string)join.CinarTableOptions["Lang"].Calculate(this);
                            if (join.CinarTableOptions.ContainsKey("Page"))
                                page = Convert.ToInt32(join.CinarTableOptions["Page"].Calculate(this));
                            TwitterProvider twProvider = new TwitterProvider(query2, lang, page);
                            list.AddRange(twProvider.GetData(this, where, fieldNames));
                        }
                        else
                            throw new Exception("Provide query. Exp: select .. from Twitter(Query='...' [, Lang='tr'] [, Page=1])");
                        break;
                    }
                case "youtube":
                    {
                        if (!join.CinarTableOptions.ContainsKey("Query"))
                            throw new Exception("Provide query. Exp: select .. from Youtube(Query='...')");
                        string query = (string)join.CinarTableOptions["Query"].Calculate(this);
                        YoutubeProvider ytProvider = new YoutubeProvider(query);
                        list.AddRange(ytProvider.GetData(this, where, fieldNames));
                        break;
                    }
                case "socialmedia":
                    {
                        if (!join.CinarTableOptions.ContainsKey("Query"))
                            throw new Exception("Provide query. Exp: select .. from SocialMedia(Query='...' [, Lang='tr'] [, Source='Twitter,Facebook'] [, Page=1])");
                        string query = (string)join.CinarTableOptions["Query"].Calculate(this);
                        string lang = "";
                        if (join.CinarTableOptions.ContainsKey("Lang"))
                            lang = (string)join.CinarTableOptions["Lang"].Calculate(this);
                        string source = "All";
                        if (join.CinarTableOptions.ContainsKey("Source"))
                            source = (string)join.CinarTableOptions["Source"].Calculate(this);
                        int page = 1;
                        if (join.CinarTableOptions.ContainsKey("Page"))
                            page = Convert.ToInt32(join.CinarTableOptions["Page"].Calculate(this));
                        SocialMediaProvider provider = new SocialMediaProvider(query, lang, page, source);
                        list.AddRange(provider.GetData(this, where, fieldNames));
                        break;
                    }
                case "yahoo":
                    {
                        string query2 = "";
                        if (join.CinarTableOptions.ContainsKey("Query"))
                        {
                            query2 = (string)join.CinarTableOptions["Query"].Calculate(this);
                            YahooBossProvider twProvider = new YahooBossProvider(query2);
                            list.AddRange(twProvider.GetData(this, where, fieldNames));
                        }
                        else
                            throw new Exception("Provide query. Exp: select .. from Yahoo(Query='...')");
                        break;
                    }
                case "friendfeed":
                    {
                        string query2 = "";
                        if (join.CinarTableOptions.ContainsKey("Query"))
                        {
                            query2 = (string)join.CinarTableOptions["Query"].Calculate(this);
                            FriendFeedProvider twProvider = new FriendFeedProvider(query2, "");
                            list.AddRange(twProvider.GetData(this, where, fieldNames));
                        }
                        else
                            throw new Exception("Provide query. Exp: select .. from Yahoo(Query='...')");
                        break;
                    }
                case "dailymotion":
                    {
                        string query2 = "", lang = "";
                        if (join.CinarTableOptions.ContainsKey("Query"))
                        {
                            query2 = (string)join.CinarTableOptions["Query"].Calculate(this);
                            if (join.CinarTableOptions.ContainsKey("Lang"))
                                lang = (string)join.CinarTableOptions["Lang"].Calculate(this);
                            DailyMotionProvider twProvider = new DailyMotionProvider(query2, lang);
                            list.AddRange(twProvider.GetData(this, where, fieldNames));
                        }
                        else
                            throw new Exception("Provide query. Exp: select .. from Twitter(Query='...')");
                        break;
                    }
                case "csv":
                    {
                        if (!join.CinarTableOptions.ContainsKey("Path") || !join.CinarTableOptions.ContainsKey("Seperator"))
                            throw new Exception("Provide file path. Exp: select .. from CSV(Path='c:\\...', Seperator=';')");
                        string path = Convert.ToString(join.CinarTableOptions["Path"].Calculate(this));
                        char seperator = Convert.ToChar(join.CinarTableOptions["Seperator"].Calculate(this));
                        CSVProvider csvProvider = new CSVProvider(path, seperator);
                        list.AddRange(csvProvider.GetData(this, where, fieldNames));
                        break;
                    }
            }

            return list;
        }
Пример #10
0
        private void execute(Statement statement, Context context)
        {
            if (statement is SelectStatement)
            {
                // Join'den tabloları al
                // her bir kayıt için hashtable oluştur, context'e ekle, where expressionı üzerinde excute ettir. true ise listeye ekle.
                // falan filan uzun iş bu. niye yapıyorum ki ben bunu?

                SelectStatement ss = statement as SelectStatement;
                Expression filter = null;
                if (ss.From[0].On == null && ss.Where == null) filter = null;
                else if (ss.From[0].On != null && ss.Where != null) filter = new AndExpression(ss.From[0].On, ss.Where);
                else if (ss.From[0].On != null) filter = ss.From[0].On;
                else filter = ss.Where;

                this.FieldNames = ss.Select;
                this.ResultSet = context.GetData(ss.From[0], filter, ss.Select);
                this.FieldTypes = new List<Type>();
                if (this.ResultSet.Count > 0)
                {
                    foreach (Select key in ss.Select)
                        if (this.ResultSet[0][key.Alias] != null)
                            this.FieldTypes.Add(this.ResultSet[0][key.Alias].GetType());
                        else
                            this.FieldTypes.Add(typeof(string));
                }
                if (ss.OrderBy.Count > 0)
                {
                    IOrderedEnumerable<Hashtable> orderedList = this.ResultSet.OrderBy(ht=>1);
                    for (int i = 0; i < ss.OrderBy.Count; i++)
                    {
                        object orderBy = null;
                        if (ss.OrderBy[i].By is IntegerConstant)
                            orderBy = ((IntegerConstant)ss.OrderBy[i].By).Value;
                        else
                            orderBy = ((DbObjectName)ss.OrderBy[i].By).Name;

                        if (orderBy.GetType() == typeof(int))
                        {
                            int fieldNo = (int)orderBy - 1;
                            if (!(fieldNo < 0 || fieldNo >= FieldNames.Count))
                            {
                                if (ss.OrderBy[i].Desc)
                                    orderedList = orderedList.ThenByDescending(ht => ht[FieldNames[(int)fieldNo].Alias]);
                                else
                                    orderedList = orderedList.ThenBy(ht => ht[FieldNames[(int)fieldNo].Alias]);
                            }
                        }
                        else
                        {
                            string alias = orderBy.ToString();
                            if (FieldNames.IndexOf(alias) > -1)
                            {
                                if (ss.OrderBy[i].Desc)
                                    orderedList = orderedList.ThenByDescending(ht => ht[alias]);
                                else
                                    orderedList = orderedList.ThenBy(ht => ht[alias]);
                            }
                        }
                    }
                    this.ResultSet = orderedList.ToList();
                }

                if (ss.Limit != null)
                {
                    int offset = ss.Offset == null ? 0 : Convert.ToInt32(ss.Offset.Calculate(context));
                    int limit = Convert.ToInt32(ss.Limit.Calculate(context));
                    this.ResultSet = this.ResultSet.Skip(offset).Take(limit).ToList();
                }
            }
        }
Пример #11
0
        private List<Hashtable> getColumnsOf(Type type, string tableName, Expression where, ListSelect fieldNames)
        {
            List<Hashtable> list = new List<Hashtable>();
            foreach (PropertyInfo pi in type.GetProperties())
            {
                if (pi.PropertyType == typeof(string) || pi.PropertyType.IsValueType || pi.PropertyType==typeof(byte[]))
                {
                    if (pi.PropertyType.IsEnum) continue;

                    Variables["COLUMN_DEFAULT"] = "";
                    Variables["DATA_TYPE"] = pi.PropertyType.Name;
                    Variables["COLUMN_TYPE"] = pi.PropertyType.Name;
                    Variables["CHARACTER_MAXIMUM_LENGTH"] = 65532;
                    Variables["IS_NULLABLE"] = false;
                    Variables["COLUMN_NAME"] = pi.Name;
                    Variables["IS_AUTO_INCREMENT"] = false;
                    Variables["TABLE_NAME"] = tableName;

                    if (where==null || (bool)where.Calculate(this))
                    {
                        Hashtable ht = new Hashtable();
                        foreach (Select field in fieldNames)
                            ht[field.Alias] = field.Field.Calculate(this);//Variables[fieldName];
                        list.Add(ht);
                    }
                }
            }

            return list;
        }