Example #1
0
        public TForm GetForm(string form)
        {
            var template = _o.ArrayObjects("templates").First(x => x.Get <string>("rel") == form);

            var method = template.Get <string>("method") == "post" ? HttpMethod.Post : HttpMethod.Get;
            var href   = template.Get <string>("href");

            var fields = template.ArrayObjects("data").ToDictionary(x => x.Get <string>("name"), x => x.Get <string>("value"));

            return(new TForm(method, new string[0], href, fields, _action));
        }
Example #2
0
 public static IEnumerable <Transition> Parse(JsonObject json)
 {
     return
         (json.ArrayObjects("transitions")
          .ConvertAll(
              x =>
              new Transition
     {
         Id = x.Get <int>("id"),
         Name = x.Get("name"),
         To = x.Get <Transition.TransitionTo>("to"),
         Fields = ParseFields(x.Get <Dictionary <string, JsonObject> >("fields"))
     }));
 }
Example #3
0
        public TLSchema GetTLSchemaFromJson(string json)
        {
            JsonObject tlSchemaJsonObject = JsonObject.Parse(json);

            List <TLCombinator> constructors = CreateConstructorsFromJsonArrayObjects(tlSchemaJsonObject.ArrayObjects("constructors"));
            List <TLCombinator> methods      = CreateMethodsFromJsonArrayObjects(tlSchemaJsonObject.ArrayObjects("methods"));
            List <TLType>       types        = UpdateAndGetTLTypes(constructors);

            var schema = new TLSchema {
                Constructors = constructors, Methods = methods, Types = types
            };

            return(schema);
        }
 public static IEnumerable<Transition> Parse(JsonObject json)
 {
     return
         json.ArrayObjects("transitions")
             .ConvertAll(
                 x =>
                     new Transition
                     {
                         Id = x.Get<int>("id"),
                         Name = x.Get("name"),
                         To = x.Get<Transition.TransitionTo>("to"),
                         Fields = ParseFields(x.Get<Dictionary<string, JsonObject>>("fields"))
                     });
 }
        private static CimFieldInfo ParseIssueFieldInfo(JsonObject json, string id)
        {
            var schema = json.Get <FieldSchema>("schema");

            return(new CimFieldInfo
            {
                Id = id,
                Name = json.Get("name"),
                Required = json.Get <bool>("required"),
                Schema = schema,
                Operations = json.Get <List <StandardOperation> >("operations"),
                AllowedValues = ParseAllowedValues(json.ArrayObjects("allowedValues"), schema),
                AutoCompleteUri = json.Get <Uri>("autoCompleteUrl")
            });
        }
Example #6
0
        /// <summary>
        /// From a provided REST API endpoint download a mod.
        /// </summary>
        public async Task DownloadMod(string url)
        {
            Downloading = true;
            string modZipPath;
            string modImagePath;
            string modExtractPath;
            string modString = string.Empty;

            using (WebClient wc = new WebClient()) {
                dynamic Data = new OnDownloadCompleteArgs();
                OnDownloadStart?.Invoke(this, Data);


                wc.DownloadProgressChanged += WCDownloadPercentChanged;
                try {
                    modString = await wc.DownloadStringTaskAsync(url);
                } catch (WebException ex) {
                    Data.ErrorMessage = ex.Message;
                    OnDownloadComplete?.Invoke(this, Data);
                    return;
                }
                JsonObject json = JsonObject.Parse(modString);
                // Let's make sure the slug doesn't have weird stuff.
                json["slug"] = string.Join(" ", json["slug"].Split(Path.GetInvalidFileNameChars().Concat(Path.GetInvalidPathChars()).ToArray()));
                if (json["compatible"] != "Yes")
                {
                    Data.ErrorMessage = Helpers._("Error.NotCompatible");
                    OnDownloadComplete?.Invoke(this, Data);
                    return;
                }
                m = new Mod(
                    json["id"],
                    json.ArrayObjects("title") [0]["rendered"],
                    DateTime.ParseExact(json["modified"].Replace("T", " "), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
                    json.ArrayObjects("content") [0]["rendered"],
                    json["author_name"],
                    url,
                    json["File"],
                    json["slug"],
                    json["slug"] + ".jpg"
                    );
                modZipPath     = zipPath + m.Slug + ".zip";
                modExtractPath = Mod.InstallPath + m.Slug + "\\";
                modImagePath   = Mod.ImagePath + m.Thumbnail;

                // Cleanup previous versions and files.
                Delete(m.Slug);
                if (File.Exists(modZipPath))
                {
                    File.Delete(modZipPath);
                }
                if (Directory.Exists(modExtractPath))
                {
                    Directory.Delete(modExtractPath, true);
                }
                if (File.Exists(modImagePath))
                {
                    File.Delete(modImagePath);
                }

                // And start downloading stuff.
                try {
                    await wc.DownloadFileTaskAsync(new System.Uri(json["image"]), modImagePath);
                } catch (WebException we) {
                    Data.ErrorMessage = we.Message;
                    OnDownloadComplete?.Invoke(this, Data);
                    return;
                }
                try {
                    await wc.DownloadFileTaskAsync(new System.Uri(m.File), modZipPath);
                } catch (WebException we) {
                    Data.ErrorMessage = we.Message;
                    OnDownloadComplete?.Invoke(this, Data);
                    return;
                }
                UnpackMod(modZipPath, modExtractPath);
                AvailableMods.Add(m);
                Data.Success = true;
                OnDownloadComplete?.Invoke(this, Data);
                UpdateSettings();
            }
            Downloading = false;
        }
Example #7
0
        public static TLSchema FromJson(string schemaText)
        {
            var typesBox = new TLTypesBox();

            JsonObject tlSchemaJsonObject = JsonObject.Parse(schemaText);

            IEnumerable <TLCombinator> constructors = CreateConstructorsFromJsonArrayObjects(tlSchemaJsonObject.ArrayObjects("constructors"), typesBox);
            IEnumerable <TLCombinator> methods      = CreateMethodsFromJsonArrayObjects(tlSchemaJsonObject.ArrayObjects("methods"), typesBox);

            return(new TLSchema(constructors, methods));
        }
        private static CimFieldInfo ParseIssueFieldInfo(JsonObject json, string id)
        {
            var schema = json.Get<FieldSchema>("schema");

            return new CimFieldInfo
            {
                Id = id,
                Name = json.Get("name"),
                Required = json.Get<bool>("required"),
                Schema = schema,
                Operations = json.Get<List<StandardOperation>>("operations"),
                AllowedValues = ParseAllowedValues(json.ArrayObjects("allowedValues"), schema),
                AutoCompleteUri = json.Get<Uri>("autoCompleteUrl")
            };
        }