public ComparisonResult CompareObjects(IComparisonContext context, object source, object destination) { PreparePropertyInfo(source, destination); foreach (var pair in propertyMap) { currentPair = pair; var sourceValue = new Lazy<object>(() => currentPair.Source.Read(source)); var destinationValue = new Lazy<object>(() => currentPair.Destination.Read(destination)); if (IsPropertyIgnored()) { continue; } if (HandleMissingValues(context, destinationValue, sourceValue)) { continue; } var innerContext = context.VisitingProperty(currentPair.Name); results.Add(inner.Compare(innerContext, sourceValue.Value, destinationValue.Value)); } return results.ToResult(); }
public ComparisonResult CompareObjects(IComparisonContext context, object source, object destination) { PreparePropertyInfo(source, destination); foreach (var pair in propertyMap) { currentPair = pair; var sourceValue = new Lazy <object>(() => currentPair.Source.Read(source)); var destinationValue = new Lazy <object>(() => currentPair.Destination.Read(destination)); if (IsPropertyIgnored()) { continue; } if (HandleMissingValues(context, destinationValue, sourceValue)) { continue; } var innerContext = context.VisitingProperty(currentPair.Name); results.Add(inner.Compare(innerContext, sourceValue.Value, destinationValue.Value)); } return(results.ToResult()); }
public void setProperty(PropertyPair prop, float mod) { if (mod > 0) { switch (prop.Identifier) { case "Tech": Technology.Add(prop.Val); break; case "Income": Income += int.Parse(prop.Val); break; } } else { switch (prop.Identifier) { case "Tech": Technology.Remove(prop.Val); break; case "Income": Income -= int.Parse(prop.Val); break; } } }
public void ValidCommentLineShouldReturnTrue(string key) { var p = new PropertyPair { Key = key, Value = "I am a comment." }; Assert.True(p.IsComment()); }
public void NonCommentsShouldReturnFalse() { var p = new PropertyPair { Key = "Key1", Value = "I am not a comment." }; Assert.False(p.IsComment()); }
public void EmptyLineShouldReturnTrue() { var p = new PropertyPair { Key = "", Value = "" }; Assert.True(p.IsEmptyLine()); }
public void NonEmptyLineShouldReturnFalse(string key, string value) { var p = new PropertyPair { Key = key, Value = value }; Assert.False(p.IsEmptyLine()); }
public void NullCollection_ShouldNotThrow() { IUserConfirmation uc = new ThrowOnTriggerUserConfirmation(); var prop = new PropertyPair { Key = "A", Value = "a" }; ICommand cmd = new AddPropertyCommand(null, prop, uc); cmd.Execute(); }
public Builder AddProperty(string key, long value) { var property = new PropertyPair() { Key = key, IntValue = value }; message.payload.MatchmakeAdd.Properties.Add(property); return(this); }
public Builder AddProperty(string key, HashSet <string> values) { var property = new PropertyPair() { Key = key, StringSet = new PropertyPair.Types.StringSet() }; property.StringSet.Values.AddRange(values); message.payload.MatchmakeAdd.Properties.Add(property); return(this); }
public void ShouldAddIntoEmptyCollection() { IPropertiesFile file = new InMemoryPropertiesFile(new List <PropertyPair>()); IUserConfirmation uc = new ThrowOnTriggerUserConfirmation(); var prop = new PropertyPair { Key = "greeting", Value = "Hello, World!" }; ICommand cmd = new AddPropertyCommand(file, prop, uc); cmd.Execute(); var collection = file.GetProperties(); Assert.Single(collection); Assert.Same(prop, collection.First()); }
public (ComparisonResult, IComparisonContext) CompareObjects(IComparisonContext context, object source, object destination) { PreparePropertyInfo(source, destination); var currentContext = context; foreach (var pair in propertyMap) { currentPair = pair; var sourceValue = new Lazy <object>(() => currentPair.Source.Read(source)); var destinationValue = new Lazy <object>(() => currentPair.Destination.Read(destination)); if (IsPropertyIgnored()) { continue; } if (SourceAndDestinationPresent()) { var(result, innerContext) = inner.Compare( context.VisitingProperty(currentPair.Name), sourceValue.Value, destinationValue.Value ); results.Add(result); currentContext = currentContext.MergeDifferencesFrom(innerContext); } else if (!ignoreUnmatchedProperties) { if (currentPair.Source == null) { currentContext = currentContext.AddDifference("(missing)", destinationValue.Value, currentPair.Name); results.Add(ComparisonResult.Fail); } if (currentPair.Destination == null) { currentContext = currentContext.AddDifference(sourceValue.Value, "(missing)", currentPair.Name); results.Add(ComparisonResult.Fail); } } } return(results.ToResult(), currentContext); }
public void WhenUserDeniesShouldNotAddDuplicateValue() { IPropertiesFile file = new InMemoryPropertiesFile(new List <PropertyPair> { new PropertyPair { Key = "A", Value = "a" }, new PropertyPair { Key = "B", Value = "b" } }); IUserConfirmation uc = new AlwaysDenyingUserConfirmation(); var prop = new PropertyPair { Key = "greeting", Value = "b" }; ICommand cmd = new AddPropertyCommand(file, prop, uc); cmd.Execute(); Assert.Equal(2, file.GetProperties().Count()); }
public void ShouldUpdateExistingIfKeyAlreadyExists() { IPropertiesFile file = new InMemoryPropertiesFile(new List <PropertyPair> { new PropertyPair { Key = "A", Value = "a" }, new PropertyPair { Key = "B", Value = "b" } }); IUserConfirmation uc = new ThrowOnTriggerUserConfirmation(); var prop = new PropertyPair { Key = "B", Value = "Hello, World!" }; ICommand cmd = new AddPropertyCommand(file, prop, uc); cmd.Execute(); Assert.Equal(2, file.GetProperties().Count()); Assert.Equal("Hello, World!", file.GetProperties().Last().Value); }
public void ShouldBeAddedAtTheEndOfCollection() { IPropertiesFile file = new InMemoryPropertiesFile(new List <PropertyPair> { new PropertyPair { Key = "A", Value = "a" }, new PropertyPair { Key = "B", Value = "b" } }); IUserConfirmation uc = new ThrowOnTriggerUserConfirmation(); var prop = new PropertyPair { Key = "greeting", Value = "Hello, World!" }; ICommand cmd = new AddPropertyCommand(file, prop, uc); cmd.Execute(); var collection = file.GetProperties(); Assert.Equal(3, collection.Count()); Assert.Same(prop, collection.Last()); }
public void deleteProperty(PropertyPair pair) { this.properties.Remove(pair); }
/// <remarks/> public void savePageToFormAsync(AuthenticationType auth, string form_name, string page_name, PropertyPair[] properties, string freetext, string[] categories, string active_form, string[] applicable_forms, bool no_wrapper) { this.savePageToFormAsync(auth, form_name, page_name, properties, freetext, categories, active_form, applicable_forms, no_wrapper, null); }
/// <remarks/> public void savePageToFormAsync(AuthenticationType auth, string form_name, string page_name, PropertyPair[] properties, string freetext, string[] categories, string active_form, string[] applicable_forms, bool no_wrapper, object userState) { if ((this.savePageToFormOperationCompleted == null)) { this.savePageToFormOperationCompleted = new System.Threading.SendOrPostCallback(this.OnsavePageToFormOperationCompleted); } this.InvokeAsync("savePageToForm", new object[] { auth, form_name, page_name, properties, freetext, categories, active_form, applicable_forms, no_wrapper}, this.savePageToFormOperationCompleted, userState); }
public AddPropertyCommand(IPropertiesFile file, PropertyPair newProperty, IUserConfirmation userConfirmation) { _file = file; _propertyToAdd = newProperty; _userConfirmation = userConfirmation; }
/// <remarks/> public System.IAsyncResult BegincreateFormTemplate(AuthenticationType auth, string name, PropertyPair[] properties, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("createFormTemplate", new object[] { auth, name, properties}, callback, asyncState); }
public ExceptionType savePageToForm(AuthenticationType auth, string form_name, string page_name, PropertyPair[] properties, string freetext, string[] categories, string active_form, string[] applicable_forms, bool no_wrapper) { object[] results = this.Invoke("savePageToForm", new object[] { auth, form_name, page_name, properties, freetext, categories, active_form, applicable_forms, no_wrapper}); return ((ExceptionType)(results[0])); }
/// <remarks/> public System.IAsyncResult BeginsavePageBasic(AuthenticationType auth, string form_name, string page_name, PropertyPair[] properties, string freetext, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("savePageBasic", new object[] { auth, form_name, page_name, properties, freetext}, callback, asyncState); }
/// <remarks/> public void createFormTemplateAsync(AuthenticationType auth, string name, PropertyPair[] properties, object userState) { if ((this.createFormTemplateOperationCompleted == null)) { this.createFormTemplateOperationCompleted = new System.Threading.SendOrPostCallback(this.OncreateFormTemplateOperationCompleted); } this.InvokeAsync("createFormTemplate", new object[] { auth, name, properties}, this.createFormTemplateOperationCompleted, userState); }
/// <remarks/> public void createFormTemplateAsync(AuthenticationType auth, string name, PropertyPair[] properties) { this.createFormTemplateAsync(auth, name, properties, null); }
public ExceptionType createFormTemplate(AuthenticationType auth, string name, PropertyPair[] properties) { object[] results = this.Invoke("createFormTemplate", new object[] { auth, name, properties}); return ((ExceptionType)(results[0])); }
/// <remarks/> public System.IAsyncResult BeginsavePageToForm(AuthenticationType auth, string form_name, string page_name, PropertyPair[] properties, string freetext, string[] categories, string active_form, string[] applicable_forms, bool no_wrapper, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("savePageToForm", new object[] { auth, form_name, page_name, properties, freetext, categories, active_form, applicable_forms, no_wrapper}, callback, asyncState); }
private void fillMembers() { lock (this) { if (_members != null) { return; } var tempMembers = new StringMap <IList <MemberInfo> >(); string prewName = null; IList <MemberInfo> temp = null; bool instanceAttribute = false; #if (PORTABLE || NETCORE) var members = _hostedType.GetTypeInfo().DeclaredMembers .Union(_hostedType.GetRuntimeMethods()) .Union(_hostedType.GetRuntimeProperties()) .Union(_hostedType.GetRuntimeFields()) .Union(_hostedType.GetRuntimeEvents()).ToArray(); #else var members = _hostedType.GetMembers(); #endif for (int i = 0; i < members.Length; i++) { var member = members[i]; if (member.IsDefined(typeof(HiddenAttribute), false)) { continue; } instanceAttribute = member.IsDefined(typeof(InstanceMemberAttribute), false); if (!IsInstancePrototype && instanceAttribute) { continue; } var property = member as PropertyInfo; if (property != null) { if ((property.GetSetMethod(true) ?? property.GetGetMethod(true)).IsStatic != !(IsInstancePrototype ^ instanceAttribute)) { continue; } if ((property.GetSetMethod(true) == null || !property.GetSetMethod(true).IsPublic) && (property.GetGetMethod(true) == null || !property.GetGetMethod(true).IsPublic)) { continue; } var parentProperty = property; while (parentProperty != null && parentProperty.DeclaringType != typeof(object) && ((property.GetGetMethod() ?? property.GetSetMethod()).Attributes & MethodAttributes.NewSlot) == 0) { property = parentProperty; #if (PORTABLE || NETCORE) parentProperty = property.DeclaringType.GetTypeInfo().BaseType?.GetRuntimeProperty(property.Name); #else parentProperty = property.DeclaringType.GetTypeInfo().BaseType?.GetProperty(property.Name, BindingFlags.Public | BindingFlags.Instance); #endif } member = property; } if (member is EventInfo && (!(member as EventInfo).GetAddMethod(true).IsPublic || (member as EventInfo).GetAddMethod(true).IsStatic != !IsInstancePrototype)) { continue; } if (member is FieldInfo && (!(member as FieldInfo).IsPublic || (member as FieldInfo).IsStatic != !IsInstancePrototype)) { continue; } #if (PORTABLE || NETCORE) if ((members[i] is TypeInfo) && !(members[i] as TypeInfo).IsPublic) { continue; } #else if (member is Type && !(member as Type).IsPublic && !(member as Type).IsNestedPublic) { continue; } #endif var method = member as MethodBase; if (method != null) { if (method.IsStatic != !(IsInstancePrototype ^ instanceAttribute)) { continue; } if (!method.IsPublic) { continue; } if (method.DeclaringType == typeof(object) && member.Name == "GetType") { continue; } if (method is ConstructorInfo) { continue; } var parameterTypes = method.GetParameters().Select(x => x.ParameterType).ToArray(); if (parameterTypes.Any(x => x.IsByRef)) { continue; } if (method.IsVirtual && (method.Attributes & MethodAttributes.NewSlot) == 0) { var parentMethod = method; while (parentMethod != null && parentMethod.DeclaringType != typeof(object) && (method.Attributes & MethodAttributes.NewSlot) == 0) { method = parentMethod; #if (PORTABLE || NETCORE) parentMethod = method.DeclaringType.GetTypeInfo().BaseType?.GetMethod(method.Name, parameterTypes); #else parentMethod = method.DeclaringType.BaseType?.GetMethod(method.Name, BindingFlags.Public | BindingFlags.Instance, null, parameterTypes, null); #endif } } member = method; } var membername = member.Name; if (member.IsDefined(typeof(JavaScriptNameAttribute), false)) { var nameOverrideAttribute = member.GetCustomAttributes(typeof(JavaScriptNameAttribute), false).ToArray(); membername = (nameOverrideAttribute[0] as JavaScriptNameAttribute).Name; } else { membername = membername[0] == '.' ? membername : membername.Contains(".") ? membername.Substring(membername.LastIndexOf('.') + 1) : membername; #if (PORTABLE || NETCORE) if (members[i] is TypeInfo && membername.Contains("`")) #else if (member is Type && membername.Contains('`')) #endif { membername = membername.Substring(0, membername.IndexOf('`')); } } if (prewName != membername) { if (temp != null && temp.Count > 1) { var type = temp[0].DeclaringType; for (var j = 1; j < temp.Count; j++) { if (type != temp[j].DeclaringType && type.IsAssignableFrom(temp[j].DeclaringType)) { type = temp[j].DeclaringType; } } int offset = 0; for (var j = 1; j < temp.Count; j++) { if (!type.IsAssignableFrom(temp[j].DeclaringType)) { temp.RemoveAt(j--); tempMembers.Remove(prewName + "$" + (++offset + j)); } } if (temp.Count == 1) { tempMembers.Remove(prewName + "$0"); } } if (!tempMembers.TryGetValue(membername, out temp)) { tempMembers[membername] = temp = new List <MemberInfo>(); } prewName = membername; } if (membername.StartsWith("@@")) { if (_symbols == null) { _symbols = new Dictionary <Symbol, JSValue>(); } _symbols.Add(Symbol.@for(membername.Substring(2)), proxyMember(false, new[] { member })); } else { if (temp.Count == 1) { tempMembers.Add(membername + "$0", new[] { temp[0] }); } temp.Add(member); if (temp.Count != 1) { tempMembers.Add(membername + "$" + (temp.Count - 1), new[] { member }); } } } _members = tempMembers; if (IsInstancePrototype) { if (typeof(IIterable).IsAssignableFrom(_hostedType)) { IList <MemberInfo> iterator = null; if (_members.TryGetValue("iterator", out iterator)) { if (_symbols == null) { _symbols = new Dictionary <Symbol, JSValue>(); } _symbols.Add(Symbol.iterator, proxyMember(false, iterator)); _members.Remove("iterator"); } } #if NET40 var toStringTag = _hostedType.GetCustomAttribute <ToStringTagAttribute>(); #else var toStringTag = _hostedType.GetTypeInfo().GetCustomAttribute <ToStringTagAttribute>(); #endif if (toStringTag != null) { if (_symbols == null) { _symbols = new Dictionary <Symbol, JSValue>(); } _symbols.Add(Symbol.toStringTag, toStringTag.Tag); } } if (_indexersSupported) { IList <MemberInfo> getter = null; IList <MemberInfo> setter = null; _members.TryGetValue("get_Item", out getter); _members.TryGetValue("set_Item", out setter); if (getter != null || setter != null) { _indexerProperty = new PropertyPair(); if (getter != null) { _indexerProperty.getter = (Function)proxyMember(false, getter); _fields["get_Item"] = _indexerProperty.getter; } if (setter != null) { _indexerProperty.setter = (Function)proxyMember(false, setter); _fields["set_Item"] = _indexerProperty.setter; } } else { _indexersSupported = false; } } } }
/// <remarks/> public void savePageBasicAsync(AuthenticationType auth, string form_name, string page_name, PropertyPair[] properties, string freetext) { this.savePageBasicAsync(auth, form_name, page_name, properties, freetext, null); }
public static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { AuthLogic.AssertStarted(sb); PropertyRouteLogic.Start(sb); sb.Include <RulePropertyEntity>() .WithUniqueIndex(rt => new { rt.Resource, rt.Role }); cache = new AuthCache <RulePropertyEntity, PropertyAllowedRule, PropertyRouteEntity, PropertyRoute, PropertyAllowed>(sb, toKey: PropertyRouteEntity.ToPropertyRouteFunc, toEntity: PropertyRouteLogic.ToPropertyRouteEntity, isEquals: (p1, p2) => p1 == p2, merger: new PropertyMerger(), invalidateWithTypes: true, coercer: PropertyCoercer.Instance); sb.Schema.EntityEvents <RoleEntity>().PreUnsafeDelete += query => { Database.Query <RulePropertyEntity>().Where(r => query.Contains(r.Role.Entity)).UnsafeDelete(); return(null); }; PropertyRoute.SetIsAllowedCallback(pp => pp.GetAllowedFor(PropertyAllowed.Read)); AuthLogic.ExportToXml += exportAll => cache.ExportXml("Properties", "Property", p => TypeLogic.GetCleanName(p.RootType) + "|" + p.PropertyString(), pa => pa.ToString(), exportAll ? TypeLogic.TypeToEntity.Keys.SelectMany(t => PropertyRoute.GenerateRoutes(t)).ToList() : null); AuthLogic.ImportFromXml += (x, roles, replacements) => { Dictionary <Type, Dictionary <string, PropertyRoute> > routesDicCache = new Dictionary <Type, Dictionary <string, PropertyRoute> >(); var groups = x.Element("Properties").Elements("Role").SelectMany(r => r.Elements("Property")).Select(p => new PropertyPair(p.Attribute("Resource").Value)) .AgGroupToDictionary(a => a.Type, gr => gr.Select(pp => pp.Property).ToHashSet()); foreach (var item in groups) { Type?type = TypeLogic.NameToType.TryGetC(replacements.Apply(TypeAuthCache.typeReplacementKey, item.Key)); if (type == null) { continue; } var dic = PropertyRoute.GenerateRoutes(type).ToDictionary(a => a.PropertyString()); replacements.AskForReplacements( item.Value, dic.Keys.ToHashSet(), AuthPropertiesReplacementKey(type)); routesDicCache[type] = dic; } var routes = Database.Query <PropertyRouteEntity>().ToDictionary(a => a.ToPropertyRoute()); return(cache.ImportXml(x, "Properties", "Property", roles, s => { var pp = new PropertyPair(s); Type?type = TypeLogic.NameToType.TryGetC(replacements.Apply(TypeAuthCache.typeReplacementKey, pp.Type)); if (type == null) { return null; } PropertyRoute?route = routesDicCache[type].TryGetC(replacements.Apply(AuthPropertiesReplacementKey(type), pp.Property)); if (route == null) { return null; } var property = routes.GetOrCreate(route, () => new PropertyRouteEntity { RootType = TypeLogic.TypeToEntity[route.RootType], Path = route.PropertyString() }.Save()); return property; }, EnumExtensions.ToEnum <PropertyAllowed>)); }; sb.Schema.Table <PropertyRouteEntity>().PreDeleteSqlSync += new Func <Entity, SqlPreCommand>(AuthCache_PreDeleteSqlSync); } }
/// <remarks/> public void savePageBasicAsync(AuthenticationType auth, string form_name, string page_name, PropertyPair[] properties, string freetext, object userState) { if ((this.savePageBasicOperationCompleted == null)) { this.savePageBasicOperationCompleted = new System.Threading.SendOrPostCallback(this.OnsavePageBasicOperationCompleted); } this.InvokeAsync("savePageBasic", new object[] { auth, form_name, page_name, properties, freetext}, this.savePageBasicOperationCompleted, userState); }
public PropertyPair createProperty() { PropertyPair propertyPair = new PropertyPair(); this.Properties.Add(propertyPair); return propertyPair; }
public ExceptionType savePageBasic(AuthenticationType auth, string form_name, string page_name, PropertyPair[] properties, string freetext) { object[] results = this.Invoke("savePageBasic", new object[] { auth, form_name, page_name, properties, freetext}); return ((ExceptionType)(results[0])); }