示例#1
0
        private JToken ImportTraverse(JObject alpaca, JToken json)
        {
            var ModuleFilesFolder   = /*PortalSettings.HomeDirectory +*/ "OpenContent/Files/" + ModuleId.ToString() + "/";
            var ModuleCroppedFolder = /*PortalSettings.HomeDirectory +*/ "OpenContent/Cropped/" + ModuleId.ToString() + "/";

            return(JsonTraverse.Traverse(json.DeepClone(), alpaca["schema"] as JObject, alpaca["options"] as JObject, (data, schema, options) =>
            {
                var optionsType = options?.Value <string>("type");
                if (optionsType == "image" || optionsType == "file")
                {
                    return ImportFile(data, ModuleFilesFolder);
                }
                else if (optionsType == "mlimage" || optionsType == "mlfile")
                {
                    if (json is JObject)
                    {
                        var newObj = new JObject();
                        foreach (var item in (data as JObject).Children <JProperty>())
                        {
                            newObj[item.Name] = ImportFile(item.Value, ModuleFilesFolder);
                        }
                        return newObj;
                    }
                }
                else if (optionsType == "imagex")
                {
                    var folder = "";
                    var optionsFolder = options?.Value <string>("uploadfolder");
                    if (!string.IsNullOrEmpty(optionsFolder))
                    {
                        folder = optionsFolder + "/";
                    }
                    ImportFile(data, "url", ModuleFilesFolder, folder, true);
                    var cropfolder = folder;
                    var optionsCropFolder = options?.Value <string>("cropfolder");
                    if (!string.IsNullOrEmpty(optionsCropFolder))
                    {
                        cropfolder = optionsCropFolder + "/";
                    }
                    ImportFile(data, "cropUrl", ModuleCroppedFolder, cropfolder);
                }
                else if (optionsType == "mlimagex")
                {
                    var folder = "";
                    var optionsFolder = options?.Value <string>("uploadfolder");
                    if (!string.IsNullOrEmpty(optionsFolder))
                    {
                        folder = optionsFolder + "/";
                    }
                    var cropfolder = folder;
                    var optionsCropFolder = options?.Value <string>("cropfolder");
                    if (!string.IsNullOrEmpty(optionsCropFolder))
                    {
                        cropfolder = optionsCropFolder + "/";
                    }
                    if (json is JObject)
                    {
                        foreach (var item in (data as JObject).Children <JProperty>())
                        {
                            ImportFile(item.Value, "url", ModuleFilesFolder, folder, true);
                            ImportFile(item.Value, "cropUrl", ModuleCroppedFolder, cropfolder);
                        }
                    }
                }
                else if (optionsType == "file2")
                {
                    var filename = Files[data.ToString()].ToString();
                    var folder = ""; // ModuleFilesFolder;
                    var optionsFolder = options?.Value <string>("folder");
                    if (!string.IsNullOrEmpty(optionsFolder))
                    {
                        folder = optionsFolder + "/";
                    }
                    return ImportFileId(filename, ModuleFilesFolder, folder);
                }
                else if (optionsType == "mlfile2")
                {
                    var folder = ""; // ModuleFilesFolder;
                    var optionsFolder = options?.Value <string>("folder");
                    if (!string.IsNullOrEmpty(optionsFolder))
                    {
                        folder = optionsFolder + "/";
                    }
                    if (json is JObject)
                    {
                        var newObj = new JObject();
                        foreach (var item in (data as JObject).Children <JProperty>())
                        {
                            var filename = Files[data.ToString()].ToString();
                            newObj[item.Name] = ImportFileId(filename, ModuleFilesFolder, folder);
                        }
                        return newObj;
                    }
                }
                return data;
            }));
        }
示例#2
0
 private void ExportTraverse(JObject alpaca, JToken json)
 {
     JsonTraverse.Traverse(json.DeepClone(), alpaca["schema"] as JObject, alpaca["options"] as JObject, (data, schema, options) =>
     {
         var optionsType = options?.Value <string>("type");
         if (optionsType == "image" || optionsType == "file")
         {
             SaveFile(data.ToString(), "");
         }
         else if (optionsType == "mlimage" || optionsType == "mlfile")
         {
             if (json is JObject)
             {
                 foreach (var item in (data as JObject).Children <JProperty>())
                 {
                     SaveFile(item.Value.ToString(), "");
                 }
             }
         }
         else if (optionsType == "imagex")
         {
             var folder        = "";
             var optionsFolder = options?.Value <string>("uploadfolder");
             if (!string.IsNullOrEmpty(optionsFolder))
             {
                 folder = optionsFolder + "/";
             }
             var cropfolder        = folder;
             var optionsCropFolder = options?.Value <string>("cropfolder");
             if (!string.IsNullOrEmpty(optionsCropFolder))
             {
                 cropfolder = optionsCropFolder + "/";
             }
             SaveFile(data?["url"].ToString(), folder);
             SaveFile(data?["cropUrl"].ToString(), cropfolder);
         }
         else if (optionsType == "mlimagex")
         {
             var folder        = "";
             var optionsFolder = options?.Value <string>("uploadfolder");
             if (!string.IsNullOrEmpty(optionsFolder))
             {
                 folder = optionsFolder + "/";
             }
             var cropfolder        = folder;
             var optionsCropFolder = options?.Value <string>("cropfolder");
             if (!string.IsNullOrEmpty(optionsCropFolder))
             {
                 cropfolder = optionsCropFolder + "/";
             }
             if (json is JObject)
             {
                 foreach (var item in (data as JObject).Children <JProperty>())
                 {
                     if (item.Type == JTokenType.Object)
                     {
                         SaveFile(item.Value?["url"].ToString(), folder);
                         SaveFile(item.Value?["cropUrl"].ToString(), cropfolder);
                     }
                 }
             }
         }
         else if (optionsType == "file2")
         {
             var folder        = "";
             var optionsFolder = options?.Value <string>("folder");
             if (!string.IsNullOrEmpty(optionsFolder))
             {
                 folder = optionsFolder + "/";
             }
             SaveFile(data.Value <int>(), folder);
         }
         else if (optionsType == "mlfile2")
         {
             var folder        = "";
             var optionsFolder = options?.Value <string>("folder");
             if (!string.IsNullOrEmpty(optionsFolder))
             {
                 folder = optionsFolder + "/";
             }
             if (json is JObject)
             {
                 foreach (var item in (data as JObject).Children <JProperty>())
                 {
                     SaveFile(item.Value <int>(), folder);
                 }
             }
         }
     });
 }