public Promise SubmitItemVote(ulong itemID, WorkshopVote vote)
        {
            var result = new SimplePromise();

            m_network.MakeCall(
                SteamUGC.SetUserItemVote(new PublishedFileId_t(itemID), (vote == WorkshopVote.Up)),
                delegate(SetUserItemVoteResult_t args, bool ioFailure)
            {
                if (ioFailure || args.m_eResult != EResult.k_EResultOK)
                {
                    if (!ioFailure)
                    {
                        result.Fail("Failed to submit item vote: " + args.m_eResult);
                    }
                    else
                    {
                        result.Fail("Failed to submit item vote");
                    }
                }
                else
                {
                    result.Succeed();
                }
            }
                );
            return(result);
        }
Beispiel #2
0
        public static Promise <string[]> GetMOTD()
        {
            var request = new SimplePromise <string[]>();

            new Task(delegate
            {
                try
                {
                    string[] results = GET("motd_get.php");
                    if (results.Length >= 1)
                    {
                        request.Succeed(results);
                    }
                    else
                    {
                        request.Succeed(null);
                    }
                }
                catch (Exception e)
                {
                    request.Fail(e.Message);
                }
            }).Start();
            return(request);
        }
        public Promise SetItemCompleted(ulong itemID)
        {
            var result = new SimplePromise();

            m_network.MakeCall(
                SteamRemoteStorage.SetUserPublishedFileAction(new PublishedFileId_t(itemID), EWorkshopFileAction.k_EWorkshopFileActionCompleted),
                delegate(RemoteStorageSetUserPublishedFileActionResult_t args, bool ioFailure)
            {
                if (ioFailure || args.m_eResult != EResult.k_EResultOK)
                {
                    if (!ioFailure)
                    {
                        result.Fail("Failed to set item completed: " + args.m_eResult);
                    }
                    else
                    {
                        result.Fail("Failed to set item completed");
                    }
                }
                else
                {
                    result.Succeed();
                }
            }
                );
            return(result);
        }
        public Promise <WorkshopPublishResult> CreateItem(string filePath, string previewImagePath, string title, string description, string[] tags, bool visibility)
        {
            var result = new SimplePromise <WorkshopPublishResult>();

            m_network.MakeCall(
                SteamUGC.CreateItem(new AppId_t(App.Info.SteamAppID), EWorkshopFileType.k_EWorkshopFileTypeCommunity),
                delegate(CreateItemResult_t args, bool ioFailure)
            {
                if (ioFailure || args.m_eResult != EResult.k_EResultOK)
                {
                    if (!ioFailure)
                    {
                        result.Fail("Failed to create file: " + args.m_eResult);
                    }
                    else
                    {
                        result.Fail("Failed to create file");
                    }
                }
                else
                {
                    ulong fileID = args.m_nPublishedFileId.m_PublishedFileId;
                    UpdateItem(fileID, "Initial upload", filePath, previewImagePath, title, description, tags, visibility, result);
                }
            }
                );
            return(result);
        }
        public Promise UnsubscribeFromItem(ulong itemID)
        {
            var promise = new SimplePromise();

            m_network.MakeCall(
                SteamUGC.UnsubscribeItem(new PublishedFileId_t(itemID)),
                delegate(RemoteStorageUnsubscribePublishedFileResult_t args, bool ioFailure)
            {
                if (ioFailure || args.m_eResult != EResult.k_EResultOK)
                {
                    if (!ioFailure)
                    {
                        promise.Fail("Failed to unsubscribe from item: " + args.m_eResult);
                    }
                    else
                    {
                        promise.Fail("Failed to unsubscribe from item");
                    }
                }
                else
                {
                    promise.Succeed();
                }
            }
                );
            return(promise);
        }
        public Promise <WorkshopPublishResult> UpdateItem(ulong itemID, string changeMessage, string filePath = null, string previewImagePath = null, string title = null, string description = null, string[] tags = null, bool?visibility = null)
        {
            var result = new SimplePromise <WorkshopPublishResult>();

            UpdateItem(itemID, changeMessage, filePath, previewImagePath, title, description, tags, visibility, result);
            return(result);
        }
        public Promise <WorkshopItemInfo[]> GetItemInfo(ulong[] itemIDs)
        {
            var result = new SimplePromise <WorkshopItemInfo[]>();

            var publishedFileIDs = new PublishedFileId_t[itemIDs.Length];

            for (int i = 0; i < itemIDs.Length; ++i)
            {
                publishedFileIDs[i] = new PublishedFileId_t(itemIDs[i]);
            }

            var query = SteamUGC.CreateQueryUGCDetailsRequest(publishedFileIDs, (uint)publishedFileIDs.Length);

            m_network.MakeCall(
                SteamUGC.SendQueryUGCRequest(query),
                delegate(SteamUGCQueryCompleted_t args, bool ioFailure)
            {
                if (ioFailure || args.m_eResult != EResult.k_EResultOK)
                {
                    if (!ioFailure)
                    {
                        result.Fail("Failed to get item info: " + args.m_eResult);
                    }
                    else
                    {
                        result.Fail("Failed to get item info");
                    }
                }
                else
                {
                    var results = new List <WorkshopItemInfo>((int)args.m_unNumResultsReturned);
                    for (uint i = 0; i < args.m_unNumResultsReturned; ++i)
                    {
                        SteamUGCDetails_t details;
                        uint subscribers, totalSubscribers;
                        if (SteamUGC.GetQueryUGCResult(query, i, out details) &&
                            SteamUGC.GetQueryUGCStatistic(query, i, EItemStatistic.k_EItemStatistic_NumSubscriptions, out subscribers) &&
                            SteamUGC.GetQueryUGCStatistic(query, i, EItemStatistic.k_EItemStatistic_NumUniqueSubscriptions, out totalSubscribers))
                        {
                            var id                = details.m_nPublishedFileId.m_PublishedFileId;
                            var info              = new WorkshopItemInfo(id);
                            info.AuthorID         = details.m_ulSteamIDOwner;
                            info.Title            = details.m_rgchTitle;
                            info.Description      = details.m_rgchDescription;
                            info.Subscribers      = (int)subscribers;
                            info.TotalSubscribers = (int)Math.Max(subscribers, totalSubscribers);
                            info.UpVotes          = (int)details.m_unVotesUp;
                            info.DownVotes        = (int)details.m_unVotesDown;
                            results.Add(info);
                        }
                    }
                    result.Succeed(results.ToArray());
                }
                SteamUGC.ReleaseQueryUGCRequest(query);
            }
                );

            return(result);
        }
