Notitie
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen u aan te melden of de directory te wijzigen.
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen de mappen te wijzigen.
Bestands-SDK ondersteunt labelbewerkingen voor .msg bestanden op een manier die identiek is aan elk ander bestandstype, behalve dat de SDK de toepassing nodig heeft om msG-functievlag in te schakelen. Hier ziet u hoe u deze vlag instelt.
Zoals eerder besproken, is het instantiƫren van mip::FileEngine een instellingsobject vereist. mip::FileEngineSettings FileEngineSettings kan worden gebruikt om parameters door te geven voor aangepaste instellingen die de toepassing moet instellen voor een bepaald exemplaar.
CustomSettings eigenschap van de mip::FileEngineSettings wordt gebruikt voor het instellen van de vlag voor enable_msg_file_type het inschakelen van de verwerking van .msg bestanden.
Vereiste voorwaarden
Als u dat nog niet hebt gedaan, moet u de volgende vereisten voltooien voordat u doorgaat:
- Voltooi eerst de Quickstart: Initialisatie van bestands-SDK-toepassingen (C++), waarmee een eenvoudige Visual Studio-oplossing wordt gebouwd. Deze quickstart 'Hoe te - e-mailbericht .msg bestanden verwerken (C++)' is gebaseerd op de vorige.
- Review Snelstart: Vertrouwelijkheidslabels (C++) opsommen.
- Snelstart: Vertrouwelijkheidslabels instellen/ophalen (C++).
- Bekijk de MIP SDK-concepten voor e-mailbestanden .
- Optioneel: Bekijk de bestandsengines in de MIP SDK-concepten.
- Optioneel: Bekijk de bestandshandlers in de MIP SDK-concepten.
Vereiste implementatiestappen
Open de Visual Studio-oplossing die u in het vorige artikel 'Quickstart: Initialisatie van clienttoepassingen (C++)' hebt gemaakt.
Maak een PowerShell-script om toegangstokens te genereren, zoals wordt uitgelegd in quickstart 'Vertrouwelijkheidslabels (C++) vermelden'.
Implementeer waarnemersklasse om te bewaken
mip::FileHandler, zoals wordt uitgelegd in de quickstart 'Vertrouwelijkheidslabels instellen/ophalen (C++)'.
Enable_msg_file_type instellen en bestands-SDK gebruiken om .msg bestand te labelen
Voeg de onderstaande code voor de constructie van de bestandsengine toe om enable_msg_file_type flag in te stellen en gebruik de bestandsengine om een .msg-bestand te labelen.
Open met Solution Explorer het .cpp-bestand in uw project dat de implementatie van de
main()methode bevat. Deze wordt standaard ingesteld op dezelfde naam als het project dat het bevat, die u hebt opgegeven tijdens het maken van het project.Voeg de volgende #include en using-instructies toe, onder de overeenkomende bestaande instructies, bovenaan in het bestand:
#include "filehandler_observer.h" #include "mip/file/file_handler.h" #include <iostream> using mip::FileHandler; using std::endl;Verwijder de implementatie van de functie
main()uit de vorige quickstart. Voeg in demain()hoofdtekst de volgende code in. In de onderstaande codeblok wordt de vlagenable_msg_file_typeingesteld tijdens het maken van een bestandsmotor, en vervolgens kan een .msg-bestand worden verwerkt doormip::FileHandlerobjecten die zijn gemaakt met behulp van de bestandsmotor.
int main()
{
// Construct/initialize objects required by the application's profile object
ApplicationInfo appInfo { "<application-id>", // ApplicationInfo object (App ID, name, version)
"<application-name>",
"1.0"
};
std::shared_ptr<mip::MipConfiguration> mipConfiguration = std::make_shared<mip::MipConfiguration>(mAppInfo,
"mip_data",
mip::LogLevel::Trace,
false);
std::shared_ptr<mip::MipContext> mMipContext = mip::MipContext::Create(mipConfiguration);
auto profileObserver = make_shared<ProfileObserver>(); // Observer object
auto authDelegateImpl = make_shared<AuthDelegateImpl>("<application-id>"); // Authentication delegate object (App ID)
auto consentDelegateImpl = make_shared<ConsentDelegateImpl>(); // Consent delegate object
// Construct/initialize profile object
FileProfile::Settings profileSettings(mipContext,mip::CacheStorageType::OnDisk,authDelegateImpl,
consentDelegateImpl,profileObserver);
// Set up promise/future connection for async profile operations; load profile asynchronously
auto profilePromise = make_shared<promise<shared_ptr<FileProfile>>>();
auto profileFuture = profilePromise->get_future();
try
{
mip::FileProfile::LoadAsync(profileSettings, profilePromise);
}
catch (const std::exception& e)
{
std::cout << "An exception occurred. Are the Settings and ApplicationInfo objects populated correctly?\n\n"<< e.what() << "'\n";
system("pause");
return 1;
}
auto profile = profileFuture.get();
// Construct/initialize engine object
FileEngine::Settings engineSettings(
mip::Identity("<engine-account>"), // Engine identity (account used for authentication)
"<engine-state>", // User-defined engine state
"en-US"); // Locale (default = en-US)
//Set enable_msg_file_type flag as true
std::vector<std::pair<string, string>> customSettings;
customSettings.emplace_back(mip::GetCustomSettingEnableMsgFileType(), "true");
engineSettings.SetCustomSettings(customSettings);
// Set up promise/future connection for async engine operations; add engine to profile asynchronously
auto enginePromise = make_shared<promise<shared_ptr<FileEngine>>>();
auto engineFuture = enginePromise->get_future();
profile->AddEngineAsync(engineSettings, enginePromise);
std::shared_ptr<FileEngine> engine;
try
{
engine = engineFuture.get();
}
catch (const std::exception& e)
{
cout << "An exception occurred... is the access token incorrect/expired?\n\n"<< e.what() << "'\n";
system("pause");
return 1;
}
//Set file paths
string inputFilePath = "<input-file-path>"; //.msg file to be labeled
string actualFilePath = inputFilePath;
string outputFilePath = "<output-file-path>"; //labeled .msg file
string actualOutputFilePath = outputFilePath;
//Create a file handler for original file
auto handlerPromise = std::make_shared<std::promise<std::shared_ptr<FileHandler>>>();
auto handlerFuture = handlerPromise->get_future();
engine->CreateFileHandlerAsync(inputFilePath,
actualFilePath,
true,
std::make_shared<FileHandlerObserver>(),
handlerPromise);
auto fileHandler = handlerFuture.get();
//List labels available to the user
// Use mip::FileEngine to list all labels
labels = mEngine->ListSensitivityLabels();
// Iterate through each label, first listing details
for (const auto& label : labels) {
cout << label->GetName() << " : " << label->GetId() << endl;
// get all children for mip::Label and list details
for (const auto& child : label->GetChildren()) {
cout << "-> " << child->GetName() << " : " << child->GetId() << endl;
}
}
string labelId = "<labelId-id>"; //set a label ID to use
// Labeling requires a mip::LabelingOptions object.
// Review API ref for more details. The sample implies that the file was labeled manually by a user.
mip::LabelingOptions labelingOptions(mip::AssignmentMethod::PRIVILEGED);
fileHandler->SetLabel(labelId, labelingOptions, mip::ProtectionSettings());
// Commit changes, save as outputFilePath
auto commitPromise = std::make_shared<std::promise<bool>>();
auto commitFuture = commitPromise->get_future();
if(fileHandler->IsModified())
{
fileHandler->CommitAsync(outputFilePath, commitPromise);
}
if (commitFuture.get()) {
cout << "\n Label applied to file: " << outputFilePath << endl;
}
else {
cout << "Failed to label: " + outputFilePath << endl;
return 1;
}
// Create a new handler to read the label
auto msgHandlerPromise = std::make_shared<std::promise<std::shared_ptr<FileHandler>>>();
auto msgHandlerFuture = handlerPromise->get_future();
engine->CreateFileHandlerAsync(inputFilePath,
actualFilePath,
true,
std::make_shared<FileHandlerObserver>(),
msgHandlerPromise);
auto msgFileHandler = msgHandlerFuture.get();
cout << "Original file: " << inputFilePath << endl;
cout << "Labeled file: " << outputFilePath << endl;
cout << "Label applied to file : "
<< msgFileHandler->GetName()
<< endl;
// Application shutdown. Null out profile, engine, handler.
// Application may crash at shutdown if resources aren't properly released.
msgFileHandler = nullptr;
fileHandler = nullptr;
engine = nullptr;
profile = nullptr;
mipContext = nullptr;
return 0;
}
Raadpleeg de bestandsbeheerconcepten voor meer informatie over bestandsbewerkingen.
Vervang de tijdelijke aanduidingen in de broncode met behulp van de volgende waarden:
Plaatsvervanger Waarde <toepassings-ID> De toepassings-id zoals geregistreerd bij Microsoft Entra-tenant, bijvoorbeeld: 0edbblll-8773-44de-b87c-b8c6276d41eb.<engine-account> Het account dat wordt gebruikt voor de identiteit van de engine, bijvoorbeeld: user@tenant.onmicrosoft.com.<motorconditie> Door de gebruiker gedefinieerde toepassingsstatus, bijvoorbeeld: My engine state.<input-file-path> Het volledige pad naar een testinvoerberichtbestand, bijvoorbeeld: c:\\Test\\message.msg.<uitvoer-bestand-pad> Het volledige pad naar het uitvoerbestand, een gelabelde kopie van het invoerbestand, bijvoorbeeld: c:\\Test\\message_labeled.msg<label-id> De labelId verkregen met ListSensitivityLabels, bijvoorbeeld:667466bf-a01b-4b0a-8bbf-a79a3d96f720.
De toepassing bouwen en testen
Gebruik F6 (Build Solution) om uw clienttoepassing te bouwen. Als u geen buildfouten hebt, gebruikt u F5 (Foutopsporing starten) om uw toepassing uit te voeren.