私はDB I.Pを入力する必要があるアプリケーションで作業しています。アプリケーションが最初に実行されたときにポートします。私は、認証を処理するDatabase.cs(後に続くコード)というクラスを作成しました。適切な情報が入力されれば、すべて正常に動作します。しかし、誤った情報が追加されたかどうかを確認する方法はありません。私はそれをハードコーディングすることができますが、ハードコーディングに頼ることなくそれを処理する方法を探しています。このシナリオではXamarin Visual Studio Android C#couchbase liteの資格情報を検証する方法
Database.cs
using System;
using Android.Util;
using Couchbase.Lite;
using Couchbase.Lite.Auth;
namespace Core
{
public class Database
{
static readonly string TAG = "eTest: " + typeof(Database).Name;
const string DB_NAME = "dev";
public static Couchbase.Lite.Database db;
static public Replication pull;
static public Replication push;
public static void CreateDatabase()
{
try
{
Log.Debug(TAG, "Entering method CreateDatabase try block");
db = Manager.SharedInstance.GetDatabase(DB_NAME);
Log.Debug(TAG, "Exiting method CreateDatabase try block");
}
catch (Exception e)
{
Log.Debug(TAG, "Entering method CreateDatabase catch block");
Log.Error(TAG, "Error getting database", e);
Log.Debug(TAG, "Exiting method CreateDatabase catch block");
return;
}
}
public static Uri CreateSyncUri(string host, int port)
{
Log.Debug(TAG, "Entering method CreateSyncUri");
Uri syncUri = null;
string scheme = "http";
try
{
Log.Debug(TAG, "Entering try block of method CreateSyncUri");
var uriBuilder = new UriBuilder(scheme, host, port, DB_NAME);
syncUri = uriBuilder.Uri;
Log.Debug(TAG, "Exiting try block of method CreateSyncUri");
}
catch (UriFormatException e)
{
Log.Error(TAG, " Cannot Create sync uri", e);
}
return syncUri;
}
public static void StartReplicationWithAuth(string host, int port)
{
Log.Debug(TAG, "Entering method StartReplicationWithAuth");
pull = db.CreatePullReplication(CreateSyncUri(host, port));
push = db.CreatePushReplication(CreateSyncUri(host, port));
var authenticator = AuthenticatorFactory.CreateBasicAuthenticator("name", "password");
pull.Authenticator = authenticator;
push.Authenticator = authenticator;
pull.Continuous = true;
push.Continuous = true;
pull.Start();
push.Start();
Log.Debug(TAG, "Exiting method StartReplicationWithAuth");
}
}
}
ありがとうございました 上記のコードは、私が探していたものです。 – RRH