Esempio n. 1
0
        protected internal override Expression VisitProjection(ProjectionExpression proj)
        {
            using (HeavyProfiler.LogNoStackTrace(nameof(VisitProjection), () => proj.Type.TypeName()))
            {
                GetColumnCollector(proj.Select.KnownAliases).Visit(proj.Projector);

                SelectExpression source    = (SelectExpression)this.Visit(proj.Select);
                Expression       projector = this.Visit(proj.Projector);
                CurrentScope.RemoveAll(kvp =>
                {
                    if (source.KnownAliases.Contains(kvp.Key.Alias))
                    {
                        if (kvp.Value == null)
                        {
                            throw new InvalidOperationException();
                        }

                        return(true);
                    }

                    return(false);
                });

                if (source != proj.Select || projector != proj.Projector)
                {
                    return(new ProjectionExpression(source, projector, proj.UniqueFunction, proj.Type));
                }
                return(proj);
            }
        }
Esempio n. 2
0
        public static string WikiParse(this WikiSettings settings, string content)
        {
            using (HeavyProfiler.Log("Wiki"))
                using (var t = HeavyProfiler.LogNoStackTrace("SaveCodeRegions"))
                {
                    string result = content;

                    result = SaveCodeRegions(result, out Dictionary <string, string> codeRegions);

                    if (settings.EncodeHtml)
                    {
                        t.Switch("HtmlEncode");
                        //1: Replace token delimiters which are different from their encoded string so that they are not encoded
                        result = Regex.Replace(result, "'{2,}", m => "####" + m.Length + "####");


                        //2: Encode all text
                        result = HttpUtility.HtmlEncode(result);

                        //3: Replace encrypted tokens to original tokens
                        result = Regex.Replace(result, "####(?<count>\\d+)####", m => new string('\'', int.Parse(m.Groups["count"].Value)));
                    }
                    t.Switch("ProcessTokens");
                    result = ProcessTokens(result, settings);
                    t.Switch("ProcessFormat");

                    result = ProcessFormat(result, settings);
                    t.Switch("WriteCodeRegions");

                    result = WriteCodeRegions(result, codeRegions, settings);

                    return(result.Trim());
                }
        }
Esempio n. 3
0
        public Dictionary <string, string> IntegrityCheck()
        {
            using (var log = HeavyProfiler.LogNoStackTrace("IntegrityCheck"))
            {
                var validators = Validator.GetPropertyValidators(GetType());

                Dictionary <string, string> result = null;

                foreach (var pv in validators.Values)
                {
                    var error = pv.PropertyCheck(this);

                    if (error != null)
                    {
                        if (result == null)
                        {
                            result = new Dictionary <string, string>();
                        }

                        result.Add(pv.PropertyInfo.Name, error);
                    }
                }

                return(result);
            }
        }
        public List <PredictDictionary> PredictMultiple(PredictorPredictContext ctx, List <PredictDictionary> inputs)
        {
            using (HeavyProfiler.LogNoStackTrace("PredictMultiple"))
            {
                var nnSettings = (NeuralNetworkSettingsEntity)ctx.Predictor.AlgorithmSettings;
                lock (lockKey) //https://docs.microsoft.com/en-us/cognitive-toolkit/cntk-library-evaluation-on-windows#evaluation-of-multiple-requests-in-parallel
                {
                    Function calculatedOutputs = (Function)ctx.Model !;
                    var      device            = GetDevice(nnSettings);
                    Value    inputValue        = GetValueForPredict(ctx, inputs, device);

                    var inputVar = calculatedOutputs.Inputs.SingleEx(i => i.Name == "input");
                    var inputDic = new Dictionary <Variable, Value> {
                        { inputVar, inputValue }
                    };
                    var outputDic = new Dictionary <Variable, Value> {
                        { calculatedOutputs, null ! }
                    };

                    calculatedOutputs.Evaluate(inputDic, outputDic, device);

                    Value output = outputDic[calculatedOutputs];
                    IList <IList <float> > values = output.GetDenseData <float>(calculatedOutputs);
                    var result = values.Select((val, i) => GetPredictionDictionary(val.ToArray(), ctx, inputs[i].Options !)).ToList();
                    return(result);
                }
            }
        }
