Ejemplo n.º 1
0
        public bool RemoveRSSItem(int rssid)
        {
            bool result = true;

            try
            {
                RSSDBDataContext data = new RSSDBDataContext();
                RSSItem          item = (from rssitem in data.RSSItems
                                         where rssitem.ID == rssid
                                         select rssitem).Single();

                if (item.Tab.UserID != GetCurrentUserID())
                {
                    return(false);
                }

                data.RSSItems.DeleteOnSubmit(item);
                data.SubmitChanges();
            }
            catch
            {
                result = false;
            }
            finally
            {
            }
            return(result);
        }
Ejemplo n.º 2
0
        // 0 - success
        // 1 - different owner
        // 2 - tab not exist
        // 3 - exception
        public int RemoveTab(int tabid)
        {
            int result = -1;

            try
            {
                RSSDBDataContext dt = new RSSDBDataContext();

                var tabsToDelete = dt.Tabs.Where(_tab => _tab.ID == tabid);
                if (tabsToDelete.Count <Tab>() == 0)
                {
                    result = 2;
                }
                else
                {
                    var tabToDelete = tabsToDelete.Single();
                    if (tabToDelete.UserID != GetCurrentUserID())
                    {
                        var shares = dt.Shares.Where(share => share.TabID == tabToDelete.ID && share.AccountID == GetCurrentUserID());
                        dt.Shares.DeleteAllOnSubmit(shares);
                        dt.SubmitChanges();
                        result = 0;
                    }
                    else
                    {
                        var shares = dt.Shares.Where(share => share.TabID == tabToDelete.ID);

                        dt.Shares.DeleteAllOnSubmit(shares);

                        dt.RSSItems.DeleteAllOnSubmit(tabToDelete.RSSItems);

                        dt.Tabs.DeleteOnSubmit(tabToDelete);
                        dt.SubmitChanges();
                        result = 0;
                    }
                }
            }
            catch
            {
                result = 3;
            }
            finally
            {
            }

            return(result);
        }
Ejemplo n.º 3
0
        // 0 - successful
        // 1 - existed
        // 2 - incorrect link
        // 3 - Different onwer
        // 4 - failed
        public int AddRSSItem(int tabid, string rsslink)
        {
            int result = 0;

            try
            {
                if (IsExist(rsslink, tabid))
                {
                    result = 1;
                    return(result);
                }

                string nameStr        = "";
                string descriptionStr = "";

                if (!IsValid(rsslink, ref nameStr, ref descriptionStr))
                {
                    result = 2;
                    return(result);
                }

                RSSDBDataContext data = new RSSDBDataContext();
                Tab tabToInsert       = (from tab in data.Tabs
                                         where tab.ID == tabid
                                         select tab).Single();

                if (tabToInsert.UserID != GetCurrentUserID())
                {
                    return(3);
                }

                RSSItem newRssItem = new RSSItem();
                newRssItem.Name        = nameStr;
                newRssItem.Description = descriptionStr;
                newRssItem.RSSLink     = rsslink;
                newRssItem.TabID       = tabid;
                newRssItem.PluginID    = null;

                tabToInsert.RSSItems.Add(newRssItem);

                data.SubmitChanges();
            }
            catch
            {
                result = 4;
            }
            finally
            {
            }
            return(result);
        }
        public int AddRSSItem(int tabid, string rsslink)
        {
            int result = 0;
            try
            {
                if (IsExist(rsslink, tabid))
                {
                    result = 1;
                    return result;
                }

                string nameStr = "";
                string descriptionStr = "";

                if (!IsValid(rsslink, ref nameStr, ref descriptionStr))
                {
                    result = 2;
                    return result;
                }

                RSSDBDataContext data = new RSSDBDataContext();
                Tab tabToInsert = (from tab in data.Tabs
                                   where tab.ID == tabid
                                   select tab).Single();

                if (tabToInsert.UserID != GetCurrentUserID())
                    return 3;

                RSSItem newRssItem = new RSSItem();
                newRssItem.Name = nameStr;
                newRssItem.Description = descriptionStr;
                newRssItem.RSSLink = rsslink;
                newRssItem.TabID = tabid;
                newRssItem.PluginID = null;

                tabToInsert.RSSItems.Add(newRssItem);

                data.SubmitChanges();
            }
            catch
            {
                result = 4;
            }
            finally
            {

            }
            return result;
        }