Beispiel #8
0
        private IPromise <bool> RunPluginSync(CancellationToken cancellationToken, IPlugin plugin, ExecutePluginHandler pluginRunner)
        {
            var promise =
                new SimplePromise(_uiContext)
                .CancelWith(cancellationToken)
                .Before(delegate
            {
                var progressProvider = _pluginRepository.GetProgressProvider(plugin);

                progressProvider.Updated -= ProgressProviderOnUpdated;
                progressProvider.Updated += ProgressProviderOnUpdated;

                progressProvider.Reset();
                progressProvider.Start();
            })
                .Work(delegate
            {
                pluginRunner(cancellationToken);
            })
                .Fail(delegate(IPromise <bool> p)
            {
                var progressProvider = _pluginRepository.GetProgressProvider(plugin);

                // Sanity check
                if (cancellationToken.IsCancellationRequested ||
                    progressProvider.State == ProgressProviderState.Canceled)
                {
                    progressProvider.Cancel();
                    return;
                }

                progressProvider.Error(p.LastException);
                HandleUnhandledException(p.LastException);
            })
                .Canceled(delegate
            {
                _pluginRepository.GetProgressProvider(plugin).Cancel();
            })
                .Done(delegate
            {
                var progressProvider = _pluginRepository.GetProgressProvider(plugin);
                if (cancellationToken.IsCancellationRequested)
                {
                    progressProvider.Cancel();
                }
                else
                {
                    progressProvider.Succeed();
                }
            })
            ;

            promise.Start().Wait();
            return(promise);
        }
