/// <summary>
        /// 保存之前检查文章配置
        /// </summary>
        public override void BeforeSave()
        {
            if (base.ObjektStatus == ObjektStatus.NewModified)
            {
                SystemConfiguration sysArticCommentGlobal = ObjektFactory.Find <SystemConfiguration>("249509bf3a0d414ead15911013ad7dbb@SystemConfiguration");
                switch (sysArticCommentGlobal.Value)
                {
                case "6d5504f429304db5914989c2f2f98f3f@Value":
                    throw new Exception("不允许评论");

                case "377ed2338daa463090f7c0c19195eb5c@Value":
                    if (!(base.Source as FeArticle).CanComment)
                    {
                        throw new Exception("该文章不允许评论");
                    }
                    break;

                default:
                    throw new Exception("未检测到文章配置");

                case "48632d3bf3dd4c899480044e5b0355da@Value":
                    break;
                }
                FeComment feComment = base.Related as FeComment;
                if (feComment.Parent == null)
                {
                    SystemConfiguration sysArticCommentApproved2 = ObjektFactory.Find <SystemConfiguration>("f7fa2e0a9bc4462892e19210c804fdf3@SystemConfiguration");
                    if (sysArticCommentApproved2.Value == "True")
                    {
                        feComment.ApprovalStatus = ObjektFactory.Find <Value>("fd96691ff35f46db9fb42464db910972@Value");
                    }
                    else
                    {
                        feComment.ApprovalStatus = ObjektFactory.Find <Value>("e87630c5ca374e98a454287ff8484b68@Value");
                    }
                }
                else
                {
                    SystemConfiguration sysArticCommentApproved = ObjektFactory.Find <SystemConfiguration>("466370a15ebc45f2959909b13c9d5b20@SystemConfiguration");
                    if (sysArticCommentApproved.Value == "True")
                    {
                        feComment.ApprovalStatus = ObjektFactory.Find <Value>("fd96691ff35f46db9fb42464db910972@Value");
                    }
                    else
                    {
                        feComment.ApprovalStatus = ObjektFactory.Find <Value>("e87630c5ca374e98a454287ff8484b68@Value");
                    }
                }
                SystemConfiguration sysArticCommentTourist = ObjektFactory.Find <SystemConfiguration>("f86f83ae533849388c3f8349c2b7488d@SystemConfiguration");
                if (sysArticCommentTourist.Value == "False" && User.Current.Id == "28ca8458ea9748c1a496c567a36fad31@User")
                {
                    throw new Exception("不允许游客评论");
                }
            }
            base.BeforeSave();
        }
Exemple #2
0
        /// <summary>
        /// 设置指定对象的seo关键字。
        /// </summary>
        /// <param name="keys"></param>
        /// <param name="relationshipName"></param>
        /// <param name="sourceId"></param>
        public static void SetObjektSeo(List <string> keys, string relationshipName, string sourceId)
        {
            List <FeSeoKey> entityKeys = new List <FeSeoKey>();

            foreach (string key in keys)
            {
                FeSeoKey entity = new ObjektCollection <FeSeoKey>(Klass.ForId("FeSeoKey@Klass"), new WhereClause("\"key\" = '" + key + "'")).TryGetSingleResult();
                if (entity == null)
                {
                    entity     = new FeSeoKey();
                    entity.Key = key;
                    entity.Save();
                }
                IEnumerable <FeSeoKey> query = from t in entityKeys
                                               where t.Key == entity.Key
                                               select t;
                if (query.Count() == 0)
                {
                    entityKeys.Add(entity);
                }
            }
            Objekt objekt = ObjektFactory.Find(sourceId);
            List <RelationshipObjekt> relationshipList = objekt.ROCC.GetROC(relationshipName).ToList();
            List <RelationshipObjekt> deleteList       = new List <RelationshipObjekt>();

            foreach (RelationshipObjekt item3 in relationshipList)
            {
                IEnumerable <FeSeoKey> existQuery2 = from t in entityKeys
                                                     where t.Id == item3.Related.Id
                                                     select t;
                if (existQuery2.Count() == 0)
                {
                    deleteList.Add(item3);
                }
            }
            foreach (RelationshipObjekt item4 in deleteList)
            {
                item4.Delete();
                item4.Save();
            }
            foreach (FeSeoKey item5 in entityKeys)
            {
                IEnumerable <RelationshipObjekt> existQuery = from t in relationshipList
                                                              where t.Related.Id == item5.Id
                                                              select t;
                if (existQuery.Count() == 0)
                {
                    RelationshipObjekt relationship = ObjektFactory.New <RelationshipObjekt>(Klass.ForName(relationshipName));
                    relationship.Source  = objekt;
                    relationship.Related = item5;
                    relationship.Save();
                }
            }
        }
