private void DropStore(DataTypeDescriptor dataTypeDescriptor, DataScopeIdentifier dataScope, CultureInfo cultureInfo)
        {
            string tableName = GetConfiguredTableName(dataTypeDescriptor, dataScope, cultureInfo.Name);

            if (string.IsNullOrEmpty(tableName))
            {
                return;
            }

            try
            {
                var tables = GetTablesList();

                if (tables.Contains(tableName))
                {
                    ExecuteNonQuery(string.Format("DROP TABLE [{0}];", tableName));

                    SqlTableInformationStore.ClearCache(_connectionString, tableName);
                }
            }
            catch (Exception ex)
            {
                throw MakeVerboseException(ex);
            }
        }
Exemple #2
0
        public XmlDataTypeStoreDataScope GetDataScope(DataScopeIdentifier dataScope, CultureInfo culture, Type type)
        {
            string dataScopeName = dataScope.Name;

            Verify.That(HasDataScopeName(dataScope), "The store named '{0}' is not supported for data type '{1}'", dataScopeName, type);

            string cultureName = culture.Name;

            XmlDataTypeStoreDataScope dateTypeStoreDataScope =
                _xmlDateTypeStoreDataScopes.SingleOrDefault(f => f.DataScopeName == dataScopeName && f.CultureName == cultureName);

            if (dateTypeStoreDataScope == null)
            {
                if (culture.Equals(CultureInfo.InvariantCulture) && DataLocalizationFacade.IsLocalized(type))
                {
                    throw new InvalidOperationException("Failed to get data for type '{0}', no localization scope is provided for a localized type."
                                                        .FormatWith(type.FullName));
                }

                throw new InvalidOperationException("Failed to get '{0}' data for data scope ({1}, {2})"
                                                    .FormatWith(type.FullName, dataScopeName, culture.Equals(CultureInfo.InvariantCulture) ? "invariant" : cultureName));
            }

            return(dateTypeStoreDataScope);
        }
Exemple #3
0
        /// <exclude />
        internal static IQueryable <T> GetDataFromCache <T>(Func <IQueryable <T> > getQueryFunc)
            where T : class, IData
        {
            Verify.That(_isEnabled, "The cache is disabled.");

            DataScopeIdentifier dataScopeIdentifier = DataScopeManager.MapByType(typeof(T));
            CultureInfo         localizationScope   = LocalizationScopeManager.MapByType(typeof(T));

            var typeData = _cachedData.GetOrAdd(typeof(T), t => new TypeData());

            var dataScopeData = typeData.GetOrAdd(dataScopeIdentifier, scope => new ConcurrentDictionary <CultureInfo, CachedTable>());


            CachedTable cachedTable;

            if (!dataScopeData.TryGetValue(localizationScope, out cachedTable))
            {
                IQueryable <T> wholeTable = getQueryFunc();

                if (!DataProvidersSupportDataWrapping(typeof(T)))
                {
                    DisableCachingForType(typeof(T));

                    return(Verify.ResultNotNull(wholeTable));
                }

                if (_maximumSize != -1)
                {
                    List <IData> cuttedTable = TakeElements(wholeTable, _maximumSize + 1);
                    if (cuttedTable.Count > _maximumSize)
                    {
                        DisableCachingForType(typeof(T));

                        return(Verify.ResultNotNull(wholeTable));
                    }
                    cachedTable = new CachedTable(cuttedTable.Cast <T>().AsQueryable());
                }
                else
                {
                    cachedTable = new CachedTable(wholeTable.Evaluate().AsQueryable());
                }

                dataScopeData[localizationScope] = cachedTable;
            }

            var typedData = cachedTable.Queryable as IQueryable <T>;

            Verify.IsNotNull(typedData, "Cached value is invalid.");

            // Leaving a possibility to extract original query
            Func <IQueryable> originalQueryGetter = () =>
            {
                using (new DataScope(dataScopeIdentifier, localizationScope))
                {
                    return(getQueryFunc());
                }
            };

            return(new CachingQueryable <T>(cachedTable, originalQueryGetter));
        }
 private void CreateScopeData(DataTypeDescriptor typeDescriptor, DataScopeIdentifier dataScope)
 {
     foreach (var cultureInfo in GetCultures(typeDescriptor))
     {
         CreateStore(typeDescriptor, dataScope, cultureInfo);
     }
 }