Beispiel #9
0
    /// <summary>
    /// Gets the price of the coin of a given symbol.
    /// </summary>
    /// <param name="symbol"> The symbol of the coin on CoinMarketCap. </param>
    /// <returns> The promise of an eventual decimal price or null. </returns>
    public SimplePromise <decimal?> GetCoinPrice(string symbol)
    {
        SimplePromise <decimal?> promise = new SimplePromise <decimal?>();

        if (!CoinIDs.ContainsKey(symbol))
        {
            return(promise.ResolveResult(null));
        }

        coinMarketCapApiService.SendTickerRequest(CoinIDs[symbol], currencyManager.ActiveCurrency).OnSuccess(jsonData => promise.ResolveResult((decimal?)GetCoinPriceData(JsonUtils.DeserializeDynamic(jsonData).data.quotes).price));

        return(promise);
    }
Beispiel #10
0
    /// <summary>
    /// Queues a request if there are no sendable requests available.
    /// </summary>
    /// <param name="promise"> The promise returning the result of this request. </param>
    /// <param name="request"> The api request to send. </param>
    private void InternalQueueRequest(SimplePromise <string> promise, string request)
    {
        int maximumSendableRequests = maximumRequestsPerInterval - sentRequestCount;

        if (maximumSendableRequests > 0)
        {
            return;
        }

        queuedRequests.Enqueue(new QueuedRequest {
            urlRequest = request, result = promise
        });
    }
    /// <summary>
    /// Processes the data retrieved from the trade history request on the DubiEx api.
    /// </summary>
    /// <param name="promise"> The promise returning the resulting eth price. </param>
    /// <param name="jsonData"> The json data returned from the rest api request. </param>
    private void ProcessData(SimplePromise <decimal?> promise, string jsonData)
    {
        dynamic deserializedData = JsonUtils.DeserializeDynamic(jsonData);

        if ((int)deserializedData.itemCount == 0)
        {
            promise.ResolveResult(null);
        }
        else
        {
            promise.ResolveResult((decimal?)decimal.Parse(deserializedData.result[0].metadata.price));
        }
    }
Beispiel #12
0
    /// <summary>
    /// Sends a request if this ApiService is under the limit. If the limit has been exceeded, the request will be added to queue.
    /// </summary>
    /// <param name="request"> The api request to send. </param>
    /// <returns> The promise of the result from the api. </returns>
    protected SimplePromise <string> SendRequest(string request)
    {
        var promise = new SimplePromise <string>();

        if (string.IsNullOrEmpty(request))
        {
            return(promise);
        }

        InternalQueueRequest(promise, request);
        InternalSendRequest(promise, request);

        return(promise);
    }
Beispiel #13
0
    /// <summary>
    /// Sends the api request if we are under the maximum sendable requests in this time interval.
    /// </summary>
    /// <param name="promise"> The promise returning the result of this request. </param>
    /// <param name="request"> The api request to send. </param>
    private void InternalSendRequest(SimplePromise <string> promise, string request)
    {
        int maximumSendableRequests = maximumRequestsPerInterval - sentRequestCount;

        if (maximumSendableRequests <= 0)
        {
            return;
        }

        sentRequestCount++;

        Observable.WhenAll(ObservableWWW.Get(request))
        .Subscribe(results => promise.ResolveResult(results[0]), ex => promise.ResolveException(ex));
    }
