/// <summary>
        /// Initialize all the config values
        /// </summary>
        public WBTopicsWebServiceRest(PersistenceManager manager, WorldBankOrgOSDatabase db,
                                      ProducerConsumerService tasksConsumerService)
            : base(tasksConsumerService, new WBWebServiceRestConfig())
        {
            config.UniqueName         = "topics";
            config.RelativeUriPath    = config.UniqueName;
            config.RootXPath          = $@"//wb:{config.UniqueName}";
            config.XPathDataNodes     = ".//wb:topic";
            config.PersistenceManager = manager;
            config.Database           = db;

            RequestCompleted += Program.WBTopicsWebServiceRestCompleted;
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="db"></param>
        public WBIndicatorsPerTopicWebServiceRest(int topicId, PersistenceManager manager, WorldBankOrgOSDatabase db,
                                                  ProducerConsumerService tasksConsumerService)
            : base(tasksConsumerService, new WBWebServiceRestConfig())
        {
            TopicId                   = topicId;
            config.UniqueName         = "indicators";
            config.RelativeUriPath    = $"topics/{TopicId}/{config.UniqueName}";
            config.RootXPath          = $@"//wb:{config.UniqueName}";
            config.XPathDataNodes     = ".//wb:indicator";
            config.PersistenceManager = manager;
            config.Database           = db;

            RequestCompleted += Program.WBIndicatorsPerTopicWebServiceRestCompleted;
        }
    static void Main(string[] args)
    {
        var cts           = new CancellationTokenSource();
        var service       = new Service();
        var serviceClient = new ServiceClient();
        var processor     = new ProducerConsumerService(serviceClient, service);

        processor.Process("A", cts.Token);
        processor.Process("B", cts.Token);
        processor.Process("C", cts.Token);
        processor.Process("D", cts.Token);

        Console.WriteLine("Press any key to shutdown");
        Console.Read();

        cts.Cancel();
        processor.WaitForCompletion();
    }
Exemple #4
0
        public static async Task Process()
        {
            try
            {
                tasksConsumerService   = new ProducerConsumerService(100);
                programAllTasks        = new ConcurrentBag <Task>();
                persistenceManagerList = new ConcurrentBag <PersistenceManager>();
                persistenceManagerMain = new PersistenceManager("WorldBank",
                                                                (topic) => new SqlitePersistContext(topic));

                persistenceManagerList.Add(persistenceManagerMain);

                // Create the database
                databaseModel = new WorldBankOrgOSDatabase();
                databaseModel.Create(persistenceManagerMain);

                var wbTopics = new WBTopicsWebServiceRest(persistenceManagerMain, databaseModel, tasksConsumerService);
                wbTopics.Read();

                tasksConsumerService.Wait();

                //while (programAllTasks.Any(t => !t.IsCompleted))
                //{
                //    await Task.WhenAll(programAllTasks.ToArray());
                //}

                var persistenceTaskList = new List <Task>();
                foreach (var item in persistenceManagerList)
                {
                    persistenceTaskList.Add(Task.Factory.StartNew(() => item.Wait()));
                }

                await Task.WhenAll(persistenceTaskList.ToArray());
            }
            finally
            {
            }
        }
 /// <summary>
 /// Constructor
 /// </summary>
 public WBWebServiceRest(ProducerConsumerService tasksConsumerService, WBWebServiceRestConfig config)
 {
     this.config = config;
     Result      = new ConcurrentBag <T>();
     this.tasksConsumerService = tasksConsumerService;
 }