コード例 #1
0
        /// <summary> Aliases the current stream under a certain name. </summary>
        private static void CmdAlias(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Usage: alias <name>");
                Console.WriteLine("Aliases current stream under provided name.");
                return;
            }

            var name = args[0];

            if (Fetched.ContainsKey(name))
            {
                Console.WriteLine("Stream `{0}` already exists.", name);
                Console.WriteLine("Use `drop {0}` to drop it.", name);
                return;
            }

            if (Current == null)
            {
                Console.WriteLine("No current stream to alias.");
                return;
            }

            Console.WriteLine("Aliased `{0}` ({1} events).", name, Current.Count);
            Fetched.Add(name, Current);
        }
コード例 #2
0
        public IActionResult Index()
        {
            int howManyFetchedToday     = GetHowManyFetchedToday();
            int howManyFetchedThisWeek  = GetHowManyFetchedThisWeek();
            int howManyFetchedThisMonth = GetHowManyFetchedThisMonth();
            int howManyFetchedOverall   = _context.Forecasts.Count();

            var distinct         = _context.Forecasts.Select(x => x.Provider).Distinct().ToList();
            var providersFetched = new ProvidersFetched
            {
                ProviderFetched = new List <Fetched>()
            };

            foreach (var item in distinct)
            {
                var addition = new Fetched
                {
                    Providers = item,
                    HowMany   = _context.Forecasts.Where(x => x.Provider == item).Count()
                };
                providersFetched.ProviderFetched.Add(addition);
            }
            return(View(new StatisticsViewModel
            {
                HowManyFetchedToday = howManyFetchedToday,
                HowManyFetchedThisWeek = howManyFetchedThisWeek,
                HowManyFetchedThisMonth = howManyFetchedThisMonth,
                ProvidersFetched = providersFetched,
                HowManyFetchedAllTime = howManyFetchedOverall
            }));
        }
コード例 #3
0
        /// <summary> Peek at the end of a stream. </summary>
        private static void CmdPeek(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Usage: peek <count> ; peek <name> <count>");
            }

            var stream = Current;
            var count  = 10;

            if (args.Length == 1)
            {
                count = int.Parse(args[0]);
            }

            if (args.Length == 2)
            {
                count = int.Parse(args[1]);
                if (!Fetched.TryGetValue(args[0], out stream))
                {
                    Console.WriteLine("No fetched stream `{0}`.", args[0]);
                    return;
                }
            }

            if (stream == null)
            {
                Console.WriteLine("No current stream.");
                return;
            }

            if (count < 1)
            {
                count = 1;
            }

            for (var i = 0; i < count && i < stream.Count; ++i)
            {
                Show(stream[stream.Count - i - 1]);
            }
        }
コード例 #4
0
        /// <summary> Drops events from <see cref="Fetched"/>. </summary>
        private static void CmdDrop(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Usage: drop <name>");
                Console.WriteLine("Drops a fetched stream from memory.");
                return;
            }

            var name = args[0];
            IReadOnlyList <EventData> list;

            if (!Fetched.TryGetValue(name, out list))
            {
                Console.WriteLine("No fetched stream `{0}`.", name);
                return;
            }

            Console.WriteLine("Dropped `{0}` ({1} events).", name, list.Count);

            Fetched.Remove(name);
        }
コード例 #5
0
        /// <summary> Use the named fetched stream as the current one. </summary>
        private static void CmdUse(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Usage: use <name>");
                Console.WriteLine("Uses named stream as current one.");
                return;
            }

            var name = args[0];
            IReadOnlyList <EventData> list;

            if (!Fetched.TryGetValue(name, out list))
            {
                Console.WriteLine("No fetched stream `{0}`.", name);
                return;
            }

            Console.WriteLine("Current is `{0}` ({1} events).", name, list.Count);

            Current = list;
            Peek(list);
        }
コード例 #6
0
        //Cycles
        public void fetch()
        {
            //First Get the instruction from the address of the pc counter.
            //Since the memory can load directly without the need of the full address,
            //Calculate the offset
            int offset = PC - 4194304;

            //Now fetch;
            IR = Mem.loadInstruction(offset);

            //First check if IR =0
            int IR_int = Convert.ToInt32(IR, 2);

            if (IR_int == 0)
            {
                //Now check if Clock == 0;
                if (clock == 0)
                {
                    running = false;
                    EmptyInstructions.Invoke();
                }
                else
                {
                    running = false;
                    Terminate_Dropped.Invoke("Program Dropped...\n");
                }
            }
            else
            {
                running = true;

                //Now increment the PC;
                PC += 4; //by one because LoadInstruction handles the stuff.. ;)

                Fetched.Invoke();
            }
        }
コード例 #7
0
 private static async Task <XDocument> LoadFromUrlAsync(Uri url)
 {
     using (var httpClient = new HttpClient())
     {
         httpClient.DefaultRequestHeaders.Add(
             "User-Agent",
             "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.3; WOW64; Trident/7.0; Touch; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; Tablet PC 2.0)");
         Fetching?.Invoke(null, new FetchingEventArgs(url));
         try
         {
             using (var hs = await httpClient.GetStreamAsync(url))
             {
                 var document = SgmlReader.Parse(hs);
                 Fetched?.Invoke(null, new FetchedEventArgs(url, document, null));
                 return(document);
             }
         }
         catch (Exception ex)
         {
             Fetched?.Invoke(null, new FetchedEventArgs(url, null, ex));
             throw;
         }
     }
 }
コード例 #8
0
 public override string ToString()
 {
     return($"Id:{Id}, Url:{Url}, Fetched:{Fetched.ToString()}, Name:{Name}, Location: {Location}, Disabled: {Disabled.ToString()}");
 }
