예제 #1
0
        private List <DataObject> ExecuteOneQuery(JObject jsonQuery)
        {
            QueryBase queryBase;
            string    command = ((string)jsonQuery.GetProperty("cmd").Value).Trim();

            if (command == "select")
            {
                queryBase = new QuerySelect(this, jsonQuery);
            }
            else if (command == "insert")
            {
                queryBase = new QueryInsert(this, jsonQuery);
            }
            else if (command == "update")
            {
                queryBase = new QueryUpdate(this, jsonQuery);
            }
            else if (command == "delete")
            {
                queryBase = new QueryDelete(this, jsonQuery);
            }
            else
            {
                throw new AegisException(RoseResult.UnknownCommand);
            }


            var ret = queryBase.Execute();

            return(ret);
        }
예제 #2
0
        public async Task <IActionResult> PostReply([FromBody] QueryUpdate queryUpdate)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        IsDomainValidationErrors = true,
                        StatusCode = ((int)ResponseStatus.BadRequest).ToString(),
                        Message = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage))
                    }));
                }

                NotificationsDataAccess _notificationsDataAccess = new NotificationsDataAccess(_configuration);

                DatabaseResponse response = await _notificationsDataAccess.PostReply(queryUpdate);

                if (response.ResponseCode == (int)DbReturnValue.UpdateSuccess)
                {
                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = true,
                        IsDomainValidationErrors = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.UpdateSuccess),
                        ReturnedObject = response.Results
                    }));
                }
                else
                {
                    Log.Error(EnumExtensions.GetDescription(DbReturnValue.UpdationFailed));

                    return(Ok(new OperationResponse
                    {
                        HasSucceeded = false,
                        IsDomainValidationErrors = false,
                        Message = EnumExtensions.GetDescription(DbReturnValue.AlreadyReplied),
                        ReturnedObject = response.Results
                    }));
                }
            }
            catch (Exception ex)
            {
                Log.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));

                return(Ok(new OperationResponse
                {
                    HasSucceeded = false,
                    Message = StatusMessages.ServerError,
                    StatusCode = ((int)ResponseStatus.ServerError).ToString(),
                    IsDomainValidationErrors = false
                }));
            }
        }
예제 #3
0
        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="groupName">组名</param>
        /// <param name="fileId">文件名</param>
        /// <param name="clusterName">集群名称</param>
        /// <returns>是否删除成功</returns>

        public async ValueTask <bool> RemoveFileAsync(string groupName, string fileId, string clusterName = "")
        {
            var queryUpdateRequest  = new QueryUpdate(groupName, fileId);
            var queryUpdateResponse = await _executer.Execute(queryUpdateRequest, clusterName);

            var storageNode = new StorageNode(queryUpdateResponse.GroupName, queryUpdateResponse.IPAddress, queryUpdateResponse.Port, 0);

            var request  = new DeleteFile(groupName, fileId);
            var response = await _executer.Execute(request, clusterName, storageNode.ConnectionAddress);

            return(response.Success);
        }
예제 #4
0
        /// <summary>
        /// 附加文件
        /// </summary>
        /// <param name="groupName">组名</param>
        /// <param name="fileId">文件名</param>
        /// <param name="content">文件内容</param>
        /// <param name="clusterName">集群名称</param>
        /// <returns>文件名</returns>
        public async ValueTask <string> AppendFileAsync(string groupName, string fileId, byte[] content, string clusterName = "")
        {
            var queryUpdateRequest  = new QueryUpdate(groupName, fileId);
            var queryUpdateResponse = await _executer.Execute(queryUpdateRequest, clusterName);

            var storageNode = new StorageNode(queryUpdateResponse.GroupName, queryUpdateResponse.IPAddress, queryUpdateResponse.Port, 0);

            var request  = new AppendFile(fileId, content);
            var response = await _executer.Execute(request, clusterName, storageNode.ConnectionAddress);

            return(response.FileId);
        }
