private void UpdatePropTypeRecord(string propName, IResource res) { IResultSet rs = _propTypeTable.CreateModifiableResultSet(1, propName); try { IEnumerator enumerator = rs.GetEnumerator(); using ((IDisposable)enumerator) { if (!enumerator.MoveNext()) { throw new StorageException("Cannot find the property type to be updated"); } IRecord rec = (IRecord)enumerator.Current; if (rec.GetIntValue(2) != res.GetIntProp("DataType")) { throw new StorageException("Invalid attempt to change data type of property " + propName + " from " + (PropDataType)rec.GetIntValue(2) + " to " + (PropDataType)res.GetIntProp("DataType")); } rec.SetValue(3, res.GetIntProp("Flags")); _storage.SafeCommitRecord(rec, "PropTypeCollection.UpdatePropTypeRecord"); } } finally { rs.Dispose(); } }
public static IResultSet <T> ToSortedResultSet(IResultSet <T> source) { if (source is SortedResultSet <T> ) { return(source); } return(new SortedResultSet <T>(source.GetEnumerator())); }
public static IResultSet <T> ToBaggedResultSet(IResultSet <T> source) { if (source is ListedResultSet <T> ) { return(source); } return(new ListedResultSet <T>(source.GetEnumerator())); }
private void ProcessUpdates() { IResultSet <TKey, TValue> results = null; IEnumerator <KeyValuePair <TKey, TValue> > enumerator; KeyValuePair <TKey, TValue> item; do { Monitor.Enter(_syncLock); try { if (_updateRequests.Count == 0) { _updateInProgress = false; } else { results = _updateRequests.Dequeue(); } } finally { Monitor.Exit(_syncLock); } if (_updateInProgress && results != null) { using (results) { using (enumerator = results.GetEnumerator()) { while (enumerator.MoveNext()) { try { item = enumerator.Current; _cache.Add(item); } catch (Exception e) { OnError(new OnErrorEventArgs(e)); } } } } OnFilled(new OnFilledEventArgs()); } } while (_updateInProgress); }
protected SafeRecordEnumeratorBase(IResultSet resultSet, string operation) { _resultSet = resultSet; _operation = operation; try { _baseEnumerator = resultSet.GetEnumerator(); } catch (IOException ex) { _ioError = true; _resultSet.Dispose(); MyPalStorage.Storage.OnIOErrorDetected(ex); _baseEnumerator = null; } }
private void RepairProps(ITable propTable, PropDataType dataType) { HashSet resPropTypes = new HashSet(); int lastResID = -1; using (IResultSet rs = propTable.CreateResultSet(0)) { IEnumerator enumerator = rs.GetEnumerator(); try { while (enumerator.MoveNext()) { IRecord rec; try { rec = (IRecord)enumerator.Current; } catch (AttemptReadingDeletedRecordException) { ReportError("Deleted record found in index for " + dataType + " property table"); continue; } _propCount++; int resID = rec.GetIntValue(0); int propType = rec.GetIntValue(1); if (resID != lastResID) { lastResID = resID; resPropTypes.Clear(); } IRecord resRec = _resources.GetRecordByEqual(0, resID); if (resRec == null) { ReportError("Found a property of a non-existing resource " + resID); if (_fixErrors) { rec.Delete(); _fixCount++; } continue; } if (!_propTypeMap.Contains(propType)) { ReportError("Found a property with an invalid type " + propType); if (_fixErrors) { rec.Delete(); _fixCount++; } continue; } if ((int)_propDataTypes [propType] != (int)dataType) { ReportError("Type of property " + propType + " does not match type of table " + dataType); if (_fixErrors) { rec.Delete(); _fixCount++; } continue; } string propTypeName = (string)_propTypeMap [propType]; if (dataType != PropDataType.StringList && resPropTypes.Contains(propType)) { ReportError("Duplicate property " + propTypeName + " of resource " + resID); if (_fixErrors) { rec.Delete(); _fixCount++; } continue; } if (dataType == PropDataType.Blob) { IBLOB blob = rec.GetBLOBValue(2); Stream stream; try { stream = blob.Stream; } catch (IOException) { ReportError("Missing blob stream for property " + propTypeName + " of resource " + resID); if (_fixErrors) { rec.Delete(); _fixCount++; } continue; } try { long length = stream.Length; byte[] buffer = new byte[4096]; for (long bytesRead = 0; bytesRead < length; bytesRead += 4096) { int bytesToRead = Math.Min(4096, (int)(length - bytesRead)); stream.Read(buffer, 0, bytesToRead); } } catch (IOException) { ReportError("Failed to read blob stream for property " + propTypeName + " of resource " + resID); if (_fixErrors) { rec.Delete(); _fixCount++; } } stream.Close(); } else if (dataType == PropDataType.String || dataType == PropDataType.LongString) { try { rec.GetStringValue(2); } catch (IOException ex) { ReportError("Failed to read string value for property " + propTypeName + " of resource " + resID); if (_fixErrors) { rec.Delete(); _fixCount++; } } } resPropTypes.Add(propType); } } finally { IDisposable disp = enumerator as IDisposable; if (disp != null) { disp.Dispose(); } } } }
public IEnumerator GetEnumerator() { return(new VerifyStringEnumerator(_resultSet.GetEnumerator(), _indexStringColumn, _value)); }