コード例 #1
0
        public static void Main(string[] args)
        {
            StatXClient statxClient = new StatXClient();

            Configuration configuration = statxClient.getConfiguration();

            Console.WriteLine("Enter Stat Title");

            string statTitle = Console.ReadLine();

            string    groupName = "StatX-API-Examples";
            GroupsApi groupsApi = new GroupsApi(configuration);
            GroupList groupList = groupsApi.GetGroups(groupName);
            Group     group;

            if ((groupList == null) || (groupList.Data == null) || (groupList.Data.Count == 0))
            {
                // The group does not exist. Let's create one. Since we are creating the group
                // the api will add the current user as a member and admin of the group.
                group = new Group(null, groupName, null);
                group = groupsApi.CreateGroup(group);
            }
            else
            {
                // Pick the first group (should be the only one).
                group = groupList.Data[0];
            }

            // Find the stat by name. If the stat does not exist then create it.
            //
            // Note: The stat title is not unique. In general it is not a good idea to use
            // the stat title as a key to determine whether the stat exists or not. If possible
            // use the statid instead.
            StatsApi statsApi = new StatsApi(configuration);
            StatList statList = statsApi.GetStats(group.Name, statTitle);

            if ((statList == null) || (statList.Data == null) || (statList.Data.Count == 0))
            {
                // The stat does not exist. Let's create a number stat.
                HorizontalBarStat horizontalBar = new HorizontalBarStat();
                horizontalBar.Title      = statTitle;
                horizontalBar.VisualType = Stat.VisualTypeEnum.HorizontalBars;
                horizontalBar.Items      = getStockInfo();
                statsApi.CreateStat(group.Id, horizontalBar);
            }
            else
            {
                // Pick the first stat (should be the only one) and get the statId from it.
                string            statId            = statList.Data[0].Id;
                HorizontalBarStat horizontalBarStat = (HorizontalBarStat)statList.Data[0];

                // Create the stat to update.
                HorizontalBarStat newHorizontalBardStat = new HorizontalBarStat();
                newHorizontalBardStat.Items = getStockInfo();
                newHorizontalBardStat.LastUpdatedDateTime = DateTime.Now;
                statsApi.UpdateStat(group.Id, statId, newHorizontalBardStat);
            }

            Console.WriteLine("Last update at: " + DateTime.Now);
        }
