コード例 #1
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);
            }
コード例 #2
0
            private void RegisterKeyUsage(DataType dataType, string localeName, DataScopeIdentifier publicationScope, KeyValuePair<string, object> keyValuePair)
            {
                string dataScopeKey = GetDataScopeKey(publicationScope, localeName);

                if (!_dataScopes.ContainsKey(dataScopeKey))
                {
                    _dataScopes.Add(dataScopeKey, new HashSet<KeyValuePair<string, object>>());
                }

                var hashset = _dataScopes[dataScopeKey];

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

                hashset.Add(keyValuePair);
            }
コード例 #3
0
            public void RegisterKeyUsage(DataType dataType, KeyValuePair<string, object> keyValuePair)
            {
                var dataScopeIdentifier = dataType.DataScopeIdentifier;

                if (!_isLocalized)
                {
                    RegisterKeyUsage(dataType, "", dataScopeIdentifier, keyValuePair);
                    return;
                }

                if (dataType.AddToCurrentLocale)
                {
                    RegisterKeyUsage(dataType, LocalizationScopeManager.CurrentLocalizationScope.Name, dataScopeIdentifier, keyValuePair);
                    return;
                }

                if (dataType.Locale != null)
                {
                    RegisterKeyUsage(dataType, dataType.Locale.Name, dataScopeIdentifier, keyValuePair);
                    return;
                }

                if (dataType.AddToAllLocales)
                {
                    RegisterKeyUsage(dataType, AllLocalesKey, dataScopeIdentifier, keyValuePair);
                    return;
                }

                throw new InvalidOperationException("Type is localized but no localization info specified");
            }
コード例 #4
0
            public bool KeyRegistered(DataType refereeDataType, KeyValuePair<string, object> keyValuePair)
            {
                var dataScopeIdentifier = refereeDataType.DataScopeIdentifier;

                if (!_isLocalized)
                {
                    return KeyRegistered(dataScopeIdentifier, "", keyValuePair);
                }

                if (KeyRegistered(refereeDataType.DataScopeIdentifier, AllLocalesKey, keyValuePair))
                {
                    return true;
                }

                if (refereeDataType.Locale != null)
                {
                    return KeyRegistered(refereeDataType.DataScopeIdentifier, refereeDataType.Locale.Name, keyValuePair);
                }

                var currentLocale = LocalizationScopeManager.CurrentLocalizationScope;

                if (refereeDataType.AddToCurrentLocale)
                {
                    return KeyRegistered(refereeDataType.DataScopeIdentifier, currentLocale.Name, keyValuePair);
                }

                if (DataLocalizationFacade.ActiveLocalizationCultures.Count() == 1
                    && KeyRegistered(refereeDataType.DataScopeIdentifier, currentLocale.Name, keyValuePair))
                {
                    return true;
                }

                return false;
            }
コード例 #5
0
        private void CheckForBrokenReference(DataType refereeType, Type type, string propertyName, object propertyValue)
        {
            Type referredType;
            string keyPropertyName;
            object referenceKey;

            MapReference(type, propertyName, propertyValue, out referredType, out keyPropertyName, out referenceKey);

            // Checking key in the keys to be installed
            var keyValuePair = new KeyValuePair<string, object>(keyPropertyName, referenceKey);

            if (_missingDataReferences.ContainsKey(referredType) && _missingDataReferences[referredType].Contains(keyValuePair))
            {
                return;
            }

            if (_dataKeysToBeInstalled.ContainsKey(referredType) && _dataKeysToBeInstalled[referredType].KeyRegistered(refereeType, keyValuePair))
            {
                return;
            }

            using (GetDataScopeFromDataTypeElement(refereeType))
            {
                if (DataFacade.TryGetDataByUniqueKey(type, propertyValue) == null)
                {
                    _validationResult.AddFatal(Texts.DataPackageFragmentInstaller_ReferencedDataMissing(
                        type.FullName, propertyName, propertyValue));

                    var missingReferences = _missingDataReferences.GetOrAdd(referredType,
                        () => new HashSet<KeyValuePair<string, object>>());

                    missingReferences.Add(keyValuePair);
                }
            }
        }
コード例 #6
0
        internal static void ReinitializeTheSystem(RunInWriterLockScopeDelegate runInWriterLockScopeDelegate, bool initializeHooksInTheSameThread)
        {
            if (_hookingFacadeThread != null)
            {
                _hookingFacadeThread.Join(TimeSpan.FromSeconds(30));
                if (_hookingFacadeException != null)
                {
                    throw new InvalidOperationException("The initialization of the HookingFacade failed before this reinitialization was issued", _hookingFacadeException);
                }
            }

            using (GlobalInitializerFacade.CoreLockScope)
            {
                IsReinitializingTheSystem = true;

                runInWriterLockScopeDelegate();

                _coreInitialized = false;
                _initializing = false;
                _exceptionThrownDuringInitialization = null;

                Verify.That(_fatalErrorFlushCount <= 1, "Failed to reload the system. See the log for the details.");

                InitializeTheSystem();

                if (!SystemSetupFacade.SetupIsRunning)
                {
                    // Updating "hooks" either in the same thread, or in another
                    if (initializeHooksInTheSameThread)
                    {
                        object threadStartParameter = new KeyValuePair<TimeSpan, StackTrace>(TimeSpan.Zero, new StackTrace());
                        EnsureHookingFacade(threadStartParameter);
                    }
                    else
                    {
                        _hookingFacadeThread = new Thread(EnsureHookingFacade) {Name = "EnsureHookingFacade"};
                        _hookingFacadeThread.Start(new KeyValuePair<TimeSpan, StackTrace>(TimeSpan.FromSeconds(1), new StackTrace()));
                    }
                }

                IsReinitializingTheSystem = false;
            }
        }
コード例 #7
0
        private static void GetLabelVisualizationMethodInfo(IData data, bool useForeignLabel, out MethodInfo methodInfo, out string propertyName, out string undefinedLabelValue)
        {
            using (_resourceLocker.Locker)
            {
                undefinedLabelValue = _resourceLocker.Resources.UndefinedLableValue;

                KeyValuePair<MethodInfo, string> cachedValue;

                if (_resourceLocker.Resources.InterfaceTypeToLabelMethodInfoCache.TryGetValue(data.DataSourceId.InterfaceType, out cachedValue))
                {
                    methodInfo = cachedValue.Key;
                    propertyName = cachedValue.Value;
                    return;
                }

                PropertyInfo propertyInfo = GetLabelPropertyInfo(data);
                propertyName = null;

                if (useForeignLabel)
                {
                    List<ForeignKeyAttribute> foreignKeyAttributes = propertyInfo.GetCustomAttributesRecursively<ForeignKeyAttribute>().ToList();
                    if (foreignKeyAttributes.Count > 0)
                    {
                        propertyName = propertyInfo.Name;

                        IData foreignData = data.GetReferenced(propertyInfo.Name);

                        if (foreignData == null)
                        {
                            undefinedLabelValue = string.Format(undefinedLabelValue, propertyInfo.Name);
                            methodInfo = null;
                            return;
                        }

                        propertyInfo = GetLabelPropertyInfo(foreignData);
                    }
                }

                methodInfo = propertyInfo.GetGetMethod();

                var cacheEntry = new KeyValuePair<MethodInfo, string>(methodInfo, propertyName);
                _resourceLocker.Resources.InterfaceTypeToLabelMethodInfoCache.Add(data.DataSourceId.InterfaceType, cacheEntry);
            }
        }