コード例 #1
0
ファイル: Vault.cs プロジェクト: FourFourHero/TDSM-Vault
        public void getVaultObject(VaultObject vaultObject)
        {
            try {
                String tableName = tableNameFromPluginName(vaultObject.getPluginName());
                String query = "select id \"id\",";
                query += "objectName \"objectName\", xml \"xml\"";
                query += " from " + tableName;
                query += " where objectName = \"" + vaultObject.getObjectName() + "\"";

                // use passport info if present
                if (vaultObject.getPassport() != null) {
                    String username = vaultObject.getPassport().getUser().username;
                    query += " and passportUsername = \"" + username + "\"";
                } else {
                    query += " and passportUsername ISNULL";
                }

                debug(query);

                DataTable results = database.GetDataTable(query);
                // there should only ever be one copy of an object in the database
                DataRow row = results.Rows[0];
                vaultObject.fromDataRow(row);
            } catch (Exception e) {
                throw new VaultObjectNotFoundException();
            }
        }
コード例 #2
0
ファイル: Vault.cs プロジェクト: FourFourHero/TDSM-Vault
        public int getVaultObjectId(VaultObject vaultObject)
        {
            int id = -1;
            try {
                String tableName = tableNameFromPluginName(vaultObject.getPluginName());
                String query = "select id \"id\"";
                query += " from " + tableName;
                query += " where objectName = \"" + vaultObject.getObjectName() + "\"";

                // use passport info if present
                if (vaultObject.getPassport() != null) {
                    String username = vaultObject.getPassport().getUser().username;
                    query += " and passportUsername = \"" + username + "\"";
                } else {
                    query += " and passportUsername ISNULL";
                }
                debug(query);

                DataTable results = database.GetDataTable(query);
                // there should only ever be one copy of an object in the database
                DataRow row = results.Rows[0];
                id = Int32.Parse(row["id"].ToString());
            } catch (Exception e) {
                id = -1;
            }
            return id;
        }
コード例 #3
0
ファイル: Vault.cs プロジェクト: FourFourHero/TDSM-Vault
        //
        // API
        //
        public void store(VaultObject vaultObject)
        {
            try {
                String tableName = tableNameFromPluginName(vaultObject.getPluginName());
                createTable(tableName);

                Dictionary<string, string > dataDictionary = vaultObject.getDataDictionary();
                int id = this.getVaultObjectId(vaultObject);
                if (id == -1) {
                    System.Console.WriteLine("insert");
                    DateTime now = System.DateTime.Now;
                    dataDictionary["created"] = now.ToString();
                    dataDictionary["updated"] = now.ToString();
                    database.Insert(tableName, dataDictionary);
                } else {
                    System.Console.WriteLine("update");
                    DateTime now = System.DateTime.Now;
                    dataDictionary["updated"] = now.ToString();
                    String idString = tableName + ".id = " + id;
                    database.Update(tableName, dataDictionary, idString);
                }
                vaultObject.setId(this.getVaultObjectId(vaultObject));
            } catch (Exception e) {
                log(e.Message);
            }
        }