Пример #1
0
 private int ReadInt(string database, string query)
 {
     using (var session = _driver.Session(SessionConfigBuilder.ForDatabase(database)))
     {
         return(ValueExtensions.As <int>(session.Run(query).Single()[0]));
     }
 }
Пример #2
0
 public static PropertyInfo[] GetSimpleProperties(this IDotnetExpander expander, string assemblyName, string typeName)
 {
     return(Ex.Cache.Read("simpleproperties", assemblyName ?? "", typeName ?? "", "properties", () =>
     {
         return expander.GetProperties(assemblyName, typeName).Where(p => ValueExtensions.IsPrimitive(p.PropertyType)).ToArray();
     }));
 }
Пример #3
0
 public override string ToString( )
 {
     fixed(byte *t = tag)
     {
         return($"{ValueExtensions.Name(this)}[{*t}]");
     }
 }
Пример #4
0
        private static bool IsNative(object value)
        {
            var type = value != null && value != DBNull.Value ? value.GetType() : null;

            return(type == null || ValueExtensions.IsPrimitive(type) || value is ValueSet || value is Attribute || value is Type || value is Assembly || value is ResourceManager ||
                   value is PropertyInfo || value is PropertyInfo[] ||
                   value is MethodInfo || value is MethodInfo[] ||
                   value is FieldInfo || value is FieldInfo[]);
        }
Пример #5
0
 public void Configure(IReadOnlyList <DiagnosticProbe> probes)
 {
     _queueProbes = probes
                    .Where(x => ValueExtensions.IsNotNull <DiagnosticProbe>(x) && x.ComponentType == ComponentType.Queue)
                    .ToList();
     _exchangeProbes = probes
                       .Where(x => x.IsNotNull() && x.ComponentType == ComponentType.Exchange)
                       .ToList();
 }
Пример #6
0
        public static string BuildName(this IDotnetExpander expander, object value)
        {
            if (value == null)
            {
                return(string.Empty);
            }
            var type        = value.GetType();
            var stringValue = ValueExtensions.IsPrimitive(type) ? $", {value.As<string>()}" : string.Empty;

            return($"{expander.BuildName(type)}{stringValue}");
        }
Пример #7
0
 public List <string> GetPeople()
 {
     using (var session = _driver.Session())
     {
         return(session.ReadTransaction(tx =>
         {
             var result = tx.Run("MATCH (a:Person) RETURN a.name ORDER BY a.name");
             return result.Select(record => ValueExtensions.As <string>(record[0])).ToList();// .As<string>())
         }));
     }
 }
Пример #8
0
 private static object DeserializeJson(string json, Type resultType)
 {
     if (ValueExtensions.IsPrimitive(resultType))
     {
         return(json.As(resultType));
     }
     using (var sr = new StringReader(json))
     {
         return(JsonSerializer.Deserialize(sr, resultType));
     }
 }
Пример #9
0
        public static object CreateInstance(this IDotnetExpander expander, string name, object[] args = null)
        {
            string assemblyName, typeName, value;

            expander.ParseName(name, out assemblyName, out typeName, out value);
            if (string.IsNullOrWhiteSpace(value))
            {
                return(expander.CreateInstance(assemblyName, typeName, args));
            }
            var type = expander.GetType(assemblyName, typeName);

            return(ValueExtensions.IsPrimitive(type) ? value.As(type) : expander.CreateInstance(assemblyName, typeName, args));
        }
        /// <inheritdoc />
        protected override object Operate(object lhs, object rhs, ScriptContext context)
        {
            object value = lhs;
            int    steps = rhs.Convert <int>();

            int numberofbits = value.GetNumberOfBits(this);

            if (steps >= numberofbits)
            {
                return(Activator.CreateInstance(value.GetType()));
            }

            object mask = ValueExtensions.GetMask(value.GetType(), numberofbits - steps);

            return(((dynamic)value >> (dynamic)steps) & (dynamic)mask);
        }
Пример #11
0
 public int AddEmployees(string companyName)
 {
     using (var session = _driver.Session())
     {
         var persons =
             session.ReadTransaction(tx => tx.Run("MATCH (a:Person) RETURN a.name AS name").ToList());
         return(persons.Sum(person => session.WriteTransaction(tx =>
         {
             tx.Run("MATCH (emp:Person {name: $person_name}) " +
                    "MERGE (com:Company {name: $company_name}) " +
                    "MERGE (emp)-[:WORKS_FOR]->(com)",
                    new { person_name = ValueExtensions.As <string>(person["name"]), company_name = companyName });
             return 1;
         })));
     }
 }
Пример #12
0
        /// <inheritdoc />
        protected override object Operate(object lhs, object rhs, ScriptContext context)
        {
            object value = lhs;
            int    steps = Converter.Convert <int>(rhs);

            int numberofbits = value.GetNumberOfBits(this);

            steps = steps % numberofbits;
            if (steps == 0)
            {
                return(value);
            }

            object mask = ValueExtensions.GetMask(value.GetType(), numberofbits - steps);

            return((((dynamic)value >> steps) & (dynamic)mask) | ((dynamic)value << (numberofbits - steps)));
        }