Exemple #5
0
            private string GetDataScopeKey(DataScopeIdentifier publicationScope, string languageName)
            {
                string publicationScopeKey = _isPublishable ? publicationScope.Name : string.Empty;
                string languageScopeKey    = _isLocalized ? languageName : string.Empty;

                return(publicationScopeKey + languageScopeKey);
            }
        private void CheckForPotentialBrokenReferences(IData data, List <PackageFragmentValidationResult> validationResult,
                                                       Type type, DataScopeIdentifier dataScopeIdentifier, CultureInfo locale, DataKeyPropertyCollection dataKeyPropertyCollection)
        {
            var pagesReferencingPageTypes          = new HashSet <string>();
            var dataReferencingDataToBeUninstalled = new HashSet <string>();

            List <IData> referees = data.GetReferees();

            bool addToDelete = true;

            foreach (IData referee in referees)
            {
                if (this.UninstallerContext.IsPendingForDeletionData(referee))
                {
                    continue;
                }

                addToDelete = false;

                if (referee is IPage && data is IPageType)
                {
                    string pathToPage;

                    using (new DataScope(referee.DataSourceId.PublicationScope, referee.DataSourceId.LocaleScope))
                    {
                        pathToPage = GetPathToPage(referee as IPage);
                    }

                    if (!pagesReferencingPageTypes.Contains(pathToPage))
                    {
                        validationResult.AddFatal(Texts.DataPackageFragmentUninstaller_PageTypeIsReferenced(
                                                      data.GetLabel(), pathToPage));
                        pagesReferencingPageTypes.Add(pathToPage);
                    }
                }
                else
                {
                    var refereeType = referee.DataSourceId.InterfaceType;

                    string label = referee.GetLabel();
                    string key   = label + refereeType.FullName;

                    if (!dataReferencingDataToBeUninstalled.Contains(key))
                    {
                        validationResult.AddFatal(Texts.DataPackageFragmentUninstaller_DataIsReferenced(
                                                      data.GetLabel(),
                                                      type.FullName,
                                                      label,
                                                      refereeType.FullName));

                        dataReferencingDataToBeUninstalled.Add(key);
                    }
                }
            }

            if (addToDelete)
            {
                AddDataToDelete(type, dataScopeIdentifier, locale, dataKeyPropertyCollection);
            }
        }
 public static Dictionary<Guid, string> GetIdToUrlLookup(string dataScopeIdentifier, CultureInfo culture)
 {
     using (new DataScope(DataScopeIdentifier.Deserialize(dataScopeIdentifier), culture))
     {
         return GetMap().IdToUrlLookup;
     }
 }
        /// <summary>
        /// Flush cached data for a data type in the specified data scope.
        /// </summary>
        /// <param name="interfaceType">The type of data to flush from the cache</param>
        /// <param name="dataScopeIdentifier">The data scope to flush</param>
        public static void ClearCache(Type interfaceType, DataScopeIdentifier dataScopeIdentifier)
        {
            using (_resourceLocker.Locker)
            {
                var cachedData = _resourceLocker.Resources.CachedData;

                if (!cachedData.ContainsKey(interfaceType))
                {
                    return;
                }

                if (dataScopeIdentifier == null)
                {
                    dataScopeIdentifier = DataScopeManager.MapByType(interfaceType);
                }

                if (cachedData[interfaceType].ContainsKey(dataScopeIdentifier))
                {
                    cachedData[interfaceType].Remove(dataScopeIdentifier);

                    if (cachedData[interfaceType].Count == 0)
                    {
                        cachedData.Remove(interfaceType);
                    }
                }
            }
        }
 private void DropScopeData(DataTypeDescriptor typeDescriptor, DataScopeIdentifier dataScope)
 {
     foreach (var culture in GetCultures(typeDescriptor))
     {
         DropStore(typeDescriptor, dataScope, culture);
     }
 }
        public XmlDataTypeStore(DataTypeDescriptor dataTypeDescriptor, Type dataProviderHelperType, Type dataIdClassType, IEnumerable <XmlDataTypeStoreDataScope> xmlDateTypeStoreDataScopes, bool isGeneratedDataType)
        {
            DataTypeDescriptor     = dataTypeDescriptor ?? throw new ArgumentNullException(nameof(dataTypeDescriptor));
            DataProviderHelperType = dataProviderHelperType ?? throw new ArgumentNullException(nameof(dataProviderHelperType));
            DataIdClassType        = dataIdClassType ?? throw new ArgumentNullException(nameof(dataIdClassType));
            IsGeneratedDataType    = isGeneratedDataType;

            _xmlDateTypeStoreDataScopes = xmlDateTypeStoreDataScopes.Evaluate();

            var ordering = new List <Func <XElement, IComparable> >();

            foreach (string key in dataTypeDescriptor.KeyPropertyNames)
            {
                XName localKey = key;
                ordering.Add(f => (string)f.Attribute(localKey) ?? "");
            }
            Func <IEnumerable <XElement>, IOrderedEnumerable <XElement> > orderer = f => ordering.Skip(1).Aggregate(f.OrderBy(ordering.First()), Enumerable.ThenBy);

            foreach (XmlDataTypeStoreDataScope xmlDataTypeStoreDataScope in _xmlDateTypeStoreDataScopes)
            {
                DataScopeIdentifier dataScopeIdentifier = DataScopeIdentifier.Deserialize(xmlDataTypeStoreDataScope.DataScopeName);
                CultureInfo         culture             = CultureInfo.CreateSpecificCulture(xmlDataTypeStoreDataScope.CultureName);
                Type dataType = dataTypeDescriptor.GetInterfaceType();

                Action cacheFlush = () => DataEventSystemFacade.FireExternalStoreChangedEvent(dataType, dataScopeIdentifier.ToPublicationScope(), culture);
                XmlDataProviderDocumentCache.RegisterExternalFileChangeAction(xmlDataTypeStoreDataScope.Filename, cacheFlush);

                XmlDataProviderDocumentWriter.RegisterFileOrderer(xmlDataTypeStoreDataScope.Filename, orderer);
            }
        }
        internal static string MakeFileName(DataTypeDescriptor dataTypeDescriptor, DataScopeIdentifier dataScopeIdentifier, string cultureName)
        {
            string typeFullName = StringExtensionMethods.CreateNamespace(dataTypeDescriptor.Namespace, dataTypeDescriptor.Name, '.');

            string publicationScopePart = "";

            switch (dataScopeIdentifier.Name)
            {
            case DataScopeIdentifier.PublicName:
                break;

            case DataScopeIdentifier.AdministratedName:
                publicationScopePart = "_" + PublicationScope.Unpublished;
                break;

            default:
                throw new InvalidOperationException($"Unsupported data scope identifier: '{dataScopeIdentifier.Name}'");
            }

            string cultureNamePart = "";

            if (cultureName != "")
            {
                cultureNamePart = "_" + cultureName;
            }

            return(typeFullName + publicationScopePart + cultureNamePart + ".xml");
        }
        /// <exclude />
        public Func <XElement, T> CreateSelectFunction <T>(string providerName) where T : IData
        {
            Type type = typeof(T);

            var cache = _selectFunctionCache[typeof(T)];

            if (cache == null)
            {
                lock (_selectFunctionCache)
                {
                    cache = _selectFunctionCache[type];

                    if (cache == null)
                    {
                        cache = new Hashtable <string, Delegate>();
                        _selectFunctionCache.Add(type, cache);
                    }
                }
            }

            CultureInfo         cultureInfo         = LocalizationScopeManager.MapByType(type);
            DataScopeIdentifier dataScopeIdentifier = DataScopeManager.MapByType(type);

            string cacheKey = cultureInfo + "|" + dataScopeIdentifier.Name;

            Delegate result = cache[cacheKey];

            if (result == null)
            {
                lock (this)
                {
                    result = cache[cacheKey];
                    if (result == null)
                    {
                        // element => new [WrapperClass](element, new DataSourceId(new [DataIdClass](element), providerName, type, dataScope, localizationScope)), element
                        ParameterExpression parameterExpression = Expression.Parameter(typeof(XElement), "element");
                        result = Expression.Lambda <Func <XElement, T> >(
                            Expression.New(_wrapperClassConstructor,
                                           new Expression[]
                        {
                            parameterExpression,
                            Expression.New(GeneretedClassesMethodCache.DataSourceIdConstructor2,
                                           new Expression[]
                            {
                                Expression.New(_idClassConstructor, new Expression[] { parameterExpression }),
                                Expression.Constant(providerName, typeof(string)),
                                Expression.Constant(type, typeof(Type)),
                                Expression.Constant(dataScopeIdentifier, typeof(DataScopeIdentifier)),
                                Expression.Constant(cultureInfo, typeof(CultureInfo))
                            })
                        }), new[] { parameterExpression }).Compile();
                        cache.Add(cacheKey, result);
                    }
                }
            }
            return((Func <XElement, T>)result);
        }
        /// <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));
        }