Ejemplo n.º 5
0
        // 0 - success
        // 1 - different owner
        // 2 - tab not exist
        // 3 - duplicate name
        // 4 - exception
        public int RenameTab(int tabid, string newName)
        {
            int result = -1;

            try
            {
                RSSDBDataContext dt = new RSSDBDataContext();

                var tabsToRename = dt.Tabs.Where(_tab => _tab.ID == tabid);
                if (tabsToRename.Count <Tab>() == 0)
                {
                    result = 2;
                }
                else
                {
                    var tabToRename = tabsToRename.Single();
                    if (tabToRename.UserID != GetCurrentUserID())
                    {
                        result = 1;
                    }
                    else
                    {
                        var sameName = dt.Tabs.Where(tab => tab.UserID == GetCurrentUserID() && tab.Name.CompareTo(newName) == 0);
                        if (sameName.Count <Tab>() != 0)
                        {
                            result = 3;
                        }
                        else
                        {
                            tabToRename.Name = newName;
                            dt.SubmitChanges();

                            result = 0;
                        }
                    }
                }
            }
            catch
            {
                result = 4;
            }
            finally
            {
            }

            return(result);
        }
Ejemplo n.º 6
0
        // 0 - success.
        // 1 - name exist
        // 2 - exception
        public int AddTab(string tabName)
        {
            int result = -1;

            try
            {
                RSSDBDataContext dt = new RSSDBDataContext();
                var tabs            = dt.Tabs.Where(tab => tab.Name.CompareTo(tabName) == 0 && tab.UserID == GetCurrentUserID());
                if (tabs.Count <Tab>() == 0)
                {
                    int UserID = GetCurrentUserID();

                    Tab newTab = new Tab()
                    {
                        Name   = tabName,
                        UserID = UserID,
                    };

                    dt.Tabs.InsertOnSubmit(newTab);
                    dt.SubmitChanges();

                    result = 0;
                }
                else
                {
                    result = 1;
                }
            }
            catch
            {
                result = 2;
            }
            finally
            {
            }

            return(result);
        }
Ejemplo n.º 7
0
        public bool Register(string username, string password)
        {
            if (!CheckValidUsername(username))
            {
                return(false);
            }
            bool result = false;

            try
            {
                RSSDBDataContext dt = new RSSDBDataContext();
                int    randomvalue  = RANDOM.Next(0, int.MaxValue);
                string md5pass      = ServiceUtility.CalculateMD5Hash(password + randomvalue.ToString());

                Account account = new Account()
                {
                    Username = username,
                    Password = md5pass,
                    Salt     = randomvalue,
                };

                dt.Accounts.InsertOnSubmit(account);
                dt.SubmitChanges();

                result = true;
            }
            catch
            {
                result = false;
            }
            finally
            {
            }

            return(result);
        }
Ejemplo n.º 8
0
        // 0 - successful
        // 1 - existed
        // 2 - tab not exist
        // 3 - Different onwer
        // 4 - plugin not exist
        // 5 - failed
        public int AddRSSItemWithPlugin(int tabid, int pluginID)
        {
            int result = 5;

            try
            {
                RSSDBDataContext data = new RSSDBDataContext();
                List <Tab>       tabs = (from tab in data.Tabs
                                         where tab.ID == tabid
                                         select tab).ToList();
                if (tabs.Count == 0)
                {
                    return(2);
                }

                Tab tabToAdd = tabs[0];
                if (tabToAdd.UserID != GetCurrentUserID())
                {
                    return(3);
                }

                List <RSSPlugin> plugins = (from plu in data.RSSPlugins
                                            where plu.ID == pluginID
                                            select plu).ToList();
                if (plugins.Count == 0)
                {
                    return(4);
                }

                RSSPlugin plugin = plugins[0];

                //Kiểm tra đã tồn tại plugin trong tab hay chưa
                for (int i = 0; i < tabToAdd.RSSItems.Count; i++)
                {
                    if (tabToAdd.RSSItems[i].PluginID == pluginID)
                    {
                        return(1);
                    }
                }
                //---------------------------------------------------------------------------

                string[] fileNames = Directory.GetFiles(Server.MapPath("~") + @"\bin", plugin.DLLName);
                foreach (string fileName in fileNames)
                {
                    Assembly asm   = Assembly.LoadFile(fileName);
                    Type[]   types = asm.GetTypes();
                    foreach (Type type in types)
                    {
                        if (type.GetInterface("IRSSPlugin") != null)
                        {
                            IRSSPlugin pluginObject = Activator.CreateInstance(type) as IRSSPlugin;

                            RSSItem newItem = new RSSItem();
                            newItem.Name        = pluginObject.GetRSSName();
                            newItem.Description = pluginObject.GetRSSDescription();
                            newItem.RSSLink     = pluginObject.GetRSSWebsiteLink();
                            newItem.TabID       = tabid;
                            newItem.PluginID    = plugin.ID;
                            data.RSSItems.InsertOnSubmit(newItem);
                            data.SubmitChanges();
                            result = 0;
                        }
                    }
                }
            }
            catch
            {
                result = 5;
            }
            finally
            {
            }
            return(result);
        }
