Esempio n. 1
0
        protected override void OnBegin()
        {
            IObservable <string> www = null;

            if (User.Logined)
            {
                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Authorization", "Token " + User.Token);

                var form = new WWWForm();

                form.AddField("username", User.Username.Value);
                form.AddField("password", User.Password.Value);

                www = ObservableWWW.Post("https://api.liangxiegame.com/qf/v4/package/list", form, headers);
            }
            else
            {
                www = ObservableWWW.Post("https://api.liangxiegame.com/qf/v4/package/list", new WWWForm());
            }


            www.Subscribe(response =>
            {
                var responseJson = JObject.Parse(response);

                if (responseJson["code"].Value <string>() == "1")
                {
                    var packageInfosJson = responseJson["data"];

                    var packageDatas = new List <PackageData>();
                    foreach (var packageInfo in packageInfosJson)
                    {
                        var name = packageInfo["name"].Value <string>();

                        var package = packageDatas.Find(packageData => packageData.Name == name);

                        if (package == null)
                        {
                            package = new PackageData()
                            {
                                Name = name,
                            };

                            packageDatas.Add(package);
                        }

                        var id          = packageInfo["id"].Value <string>();
                        var version     = packageInfo["version"].Value <string>();
                        var url         = packageInfo["downloadUrl"].Value <string>();            // download_url
                        var installPath = packageInfo["installPath"].Value <string>();
                        var releaseNote = packageInfo["releaseNote"].Value <string>();
                        var createAt    = packageInfo["createAt"].Value <string>();
                        var creator     = packageInfo["username"].Value <string>();
//					    var docUrl = packageInfo["doc_url"].Value<string>();
                        var releaseItem     = new ReleaseItem(version, releaseNote, creator, DateTime.Parse(createAt));
                        var accessRightName = packageInfo["accessRight"].Value <string>();
                        var typeName        = packageInfo["type"].Value <string>();

                        var packageType = PackageType.FrameworkModule;

                        switch (typeName)
                        {
                        case "fm":
                            packageType = PackageType.FrameworkModule;
                            break;

                        case "s":
                            packageType = PackageType.Shader;
                            break;

                        case "agt":
                            packageType = PackageType.AppOrGameDemoOrTemplate;
                            break;

                        case "p":
                            packageType = PackageType.Plugin;
                            break;
                        }

                        var accessRight = PackageAccessRight.Public;

//					    accessRightName.LogInfo();
                        switch (accessRightName)
                        {
                        case "public":
                            accessRight = PackageAccessRight.Public;
                            break;

                        case "private":
                            accessRight = PackageAccessRight.Private;
                            break;
                        }

                        package.PackageVersions.Add(new PackageVersion()
                        {
                            Id          = id,
                            Version     = version,
                            DownloadUrl = url,
                            InstallPath = installPath,
                            Type        = packageType,
                            AccessRight = accessRight,
                            Readme      = releaseItem,
//						    DocUrl = docUrl,
                        });

                        package.readme.AddReleaseNote(releaseItem);
                    }

                    packageDatas.ForEach(packageData =>
                    {
                        packageData.PackageVersions.Sort((a, b) =>
                                                         b.VersionNumber - a.VersionNumber);
                        packageData.readme.items.Sort((a, b) =>
                                                      b.VersionNumber - a.VersionNumber);
                    });

                    mOnGet.InvokeGracefully(packageDatas);

                    new PackageInfosRequestCache()
                    {
                        PackageDatas = packageDatas
                    }.Save();

                    Finished = true;
                }
            }, e =>
            {
                mOnGet.InvokeGracefully(null);
                Log.E(e);
            });
        }
Esempio n. 2
0
 public InstallPackage(PackageData requestPackageData)
 {
     mRequestPackageData = requestPackageData;
 }
        void OnResponse(ResponseType responseType, string response)
        {
            if (responseType == ResponseType.SUCCEED)
            {
                var responseJson = JObject.Parse(response);

                if (responseJson["code"].Value <string>() == "1")
                {
                    var packageInfosJson = responseJson["data"];

                    var packageDatas = new List <PackageData>();
                    foreach (var packageInfo in packageInfosJson)
                    {
                        var name = packageInfo["name"].Value <string>();

                        var package = packageDatas.Find(packageData => packageData.Name == name);

                        if (package == null)
                        {
                            package = new PackageData()
                            {
                                Name = name,
                            };

                            packageDatas.Add(package);
                        }

                        var id              = packageInfo["id"].Value <string>();
                        var version         = packageInfo["version"].Value <string>();
                        var url             = packageInfo["downloadUrl"].Value <string>();        // download_url
                        var installPath     = packageInfo["installPath"].Value <string>();
                        var releaseNote     = packageInfo["releaseNote"].Value <string>();
                        var createAt        = packageInfo["createAt"].Value <string>();
                        var creator         = packageInfo["username"].Value <string>();
                        var releaseItem     = new ReleaseItem(version, releaseNote, creator, DateTime.Parse(createAt), id);
                        var accessRightName = packageInfo["accessRight"].Value <string>();
                        var typeName        = packageInfo["type"].Value <string>();

                        var packageType = PackageType.FrameworkModule;

                        switch (typeName)
                        {
                        case "fm":
                            packageType = PackageType.FrameworkModule;
                            break;

                        case "s":
                            packageType = PackageType.Shader;
                            break;

                        case "agt":
                            packageType = PackageType.AppOrGameDemoOrTemplate;
                            break;

                        case "p":
                            packageType = PackageType.Plugin;
                            break;

                        case "master":
                            packageType = PackageType.Master;
                            break;
                        }

                        var accessRight = PackageAccessRight.Public;

                        switch (accessRightName)
                        {
                        case "public":
                            accessRight = PackageAccessRight.Public;
                            break;

                        case "private":
                            accessRight = PackageAccessRight.Private;
                            break;
                        }

                        package.PackageVersions.Add(new PackageVersion()
                        {
                            Id          = id,
                            Version     = version,
                            DownloadUrl = url,
                            InstallPath = installPath,
                            Type        = packageType,
                            AccessRight = accessRight,
                            Readme      = releaseItem,
                        });

                        package.readme.AddReleaseNote(releaseItem);
                    }

                    packageDatas.ForEach(packageData =>
                    {
                        packageData.PackageVersions.Sort((a, b) =>
                                                         b.VersionNumber - a.VersionNumber);
                        packageData.readme.items.Sort((a, b) =>
                                                      b.VersionNumber - a.VersionNumber);
                    });

                    mOnGet.InvokeGracefully(packageDatas);

                    new PackageInfosRequestCache()
                    {
                        PackageDatas = packageDatas
                    }.Save();

                    Finished = true;
                }
            }
        }