Exemple #14
0
 internal void AddData(Type type, DataScopeIdentifier dataScopeIdentifier, Func <IData, bool> where)
 {
     using (new DataScope(dataScopeIdentifier))
     {
         foreach (var data in DataFacade.GetData(type).ToDataEnumerable().Where(where).OrderBy(d => d.GetSelfPosition()))
         {
             AddData(data);
         }
     }
 }
        /// <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);
        }
Exemple #16
0
        /// <exclude />
        public bool IsPendingForDeletionData(Type interfaceType, DataScopeIdentifier dataScopeIdentifier, CultureInfo locale, DataKeyPropertyCollection dataKeyPropertyCollection)
        {
            Verify.ArgumentNotNull(interfaceType, "interfaceType");
            Verify.ArgumentNotNull(dataScopeIdentifier, "dataScopeIdentifier");
            Verify.ArgumentNotNull(dataKeyPropertyCollection, "dataKeyPropertyCollection");

            List <DataKeyPropertyCollection> dataKeyPropertyCollections = GetDataKeyPropertyCollection(interfaceType, dataScopeIdentifier, locale);

            return(dataKeyPropertyCollections.Contains(dataKeyPropertyCollection));
        }
Exemple #17
0
            private void RegisterKeyUsage(DataType dataType, string localeName, DataScopeIdentifier publicationScope, KeyValuePair <string, object> keyValuePair)
            {
                string dataScopeKey = GetDataScopeKey(publicationScope, localeName);

                var hashset = _dataScopes.GetOrAdd(dataScopeKey, () => new HashSet <KeyValuePair <string, object> >());

                Verify.That(!hashset.Contains(keyValuePair), "Item with the same key present twice. Data type: '{0}', field '{1}', value '{2}'",
                            dataType.InterfaceTypeName ?? dataType.InterfaceTypeName ?? "null", keyValuePair.Key, keyValuePair.Value ?? "null");

                hashset.Add(keyValuePair);
            }
        internal void AddData(Type type, DataScopeIdentifier dataScopeIdentifier, Func <IData, bool> where)
        {
            using (var conn = new DataConnection(dataScopeIdentifier.ToPublicationScope()))
            {
                conn.DisableServices();

                foreach (var data in DataFacade.GetData(type).ToDataEnumerable().Where(where).OrderBy(d => d.GetSelfPosition()))
                {
                    AddData(data);
                }
            }
        }
        public static PageUrlOptions ParsePublicUrl(string url, out NameValueCollection notUsedQueryParameters)
        {
            var urlString = new UrlString(url);

            notUsedQueryParameters = null;
            if (!IsPublicUrl(urlString.FilePath))
            {
                return(null);
            }

            string requestPath;
            Uri    uri;

            if (Uri.TryCreate(urlString.FilePath, UriKind.Absolute, out uri))
            {
                requestPath = HttpUtility.UrlDecode(uri.AbsolutePath).ToLower();
            }
            else
            {
                requestPath = urlString.FilePath.ToLower();
            }

            string      requestPathWithoutUrlMappingName;
            CultureInfo locale = PageUrl.GetCultureInfo(requestPath, out requestPathWithoutUrlMappingName);

            if (locale == null)
            {
                return(null);
            }

            string dataScopeName = urlString["dataScope"];

            if (dataScopeName.IsNullOrEmpty())
            {
                dataScopeName = DataScopeIdentifier.GetDefault().Name;
            }

            Guid pageId = Guid.Empty;

            using (new DataScope(DataScopeIdentifier.Deserialize(dataScopeName), locale))
            {
                if (PageStructureInfo.GetLowerCaseUrlToIdLookup().TryGetValue(requestPath.ToLower(), out pageId) == false)
                {
                    return(null);
                }
            }

            urlString["dataScope"] = null;

            notUsedQueryParameters = urlString.GetQueryParameters();

            return(new PageUrlOptions(dataScopeName, locale, pageId, UrlType.Public));
        }
        private Dictionary <string, List <CategoryPage> > GetCategoryMap(DataScopeIdentifier scope, CultureInfo cultureInfo)
        {
            var cacheKey = new CacheKey(CacheConfigurationCategoryNames.CategoryUrls, $"map_{scope.Name}", cultureInfo);

            return(CacheProvider.GetOrAdd(cacheKey, () =>
            {
                using (new DataConnection(scope.ToPublicationScope(), cultureInfo))
                {
                    return DataFacade.GetData <CategoryPage>()
                    .GroupBy(_ => _.CategoryId)
                    .ToDictionary(_ => _.Key, _ => _.ToList());
                }
            }));
        }
