Example #1
0
        protected override ViolationRequest PrepareRequest(ISyncContext context)
        {
            var cfg = GetSyncConfig();

            using (var db = context.CreateDBContext())
                return
                    new ViolationRequest
                    {
                        UserName         = cfg.Login,
                        Password         = cfg.Password,
                        LastRowVersion   = context.DBVars()[_rvVarSlotName].FromHexString(),
                        SubscribedForums = db.GetSubscribedForums()
                    };
        }
Example #2
0
 protected override PostRequest PrepareRequest(ISyncContext context)
 {
     using (var db = context.CreateDBContext())
     {
         var writed =
             db
             .OutboxMessages(m => !m.Hold)
             .Select(
                 m =>
                 new PostMessageInfo
         {
             forumId        = m.ForumID,
             localMessageId = m.ID,
             message        = m.Body
                              + (string.IsNullOrEmpty(m.Tagline)
                                                                                 ? ""
                                                                                 : "\r\n[tagline]{0}[/tagline]".FormatStr(m.Tagline)),
             parentId = m.ReplyToID,
             subject  = m.Subject
         })
             .ToArray();
         var rates =
             db
             .OutboxRates()
             .Select(
                 r =>
                 new PostRatingInfo
         {
             localRatingId = r.ID,
             messageId     = r.MessageID,
             rate          = (int)r.RateType
         })
             .ToArray();
         var cfg = GetSyncConfig();
         return
             (new PostRequest
         {
             userName = cfg.Login,
             password = cfg.Password,
             writedMessages = writed,
             rates = rates
         });
     }
 }
Example #3
0
        protected override void ProcessResponse(
            ISyncContext context,
            ViolationRequest request,
            ViolationResponse response)
        {
            using (var db = context.CreateDBContext())
                using (var tx = db.BeginTransaction())
                {
                    foreach (var violation in response.Violations)
                    {
                        db
                        .Violations()
                        // ReSharper disable AccessToModifiedClosure
                        .Value(_ => _.MessageID, () => violation.MessageID)
                        .Value(_ => _.PenaltyType, () => (PenaltyType)violation.PenaltyType)
                        .Value(_ => _.Reason, () => violation.Reason)
                        .Value(_ => _.Create, () => violation.CreatedOn)
                        // ReSharper restore AccessToModifiedClosure
                        .Insert();
                    }
                    tx.Commit();
                }

            if (response.Violations.Length > 0)
            {
                JanusViolationInfo max = null;

                foreach (var v in response.Violations)
                {
                    if (max == null || RVValue(max.RowVersion) < RVValue(v.RowVersion))
                    {
                        max = v;
                    }
                }
                if (max != null)
                {
                    context.DBVars()[_rvVarSlotName] = max.RowVersion.ToHexString();
                }
            }
        }
        protected override void ProcessResponse(
            ISyncContext context,
            ForumRequest request,
            ForumResponse response)
        {
            var newForums = 0;

            if (response.forumList.Length > 0)
            {
                using (var db = context.CreateDBContext())
                    using (var tx = db.BeginTransaction())
                    {
                        newForums = SyncServerForums(db, response.forumList);
                        tx.Commit();
                    }
            }
            context.DBVars()[_lastForumListRowVersion] = response.forumsRowVersion.ToHexString();
            context.StatisticsContainer.AddValue(JanusATInfo.ForumsStats, response.forumList.Length);
            if (newForums > 0)
            {
                context.StatisticsContainer.AddValue(JanusATInfo.NewForumsStat, newForums);
            }
        }