private void BuildDisplayMap()
 {
     m_displayMapping = new Dictionary <Text, GetDisplayString>();
     if (userIdDisplay != null)
     {
         m_displayMapping.Add(userIdDisplay, (d) => d.userId.ToString());
     }
     if (nameIdDisplay != null)
     {
         m_displayMapping.Add(nameIdDisplay, (d) => d.nameId);
     }
     if (usernameDisplay != null)
     {
         m_displayMapping.Add(usernameDisplay, (d) => d.username);
     }
     if (lastOnlineDisplay != null)
     {
         m_displayMapping.Add(lastOnlineDisplay, (d) => ServerTimeStamp.ToLocalDateTime(d.lastOnline).ToString());
     }
     if (timezoneDisplay != null)
     {
         m_displayMapping.Add(timezoneDisplay, (d) => d.timezone);
     }
     if (languageDisplay != null)
     {
         m_displayMapping.Add(languageDisplay, (d) => d.language);
     }
     if (profileURLDisplay != null)
     {
         m_displayMapping.Add(profileURLDisplay, (d) => d.profileURL);
     }
 }
        private void BuildDisplayMap()
        {
            string dateTimeFormat = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;

            m_displayMapping = new Dictionary <Text, GetDisplayString>();

            if (modfileIdDisplay != null)
            {
                m_displayMapping.Add(modfileIdDisplay, (d) => d.modfileId.ToString());
            }
            if (modIdDisplay != null)
            {
                m_displayMapping.Add(modIdDisplay, (d) => d.modId.ToString());
            }
            if (dateAddedDisplay != null)
            {
                m_displayMapping.Add(dateAddedDisplay, (d) => ServerTimeStamp.ToLocalDateTime(d.dateAdded).ToString(dateTimeFormat));
            }
            if (fileNameDisplay != null)
            {
                m_displayMapping.Add(fileNameDisplay, (d) => d.fileName);
            }
            if (fileSizeDisplay != null)
            {
                m_displayMapping.Add(fileSizeDisplay, (d) => ValueFormatting.ByteCount(d.fileSize, "0.0"));
            }
            if (MD5Display != null)
            {
                m_displayMapping.Add(MD5Display, (d) => d.MD5);
            }
            if (versionDisplay != null)
            {
                m_displayMapping.Add(versionDisplay, (d) => d.version);
            }
            if (changelogDisplay != null)
            {
                m_displayMapping.Add(changelogDisplay, (d) => d.changelog);
            }
            if (metadataBlobDisplay != null)
            {
                m_displayMapping.Add(metadataBlobDisplay, (d) => d.metadataBlob);
            }
            if (virusScanDateDisplay != null)
            {
                m_displayMapping.Add(virusScanDateDisplay, (d) => ServerTimeStamp.ToLocalDateTime(d.virusScanDate).ToString(dateTimeFormat));
            }
            if (virusScanStatusDisplay != null)
            {
                m_displayMapping.Add(virusScanStatusDisplay, (d) => d.virusScanStatus.ToString());
            }
            if (virusScanResultDisplay != null)
            {
                m_displayMapping.Add(virusScanResultDisplay, (d) => d.virusScanResult.ToString());
            }
            if (virusScanHashDisplay != null)
            {
                m_displayMapping.Add(virusScanHashDisplay, (d) => d.virusScanHash);
            }
        }
示例#3
0
        /// <summary>Generates the string for debugging the data in the request cache.</summary>
        public static string GenerateDebugInfo(int responseBodyCharacterLimit)
        {
            var s = new System.Text.StringBuilder();

            s.AppendLine("currentCacheSize="
                         + ValueFormatting.ByteCount(RequestCache.currentCacheSize, "0.0")
                         + "/"
                         + ValueFormatting.ByteCount(RequestCache.MAX_CACHE_SIZE, "0.0"));

            s.AppendLine("constructedCache=");

            foreach (var kvp in RequestCache.urlResponseIndexMap)
            {
                s.AppendLine("[" + kvp.Value.ToString("00") + "]:" + kvp.Key);

                if (kvp.Value < RequestCache.responses.Count)
                {
                    Entry e = RequestCache.responses[kvp.Value];

                    s.AppendLine("> "
                                 + ServerTimeStamp.ToLocalDateTime(e.timeStamp).ToString()
                                 + " [+" + (ServerTimeStamp.Now - e.timeStamp).ToString() + "s] -- "
                                 + ValueFormatting.ByteCount(e.size, "0.00"));

                    string r = e.responseBody;
                    if (string.IsNullOrEmpty(r))
                    {
                        r = "[NULL-OR-EMPTY]";
                    }
                    else
                    {
                        r = r.Substring(0, UnityEngine.Mathf.Min(responseBodyCharacterLimit, r.Length));
                    }

                    s.AppendLine("> " + r);
                }
                else
                {
                    s.AppendLine("[BAD INDEX!!!]:" + kvp.Key.ToString());
                }
            }

            return(s.ToString());
        }
