コード例 #1
0
ファイル: TtrsStore.cs プロジェクト: ezaruba/Poltergeist
    public static IEnumerator LoadStoreInfo()
    {
        var url = "http://www.22series.com/api/store/info";

        var storeInfo = Cache.GetAsString("ttrs-store-info", Cache.FileType.JSON, 60 * 24);

        if (!String.IsNullOrEmpty(storeInfo))
        {
            LoadStoreInfoFromDataNode(DataFormats.LoadFromString(storeInfo));
            yield break;
        }

        yield return(WebClient.RESTRequest(url, WebClient.DefaultTimeout, (error, msg) =>
        {
            Log.Write("LoadStoreInfo() error: " + error);
        },
                                           (response) =>
        {
            if (response != null)
            {
                Cache.Add("ttrs-store-info", Cache.FileType.JSON, DataFormats.SaveToString(DataFormat.JSON, response));

                LoadStoreInfoFromDataNode(response);
            }
            else
            {
                Log.Write("LoadStoreInfo() error: No response from 22series.com");
            }
        }));
    }
コード例 #2
0
ファイル: Cache.cs プロジェクト: RobB2012/Poltergeist
    public static void AddDataNode(string CacheId, FileType FileType, DataNode CacheContents, string WalletAddress = "", string WalletName = "")
    {
        if (!String.IsNullOrEmpty(WalletAddress))
        {
            CacheId = CacheId + "." + WalletAddress;
        }

        string filePath = GetFilePath(CacheId, FileType);

        var serializedCacheContents = DataFormats.SaveToString(DataFormat.JSON, CacheContents);

        File.WriteAllText(filePath, serializedCacheContents);

        UpdateRegistry(CacheId, DateTime.Now, System.Text.ASCIIEncoding.ASCII.GetByteCount(serializedCacheContents), WalletName);
    }
コード例 #3
0
ファイル: API.cs プロジェクト: ghost-devs/LunarServer
        protected HTTPResponse HandleRequest(HTTPRequest request)
        {
            var url = StringUtils.FixUrl(request.path);

            if (url.Equals("/favicon.ico"))
            {
                return(null);
            }

            DataNode result;
            var      query = request.args;

            RouteEntry route = null;// router.Find(url, query);

            if (route != null)
            {
                var handler = route.Handlers.First().Handler; // TODO fixme

                try
                {
                    result = (DataNode)handler(request);
                }
                catch (Exception ex)
                {
                    result = OperationResult(ex.Message);
                }
            }
            else
            {
                result = DataNode.CreateObject("result");
                result.AddField("error", "invalid route");
            }

            var response = new HTTPResponse();


            var content = DataFormats.SaveToString(format, result);

            response.bytes = System.Text.Encoding.UTF8.GetBytes(content);

            response.headers["Content-Type"] = mimeType + "; charset=UTF-8";

            return(response);
        }
コード例 #4
0
 public static void WriteXML(DataNode node, string message = "", Level level = Level.Logic, UnityDebugLogMode unityDebugLogMode = UnityDebugLogMode.Normal)
 {
     Write(message + DataFormats.SaveToString(DataFormat.XML, node), level, unityDebugLogMode);
 }
コード例 #5
0
ファイル: TtrsStore.cs プロジェクト: RobB2012/Poltergeist
    public static IEnumerator LoadStoreNft(string[] ids, Action <Nft> onItemLoadedCallback, Action onAllItemsLoadedCallback)
    {
        var url      = "http://www.22series.com/api/store/nft";
        var storeNft = Cache.GetDataNode("ttrs-store-nft", Cache.FileType.JSON, 60 * 24);

        if (storeNft != null)
        {
            LoadStoreNftFromDataNode(storeNft, onItemLoadedCallback);

            // Checking, that cache contains all needed NFTs.
            string[] missingIds = ids;
            for (int i = 0; i < ids.Length; i++)
            {
                if (CheckIfNftLoaded(ids[i]))
                {
                    missingIds = missingIds.Where(x => x != ids[i]).ToArray();
                }
            }
            ids = missingIds;

            if (ids.Length == 0)
            {
                onAllItemsLoadedCallback();
                yield break;
            }
        }

        var idList = "";

        for (int i = 0; i < ids.Length; i++)
        {
            if (String.IsNullOrEmpty(idList))
            {
                idList += "\"" + ids[i] + "\"";
            }
            else
            {
                idList += ",\"" + ids[i] + "\"";
            }
        }

        yield return(WebClient.RESTRequest(url, "{\"ids\":[" + idList + "]}", (error, msg) =>
        {
            Log.Write("LoadStoreNft() error: " + error);
        },
                                           (response) =>
        {
            if (response != null)
            {
                LoadStoreNftFromDataNode(response, onItemLoadedCallback);

                if (storeNft != null)
                {
                    // Cache already exists, need to add new nfts to existing cache.
                    foreach (var node in response.Children)
                    {
                        storeNft.AddNode(node);
                    }
                }
                else
                {
                    storeNft = response;
                }
                if (storeNft != null)
                {
                    Cache.Add("ttrs-store-nft", Cache.FileType.JSON, DataFormats.SaveToString(DataFormat.JSON, storeNft));
                }
            }
            onAllItemsLoadedCallback();
        }));
    }