当前位置: 首页>>代码示例>>C#>>正文


C# IMedia.SetValue方法代码示例

本文整理汇总了C#中IMedia.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# IMedia.SetValue方法的具体用法?C# IMedia.SetValue怎么用?C# IMedia.SetValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMedia的用法示例。


在下文中一共展示了IMedia.SetValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SaveMedia

        private void SaveMedia(XElement node, IMedia media, ZipFile zip)
        {
            media.Name = node.Attribute("name").Value;
            media.ParentId = GetMediaParentId(node);
            media.Key = new Guid(node.Attribute("guid").Value);

            int sortOrder;
            if (int.TryParse(node.Attribute("sortOrder").Value, out sortOrder))
            {
                media.SortOrder = sortOrder;
            }

            foreach (var propertyTag in node.Elements())
            {
                var dataTypeGuid = new Guid(propertyTag.Attribute("dataTypeGuid").Value);

                if (dataTypeGuid == new Guid(Constants.UploadDataTypeGuid))
                {
                    var fileName = propertyTag.Attribute("fileName").Value;
                    var umbracoFile = propertyTag.Attribute("umbracoFile").Value;

                    if (!string.IsNullOrWhiteSpace(umbracoFile))
                    {
                        media.SetValue(propertyTag.Name.ToString(), fileName, GetFileStream(umbracoFile, zip));
                    }
                    else
                    {
                        media.SetValue(propertyTag.Name.ToString(), string.Empty);
                    }
                }
                else if (!SpecialDataTypes.ContainsKey(dataTypeGuid))
                {
                    media.SetValue(propertyTag.Name.ToString(), propertyTag.Value);
                }
            }

            Services.MediaService.Save(media);
        }
开发者ID:EnjoyDigital,项目名称:Conveyor,代码行数:38,代码来源:ImportContent.cs

示例2: ImportMediaFile

        public static void ImportMediaFile(Guid guid, IMedia item)
        {
            string fileroot = IOHelper.MapPath(_mappedFilesRoot);
            string folder = Path.Combine(fileroot, guid.ToString());

            LogHelper.Debug<FileHelper>("Importing {0}", () => folder);
            if (!Directory.Exists(folder))
                return;

            //
            // we look for an existing folder, if it's there we get the
            // file info. we only want to import changed files, as it 
            // creates directories all the time
            //

            FileInfo currentFile = null; 
            // some is it already there logic ? 
            if (item.HasProperty("umbracoFile"))
            {
                LogHelper.Debug<FileHelper>("Has umbracoFile");
                if (item.GetValue("umbracoFile") != null)
                {
                    LogHelper.Debug<FileHelper>("umbracoFile value [{0}]", () => item.GetValue("umbracoFile").ToString() );
                    string umbracoFile = item.GetValue("umbracoFile").ToString();

                    // standard uploaded the path is a string . 
                    // for Umbraco 7's image cropper it's all JSON
                    string path = umbracoFile;
                    if ( !string.IsNullOrWhiteSpace(umbracoFile))
                    {
                        if ( IsJson(umbracoFile))
                        {
                            var jsonUmbracoFile = JsonConvert.DeserializeObject<dynamic>(umbracoFile);
                            path = jsonUmbracoFile.src;
                        }
                    }

                    LogHelper.Debug<FileHelper>("path {0}", () => path);

                    if (!string.IsNullOrWhiteSpace(path))
                    {
                        //
                        // we check it's in the media folder, because later we delete it and all it's sub folders
                        // if for some reason it was blank or mallformed we could trash the whole umbraco just here.
                        //
                        if (path.StartsWith("/media/"))
                        {
                            string f = IOHelper.MapPath(string.Format("~{0}", path));
                            if (System.IO.File.Exists(f))
                            {
                                LogHelper.Debug<FileHelper>("Getting info for {0}", () => f);
                                currentFile = new FileInfo(f);
                            }
                        }
                    }
                }
            }




            foreach (var file in Directory.GetFiles(folder, "*.*"))
            {

                LogHelper.Debug<FileHelper>("Import {0}", () => file);


                if (currentFile != null)
                {
                    // LogHelper.Debug<FileHelper>("Comparing {0} - {1}", () => currentFile.Name, () => file);
                    // do some file comparison, we only import if the new file
                    // is diffrent than the existing one..
                    if (!FilesAreEqual(currentFile, new FileInfo(file)))
                    {
                        LogHelper.Info<FileHelper>("Updating umbracoFile with {0} ", () => file);
                        string filename = Path.GetFileName(file);

                        FileStream s = new FileStream(file, FileMode.Open);
                        item.SetValue("umbracoFile", filename, s); // question this for imagecropper types... 
                        s.Close();

                        // ok so now we've gone and created a new folder, we need to delete the old on
                        if (Directory.Exists(currentFile.DirectoryName))
                        {
                            LogHelper.Info<FileHelper>("Removing old media folder location {0}", () => currentFile.DirectoryName);
                            Directory.Delete(currentFile.DirectoryName, true);
                        }
                    }
                    // LogHelper.Debug<FileHelper>("Done comparing {0} - {1}", () => currentFile.Name, () => file);
                }
                else
                {
                    // if we have no currentfile, that's because it's not been imported first time yet.
                    LogHelper.Info<FileHelper>("First time import of {0}", () => file);

                    FileStream s = new FileStream(file, FileMode.Open);
                    item.SetValue("umbracoFile", Path.GetFileName(file), s);
                    s.Close();
                }
                LogHelper.Debug<FileHelper>("<< Done Import {0}", () => file);
//.........这里部分代码省略.........
开发者ID:pbevis,项目名称:jumoo.usync,代码行数:101,代码来源:FileHelper.cs


注:本文中的IMedia.SetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。