示例#4
0
        /// <summary>Creates and sends an image download request for the given url.</summary>
        protected UnityWebRequestAsyncOperation DownloadImage(string url)
        {
            Debug.Assert(!string.IsNullOrEmpty(url));

            // create new download
            UnityWebRequest webRequest = UnityWebRequest.Get(url);

            webRequest.downloadHandler = new DownloadHandlerTexture(true);

            // start download and attach callbacks
            var operation = webRequest.SendWebRequest();

            operation.completed += (o) =>
            {
                OnDownloadCompleted(operation.webRequest, url);
            };

            #if DEBUG
            if (PluginSettings.data.logAllRequests && logDownloads)
            {
                string        requestHeaders = "";
                List <string> requestKeys    = new List <string>(APIClient.UNITY_REQUEST_HEADER_KEYS);
                requestKeys.AddRange(APIClient.MODIO_REQUEST_HEADER_KEYS);

                foreach (string headerKey in requestKeys)
                {
                    string headerValue = webRequest.GetRequestHeader(headerKey);
                    if (headerValue != null)
                    {
                        requestHeaders += "\n" + headerKey + ": " + headerValue;
                    }
                }

                int timeStamp = ServerTimeStamp.Now;
                Debug.Log("IMAGE DOWNLOAD STARTED"
                          + "\nURL: " + webRequest.url
                          + "\nTimeStamp: [" + timeStamp.ToString() + "] "
                          + ServerTimeStamp.ToLocalDateTime(timeStamp).ToString()
                          + "\nHeaders: " + requestHeaders);
            }
            #endif

            return(operation);
        }
示例#5
0
        // ---------[ FUNCTIONALITY ]---------
        /// <summary>Formats a value as a display string.</summary>
        public static string FormatValue(object value, Method method, string toStringParameter)
        {
            string displayString = string.Empty;

            if (string.IsNullOrEmpty(toStringParameter))
            {
                // Default value for ToString() in most cases is (G)eneral
                toStringParameter = "G";
            }

            switch (method)
            {
            case Method.ByteCount:
            {
                Int64 bytes = 0;

                if (value != null)
                {
                    bytes = (Int64)value;
                }

                displayString = ValueFormatting.ByteCount(bytes, toStringParameter);
            }
            break;

            case Method.AbbreviatedNumber:
            {
                int number = 0;

                if (value != null)
                {
                    number = (int)value;
                }

                displayString = ValueFormatting.AbbreviateInteger(number, toStringParameter);
            }
            break;

            case Method.TimeStampAsDateTime:
            {
                if (value == null)
                {
                    displayString = "--";
                }
                else
                {
                    displayString = ServerTimeStamp.ToLocalDateTime((int)value).ToString(toStringParameter);
                }
            }
            break;

            case Method.Percentage:
            {
                if (value == null)
                {
                    displayString = "--%";
                }
                else
                {
                    displayString = ((float)value * 100.0f).ToString(toStringParameter) + "%";
                }
            }
            break;

            case Method.SecondsAsTime:
            {
                int seconds = 0;

                if (value != null)
                {
                    seconds = (int)value;
                }

                displayString = ValueFormatting.SecondsAsTime(seconds);
            }
            break;

            default:
            {
                displayString = null;

                if (value != null &&
                    !string.IsNullOrEmpty(toStringParameter))
                {
                    if (value is float)
                    {
                        displayString = ((float)value).ToString(toStringParameter);
                    }
                    else if (value is int)
                    {
                        displayString = ((int)value).ToString(toStringParameter);
                    }
                    else if (value is Int64)
                    {
                        displayString = ((Int64)value).ToString(toStringParameter);
                    }
                }

                if (displayString == null)
                {
                    if (value != null)
                    {
                        displayString = value.ToString();
                    }
                    else
                    {
                        displayString = string.Empty;
                    }
                }
            }
            break;
            }
            return(displayString);
        }