Exemple #3
0
 /// <summary>
 ///
 /// </summary>
 public override void BeforeSave()
 {
     if (base.ObjektStatus == ObjektStatus.NewModified)
     {
         SystemConfiguration sysArticGlobal = ObjektFactory.Find <SystemConfiguration>("58e502ecf56144cdb67ff129b6e6e4d5@SystemConfiguration");
         if (sysArticGlobal.Value == "False")
         {
             ApprovalStatus = ObjektFactory.Find <Value>("e87630c5ca374e98a454287ff8484b68@Value");
         }
         else
         {
             ApprovalStatus = ObjektFactory.Find <Value>("fd96691ff35f46db9fb42464db910972@Value");
         }
     }
     base.BeforeSave();
 }
Exemple #4
0
        /// <summary>
        ///     设置指定对象的属性。
        /// </summary>
        /// <param name="characters"></param>
        /// <param name="relationshipName"></param>
        /// <param name="sourceId"></param>
        public static void SetObjektCharacter(List <string> characters, string relationshipName, string sourceId)
        {
            Objekt objekt = ObjektFactory.Find(sourceId);
            List <RelationshipObjekt> relationshipList = objekt.ROCC.GetROC(relationshipName).ToList();

            foreach (RelationshipObjekt item in relationshipList)
            {
                item.Delete();
                item.Save();
            }
            foreach (string character in characters)
            {
                RelationshipObjekt relationship = ObjektFactory.New <RelationshipObjekt>(Klass.ForName(relationshipName));
                relationship.Source  = objekt;
                relationship.Related = ObjektFactory.Find(character);
                relationship.Save();
            }
        }
Exemple #5
0
        /// <summary>
        /// 获取会话上下文,如没有设置会话上下文,则返回guest身份的会话上下文
        /// </summary>
        /// <returns>持有的会话上下文,如没有设置会话上下文,则返回guest身份的会话上下文</returns>
        public override SessionContext Get()
        {
            HttpContext current = HttpContext.Current;

            if (current == null)
            {
                throw new Exception("当前计算无有效HTTP上下文!");
            }
            HttpSessionState session = current.Session;

            if (session == null)
            {
                return(new SessionContext(ObjektFactory.Find <User>("28ca8458ea9748c1a496c567a36fad31@User")));
            }
            if (session[sessionContextKey] != null)
            {
                return(session[sessionContextKey] as SessionContext);
            }
            return(new SessionContext(ObjektFactory.Find <User>("28ca8458ea9748c1a496c567a36fad31@User")));
        }
