Example #1
0
        public void QueryLinq()
        {
            try
            {
                using (IIgniteClient client = Ignition.StartClient(this._igniteClientConfiguration))
                {
                    //get cache configuraation
                    var cache = client.GetCache <string, ChatMessege>("messages");
                    //var data = cache.Query(new SqlFieldsQuery("select * from ChatMessege  Where Name = 'abc'")).GetAll();
                    //Console.WriteLine(JsonConvert.SerializeObject(data));
                    //IQueryable<ICacheEntry<string, ChatMessege>> msgs = cache.AsCacheQueryable().OrderByDescending(msg => msg.Value.CreatedDateTime).Where(msg => msg.Value.Name == "abc").Take(2);
                    var cache0 = cache.AsCacheQueryable();
                    //Compiled Query
                    //var compileQuery = CompiledQuery.Compile((IQueryable<ICacheEntry<string,ChatMessege>> query,string name) => query.Where(msg => msg.Value.Name == name));
                    // var compileQuery = CompiledQuery.Compile((string name) => cache0.Where(msg => msg.Value.Name == name));


                    //IQueryable<ICacheEntry<string, ChatMessege>> qry = (from msg in msgs orderby msg.Value.CreatedDateTime descending select msg).Take(2);
                    foreach (ICacheEntry <string, ChatMessege> entry in compile.Invoke(cache0, "abc"))
                    {
                        Console.WriteLine(">>>     " + entry.Value.CreatedDateTime + "\t" + entry.Value.Name);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Example #2
0
        public static void Main()
        {
            var cfg = new IgniteClientConfiguration
            {
                Host = "127.0.0.1"
            };

            using (IIgniteClient igniteClient = Ignition.StartClient(cfg))
            {
                Console.WriteLine();
                Console.WriteLine(">>> Cache query client example started.");

                ICacheClient <int, Employee> cache = igniteClient.GetCache <int, Employee>(CacheName);

                // Populate cache with sample data entries.
                PopulateCache(cache);

                // Run scan query example.
                ScanQueryExample(cache);
            }

            Console.WriteLine();
            Console.WriteLine(">>> Example finished, press any key to exit ...");
            Console.ReadKey();
        }
Example #3
0
        public async Task SetValueAsync(object?value, CancellationToken cancellationToken)
        {
            if (_trigger.ContainsKey("Call"))
            {
                var call       = (string)_trigger["Call"] !;
                var callsCache = _ignite.GetCache <string, CallData>("calls");
                var callData   = await callsCache.GetAsync(call);

                callData.Result   = value;
                callData.Finished = true;
                await callsCache.ReplaceAsync(call, callData);
            }
            else
            {
                var stream = (string)_trigger["Stream"] !;

                if (value == null)
                {
                    return;
                }

                var asyncEnumerableInterface = PerperTypeUtils.GetGenericInterface(value.GetType(), typeof(IAsyncEnumerable <>));
                if (asyncEnumerableInterface == null)
                {
                    throw new NotSupportedException($"Expected IAsyncEnumerable<*> return from stream function, got: {value.GetType()}.");
                }

                var cacheType     = asyncEnumerableInterface.GetGenericArguments()[0];
                var processMethod = GetType().GetMethod(nameof(ProcessAsyncEnumerable), BindingFlags.NonPublic | BindingFlags.Instance) !
                                    .MakeGenericMethod(cacheType);

                await(Task) processMethod.Invoke(this, new object[] { stream, value, cancellationToken }) !;
            }
        }
Example #4
0
        /// <summary>
        /// Queries employees that have specific salary with a compiled query.
        /// </summary>
        /// <param name="cache">Cache.</param>
        private void CompiledQueryExample()
        {
            using (IIgniteClient client = Ignition.StartClient(this._igniteClientConfiguration))
            {
                var       cache     = client.GetCache <string, Employee>("Employees");
                const int minSalary = 200;
                var       queryable = cache.AsCacheQueryable();

                //this query causing issue
                Func <string, IQueryCursor <ICacheEntry <string, Employee> > > issueqry =
                    CompiledQuery.Compile((string empName) => queryable.Where(emp => emp.Value.Name == empName));

                //with this no issue
                Func <int, IQueryCursor <ICacheEntry <string, Employee> > > qry =
                    CompiledQuery.Compile((int min) => queryable.Where(emp => emp.Value.Salary == min));

                foreach (var entry in qry(minSalary))
                {
                    Console.WriteLine(">>>    " + entry.Value.Name);
                }

                foreach (var entry in issueqry("abc"))
                {
                    Console.WriteLine(">>>    " + entry.Value.Name);
                }
            }
        }
Example #5
0
        private async Task ExecuteAsync(Notification notification, CancellationToken cancellationToken)
        {
            var trigger = JObject.FromObject(notification);
            var input   = new TriggeredFunctionData {
                TriggerValue = trigger
            };
            var result = await _executor.TryExecuteAsync(input, cancellationToken);

            string?error = null;

            if (result.Exception != null && !(result.Exception is OperationCanceledException))
            {
                _logger.LogError($"Exception during execution: {result.Exception}");
                error = (result.Exception.InnerException ?? result.Exception).Message;
            }

            if (trigger.ContainsKey("Call"))
            {
                // TODO: Can we somehow detect that PerperTriggerValueBinder was already invoked for this?
                var call           = (string)trigger["Call"] !;
                var callsCache     = _ignite.GetCache <string, CallData>("calls");
                var callDataResult = await callsCache.TryGetAsync(call);

                if (callDataResult.Success)
                {
                    var callData = callDataResult.Value;
                    callData.Finished = true;
                    callData.Error    = error;
                    await callsCache.ReplaceAsync(call, callData);
                }
            }
        }
Example #6
0
        /// <summary>
        /// Execute individual Put and Get, getting value in binary format, without de-serializing it.
        /// </summary>
        /// <param name="ignite">Ignite instance.</param>
        private static void PutGetBinary(IIgniteClient ignite)
        {
            ICacheClient <int, Organization> cache = ignite.GetCache <int, Organization>(CacheName);

            // Create new Organization to store in cache.
            Organization org = new Organization(
                "Microsoft",
                new Address("1096 Eddy Street, San Francisco, CA", 94109),
                OrganizationType.Private,
                DateTime.Now
                );

            // Put created data entry to cache.
            cache.Put(1, org);

            // Create projection that will get values as binary objects.
            var binaryCache = cache.WithKeepBinary <int, IBinaryObject>();

            // Get recently created organization as a binary object.
            var binaryOrg = binaryCache.Get(1);

            // Get organization's name from binary object (note that  object doesn't need to be fully deserialized).
            string name = binaryOrg.GetField <string>("name");

            Console.WriteLine();
            Console.WriteLine(">>> Retrieved organization name from binary object: " + name);
        }
Example #7
0
        static void Main(string[] args)
        {
            var cfg = new IgniteClientConfiguration
            {
                Host = "127.0.0.1"
            };

            using (IIgniteClient client = Ignition.StartClient(cfg))
            {
                var cache = client.GetCache <string, Forex>("myCache");

                var forexWritten = Forex.CreateBuilder()
                                   .SetCommon(CommonFields.CreateBuilder().SetId("EUR").SetName("EUR").SetTimestamp(misysdatamodel.DateTime.DefaultInstance).SetSourceRef("tt").SetInstanceRef("zzz").Build())
                                   .AddQuotes(Forex.Types.ForexQuote.CreateBuilder().SetLast(12).Build())
                                   .Build();

                cache.Put("EUR", forexWritten);
                var f = cache.Get("EUR");

                //for (int i = 0; i < 10; i++)
                //    cache.Put(i, i.ToString());

                //for (int i = 0; i < 10; i++)
                //    Console.WriteLine("Got [key={0}, val={1}]", i, cache.Get(i));
            }
        }
        public CacheViewModel(IIgniteClient ignite, string cacheName)
        {
            // TODO: Binary mode.
            _cache = ignite.GetCache <object, object>(cacheName)
                     .WithKeepBinary <object, object>();

            Task.Run(() =>
            {
                CacheEntries = _cache.Query(new ScanQuery <object, object>()).Take(10).ToArray();
            });
        }
Example #9
0
        public async Task SetTriggerValue(JObject trigger)
        {
            // Done using binary, since this.Agent is sometimes needed while deserializing Parameters
            ICacheClient <string, IBinaryObject> instanceCache;

            if (trigger.ContainsKey("Call"))
            {
                InstanceName  = (string)trigger["Call"] !;
                instanceCache = _ignite.GetCache <string, CallData>("calls").WithKeepBinary <string, IBinaryObject>();
            }
            else
            {
                InstanceName  = (string)trigger["Stream"] !;
                instanceCache = _ignite.GetCache <string, StreamData>("streams").WithKeepBinary <string, IBinaryObject>();
            }

            var instanceDataBinary = await instanceCache.GetAsync(InstanceName);

            Agent      = instanceDataBinary.GetField <string>(nameof(IInstanceData.Agent));
            Parameters = instanceDataBinary.GetField <object>(nameof(IInstanceData.Parameters));

            _initialized = true;
        }
Example #10
0
        public static void Main()
        {
            Ignition.Start();

            var cfg = new IgniteClientConfiguration
            {
                Host = "192.168.1.35"
            };

            using (IIgniteClient client = Ignition.StartClient(cfg))
            {
                ICacheClient <int, string> cache = client.GetCache <int, string>("cache");
                cache.Put(1, "Hello, World!");
            }
            Console.ReadKey();
        }
Example #11
0
        /// <summary>
        /// Execute bulk Put and Get operations getting values in binary format, without de-serializing it.
        /// </summary>
        /// <param name="ignite">Ignite instance.</param>
        private static void PutAllGetAllBinary(IIgniteClient ignite)
        {
            ICacheClient <int, Organization> cache = ignite.GetCache <int, Organization>(CacheName);

            // Create new Organizations to store in cache.
            Organization org1 = new Organization(
                "Microsoft",
                new Address("1096 Eddy Street, San Francisco, CA", 94109),
                OrganizationType.Private,
                DateTime.Now
                );

            Organization org2 = new Organization(
                "Red Cross",
                new Address("184 Fidler Drive, San Antonio, TX", 78205),
                OrganizationType.NonProfit,
                DateTime.Now
                );

            var map = new Dictionary <int, Organization> {
                { 1, org1 }, { 2, org2 }
            };

            // Put created data entries to cache.
            cache.PutAll(map);

            // Create projection that will get values as binary objects.
            var binaryCache = cache.WithKeepBinary <int, IBinaryObject>();

            // Get recently created organizations as binary objects.
            ICollection <ICacheEntry <int, IBinaryObject> > binaryMap = binaryCache.GetAll(new List <int> {
                1, 2
            });

            Console.WriteLine();
            Console.WriteLine(">>> Retrieved organization names from binary objects:");

            foreach (var pair in binaryMap)
            {
                Console.WriteLine(">>>     " + pair.Value.GetField <string>("name"));
            }
        }
Example #12
0
        /// <summary>
        /// Execute individual Put and Get.
        /// </summary>
        /// <param name="ignite">Ignite instance.</param>
        private static void PutGet(IIgniteClient ignite)
        {
            ICacheClient <int, Organization> cache = ignite.GetCache <int, Organization>(CacheName);

            // Create new Organization to store in cache.
            Organization org = new Organization(
                "Microsoft",
                new Address("1096 Eddy Street, San Francisco, CA", 94109),
                OrganizationType.Private,
                DateTime.Now
                );

            // Put created data entry to cache.
            cache.Put(1, org);

            // Get recently created employee as a strongly-typed fully de-serialized instance.
            Organization orgFromCache = cache.Get(1);

            Console.WriteLine();
            Console.WriteLine(">>> Retrieved organization instance from cache: " + orgFromCache);
        }
Example #13
0
        public static void Main()
        {
            var cfg = new IgniteClientConfiguration
            {
                Host = "127.0.0.1"
            };

            using (IIgniteClient igniteClient = Ignition.StartClient(cfg))
            {
                Console.WriteLine();
                Console.WriteLine(">>> Cache put-get client example started.");

                ICacheClient <int, Organization> cache = igniteClient.GetCache <int, Organization>(CacheName);

                PutGet(cache);
            }

            Console.WriteLine();
            Console.WriteLine(">>> Example finished, press any key to exit ...");
            Console.ReadKey();
        }
Example #14
0
        public void IgniteOperations()
        {
            IgniteClientConfiguration _igniteClientConfiguration = new IgniteClientConfiguration
            {
                Endpoints     = new string[] { "localhost" },
                SocketTimeout = TimeSpan.FromSeconds(30)
            };
            Student student = new Student {
                Department = "ece", Year = 2, Name = "ABC", RoleNumber = "12-abc"
            };
            Lecturer lect = new Lecturer {
                Name = "ABC-L", Id = "LET-1"
            };

            using (IIgniteClient client = Ignition.StartClient(_igniteClientConfiguration))
            {
                try
                {
                    var cache = client.GetCache <string, ICollege>("college-code-123");
                    //create student
                    cache.Put(student.RoleNumber, student);
                    var sqlQuery = new SqlQuery(typeof(Student), "where Name = ?", "ABC");
                    var record   = cache.Query(sqlQuery).GetAll();

                    //create lecturer
                    cache.Put(lect.Id, lect);
                    var lectRec = cache.Get(lect.Id);
                    //create lecturer table since cache configuration not able to change for existing cache
                    var sQuery = CreateTable();
                    cache.Query(sQuery);

                    var lsqlQuery = new SqlQuery(typeof(Lecturer), "where Name = ?", "ABC-L");
                    var lrecord   = cache.Query(sqlQuery).GetAll();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
        }
Example #15
0
        /// <summary>
        /// Execute bulk Put and Get operations.
        /// </summary>
        /// <param name="ignite">Ignite instance.</param>
        private static void PutAllGetAll(IIgniteClient ignite)
        {
            ICacheClient <int, Organization> cache = ignite.GetCache <int, Organization>(CacheName);

            // Create new Organizations to store in cache.
            Organization org1 = new Organization(
                "Microsoft",
                new Address("1096 Eddy Street, San Francisco, CA", 94109),
                OrganizationType.Private,
                DateTime.Now
                );

            Organization org2 = new Organization(
                "Red Cross",
                new Address("184 Fidler Drive, San Antonio, TX", 78205),
                OrganizationType.NonProfit,
                DateTime.Now
                );

            var map = new Dictionary <int, Organization> {
                { 1, org1 }, { 2, org2 }
            };

            // Put created data entries to cache.
            cache.PutAll(map);

            // Get recently created organizations as a strongly-typed fully de-serialized instances.
            ICollection <ICacheEntry <int, Organization> > mapFromCache = cache.GetAll(new List <int> {
                1, 2
            });

            Console.WriteLine();
            Console.WriteLine(">>> Retrieved organization instances from cache:");

            foreach (ICacheEntry <int, Organization> org in mapFromCache)
            {
                Console.WriteLine(">>>     " + org.Value);
            }
        }
Example #16
0
        public T Get <T>(string key) where T : class
        {
            var cache = _ignite.GetCache <string, T>(CacheName);

            return(cache.Get(key));
        }
Example #17
0
 public IPerperStream DeclareStream(string streamName, string delegateName, Type?indexType = null)
 {
     return(new PerperFabricStream(streamName, false, null, null, delegateName, indexType, () => _igniteClient.GetCache <string, StreamData>("streams").RemoveAsync(streamName)));
 }
Example #18
0
 public PerperCollector(IIgniteClient ignite, PerperBinarySerializer serializer, string stream)
 {
     cache       = ignite.GetCache <long, object>(stream).WithKeepBinary <long, object>();
     _serializer = serializer;
 }