Exemple #21
0
            public ThreadWrapper(Action <TSource> body, ThreadDataManagerData parentData)
            {
                _body       = body;
                _parentData = parentData;

                _parentThreadLocale      = LocalizationScopeManager.CurrentLocalizationScope;
                _parentThreadDataScope   = DataScopeManager.CurrentDataScope;
                _parentThreadHttpContext = HttpContext.Current;

                var currentThread = System.Threading.Thread.CurrentThread;

                _parentThreadCulture   = currentThread.CurrentCulture;
                _parentThreadUiCulture = currentThread.CurrentUICulture;
            }
Exemple #22
0
        /// <exclude />
        public void AddPendingForDeletionData(Type interfaceType, DataScopeIdentifier dataScopeIdentifier, CultureInfo locale, DataKeyPropertyCollection dataKeyPropertyCollection)
        {
            Verify.ArgumentNotNull(interfaceType, "interfaceType");
            Verify.ArgumentNotNull(dataScopeIdentifier, "dataScopeIdentifier");
            Verify.ArgumentNotNull(dataKeyPropertyCollection, "dataKeyPropertyCollection");

            List <DataKeyPropertyCollection> dataKeyPropertyCollections = GetDataKeyPropertyCollection(interfaceType, dataScopeIdentifier, locale);

            if (dataKeyPropertyCollections.Contains(dataKeyPropertyCollection))
            {
                throw new ArgumentException(string.Format("The data item of type '{0}' with the key '{1}' has already been added", interfaceType, dataKeyPropertyCollection));
            }

            dataKeyPropertyCollections.Add(dataKeyPropertyCollection);
        }
        public static bool TryParseFriendlyUrl(string relativeUrl, out PageUrlOptions urlOptions)
        {
            if (IsAdminPath(relativeUrl))
            {
                urlOptions = null;
                return(false);
            }

            string      path;
            CultureInfo cultureInfo = PageUrl.GetCultureInfo(relativeUrl, out path);

            if (cultureInfo == null)
            {
                urlOptions = null;
                return(false);
            }

            string loweredRelativeUrl = relativeUrl.ToLower(CultureInfo.InvariantCulture);

            // Getting the site map
            IEnumerable <XElement> siteMap;
            DataScopeIdentifier    dataScope = DataScopeIdentifier.GetDefault();

            using (new DataScope(dataScope, cultureInfo))
            {
                siteMap = PageStructureInfo.GetSiteMap();
            }

            XAttribute matchingAttributeNode = siteMap.DescendantsAndSelf()
                                               .Attributes("FriendlyUrl")
                                               .FirstOrDefault(f => string.Equals(f.Value, loweredRelativeUrl, StringComparison.OrdinalIgnoreCase));

            if (matchingAttributeNode == null)
            {
                urlOptions = null;
                return(false);
            }

            XElement pageNode = matchingAttributeNode.Parent;

            XAttribute pageIdAttr = pageNode.Attributes("Id").FirstOrDefault();

            Verify.IsNotNull(pageIdAttr, "Failed to get 'Id' attribute from the site map");
            Guid pageId = new Guid(pageIdAttr.Value);

            urlOptions = new PageUrlOptions(dataScope.Name, cultureInfo, pageId, UrlType.Friendly);
            return(true);
        }
        private static void IncreaseTableVersion(Type type, DataScopeIdentifier dataScopeIdentifier, CultureInfo locale)
        {
            string key = GetKey(type, dataScopeIdentifier, locale);

            lock (_versionNumbers)
            {
                if (_versionNumbers.ContainsKey(key))
                {
                    _versionNumbers[key].Value++;
                }
                else
                {
                    _versionNumbers.Add(key, 1);
                }
            }
        }