Exemple #6
0
        /// <summary>
        /// 设置指定对象的seo关键字。
        /// </summary>
        /// <param name="tags"></param>
        /// <param name="relationshipName"></param>
        /// <param name="sourceId"></param>
        public static void SetObjektTag(List <string> tags, string relationshipName, string sourceId)
        {
            List <FeTag> entityTags = new List <FeTag>();

            foreach (string tag in tags)
            {
                FeTag entity = new ObjektCollection <FeTag>(Klass.ForId("FeTag@Klass"), new WhereClause("\"tag\" = '" + tag + "'")).TryGetSingleResult();
                if (entity == null)
                {
                    entity      = new FeTag();
                    entity.Tag  = tag;
                    entity.From = ObjektFactory.Find <Value>("75d290896b3d40ad802c9d6b04d61a9b@Value");
                    entity.Save();
                }
                IEnumerable <FeTag> query = from t in entityTags
                                            where t.Tag == entity.Tag
                                            select t;
                if (query.Count() == 0)
                {
                    entityTags.Add(entity);
                }
            }
            Objekt objekt = ObjektFactory.Find(sourceId);
            List <RelationshipObjekt> relationshipList = objekt.ROCC.GetROC(relationshipName).ToList();

            foreach (RelationshipObjekt item2 in relationshipList)
            {
                item2.Delete();
                item2.Save();
            }
            foreach (FeTag item3 in entityTags)
            {
                RelationshipObjekt relationship = ObjektFactory.New <RelationshipObjekt>(Klass.ForName(relationshipName));
                relationship.Source  = objekt;
                relationship.Related = item3;
                relationship.Save();
            }
        }
Exemple #7
0
 /// <summary>
 /// 创建水印
 /// </summary>
 /// <param name="warterid"></param>
 /// <param name="fileid"></param>
 /// <returns></returns>
 public Stream CreateWarterImage(string warterid, string fileid)
 {
     GroupflyGroup.Platform.ObjectFramework.File waterImage = ObjektFactory.Find <GroupflyGroup.Platform.ObjectFramework.File>(fileid);
     return(CreateWarterImage(warterid, waterImage.FileContent));
 }