Beispiel #14
0
        private void TakeScreenshot()
        {
            // Capture image
            var bitmap = new Bitmap(Window.Width, Window.Height);

            using (var bits = bitmap.Lock())
            {
                try
                {
                    GL.PixelStore(PixelStoreParameter.UnpackRowLength, bits.Stride / bits.BytesPerPixel);
                    GL.ReadPixels(
                        0, 0,
                        Window.Width, Window.Height,
                        (bits.BytesPerPixel == 4) ? PixelFormat.Rgba : PixelFormat.Rgb,
                        PixelType.UnsignedByte,
                        bits.Data
                        );
                }
                finally
                {
                    GL.PixelStore(PixelStoreParameter.UnpackRowLength, 0);
                    App.CheckOpenGLError();
                }
            }

            // Flip image
            bitmap.FlipY();

            if (m_pendingScreenshot.Width > 0 && m_pendingScreenshot.Height > 0)
            {
                // Resize image
                var resizedBitmap = bitmap.Resize(m_pendingScreenshot.Width, m_pendingScreenshot.Height, true, true);
                bitmap.Dispose();
                bitmap = resizedBitmap;
            }
            else
            {
                // Use original size
                m_pendingScreenshot.Width  = bitmap.Width;
                m_pendingScreenshot.Height = bitmap.Height;
            }

            // Complete the promise
            m_pendingScreenshot.Bitmap = bitmap;
            m_pendingScreenshotPromise.Succeed(m_pendingScreenshot);
            m_pendingScreenshotPromise = null;
            m_pendingScreenshot        = null;
        }
    /// <summary>
    /// Gets the recent eth value of an asset traded on DubiEx.
    /// </summary>
    /// <param name="assetSymbol"> The symbol of the asset. </param>
    /// <returns> The most recent eth price of the asset on DubiEx. Returns null if no price was found. </returns>
    public SimplePromise <decimal?> GetRecentEthPrice(string assetSymbol)
    {
        SimplePromise <decimal?> promise = new SimplePromise <decimal?>();

        if (tradableAssetManager.TradableAssets.Values.Select(asset => asset.AssetSymbol).ContainsIgnoreCase(assetSymbol))
        {
            dubiExApiService.SendTradeHistoryRequest(tradableAssetManager.TradableAssets.Values.First(asset => asset.AssetSymbol == assetSymbol).AssetAddress)
            .OnSuccess(jsonData => ProcessData(promise, jsonData));
        }
        else
        {
            promise.ResolveException(new Exception("Asset symbol not found in TradableAsset collection."));
        }

        return(promise);
    }
        private void TestConnectionAsync(bool notify)
        {
            var promise =
                new SimplePromise()
                .Work(TestConnection)
                .Fail(Fail)
                .Canceled(Fail)
                .Done(Done)
            ;

            if (notify)
            {
                promise.Always(NotifyObservers);
            }

            promise.Start();
        }
        public Promise SubmitLocalUserLeaderboardScore(ulong id, int score)
        {
            var result = new SimplePromise();

            MakeCall(
                SteamUserStats.UploadLeaderboardScore(new SteamLeaderboard_t(id), ELeaderboardUploadScoreMethod.k_ELeaderboardUploadScoreMethodKeepBest, score, null, 0),
                delegate(LeaderboardScoreUploaded_t args2, bool ioFailure2)
            {
                if (ioFailure2 || args2.m_bSuccess == 0)
                {
                    result.Fail("Failed to submit leaderboard score");
                }
                else
                {
                    result.Succeed();
                }
            }
                );
            return(result);
        }
        public Promise <ulong> GetLeaderboardID(string name, bool createIfAbsent)
        {
            var result = new SimplePromise <ulong>();

            MakeCall(
                createIfAbsent ?
                SteamUserStats.FindOrCreateLeaderboard(name, ELeaderboardSortMethod.k_ELeaderboardSortMethodDescending, ELeaderboardDisplayType.k_ELeaderboardDisplayTypeNumeric) :
                SteamUserStats.FindLeaderboard(name),
                delegate(LeaderboardFindResult_t args, bool ioFailure)
            {
                if (ioFailure || args.m_bLeaderboardFound == 0)
                {
                    result.Fail("Failed to get leaderboard ID");
                }
                else
                {
                    var id = args.m_hSteamLeaderboard.m_SteamLeaderboard;
                    result.Succeed(id);
                }
            }
                );
            return(result);
        }
        public Promise <Leaderboard> DownloadLeaderboard(ulong id, LeaderboardType type, int maxEntries)
        {
            var result = new SimplePromise <Leaderboard>();

            if (maxEntries > 0)
            {
                ELeaderboardDataRequest requestType;
                int rangeStart, rangeEnd;
                switch (type)
                {
                case LeaderboardType.Global:
                default:
                {
                    requestType = ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobal;
                    rangeStart  = 1;
                    rangeEnd    = maxEntries;
                    break;
                }

                case LeaderboardType.Local:
                {
                    requestType = ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobalAroundUser;
                    rangeStart  = -(maxEntries / 2);
                    rangeEnd    = rangeStart + maxEntries - 1;
                    break;
                }

                case LeaderboardType.Friends:
                {
                    requestType = ELeaderboardDataRequest.k_ELeaderboardDataRequestFriends;
                    rangeStart  = 1;
                    rangeEnd    = maxEntries;
                    break;
                }
                }
                MakeCall(
                    SteamUserStats.DownloadLeaderboardEntries(new SteamLeaderboard_t(id), requestType, rangeStart, rangeEnd),
                    delegate(LeaderboardScoresDownloaded_t args2, bool ioFailure2)
                {
                    if (ioFailure2)
                    {
                        result.Fail("Failed to download leaderboard");
                    }
                    else
                    {
                        var leaderboard = new Leaderboard(id, type);
                        for (int i = 0; i < Math.Min(args2.m_cEntryCount, maxEntries); ++i)
                        {
                            LeaderboardEntry_t entry;
                            if (SteamUserStats.GetDownloadedLeaderboardEntry(args2.m_hSteamLeaderboardEntries, i, out entry, null, 0))
                            {
                                var rank     = entry.m_nGlobalRank;
                                var username = SteamFriends.GetFriendPersonaName(entry.m_steamIDUser);
                                var score    = entry.m_nScore;
                                leaderboard.Entries.Add(new LeaderboardEntry(rank, username, score));
                            }
                        }
                        result.Succeed(leaderboard);
                    }
                }
                    );
            }
            else
            {
                result.Succeed(new Leaderboard(id, type));
            }
            return(result);
        }
        private void UpdateItem(ulong itemID, string changeMessage, string filePath, string previewImagePath, string title, string description, string[] tags, bool?visibility, SimplePromise <WorkshopPublishResult> promise)
        {
            UGCUpdateHandle_t handle = SteamUGC.StartItemUpdate(new AppId_t(App.Info.SteamAppID), new PublishedFileId_t(itemID));

            if (filePath != null)
            {
                SteamUGC.SetItemContent(handle, filePath + Path.DirectorySeparatorChar);
            }
            if (previewImagePath != null)
            {
                SteamUGC.SetItemPreview(handle, previewImagePath);
            }
            if (title != null)
            {
                SteamUGC.SetItemTitle(handle, title);
            }
            if (description != null)
            {
                SteamUGC.SetItemDescription(handle, description);
            }
            if (tags != null)
            {
                SteamUGC.SetItemTags(handle, new List <string>(tags));
            }
            if (visibility.HasValue)
            {
                SteamUGC.SetItemVisibility(handle, visibility.Value ?
                                           (App.Debug ?
                                            ERemoteStoragePublishedFileVisibility.k_ERemoteStoragePublishedFileVisibilityFriendsOnly :
                                            ERemoteStoragePublishedFileVisibility.k_ERemoteStoragePublishedFileVisibilityPublic) :
                                           ERemoteStoragePublishedFileVisibility.k_ERemoteStoragePublishedFileVisibilityPrivate
                                           );
            }
            m_network.MakeCall(
                SteamUGC.SubmitItemUpdate(handle, changeMessage),
                delegate(SubmitItemUpdateResult_t args, bool ioFailure)
            {
                if (ioFailure || args.m_eResult != EResult.k_EResultOK)
                {
                    if (!ioFailure)
                    {
                        promise.Fail("Failed to update file: " + args.m_eResult);
                    }
                    else
                    {
                        promise.Fail("Failed to update file");
                    }
                }
                else
                {
                    var result             = new WorkshopPublishResult(itemID);
                    result.AgreementNeeded = args.m_bUserNeedsToAcceptWorkshopLegalAgreement;
                    promise.Succeed(result);
                }
            }
                );
        }
Beispiel #21
0
 public Promise <Screenshot> QueueScreenshot(int customWidth = 0, int customHeight = 0)
 {
     m_pendingScreenshot        = new Screenshot(customWidth, customHeight);
     m_pendingScreenshotPromise = new SimplePromise <Screenshot>();
     return(m_pendingScreenshotPromise);
 }