コード例 #1
0
        public IOConnectionInfo CursorToIoc(ICursor cursor)
        {
            if (cursor == null)
            {
                return(null);
            }
            var ioc = new IOConnectionInfo
            {
                Path = cursor.GetString(cursor
                                        .GetColumnIndexOrThrow(KeyFileFilename)),
                UserName = cursor.GetString(cursor
                                            .GetColumnIndexOrThrow(KeyFileUsername)),
                Password = cursor.GetString(cursor
                                            .GetColumnIndexOrThrow(KeyFilePassword)),
                CredSaveMode = (IOCredSaveMode)cursor.GetInt(cursor
                                                             .GetColumnIndexOrThrow(KeyFileCredsavemode)),
                CredProtMode = IOCredProtMode.Obf
            };

            ioc.Obfuscate(false);

            return(ioc);
        }
コード例 #2
0
        public long CreateFile(IOConnectionInfo ioc, String keyFile)
        {
            // Check to see if this filename is already used
            ICursor cursor;

            try {
                cursor = mDb.Query(true, FileTable, new[] { KeyFileId },
                                   KeyFileFilename + "=?", new[] { ioc.Path }, null, null, null, null);
            } catch (Exception) {
                return(-1);
            }

            IOConnectionInfo iocToStore = ioc.CloneDeep();

            if (ioc.CredSaveMode != IOCredSaveMode.SaveCred)
            {
                iocToStore.Password = "";
            }
            if (ioc.CredSaveMode == IOCredSaveMode.NoSave)
            {
                iocToStore.UserName = "";
            }

            iocToStore.Obfuscate(true);

            long result;

            // If there is an existing entry update it
            if (cursor.Count > 0)
            {
                cursor.MoveToFirst();
                long id = cursor.GetLong(cursor.GetColumnIndexOrThrow(KeyFileId));

                var vals = new ContentValues();
                vals.Put(KeyFileKeyfile, keyFile);
                vals.Put(KeyFileUpdated, Java.Lang.JavaSystem.CurrentTimeMillis());

                vals.Put(KeyFileUsername, iocToStore.UserName);
                vals.Put(KeyFilePassword, iocToStore.Password);
                vals.Put(KeyFileCredsavemode, (int)iocToStore.CredSaveMode);

                result = mDb.Update(FileTable, vals, KeyFileId + " = " + id, null);

                // Otherwise add the new entry
            }
            else
            {
                var vals = new ContentValues();
                vals.Put(KeyFileFilename, ioc.Path);
                vals.Put(KeyFileKeyfile, keyFile);
                vals.Put(KeyFileUsername, iocToStore.UserName);
                vals.Put(KeyFilePassword, iocToStore.Password);
                vals.Put(KeyFileCredsavemode, (int)iocToStore.CredSaveMode);
                vals.Put(KeyFileUpdated, Java.Lang.JavaSystem.CurrentTimeMillis());

                result = mDb.Insert(FileTable, null, vals);
            }
            // Delete all but the last five records
            try {
                DeleteAllBut(MaxFiles);
            } catch (Exception ex) {
                Android.Util.Log.Error("ex", ex.StackTrace);
            }

            cursor.Close();

            return(result);
        }