/// <summary> /// Serialize to string /// </summary> /// <returns>Serialized as string</returns> public string Serialize() { IDataId dataId = EnsureDataIdType(_dataId); if ((_serializedData == null) || (dataId != _dataId)) { string s = SerializationFacade.Serialize(this.DataId); System.Text.StringBuilder sb = new System.Text.StringBuilder(); StringConversionServices.SerializeKeyValuePair(sb, "_dataId_", s); StringConversionServices.SerializeKeyValuePair(sb, "_dataIdType_", TypeManager.SerializeType(this.DataId.GetType())); if (_providerName != DataProviderRegistry.DefaultDynamicTypeDataProviderName) { StringConversionServices.SerializeKeyValuePair(sb, "_providerName_", _providerName); } StringConversionServices.SerializeKeyValuePair(sb, "_interfaceType_", TypeManager.SerializeType(_interfaceType)); StringConversionServices.SerializeKeyValuePair(sb, "_dataScope_", DataScopeIdentifier.Serialize()); StringConversionServices.SerializeKeyValuePair(sb, "_localeScope_", LocaleScope.Name); _serializedData = sb.ToString(); } return(_serializedData); }
/// <exclude /> public static bool CompareTo(this IDataId sourceDataId, IDataId targetDataId, bool throwExceptionOnTypeMismathc) { if (sourceDataId == null) throw new ArgumentNullException("sourceDataId"); if (targetDataId == null) throw new ArgumentNullException("targetDataId"); if (sourceDataId.GetType() != targetDataId.GetType()) { if (throwExceptionOnTypeMismathc) throw new ArgumentException(string.Format("Type mismatch {0} and {1}", sourceDataId.GetType(), targetDataId.GetType())); return false; } bool equal = true; foreach (PropertyInfo sourcePropertyInfo in sourceDataId.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) { PropertyInfo targetPropertyInfo = targetDataId.GetType().GetProperty(sourcePropertyInfo.Name, BindingFlags.Public | BindingFlags.Instance); object sourceValue = sourcePropertyInfo.GetValue(sourceDataId, null); object targetValue = targetPropertyInfo.GetValue(targetDataId, null); if (object.Equals(sourceValue, targetValue) == false) { equal = false; break; } } return equal; }
/// <summary> /// This is for internal use only! /// </summary> public DataSourceId(IDataId dataId, string providerName, Type interfaceType, DataScopeIdentifier dataScope, CultureInfo localeScope) { // This constructor has to be extremely fast, we have up to 100.000 objects related while some requests if (dataId == null) { throw new ArgumentNullException("dataId"); } if (string.IsNullOrEmpty(providerName)) { throw new ArgumentNullException("providerName"); } if (interfaceType == null) { throw new ArgumentNullException("interfaceType"); } if (dataScope == null) { throw new ArgumentNullException("dataScope"); } if (localeScope == null) { throw new ArgumentNullException("localeScope"); } this.DataId = dataId; ProviderName = providerName; InterfaceType = interfaceType; _dataScopeIdentifier = dataScope; _localeScope = localeScope; this.ExistsInStore = true; }
/// <exclude /> public DataSourceId CreateDataSourceId(IDataId dataId, Type interfaceType) { Verify.ArgumentNotNull(dataId, "dataId"); Verify.ArgumentNotNull(interfaceType, "interfaceType"); Verify.ArgumentCondition(typeof(IData).IsAssignableFrom(interfaceType), "interfaceType", "The interface type '{0}' does not inherit the interface '{1}'".FormatWith(interfaceType, typeof(IData))); return(new DataSourceId(dataId, _providerName, interfaceType, DataScopeManager.MapByType(interfaceType), LocalizationScopeManager.MapByType(interfaceType))); }
/// <exclude /> public DataSourceId CreateDataSourceId(IDataId dataId, Type interfaceType) { Verify.ArgumentNotNull(dataId, "dataId"); Verify.ArgumentNotNull(interfaceType, "interfaceType"); Verify.ArgumentCondition(typeof(IData).IsAssignableFrom(interfaceType), "interfaceType", "The interface type '{0}' does not inherit the interface '{1}'".FormatWith(interfaceType, typeof(IData))); return new DataSourceId(dataId, _providerName, interfaceType, DataScopeManager.MapByType(interfaceType), LocalizationScopeManager.MapByType(interfaceType)); }
public static string Serialize(this IDataId dataId, IEnumerable <string> propertyNames) { if (dataId == null) { throw new ArgumentNullException(nameof(dataId)); } return(CompositeJsonSerializer.SerializePartial(dataId, propertyNames)); }
/// <exclude /> public T GetData <T>(IDataId dataId) where T : class, IData { if (dataId == null) { throw new ArgumentNullException("dataId"); } CheckInterface(typeof(T)); MediaDataId mediaDataId = dataId as MediaDataId; if (mediaDataId == null) { return(null); } if (mediaDataId.MediaType == MediaElementType.Folder) { if (typeof(T) != typeof(IMediaFileFolder)) { throw new ArgumentException("The dataId specifies a IMediaFileFolder, but the generic method was invoked with different type"); } IMediaFolderData folder = DataFacade.GetData <IMediaFolderData>().FirstOrDefault(x => x.Id == mediaDataId.Id); if (folder == null) { return(null); } return(new MediaFileFolder(folder, Store.Id, _context.CreateDataSourceId(new MediaDataId { MediaType = MediaElementType.Folder, Id = folder.Id }, typeof(IMediaFileFolder))) as T); } if (mediaDataId.MediaType == MediaElementType.File) { if (typeof(T) != typeof(IMediaFile)) { throw new ArgumentException("The dataId specifies a IMediaFile, but the generic method was invoked with different type"); } IMediaFileData file = DataFacade.GetData <IMediaFileData>().FirstOrDefault(x => x.Id == mediaDataId.Id); if (file == null) { return(null); } string internalPath = Path.Combine(_workingDirectory, file.Id.ToString()); return(new MediaFile(file, Store.Id, _context.CreateDataSourceId(new MediaDataId { MediaType = MediaElementType.File, Id = file.Id }, typeof(IMediaFile)), internalPath) as T); } return(Store as T); }
/// <exclude /> public DataSourceId CreateDataSourceId(IDataId dataId, Type interfaceType, DataScopeIdentifier dataScopeIdentifier, CultureInfo cultureInfo) { Verify.ArgumentNotNull(dataId, "dataId"); Verify.ArgumentNotNull(interfaceType, "interfaceType"); Verify.ArgumentNotNull(dataScopeIdentifier, "dataScopeIdentifier"); Verify.ArgumentNotNull(cultureInfo, "cultureInfo"); Verify.ArgumentCondition(typeof(IData).IsAssignableFrom(interfaceType), "interfaceType", "The interface type '{0}' does not inherit the interface '{1}'".FormatWith(interfaceType, typeof(IData))); return new DataSourceId(dataId, _providerName, interfaceType, dataScopeIdentifier, cultureInfo); }
/// <exclude /> public DataSourceId CreateDataSourceId(IDataId dataId, Type interfaceType, DataScopeIdentifier dataScopeIdentifier, CultureInfo cultureInfo) { Verify.ArgumentNotNull(dataId, "dataId"); Verify.ArgumentNotNull(interfaceType, "interfaceType"); Verify.ArgumentNotNull(dataScopeIdentifier, "dataScopeIdentifier"); Verify.ArgumentNotNull(cultureInfo, "cultureInfo"); Verify.ArgumentCondition(typeof(IData).IsAssignableFrom(interfaceType), "interfaceType", "The interface type '{0}' does not inherit the interface '{1}'".FormatWith(interfaceType, typeof(IData))); return(new DataSourceId(dataId, _providerName, interfaceType, dataScopeIdentifier, cultureInfo)); }
public static T GetData <T>(string providerName, IDataId dataId) where T : class, IData { Verify.ArgumentNotNull(dataId, "dataId"); using (TimerProfilerFacade.CreateTimerProfiler()) { return(Call <IDataProvider, T>(providerName, provider => provider.GetData <T>(dataId))); } }
private DataSourceId(IDataId dataId, string providerName, Type interfaceType, DataScopeIdentifier dataScopeIdentifier, string localeScope) { // This constructor has to be extremely fast, we have up to 100.000 objects related while some requests this.DataId = dataId ?? throw new ArgumentNullException(nameof(dataId)); ProviderName = providerName ?? DataProviderRegistry.DefaultDynamicTypeDataProviderName; InterfaceType = interfaceType ?? throw new ArgumentNullException(nameof(interfaceType)); DataScopeIdentifier = dataScopeIdentifier ?? throw new ArgumentNullException(nameof(dataScopeIdentifier)); LocaleScope = CultureInfo.CreateSpecificCulture(localeScope); this.ExistsInStore = true; }
public List <T> AddNew <T>(IEnumerable <T> dataset) where T : class, IData { Verify.ArgumentNotNull(dataset, "dataset"); CheckTransactionNotInAbortedState(); var resultList = new List <T>(); using (XmlDataProviderDocumentCache.CreateEditingContext()) { XmlDataTypeStore dataTypeStore = _xmlDataTypeStoresContainer.GetDataTypeStore(typeof(T)); var dataTypeStoreScope = dataTypeStore.GetDataScopeForType(typeof(T)); var fileRecord = GetFileRecord(dataTypeStore, dataTypeStoreScope); var validatedElements = new Dictionary <DataSourceId, XElement>(); // validating phase foreach (IData data in dataset) { Verify.ArgumentCondition(data != null, nameof(dataset), "The enumeration dataset may not contain nulls"); ValidationHelper.Validate(data); XElement newElement; T newData = dataTypeStore.Helper.CreateNewElement <T>(data, out newElement, dataTypeStoreScope.ElementName, _dataProviderContext.ProviderName); IDataId dataId = dataTypeStore.Helper.CreateDataId(newElement); XElement violatingElement = fileRecord.RecordSet.Index[dataId]; if (violatingElement != null) { throw new ArgumentException(nameof(dataset), "Key violation error. A data element with the same dataId is already added. Type: " + typeof(T).FullName); } validatedElements.Add(newData.DataSourceId, newElement); resultList.Add(newData); } // commit validated elements foreach (var key in validatedElements.Keys) { fileRecord.RecordSet.Index.Add(key.DataId, validatedElements[key]); fileRecord.Dirty = true; } XmlDataProviderDocumentCache.SaveChanges(); SubscribeToTransactionRollbackEvent(); } return(resultList); }
/// <summary> /// This is for internal use only! /// </summary> public DataSourceId(IDataId dataId, string providerName, Type interfaceType) { if (string.IsNullOrEmpty(providerName)) { throw new ArgumentNullException(nameof(providerName)); } this.DataId = dataId ?? throw new ArgumentNullException(nameof(dataId)); ProviderName = providerName; InterfaceType = interfaceType ?? throw new ArgumentNullException(nameof(interfaceType)); DataScopeIdentifier = DataScopeManager.MapByType(interfaceType); LocaleScope = LocalizationScopeManager.MapByType(interfaceType); this.ExistsInStore = true; }
public T GetData <T>(IDataId dataId) where T : class, IData { CheckInterface(typeof(T)); FileSystemFileDataId fileSystemFileDataId = dataId as FileSystemFileDataId; if (fileSystemFileDataId == null) { return(null); } return(BuildNewFileSystemFile <T>(fileSystemFileDataId.FullPath)); }
public static string Serialize(this IDataId dataId) { if (dataId == null) { throw new ArgumentNullException("dataId"); } StringBuilder sb = new StringBuilder(); StringConversionServices.SerializeKeyValuePair(sb, "_dataIdType_", TypeManager.SerializeType(dataId.GetType())); StringConversionServices.SerializeKeyValuePair(sb, "_dataId_", SerializationFacade.Serialize(dataId)); return(sb.ToString()); }
/// <exclude /> public static void FullCopyTo(this IDataId sourceDataId, IDataId targetDataId) { if (sourceDataId == null) throw new ArgumentNullException("sourceDataId"); if (targetDataId == null) throw new ArgumentNullException("targetDataId"); foreach (PropertyInfo sourcePropertyInfo in sourceDataId.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) { PropertyInfo targetPropertyInfo = targetDataId.GetType().GetProperty(sourcePropertyInfo.Name, BindingFlags.Public | BindingFlags.Instance); object value = sourcePropertyInfo.GetValue(sourceDataId, null); targetPropertyInfo.SetValue(targetDataId, value, null); } }
public static string Serialize(this IDataId dataId, IEnumerable <string> propertyNames) { if (dataId == null) { throw new ArgumentNullException(nameof(dataId)); } var sb = new StringBuilder(); SerializeKeyValuePair(sb, "_dataIdType_", TypeManager.SerializeType(dataId.GetType())); SerializeKeyValuePair(sb, "_dataId_", SerializationFacade.Serialize(dataId, propertyNames)); return(sb.ToString()); }
/// <summary> /// This is for internal use only! /// </summary> public DataSourceId(IDataId dataId, string providerName, Type interfaceType) { if (null == dataId) throw new ArgumentNullException("dataId"); if (string.IsNullOrEmpty(providerName)) throw new ArgumentNullException("providerName"); if (null == interfaceType) throw new ArgumentNullException("interfaceType"); this.DataId = dataId; _providerName = providerName; _interfaceType = interfaceType; _dataScopeIdentifier = DataScopeManager.MapByType(interfaceType); _localeScope = LocalizationScopeManager.MapByType(interfaceType); this.ExistsInStore = true; }
/// <summary> /// This is for internal use only! /// </summary> public DataSourceId(IDataId dataId, string providerName, Type interfaceType, DataScopeIdentifier dataScope, CultureInfo localeScope) { // This constructor has to be extremely fast, we have up to 100.000 objects reated while some requests if (dataId == null) throw new ArgumentNullException("dataId"); if (string.IsNullOrEmpty(providerName)) throw new ArgumentNullException("providerName"); if (interfaceType == null) throw new ArgumentNullException("interfaceType"); if (dataScope == null) throw new ArgumentNullException("dataScope"); if (localeScope == null) throw new ArgumentNullException("localeScope"); this.DataId = dataId; _providerName = providerName; _interfaceType = interfaceType; _dataScopeIdentifier = dataScope; _localeScope = localeScope; this.ExistsInStore = true; }
public object GetKeyValue(IDataId dataId, string keyName) { if (keyName == null) { keyName = this.GetDefaultKeyName(dataId.GetType()); if (keyName == null) throw new InvalidOperationException("Could not find default key for the type: " + dataId.GetType()); } Func<Type, PropertyInfo> valueFactory = f => f.GetProperty(keyName); PropertyInfo keyPropertyInfo = _keyPropertyInfoCache.GetOrAdd(dataId.GetType(), valueFactory); object keyValue = keyPropertyInfo.GetValue(dataId, null); return keyValue; }
/// <exclude /> public override void OnGetPrettyHtml(EntityTokenHtmlPrettyfier prettifier) { prettifier.OnWriteId = (token, helper) => { IDataId dataId = DataIdSerializer.Deserialize(this.Id, this.VersionId); var sb = new StringBuilder(); sb.Append("<b>DataId</b><br />"); sb.Append("<b>Type:</b> " + dataId.GetType() + "<br />"); foreach (PropertyInfo propertyInfo in dataId.GetType().GetPropertiesRecursively()) { sb.Append("<b>" + propertyInfo.Name + ":</b> " + propertyInfo.GetValue(dataId, null).ToString() + "<br />"); } helper.AddFullRow(new [] { "<b>Id</b>", sb.ToString() }); }; }
public static IDataId DeserializeLegacy(string serializedId, string serializedVersionId) { Dictionary <string, string> dataIdValues = ParseKeyValueCollection(serializedId); if (!dataIdValues.ContainsKey("_dataIdType_") || !dataIdValues.ContainsKey("_dataId_")) { throw new ArgumentException("The serializedId is not a serialized id", nameof(serializedId)); } string dataIdType = DeserializeValueString(dataIdValues["_dataIdType_"]); string serializedIdString = DeserializeValueString(dataIdValues["_dataId_"]); string serializedVersionIdString = ""; if (!string.IsNullOrEmpty(serializedVersionId)) { Dictionary <string, string> versionValues = ParseKeyValueCollection(serializedVersionId); if (!versionValues.ContainsKey("_dataIdType_") || !versionValues.ContainsKey("_dataId_")) { throw new ArgumentException("The serializedVersionId is not a serialized version id", nameof(serializedVersionId)); } if (dataIdValues["_dataIdType_"] != versionValues["_dataIdType_"]) { throw new ArgumentException("Serialized id and version id have diffrent types", nameof(serializedId)); } serializedVersionIdString = DeserializeValueString(versionValues["_dataId_"]); } Type type = TypeManager.TryGetType(dataIdType); if (type == null) { throw new InvalidOperationException($"The type {dataIdType} could not be found"); } IDataId dataId = SerializationFacade.Deserialize <IDataId>(type, string.Join("", serializedIdString, serializedVersionIdString)); return(dataId); }
public T GetData <T>(IDataId dataId) where T : class, IData { if (dataId == null) { throw new ArgumentNullException("dataId"); } CheckInterface(typeof(T)); MediaDataId mediaDataId = dataId as MediaDataId; if (mediaDataId == null) { return(null); } if (mediaDataId.MediaType == _folderType) { if (typeof(T) != typeof(IMediaFileFolder)) { throw new ArgumentException("The dataId specifies a IMediaFileFolder, but the generic method was invoked with different type"); } FileSystemMediaFileFolder folder = (from dirInfo in C1Directory.GetDirectories(_rootDir, "*", SearchOption.AllDirectories) where GetRelativePath(dirInfo) == mediaDataId.Path select CreateFolder(dirInfo)).FirstOrDefault(); return(folder as T); } else if (mediaDataId.MediaType == _fileType) { if (typeof(T) != typeof(IMediaFile)) { throw new ArgumentException("The dataId specifies a IMediaFile, but the generic method was invoked with different type"); } FileSystemMediaFile file = (from fileInfo in C1Directory.GetFiles(_rootDir, "*", SearchOption.AllDirectories) where GetRelativePath(Path.GetDirectoryName(fileInfo)) == mediaDataId.Path && Path.GetFileName(fileInfo) == mediaDataId.FileName select CreateFile(fileInfo)).FirstOrDefault(); return(file as T); } else { return(Store as T); } }
T IDataProvider.GetData <T>(IDataId dataId) { var mediaDataId = dataId as MediaDataId; switch (mediaDataId.MediaType) { case MediaElementType.File: return(GetFileList().Where(f => f.Id == mediaDataId.Id).FirstOrDefault() as T); case MediaElementType.Folder: return(GetFolderList().Where(f => f.Id == mediaDataId.Id).FirstOrDefault() as T); case MediaElementType.Store: return(GetStoreList().FirstOrDefault() as T); default: throw new NotImplementedException(); } }
/// <exclude /> public void UpdateDataSourceId(IData data, IDataId dataId, Type interfaceType) { Verify.ArgumentNotNull(data, "data"); Verify.ArgumentNotNull(dataId, "dataId"); Verify.ArgumentNotNull(interfaceType, "interfaceType"); Verify.ArgumentCondition(typeof(IData).IsAssignableFrom(interfaceType), "interfaceType", "The interface type '{0}' does not inherit the interface '{1}'".FormatWith(interfaceType, typeof(IData))); var emptyDataClassBase = data as EmptyDataClassBase; if (emptyDataClassBase == null) { throw new InvalidOperationException("Updates on DataSourceIds can only be done on objects that are returned by the DataFacade.BuildNew<T>() method"); } if (emptyDataClassBase.DataSourceId.ExistsInStore) { throw new InvalidOperationException("Updates on DataSourceIds can only be done once"); } emptyDataClassBase.DataSourceId = CreateDataSourceId(dataId, interfaceType); }
public object GetKeyValue(IDataId dataId, string keyName) { if (keyName == null) { keyName = this.GetDefaultKeyName(dataId.GetType()); if (keyName == null) { throw new InvalidOperationException("Could not find default key for the type: " + dataId.GetType()); } } Func <Type, PropertyInfo> valueFactory = f => f.GetProperty(keyName); PropertyInfo keyPropertyInfo = _keyPropertyInfoCache.GetOrAdd(dataId.GetType(), valueFactory); object keyValue = keyPropertyInfo.GetValue(dataId, null); return(keyValue); }
public T GetData <T>(IDataId dataId) where T : class, IData { Verify.ArgumentNotNull(dataId, "dataId"); using (TimerProfilerFacade.CreateTimerProfiler(string.Format("dataId ({0})", typeof(T)))) { string errorMessage; if (!DataTypeValidationRegistry.IsValidForProvider(typeof(T), _dataProviderContext.ProviderName, out errorMessage)) { throw new InvalidOperationException(errorMessage); } SqlDataTypeStore result = _sqlDataTypeStoresContainer.GetDataTypeStore(typeof(T)); IData data = result.GetDataByDataId(dataId, _dataProviderContext); return((T)data); } }
/// <exclude /> public static void FullCopyTo(this IDataId sourceDataId, IDataId targetDataId) { if (sourceDataId == null) { throw new ArgumentNullException("sourceDataId"); } if (targetDataId == null) { throw new ArgumentNullException("targetDataId"); } foreach (PropertyInfo sourcePropertyInfo in sourceDataId.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) { PropertyInfo targetPropertyInfo = targetDataId.GetType().GetProperty(sourcePropertyInfo.Name, BindingFlags.Public | BindingFlags.Instance); object value = sourcePropertyInfo.GetValue(sourceDataId, null); targetPropertyInfo.SetValue(targetDataId, value, null); } }
/// <exclude /> public void UpdateDataSourceId(IData data, IDataId dataId, Type interfaceType) { Verify.ArgumentNotNull(data, "data"); Verify.ArgumentNotNull(dataId, "dataId"); Verify.ArgumentNotNull(interfaceType, "interfaceType"); Verify.ArgumentCondition(typeof(IData).IsAssignableFrom(interfaceType), "interfaceType", "The interface type '{0}' does not inherit the interface '{1}'".FormatWith(interfaceType, typeof(IData))); var emptyDataClassBase = data as EmptyDataClassBase; if (emptyDataClassBase == null) { throw new InvalidOperationException("Updates on DataSourceIds can only be done on objects that are returned by the DataFacade.BuildNew<T>() method"); } if (emptyDataClassBase.DataSourceId.ExistsInStore) { throw new InvalidOperationException("Updates on DataSourceIds can only be done once"); } emptyDataClassBase.DataSourceId = CreateDataSourceId(dataId, interfaceType); }
/// <exclude /> public static bool CompareTo(this IDataId sourceDataId, IDataId targetDataId, bool throwExceptionOnTypeMismathc) { if (sourceDataId == null) { throw new ArgumentNullException("sourceDataId"); } if (targetDataId == null) { throw new ArgumentNullException("targetDataId"); } if (sourceDataId.GetType() != targetDataId.GetType()) { if (throwExceptionOnTypeMismathc) { throw new ArgumentException(string.Format("Type mismatch {0} and {1}", sourceDataId.GetType(), targetDataId.GetType())); } return(false); } bool equal = true; foreach (PropertyInfo sourcePropertyInfo in sourceDataId.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) { PropertyInfo targetPropertyInfo = targetDataId.GetType().GetProperty(sourcePropertyInfo.Name, BindingFlags.Public | BindingFlags.Instance); object sourceValue = sourcePropertyInfo.GetValue(sourceDataId, null); object targetValue = targetPropertyInfo.GetValue(targetDataId, null); if (object.Equals(sourceValue, targetValue) == false) { equal = false; break; } } return(equal); }
public static IDataId Deserialize(string serializedId, string serializedVersionId) { Dictionary <string, string> dicid = StringConversionServices.ParseKeyValueCollection(serializedId); if ((dicid.ContainsKey("_dataIdType_") == false) || (dicid.ContainsKey("_dataId_") == false)) { throw new ArgumentException("The serializedId is not a serialized id", nameof(serializedId)); } Dictionary <string, string> dicversion = StringConversionServices.ParseKeyValueCollection(serializedVersionId); if ((dicversion.ContainsKey("_dataIdType_") == false) || (dicversion.ContainsKey("_dataId_") == false)) { throw new ArgumentException("The serializedVersionId is not a serialized version id", nameof(serializedVersionId)); } if (dicid["_dataIdType_"] != dicversion["_dataIdType_"]) { throw new ArgumentException("Serialized id and version id have diffrent types", nameof(serializedId)); } string dataIdType = StringConversionServices.DeserializeValueString(dicid["_dataIdType_"]); string serializedIdString = StringConversionServices.DeserializeValueString(dicid["_dataId_"]); string serializedVersionIdString = StringConversionServices.DeserializeValueString(dicversion["_dataId_"]); Type type = TypeManager.TryGetType(dataIdType); if (type == null) { throw new InvalidOperationException(string.Format("The type {0} could not be found", dataIdType)); } IDataId dataId = SerializationFacade.Deserialize <IDataId>(type, string.Join("", serializedIdString, serializedVersionIdString)); return(dataId); }
/// <summary> /// This is for internal use only! /// </summary> public DataSourceId(IDataId dataId, string providerName, Type interfaceType) { if (null == dataId) { throw new ArgumentNullException("dataId"); } if (string.IsNullOrEmpty(providerName)) { throw new ArgumentNullException("providerName"); } if (null == interfaceType) { throw new ArgumentNullException("interfaceType"); } this.DataId = dataId; ProviderName = providerName; InterfaceType = interfaceType; _dataScopeIdentifier = DataScopeManager.MapByType(interfaceType); _localeScope = LocalizationScopeManager.MapByType(interfaceType); this.ExistsInStore = true; }
public static IDataId Deserialize(string serializedDataId) { Dictionary <string, string> dic = StringConversionServices.ParseKeyValueCollection(serializedDataId); if ((dic.ContainsKey("_dataIdType_") == false) || (dic.ContainsKey("_dataId_") == false)) { throw new ArgumentException("The serializedDataId is not a serialized data id", "serializedDataId"); } string dataIdType = StringConversionServices.DeserializeValueString(dic["_dataIdType_"]); string serializedDataIdString = StringConversionServices.DeserializeValueString(dic["_dataId_"]); Type type = TypeManager.TryGetType(dataIdType); if (type == null) { throw new InvalidOperationException(string.Format("The type {0} could not be found", dataIdType)); } IDataId dataId = SerializationFacade.Deserialize <IDataId>(type, serializedDataIdString); return(dataId); }
public T GetData <T>(IDataId dataId) where T : class, IData { if (dataId == null) { throw new ArgumentNullException("dataId"); } XmlDataTypeStore dataTypeStore = _xmlDataTypeStoresContainer.GetDataTypeStore(typeof(T)); var dataTypeStoreScope = dataTypeStore.GetDataScopeForType(typeof(T)); var fileRecord = GetFileRecord(dataTypeStore, dataTypeStoreScope); XElement element = fileRecord.RecordSet.Index[dataId]; if (element == null) { return(null); } Func <XElement, T> selectFun = dataTypeStore.Helper.CreateSelectFunction <T>(_dataProviderContext.ProviderName); return(selectFun(element)); }
public T GetData <T>(IDataId dataId) where T : class, IData { var folderId = dataId as FacebookMediaFolderId; if (folderId != null) { using (var data = new DataConnection(PublicationScope.Published)) { var album = data.Get <IFacebookAlbum>().Single(a => a.Id == folderId.Id); var id = new FacebookMediaFolderId { Id = album.Id }; var dataSourceId = _context.CreateDataSourceId(id, typeof(IMediaFileFolder)); return((new FacebookMediaFolder(album, Store.Id, dataSourceId)) as T); } } var fileId = dataId as FacebookMediaFileId; if (fileId != null) { using (var data = new DataConnection(PublicationScope.Published)) { var photo = data.Get <IFacebookPhoto>().Single(p => p.Id == fileId.Id); var album = data.Get <IFacebookAlbum>().Single(a => a.Id == fileId.AlbumId); var dataSourceId = _context.CreateDataSourceId(new FacebookMediaFileId { Id = photo.Id, AlbumId = album.Id }, typeof(IMediaFile)); return((new FacebookMediaFile(photo, album, Store.Id, dataSourceId)) as T); } } var photoId = dataId as FacebookPhotoId; if (photoId != null) { using (var data = new DataConnection(PublicationScope.Published)) { var album = data.Get <IFacebookAlbum>().SingleOrDefault(a => a.AlbumId == photoId.AlbumId); if (album != null) { var token = album.AccessToken; var client = new FacebookClient(token); dynamic photo = client.Get(photoId.Id); var id = new FacebookPhotoId { Id = photo.Id, AlbumId = album.AlbumId }; var facebookPhoto = new FacebookPhoto(_context.CreateDataSourceId(id, typeof(IFacebookPhoto))) { Id = photo.id, AlbumId = album.AlbumId, Title = photo.name ?? String.Empty }; return(facebookPhoto as T); } } } return(default(T)); }
/// <exclude /> public static bool CompareTo(this IDataId sourceDataId, IDataId targetDataId) { return CompareTo(sourceDataId, targetDataId, false); }
// Overload /// <exclude /> public static string GetDefaultKeyName(IDataId dataId) { return(_implementation.GetDefaultKeyName(dataId.GetType())); }
/// <exclude /> public static object GetKeyValue(IDataId dataId, string keyName = null) { return(_implementation.GetKeyValue(dataId, keyName)); }
// Overload /// <exclude /> public static T GetKeyValue <T>(IDataId dataId, string keyName = null) { return((T)_implementation.GetKeyValue(dataId, keyName)); }
public IData GetDataByDataId(IDataId dataId, DataProviderContext dataProivderContext) { SqlDataTypeStoreTable storage = GetCurrentTable(); return storage.SqlDataProviderHelper.GetDataById(GetQueryable(), dataId, dataProivderContext); }
private static IDataId EnsureDataIdType(IDataId dataId) { // After the new build manager this should always be the right type return dataId; }