DHI.Services.MIKECloud for Documents — Internal Developer Guide¶
Use MIKECloud as the backend for the Documents domain (flat and grouped). For platform/auth/path rules, see MIKECloud Core.
What you get¶
Two flavors sharing the same concepts:
GroupedDocumentRepository(BaseGroupedDocumentRepository<string>) Best for most usage: groups/folders, group filters, metadata filtering.DocumentRepository(IDocumentRepository<string>) Flat repo. No group APIs, but accepts full-path IDs.
Mapping to MIKECloud
| Documents concept | MIKECloud object |
|---|---|
| Group/folder path | Project + nested Subprojects |
| Document (payload) | File dataset (DatasetType.File) |
Document metadata (Parameters) |
Dataset Metadata (string values) |
| Document ID | Full path /…/…/name.ext |
Capabilities & differences¶
| Operation / Area | Grouped repo | Flat repo | Notes |
|---|---|---|---|
| Add (upload) | ✓ | ✓ | Creates missing subprojects. Upload via Transfer; then copies Parameters → Metadata |
| Get (download) | ✓ | ✓ | Returns (Stream, fileType, fileName); Grouped rewinds stream, Flat doesn’t |
| Remove | ✓ | ✓ | Hard-deletes dataset |
| Contains | ✓ | ✓ | Resolves dataset by full path |
| Count | ✓ | ✓ | Counts File datasets recursively |
| GetIds | ✓ | ✓ | Returns full path IDs |
| GetAll | ✓ | ✗ | Emits Document<string> (Id/Name/Group + Metadata) |
| GetByGroup | ✓ | ✗ | Exact group match (normalized, case-insensitive) |
| GetMetadata | ✓ | ✓ | Dictionary from dataset Metadata |
| GetAllMetadata / Filter | ✓ | ✗ | Grouped supports value-token AND filtering |
Paths & IDs¶
- Full path ID:
"group/full/path/FileName.ext". - The path (before the last
/) → subprojects (created on demand by Add). - The last segment → dataset/file name in MIKECloud.
Connecting¶
Connection string
apiKey=<APIKEY>;projectId=<PROJECTID>;environment=Prod
Direct (code)
var grouped = new DHI.Services.Provider.MIKECloud.GroupedDocumentRepository(connString);
var flat = new DHI.Services.Provider.MIKECloud.DocumentRepository(connString);
groupedSvc = new new GroupedDocumentService<string>(grouped);
flatSvc = new new DocumentService<string>(flat);
ServiceLocator.Register(groupedSvc, "grouped-mc-docs");
ServiceLocator.Register(flatSvc, "flat-mc-docs");
Web API (Connections module)
{
"$type": "DHI.Services.Documents.WebApi.GroupedDocumentServiceConnection, DHI.Services.Documents.WebApi",
"RepositoryType": "DHI.Services.Provider.MIKECloud.GroupedDocumentRepository, DHI.Services.Provider.MIKECloud",
"ConnectionString": "apiKey=[env:MIKECLOUD_APIKEY];projectId=[env:MIKECLOUD_PROJECT];environment=Prod",
"Name": "Documents via MIKECloud (grouped)",
"Id": "mc-docs"
}
Code recipes¶
Upload + metadata → download¶
var docs = new GroupedDocumentRepository(conn);
using var file = File.OpenRead(@"C:\Temp\Summary.pdf");
var meta = new Parameters { { "Department","Finance" }, { "Confidential","Yes" } };
docs.Add(file, "reports/2025/Q3/Summary.pdf", meta);
var (stream, ext, name) = docs.Get("reports/2025/Q3/Summary.pdf");
// Grouped returns a rewound stream
using var outFs = File.Create($@"C:\Temp\{name}");
stream.CopyTo(outFs);
Flat repo download (remember to rewind)¶
var flat = new DocumentRepository(conn);
var (s, ext, name) = flat.Get("/Models/HEC/v2/notes.txt");
s.Seek(0, SeekOrigin.Begin);
Troubleshooting & notes¶
- Project not found: constructor validates
projectId→ArgumentException. - Remove “Invalid path …” → Provided path is not a dataset; ensure the last segment is a file name.
- Get:
fileTypeincludes the leading dot (e.g.,.csv). - Large files: Upload/download use the platform
TransferClient(streamed); avoid buffering. - Dataset overwrite: Re-uploading the same name in the same folder updates the existing dataset per platform rules.