Esempio n. 5
0
        public AttributeCollection FieldAttributes(PropertyRoute propertyRoute)
        {
            using (HeavyProfiler.LogNoStackTrace("FieldAttributes"))
            {
                return(FieldAttributesCache.GetOrAdd(propertyRoute, pr =>
                {
                    switch (propertyRoute.PropertyRouteType)
                    {
                    case PropertyRouteType.FieldOrProperty:
                        if (propertyRoute.FieldInfo == null)
                        {
                            return null;
                        }
                        return CreateFieldAttributeCollection(propertyRoute);

                    case PropertyRouteType.MListItems:
                        if (propertyRoute.Parent.FieldInfo == null)
                        {
                            return null;
                        }
                        return CreateFieldAttributeCollection(propertyRoute.Parent);

                    default:
                        throw new InvalidOperationException("Route of type {0} not supported for this method".FormatWith(propertyRoute.PropertyRouteType));
                    }
                }));
            }
        }
Esempio n. 6
0
        public override T GetValue(MappingContext <T> ctx)
        {
            using (HeavyProfiler.LogNoStackTrace("GetValue", () => "AutoEntityMapping<{0}>".FormatWith(typeof(T).TypeName())))
            {
                if (ctx.Empty())
                {
                    return(ctx.None());
                }

                Type entityType;
                entityType = GetRuntimeType(ctx);


                if (entityType == null)
                {
                    return((T)(object)null);
                }

                if (typeof(T) == entityType || typeof(T).IsEmbeddedEntity())
                {
                    return(GetRuntimeValue <T>(ctx, ctx.PropertyRoute));
                }

                return(miGetRuntimeValue.GetInvoker(entityType)(this, ctx, PropertyRoute.Root(entityType)));
            }
        }
Esempio n. 7
0
        public override MList <S> GetValue(MappingContext <MList <S> > ctx)
        {
            using (HeavyProfiler.LogNoStackTrace("GetValue", () => "MListCorrelatedMapping<{0}>".FormatWith(typeof(S).TypeName())))
            {
                MList <S> list = ctx.Value;
                int       i    = 0;

                foreach (MappingContext <S> itemCtx in GenerateItemContexts(ctx).OrderBy(mc => mc.Prefix.Substring(mc.Prefix.LastIndexOf("_") + 1).ToInt().Value))
                {
                    Debug.Assert(!itemCtx.Empty());

                    itemCtx.Value = list[i];
                    itemCtx.Value = ElementMapping(itemCtx);

                    ctx.AddChild(itemCtx);

                    if (!itemCtx.SupressChange && !object.Equals(list[i], itemCtx.Value))
                    {
                        Signum.Web.Mapping.AssertCanChange(ctx.PropertyRoute);
                    }

                    if (!list[i].Equals(itemCtx.Value))
                    {
                        list[i] = itemCtx.Value;
                    }

                    i++;
                }

                return(list);
            }
        }
Esempio n. 8
0
        public override T GetValue(MappingContext <T> ctx)
        {
            using (HeavyProfiler.LogNoStackTrace("GetValue", () => "EntityMapping<{0}>".FormatWith(typeof(T).TypeName())))
            {
                if (ctx.Empty())
                {
                    return(ctx.None());
                }

                var val = GetEntity(ctx);

                if (val == ctx.Value)
                {
                    ctx.SupressChange = true;
                }
                else
                {
                    ctx.Value = val;
                }

                SetValueProperties(ctx);

                return(val);
            }
        }
