private void processPredefinedLocationContainer(PredefinedLocationContainer predefinedLocationContainer, DateTime publicationTime)
 {
     if (predefinedLocationContainer.GetType() == typeof(PredefinedItinerary))
     {
         PredefinedItinerary predefinedItinerary = (PredefinedItinerary)predefinedLocationContainer;
         string predefinedLocationContainerId    = predefinedItinerary.id;
         _PredefinedItineraryIndexPredefinedLocation[] predefinedLocationList = predefinedItinerary.predefinedLocation;
         for (int predefinedLocationListPos = 0; predefinedLocationListPos < predefinedLocationList.Length; predefinedLocationListPos++)
         {
             _PredefinedItineraryIndexPredefinedLocation predefinedItineraryIndexPredefinedLocation = predefinedLocationList[predefinedLocationListPos];
             processPredefinedLocation(predefinedItineraryIndexPredefinedLocation.predefinedLocation, publicationTime, predefinedLocationContainerId);
         }
     }
     else if (predefinedLocationContainer.GetType() == typeof(PredefinedNonOrderedLocationGroup))
     {
         PredefinedNonOrderedLocationGroup predefinedNonOrderedLocationGroup = (PredefinedNonOrderedLocationGroup)predefinedLocationContainer;
         string predefinedLocationContainerId        = predefinedNonOrderedLocationGroup.id;
         PredefinedLocation[] predefinedLocationList = predefinedNonOrderedLocationGroup.predefinedLocation;
         for (int predefinedLocationListPos = 0; predefinedLocationListPos < predefinedLocationList.Length; predefinedLocationListPos++)
         {
             PredefinedLocation predefinedLocation = predefinedLocationList[predefinedLocationListPos];
             processPredefinedLocation(predefinedLocation, publicationTime, predefinedLocationContainerId);
         }
     }
     else
     {
         logWrapper.Error("Unexpected data type for PredefinedLocationContainer: " + predefinedLocationContainer.GetType().ToString());
         return;
     }
 }
示例#2
0
        /// <summary>
        /// Serialize the class data to a stream.
        /// </summary>
        /// <param name="writer">The <see cref="T:MySpace.Common.IO.IPrimitiveWriter"/> that writes to the stream.</param>
        public void Serialize(IPrimitiveWriter writer)
        {
            using (writer.CreateRegion())
            {
                //FieldValue
                if (FieldValue == null || FieldValue.Length == 0)
                {
                    _log.Error("FieldValue in FilterCaps cannot be null or zero length byte array");
                    throw new Exception("FieldValue in FilterCaps cannot be null or zero length byte array");
                }
                writer.Write((ushort)FieldValue.Length);
                writer.Write(FieldValue);

                //UseParentFilter
                writer.Write(UseParentFilter);

                //Filter
                if (Filter == null)
                {
                    writer.Write((byte)0);
                }
                else
                {
                    writer.Write((byte)Filter.FilterType);
                    Serializer.Serialize(writer.BaseStream, Filter);
                }

                //Cap
                writer.Write(Cap);
            }
        }