예제 #5
0
        /// <summary>
        /// 上传从文件
        /// </summary>
        /// <param name="groupName">组名</param>
        /// <param name="masterFileId">主文件名</param>
        /// <param name="prefixName">从文件后缀</param>
        /// <param name="content">文件内容</param>
        /// <param name="fileExt">文件扩展名(注意:不包含".")</param>
        /// <param name="clusterName">集群名称</param>
        /// <returns>文件名</returns>
        public async ValueTask <string> UploadSlaveFileAsync(string groupName, string masterFileId, string prefixName, byte[] content, string fileExt, string clusterName = "")
        {
            fileExt = fileExt.TrimStart('.');
            var queryUpdateRequest  = new QueryUpdate(groupName, masterFileId);
            var queryUpdateResponse = await _executer.Execute(queryUpdateRequest, clusterName);

            var storageNode = new StorageNode(queryUpdateResponse.GroupName, queryUpdateResponse.IPAddress, queryUpdateResponse.Port, 0);

            var request  = new UploadSlaveFile(masterFileId, prefixName, fileExt, content);
            var response = await _executer.Execute(request, clusterName, storageNode.ConnectionAddress);

            return(response.FileId);
        }
예제 #6
0
        public override Node VisitQueryUpdate(QueryUpdate update)
        {
            update.Source = this.VisitExpression(update.Source);
            Composer saveContext = this.contextComposer;
            bool     savehcr     = this.hasContextReference;
            Composer c           = this.contextComposer = this.GetComposer(update.Source);

            this.hasContextReference = false;
            this.VisitExpressionList(update.UpdateList);
            this.contextComposer     = saveContext;
            this.hasContextReference = savehcr;
            return(this.Compose(update, c));
        }
예제 #7
0
        /// <summary>
        /// 上传从文件
        /// </summary>
        /// <param name="groupName">组名</param>
        /// <param name="masterFileId">主文件名</param>
        /// <param name="prefixName">从文件后缀</param>
        /// <param name="filename">本地文件名</param>
        /// <param name="clusterName">集群名称</param>
        /// <returns>文件名</returns>
        public async ValueTask <string> UploadSlaveFileAsync(string groupName, string masterFileId, string prefixName, string filename, string clusterName = "")
        {
            var queryUpdateRequest  = new QueryUpdate(groupName, masterFileId);
            var queryUpdateResponse = await _executer.Execute(queryUpdateRequest, clusterName);

            var storageNode = new StorageNode(queryUpdateResponse.GroupName, queryUpdateResponse.IPAddress, queryUpdateResponse.Port, 0);

            string extension = Path.GetExtension(filename).Substring(1);
            var    fs        = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
            var    request   = new UploadSlaveFile(masterFileId, prefixName, extension, fs);
            var    response  = await _executer.Execute(request, clusterName, storageNode.ConnectionAddress);

            return(response.FileId);
        }
예제 #8
0
        public async Task <DatabaseResponse> PostReply(QueryUpdate queryUpdate)
        {
            try
            {
                SqlParameter[] parameters =
                {
                    new SqlParameter("@Id",          SqlDbType.Int),
                    new SqlParameter("@RepliedBy",   SqlDbType.Int),
                    new SqlParameter("@RepliedText", SqlDbType.NVarChar)
                };

                parameters[0].Value = queryUpdate.QueryId;
                parameters[1].Value = queryUpdate.RepliedBy;
                parameters[2].Value = queryUpdate.ReplyText;

                _DataHelper = new DataAccessHelper("spu_ContactUs", parameters, _configuration);

                DataTable dt = new DataTable();

                int result = await _DataHelper.RunAsync(dt);

                if (result == 101)
                {
                    UserEmail userEmail = new UserEmail();
                    userEmail.Email = queryUpdate.Email;
                    string text = queryUpdate.ReplyText;
                    userEmail.Body    = Emailer.CreateEmailBodyForReply(queryUpdate.Username, queryUpdate.Url, text, _configuration);
                    userEmail.Subject = "Reply of your query submitted";
                    await Emailer.SendEmailAsync(userEmail, _configuration);
                }

                return(new DatabaseResponse {
                    ResponseCode = result
                });
            }

            catch (Exception ex)
            {
                Log.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));
                throw;
            }
            finally
            {
                _DataHelper.Dispose();
            }
        }
