C# Umbraco以编程方式上载图像和裁剪器信息

C# Umbraco以编程方式上载图像和裁剪器信息,c#,asp.net-mvc,umbraco,umbraco7,C#,Asp.net Mvc,Umbraco,Umbraco7,我正在尝试将媒体从7.2移动到7.4,但移动到一个新实例。因此,基本上,我使用下面的代码从7.2实例中获取xml格式图像的结构和细节 umbraco.DataLayer.ISqlHelper SqlHelper = umbraco.BusinessLogic.Application.SqlHelper; int mediaId = -1; //Create an empty xmlDocument. System.Xml.Linq.XDocument xmlDocument = new

我正在尝试将媒体从7.2移动到7.4,但移动到一个新实例。因此,基本上,我使用下面的代码从7.2实例中获取xml格式图像的结构和细节

   umbraco.DataLayer.ISqlHelper SqlHelper = umbraco.BusinessLogic.Application.SqlHelper;

int mediaId = -1;
//Create an empty xmlDocument.
System.Xml.Linq.XDocument xmlDocument = new System.Xml.Linq.XDocument(
        new System.Xml.Linq.XElement("Media")
    );

if (mediaId == -1)
{
    //If the mediaId is -1 loop through all the top media nodes.
    using (umbraco.DataLayer.IRecordsReader dr = SqlHelper.ExecuteReader("Select id from umbracoNode where nodeObjectType = @type And parentId = -1 order by sortOrder",
        SqlHelper.CreateParameter("@type", umbraco.cms.businesslogic.media.Media._objectType)))
    {
        while (dr.Read())
        {
            //Get the hierarchical xml from each topnode and add it to the xmlDocument.
            xmlDocument.Root.Add(System.Xml.Linq.XElement.Parse(umbraco.library.GetMedia(dr.GetInt("id"), true).Current.OuterXml));
        }
    }
}
else
{
    //Get the hierarchical xml from the media id and add it to the xmlDocument.
    xmlDocument.Root.Add(System.Xml.Linq.XElement.Parse(umbraco.library.GetMedia(mediaId, true).Current.OuterXml));
}
它工作得很好,但现在我正在尝试将内容推送到新的媒体实例,我知道我可以使用下面的媒体服务创建文件夹和图像

