예제 #1
0
        public static FilePermission File(string id)
        {
            //_fileRepositoryDataTable = null;

            //DataRowCollection rows = FileRepositoryDataTable.Rows;

            string searchString = "ID = '" + id + "'";
            string targetString = null;

            _fileRepositoryDataTable = Database.DB["CloudApp"].GetDataTable(_fileReposityTableName, targetString, searchString);
            DataRowCollection rows = _fileRepositoryDataTable.Rows;

            //var lrows = from lrow in new LINQList<DataRow>(rows)
            //            where (string)lrow["Id"] == id
            //            select lrow;

            if (rows.Count != 0)
            {
                foreach (DataRow row in rows)
                {
                    string name = (string)row["Name"];
                    // string description = (string)row["Description"];
                    string type               = (string)row["Type"];
                    string userid             = (string)row["UserID"];
                    QuantApp.Kernel.User user = QuantApp.Kernel.User.FindUser(userid);
                    DateTime             date = (DateTime)row["Timestamp"];
                    byte[] data               = System.Convert.FromBase64String((string)row["Data"]);
                    // FilePermission file = new FilePermission(id, name, description, type, date, user, data);
                    FilePermission file = new FilePermission(id, name, date, user, data, type);
                    return(file);
                }
            }
            return(null);
        }
예제 #2
0
        public static Dictionary <string, FilePermission> FilesByUser(string userID)
        {
            //_fileRepositoryDataTable = null;
            //DataTable table = DataTable;
            //DataRowCollection rows = FileRepositoryDataTable.Rows;

            string searchString = "UserID = '" + userID + "'";
            string targetString = null;

            _fileRepositoryDataTable = Database.DB["CloudApp"].GetDataTable(_fileReposityTableName, targetString, searchString);
            DataRowCollection rows = _fileRepositoryDataTable.Rows;


            //var lrows = from lrow in new LINQList<DataRow>(rows)
            //            where (string)lrow["UserID"] == userID
            //            orderby (DateTime)lrow["Timestamp"] descending
            //            select lrow;

            Dictionary <string, FilePermission> result = new Dictionary <string, FilePermission>();

            if (rows.Count != 0)
            {
                foreach (DataRow row in rows)
                {
                    string id   = (string)row["ID"];
                    string name = (string)row["Name"];
                    // string description = (string)row["Description"];
                    string type               = (string)row["Type"];
                    string userid             = (string)row["UserID"];
                    QuantApp.Kernel.User user = QuantApp.Kernel.User.FindUser(userid);
                    DateTime             date = (DateTime)row["Timestamp"];
                    byte[] data               = System.Convert.FromBase64String((string)row["Data"]);
                    // FilePermission file = new FilePermission(id, name, description, type, date, user, data);
                    Console.WriteLine("----- FILE: " + name);
                    FilePermission file = new FilePermission(id, name, date, user, data, type);
                    result.Add((string)row["ID"], file);
                }
            }

            return(result);
        }
예제 #3
0
        public static void AddFile(string id, string name, byte[] data, string type, DateTime timestamp, string userID, string groupID)
        {
            //DataTable table = DataTable;
            //DataRowCollection rows = FileRepositoryDataTable.Rows;
            string searchString = "ID = '" + id + "'";
            string targetString = "TOP 1 *";

            if (Database.DB["CloudApp"] is QuantApp.Kernel.Adapters.SQL.SQLiteDataSetAdapter || Database.DB["CloudApp"] is QuantApp.Kernel.Adapters.SQL.PostgresDataSetAdapter)
            {
                searchString += "LIMIT 1";
                targetString  = "*";
            }

            _fileRepositoryDataTable = Database.DB["CloudApp"].GetDataTable(_fileReposityTableName, targetString, searchString);
            DataRowCollection rows = _fileRepositoryDataTable.Rows;

            QuantApp.Kernel.User user = QuantApp.Kernel.User.FindUser(userID);
            FilePermission       file = new FilePermission(id, name, timestamp, user, data, type);

            Group group = Group.FindGroup(groupID);

            if (group != null)
            {
                group.Add(file, typeof(FilePermission), AccessType.Write);
            }

            DataRow r = _fileRepositoryDataTable.NewRow();

            r["ID"]   = id;
            r["Data"] = System.Convert.ToBase64String(data);
            r["Type"] = type;
            r["Name"] = name;
            // r["Description"] = description;
            r["Timestamp"] = timestamp;
            r["UserID"]    = userID;
            rows.Add(r);
            Database.DB["CloudApp"].UpdateDataTable(_fileRepositoryDataTable);
        }