Exemple #25
0
        private static void IncreaseTableVersion(Type type, DataScopeIdentifier dataScopeIdentifier, CultureInfo locale)
        {
            string key =  GetKey(type, dataScopeIdentifier, locale);

            lock (_versionNumbers)
            {
                if (_versionNumbers.ContainsKey(key))
                {
                    _versionNumbers[key].Value++;
                }
                else
                {
                    _versionNumbers.Add(key, 1);
                }
            }
        }
Exemple #26
0
            private bool KeyRegistered(DataScopeIdentifier publicationScope, string languageName, KeyValuePair <string, object> keyValuePair)
            {
                HashSet <KeyValuePair <string, object> > hashset;

                if (languageName != AllLocalesKey && _isLocalized)
                {
                    hashset = GetDataset(publicationScope, languageName);
                    if (hashset != null && hashset.Contains(keyValuePair))
                    {
                        return(true);
                    }
                }

                hashset = GetDataset(publicationScope, AllLocalesKey);
                return(hashset != null && hashset.Contains(keyValuePair));
            }
        internal static void ClearCache(Type interfaceType, DataScopeIdentifier dataScopeIdentifier, CultureInfo localizationScope)
        {
            if (!_cachedData.TryGetValue(interfaceType, out TypeData typeData))
            {
                return;
            }

            dataScopeIdentifier = dataScopeIdentifier ?? DataScopeManager.MapByType(interfaceType);
            localizationScope   = !DataLocalizationFacade.IsLocalized(interfaceType)
                ? CultureInfo.InvariantCulture
                : (localizationScope ?? LocalizationScopeManager.CurrentLocalizationScope);

            var key = new Tuple <DataScopeIdentifier, CultureInfo>(dataScopeIdentifier, localizationScope);

            typeData.TryRemove(key, out _);
        }