var mediaImage = mediaService.CreateMedia("test4", 1152, "Image");
mediaImage.SetValue("umbracoFile", test, fileStream);
mediaService.Save(mediaImage);
但问题是,我有大量裁剪过的图像,但我不知道如何添加它们。下面是一个xml示例

 <Folder id="1126" parentID="-1" level="1" creatorID="0" sortOrder="0" createDate="2014-09-29T16:22:37" updateDate="2015-05-12T16:27:28" nodeName="Images" urlName="images" path="-1,1126" isDoc="" nodeType="1031" writerName="  Admin" writerID="0" version="3c3ccf09-e001-4fe5-8b1c-75a2da18d40c" template="0" nodeTypeAlias="Folder">
    <ImageCropper id="13081" parentID="1126" level="5" creatorID="0" sortOrder="4" createDate="2015-10-26T16:21:23" updateDate="2016-02-22T10:32:32" nodeName="Bla bla" urlName="test" path="-1,1126,1235,1378,1401,13081" isDoc="" nodeType="12390" writerName="  Admin" writerID="0" version="5860627c-f0f9-49e9-8114-3d52d3f93f03" template="0" nodeTypeAlias="ImageCropper">
              <umbracoHeight>200</umbracoHeight>
              <umbracoBytes>54244</umbracoBytes>
              <umbracoExtension>jpg</umbracoExtension>
              <umbracoFile>{ "focalPoint": { "left": 0.5, "top": 0.5 }, "src": "/media/392270/cropped-test.jpg", "crops": [ { "alias": "CTA Image", "width": 542, "height": 364, "coordinates": { "x1": 0.038364212277255755, "y1": 0, "x2": 0.0984410114844898, "y2": 0 } }, { "alias": "Wide CTA Image", "width": 960, "height": 320 }, { "alias": "Sidebar Image", "width": 400, "height": 333 }, { "alias": "Home Featured Videos Image", "width": 300, "height": 200, "coordinates": { "x1": 0.057971014492753624, "y1": 0, "x2": 0.072463768115942032, "y2": 0 } }, { "alias": "Support   Box Image", "width": 670, "height": 107 }, { "alias": "Council Landing Page Image", "width": 166, "height": 173 }, { "alias": "Trainee Committee Image", "width": 166, "height": 173 }, { "alias": "Masthead Image", "width": 1280, "height": 200 } ] }</umbracoFile>
           </ImageCropper>
           <ImageCropper id="13082" parentID="1401" level="5" creatorID="0" sortOrder="5" createDate="2015-10-26T16:26:25" updateDate="2016-02-22T10:32:51" nodeName="Getting into Medical School" urlName="getting-into-medical-school" path="-1,1126,1235,1378,1401,13082" isDoc="" nodeType="12390" writerName="  Admin" writerID="0" version="8fd4760d-fde4-42ff-9073-2d4170bd5fdf" template="0" nodeTypeAlias="ImageCropper">
              <umbracoHeight>313</umbracoHeight>
              <umbracoBytes>259343</umbracoBytes>
              <umbracoExtension>jpg</umbracoExtension>
              <umbracoFile>{ "focalPoint": { "left": 0.5, "top": 0.5 }, "src": "/media/392271/gh_rcs_250715_urgent_28-v2.jpg", "crops": [ { "alias": "CTA Image", "width": 542, "height": 364, "coordinates": { "x1": 0.042627479228088981, "y1": 0, "x2": 0.24691453363709465, "y2": 0 } }, { "alias": "Wide CTA Image", "width": 960, "height": 320 }, { "alias": "Sidebar Image", "width": 400, "height": 333 }, { "alias": "Home Featured Videos Image", "width": 300, "height": 200, "coordinates": { "x1": 0.042942073170731711, "y1": 0, "x2": 0.24135670731707312, "y2": 0 } }, { "alias": "Support   Box Image", "width": 670, "height": 107 }, { "alias": "Council Landing Page Image", "width": 166, "height": 173 }, { "alias": "Trainee Committee Image", "width": 166, "height": 173 }, { "alias": "Masthead Image", "width": 1280, "height": 200 } ] }</umbracoFile>
           </ImageCropper>

200
54244
jpg
{“focalPoint”:{“left”:0.5,“top”:0.5},“src”:“/media/392270/croped test.jpg”,“crops”:[{“alias”:“CTA图像”,“宽度”:542,“高度”:364,“坐标”:{“x1”:0.03836421227725555,“y1”:0,“x2”:0.0984410114844898,“y2”:0},{“alias”:“宽CTA图像”,“宽度”:960,“高度”:320},“alias”:“侧栏图像”,“宽度”:400,“高度”:333},{“别名”:“主页特色视频图像”,“宽度”:300,“高度”:200,“坐标”:{“x1”:0.057971014492753624,“y1”:0,“x2”:0.07246378115942032,“y2”:0},{“别名”:“支持框图像”,“宽度”:670,“高度”:107},{“别名”:“委员会登录页图像”,“宽度”:166,“高度”:173},{“别名”:学员委员会图像,“宽度”:166,“高度”:173},{“别名”:“桅杆头图像”,“宽度”:1280,“高度”:200}}
313
259343
jpg
{“焦点”:{“左”:0.5,“顶”:0.5},“src”:“/media/392271/gh_rcs_250715_emergency_28-v2.jpg”,“crops”:[{“别名”:“CTA图像”,“宽度”:542,“高度”:364,“坐标”:{“x1”:0.0426274792288981,“y1”:0,“x2”:0.246943363709465,“y2”:0},{“别名”:“宽CTA图像”,“宽度”:960,“高度”:320},“别名”,边栏“{”宽度:400,“高度”:333},{“别名”:“主页特色视频图像”,“宽度”:300,“高度”:200,“坐标”:{“x1”:0.042942073170731711,“y1”:0,“x2”:0.24135670731707312,“y2”:0},{“别名”:“支持框图像”,“宽度”:670,“高度”:107},{“别名”:“议会登录页图像”,“宽度”:166,“高度”:173},{“别名”:学员委员会图像,“宽度”:166,“高度”:173},{“别名”:“桅杆头图像”,“宽度”:1280,“高度”:200}}
正如您所看到的,nodeTypeAlias是ImageCropper,因此chow可以上传这些图像或在中插入裁剪器详细信息

可能吗