private void localizeEntryIds(BundleEntry entry) { // Did we already reassign this entry.Id within this batch? if (!uriMap.ContainsKey(entry.Id)) { Uri localUri; ResourceIdentity identity; identity = new ResourceIdentity(entry.Id); // If we shared this id space, use the relative path as id if (inSharedIdSpace(entry.Id) && (identity.Collection != null && identity.Id != null)) { localUri = identity.OperationPath; // If we're about to add an entry with a numerical id > than our current // "new record counter", make sure the next new record gets an id 1 higher // than this entries id. int newIdNum = 0; if (Int32.TryParse(identity.Id, out newIdNum)) { _store.EnsureNextSequenceNumberHigherThan(newIdNum); } } else { // Otherwise, give it a new relative, local id var newResourceId = _store.GenerateNewIdSequenceNumber(); string collectionName = getCollectionNameFromEntry(entry); localUri = ResourceIdentity.Build(collectionName, newResourceId.ToString()); } uriMap.Add(entry.Id, localUri); } // Reassign the resultString to our new local resultString entry.Id = uriMap[entry.Id]; // Now, build a new version-specific link (always, no reuse) string vid = _store.GenerateNewVersionSequenceNumber().ToString(); var id = new ResourceIdentity(entry.Id).WithVersion(vid); // If the entry did carry an version-specific resultString originally, // keep it in the map so we can update references to it. if (entry.SelfLink != null) { uriMap.Add(entry.SelfLink, id); } // Assign a new version-specific link to entry entry.SelfLink = id; }
/// <summary> /// Reinitializes the (database of) the server to its initial state /// </summary> /// <returns></returns> /// <remarks>Quite a destructive operation, mostly useful in debugging situations</remarks> public OperationOutcome Initialize() { //Note: also clears the counters collection, so id generation starts anew and //clears all stored binaries at Amazon S3. Stopwatch w = new Stopwatch(); w.Start(); _store.Clean(); //_store.EraseData(); //_store.EnsureIndices(); _index.Clean(); w.Stop(); long cleaning = w.ElapsedMilliseconds; //Insert our own conformance statement into Conformance collection ResourceEntry conformanceentry = ResourceEntry.Create(ConformanceBuilder.Build()); _service.Create(ConformanceBuilder.CONFORMANCE_COLLECTION_NAME, conformanceentry, ConformanceBuilder.CONFORMANCE_ID); //Insert standard examples w.Restart(); var examples = loadExamples(); var count = examples.Entries.OfType <Condition>().Count(); w.Stop(); long loadex = w.ElapsedMilliseconds; w.Restart(); _service.Transaction(examples); w.Stop(); var batch = w.ElapsedMilliseconds; //Start numbering new resources at an id higher than the examples (we hope) //EK: I like the convention of examples having id <10000, and new records >10.000, so please retain _store.EnsureNextSequenceNumberHigherThan(9999); string message = String.Format("Database was succesfully re-initialized: cleaning {0}, examples {1}, storage {2} ms", cleaning, loadex, batch); return(new OperationOutcome().Message(message)); }