Ejemplo n.º 1
1
		// 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();
		}
Ejemplo n.º 2
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            // Allow saved page state to override the initial item to display
            if (pageState != null && pageState.ContainsKey("SelectedItem"))
            {
                navigationParameter = pageState["SelectedItem"];
            }

            var itemId = navigationParameter.ToString();
            var item = DataSource.Instance.GetItem(navigationParameter.ToString());
            this.DefaultViewModel["Item"] = item;
            this.DefaultViewModel["ItemElements"] = item.Elements;

            var serviceItem = DataSource.Instance.GetItem(itemId.Split('/').First());
            var odataClient = new ODataClient(serviceItem.Subtitle);
            var results = (odataClient.FindEntries(itemId.Split('/').Last()).Take(10));

            foreach (var key in results.First().Keys)
            {
                this.gridResult.ColumnDefinitions.Add(new ColumnDefinition());
            }
            for (int index = 0; index < results.Count(); index++)
            {
                this.gridResult.RowDefinitions.Add(new RowDefinition());
            }
            this.DefaultViewModel["QueryResults"] = results.Select(x => x.Values.ToArray());
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataBase"/> class with a <paramref name="clientSettings"/>.
 /// </summary>
 /// <param name="clientSettings">The <see cref="Soc.ODataClientSettings"/>.</param>
 /// <remarks><i>Note:</i> Overrides the <see cref="Soc.ODataClientSettings.IgnoreResourceNotFoundException"/> to <c>true</c> by design.</remarks>
 protected ODataBase(Soc.ODataClientSettings clientSettings)
 {
     ClientSettings = Check.NotNull(clientSettings, nameof(clientSettings));
     ClientSettings.IgnoreResourceNotFoundException = true;
     ClientSettings.PreferredUpdateMethod           = Soc.ODataUpdateMethod.Patch;
     Client = new Soc.ODataClient(ClientSettings);
 }
        private async Task<IEnumerable<IDictionary<string, object>>> IterateEntriesAsync(
            string collection, string commandText, IDictionary<string, object> entryData, bool resultRequired,
            Func<string, IDictionary<string, object>, IDictionary<string, object>, bool, Task<IDictionary<string, object>>> func)
        {
            IEnumerable<IDictionary<string, object>> result = null;

            var entryKey = ExtractKeyFromCommandText(collection, commandText);
            if (entryKey != null)
            {
                result = new [] { await func(collection, entryKey, entryData, resultRequired) };
            }
            else
            {
                var client = new ODataClient(_settings);
                var entries = await client.FindEntriesAsync(commandText);
                if (entries != null)
                {
                    var entryList = entries.ToList();
                    var resultList = new List<IDictionary<string, object>>();
                    foreach (var entry in entryList)
                    {
                        resultList.Add(await func(collection, entry, entryData, resultRequired));
                    }
                    result = resultList;
                }
            }

            return result;
        }
 private async Task<int> IterateEntriesAsync(
     string collection, string commandText, 
     Func<string, IDictionary<string, object>, Task> func)
 {
     var result = 0;
     var entryKey = ExtractKeyFromCommandText(collection, commandText);
     if (entryKey != null)
     {
         await func(collection, entryKey);
         result = 1;
     }
     else
     {
         var client = new ODataClient(_settings);
         var entries = await client.FindEntriesAsync(commandText);
         if (entries != null)
         {
             var entryList = entries.ToList();
             foreach (var entry in entryList)
             {
                 await func(collection, entry);
                 ++result;
             }
         }
     }
     return result;
 }
 private int IterateEntries(string collection, string commandText, IDictionary<string, object> entryData,
     Func<string, IDictionary<string, object>, IDictionary<string, object>, int> func)
 {
     var entryKey = ExtractKeyFromCommandText(collection, commandText);
     if (entryKey != null)
     {
         return func(collection, entryKey, entryData);
     }
     else
     {
         var entries = new ODataClient(_settings).FindEntries(commandText);
         if (entries != null)
         {
             var entryList = entries.ToList();
             foreach (var entry in entryList)
             {
                 func(collection, entry, entryData);
             }
             return entryList.Count;
         }
         else
         {
             return 0;
         }
     }
 }
Ejemplo n.º 7
0
		public MainViewModel( CommandClient jason, ODataClient odata )
		{
			this.jason = jason;
			this.odata = odata;

			this.People = new ObservableCollection<PersonView>();
		}
        protected override void Initialize()
        {
            base.Initialize();

            lock (SyncLock)
            {
                _client = new ODataClient(_baseUri);
            }
        }
        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);
        }
 public ActionTests()
 {
     _server = TestServer.Create<ActionStartup>();
     _client = new ODataClient(new ODataClientSettings()
     {
         BaseUri = new Uri("http://localhost/actions"),
         PayloadFormat = ODataPayloadFormat.Json,
         OnCreateMessageHandler = () => _server.Handler,
         OnTrace = (x,y) => Console.WriteLine(string.Format(x,y)),
     });
 }
