Exemple #1
0
        async Task InitializeCommonEventList(string dataPath)
        {
            string datPath = $"{dataPath}BasicData/CommonEvent.dat";

            var             reader = new CommonEventDatFileReader();
            CommonEventData data   = await reader.ReadFileAsync(datPath);

            CoreData.Instance.commonEvents = data.CommonEventList;

            int eventCount = data.CommonEventList.Count;

            CoreData.Instance.commonEventVariables = new int[eventCount][];
            CoreData.Instance.commonEventStrings   = new string[eventCount][];
            for (int i = 0; i < eventCount; i++)
            {
                CoreData.Instance.commonEventVariables[i] = new int[95];
                CoreData.Instance.commonEventStrings[i]   = new string[5];
            }
        }
        public static void CommonEvent00DataIOTest()
        {
            const string inputFileName  = "CommonEvent_00.dat";
            const string outputFileName = "OutputCommonEvent_00.dat";

            var reader =
                new CommonEventDatFileReader(
                    $@"{CommonEventDataFileTestItemGenerator.TestWorkRootDir}\{inputFileName}");
            var             isSuccessRead   = false;
            CommonEventData commonEventData = null;

            try
            {
                commonEventData = reader.ReadAsync().GetAwaiter().GetResult();
                isSuccessRead   = true;
            }
            catch (Exception ex)
            {
                logger.Exception(ex);
            }

            Assert.IsTrue(isSuccessRead);

            var writer = new CommonEventDatFileWriter(
                $@"{CommonEventDataFileTestItemGenerator.TestWorkRootDir}\{outputFileName}");
            var isSuccessWrite = false;

            try
            {
                writer.WriteAsync(commonEventData).GetAwaiter().GetResult();
                isSuccessWrite = true;
            }
            catch (Exception ex)
            {
                logger.Exception(ex);
            }

            Assert.IsTrue(isSuccessWrite);

            Console.WriteLine(
                $@"Written FilePath : {CommonEventDataFileTestItemGenerator.TestWorkRootDir}\{outputFileName}");
        }
        private static void Common(CommonEventData resultData, string readFileName)
        {
            var filePath = $@"{CommonEventDataFileTestItemGenerator.TestWorkRootDir}\{readFileName}";
            var reader   = new CommonEventDatFileReader(filePath);

            var             readResult      = false;
            CommonEventData commonEventData = null;
            var             errorMessage    = "";

            try
            {
                commonEventData = reader.ReadSync();
                readResult      = true;
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
            }


            // 正しく読めること
            if (!readResult)
            {
                throw new InvalidOperationException(
                          $"Error Occured. Message : {errorMessage}");
            }

            Console.WriteLine("Write Test Clear.");

            var readResultDataBytes = commonEventData.ToBinary().ToArray();

            // 元のデータと一致すること
            using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                var bufLength = (int)stream.Length;
                var buf       = new byte[bufLength];
                stream.Read(buf, 0, bufLength);

                if (readResultDataBytes.Length != bufLength)
                {
                    throw new InvalidOperationException(
                              $"Data Length Not Match. " +
                              $"(answerLength: {bufLength}, readResultLength: {readResultDataBytes.Length})");
                }

                for (long i = 0; i < 0; i++)
                {
                    if (readResultDataBytes[i] != buf[i])
                    {
                        throw new InvalidOperationException(
                                  $"Data Byte Not Match. (index: {i}, answer: {buf[i]}," +
                                  $" readResult: {readResultDataBytes[i]})");
                    }
                }
            }

            // 意図したデータと一致すること
            var resultDataBytes = resultData.ToBinary().ToArray();

            if (resultDataBytes.Length != readResultDataBytes.Length)
            {
                throw new InvalidOperationException(
                          $"Data Length Not Match. " +
                          $"(answerLength: {resultDataBytes.Length}, readResultLength: {readResultDataBytes.Length})");
            }

            for (long i = 0; i < 0; i++)
            {
                if (resultDataBytes[i] != readResultDataBytes[i])
                {
                    throw new InvalidOperationException(
                              $"Data Byte Not Match. (index: {i}, answer: {resultDataBytes[i]}," +
                              $" readResult: {readResultDataBytes[i]})");
                }
            }
        }