예제 #1
0
        public void BeginUpload()
        {
            if (!PublisherIsReady())
            {
                return;
            }
            Status       = PublisherStatus.Uploading;
            ErrorMessage = null;
            userAborted  = false;

            var collatedData = PrepareLogData();

#if TEST_MOCK_UPLOAD
            HugsLibController.Logger.Message(collatedData);
            HugsLibUtility.CopyToClipboard(collatedData);
            MockUpload();
            return;
#endif

            if (collatedData == null)
            {
                ErrorMessage = "Failed to collect data";
                Status       = PublisherStatus.Error;
                return;
            }
            Action <Exception> onRequestFailed = ex => {
                if (userAborted)
                {
                    return;
                }
                OnRequestError(ex.Message);
                HugsLibController.Logger.Warning("Exception during log publishing (gist creation): " + ex);
            };
            try {
                collatedData = CleanForJSON(collatedData);
                var payload = string.Format(GistPayloadJson, GistDescription, OutputLogFilename, collatedData);
                activeRequest = new UnityWebRequest(GistApiUrl, UnityWebRequest.kHttpVerbPOST);
                activeRequest.SetRequestHeader("Authorization", "token " + GitHubAuthToken);
                activeRequest.SetRequestHeader("User-Agent", RequestUserAgent);
                activeRequest.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(payload))
                {
                    contentType = "application/json"
                };
                activeRequest.downloadHandler = new DownloadHandlerBuffer();
                HugsLibUtility.AwaitUnityWebResponse(activeRequest, OnUploadComplete, onRequestFailed, HttpStatusCode.Created);
            } catch (Exception e) {
                onRequestFailed(e);
            }
        }
예제 #2
0
        private void BeginUrlShortening()
        {
            Status = PublisherStatus.Shortening;

            Action <Exception> onRequestFailed = ex => {
                if (userAborted)
                {
                    return;
                }
                Status = PublisherStatus.Done;
                HugsLibController.Logger.Warning("Exception during log publishing (url shortening): " + ex);
            };

            try {
                var formData = new Dictionary <string, string> {
                    { "url", ResultUrl }
                };
                activeRequest = UnityWebRequest.Post(ShortenerUrl, formData);
                activeRequest.SetRequestHeader("User-Agent", RequestUserAgent);
                HugsLibUtility.AwaitUnityWebResponse(activeRequest, OnUrlShorteningComplete, onRequestFailed, HttpStatusCode.Created);
            } catch (Exception e) {
                onRequestFailed(e);
            }
        }