Exemple #28
0
        internal static void ClearCache(Type interfaceType, DataScopeIdentifier dataScopeIdentifier, CultureInfo localizationScope)
        {
            TypeData typeData;

            if (!_cachedData.TryGetValue(interfaceType, out typeData))
            {
                return;
            }

            dataScopeIdentifier = dataScopeIdentifier ?? DataScopeManager.MapByType(interfaceType);
            localizationScope   = localizationScope ?? LocalizationScopeManager.MapByType(interfaceType);

            var key = new Tuple <DataScopeIdentifier, CultureInfo>(dataScopeIdentifier, localizationScope);

            CachedTable value;

            typeData.TryRemove(key, out value);
        }
        private string GetConfiguredTableName(DataTypeDescriptor dataTypeDescriptor, DataScopeIdentifier dataScope, string cultureName)
        {
            var stores =
                (from dataInterface in _generatedInterfaces
                 where dataInterface.DataTypeId == dataTypeDescriptor.DataTypeId
                 select dataInterface.Stores).FirstOrDefault();

            if (stores == null)
            {
                return(null);
            }

            var tableName = (from store in stores
                             where store.CultureName == cultureName && store.DataScope == dataScope.Name
                             select store.TableName).FirstOrDefault();

            return(tableName);
        }
Exemple #30
0
        /// <summary>
        /// Flush cached data for a data type in the specified data scope.
        /// </summary>
        /// <param name="interfaceType">The type of data to flush from the cache</param>
        /// <param name="dataScopeIdentifier">The data scope to flush</param>
        public static void ClearCache(Type interfaceType, DataScopeIdentifier dataScopeIdentifier)
        {
            TypeData typeData;

            if (!_cachedData.TryGetValue(interfaceType, out typeData))
            {
                return;
            }

            if (dataScopeIdentifier == null)
            {
                dataScopeIdentifier = DataScopeManager.MapByType(interfaceType);
            }

            ConcurrentDictionary <CultureInfo, CachedTable> data;

            typeData.TryRemove(dataScopeIdentifier, out data);
        }
        private void AddDataToDelete(Type interfaceType, DataScopeIdentifier dataScopeIdentifier, CultureInfo locale, DataKeyPropertyCollection dataKeyPropertyCollection)
        {
            DataType dataType = _dataToDelete.SingleOrDefault(dt =>
                                                              dt.InterfaceType == interfaceType &&
                                                              dt.DataScopeIdentifier.Equals(dataScopeIdentifier) &&
                                                              ((dt.Locale == null && locale == null) || (dt.Locale != null && dt.Locale.Equals(locale))));

            if (dataType == null)
            {
                dataType = new DataType {
                    InterfaceType = interfaceType, DataScopeIdentifier = dataScopeIdentifier, Locale = locale
                };
                _dataToDelete.Add(dataType);
            }

            dataType.DataKeys.Add(dataKeyPropertyCollection);
            this.UninstallerContext.AddPendingForDeletionData(interfaceType, dataScopeIdentifier, locale, dataKeyPropertyCollection);
        }
        /// <summary>
        /// Flush cached data for a data type in the specified data scope.
        /// </summary>
        /// <param name="interfaceType">The type of data to flush from the cache</param>
        /// <param name="dataScopeIdentifier">The data scope to flush</param>
        public static void ClearCache(Type interfaceType, DataScopeIdentifier dataScopeIdentifier)
        {
            TypeData typeData;

            if (!_cachedData.TryGetValue(interfaceType, out typeData))
            {
                return;
            }

            dataScopeIdentifier = dataScopeIdentifier ?? DataScopeManager.MapByType(interfaceType);

            var toRemove = typeData.Keys.Where(key => key.Item1 == dataScopeIdentifier).ToList();

            foreach (var key in toRemove)
            {
                CachedTable value;
                typeData.TryRemove(key, out value);
            }
        }
Exemple #33
0
 private static string GetKey(Type type, DataScopeIdentifier dataScopeIdentifier, CultureInfo cultureInfo)
 {
     return type.FullName + " " + dataScopeIdentifier.Name + " " + cultureInfo.Name;
 }