Exemple #1
0
 private ExtentionPropertiesModel.Row GetRow(Guid id, ExtentionPropertyOwner owner)
 {
     if (owner == ExtentionPropertyOwner.Log)
     {
         var property = CurrentAccountDbContext.LogProperties.Find(id);
         if (property == null)
         {
             return(null);
         }
         return(new ExtentionPropertiesModel.Row()
         {
             Id = property.Id,
             DataType = property.DataType,
             Value = property.Value,
             Name = property.Name
         });
     }
     if (owner == ExtentionPropertyOwner.Event)
     {
         var property = CurrentAccountDbContext.EventProperties.Find(id);
         if (property == null)
         {
             return(null);
         }
         return(new ExtentionPropertiesModel.Row()
         {
             Id = property.Id,
             DataType = property.DataType,
             Value = property.Value,
             Name = property.Name
         });
     }
     if (owner == ExtentionPropertyOwner.Component)
     {
         var property = CurrentAccountDbContext.ComponentProperties.Find(id);
         if (property == null)
         {
             return(null);
         }
         return(new ExtentionPropertiesModel.Row()
         {
             Id = property.Id,
             DataType = property.DataType,
             Value = property.Value,
             Name = property.Name
         });
     }
     throw new Exception("Неизвестное значение owner: " + owner);
 }
Exemple #2
0
        public ActionResult DownloadFile(Guid id, ExtentionPropertyOwner owner)
        {
            var row = GetRow(id, owner);

            if (row == null)
            {
                throw new HttpException(404, "Файл не найден");
            }

            // банарный файл
            if (row.DataType == DataType.Binary)
            {
                var contentType = GuiHelper.GetContentType(row.Name);
                var bytes       = Convert.FromBase64String(row.Value);
                return(File(bytes, contentType, row.Name));
            }

            // текстовые файлы
            var textTypes = new[]
            {
                DataType.String,
                DataType.Unknown
            };

            if (textTypes.Contains(row.DataType))
            {
                var bytes = Encoding.UTF8.GetBytes(row.Value);
                bytes = Encoding.UTF8.GetPreamble().Concat(bytes).ToArray();

                var fileName = row.Name.EndsWith(".txt", StringComparison.InvariantCultureIgnoreCase)
                    ? row.Name
                    : row.Name + ".txt";

                return(File(bytes, "text/plain", fileName));
            }
            throw new Exception("Недопустимое для файла значение DataType: " + row.DataType);
        }