コード例 #2
0
        public IndiebackendAPI(string appId)
        {
            _http = new HttpUtils(Constants.API_GATEWAY, appId);

            // HTTP Services initialization

            Players  = new PlayersApi(_http);
            Profiles = new ProfilesApi(_http);
            Groups   = new GroupsApi(_http);
            Stats    = new StatsApi(_http);
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LazyManChannel"/> class.
        /// </summary>
        /// <param name="httpClientFactory">Instance of the <see cref="IHttpClientFactory"/> interface.</param>
        /// <param name="loggerFactory">Instance of the <see cref="ILoggerFactory"/> interface.</param>
        /// <param name="powerSportsApi">Instance of the <see cref="PowerSportsApi"/>.</param>
        public LazyManChannel(IHttpClientFactory httpClientFactory, ILoggerFactory loggerFactory, PowerSportsApi powerSportsApi)
        {
            _logger = loggerFactory.CreateLogger <LazyManChannel>();
            var statsApiLogger = loggerFactory.CreateLogger <StatsApi>();

            _nhlStatsApi    = new StatsApi(httpClientFactory, statsApiLogger, "nhl");
            _mlbStatsApi    = new StatsApi(httpClientFactory, statsApiLogger, "MLB");
            _powerSportsApi = powerSportsApi;

            _gameCache = new ConcurrentDictionary <string, CacheItem <List <Game> > >();
        }
コード例 #4
0
        public LazyManChannel(IHttpClient httpClient, IJsonSerializer jsonSerializer, ILogManager logManager)
        {
            _logger = logManager.GetLogger(GetType().Name);

            _nhlStatsApi = new StatsApi(httpClient, _logger, jsonSerializer, "nhl");
            _mlbStatsApi = new StatsApi(httpClient, _logger, jsonSerializer, "MLB");

            _powerSportsApi = new PowerSportsApi(httpClient, _logger);

            _jsonSerializer = jsonSerializer;
            _gameCache      = new ConcurrentDictionary <string, CacheItem <List <Game> > >();
        }
コード例 #5
0
        /// <summary>
        /// Creates a client to work with VK API methods.
        /// </summary>
        public CitrinaClient()
        {
            AuthHelper = new AuthHelper();
            Execute    = new ExecuteApi();

            Account       = new AccountApi();
            Ads           = new AdsApi();
            Apps          = new AppsApi();
            Auth          = new AuthApi();
            Board         = new BoardApi();
            Database      = new DatabaseApi();
            Docs          = new DocsApi();
            Fave          = new FaveApi();
            Friends       = new FriendsApi();
            Gifts         = new GiftsApi();
            Groups        = new GroupsApi();
            Leads         = new LeadsApi();
            Likes         = new LikesApi();
            Market        = new MarketApi();
            Messages      = new MessagesApi();
            Newsfeed      = new NewsfeedApi();
            Notes         = new NotesApi();
            Notifications = new NotificationsApi();
            Orders        = new OrdersApi();
            Pages         = new PagesApi();
            Photos        = new PhotosApi();
            Places        = new PlacesApi();
            Polls         = new PollsApi();
            Search        = new SearchApi();
            Secure        = new SecureApi();
            Stats         = new StatsApi();
            Status        = new StatusApi();
            Storage       = new StorageApi();
            Users         = new UsersApi();
            Utils         = new UtilsApi();
            Video         = new VideoApi();
            Wall          = new WallApi();
            Widgets       = new WidgetsApi();
        }
コード例 #6
0
 public void Init()
 {
     instance = new StatsApi();
 }
コード例 #7
0
        void Init()
        {
            // Init the core api inteface.
            Bitswap         = new BitswapApi(this);
            Block           = new BlockApi(this);
            BlockRepository = new BlockRepositoryApi(this);
            Bootstrap       = new BootstrapApi(this);
            Config          = new ConfigApi(this);
            Dag             = new DagApi(this);
            Dht             = new DhtApi(this);
            Dns             = new DnsApi(this);
            FileSystem      = new FileSystemApi(this);
            Generic         = new GenericApi(this);
            Key             = new KeyApi(this);
            Name            = new NameApi(this);
            Object          = new ObjectApi(this);
            Pin             = new PinApi(this);
            PubSub          = new PubSubApi(this);
            Stats           = new StatsApi(this);
            Swarm           = new SwarmApi(this);

            // Async properties
            LocalPeer = new AsyncLazy <Peer>(async() =>
            {
                log.Debug("Building local peer");
                var keyChain = await KeyChain().ConfigureAwait(false);
                log.Debug("Getting key info about self");
                var self      = await keyChain.FindKeyByNameAsync("self").ConfigureAwait(false);
                var localPeer = new Peer
                {
                    Id              = self.Id,
                    PublicKey       = await keyChain.GetPublicKeyAsync("self").ConfigureAwait(false),
                    ProtocolVersion = "ipfs/0.1.0"
                };
                var version            = typeof(IpfsEngine).GetTypeInfo().Assembly.GetName().Version;
                localPeer.AgentVersion = $"net-ipfs/{version.Major}.{version.Minor}.{version.Revision}";
                log.Debug("Built local peer");
                return(localPeer);
            });
            SwarmService = new AsyncLazy <Swarm>(async() =>
            {
                log.Debug("Building swarm service");
                if (Options.Swarm.PrivateNetworkKey == null)
                {
                    var path = Path.Combine(Options.Repository.Folder, "swarm.key");
                    if (File.Exists(path))
                    {
                        using (var x = File.OpenText(path))
                        {
                            Options.Swarm.PrivateNetworkKey = new PreSharedKey();
                            Options.Swarm.PrivateNetworkKey.Import(x);
                        }
                    }
                }
                var peer     = await LocalPeer.ConfigureAwait(false);
                var keyChain = await KeyChain().ConfigureAwait(false);
                var self     = await keyChain.GetPrivateKeyAsync("self").ConfigureAwait(false);
                var swarm    = new Swarm
                {
                    LocalPeer        = peer,
                    LocalPeerKey     = PeerTalk.Cryptography.Key.CreatePrivateKey(self),
                    NetworkProtector = Options.Swarm.PrivateNetworkKey == null
                        ? null
                        : new Psk1Protector {
                        Key = Options.Swarm.PrivateNetworkKey
                    }
                };
                if (Options.Swarm.PrivateNetworkKey != null)
                {
                    log.Debug($"Private network {Options.Swarm.PrivateNetworkKey.Fingerprint().ToHexString()}");
                }

                log.Debug("Built swarm service");
                return(swarm);
            });
            BitswapService = new AsyncLazy <BlockExchange.Bitswap>(async() =>
            {
                log.Debug("Building bitswap service");
                var bitswap = new BlockExchange.Bitswap
                {
                    Swarm        = await SwarmService.ConfigureAwait(false),
                    BlockService = Block
                };
                log.Debug("Built bitswap service");
                return(bitswap);
            });
            DhtService = new AsyncLazy <PeerTalk.Routing.Dht1>(async() =>
            {
                log.Debug("Building DHT service");
                var dht = new PeerTalk.Routing.Dht1
                {
                    Swarm = await SwarmService.ConfigureAwait(false)
                };
                dht.Swarm.Router = dht;
                log.Debug("Built DHT service");
                return(dht);
            });
            PubSubService = new AsyncLazy <PeerTalk.PubSub.NotificationService>(async() =>
            {
                log.Debug("Building PubSub service");
                var pubsub = new PeerTalk.PubSub.NotificationService
                {
                    LocalPeer = await LocalPeer.ConfigureAwait(false)
                };
                pubsub.Routers.Add(new PeerTalk.PubSub.FloodRouter
                {
                    Swarm = await SwarmService.ConfigureAwait(false)
                });
                log.Debug("Built PubSub service");
                return(pubsub);
            });
        }
コード例 #8
0
        void Init()
        {
            // Init the core api inteface.
            Bitswap    = new BitswapApi(this);
            Block      = new BlockApi(this);
            Bootstrap  = new BootstrapApi(this);
            Config     = new ConfigApi(this);
            Dag        = new DagApi(this);
            Dht        = new DhtApi(this);
            Dns        = new DnsApi(this);
            FileSystem = new FileSystemApi(this);
            Generic    = new GenericApi(this);
            Key        = new KeyApi(this);
            Name       = new NameApi(this);
            Object     = new ObjectApi(this);
            Pin        = new PinApi(this);
            PubSub     = new PubSubApi(this);
            Stats      = new StatsApi(this);
            Swarm      = new SwarmApi(this);

            // Async properties
            LocalPeer = new AsyncLazy <Peer>(async() =>
            {
                log.Debug("Building local peer");
                var keyChain = await KeyChain();
                log.Debug("Getting key info about self");
                var self                  = await keyChain.FindKeyByNameAsync("self");
                var localPeer             = new Peer();
                localPeer.Id              = self.Id;
                localPeer.PublicKey       = await keyChain.GetPublicKeyAsync("self");
                localPeer.ProtocolVersion = "ipfs/0.1.0";
                var version               = typeof(IpfsEngine).GetTypeInfo().Assembly.GetName().Version;
                localPeer.AgentVersion    = $"net-ipfs/{version.Major}.{version.Minor}.{version.Revision}";
                log.Debug("Built local peer");
                return(localPeer);
            });
            SwarmService = new AsyncLazy <Swarm>(async() =>
            {
                log.Debug("Building swarm service");
                var peer     = await LocalPeer;
                var keyChain = await KeyChain();
                var self     = await keyChain.GetPrivateKeyAsync("self");
                var swarm    = new Swarm
                {
                    LocalPeer    = peer,
                    LocalPeerKey = PeerTalk.Cryptography.Key.CreatePrivateKey(self)
                };
                log.Debug("Built swarm service");
                return(swarm);
            });
            BitswapService = new AsyncLazy <BlockExchange.Bitswap>(async() =>
            {
                log.Debug("Building bitswap service");
                var bitswap = new BlockExchange.Bitswap
                {
                    Swarm        = await SwarmService,
                    BlockService = Block
                };
                log.Debug("Built bitswap service");
                return(bitswap);
            });
            DhtService = new AsyncLazy <PeerTalk.Routing.Dht1>(async() =>
            {
                log.Debug("Building DHT service");
                var dht = new PeerTalk.Routing.Dht1
                {
                    Swarm = await SwarmService
                };
                dht.Swarm.Router = dht;
                log.Debug("Built DHT service");
                return(dht);
            });
        }
コード例 #9
0
        public static void Main(string[] args)
        {
            StatXClient statxClient = new StatXClient();

            Configuration configuration = statxClient.getConfiguration();

            Console.WriteLine("Enter Target Date in mm/dd/yyy format:");

            string targetDate = Console.ReadLine();

            Console.WriteLine("Enter Stat Title");

            string statTitle = Console.ReadLine();


            // Repeat once every 24 hours (see parameter below).
            while (true)
            {
                string    groupName = "StatX-API-Examples";
                GroupsApi groupsApi = new GroupsApi(configuration);
                GroupList groupList = groupsApi.GetGroups(groupName);
                Group     group;
                if ((groupList == null) || (groupList.Data == null) || (groupList.Data.Count == 0))
                {
                    // The group does not exist. Let's create one. Since we are creating the group
                    // the api will add the current user as a member and admin of the group.
                    group = new Group(null, groupName, null);
                    group = groupsApi.CreateGroup(group);
                }
                else
                {
                    // Pick the first group (should be the only one).
                    group = groupList.Data[0];
                }


                // Find the stat by name. If the stat does not exist then create it.
                //
                // Note: The stat title is not unique. In general it is not a good idea to use
                // the stat title as a key to determine whether the stat exists or not. If possible
                // use the statid instead.
                StatsApi statsApi = new StatsApi(configuration);
                StatList statList = statsApi.GetStats(group.Name, statTitle);
                if ((statList == null) || (statList.Data == null) || (statList.Data.Count == 0))
                {
                    // The stat does not exist. Let's create a number stat.
                    NumberStat numberStat = new NumberStat();
                    numberStat.Title      = statTitle;
                    numberStat.VisualType = Stat.VisualTypeEnum.Number;
                    numberStat.Value      = getRemainingDays(targetDate);
                    statsApi.CreateStat(group.Id, numberStat);
                }
                else
                {
                    // Pick the first stat (should be the only one) and get the statId from it.
                    string statId = statList.Data[0].Id;

                    // Create the stat to update.
                    NumberStat numberStat = new NumberStat();
                    numberStat.Value = getRemainingDays(targetDate);
                    numberStat.LastUpdatedDateTime = DateTime.Now;
                    statsApi.UpdateStat(group.Id, statId, numberStat);
                }

                Console.WriteLine("Last update at: " + DateTime.Now);

                System.Threading.Thread.Sleep(TimeSpan.FromDays(1));
            }
        }