Exemple #8
0
        /// <summary>
        /// 生成水印
        /// </summary>
        /// <param name="warterid"></param>
        /// <param name="imgStream"></param>
        /// <returns></returns>
        public Stream CreateWarterImage(string warterid, Stream imgStream)
        {
            FeWatermark  watermarkType      = ObjektFactory.Find <FeWatermark>(warterid);
            MemoryStream result             = null;
            double       inttransparency2   = 1.0;
            string       tlocationValueName = watermarkType.Location.Value_;

            using (Bitmap bitmap = new Bitmap(imgStream))
            {
                if (watermarkType.Type.Id == "af8d0384224e46e7a556ef06a019b1bd@Value")
                {
                    string tfontSizeName        = watermarkType.FontSize.Value_;
                    string tfontfamilyValueName = watermarkType.Font.Value_;
                    inttransparency2 = Convert.ToDouble(watermarkType.Transparency) / 100.0 * 255.0;
                    float fontsize    = float.Parse(tfontSizeName);
                    float textwidth   = (float)watermarkType.Text.Length * fontsize;
                    float rectx       = 0f;
                    float recty       = 0f;
                    float rectwidth   = (float)watermarkType.Text.Length * (fontsize + 8f);
                    float rectheight  = fontsize + 8f;
                    float imageHeight = (float)bitmap.Height;
                    float imageWeight = (float)bitmap.Width;
                    switch (tlocationValueName)
                    {
                    case "1":
                        rectx = 0f;
                        recty = 0f;
                        break;

                    case "2":
                        rectx = imageWeight / 2f - rectwidth / 2f;
                        recty = 0f;
                        break;

                    case "3":
                        rectx = imageWeight - rectwidth;
                        recty = 0f;
                        break;

                    case "4":
                        rectx = 0f;
                        recty = imageHeight / 2f - rectheight / 2f;
                        break;

                    case "5":
                        rectx = imageWeight / 2f - rectwidth / 2f;
                        recty = imageHeight / 2f - rectheight / 2f;
                        break;

                    case "6":
                        rectx = imageWeight - rectwidth;
                        recty = imageHeight / 2f - rectheight / 2f;
                        break;

                    case "7":
                        rectx = 0f;
                        recty = imageHeight - rectheight;
                        break;

                    case "8":
                        rectx = imageWeight / 2f - rectwidth / 2f;
                        recty = imageHeight - rectheight;
                        break;

                    case "9":
                        rectx = imageWeight - rectwidth;
                        recty = imageHeight - rectheight;
                        break;
                    }
                    RectangleF textarea   = new RectangleF(rectx, recty, rectwidth, rectheight);
                    Font       font       = new Font(tfontfamilyValueName, fontsize);
                    Color      color      = ColorTranslator.FromHtml(watermarkType.FontColor);
                    Brush      whitebrush = new SolidBrush(Color.FromArgb(Convert.ToInt32(inttransparency2), color));
                    Brush      blackbrush = new SolidBrush(Color.FromArgb(14492536));
                    using (Graphics g = Graphics.FromImage(bitmap))
                    {
                        g.FillRectangle(blackbrush, rectx, recty, rectwidth, rectheight);
                        StringFormat strFormat = new StringFormat();
                        strFormat.Alignment = StringAlignment.Center;
                        g.DrawString(watermarkType.Text, font, whitebrush, textarea, strFormat);
                        result = new MemoryStream();
                        bitmap.Save(result, bitmap.RawFormat);
                    }
                }
                else
                {
                    int phWidth  = bitmap.Width;
                    int phHeight = bitmap.Height;
                    using (Bitmap bmPhoto = new Bitmap(phWidth, phHeight, PixelFormat.Format24bppRgb))
                    {
                        bmPhoto.SetResolution(bitmap.HorizontalResolution, bitmap.VerticalResolution);
                        using (Graphics grPhoto = Graphics.FromImage(bmPhoto))
                        {
                            using (Image imgWatermark = new Bitmap(watermarkType.imageFile.FileContent))
                            {
                                int wmWidth  = imgWatermark.Width;
                                int wmHeight = imgWatermark.Height;
                                grPhoto.SmoothingMode = SmoothingMode.AntiAlias;
                                grPhoto.DrawImage(bitmap, new Rectangle(0, 0, phWidth, phHeight), 0, 0, phWidth, phHeight, GraphicsUnit.Pixel);
                                using (Bitmap bmWatermark = new Bitmap(bmPhoto))
                                {
                                    bmWatermark.SetResolution(bitmap.HorizontalResolution, bitmap.VerticalResolution);
                                    using (Graphics grWatermark = Graphics.FromImage(bmWatermark))
                                    {
                                        ImageAttributes imageAttributes = new ImageAttributes();
                                        ColorMap        colorMap        = new ColorMap();
                                        colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
                                        colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);
                                        ColorMap[] remapTable = new ColorMap[1]
                                        {
                                            colorMap
                                        };
                                        imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);
                                        float     alpha = float.Parse(watermarkType.Transparency.ToString()) / 100f;
                                        float[][] colorMatrixElements = new float[5][]
                                        {
                                            new float[5]
                                            {
                                                1f,
                                                0f,
                                                0f,
                                                0f,
                                                0f
                                            },
                                            new float[5]
                                            {
                                                0f,
                                                1f,
                                                0f,
                                                0f,
                                                0f
                                            },
                                            new float[5]
                                            {
                                                0f,
                                                0f,
                                                1f,
                                                0f,
                                                0f
                                            },
                                            new float[5]
                                            {
                                                0f,
                                                0f,
                                                0f,
                                                alpha,
                                                0f
                                            },
                                            new float[5]
                                            {
                                                0f,
                                                0f,
                                                0f,
                                                0f,
                                                1f
                                            }
                                        };
                                        ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements);
                                        imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
                                        int xPosOfWm = 0;
                                        int yPosOfWm = 0;
                                        switch (tlocationValueName)
                                        {
                                        case "1":
                                            xPosOfWm = 0;
                                            yPosOfWm = 0;
                                            break;

                                        case "2":
                                            xPosOfWm = phWidth / 2 - wmWidth / 2;
                                            yPosOfWm = 0;
                                            break;

                                        case "3":
                                            xPosOfWm = phWidth - wmWidth;
                                            yPosOfWm = 0;
                                            break;

                                        case "4":
                                            xPosOfWm = 0;
                                            yPosOfWm = phHeight / 2 - wmHeight / 2;
                                            break;

                                        case "5":
                                            xPosOfWm = phWidth / 2 - wmWidth / 2;
                                            yPosOfWm = phHeight / 2 - wmHeight / 2;
                                            break;

                                        case "6":
                                            xPosOfWm = phWidth - wmWidth;
                                            yPosOfWm = phHeight / 2 - wmHeight / 2;
                                            break;

                                        case "7":
                                            xPosOfWm = 0;
                                            yPosOfWm = phHeight - wmHeight;
                                            break;

                                        case "8":
                                            xPosOfWm = phWidth / 2 - wmWidth / 2;
                                            yPosOfWm = phHeight - wmHeight;
                                            break;

                                        case "9":
                                            xPosOfWm = phWidth - wmWidth;
                                            yPosOfWm = phHeight - wmHeight;
                                            break;
                                        }
                                        grWatermark.DrawImage(imgWatermark, new Rectangle(xPosOfWm, yPosOfWm, wmWidth, wmHeight), 0, 0, wmWidth, wmHeight, GraphicsUnit.Pixel, imageAttributes);
                                        result = new MemoryStream();
                                        bmWatermark.Save(result, bitmap.RawFormat);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
Exemple #9
0
        private void Error(object sender, EventArgs e)
        {
            SessionContext sessionContext = null;

            if (PersistenceContext.IsExisting)
            {
                if (PersistenceContext.SessionContext.IsDiagnosis)
                {
                    string        loginName     = User.Current.LoginName;
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.Append(loginName).Append(" ObjetkFrameworkWebAdapter ").Append("PersitentContextAutoFinish(Failure:Discard) ")
                    .Append(PersistenceContext.GetString());
                    diagnosis.Info(stringBuilder);
                }
                sessionContext = PersistenceContext.SessionContext;
                if (!PersistenceContext.IsTransaction)
                {
                    try
                    {
                        PersistenceContext.Discard();
                    }
                    catch (Exception exception)
                    {
                        log.Warn("未处理异常检查,自动结束(Discard)当前持久化上下文出错。", exception);
                    }
                }
                else
                {
                    PersistenceContext.Discard();
                }
            }
            string message    = httpApplication.Server.GetLastError().Message;
            string stackTrace = httpApplication.Server.GetLastError().StackTrace;

            log.Error(message + stackTrace);
            try
            {
                if (sessionContext == null)
                {
                    sessionContext = new SessionContext("Web未处理异常", ObjektFactory.Find <User>("e2c4e2f4ecec4d6d8dce2fe6c831352e@User"));
                }
                if (!PersistenceContext.IsExisting)
                {
                    PersistenceContext.BeginTransaction(sessionContext);
                }
                Objekt    value     = ObjektFactory.Find("3c757b8d46364133a2061a455394d640@Value");
                Objekt    value2    = ObjektFactory.Find("97dff0c8a32542bc8c28e5c10c9cc3c9@Value");
                string    value3    = $"{message}发生在{HttpContext.Current.Request.RawUrl},错误堆栈{stackTrace}";
                SystemLog systemLog = new SystemLog();
                systemLog.SetProperty("type", value);
                systemLog.SetProperty("logType", value2);
                systemLog.SetProperty("abstract", message);
                systemLog.SetProperty("detail", value3);
                systemLog.Save();
                PersistenceContext.Accept();
            }
            catch
            {
                PersistenceContext.Discard();
            }
        }
Exemple #10
0
 /// <summary>
 /// </summary>
 /// <param name="fileId"></param>
 public FeFile(string fileId)
     : this(ObjektFactory.Find <File>(fileId))
 {
 }