예제 #9
0
    public virtual Differences VisitQueryUpdate(QueryUpdate update1, QueryUpdate update2){
      Differences differences = new Differences(update1, update2);
      if (update1 == null || update2 == null){
        if (update1 != update2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      QueryUpdate changes = (QueryUpdate)update2.Clone();
      QueryUpdate deletions = (QueryUpdate)update2.Clone();
      QueryUpdate insertions = (QueryUpdate)update2.Clone();

      //      update1.Context;
      //      update1.Source;
      //      update1.UpdateList;

      if (differences.NumberOfDifferences == 0){
        differences.Changes = null;
        differences.Deletions = null;
        differences.Insertions = null;
      }else{
        differences.Changes = changes;
        differences.Deletions = deletions;
        differences.Insertions = insertions;
      }
      return differences;
    }    
예제 #10
0
 public virtual Node VisitQueryUpdate(QueryUpdate update){
   if (update == null) return null;
   update.Source = this.VisitExpression(update.Source);
   update.UpdateList = this.VisitExpressionList(update.UpdateList);
   return update;
 }    
예제 #11
0
 public override Node VisitQueryUpdate(QueryUpdate qu) {
   if (qu == null) return null;
   qu.Source = this.VisitExpression(qu.Source);
   if (qu.Source == null || qu.Source.Type == null) return null;
   Cardinality card = this.typeSystem.GetCardinality(qu.Source, this.TypeViewer);
   if (card != Cardinality.OneOrMore && card != Cardinality.ZeroOrMore) {
     this.HandleError(qu.Source, Error.QueryNotStream);
     return null;
   }
   if (qu.UpdateList == null || qu.UpdateList.Count == 0) {
     this.HandleError(qu, Error.QueryBadUpdateList);
     return null;
   }
   for (int i = 0, n = qu.UpdateList.Count; i < n; i++) {
     Expression x = qu.UpdateList[i];
     if (x == null) {
       this.HandleError(qu, Error.QueryBadUpdateList);
       return null;
     }
     x = this.VisitExpression(x);
     if (x == null || x.Type == null) return null;
     qu.UpdateList[i] = x;
   }
   TypeNode elementType = this.typeSystem.GetStreamElementType(qu.Source, this.TypeViewer);
   if (elementType == null) return null;
   if (elementType.IsValueType) {
     QueryFilter qf = qu.Source as QueryFilter;
     Expression source = (qf != null) ? qf.Source : qu.Source;
     if (source == null || source.Type == null) return null;
     Method mSetItem = this.GetTypeView(source.Type).GetMethod(Identifier.For("set_Item"));
     Method mAdd = this.GetTypeView(source.Type).GetMethod(StandardIds.Add, elementType);
     if (mAdd == null) mAdd = this.GetTypeView(source.Type).GetMethod(StandardIds.Add, SystemTypes.Object);
     Method mRemove = this.GetTypeView(source.Type).GetMethod(StandardIds.Remove, elementType);
     if (mRemove == null) mRemove = this.GetTypeView(source.Type).GetMethod(StandardIds.Remove, SystemTypes.Object);
     if (mSetItem == null && (mAdd == null || mRemove == null)) {
       this.HandleError(source, Error.QueryNotUpdateStream, this.GetTypeName(source.Type), this.GetTypeName(elementType));
       return null;
     }
   }
   return qu;
 }
예제 #12
0
 public override Node VisitQueryUpdate( QueryUpdate update ){
   if (update == null) return null;
   update.Source = this.VisitExpression(update.Source);
   if (update.Source == null || update.Source.Type == null) return update;
   TypeNode sourceElementType = this.typeSystem.GetStreamElementType(update.Source, this.TypeViewer);
   update.Context = this.contextScope = new ContextScope(this.contextScope, sourceElementType);
   update.UpdateList = this.VisitExpressionList(update.UpdateList);
   this.contextScope = this.contextScope.Previous;
   update.Type = SystemTypes.Int32;
   return update;
 }
예제 #13
0
 public virtual void VisitQueryUpdate(QueryUpdate update){
   if (update == null) return;
   this.VisitExpression(update.Source);
   this.VisitExpressionList(update.UpdateList);
 }    
예제 #14
0
 public override Node VisitQueryUpdate(QueryUpdate update){
   if (update == null) return null;
   return base.VisitQueryUpdate((QueryUpdate)update.Clone());
 }    
예제 #15
0
 public virtual Node VisitQueryUpdate(QueryUpdate update1, QueryUpdate update2){
   if (update1 == null) return null;
   if (update2 == null){
     update1.Source = this.VisitExpression(update1.Source, null);
     update1.UpdateList = this.VisitExpressionList(update1.UpdateList, null);
   }else{
     update1.Source = this.VisitExpression(update1.Source, update2.Source);
     update1.UpdateList = this.VisitExpressionList(update1.UpdateList, update2.UpdateList);
   }
   return update1;
 }    
예제 #16
0
 public EventingVisitor(Action<QueryUpdate> visitQueryUpdate) { VisitedQueryUpdate += visitQueryUpdate; } public event Action<QueryUpdate> VisitedQueryUpdate; public override Node VisitQueryUpdate(QueryUpdate update) { if (VisitedQueryUpdate != null) VisitedQueryUpdate(update); return base.VisitQueryUpdate(update); }
예제 #17
0
 public override Node VisitQueryUpdate( QueryUpdate update ) {
   update.Source = this.VisitExpression(update.Source);
   Composer saveContext = this.contextComposer;
   bool savehcr = this.hasContextReference;
   Composer c = this.contextComposer = this.GetComposer(update.Source);
   this.hasContextReference = false;
   this.VisitExpressionList(update.UpdateList);
   this.contextComposer = saveContext;
   this.hasContextReference = savehcr;
   return this.Compose(update, c);
 }            
예제 #18
0
 public virtual Node VisitQueryUpdate(QueryUpdate update, QueryUpdate changes, QueryUpdate deletions, QueryUpdate insertions){
   this.UpdateSourceContext(update, changes);
   if (update == null) return changes;
   if (changes != null){
     if (deletions == null || insertions == null)
       Debug.Assert(false);
     else{
     }
   }else if (deletions != null)
     return null;
   return update;
 }    
예제 #19
0
    public override Node VisitQueryUpdate(QueryUpdate qu) {
      if (qu == null || qu.Type == null || qu.Source == null || qu.Source.Type == null) return null;
      TypeNode elementType = this.typeSystem.GetStreamElementType(qu.Source, this.TypeViewer);
      Block block = new Block(new StatementList(10));
      Expression setSource = null;
      QueryFilter qf = qu.Source as QueryFilter;
      if (qf != null) {
        if (qf.Source == null || qf.Source.Type == null) return null;
        if (!this.IsLocal(qf.Source)) {
          Local locSource = new Local(qf.Source.Type);
          block.Statements.Add(new AssignmentStatement(locSource, qf.Source));
          qf.Source = locSource;
        }
        setSource = qf.Source;
      }
      else {
        if (!this.IsLocal(qu.Source)) {
          Local locSource = new Local(qu.Source.Type);
          block.Statements.Add(new AssignmentStatement(locSource, qu.Source));
          qu.Source = locSource;
        }
        setSource = qu.Source;
      }
      Method mSetItem = null;
      Method mAdd = null;
      Method mRemove = null;
      Local locPos = null;
      if (elementType.IsValueType) {
        mSetItem = this.GetTypeView(setSource.Type).GetMethod(idSetItem, SystemTypes.Int32, elementType);
        if (mSetItem == null) {
          mAdd = this.GetTypeView(setSource.Type).GetMethod(StandardIds.Add, elementType);
          if (mAdd == null) mAdd = this.GetTypeView(setSource.Type).GetMethod(StandardIds.Add, SystemTypes.Object);
          if (mAdd == null) return null;
          mRemove = this.GetTypeView(setSource.Type).GetMethod(StandardIds.Remove, elementType);
          if (mRemove == null) mRemove = this.GetTypeView(setSource.Type).GetMethod(StandardIds.Remove, SystemTypes.Object);
          if (mRemove == null) return null;
        }
        locPos = new Local(SystemTypes.Int32);
        if (qf != null && mSetItem != null) {
          // pre-prepare position counter for filter
          qf.Context.Position = locPos;
          qf.Context.PreFilter = new Block(new StatementList(1));
          qf.Context.PostFilter = new Block(new StatementList(1));
          qf.Context.PreFilter.Statements.Add(new AssignmentStatement(locPos, Literal.Int32Zero));
          qf.Context.PostFilter.Statements.Add(new AssignmentStatement(locPos, new BinaryExpression(locPos, Literal.Int32One, NodeType.Add)));
        }
      }
      Block inner = null;
      Expression target = null;
      if (mAdd != null) {
        Local locList = new Local(SystemTypes.ArrayList);
        Construct cons = new Construct(new MemberBinding(null, SystemTypes.ArrayList.GetConstructor()), null, SystemTypes.ArrayList);
        block.Statements.Add(new AssignmentStatement(locList, cons));
        // find all matching elements
        block.Statements.Add(this.BuildClosureForEach(qu.Source, ref target, out inner, this.currentMethod.Body.Scope));
        qu.Context.Target = target;
        // remember all the matching elements
        Method mListAdd = SystemTypes.ArrayList.GetMethod(StandardIds.Add, SystemTypes.Object);
        MethodCall mcListAdd = new MethodCall(new MemberBinding(locList, mListAdd), new ExpressionList(this.typeSystem.ImplicitCoercion(target, SystemTypes.Object, this.TypeViewer)));
        mcListAdd.Type = mListAdd.ReturnType;
        inner.Statements.Add(new ExpressionStatement(mcListAdd));
        // re-iterate matching values
        block.Statements.Add(this.BuildClosureForEach(locList, ref target, out inner, this.currentMethod.Body.Scope));
        // remove old value from list
        Expression remArg = (mRemove.Parameters[0].Type == SystemTypes.Object) ? this.Box(target) : target;
        MethodCall mcRemove = new MethodCall(new MemberBinding(setSource, mRemove), new ExpressionList(remArg));
        mcRemove.Type = mRemove.ReturnType;
        if ((mRemove.Flags & MethodFlags.Virtual) != 0) mcRemove.NodeType = NodeType.Callvirt;
        inner.Statements.Add(new ExpressionStatement(mcRemove));
        // apply changes
        for( int i = 0, n = qu.UpdateList.Count; i < n; i++ ) {
          inner.Statements.Add(new ExpressionStatement(qu.UpdateList[i]));
        }
        // add changed item back
        Expression addArg = (mAdd.Parameters[0].Type == SystemTypes.Object) ? this.Box(target) : target;
        MethodCall mcAdd = new MethodCall(new MemberBinding(setSource, mAdd), new ExpressionList(addArg));
        mcAdd.Type = mAdd.ReturnType;
        if ((mAdd.Flags & MethodFlags.Virtual) != 0) mcAdd.NodeType = NodeType.Callvirt;
        inner.Statements.Add(new ExpressionStatement(mcAdd));

        // return update count
        Method mGetCount = SystemTypes.ArrayList.GetMethod(idGetCount);
        MethodCall mcGetCount = new MethodCall(new MemberBinding(locList, mGetCount), null);
        mcGetCount.Type = mGetCount.ReturnType;
        block.Statements.Add(new ExpressionStatement(mcGetCount));
      }
      else {
        Local locCount = new Local(SystemTypes.Int32);
        block.Statements.Add(new AssignmentStatement(locCount, Literal.Int32Zero));
        block.Statements.Add(this.BuildClosureForEach(qu.Source, ref target, out inner, this.currentMethod.Body.Scope));
        qu.Context.Target = target;
        // apply changes
        for( int i = 0, n = qu.UpdateList.Count; i < n; i++ ) {
          inner.Statements.Add(new ExpressionStatement(qu.UpdateList[i]));
        }
        if (mSetItem != null) {
          // put changed item back
          Expression pos = (qf != null) ? locPos : locCount;
          MethodCall mcSetItem = new MethodCall(new MemberBinding(setSource, mSetItem), new ExpressionList(pos, target));
          mcSetItem.Type = mSetItem.ReturnType;
          if ((mSetItem.Flags & MethodFlags.Virtual) != 0)
            mcSetItem.NodeType = NodeType.Callvirt;
          inner.Statements.Add(new ExpressionStatement(mcSetItem));
        }
        inner.Statements.Add(new AssignmentStatement(locCount, new BinaryExpression(locCount, Literal.Int32One, NodeType.Add)));
        block.Statements.Add(new ExpressionStatement(locCount));
      }
      // return count
      return this.VisitBlockExpression(new BlockExpression(block, SystemTypes.Int32));
    }