示例#6
0
        private void BuildDisplayMap()
        {
            m_displayMapping = new Dictionary <Text, GetDisplayString>();

            if (modIdDisplay != null)
            {
                m_displayMapping.Add(modIdDisplay, (d) => d.modId.ToString());
            }
            if (gameIdDisplay != null)
            {
                m_displayMapping.Add(gameIdDisplay, (d) => d.gameId.ToString());
            }
            if (statusDisplay != null)
            {
                m_displayMapping.Add(statusDisplay, (d) => d.status.ToString());
            }
            if (visibilityDisplay != null)
            {
                m_displayMapping.Add(visibilityDisplay, (d) => d.visibility.ToString());
            }
            if (dateAddedDisplay != null)
            {
                m_displayMapping.Add(dateAddedDisplay, (d) => ServerTimeStamp.ToLocalDateTime(d.dateAdded).ToString());
            }
            if (dateUpdatedDisplay != null)
            {
                m_displayMapping.Add(dateUpdatedDisplay, (d) => ServerTimeStamp.ToLocalDateTime(d.dateUpdated).ToString());
            }
            if (dateLiveDisplay != null)
            {
                m_displayMapping.Add(dateLiveDisplay, (d) => ServerTimeStamp.ToLocalDateTime(d.dateLive).ToString());
            }
            if (contentWarningsDisplay != null)
            {
                m_displayMapping.Add(contentWarningsDisplay, (d) => d.contentWarnings.ToString());
            }
            if (homepageURLDisplay != null)
            {
                m_displayMapping.Add(homepageURLDisplay, (d) => Utility.SafeTrimString(d.homepageURL));
            }
            if (nameDisplay != null)
            {
                m_displayMapping.Add(nameDisplay, (d) => Utility.SafeTrimString(d.name));
            }
            if (nameIdDisplay != null)
            {
                m_displayMapping.Add(nameIdDisplay, (d) => Utility.SafeTrimString(d.nameId));
            }
            if (summaryDisplay != null)
            {
                m_displayMapping.Add(summaryDisplay, (d) => Utility.SafeTrimString(d.summary));
            }
            if (descriptionAsHTMLDisplay != null)
            {
                m_displayMapping.Add(descriptionAsHTMLDisplay, (d) =>
                {
                    string description = d.descriptionAsHTML;

                    if (replaceMissingDescriptionWithSummary &&
                        String.IsNullOrEmpty(description))
                    {
                        description = d.summary;
                    }

                    return(Utility.SafeTrimString(description));
                });
            }
            if (descriptionAsTextDisplay != null)
            {
                m_displayMapping.Add(descriptionAsTextDisplay, (d) =>
                {
                    string description = d.descriptionAsText;

                    if (replaceMissingDescriptionWithSummary &&
                        String.IsNullOrEmpty(description))
                    {
                        description = d.summary;
                    }

                    return(Utility.SafeTrimString(description));
                });
            }
            if (metadataBlobDisplay != null)
            {
                m_displayMapping.Add(metadataBlobDisplay, (d) => d.metadataBlob);
            }
            if (profileURLDisplay != null)
            {
                m_displayMapping.Add(profileURLDisplay, (d) => Utility.SafeTrimString(d.profileURL.Trim()));
            }
        }
        /// <summary>Handles the completion of an image download.</summary>
        protected virtual void OnDownloadCompleted(UnityWebRequest webRequest, string imageURL)
        {
            // early out if destroyed
            if (this == null)
            {
                return;
            }

            Debug.Assert(webRequest != null);

            // - logging -
            #if DEBUG
            if (PluginSettings.data.logAllRequests && logDownloads)
            {
                if (webRequest.isNetworkError || webRequest.isHttpError)
                {
                    WebRequestError.LogAsWarning(WebRequestError.GenerateFromWebRequest(webRequest));
                }
                else
                {
                    var headerString    = new System.Text.StringBuilder();
                    var responseHeaders = webRequest.GetResponseHeaders();
                    if (responseHeaders != null &&
                        responseHeaders.Count > 0)
                    {
                        headerString.Append("\n");
                        foreach (var kvp in responseHeaders)
                        {
                            headerString.AppendLine("- [" + kvp.Key + "] " + kvp.Value);
                        }
                    }
                    else
                    {
                        headerString.Append(" NONE");
                    }

                    var    responseTimeStamp = ServerTimeStamp.Now;
                    string logString         = ("IMAGE DOWNLOAD SUCCEEDED"
                                                + "\nURL: " + webRequest.url
                                                + "\nTime Stamp: " + responseTimeStamp + " ("
                                                + ServerTimeStamp.ToLocalDateTime(responseTimeStamp) + ")"
                                                + "\nResponse Headers: " + headerString.ToString()
                                                + "\nResponse Code: " + webRequest.responseCode
                                                + "\nResponse Error: " + webRequest.error
                                                + "\n");
                    Debug.Log(logString);
                }
            }
            #endif

            // handle callbacks
            Callbacks callbacks;
            bool      isURLMapped = this.m_callbackMap.TryGetValue(imageURL, out callbacks);
            if (callbacks == null)
            {
                Debug.LogWarning("[mod.io] ImageRequestManager completed a download but the callbacks"
                                 + " entry for the download was null."
                                 + "\nImageURL = " + imageURL
                                 + "\nWebRequest.URL = " + webRequest.url
                                 + "\nm_callbackMap.TryGetValue() = " + isURLMapped.ToString()
                                 );
                return;
            }

            if (webRequest.isHttpError || webRequest.isNetworkError)
            {
                if (callbacks.failed.Count > 0)
                {
                    WebRequestError error = WebRequestError.GenerateFromWebRequest(webRequest);

                    foreach (var errorCallback in callbacks.failed)
                    {
                        errorCallback(error);
                    }
                }
            }
            else
            {
                Texture2D texture = ((DownloadHandlerTexture)webRequest.downloadHandler).texture;

                if (this.isActiveAndEnabled || !this.clearCacheOnDisable)
                {
                    this.cache[imageURL] = texture;
                }

                foreach (var successCallback in callbacks.succeeded)
                {
                    successCallback(texture);
                }
            }

            // remove from "in progress"
            this.m_callbackMap.Remove(imageURL);
        }