Esempio n. 9
0
        public PropertyRoute Add(MemberInfo member)
        {
            using (HeavyProfiler.LogNoStackTrace("PR.Add", () => member.Name))
            {
                if (member is MethodInfo && ((MethodInfo)member).IsInstantiationOf(MixinDeclarations.miMixin))
                {
                    member = ((MethodInfo)member).GetGenericArguments()[0];
                }

                if (this.Type.IsIEntity() && PropertyRouteType != PropertyRouteType.Root)
                {
                    Implementations imp = GetImplementations();

                    Type?only;
                    if (imp.IsByAll || (only = imp.Types.Only()) == null)
                    {
                        throw new InvalidOperationException("Attempt to make a PropertyRoute on a {0}. Cast first".FormatWith(imp));
                    }

                    return(new PropertyRoute(Root(only), member));
                }

                return(new PropertyRoute(this, member));
            }
        }
Esempio n. 10
0
        public override object?ReadJson(JsonReader reader, Type objectType, object?existingValue, JsonSerializer serializer)
        {
            using (HeavyProfiler.LogNoStackTrace("ReadJson", () => objectType.Name))
            {
                if (reader.TokenType == JsonToken.Null)
                {
                    return(null);
                }

                using (EntityCache ec = new EntityCache())
                {
                    reader.Assert(JsonToken.StartObject);

                    ModifiableEntity mod = GetEntity(reader, objectType, existingValue, out bool markedAsModified);

                    var pr = GetCurrentPropertyRoute(mod);

                    var dic = PropertyConverter.GetPropertyConverters(mod.GetType());
                    using (JsonSerializerExtensions.SetAllowDirectMListChanges(markedAsModified))
                        while (reader.TokenType == JsonToken.PropertyName)
                        {
                            if ((string)reader.Value ! == "mixins")
                            {
                                var entity = (Entity)mod;
                                reader.Read();
                                reader.Assert(JsonToken.StartObject);

                                reader.Read();
                                while (reader.TokenType == JsonToken.PropertyName)
                                {
                                    var mixin = entity[(string)reader.Value !];
Esempio n. 11
0
        public List <PredictDictionary> PredictMultiple(PredictorPredictContext ctx, List <PredictDictionary> inputs)
        {
            using (HeavyProfiler.LogNoStackTrace("PredictMultiple"))
            {
                lock (lockKey)
                {
                    var model = (TensorFlowModel)ctx.Model !;
                    tf.compat.v1.disable_eager_execution();
                    model.Session.as_default();
                    model.Graph.as_default();

                    var result = new List <PredictDictionary>();
                    foreach (var input in inputs)
                    {
                        NDArray           inputValue     = GetValueForPredict(ctx, input);
                        NDArray           outputValuesND = model.Session.run(model.CalculatedOutput, (model.InputPlaceholder, inputValue));
                        float[]           outputValues   = outputValuesND.ToArray <float>();
                        PredictDictionary dic            = GetPredictionDictionary(outputValues, ctx, input.Options !);
                        result.Add(dic);
                    }

                    return(result);
                }
            }
        }
Esempio n. 12
0
        public IntegrityCheck?IntegrityCheck()
        {
            using (var log = HeavyProfiler.LogNoStackTrace("IntegrityCheck"))
            {
                var validators = Validator.GetPropertyValidators(GetType());

                Dictionary <string, string>?dic = null;

                foreach (var pv in validators.Values)
                {
                    var error = pv.PropertyCheck(this);

                    if (error != null)
                    {
                        if (dic == null)
                        {
                            dic = new Dictionary <string, string>();
                        }

                        dic.Add(pv.PropertyInfo.Name, error);
                    }
                }
                if (dic == null)
                {
                    return(null);
                }

                return(new Entities.IntegrityCheck(this, dic));
            }
        }
        public override void Write(Utf8JsonWriter writer, ResultTable value, JsonSerializerOptions options)
        {
            using (HeavyProfiler.LogNoStackTrace("ReadJson", () => typeof(ResultTable).Name))
            {
                var rt = (ResultTable)value !;

                writer.WriteStartObject();

                writer.WritePropertyName("entityColumn");
                writer.WriteStringValue(rt.EntityColumn?.Name);

                writer.WritePropertyName("columns");
                JsonSerializer.Serialize(writer, rt.Columns.Select(c => c.Column.Token.FullKey()).ToList(), typeof(List <string>), options);

                writer.WritePropertyName("pagination");
                JsonSerializer.Serialize(writer, new PaginationTS(rt.Pagination), typeof(PaginationTS), options);

                writer.WritePropertyName("totalElements");
                if (rt.TotalElements == null)
                {
                    writer.WriteNullValue();
                }
                else
                {
                    writer.WriteNumberValue(rt.TotalElements !.Value);
                }


                writer.WritePropertyName("rows");
                writer.WriteStartArray();
                foreach (var row in rt.Rows)
                {
                    writer.WriteStartObject();
                    if (rt.EntityColumn != null)
                    {
                        writer.WritePropertyName("entity");
                        JsonSerializer.Serialize(writer, row.Entity, options);
                    }

                    writer.WritePropertyName("columns");
                    writer.WriteStartArray();
                    foreach (var column in rt.Columns)
                    {
                        using (EntityJsonContext.SetCurrentPropertyRouteAndEntity((column.Column.Token.GetPropertyRoute() !, null, null)))
                        {
                            JsonSerializer.Serialize(writer, row[column], options);
                        }
                    }
                    writer.WriteEndArray();


                    writer.WriteEndObject();
                }
                writer.WriteEndArray();


                writer.WriteEndObject();
            }
        }
Esempio n. 14
0
        public static bool IsCompatibleWith(Attribute a, AttributeTargets targets)
        {
            using (HeavyProfiler.LogNoStackTrace("IsCompatibleWith"))
            {
                var au = AttributeUssageCache.GetOrCreate(a.GetType(), t => t.GetCustomAttribute <AttributeUsageAttribute>());

                return(au != null && (au.ValidOn & targets) != 0);
            }
        }
Esempio n. 15
0
        internal protected virtual Table Include(Type type, PropertyRoute?route)
        {
            if (schema.Tables.TryGetValue(type, out var result))
            {
                return(result);
            }

            using (HeavyProfiler.LogNoStackTrace("Include", () => type.TypeName()))
            {
                if (type.IsAbstract)
                {
                    throw new InvalidOperationException(ErrorIncluding(route) + $"Impossible to include in the Schema the type {type} because is abstract");
                }

                if (!Reflector.IsEntity(type))
                {
                    throw new InvalidOperationException(ErrorIncluding(route) + $"Impossible to include in the Schema the type {type} because is not and Entity");
                }

                foreach (var t in type.Follow(a => a.BaseType))
                {
                    if (!t.IsSerializable)
                    {
                        throw new InvalidOperationException(ErrorIncluding(route) + $"Type {t.TypeName()} is not marked as serializable");
                    }
                }

                string cleanName = schema.Settings.desambiguatedNames?.TryGetC(type) ?? Reflector.CleanTypeName(EnumEntity.Extract(type) ?? type);

                if (schema.NameToType.ContainsKey(cleanName))
                {
                    throw new InvalidOperationException(ErrorIncluding(route) + @$ "Two types have the same cleanName '{cleanName}', desambiguate using Schema.Current.Settings.Desambiguate method:
{schema.NameToType[cleanName].FullName}
{type.FullName}");
                }

                try
                {
                    result = new Table(type);

                    schema.Tables.Add(type, result);
                    schema.NameToType[cleanName] = type;
                    schema.TypeToName[type]      = cleanName;

                    Complete(result);

                    return(result);
                }
                catch (Exception) //Avoid half-cooked tables
                {
                    schema.Tables.Remove(type);
                    schema.NameToType.Remove(cleanName);
                    schema.TypeToName.Remove(type);
                    throw;
                }
            }
        }
Esempio n. 16
0
 public static string Dump(this object o, ShowIgnoredFields showIgnoredFields = ShowIgnoredFields.OnlyQueryables, bool showByteArrays = false)
 {
     using (HeavyProfiler.LogNoStackTrace("Dump"))
     {
         var od = new DumpVisitor(showIgnoredFields, showByteArrays);
         od.DumpObject(o);
         return(od.Sb.ToString());
     }
 }
 public static string Action <TController>(this UrlHelper helper, Expression <Action <TController> > action)
     where TController : Controller
 {
     using (var a = HeavyProfiler.LogNoStackTrace("GetRouteValuesFromExpression"))
     {
         RouteValueDictionary rvd = ExpressionHelper.GetRouteValuesFromExpression(action);
         a.Switch("Action");
         return(helper.Action(null, null, rvd));
     }
 }
Esempio n. 18
0
        public static FieldInfo[] InstanceFieldsInOrder(Type type)
        {
            using (HeavyProfiler.LogNoStackTrace("Reflector", () => type.Name))
            {
                var result = type.For(t => t != typeof(object), t => t.BaseType)
                             .Reverse()
                             .SelectMany(t => t.GetFields(flags | BindingFlags.DeclaredOnly).OrderBy(f => f.MetadataToken)).ToArray();

                return(result);
            }
        }
Esempio n. 19
0
    public static T LogValue <T>(string role, Func <T> valueFactory)
    {
        if (!enabled)
        {
            return(valueFactory());
        }

        using (HeavyProfiler.LogNoStackTrace(role))
        {
            return(valueFactory());
        }
    }
Esempio n. 20
0
        public A FieldAttribute <A>(PropertyRoute propertyRoute) where A : Attribute
        {
            using (HeavyProfiler.LogNoStackTrace("FieldAttribute"))
            {
                if (propertyRoute.PropertyRouteType == PropertyRouteType.Root || propertyRoute.PropertyRouteType == PropertyRouteType.LiteEntity)
                {
                    throw new InvalidOperationException("Route of type {0} not supported for this method".FormatWith(propertyRoute.PropertyRouteType));
                }

                return((A)FieldAttributes(propertyRoute).FirstOrDefault(a => a.GetType() == typeof(A)));
            }
        }
Esempio n. 21
0
        public override void WriteJson(JsonWriter writer, object?value, JsonSerializer serializer)
        {
            using (HeavyProfiler.LogNoStackTrace("ReadJson", () => typeof(ResultTable).Name))
            {
                var rt = (ResultTable)value !;

                writer.WriteStartObject();

                writer.WritePropertyName("entityColumn");
                writer.WriteValue(rt.EntityColumn?.Name);

                writer.WritePropertyName("columns");
                serializer.Serialize(writer, rt.Columns.Select(c => c.Column.Token.FullKey()).ToList());

                writer.WritePropertyName("pagination");
                serializer.Serialize(writer, new PaginationTS(rt.Pagination));

                writer.WritePropertyName("totalElements");
                writer.WriteValue(rt.TotalElements);


                writer.WritePropertyName("rows");
                writer.WriteStartArray();
                foreach (var row in rt.Rows)
                {
                    writer.WriteStartObject();
                    if (rt.EntityColumn != null)
                    {
                        writer.WritePropertyName("entity");
                        serializer.Serialize(writer, row.Entity);
                    }

                    writer.WritePropertyName("columns");
                    writer.WriteStartArray();
                    foreach (var column in rt.Columns)
                    {
                        using (JsonSerializerExtensions.SetCurrentPropertyRoute(column.Column.Token.GetPropertyRoute()))
                        {
                            serializer.Serialize(writer, row[column]);
                        }
                    }
                    writer.WriteEndArray();


                    writer.WriteEndObject();
                }
                writer.WriteEndArray();


                writer.WriteEndObject();
            }
        }
        private Value GetValueForPredict(PredictorPredictContext ctx, List <PredictDictionary> inputs, DeviceDescriptor device)
        {
            using (HeavyProfiler.Log("GetValueForPredict", () => $"Inputs {inputs.Count} Codifications {ctx.InputCodifications.Count}"))
            {
                if (inputs.First().SubQueries.Values.Any(a => a.SubQueryGroups.Comparer != ObjectArrayComparer.Instance))
                {
                    throw new Exception("Unexpected dictionary comparer");
                }

                float[] inputValues = new float[inputs.Count * ctx.InputCodifications.Count];
                var     groups      = ctx.InputCodificationsByColumn;
                for (int i = 0; i < inputs.Count; i++)
                {
                    PredictDictionary input = inputs[i];
                    int offset = i * ctx.InputCodifications.Count;

                    foreach (var kvp in groups)
                    {
                        PredictorColumnBase col = kvp.Key;
                        object?value;
                        if (col is PredictorColumnMain pcm)
                        {
                            value = input.MainQueryValues.GetOrThrow(pcm.PredictorColumn);
                        }
                        else if (col is PredictorColumnSubQuery pcsq)
                        {
                            var sq = input.SubQueries.GetOrThrow(pcsq.SubQuery);

                            var dic = sq.SubQueryGroups.TryGetC(pcsq.Keys);

                            value = dic == null ? null : dic.GetOrThrow(pcsq.PredictorSubQueryColumn);
                        }
                        else
                        {
                            throw new UnexpectedValueException(col);
                        }

                        using (HeavyProfiler.LogNoStackTrace("EncodeValue"))
                        {
                            var enc = Encodings.GetOrThrow(col.Encoding);
                            enc.EncodeValue(value ?? CNTKDefault.GetDefaultValue(kvp.Value.FirstOrDefault()), col, kvp.Value, inputValues, offset);
                        }
                    }
                }

                using (HeavyProfiler.LogNoStackTrace("CreateBatch"))
                    return(Value.CreateBatch <float>(new int[] { ctx.InputCodifications.Count }, inputValues, device));
            }
        }
Esempio n. 23
0
        public static Func <object, object?>?CreateGetterUntyped(Type type, MemberInfo m)
        {
            using (HeavyProfiler.LogNoStackTrace("CreateGetterUntyped"))
            {
                if ((m as PropertyInfo)?.Let(a => !a.CanRead) ?? false)
                {
                    return(null);
                }

                ParameterExpression p = Expression.Parameter(typeof(object), "p");
                Type lambdaType       = typeof(Func <,>).MakeGenericType(typeof(object), typeof(object));
                var  exp = Expression.Lambda(lambdaType, Expression.Convert(Expression.MakeMemberAccess(Expression.Convert(p, type), m), typeof(object)), p);
                return((Func <object, object?>)exp.Compile());
            }
        }
Esempio n. 24
0
        public static Func <T, R>?CreateGetter <T, R>(MemberInfo m)
        {
            using (HeavyProfiler.LogNoStackTrace("CreateGetter"))
            {
                if (m is PropertyInfo pi && !pi.CanRead)
                {
                    return(null);
                }

                ParameterExpression t = Expression.Parameter(typeof(T), "t");
                var member            = Expression.MakeMemberAccess(t.ConvertIfNeeded(m.DeclaringType !), m);
                var exp = Expression.Lambda(typeof(Func <T, R>), member.ConvertIfNeeded(typeof(R)), t);
                return((Func <T, R>)exp.Compile());
            }
        }
Esempio n. 25
0
        public static Action <T, P>?CreateSetter <T, P>(MemberInfo m)
        {
            using (HeavyProfiler.LogNoStackTrace("CreateSetter"))
            {
                if ((m as PropertyInfo)?.Let(a => !a.CanWrite) ?? false)
                {
                    return(null);
                }

                ParameterExpression t = Expression.Parameter(typeof(T), "t");
                ParameterExpression p = Expression.Parameter(typeof(P), "p");
                var exp = Expression.Lambda(typeof(Action <T, P>),
                                            Expression.Assign(Expression.MakeMemberAccess(t, m), p), t, p);
                return((Action <T, P>)exp.Compile());
            }
        }
Esempio n. 26
0
        public ModifiableEntity DeserializeEntity(string viewState)
        {
            using (HeavyProfiler.LogNoStackTrace("DeserializeEntity"))
            {
                var array = Convert.FromBase64String(viewState);

                if (EntityStateKey != null)
                {
                    array = Decrypt(array);
                }

                using (var ms = new MemoryStream(array))
                    using (DeflateStream ds = new DeflateStream(ms, CompressionMode.Decompress))
                        return((ModifiableEntity)formatter.Deserialize(ds));
            }
        }
Esempio n. 27
0
        public static Action <object, object?>?CreateSetterUntyped(Type type, MemberInfo m)
        {
            using (HeavyProfiler.LogNoStackTrace("CreateSetterUntyped"))
            {
                if ((m as PropertyInfo)?.Let(a => !a.CanWrite) ?? false)
                {
                    return(null);
                }

                ParameterExpression t = Expression.Parameter(typeof(object), "t");
                ParameterExpression p = Expression.Parameter(typeof(object), "p");
                var exp = Expression.Lambda(typeof(Action <object, object>),
                                            Expression.Assign(Expression.MakeMemberAccess(Expression.Convert(t, type), m), Expression.Convert(p, m.ReturningType())), t, p);
                return((Action <object, object?>)exp.Compile());
            }
        }
Esempio n. 28
0
        internal protected virtual Table Include(Type type, PropertyRoute route)
        {
            Table result;

            if (schema.Tables.TryGetValue(type, out result))
            {
                return(result);
            }

            using (HeavyProfiler.LogNoStackTrace("Include", () => type.TypeName()))
            {
                if (type.IsAbstract)
                {
                    throw new InvalidOperationException(route?.Let(r => "Error on field {0}: ".FormatWith(r)) + "Impossible to include in the Schema the type {0} because is abstract".FormatWith(type));
                }

                if (!Reflector.IsEntity(type))
                {
                    throw new InvalidOperationException(route?.Let(r => "Error on field {0}: ".FormatWith(r)) + "Impossible to include in the Schema the type {0} because is not and Entity".FormatWith(type));
                }

                foreach (var t in type.Follow(a => a.BaseType))
                {
                    if (!t.IsSerializable)
                    {
                        throw new InvalidOperationException("Type {0} is not marked as serializable".FormatWith(t.TypeName()));
                    }
                }

                result = new Table(type);

                schema.Tables.Add(type, result);

                string name = schema.Settings.desambiguatedNames?.TryGetC(type) ?? Reflector.CleanTypeName(EnumEntity.Extract(type) ?? type);

                if (schema.NameToType.ContainsKey(name))
                {
                    throw new InvalidOperationException(route?.Let(r => "Error on field {0}: ".FormatWith(r)) + "Two types have the same cleanName, desambiguate using Schema.Current.Settings.Desambiguate method: \r\n {0}\r\n {1}".FormatWith(schema.NameToType[name].FullName, type.FullName));
                }

                schema.NameToType[name] = type;
                schema.TypeToName[type] = name;

                Complete(result);
                return(result);
            }
        }
Esempio n. 29
0
        static string SerializeToken(AuthToken entity)
        {
            using (HeavyProfiler.LogNoStackTrace("SerializeToken"))
            {
                var array = new MemoryStream().Using(ms =>
                {
                    using (DeflateStream ds = new DeflateStream(ms, CompressionMode.Compress))
                        formatter.Serialize(ds, entity);

                    return(ms.ToArray());
                });

                array = Encrypt(array);

                return(Convert.ToBase64String(array));
            }
        }
Esempio n. 30
0
        static TranslatedSummaryState?GetState(Type type, CultureInfo ci)
        {
            using (HeavyProfiler.LogNoStackTrace("GetState", () => type.Name + " " + ci.Name))
            {
                if (!TranslateableRoutes.GetOrThrow(type).Keys.Any(pr => AnyNoTranslated(pr, ci)))
                {
                    return(TranslatedSummaryState.Completed);
                }

                if (Database.Query <TranslatedInstanceEntity>().Count(ti => ti.PropertyRoute.RootType == type.ToTypeEntity() && ti.Culture == ci.ToCultureInfoEntity()) == 0)
                {
                    return(TranslatedSummaryState.None);
                }

                return(TranslatedSummaryState.Pending);
            }
        }