コード例 #1
0
ファイル: FilePathLogic.cs プロジェクト: ywscr/extensions
        public static void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                FileTypeLogic.Start(sb);

                sb.Include <FilePathEntity>()
                .WithQuery(() => p => new
                {
                    Entity = p,
                    p.Id,
                    p.FileName,
                    p.FileType,
                    p.Suffix
                });

                FilePathEntity.CalculatePrefixPair = CalculatePrefixPair;
                sb.Schema.EntityEvents <FilePathEntity>().PreSaving       += FilePath_PreSaving;
                sb.Schema.EntityEvents <FilePathEntity>().PreUnsafeDelete += new PreUnsafeDeleteHandler <FilePathEntity>(FilePathLogic_PreUnsafeDelete);

                new Graph <FilePathEntity> .Execute(FilePathOperation.Save)
                {
                    CanBeNew      = true,
                    CanBeModified = true,
                    Execute       = (fp, _) =>
                    {
                        if (!fp.IsNew)
                        {
                            var ofp = fp.ToLite().RetrieveAndRemember();

                            if (fp.FileName != ofp.FileName || fp.Suffix != ofp.Suffix)
                            {
                                using (Transaction tr = new Transaction())
                                {
                                    var preSufix = ofp.Suffix.Substring(0, ofp.Suffix.Length - ofp.FileName.Length);
                                    fp.Suffix = Path.Combine(preSufix, fp.FileName);
                                    fp.Save();
                                    fp.FileType.GetAlgorithm().MoveFile(ofp, fp);
                                    tr.Commit();
                                }
                            }
                        }
                    }
                }

                .Register();

                sb.AddUniqueIndex <FilePathEntity>(f => new { f.Suffix, f.FileType }); //With mixins, add AttachToUniqueIndexes to field

                QueryLogic.Expressions.Register((FilePathEntity fp) => fp.WebImage(), () => typeof(WebImage).NiceName(), "Image");
                QueryLogic.Expressions.Register((FilePathEntity fp) => fp.WebDownload(), () => typeof(WebDownload).NiceName(), "Download");
            }
        }
コード例 #2
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                FileTypeLogic.Start(sb, dqm);

                FilePathEmbedded.OnPreSaving += efp =>
                {
                    if (efp.BinaryFile != null) //First time
                    {
                        efp.SaveFile();
                    }
                };

                FilePathEmbedded.CalculatePrefixPair += CalculatePrefixPair;
            }
        }
コード例 #3
0
        public static void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                FileTypeLogic.Start(sb);

                FilePathEmbedded.CloneFunc = fp => new FilePathEmbedded(fp.FileType, fp.FileName, fp.GetByteArray());

                FilePathEmbedded.OnPreSaving += efp =>
                {
                    if (efp.BinaryFile != null) //First time
                    {
                        efp.SaveFile();
                    }
                };

                FilePathEmbedded.CalculatePrefixPair += CalculatePrefixPair;
            }
        }
コード例 #4
0
        public static void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                FileTypeLogic.Start(sb);

                FilePathEmbedded.CloneFunc = fp => new FilePathEmbedded(fp.FileType, fp.FileName, fp.GetByteArray());

                FilePathEmbedded.OnPreSaving += efp =>
                {
                    if (efp.BinaryFile != null) //First time
                    {
                        efp.SaveFile();
                    }
                };

                QueryLogic.Expressions.Register((FilePathEmbedded f) => f.WebImage(), () => typeof(WebImage).NiceName(), "Image");
                QueryLogic.Expressions.Register((FilePathEmbedded f) => f.WebDownload(), () => typeof(WebDownload).NiceName(), "Download");

                FilePathEmbedded.CalculatePrefixPair += CalculatePrefixPair;
            }
        }