public static ScopeConfiguration FromScopeStorage(ScopeStorage scopeStorage) { ScopeConfiguration scopeConfiguration = new ScopeConfiguration(scopeStorage.OrganizationalUnitRoot.ObjectGuid, scopeStorage.Id.ObjectGuid); UnifiedPolicyStorageFactory.CopyPropertiesFromStorage <ScopeConfiguration>(scopeConfiguration, new TenantSettingFacade <ScopeStorage>(scopeStorage)); return(scopeConfiguration); }
public override void ExecutePageHierarchy() { using (ScopeStorage.CreateTransientScope(new ScopeStorageDictionary(ScopeStorage.CurrentScope, PageData))) { ExecutePageHierarchy(_executors); } }
private static ScopeStorage ScopeStorageFromString(string scopeStorageString, ExPolicyConfigProvider policyConfigProvider) { if (!string.IsNullOrEmpty(scopeStorageString)) { Guid empty = Guid.Empty; Mode mode = Mode.Enforce; Guid empty2 = Guid.Empty; string[] array = scopeStorageString.Split(new char[] { ',' }, 5); if (array.Length == 5 && Guid.TryParse(array[0], out empty) && Enum.TryParse <Mode>(array[1], out mode) && Guid.TryParse(array[2], out empty2) && !string.IsNullOrEmpty(array[3]) && !string.IsNullOrEmpty(array[4])) { ScopeStorage scopeStorage = new ScopeStorage(); scopeStorage.SetId(PolicyStorage.PoliciesContainer.GetChildId(empty.ToString())); scopeStorage.Name = array[3]; scopeStorage.MasterIdentity = empty; scopeStorage.PolicyVersion = empty2; scopeStorage.Mode = mode; scopeStorage.Scope = array[4]; scopeStorage.ResetChangeTracking(true); return(scopeStorage); } } policyConfigProvider.LogOneEntry(ExecutionLog.EventType.CriticalError, "Convert string to scope storage", new FormatException(string.Format("'{0}' is not valid for scope storage.", scopeStorageString))); return(null); }
public BindingStorage ToBindingStorage(ExPolicyConfigProvider policyConfigProvider) { ArgumentValidator.ThrowIfNull("policyConfigProvider", policyConfigProvider); BindingStorage bindingStorage = new BindingStorage(); bindingStorage.SetId(PolicyStorage.PoliciesContainer.GetChildId(this.Name)); bindingStorage.Name = this.Name; bindingStorage.MasterIdentity = this.MasterIdentity; bindingStorage.PolicyId = this.PolicyId; bindingStorage.Workload = this.Workload; bindingStorage.PolicyVersion = this.PolicyVersion; foreach (string scopeStorageString in this.RawAppliedScopes) { ScopeStorage scopeStorage = ExBindingStoreObject.ScopeStorageFromString(scopeStorageString, policyConfigProvider); if (scopeStorage != null) { bindingStorage.AppliedScopes.Add(scopeStorage); } } if (this.WhenChanged != null) { bindingStorage.propertyBag.SetField(ADObjectSchema.WhenChangedRaw, ADValueConvertor.ConvertValueToString(this.WhenChanged.Value, null)); } if (this.WhenCreated != null) { bindingStorage.propertyBag.SetField(ADObjectSchema.WhenCreatedRaw, ADValueConvertor.ConvertValueToString(this.WhenCreated.Value, null)); } bindingStorage.ResetChangeTracking(true); bindingStorage.RawObject = this; return(bindingStorage); }
public void LoadInfo(ScopeStorage scope) { Dictionary <string, AType> functions = ExtractFunctions(scope); foreach (KeyValuePair <string, AType> function in functions) { AFunc func = function.Value.Data as AFunc; if (func.Valence <= 1) { // skip the niladic functions continue; } if (func.IsOperator) { if (func.IsDyadic) { this.dyadicOperators.Add(function.Key); } else { this.monadicOperators.Add(function.Key); } } else { this.globalFunctions.Add(function.Key); } } }
public override dynamic ScopeGetVariable(Scope scope, string name) { string[] contextParts = Util.SplitUserName(name); ScopeStorage storage = base.ScopeGetVariable <ScopeStorage>(scope, contextParts[0]); return(storage.GetValue(contextParts[1], false)); }
private static ScopeStorage ToStorageScope(PolicyBindingConfig bindingScope, ADObjectId organizationalUnitRoot) { ScopeStorage scopeStorage = new ScopeStorage(); scopeStorage[ADObjectSchema.OrganizationalUnitRoot] = organizationalUnitRoot; scopeStorage.SetId(new ADObjectId(PolicyStorage.PoliciesContainer.GetChildId(bindingScope.Identity.ToString()).DistinguishedName, bindingScope.Identity)); scopeStorage.MasterIdentity = bindingScope.Identity; PolicyConfigConverterTable.UpdateStorageScope(scopeStorage, bindingScope); return(scopeStorage); }
private static void UpdateStorageScope(ScopeStorage storageScope, PolicyBindingConfig bindingScope) { storageScope.Name = bindingScope.Name; if (storageScope.Mode != bindingScope.Mode) { storageScope.Mode = bindingScope.Mode; } storageScope.Scope = BindingMetadata.ToStorage(bindingScope.Scope); storageScope.PolicyVersion = ((bindingScope.Version != null) ? bindingScope.Version.InternalStorage : Guid.Empty); }
public static ScopeStorage ToScopeStorage(ScopeConfiguration scope) { ScopeStorage scopeStorage = new ScopeStorage(); scopeStorage[ADObjectSchema.OrganizationalUnitRoot] = new ADObjectId(scope.TenantId); scopeStorage.Name = scope.Name; scopeStorage.SetId((ADObjectId)DalHelper.ConvertFromStoreObject(scope.ObjectId, typeof(ADObjectId))); UnifiedPolicyStorageFactory.CopyPropertiesToStorage <ScopeConfiguration>(new TenantSettingFacade <ScopeStorage>(scopeStorage), scope); return(scopeStorage); }
private static string ScopeStorageToString(ScopeStorage scopeStorage) { return(string.Format("{0},{1},{2},{3},{4}", new object[] { scopeStorage.MasterIdentity, scopeStorage.Mode, scopeStorage.PolicyVersion, scopeStorage.Name.Replace(',', ' '), scopeStorage.Scope })); }
private static PolicyBindingConfig ToBindingScope(ScopeStorage storageScope) { PolicyBindingConfig policyBindingConfig = new PolicyBindingConfig(); policyBindingConfig.Identity = (ExPolicyConfigProvider.IsFFOOnline ? storageScope.Guid : storageScope.MasterIdentity); policyBindingConfig.Name = storageScope.Name; policyBindingConfig.Mode = storageScope.Mode; policyBindingConfig.Scope = BindingMetadata.FromStorage(storageScope.Scope); policyBindingConfig.Version = PolicyVersion.Create(storageScope.PolicyVersion); policyBindingConfig.ResetChangeTracking(); return(policyBindingConfig); }
public override void ScopeSetVariable(Scope scope, string name, object value) { string[] contextParts = Util.SplitUserName(name); dynamic storage; // ScopeStorage if (!base.ScopeTryGetVariable(scope, contextParts[0], out storage)) { storage = new ScopeStorage(); base.ScopeSetVariable(scope, contextParts[0], (ScopeStorage)storage); } ((ScopeStorage)storage).SetValue(contextParts[1], false, value); }
public void InvalidCssClassIsScopeBacked() { // Set a value string old = ValidationHelper.InvalidCssClass; ValidationHelper.InvalidCssClass = "outer"; using (ScopeStorage.CreateTransientScope()) { ValidationHelper.InvalidCssClass = "inner"; Assert.Equal("inner", ValidationHelper.InvalidCssClass); } Assert.Equal("outer", ValidationHelper.InvalidCssClass); ValidationHelper.InvalidCssClass = old; }
public void Dispose() { try { if (!commitVetoed) { using (var tx = new TransactionScope()) { context.SubmitChanges(); tx.Complete(); } } } finally { ScopeStorage.RemoveScope(contextType); context.Dispose(); } }
public TemplateHelpersSafeScope() { // Copying an HtmlHelper instance reads and writes the current StorageScope. // Ensure that's not the global scope. _transientScope = ScopeStorage.CreateTransientScope(); // Do not want templates to check disk for anything. var engine = new Mock <IViewEngine>(MockBehavior.Strict); engine .Setup(e => e.FindPartialView(It.IsAny <ControllerContext>(), It.IsAny <string>(), It.IsAny <bool>())) .Returns(new ViewEngineResult(Enumerable.Empty <string>())); _oldEngines = ViewEngines.Engines.ToList(); ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(engine.Object); }
private static Dictionary <string, AType> ExtractFunctions(ScopeStorage scope) { Dictionary <string, AType> functions = new Dictionary <string, AType>(); if (scope == null) { return(functions); } foreach (KeyValuePair <string, object> context in scope.GetItems()) { ICollection <KeyValuePair <string, object> > contextItems = context.Value as ICollection <KeyValuePair <string, object> >; if (contextItems == null) { ScopeStorage test = context.Value as ScopeStorage; if (test == null) { continue; } contextItems = test.GetItems(); } foreach (KeyValuePair <string, object> variableInfo in contextItems) { AType variable = variableInfo.Value as AType; if (variable != null && variable.Type == ATypes.AFunc && !variable.IsBox) { string[] parts = VariableHelper.CreateContextParts(context.Key, variableInfo.Key); if (parts[0].Contains(".")) { parts[0] = ""; } string id = string.Join(".", parts); functions.Add(id, variable); } } } return(functions); }
protected virtual void Execute(RequestContext requestContext) { if (requestContext == null) { throw new ArgumentNullException("requestContext"); } if (requestContext.HttpContext == null) { throw new ArgumentException(MvcResources.ControllerBase_CannotExecuteWithNullHttpContext, "requestContext"); } VerifyExecuteCalledOnce(); Initialize(requestContext); using (ScopeStorage.CreateTransientScope()) { ExecuteCore(); } }
private void SaveBindingStorage(BindingStorage bindingInstance) { BindingStorage existingStorage = this.FindBindingStorage(QueryFilter.AndTogether(new QueryFilter[] { new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.OrganizationalUnitRoot, base.TenantId), new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.Id, bindingInstance.Id.ObjectGuid) }), null, false, null, int.MaxValue, true).Cast <BindingStorage>().FirstOrDefault <BindingStorage>(); if (existingStorage == null) { using (MultiValuedProperty <ScopeStorage> .Enumerator enumerator = bindingInstance.AppliedScopes.GetEnumerator()) { while (enumerator.MoveNext()) { ScopeStorage scopeStorage = enumerator.Current; scopeStorage[UnifiedPolicyStorageBaseSchema.ContainerProp] = bindingInstance.Id.ObjectGuid.ToString(); scopeStorage[UnifiedPolicyStorageBaseSchema.WorkloadProp] = bindingInstance.Workload; ((IConfigDataProvider)this).Save(scopeStorage); } goto IL_20A; } } IEnumerable <ScopeStorage> enumerable = from s in bindingInstance.AppliedScopes where !existingStorage.AppliedScopes.Any((ScopeStorage e) => e.Id.ObjectGuid == s.Id.ObjectGuid) || bindingInstance.AppliedScopes.Any((ScopeStorage e) => e.Id.ObjectGuid == s.Id.ObjectGuid && s.GetChangedPropertyDefinitions().Any <PropertyDefinition>()) select s; IEnumerable <ScopeStorage> enumerable2 = from e in existingStorage.AppliedScopes where !bindingInstance.AppliedScopes.Any((ScopeStorage n) => n.Id.ObjectGuid == e.Id.ObjectGuid) select e; foreach (ScopeStorage instance in enumerable2) { ((IConfigDataProvider)this).Delete(instance); } foreach (ScopeStorage scopeStorage2 in enumerable) { scopeStorage2[UnifiedPolicyStorageBaseSchema.ContainerProp] = bindingInstance.Id.ObjectGuid.ToString(); scopeStorage2[UnifiedPolicyStorageBaseSchema.WorkloadProp] = bindingInstance.Workload; ((IConfigDataProvider)this).Save(scopeStorage2); } IL_20A: bindingInstance[UnifiedPolicyStorageBaseSchema.ContainerProp] = bindingInstance.PolicyId.ToString(); ((IConfigDataProvider)this).Save(bindingInstance); }
internal static void PopulateScopeStorages(BindingStorage bindingStorage, MultiValuedProperty <BindingMetadata> scopes) { ArgumentValidator.ThrowIfNull("bindingStorage", bindingStorage); ArgumentValidator.ThrowIfNull("scopes", scopes); if (scopes.Changed) { object[] removed = scopes.Removed; for (int i = 0; i < removed.Length; i++) { BindingMetadata removedScope = (BindingMetadata)removed[i]; ScopeStorage scopeStorage = bindingStorage.AppliedScopes.Find((ScopeStorage item) => string.Equals(BindingMetadata.FromStorage(item.Scope).ImmutableIdentity, removedScope.ImmutableIdentity, StringComparison.OrdinalIgnoreCase)); scopeStorage.Mode = Mode.PendingDeletion; scopeStorage.PolicyVersion = CombGuidGenerator.NewGuid(); } object[] added = scopes.Added; for (int j = 0; j < added.Length; j++) { BindingMetadata addedScope = (BindingMetadata)added[j]; ScopeStorage scopeStorage2 = bindingStorage.AppliedScopes.Find((ScopeStorage item) => string.Equals(BindingMetadata.FromStorage(item.Scope).ImmutableIdentity, addedScope.ImmutableIdentity, StringComparison.OrdinalIgnoreCase)); if (scopeStorage2 == null) { Guid objectGuid = Guid.NewGuid(); scopeStorage2 = new ScopeStorage(); scopeStorage2[ADObjectSchema.OrganizationalUnitRoot] = bindingStorage.OrganizationalUnitRoot; scopeStorage2.Name = objectGuid.ToString(); scopeStorage2.SetId(new ADObjectId(PolicyStorage.PoliciesContainer.GetChildId(scopeStorage2.Name).DistinguishedName, objectGuid)); bindingStorage.AppliedScopes.Add(scopeStorage2); } scopeStorage2.Mode = Mode.Enforce; scopeStorage2.Scope = BindingMetadata.ToStorage(addedScope); scopeStorage2.PolicyVersion = CombGuidGenerator.NewGuid(); } bindingStorage.PolicyVersion = CombGuidGenerator.NewGuid(); scopes.ResetChangeTracking(); } }
private static bool IsSameScope(PolicyBindingConfig bindingScope, ScopeStorage storageScope) { return(bindingScope.Identity == (ExPolicyConfigProvider.IsFFOOnline ? storageScope.Guid : storageScope.MasterIdentity)); }
protected ContextScopeBase(Type contextType) { this.contextType = contextType; context = CreateContext(); ScopeStorage.StoreScope(this, contextType); }
static PolicyConfigConverterTable() { PolicyConfigConverterBase[] array = new PolicyConfigConverterBase[4]; array[0] = new PolicyConfigConverter <PolicyDefinitionConfig, PolicyStorage>(ExPolicyConfigProvider.IsFFOOnline ? ADObjectSchema.Id : UnifiedPolicyStorageBaseSchema.MasterIdentity, ConfigurationObjectType.Policy, delegate(PolicyStorage storage, PolicyDefinitionConfig policyConfig) { policyConfig.Mode = storage.Mode; policyConfig.Scenario = storage.Scenario; policyConfig.DefaultPolicyRuleConfigId = storage.DefaultRuleId; policyConfig.Comment = storage.Comments; policyConfig.Description = storage.Description; policyConfig.Enabled = storage.IsEnabled; policyConfig.CreatedBy = storage.CreatedBy; policyConfig.LastModifiedBy = storage.LastModifiedBy; }, delegate(PolicyDefinitionConfig policyConfig, PolicyStorage storage) { if (policyConfig.Mode != storage.Mode) { storage.Mode = policyConfig.Mode; } storage.Scenario = policyConfig.Scenario; storage.DefaultRuleId = policyConfig.DefaultPolicyRuleConfigId; storage.Comments = policyConfig.Comment; storage.Description = policyConfig.Description; storage.IsEnabled = policyConfig.Enabled; storage.CreatedBy = policyConfig.CreatedBy; storage.LastModifiedBy = policyConfig.LastModifiedBy; }); array[1] = new PolicyConfigConverter <PolicyRuleConfig, RuleStorage>(RuleStorageSchema.ParentPolicyId, ConfigurationObjectType.Rule, delegate(RuleStorage storage, PolicyRuleConfig policyConfig) { policyConfig.Mode = storage.Mode; policyConfig.PolicyDefinitionConfigId = storage.ParentPolicyId; policyConfig.Priority = storage.Priority; policyConfig.RuleBlob = storage.RuleBlob; policyConfig.Comment = storage.Comments; policyConfig.Description = storage.Description; policyConfig.Enabled = storage.IsEnabled; policyConfig.CreatedBy = storage.CreatedBy; policyConfig.LastModifiedBy = storage.LastModifiedBy; policyConfig.Scenario = storage.Scenario; }, delegate(PolicyRuleConfig policyConfig, RuleStorage storage) { if (policyConfig.Mode != storage.Mode) { storage.Mode = policyConfig.Mode; } storage.ParentPolicyId = policyConfig.PolicyDefinitionConfigId; storage.Priority = policyConfig.Priority; storage.RuleBlob = policyConfig.RuleBlob; storage.Comments = policyConfig.Comment; storage.Description = policyConfig.Description; storage.IsEnabled = policyConfig.Enabled; storage.CreatedBy = policyConfig.CreatedBy; storage.LastModifiedBy = policyConfig.LastModifiedBy; storage.Scenario = policyConfig.Scenario; }); array[2] = new PolicyConfigConverter <PolicyBindingSetConfig, BindingStorage>(BindingStorageSchema.PolicyId, ConfigurationObjectType.Binding, delegate(BindingStorage storage, PolicyBindingSetConfig policyConfig) { policyConfig.PolicyDefinitionConfigId = storage.PolicyId; List <PolicyBindingConfig> list = new List <PolicyBindingConfig>(storage.AppliedScopes.Count); foreach (ScopeStorage storageScope in storage.AppliedScopes) { PolicyBindingConfig policyBindingConfig = PolicyConfigConverterTable.ToBindingScope(storageScope); policyBindingConfig.PolicyDefinitionConfigId = storage.PolicyId; list.Add(policyBindingConfig); } policyConfig.AppliedScopes = list; }, delegate(PolicyBindingSetConfig policyConfig, BindingStorage storage) { PolicyConfigConverterTable.< > c__DisplayClass12 CS$ < > 8__locals1 = new PolicyConfigConverterTable.< > c__DisplayClass12(); CS$ < > 8__locals1.storage = storage; CS$ < > 8__locals1.storage.PolicyId = policyConfig.PolicyDefinitionConfigId; IEnumerable <PolicyBindingConfig> enumerable = policyConfig.AppliedScopes ?? ((IEnumerable <PolicyBindingConfig>)Array <PolicyBindingConfig> .Empty); int index; for (index = CS$ < > 8__locals1.storage.AppliedScopes.Count - 1; index >= 0; index--) { if (!enumerable.Any((PolicyBindingConfig bindingScope) => PolicyConfigConverterTable.IsSameScope(bindingScope, CS$ < > 8__locals1.storage.AppliedScopes[index]))) { CS$ < > 8__locals1.storage.AppliedScopes.RemoveAt(index); } } using (IEnumerator <PolicyBindingConfig> enumerator = enumerable.GetEnumerator()) { while (enumerator.MoveNext()) { PolicyBindingConfig bindingScope = enumerator.Current; ScopeStorage scopeStorage = CS$ < > 8__locals1.storage.AppliedScopes.FirstOrDefault((ScopeStorage scope) => PolicyConfigConverterTable.IsSameScope(bindingScope, scope)); if (scopeStorage == null) { CS$ < > 8__locals1.storage.AppliedScopes.Add(PolicyConfigConverterTable.ToStorageScope(bindingScope, CS$ < > 8__locals1.storage.OrganizationalUnitRoot)); } else { PolicyConfigConverterTable.UpdateStorageScope(scopeStorage, bindingScope); } } } }); array[3] = new PolicyConfigConverter <PolicyAssociationConfig, AssociationStorage>(AssociationStorageSchema.PolicyIds, ConfigurationObjectType.Association, delegate(AssociationStorage storage, PolicyAssociationConfig policyConfig) { throw new NotImplementedException("Not in v1 of unified policy."); }, delegate(PolicyAssociationConfig policyConfig, AssociationStorage storage) { throw new NotImplementedException("Not in v1 of unified policy."); }); PolicyConfigConverterTable.policyConverters = array; }
private IDisposable CreateScope() { return(ScopeStorage.CreateTransientScope(new ScopeStorageDictionary(ScopeStorage.CurrentScope, PageData))); }