Ejemplo n.º 11
0
        public async void CanReceiveMetadataFromServer()
        {
            var client = new ODataClient("http://localhost:9000/odata");
            var metadata = await client.GetMetadataAsync<IEdmModel>();

            var entityTypes = metadata.SchemaElements.OfType<IEdmEntityType>().ToArray();

            foreach (var type in entityTypes)
            {
                Console.WriteLine("{0}{{{1}}}", type.Name, string.Join(",", type.Properties().Select(p => p.Name).ToArray()));
            }
        }
		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);
			}
		}
Ejemplo n.º 13
0
        // 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;
        }
Ejemplo n.º 14
0
		public void Install( IWindsorContainer container, IConfigurationStore store )
		{
			container.Register(
				Component.For<CommandClient>()
					.UsingFactoryMethod( () => 
					{
						string baseAddress = ConfigurationManager.AppSettings[ "jason/baseAddress" ];
						var client = new CommandClient( baseAddress );

						return client;
					} )
				);

			container.Register(
				Component.For<ODataClient>()
					.UsingFactoryMethod( () =>
					{
						string baseAddress = ConfigurationManager.AppSettings[ "odata/baseAddress" ];
						var client = new ODataClient( baseAddress );

						return client;
					} )
				);
		}
Ejemplo n.º 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataBatch"/> class.
 /// </summary>
 /// <param name="client">The OData client which will be used to create a batch.</param>
 /// <param name="reuseSession">Flag indicating that the existing session from the <see cref="ODataClient"/>
 /// should be used rather than creating a new one.
 /// </param>
 public ODataBatch(IODataClient client, bool reuseSession)
 {
     _client = reuseSession
         ? new ODataClient((client as ODataClient), _entryMap)
         : new ODataClient((client as ODataClient).Session.Settings, _entryMap);
 }
Ejemplo n.º 16
0
 internal MediaClient(ODataClient client, Session session, FluentCommand command = null, bool dynamicResults = false)
     : base(client, session, null, command, dynamicResults)
 {
 }
Ejemplo n.º 17
0
 internal BoundClient(ODataClient client, Session session, FluentCommand parentCommand = null, FluentCommand command = null, bool dynamicResults = false)
     : base(client, session, parentCommand, command, dynamicResults)
 {
 }
Ejemplo n.º 18
0
 private async Task SynchronizeSchemasAsync(ODataClient client, string path)
 {
     foreach (string dataItemPath in ValidateUniquenes(Directory.GetFiles(path, "*.jsrep.json", SearchOption.AllDirectories)))
     {
         await
             CreateOrUpdateDataItemInner(
                 Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(dataItemPath)),
                 File.ReadAllText(dataItemPath), client);
     }
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataBatch"/> class.
 /// </summary>
 /// <param name="settings">The settings.</param>
 public ODataBatch(ODataClientSettings settings)
 {
     _client = new ODataClient(settings, _entryMap);
 }
        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();
        }
Ejemplo n.º 21
0
 internal ODataClient(ODataClient client, ODataResponse batchResponse)
 {
     _settings      = client._settings;
     _session       = client.Session;
     _batchResponse = batchResponse;
 }
 internal ODataClient(ODataClient client)
 {
     _settings      = client._settings;
     _session       = client.Session;
     _requestRunner = client._requestRunner;
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataBatch"/> class.
 /// </summary>
 /// <param name="client">The OData client which settings will be used to create a batch.</param>
 public ODataBatch(IODataClient client)
 {
     _client = new ODataClient((client as ODataClient).Session.Settings, true);
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataBatch"/> class.
 /// </summary>
 /// <param name="settings">The settings.</param>
 public ODataBatch(ODataClientSettings settings)
 {
     _client = new ODataClient(settings, true);
 }
Ejemplo n.º 25
-1
        private ODataClient GetODataClient(IAdapterTransaction transaction = null)
        {
            ODataClient client;
            var adapterTransaction = transaction as ODataAdapterTransaction;
            if (adapterTransaction != null)
            {
                client = new ODataClient(adapterTransaction.Batch);
            }
            else
            {
                client = new ODataClient(_clientSettings);
            }

            var adapterPluralizer = Database.GetPluralizer();
            if (adapterPluralizer != null)
            {
                var clientPluralizer = new Pluralizer(adapterPluralizer.Pluralize, adapterPluralizer.Singularize);
                ODataClient.SetPluralizer(clientPluralizer);
            }

            return client;
        }
 public ODataClientWithCommand(ODataClient client, ISchema schema, ODataCommand parent = null)
 {
     _client = client;
     _schema = schema;
     _command = new ODataCommand(this, parent);
 }
		public HomeViewController ()
		{
			client = new ODataClient ("http://services.odata.org/v3/Northwind/Northwind.svc/");
		}
Ejemplo n.º 28
-1
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataBatch"/> class.
 /// </summary>
 /// <param name="settings">The settings.</param>
 public ODataBatch(ODataClientSettings settings)
 {
     _client = new ODataClient(settings, _entryMap);
 }
Ejemplo n.º 29
-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);
                }
            }
        }
Ejemplo n.º 30
-1
 /// <summary>
 /// Initializes a new instance of the <see cref="ODataBatch"/> class.
 /// </summary>
 /// <param name="client">The OData client which settings will be used to create a batch.</param>
 public ODataBatch(IODataClient client)
 {
     _client = new ODataClient((client as ODataClient).Session.Settings, _entryMap);
 }
Ejemplo n.º 31
-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);
            }
        }