Microsoft Information Protection SDK - Concetti relativi al profilo dell'API ProtezioneMicrosoft Information Protection SDK - Protection API profile concepts
I due esempi seguenti mostrano come creare l'oggetto profileSettings usando l'archiviazione locale o solo in memoria per l'archiviazione degli stati.The two examples below show how to create the profileSettings object using local storage for state storage as well as in-memory only.
Caricare un profiloLoad a Profile
Ora che ProtectionProfileObserverImpl
è definito, verrà usato per creare un'istanza mip::ProtectionProfile
.Now that the ProtectionProfileObserverImpl
is defined, we'll use it to instantiate mip::ProtectionProfile
. Per creare mip::ProtectionProfile
l'oggetto mip::ProtectionProfile::Settings
è necessario.Creating the mip::ProtectionProfile
object requires mip::ProtectionProfile::Settings
.
Parametri ProtectionProfile::SettingsProtectionProfile::Settings Parameters
std::shared_ptr<MipContext>
: Oggettomip::MipContext
inizializzato per archiviare le informazioni sull'applicazione, il percorso di stato e così via.std::shared_ptr<MipContext>
: Themip::MipContext
object that was initialized to store application info, state path, etc.mip::CacheStorageType
: Definisce come archiviare lo stato: in memoria, su disco o su disco e crittografato.mip::CacheStorageType
: Defines how to store state: In memory, on disk, or on disk and encrypted.std::shared_ptr<mip::ConsentDelegate>
: Puntatore condiviso della classemip::ConsentDelegate
.std::shared_ptr<mip::ConsentDelegate>
: A shared pointer of classmip::ConsentDelegate
.std::shared_ptr<mip::ProtectionProfile::Observer> observer
: Puntatore condiviso all'implementazione del profiloObserver
(inPolicyProfile
,ProtectionProfile
eFileProfile
).std::shared_ptr<mip::ProtectionProfile::Observer> observer
: A shared pointer to the profileObserver
implementation (inPolicyProfile
,ProtectionProfile
, andFileProfile
).
I due esempi seguenti mostrano come creare l'oggetto profileSettings usando l'archiviazione locale o solo in memoria per l'archiviazione degli stati.The two examples below show how to create the profileSettings object using local storage for state storage as well as in-memory only.
Archiviare lo stato solo in memoriaStore state in memory only
mip::ApplicationInfo appInfo {clientId, "APP NAME", "1.2.3" };
mMipContext = mip::MipContext::Create(appInfo,
"mip_app_data",
mip::LogLevel::Trace,
nullptr /*loggerDelegateOverride*/,
nullptr /*telemetryOverride*/);
ProtectionProfile::Settings profileSettings(
mipContext, // mipContext object
mip::CacheStorageType::InMemory, // use in memory storage
std::make_shared<ConsentDelegateImpl>(), // new consent delegate
std::make_shared<ProtectionProfileObserverImpl>()); // new protection profile observer
Leggere/scrivere le impostazioni del profilo dal percorso di archiviazione su discoRead/write profile settings from storage path on disk
mip::ApplicationInfo appInfo {clientId, "APP NAME", "1.2.3" };
mMipContext = mip::MipContext::Create(appInfo,
"mip_app_data",
mip::LogLevel::Trace,
nullptr /*loggerDelegateOverride*/,
nullptr /*telemetryOverride*/);
ProtectionProfile::Settings profileSettings(
mipContext, // mipContext object
mip::CacheStorageType::OnDisk, // use on disk storage
std::make_shared<ConsentDelegateImpl>(), // new consent delegate
std::make_shared<ProtectionProfileObserverImpl>()); // new protection profile
Usare poi il modello promise/future per caricare il ProtectionProfile
.Next, use the promise/future pattern to load the ProtectionProfile
.
auto profilePromise = std::make_shared<std::promise<std::shared_ptr<ProtectionProfile>>>();
auto profileFuture = profilePromise->get_future();
ProtectionProfile::LoadAsync(profileSettings, profilePromise);
Se fosse stato caricato un profilo e tale operazione fosse stata completata correttamente (ProtectionProfileObserverImpl::OnLoadSuccess
), verrebbe chiamata l'implementazione di mip::ProtectionProfile::Observer::OnLoadSuccess
.If we've loaded a profile, and that operation was successful, ProtectionProfileObserverImpl::OnLoadSuccess
, our implementation of mip::ProtectionProfile::Observer::OnLoadSuccess
is called. L'oggetto risultante o il puntatore dell'eccezione, nonché il contesto, vengono passati come parametri alla funzione.The resulting object or exception pointer, as well as the context, are passed in as parameters to the function. Il contesto è un puntatore a std::promise
creato per gestire l'operazione asincrona.The context is a pointer to the std::promise
we created to handle the async operation. La funzione imposta semplicemente il valore della promessa sull'oggetto ProtectionProfile (contesto).The function simply sets the value of the promise to the ProtectionProfile object (context). Quando la funzione main usa Future.get()
, il risultato può essere archiviato in un nuovo oggetto.When the main function uses Future.get()
, the result can be stored in a new object.
//get the future value and store in profile.
auto profile = profileFuture.get();
RiepilogoPutting it Together
Dopo aver completato l'implementazione degli osservatori e del delegato di autenticazione, è ora possibile caricare completamente un profilo.Having fully implemented the observers and authentication delegate, it's now possible to fully load a profile. Il frammento di codice riportato di seguito presuppone che tutte le intestazioni necessarie siano già incluse.The code snip below assumes all necessary headers are already included.
int main()
{
const string userName = "MyTestUser@contoso.com";
const string password = "P@ssw0rd!";
const string clientId = "MyClientId";
mip::ApplicationInfo appInfo {clientId, "APP NAME", "1.2.3" };
auto mipContext = mip::MipContext::Create(appInfo,
"mip_app_data",
mip::LogLevel::Trace,
nullptr /*loggerDelegateOverride*/,
nullptr /*telemetryOverride*/);
ProtectionProfile::Settings profileSettings(
mipContext, // mipContext object
mip::CacheStorageType::OnDisk, // use on disk storage
std::make_shared<ConsentDelegateImpl>(), // new consent delegate
std::make_shared<ProfileObserver>()); // new protection profile observer
auto profilePromise = std::make_shared<promise<shared_ptr<ProtectionProfile>>>();
auto profileFuture = profilePromise->get_future();
ProtectionProfile::LoadAsync(profileSettings, profilePromise);
auto profile = profileFuture.get();
}
Il risultato finale è il caricamento corretto del profilo e l'archiviazione nell'oggetto denominato profile
.The end result being that we've successfully loaded the profile and stored in the object called profile
.
Passaggi successiviNext Steps
Ora che il profilo è stato aggiunto, il passaggio successivo consiste nell'aggiungere un motore al profilo.Now that the profile has been added, the next step is to add an engine to the profile.
Concetti relativi al motore di protezioneProtection engine concepts