コード例 #9
0
        private static void CmdAppend(string[] args)
        {
            if (args.Length != 1 && args.Length != 2)
            {
                Console.WriteLine("Usage: append <stream> <local>?");
                Console.WriteLine("Appends events to a stream, discarding sequence ids.");
                return;
            }

            // The stream from which to append
            IReadOnlyList <EventData> from;

            if (args.Length == 1)
            {
                if (Current == null)
                {
                    Console.WriteLine("No current stream available.");
                    return;
                }

                from = Current;
            }
            else
            {
                if (!Fetched.TryGetValue(args[1], out from))
                {
                    Console.WriteLine("Stream '{0}' does not exist.", args[1]);
                    return;
                }
            }

            // The stream to which to append
            var into = args[0];

            var dstDriver = new StorageConfiguration(Parse(into)).Connect();

            using (Release(dstDriver))
            {
                var dst = new MigrationStream <JObject>(dstDriver);

                var sw     = Stopwatch.StartNew();
                var events = 0;

                Task.Run((Func <Task>)(async() =>
                {
                    Status("Current destination seq: ...");
                    var bakSeq = await dstDriver.GetLastKeyAsync();
                    Console.WriteLine("Current destination seq: {0}", bakSeq);

                    ++bakSeq;

                    while (events < @from.Count)
                    {
                        Status("Appending: {0}/{1}",
                               events,
                               @from.Count);

                        var list = new List <KeyValuePair <uint, JObject> >();
                        for (var i = 0; i < 1000 && events < @from.Count; ++i, ++events, ++bakSeq)
                        {
                            list.Add(new KeyValuePair <uint, JObject>(bakSeq, @from[events].Event));
                        }

                        events += list.Count;

                        await dst.WriteAsync(list);
                    }
                })).Wait();

                Console.WriteLine("Appended {0} events in {1:F2}s.",
                                  events,
                                  sw.ElapsedMilliseconds / 1000.0);
            }
        }
コード例 #10
0
        /// <summary> Fetches a stream's events and places it in <see cref="Fetched"/>. </summary>
        private static void CmdFetch(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Usage: fetch <name> <stream> <limit>?");
                Console.WriteLine("Downloads events from remote stream, stores in-memory.");
                Console.WriteLine("  limit: if provided, only fetch events after this seq (included).");
                return;
            }

            var name = args[0];

            if (Fetched.ContainsKey(name))
            {
                Console.WriteLine("Fetched stream `{0}` already exists.", name);
                Console.WriteLine("Use `drop {0}` to drop it.", name);
                return;
            }

            var limit = 0u;

            if (args.Length == 3)
            {
                if (!uint.TryParse(args[2], out limit))
                {
                    Console.WriteLine("Could not parse limit: {0}", args[2]);
                    return;
                }
            }

            var sw = Stopwatch.StartNew();

            var connection = new StorageConfiguration(Parse(args[1]))
            {
                ReadOnly = true
            };

            connection.Trace = true;

            var driver = connection.Connect();

            using (Release(driver))
            {
                var stream = new EventStream <JObject>(driver);
                var list   = new List <EventData>();
                var start  = 0L;

                Status("Connecting...");

                Task.Run((Func <Task>)(async() =>
                {
                    Status("Current size:");
                    var maxPos = await driver.GetPositionAsync();
                    Console.WriteLine("Current size: {0:F2} MB", maxPos / (1024.0 * 1024.0));

                    Status("Current seq:");
                    var maxSeq = await driver.GetLastKeyAsync();
                    Console.WriteLine("Current seq: {0}", maxSeq);

                    var asStatsDriver    = driver as StatsDriverWrapper;
                    var asReadOnlyDriver = (asStatsDriver?.Inner ?? driver) as ReadOnlyDriverWrapper;
                    var asAzure          = (asReadOnlyDriver?.Wrapped ?? asStatsDriver?.Inner ?? driver) as AzureStorageDriver;

                    if (asAzure != null)
                    {
                        for (var i = 0; i < asAzure.Blobs.Count; ++i)
                        {
                            Console.WriteLine("Blob {0}: {1:F2} MB from seq {2}",
                                              asAzure.Blobs[i].Name,
                                              asAzure.Blobs[i].Properties.Length / (1024.0 * 1024.0),
                                              i < asAzure.FirstKey.Count ? asAzure.FirstKey[i] : maxSeq);
                        }
                    }

                    if (limit > 0)
                    {
                        Status($"Moving to seq {limit} ..");
                        await stream.DiscardUpTo(limit);
                        start = stream.Position;
                    }

                    Func <bool> more;
                    do
                    {
                        var fetch = stream.BackgroundFetchAsync();

                        JObject obj;
                        while ((obj = stream.TryGetNext()) != null)
                        {
                            list.Add(new EventData(stream.Sequence, obj));
                        }

                        Status("Fetching: {0}/{1} ({2:F2}/{3:F2} MB)",
                               stream.Sequence,
                               maxSeq,
                               (stream.Position - start) / (1024.0 * 1024.0),
                               (maxPos - start) / (1024.0 * 1024.0));

                        more = await fetch;
                    } while (more());
                })).Wait();

                Console.WriteLine("Fetched `{0}` ({1} events, {2:F2} MB) in {3:F2}s.",
                                  name,
                                  list.Count,
                                  (stream.Position - start) / (1024.0 * 1024.0),
                                  sw.ElapsedMilliseconds / 1000.0);

                Fetched.Add(name, list);

                Peek(list);

                if (Current == null)
                {
                    Current = list;
                }
            }
        }