Пример #13
0
 public void Configure(IReadOnlyList <DiagnosticProbe> probes)
 {
     _nodeProbes = probes
                   .Where(x => ValueExtensions.IsNotNull <DiagnosticProbe>(x) && x.ComponentType == ComponentType.Node)
                   .ToList();
     _diskProbes = probes
                   .Where(x => x.IsNotNull() && x.ComponentType == ComponentType.Disk)
                   .ToList();
     _memoryProbes = probes
                     .Where(x => x.IsNotNull() && x.ComponentType == ComponentType.Memory)
                     .ToList();
     _runtimeProbes = probes
                      .Where(x => x.IsNotNull() && x.ComponentType == ComponentType.Runtime)
                      .ToList();
     _osProbes = probes
                 .Where(x => x.IsNotNull() && x.ComponentType == ComponentType.OperatingSystem)
                 .ToList();
 }
Пример #14
0
 public void PrintGreeting(string message)
 {
     using (var session = _driver.Session())
     {
         var greeting = session.WriteTransaction(tx =>
         {
             string sql = "CREATE (a:Greeting) " +
                          "SET a.message = 'message' " +
                          "RETURN a.message + ', from node ' + id(a)";
             var result = tx.Run(sql);
             //var result = tx.Run("CREATE (a:Greeting) " +
             //                    "SET a.message = $message " +
             //                    "RETURN a.message + ', from node ' + id(a)",
             //    new { message });
             return(ValueExtensions.As <string>(result.Single()[0])); //result.Single()[0].As<string>();
         });
         Console.WriteLine(greeting);
     }
 }
Пример #15
0
        private static object[] NormalizeKeys(object[] keys)
        {
            var normalKeys = new object[keys.Length];

            for (int i = 0; i < keys.Length; i++)
            {
                var key = keys[i];
                if (key == null || key == DBNull.Value)
                {
                    key = string.Empty;
                }
                var type = key.GetType();
                if (!ValueExtensions.IsPrimitive(type))
                {
                    key = string.Empty;
                }
                normalKeys[i] = key;
            }
            return(normalKeys);
        }
        public static void SetParameter(this Task task, string code, object value)
        {
            var item = task.Items.FirstOrDefault(x => x.Code == code);

            if (item == null)
            {
                item = new TaskItem {
                    Code = code, Scope = ParameterScope.Constant, Name = code, Note = code
                };
                task.Add(item);
            }
            var stringValue = string.Empty;

            if (value != null)
            {
                var type = value.GetType();
                stringValue = ValueExtensions.IsPrimitive(type) ? value.As <string>() : Je.Json.Of(value);
            }
            item.Value = stringValue;
        }
Пример #17
0
        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            if (!Enabled)
            {
                return(Ex.Inject.Call(input, getNext));
            }
            var methodId = Ex.Inject.Info(input, TypeName);
            var type     = input.Target.GetType().BaseType;
            var keys     = new List <object>();

            if (!string.IsNullOrWhiteSpace(AssemblyName) && !string.IsNullOrWhiteSpace(TypeName))
            {
                keys.Add(AssemblyName);
                keys.Add(TypeName);
                keys.Add(methodId);
                keys.AddRange(GetKeys(input.Target, type));
                Cache.Bases.Cache.ClearEx(keys.ToArray());
                return(input.CreateMethodReturn(Ex.Inject.Call(input, getNext).ReturnValue));
            }
            string assemblyName, typeName;

            Ex.Dotnet.ParseName(type, out assemblyName, out typeName);
            keys.Add(assemblyName);
            keys.Add(typeName);
            keys.Add(methodId);
            keys.AddRange(GetKeys(input.Target, type));
            var    parameters = keys.ToArray();
            object objectValue;

            if (Ex.Cache.Read(parameters, out objectValue))
            {
                var returnType  = ((MethodInfo)input.MethodBase).ReturnType;
                var returnValue = ValueExtensions.IsPrimitive(returnType) ? objectValue.As(returnType) : DeserializeJson(objectValue.ToString(), returnType);
                return(input.CreateMethodReturn(returnValue));
            }
            var value = Ex.Inject.Call(input, getNext).ReturnValue;

            Cache.Bases.Cache.WriteEx(parameters, value, LifeTime);
            return(input.CreateMethodReturn(value));
        }
Пример #18
0
 public override string ToString( )
 {
     return($"{ValueExtensions.Name(this)}");
 }
        public void It_should_throw_an_exception_when_the_table_parameter_is_null()
        {
            var exception = Assert.Throws <ArgumentNullException>(() => ValueExtensions.GetValue(null, "A1"));

            Assert.AreEqual($"Value cannot be null. (Parameter 'table')", exception.Message);
        }