示例#3
0
        private void GetConfig()
        {
            EventHandler reloadEventHandler = ReloadConfig;

            configuration = RelayNodeConfig.GetRelayNodeConfig(reloadEventHandler);

            if (configuration != null)
            {
                if (configuration.GetMyNode() != null)
                {
                    MyZone = configuration.GetMyNode().Zone;
                }

                instanceName = configuration.InstanceName;
                if (configuration.TransportSettings != null)
                {
                    portNumber     = configuration.TransportSettings.ListenPort;
                    httpPortNumber = configuration.TransportSettings.HttpListenPort;
                }
            }
            else
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("NO CONFIG SECTION FOUND, SERVICE NOT STARTING.");
                }
            }
        }
        public void UpdateUserFileName(Files file)
        {
            using (LogWrapper logger = new LogWrapper())
            {
                if (file == null)
                {
                    logger.Error("Файл не может быть null.");
                    throw new ArgumentNullException(nameof(file), "Файл не может быть null.");
                }
                try
                {
                    using (var connection = new SqlConnection(_connectionString))
                    {
                        connection.Open();

                        using (var command = new SqlCommand("upUpdate_UserFileName", connection))
                        {
                            command.CommandType = CommandType.StoredProcedure;

                            var lastModifyDate = DateTimeOffset.Now;

                            command.Parameters.AddWithValue("@id", file.Id);
                            command.Parameters.AddWithValue("@fileName", file.FileName);
                            command.Parameters.AddWithValue("@lastModifyDate", lastModifyDate);

                            command.ExecuteNonQuery();
                        }
                    }
                }
                catch (Exception e)
                {
                    logger.Error(e.Message);
                }
            }
        }
        public void Delete(Guid id)
        {
            using (LogWrapper logger = new LogWrapper())
            {
                if (id == Guid.Empty)
                {
                    logger.Error("Id не может быть null.");
                    throw new ArgumentNullException(nameof(id), "Id не может быть null.");
                }
                try
                {
                    using (var connection = new SqlConnection(_connectionString))
                    {
                        connection.Open();

                        using (var command = new SqlCommand("upDelete_UserFile", connection))
                        {
                            command.CommandType = CommandType.StoredProcedure;
                            command.Parameters.AddWithValue("@id", id);

                            command.ExecuteNonQuery();
                        }
                    }
                }
                catch (Exception e)
                {
                    logger.Error(e.Message);
                }
            }
        }
        public Task DeleteAsync(IdentityUser user)
        {
            using (LogWrapper logger = new LogWrapper())
            {
                if (user == null)
                {
                    logger.Error("Пользователь не может быть null.");
                    throw new ArgumentNullException(nameof(user), "Пользователь не может быть null.");
                }
                try
                {
                    return(Task.Factory.StartNew(() =>
                    {
                        using (var connection = new SqlConnection(_connectionString))
                        {
                            connection.Open();
                            connection.Execute("upDelete_user", new { user.Id },
                                               commandType: CommandType.StoredProcedure);
                        }
                    }));
                }

                catch (Exception e)
                {
                    logger.Error(e.Message);
                    return(null);
                }
            }
        }
        public void Error_Valid_Fact()
        {
            _wrapper.Error("This is a Fact");

            _eventArgs.Should().NotBeNull();
            _eventArgs.Name.Should().Be("This is a Fact");
            _eventArgs.Level.Should().Be(LogLevel.Error);
        }
        public DATEXIIProcessService getServiceType(string feedType)
        {
            DATEXIIProcessService datexiiProcessService;

            switch (feedType)
            {
            case "VMS":
                datexiiProcessService = getDATEXIIProcessService(DATA_SERVICE_TYPE.VMS);
                break;

            case "ANPR":
                datexiiProcessService = getDATEXIIProcessService(DATA_SERVICE_TYPE.ANPR);
                break;

            case "MIDAS":
                datexiiProcessService = getDATEXIIProcessService(DATA_SERVICE_TYPE.MIDAS);
                break;

            case "TMU":
                datexiiProcessService = getDATEXIIProcessService(DATA_SERVICE_TYPE.TMU);
                break;

            case "FUSED_SENSOR_ONLY":
                datexiiProcessService = getDATEXIIProcessService(DATA_SERVICE_TYPE.FUSED_SENSOR_ONLY);
                break;

            case "FUSED_FVD_AND_SENSOR_PTD":
                datexiiProcessService = getDATEXIIProcessService(DATA_SERVICE_TYPE.FUSED_FVD_AND_SENSOR_PTD);
                break;

            case "NTIS_MODEL_UPDATE_NOTIFICATION":
                datexiiProcessService = getDATEXIIProcessService(DATA_SERVICE_TYPE.NTIS_MODEL_UPDATE_NOTIFICATION);
                break;

            case "EVENT":
                datexiiProcessService = getDATEXIIProcessService(DATA_SERVICE_TYPE.EVENT);
                break;

            case "NTIS_MODEL_VMS_TABLES":
                datexiiProcessService = getDATEXIIProcessService(DATA_SERVICE_TYPE.NTIS_MODEL_VMS_TABLES);
                break;

            case "NTIS_MODEL_MEASUREMENT_SITES":
                datexiiProcessService = getDATEXIIProcessService(DATA_SERVICE_TYPE.NTIS_MODEL_MEASUREMENT_SITES);
                break;

            case "NTIS_MODEL_PREDEFINED_LOCATIONS":
                datexiiProcessService = getDATEXIIProcessService(DATA_SERVICE_TYPE.NTIS_MODEL_PREDEFINED_LOCATIONS);
                break;

            default:
                datexiiProcessService = null;
                logWrapper.Error("Unknown Feed Type Received:(" + feedType + ")");
                break;
            }
            return(datexiiProcessService);
        }
        public Comment GetCommentInfo(Guid id)
        {
            using (LogWrapper logger = new LogWrapper())
            {
                if (id == Guid.Empty)
                {
                    logger.Error("id не может быть empty");
                    throw new ArgumentNullException(nameof(id), "id не может быть empty");
                }

                try
                {
                    using (var connection = new SqlConnection(_connectionString))
                    {
                        connection.Open();
                        using (var command = connection.CreateCommand())
                        {
                            command.CommandText = "SELECT " +
                                                  "Id, " +
                                                  "userId, " +
                                                  "fileId, " +
                                                  "Text, " +
                                                  "PostDate FROM ufSelect_comment_by_id(@id)";

                            command.Parameters.AddWithValue("@id", id);

                            using (var reader = command.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    var commentIfo = new Comment
                                    {
                                        Id       = reader.GetGuid(reader.GetOrdinal("id")),
                                        Text     = reader.GetString(reader.GetOrdinal("text")),
                                        PostDate = reader.GetDateTimeOffset(reader.GetOrdinal("PostDate")),
                                        User     = _usersRepository
                                                   .FindByIdAsync(reader.GetGuid(reader.GetOrdinal("userId")))
                                                   .Result,
                                        File = GetInfo(reader.GetGuid(reader.GetOrdinal("fileId")))
                                    };

                                    return(commentIfo);
                                }
                                logger.Error($"Комментарий: {id} недоступен.");
                                throw new ArgumentException($"Комментарий: {id} недоступен.");
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    logger.Error(e.Message);
                    return(null);
                }
            }
        }
        public Comment AddCommentToFile(Guid fileId, Guid userId, Comment comment)
        {
            using (LogWrapper logger = new LogWrapper())
            {
                if (comment == null)
                {
                    logger.Error("Комментарий не может быть null.");
                    throw new ArgumentNullException(nameof(comment), "Комментарий не может быть null.");
                }
                if (fileId == Guid.Empty)
                {
                    logger.Error("fileId не может быть empty.");
                    throw new ArgumentNullException(nameof(fileId), "fileId не может быть empty.");
                }
                if (userId == Guid.Empty)
                {
                    logger.Error("userId не может быть empty.");
                    throw new ArgumentNullException(nameof(userId), "userId не может быть empty.");
                }

                try
                {
                    using (var connection = new SqlConnection(_connectionString))
                    {
                        connection.Open();

                        using (var command = new SqlCommand("upCreate_new_comment", connection))
                        {
                            command.CommandType = CommandType.StoredProcedure;

                            var commentId   = Guid.NewGuid();
                            var createdDate = DateTimeOffset.Now;

                            command.Parameters.AddWithValue("@id", commentId);
                            command.Parameters.AddWithValue("@userId", userId);
                            command.Parameters.AddWithValue("@fileId", fileId);
                            command.Parameters.AddWithValue("@text", comment.Text);
                            command.Parameters.AddWithValue("@postDate", createdDate);

                            command.ExecuteNonQuery();

                            comment.Id       = commentId;
                            comment.PostDate = createdDate;

                            return(comment);
                        }
                    }
                }
                catch (Exception e)
                {
                    logger.Error(e.Message);
                    return(null);
                }
            }
        }
示例#11
0
        private void AddLog(string Msg, StackTrace stack = null, string Tittle = "", int TenantId = 0, int UserId = 0, LogType logtype = LogType.Debug, Object Context = null)
        {
            try
            {
                if (stack == null)
                {
                    stack = new StackTrace(true);
                }
                var    methodBase = stack.GetFrame(1).GetMethod();
                Type   stacktype  = methodBase.DeclaringType;
                string fileName   = stacktype.FullName; //文件名
                string methodName = methodBase.Name;    //方法名
                var    logModel   = new LogModel
                {
                    TenantId   = TenantId,
                    UserId     = UserId,
                    Message    = Msg,
                    Title      = Tittle,
                    MethodName = methodName,
                    FileName   = fileName,
                    CodeLine   = "0"
                };
                var jsonValue = JsonConvert.SerializeObject(logModel);
                switch (logtype)
                {
                case LogType.Debug:
                    _log.Debug(jsonValue);
                    break;

                case LogType.Info:
                    _log.Info(jsonValue);
                    break;

                case LogType.Warn:
                    _log.Warn(jsonValue);
                    break;

                case LogType.Error:
                    _log.Error(jsonValue);
                    break;

                case LogType.Fatal:
                    _log.Fatal(jsonValue);
                    break;

                default:
                    _log.Debug(jsonValue);
                    break;
                }
            }
            catch
            {
            }
        }
示例#12
0
 private void PostError(SocketError error)
 {
     try
     {
         _replyStream = null;
         LastError    = error;
         _waitHandle.Set();
     }
     catch (Exception ex)
     {
         log.Error(ex);
     }
 }
        public IEnumerable <Files> GetUsersFiles(Guid id)
        {
            using (LogWrapper logger = new LogWrapper())
            {
                if (id == Guid.Empty)
                {
                    logger.Error("Id не может быть empty.");
                    throw new ArgumentNullException(nameof(id), "Id не может быть empty.");
                }
                try
                {
                    var files = new List <Files>();

                    using (var connection = new SqlConnection(_connectionString))
                    {
                        connection.Open();
                        using (var command = connection.CreateCommand())
                        {
                            command.CommandText = "SELECT " +
                                                  "Id, " +
                                                  "UserId, " +
                                                  "FileName, " +
                                                  "FileType, " +
                                                  "FileSize, " +
                                                  "FileExtension, " +
                                                  "CreatedDate, " +
                                                  "LastModifyDate " +
                                                  "FROM ufSelect_file_info_by_userId(@userId)";

                            command.Parameters.AddWithValue("@userid", id);

                            using (var reader = command.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    files.Add(GetInfo(reader.GetGuid(reader.GetOrdinal("Id"))));
                                }
                                return(files);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    logger.Error(e.Message);
                    return(null);
                }
            }
        }
        public IEnumerable <Comment> GetFileComments(Guid fileId)
        {
            using (LogWrapper logger = new LogWrapper())
            {
                if (fileId == Guid.Empty)
                {
                    logger.Error("Id не может быть empty.");
                    throw new ArgumentNullException(nameof(fileId), "Id не может быть empty.");
                }

                try
                {
                    var comments = new List <Comment>();

                    using (var connection = new SqlConnection(_connectionString))
                    {
                        connection.Open();
                        using (var command = connection.CreateCommand())
                        {
                            command.CommandText = "SELECT " +
                                                  "Id, " +
                                                  "userId, " +
                                                  "fileId, " +
                                                  "Text, " +
                                                  "PostDate " +
                                                  "FROM ufSelect_comments_by_fileId(@fileId)";

                            command.Parameters.AddWithValue("@fileId", fileId);

                            using (var reader = command.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    comments.Add(GetCommentInfo(reader.GetGuid(reader.GetOrdinal("Id"))));
                                }

                                return(comments);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    logger.Error(e.Message);
                    return(null);
                }
            }
        }
示例#15
0
        private void processVmsUnitRecord(VmsUnitRecord vmsUnitRecord, DateTime publicationTime, String vmsUnitTableId)
        {
            String vmsUnitIdentifier = vmsUnitRecord.id;

            if (logWrapper.isTrace())
            {
                logWrapper.Trace("Processing VMS Identifier(" + vmsUnitIdentifier + ")");
            }

            switch (vmsUnitTableId)
            {
            case "NTIS_Matrix_Units":
                MatrixSignalStaticData matrixSignalStaticData = new MatrixSignalStaticData(vmsUnitIdentifier, publicationTime, vmsUnitRecord);
                matrixSignalStaticDataStore.updateData(matrixSignalStaticData);
                break;

            case "NTIS_VMS_Units":
                VMSStaticData vmsStaticData = new VMSStaticData(vmsUnitIdentifier, publicationTime, vmsUnitRecord);
                vmsStaticDataStore.updateData(vmsStaticData);
                break;

            default:
                logWrapper.Error("VMS Unit Table Id not implemented: " + vmsUnitTableId);
                break;
            }
        }
示例#16
0
 public IEnumerable <File> GetUserFiles(Guid userId)
 {
     using (LogWrapper logger = new LogWrapper())
     {
         var result = new List <File>();
         try
         {
             using (var connection = new SqlConnection(_connectionString))
             {
                 connection.Open();
                 using (var command = connection.CreateCommand())
                 {
                     command.CommandText = "select FileId from Shared where UserId = @userid";
                     command.Parameters.AddWithValue("@userid", userId);
                     using (var reader = command.ExecuteReader())
                     {
                         while (reader.Read())
                         {
                             result.Add(GetInfo(reader.GetGuid(reader.GetOrdinal("id"))));
                         }
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             logger.Error(ex.Message);
         }
         return(result);
     }
 }
示例#17
0
        /// <summary>
        /// Register an exception thrown by a sql connection.
        /// </summary>
        public void RegisterSqlTimeout(Exception e)
        {
            exceptionLog = e.ToString() + " : " + e.Message + " : " + e.StackTrace;
            if ((e is InvalidOperationException && e.Message.StartsWith("Timeout expired.")) ||
                (e.InnerException != null && e.InnerException is MySqlException && (e.Message.StartsWith("MySQL Server does not exist or access denied.") || e.InnerException.Message.StartsWith("An error has occurred while establishing a connection to the server."))) ||
                (e is MySqlException && (e.Message.StartsWith("SQL Server does not exist or access denied.") || e.Message.StartsWith("An error has occurred while establishing a connection to the server."))))
            {
                lock (padLock)
                {
                    lastTimeout = DateTime.Now.Ticks;
                    timeoutCount++;
                    totalTimeoutCount++;

                    if (this.InstanceName.StartsWith("Shared"))
                    {
                        DatabaseManager.Instance.ResetShared();
                    }
                    else if (this.InstanceName.StartsWith("SecurityTracking"))
                    {
                        DatabaseManager.Instance.ResetSecurityTracking();
                    }
                    //else

                    //    MySqlConnection.ClearPool(new MySqlConnection(GetConnectionString()));
                }
                if (log.IsErrorEnabled)
                {
                    log.Error("Execption while RegisterSqlTimeout", e);
                }
                throw new DatabaseDownException("Database " + instanceName + " is down.");
            }
        }
示例#18
0
        static Serializer()
        {
            SerializationMemoryConfig config = null;

            try
            {
                config = (SerializationMemoryConfig)ConfigurationManager.GetSection("SerializationMemory");
            }
            catch (Exception e)
            {
                _log.Error("Failed to load configuration section 'SerializationMemory'. Using defaults. - " + e);
            }

            if (config == null || !config.EnablePooling)
            {
                _memoryPool = new Pool <MemoryStream>(
                    () => new MemoryStream(),
                    (s, phase) => false,
                    new PoolConfig());
            }
            else
            {
                _memoryPool = new Pool <MemoryStream>(
                    () => new MemoryStream(),
                    (s, phase) =>
                {
                    if (phase == PoolItemPhase.Leaving)
                    {
                        s.SetLength(0);
                    }
                    return(true);
                },
                    config);
            }
        }
示例#19
0
 public byte[] GetContent(Guid fileId)
 {
     using (LogWrapper logger = new LogWrapper())
     {
         try
         {
             using (var connection = new SqlConnection(_connectionString))
             {
                 connection.Open();
                 using (var command = connection.CreateCommand())
                 {
                     command.CommandText = "select Data from Files where Id = @id";
                     command.Parameters.AddWithValue("@id", fileId);
                     using (var reader = command.ExecuteReader())
                     {
                         while (reader.Read())
                         {
                             return(reader.GetSqlBinary(reader.GetOrdinal("Data")).Value);
                         }
                         throw new ArgumentException($"file {fileId} not found");
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             logger.Error(ex.Message);
             return(null);
         }
     }
 }
示例#20
0
        protected override void ExecuteBodyCommand(CommandData commandData, Vector3 executePos, GameEntity cell, GameEntity trigger = null)
        {
            if (!string.IsNullOrEmpty(commandData.output))
            {
                for (int i = 0; i < commandData.count; i++)
                {
                    var entity = factoryEntity.CreateGameGridObject(commandData.output);

                    if (cell == null)
                    {
                        cell = gridService.GetClosestCell(executePos, true);
                    }

                    if (!gridService.DoesFit(entity, cell))
                    {
                        cell = gridService.GetClosestFitPivotCell(entity, cell);

                        if (cell == null)
                        {
                            LogWrapper.Error("[{0}] Could not fit the entity, the command will stop execution, command id: {1}", GetType(), commandData.id);
                            entity.Destroy();
                            return;
                        }
                    }

                    entity.position = executePos;
                    gridService.SetEntityOn(entity, cell);
                    entity.TweenScale(Vector3.zero, Vector3.one, 0.5f, LeanTweenType.easeOutBack);
                    if (entity.hasCommand)
                    {
                        commandSystem.Execute(entity.command.onSpawnCommand, cell.position, cell, entity);
                    }
                }
            }
        }
示例#21
0
 public IEnumerable <Comment> GetFileComments(Guid fileId)
 {
     using (LogWrapper logger = new LogWrapper())
     {
         var result = new List <Comment>();
         try
         {
             using (var connection = new SqlConnection(_connectionString))
             {
                 connection.Open();
                 using (var command = connection.CreateCommand())
                 {
                     command.CommandText = "select Comments.Id as Id from Shared join Comments on Shared.Id = Comments.SharedId where Shared.FileId = @fileId";
                     command.Parameters.AddWithValue("@fileId", fileId);
                     using (var reader = command.ExecuteReader())
                     {
                         while (reader.Read())
                         {
                             result.Add(GetComment(reader.GetGuid(reader.GetOrdinal("Id"))));
                         }
                         return(result);
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             logger.Error(ex.Message);
         }
         return(result);
     }
 }
示例#22
0
 public void Shared(Share share)
 {
     using (LogWrapper logger = new LogWrapper())
     {
         try
         {
             using (SqlConnection connect = new SqlConnection(_connectionString))
             {
                 connect.Open();
                 using (SqlCommand command = new SqlCommand("up_Shared_file", connect))
                 {
                     command.CommandType = System.Data.CommandType.StoredProcedure;
                     command.Parameters.AddWithValue("@ownerId", share.OwnerId);
                     command.Parameters.AddWithValue("@fileId", share.FileId);
                     command.Parameters.AddWithValue("@userId", share.PartOwnerId);
                     command.Parameters.AddWithValue("@readOnlyAccess", share.ReadOnlyAccess);
                     command.ExecuteNonQuery();
                 }
             }
         }
         catch (Exception ex)
         {
             logger.Error(ex.Message);
         }
     }
 }
示例#23
0
 public File Add(File file)
 {
     using (LogWrapper logger = new LogWrapper())
     {
         try
         {
             using (var connection = new SqlConnection(_connectionString))
             {
                 connection.Open();
                 using (var command = new SqlCommand("up_Insert_file", connection))
                 {
                     command.CommandType = System.Data.CommandType.StoredProcedure;
                     var fileId = Guid.NewGuid();
                     command.Parameters.AddWithValue("@id", fileId);
                     command.Parameters.AddWithValue("@name", file.Name);
                     command.Parameters.AddWithValue("@type", GetFileType(file.Name));
                     command.Parameters.AddWithValue("@owner", file.Owner.Id);
                     command.Parameters.AddWithValue("@creationTime", file.CreationTime);
                     command.Parameters.AddWithValue("@lastWriteTime", file.LastWriteTime);
                     command.ExecuteNonQuery();
                     file.Id = fileId;
                     return(file);
                 }
             }
         }
         catch (Exception ex)
         {
             logger.Error(ex.Message);
             return(null);
         }
     }
 }
        public void DeleteComment(Guid fileId, Guid userId, Comment comment)
        {
            using (LogWrapper logger = new LogWrapper())
            {
                if (comment == null)
                {
                    logger.Error("Comment не может быть null.");
                    throw new ArgumentNullException(nameof(comment), "Comment не может быть null.");
                }
                try
                {
                    using (var connection = new SqlConnection(_connectionString))
                    {
                        connection.Open();

                        using (var command = new SqlCommand("upDelete_comment", connection))
                        {
                            command.CommandType = CommandType.StoredProcedure;

                            command.Parameters.AddWithValue("@id", comment.Id);
                            command.Parameters.AddWithValue("@userId", userId);
                            command.Parameters.AddWithValue("@fileId", fileId);

                            command.ExecuteNonQuery();
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }
        }
示例#25
0
        public TILED_MapTileset GetMapTilesetWithFirstgid(string mapPath, int gid)
        {
            if (gid == 0)
            {
                LogWrapper.Error("[{0}] the gid 0 is dedicated to void cells with no TILED_MapTileset, will return null", GetType());
                return(null);
            }

            var map = GetMap(mapPath);

            if (gid > 0 && map.tilesets.Length == 1 && gid >= map.tilesets[0].firstgid)
            {
                return(map.tilesets[0]);
            }
            else if (map.tilesets.Length > 1)
            {
                for (int i = 0; i < map.tilesets.Length - 1; i++)
                {
                    var tl_1 = map.tilesets[i];
                    var tl_2 = map.tilesets[i + 1];

                    if (gid >= tl_1.firstgid && gid < tl_2.firstgid)
                    {
                        return(tl_1);
                    }
                }

                if (gid >= map.tilesets[map.tilesets.Length - 1].firstgid)
                {
                    return(map.tilesets[map.tilesets.Length - 1]);
                }
            }

            return(null);
        }
示例#26
0
 public Comment AddCommentToFile(Comment comment)
 {
     using (LogWrapper logger = new LogWrapper())
     {
         try
         {
             using (var connection = new SqlConnection(_connectionString))
             {
                 connection.Open();
                 using (var command = new SqlCommand("up_Insert_comment", connection))
                 {
                     command.CommandType = System.Data.CommandType.StoredProcedure;
                     var commentId = Guid.NewGuid();
                     command.Parameters.AddWithValue("@id", commentId);
                     command.Parameters.AddWithValue("@fileId", comment.FileId);
                     command.Parameters.AddWithValue("@userId", comment.Author.Id);
                     command.Parameters.AddWithValue("@text", comment.Text);
                     command.Parameters.AddWithValue("@postTime", comment.PostTime);
                     command.ExecuteNonQuery();
                     comment.CommentId = commentId;
                     return(comment);
                 }
             }
         }
         catch (Exception ex)
         {
             logger.Error(ex.Message);
             return(null);
         }
     }
 }
示例#27
0
 private bool _filter(ResidentItem residentItem, PoolItemPhase phase)
 {
     if (_itemFilter == null)
     {
         return(true);
     }
     try
     {
         return(_itemFilter(residentItem.Item, phase));
     }
     catch (Exception ex)
     {
         _log.Error("Failed to re-claim an item that was returned to a {0} instance", ex);
         return(false);
     }
 }
        internal void WaitForReply(short waitId)
        {
            ResourcePoolItem <short> idItem = this.idItem; //need a reference to this so we can release it LAST and avoid a race condition

            if (Log.IsDebugEnabled)
            {
                Log.DebugFormat("WaitForReply() Waits for waitId {0} to be released.", waitId);
            }
            if (this.waitHandle.WaitOne(timeOut, false))
            {
                if (Log.IsDebugEnabled)
                {
                    Log.DebugFormat("WaitForReply() waitId {0} is released.", waitId);
                }
                this.idItem = null;
                idItem.Release();
                this.waitHandle = null;
            }
            else
            {
                this.idItem = null;
                idItem.Release();
                this.waitHandle = null;
                //ApplicationException ex = new ApplicationException("TimeOut exception.");
                if (Log.IsErrorEnabled)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendFormat("WaitForReply() WaitHandle is timed out for waitId {0}", waitId);
                    Log.Error(sb.ToString());
                }
                //throw ex;
            }
        }
示例#29
0
 public HitStatus GetHits()
 {
     if (_hits == null && _isNotcalled)
     {
         _isNotcalled = false;
         try
         {
             if (!string.IsNullOrEmpty(Response))
             {
                 var temp = JsonSerializer.Get <SearchHits>(Response);
                 if (temp != null && temp.Hits != null)
                 {
                     _hits = temp.Hits;
                 }
             }
         }
         catch (System.Exception e)
         {
             _logger.Error(Response, e);
         }
     }
     if (_hits != null)
     {
         return(_hits);
     }
     return(new HitStatus());
 }
        public Task CreateAsync(IdentityUser user)
        {
            using (LogWrapper logger = new LogWrapper())
            {
                if (user == null)
                {
                    logger.Error("Пользователь не может быть null.");
                    throw new ArgumentNullException(nameof(user), "Пользователь не может быть null.");
                }
                try
                {
                    return(Task.Factory.StartNew(() =>
                    {
                        using (var connection = new SqlConnection(_connectionString))
                        {
                            connection.Open();

                            user.Id = Guid.NewGuid();
                            user.RegDate = DateTimeOffset.Now;
                            user.PasswordHash = PasswordHashing.HashPassword(user.PasswordHash);

                            connection.Execute("upCreate_new_user",
                                               new
                            {
                                user.Id,
                                user.UserName,
                                user.PasswordHash,
                                user.Email,
                                user.EmailConfirmed,
                                user.FirstName,
                                user.SecondName,
                                user.RegDate,
                                user.City,
                                user.BirthDate,
                                user.SecurityStamp
                            },
                                               commandType: CommandType.StoredProcedure);
                        }
                    }));
                }
                catch (Exception e)
                {
                    logger.Error(e.Message);
                    return(null);
                }
            }
        }