Ejemplo n.º 9
0
        // 0 - success
        // 1 - different owner
        // 2 - tab not exist
        // 3 - username not exist
        // 4 - can't share yourselt
        // 5 - exception
        public int ShareTab(int tabid, string userName)
        {
            int result = -1;

            try
            {
                RSSDBDataContext dt = new RSSDBDataContext();

                var tabsToShare = dt.Tabs.Where(_tab => _tab.ID == tabid);

                if (tabsToShare.Count <Tab>() == 0)
                {
                    result = 2;
                }
                else
                {
                    var tabToShare = tabsToShare.Single();
                    if (tabToShare.UserID != GetCurrentUserID())
                    {
                        result = 1;
                    }
                    else
                    {
                        Share share = new Share();
                        share.TabID = tabToShare.ID;

                        var UsersToShare = dt.Accounts.Where(account => account.Username.CompareTo(userName) == 0);
                        if (UsersToShare.Count <Account>() == 0)
                        {
                            result = 3;
                        }
                        else
                        {
                            share.AccountID = UsersToShare.Single().ID;
                            if (share.AccountID == GetCurrentUserID())
                            {
                                result = 4;
                            }
                            else
                            {
                                var shares = dt.Shares.Where(_share => _share.TabID == tabid && (_share.AccountID == GetCurrentUserID() || _share.AccountID == share.AccountID));
                                if (shares.Count <Share>() == 0)
                                {
                                    dt.Shares.InsertOnSubmit(share);
                                    dt.SubmitChanges();
                                }

                                result = 0;
                            }
                        }
                    }
                }
            }
            catch
            {
                result = 3;
            }
            finally
            {
            }

            return(result);
        }
        public int ShareTab(int tabid, string userName)
        {
            int result = -1;

            try
            {
                RSSDBDataContext dt = new RSSDBDataContext();

                var tabsToShare = dt.Tabs.Where(_tab => _tab.ID == tabid);

                if (tabsToShare.Count<Tab>() == 0)
                    result = 2;
                else
                {
                    var tabToShare = tabsToShare.Single();
                    if (tabToShare.UserID != GetCurrentUserID())
                        result = 1;
                    else
                    {
                        Share share = new Share();
                        share.TabID = tabToShare.ID;

                        var UsersToShare = dt.Accounts.Where(account => account.Username.CompareTo(userName) == 0);
                        if (UsersToShare.Count<Account>() == 0)
                        {
                            result = 3;
                        }
                        else
                        {
                            share.AccountID = UsersToShare.Single().ID;
                            if (share.AccountID == GetCurrentUserID())
                                result = 4;
                            else
                            {
                                var shares = dt.Shares.Where(_share => _share.TabID == tabid && (_share.AccountID == GetCurrentUserID() || _share.AccountID == share.AccountID));
                                if (shares.Count<Share>() == 0)
                                {
                                    dt.Shares.InsertOnSubmit(share);
                                    dt.SubmitChanges();
                                }

                                result = 0;
                            }
                        }

                    }
                }

            }
            catch
            {
                result = 3;
            }
            finally
            {
            }

            return result;
        }
        public int RenameTab(int tabid, string newName)
        {
            int result = -1;

            try
            {
                RSSDBDataContext dt = new RSSDBDataContext();

                var tabsToRename = dt.Tabs.Where(_tab => _tab.ID == tabid );
                if (tabsToRename.Count<Tab>() == 0)
                    result = 2;
                else
                {
                    var tabToRename = tabsToRename.Single();
                    if (tabToRename.UserID != GetCurrentUserID())
                    {
                        result = 1;
                    }
                    else
                    {
                        var sameName = dt.Tabs.Where(tab => tab.UserID == GetCurrentUserID() && tab.Name.CompareTo(newName) == 0);
                        if (sameName.Count<Tab>() != 0)
                            result = 3;
                        else
                        {
                            tabToRename.Name = newName;
                            dt.SubmitChanges();

                            result = 0;
                        }
                    }
                }

            }
            catch
            {
                result = 4;
            }
            finally
            {
            }

            return result;
        }
        public int RemoveTab(int tabid)
        {
            int result = -1;

            try
            {
                RSSDBDataContext dt = new RSSDBDataContext();

                var tabsToDelete = dt.Tabs.Where(_tab => _tab.ID == tabid);
                if (tabsToDelete.Count<Tab>() == 0)
                {
                    result = 2;
                }
                else
                {
                    var tabToDelete = tabsToDelete.Single();
                    if (tabToDelete.UserID != GetCurrentUserID())
                    {
                        var shares = dt.Shares.Where(share => share.TabID == tabToDelete.ID && share.AccountID == GetCurrentUserID());
                        dt.Shares.DeleteAllOnSubmit(shares);
                        dt.SubmitChanges();
                        result = 0;
                    }
                    else
                    {
                        var shares = dt.Shares.Where(share => share.TabID == tabToDelete.ID);

                        dt.Shares.DeleteAllOnSubmit(shares);

                        dt.RSSItems.DeleteAllOnSubmit(tabToDelete.RSSItems);

                        dt.Tabs.DeleteOnSubmit(tabToDelete);
                        dt.SubmitChanges();
                        result = 0;
                    }
                }

            }
            catch
            {
                result = 3;
            }
            finally
            {
            }

            return result;
        }
        public bool RemoveRSSItem(int rssid)
        {
            bool result = true;
            try
            {
                RSSDBDataContext data = new RSSDBDataContext();
                RSSItem item = (from rssitem in data.RSSItems
                                where rssitem.ID == rssid
                                select rssitem).Single();

                if (item.Tab.UserID != GetCurrentUserID())
                    return false;

                data.RSSItems.DeleteOnSubmit(item);
                data.SubmitChanges();
            }
            catch
            {
                result = false;
            }
            finally
            {

            }
            return result;
        }
        public bool Register(string username, string password)
        {
            if (!CheckValidUsername(username))
                return false;
            bool result = false;

            try
            {
                RSSDBDataContext dt = new RSSDBDataContext();
                int randomvalue = RANDOM.Next(0, int.MaxValue);
                string md5pass = ServiceUtility.CalculateMD5Hash(password + randomvalue.ToString());

                Account account = new Account()
                {
                    Username = username,
                    Password = md5pass,
                    Salt = randomvalue,
                };

                dt.Accounts.InsertOnSubmit(account);
                dt.SubmitChanges();

                result = true;
            }
            catch
            {
                result = false;
            }
            finally
            {
            }

            return result;
        }
        public int AddTab(string tabName)
        {
            int result = -1;
            try
            {
                RSSDBDataContext dt = new RSSDBDataContext();
                var tabs = dt.Tabs.Where(tab => tab.Name.CompareTo(tabName) == 0 && tab.UserID == GetCurrentUserID());
                if (tabs.Count<Tab>() == 0)
                {
                    int UserID = GetCurrentUserID();

                    Tab newTab = new Tab()
                    {
                        Name = tabName,
                        UserID = UserID,
                    };

                    dt.Tabs.InsertOnSubmit(newTab);
                    dt.SubmitChanges();

                    result = 0;
                }
                else
                {
                    result = 1;
                }
            }
            catch
            {
                result = 2;
            }
            finally
            {
            }

            return result;
        }
        public int AddRSSItemWithPlugin(int tabid, int pluginID)
        {
            int result = 5;
            try
            {
                RSSDBDataContext data = new RSSDBDataContext ();
                List<Tab> tabs = (from tab in data.Tabs
                                  where tab.ID == tabid
                                  select tab).ToList();
                if (tabs.Count == 0)
                    return 2;

                Tab tabToAdd = tabs[0];
                if (tabToAdd.UserID != GetCurrentUserID())
                    return 3;

                List<RSSPlugin> plugins = (from plu in data.RSSPlugins
                                           where plu.ID == pluginID
                                           select plu).ToList();
                if (plugins.Count == 0)
                    return 4;

                RSSPlugin plugin = plugins[0];

                //Kiểm tra đã tồn tại plugin trong tab hay chưa
                for (int i = 0; i < tabToAdd.RSSItems.Count; i++)
                {
                    if (tabToAdd.RSSItems[i].PluginID == pluginID)
                        return 1;
                }
                //---------------------------------------------------------------------------

                string[] fileNames = Directory.GetFiles(Server.MapPath("~") + @"\bin", plugin.DLLName);
                foreach (string fileName in fileNames)
                {
                    Assembly asm = Assembly.LoadFile(fileName);
                    Type[] types = asm.GetTypes();
                    foreach (Type type in types)
                    {
                        if (type.GetInterface("IRSSPlugin") != null)
                        {
                            IRSSPlugin pluginObject = Activator.CreateInstance(type) as IRSSPlugin;

                            RSSItem newItem = new RSSItem();
                            newItem.Name = pluginObject.GetRSSName();
                            newItem.Description = pluginObject.GetRSSDescription();
                            newItem.RSSLink = pluginObject.GetRSSWebsiteLink();
                            newItem.TabID = tabid;
                            newItem.PluginID = plugin.ID;
                            data.RSSItems.InsertOnSubmit(newItem);
                            data.SubmitChanges();
                            result = 0;
                        }
                    }
                }
            }
            catch
            {
                result = 5;
            }
            finally
            {

            }
            return result;
        }