// args[0] = Dump path
		// args[1] = Number of packages to fetch
		// args[2] = Dump partition size

		static void Main(string[] args)
		{
			var client = new ODataClient("https://www.nuget.org/api/v2/");

			var totalPackageCount = client.For<FeedPackage>("packages").Count().FindScalarAsync<int>().Result;

			var dumpPath = args[0];
			var numberOfPackages = (args[1] == "0") ? totalPackageCount : Convert.ToInt32(args[1]);
			var partitionSize = (args[2] == "0") ? totalPackageCount : Convert.ToInt32(args[2]);

			var startTime = DateTime.Now;
			var take = Math.Min(100, numberOfPackages);
			var numberOfPages = (int)Math.Ceiling((double)numberOfPackages / (double)take);

			var sync = new object();
			var packages = new List<FeedPackage>();
			int page = 0, partition = 0;
			var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = 4 };
			using (var pbar = new ProgressBar(numberOfPages, "Downloading nuget data.."))
			{
				Parallel.For(0, numberOfPages, parallelOptions, (i, state) =>
				{
					var foundPackages = client.For<FeedPackage>("packages")
					.Skip(i * take)
					.Top(take)
					.FindEntriesAsync().Result;

					lock (sync)
					{
						packages.AddRange(foundPackages);
						if (packages.Count() >= partitionSize)
						{
							WritePackages(packages, dumpPath, partition);
							partition++;
							packages = new List<FeedPackage>();
						}
					}
					Interlocked.Increment(ref page);
					pbar.Tick(string.Format("Downloaded {0}/{1} pages, written {2} files", page, numberOfPages, partition));
				});
			}

			var span = DateTime.Now - startTime;
			Console.WriteLine("Harvesting completed in: {0}.", span);
			Console.WriteLine("Press any key to quit");
			Console.Read();
		}
        public async Task<PackageResult> GetPackages(int startAt)
        {
            var client = new ODataClient("http://chocolatey.org/api/v2");
            var packages = await client.For<Package>()
                .OrderByDescending(x => x.DownloadCount)
                .FindEntriesWithCountAsync();

            return new PackageResult(packages.Item1.ToList(), packages.Item2);
        }
		private static async Task GetTweets()
		{
			var client = new ODataClient("http://localhost/TwitterApi/api");
			var result = await client.For<Tweet>()
									 .Filter(f => f.Date > new System.DateTimeOffset(2015, 5, 2, 0, 0, 0, TimeSpan.Zero))
									 .OrderBy(f => f.User.FirstName) // See bottom comment why this doesn't work. 
									 .Expand(f => f.User)
									 .FindEntriesAsync();

			foreach (var tweet in result)
			{
				Console.WriteLine("{0}: {1}", tweet.User.FirstName, tweet.Text);
			}
		}
        // Async method to call Remote WCF Service
        static async Task<int> MainAsync(string[] args) {
            var annotations = new ODataFeedAnnotations();
            // define uri WCF service to connect to
            var client = new ODataClient("http://services.odata.org/V4/TripPinServiceRW/");
            var x = ODataDynamic.Expression;
            var duration = TimeSpan.FromHours(4);
            // LINQ Query
            var flights = await client
                .For(x.People)
                .Filter(x.Trips
                .All(x.PlanItems
                    .Any(x.Duration < duration))
                    )
                .FindEntriesAsync();

            foreach (var entry in flights) {
                Console.WriteLine(String.Format("Person [ UserName: {0} FirstName: {1} LastName: {2} Emails: {3} Gender: {4} ]", entry.UserName, entry.FirstName, entry.LastName, entry.Emails[0], entry.Gender));
            }

            Console.WriteLine("--- WCF Client ODATA Query Execution Completed. Press ENTER to exit. ---");
            Console.ReadKey();
            return 1;
        }
        private async Task<IEnumerable<Package>> FindPackagesAsync()
        {
            int count = 0;
            switch (_resultSizePicker.SelectedIndex)
            {
                case 0:
                    count = 10;
                    break;
                case 1:
                    count = 25;
                    break;
                case 2:
                    count = 100;
                    break;
            }

            var odataClient = new ODataClient("https://nuget.org/api/v1");
            var command = odataClient
                .For<Package>("Packages")
                .OrderByDescending(x => x.DownloadCount)
                .Top(count);

            switch (_sortPicker.SelectedIndex)
            {
                case 0:
                    command.OrderByDescending(x => x.DownloadCount);
                    break;
                case 1:
                    command.OrderBy(x => x.Id);
                    break;
                case 2:
                    command.OrderByDescending(x => x.LastUpdated);
                    break;
            }

            if (!string.IsNullOrEmpty(_searchText.Text))
            {
                command.Filter(x => x.Title.Contains(_searchText.Text) && x.IsLatestVersion);
            }
            else
            {
                command.Filter(x => x.IsLatestVersion);
            }

            command.Select(x => new { x.Id, x.Title, x.Version, x.LastUpdated, x.DownloadCount, x.VersionDownloadCount, x.PackageSize, x.Authors, x.Dependencies });

            return await command.FindEntriesAsync();
        }
Example #6
-1
        private async Task SynchronizeImagesAsync(ODataClient client, string path)
        {
            foreach (string imagePath in ValidateUniquenes(Directory.GetFiles(path, "*.jsrep.png", SearchOption.AllDirectories)))
            {
                string imageName = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(imagePath));
                dynamic operation = new ExpandoObject();
                operation.content = File.ReadAllBytes(imagePath);
                operation.shortid = imageName;
                operation.contentType = "image/png";
                operation.name = operation.shortid;

                var image = await (client.For<Image>().Filter(x => x.name == imageName).FindEntryAsync()).ConfigureAwait(false);

                if (image == null)
                {
                    await ((Task)client.For<Image>().Set(operation).InsertEntryAsync()).ConfigureAwait(false);
                }
                else
                {
                    operation._id = image._id;
                    await ((Task)client.For<Image>().Key(operation._id).Set(operation).UpdateEntryAsync()).ConfigureAwait(false);
                }
            }
        }
Example #7
-1
        private static async Task CreateOrUpdateDataItemInner(string name, string content, ODataClient client)
        {
            dynamic operation = new ExpandoObject();
            operation.dataJson = content;
            operation.shortid = name;
            operation.name = operation.shortid;

            var dataItem =
                await (client.For<DataItem>("data").Filter(x => x.name == name).FindEntryAsync()).ConfigureAwait(false);

            if (dataItem == null)
            {
                await ((Task) client.For<DataItem>("data").Set(operation).InsertEntryAsync()).ConfigureAwait(false);
            }
            else
            {
                operation._id = dataItem._id;
                await
                    ((Task) client.For<DataItem>("data").Key(dataItem._id).Set(operation).UpdateEntryAsync())
                        .ConfigureAwait(false);
            }
        }