public void File_Should_Be_Read()
        {
            var path = GetPath("TestData.txt");
            var res  = FileReadWrite.ReadFileAsync(path);

            Assert.Pass();
        }
Beispiel #2
0
 /// <summary>
 /// 订单编号标识文件+1
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="num"></param>
 public void SaveToFile(string key, string fileName, int num)
 {
     try
     {
         FileReadWrite.Write(fileName, FileMode.Create, (fs) =>
         {
             var buffer = BitConverter.GetBytes(num);
             fs.Write(buffer, 0, buffer.Length);
         });
         if (num == 1)
         {
             //清除昨天的流水文件
             Task.Factory.StartNew(() =>
             {
                 try
                 {
                     var delfileName = GetFileName(key, DateTime.Now.AddDays(-1));
                     delfileName     = Path.Combine(CacheFilePath, delfileName);
                     if (File.Exists(delfileName))
                     {
                         File.Delete(delfileName);
                     }
                 }
                 catch { }
             });
         }
     }
     catch (Exception ex) { }
 }
Beispiel #3
0
        public string GetPairs()
        {
            //read last pairs here
            FileReadWrite file = new FileReadWrite();

            var yesterdayPairs = GetLastPairs(file.ReadFile()); //this returns a List<tuple> of canonical pairs
            var todayPairs     = new List <Tuple <string, string> >();

            var randomPair = _pairs.OrderBy(arg => Guid.NewGuid()).Take(2).ToList();

            todayPairs.Add(Tuple.Create(randomPair[0], randomPair[1]));

            while (yesterdayPairs.Contains(todayPairs[0]))
            {
                todayPairs = new List <Tuple <string, string> >();
                randomPair = _pairs.OrderBy(arg => Guid.NewGuid()).Take(2).ToList();

                todayPairs.Add(Tuple.Create(randomPair[0], randomPair[1]));
            }
            //then write the new pair
            file.WriteToFile($"{todayPairs[0].Item1.ToString()},{todayPairs[0].Item2.ToString()}");

            //return the new pair
            return($"Today's pairs are : {todayPairs[0].Item1.ToString()} & {todayPairs[0].Item2.ToString()}");
        }
Beispiel #4
0
        public BehaviorTreeData ReadJson(string filePath)
        {
            Debug.Log("Read:" + filePath);
            BehaviorTreeData behaviorData = new BehaviorTreeData();

            string content = FileReadWrite.Read(filePath);

            if (string.IsNullOrEmpty(content))
            {
                return(behaviorData);
            }

            JsonData jsonData = JsonMapper.ToObject(content);

            behaviorData.fileName = jsonData["fileName"].ToString();

            behaviorData.rootNodeId = int.Parse(jsonData["rootNodeId"].ToString());

            JsonData nodeList = jsonData["nodeList"];

            behaviorData.nodeList = GetNodeList(nodeList);

            JsonData parameterList = jsonData["parameterList"];

            behaviorData.parameterList = GetParameterList(parameterList);

            behaviorData.descript = jsonData["descript"].ToString();

            return(behaviorData);
        }
Beispiel #5
0
 public static void Save()
 {
     if (RankData.scores.Count > 0)
     {
         FileReadWrite.WriteToBinaryFile(baseSavePath + "/rank.dat", RankData.scores);
     }
 }
Beispiel #6
0
 public static void LoadDataToRankData()
 {
     if (System.IO.File.Exists(baseSavePath + "/rank.dat"))
     {
         RankData.scores = FileReadWrite.ReadFromBinaryFile <List <int> >(baseSavePath + "/rank.dat");
     }
 }
Beispiel #7
0
        public int GetNumber()
        {
            string fileName = string.Empty;

            if (SwiftNumberMode != SwiftNumberMode.Normal)
            {
                fileName = string.Format(FILENAMEFORMAT, Name, DateTime.Now.ToString(DateFormat));
            }
            else
            {
                fileName = string.Format(FILENAMEFORMAT, Name, string.Empty);
            }
            fileName = Path.Combine(TempFilePath, fileName);

            if (!File.Exists(fileName))
            {
                SaveToFile(1);
                return(1);
            }
            return(FileReadWrite.Read(fileName, FileMode.Open, (fs) =>
            {
                byte[] buffer = new byte[4];
                fs.Read(buffer, 0, 4);
                return BitConverter.ToInt32(buffer, 0);
            }));
        }
        private void save_task_button(object sender, RoutedEventArgs e)
        {
            if (NameOfTaskTB.Text == "" || TypeComboBox.Text == "" || DueDateOfTaskDP.SelectedDate == null ||
                EndDateOfTaskDP.SelectedDate == null)
            {
                MessageBox.Show("Please enter all information");
            }
            else
            {
                string        taskName = NameOfTaskTB.Text;
                string        type     = Convert.ToString(TypeComboBox.Text);
                DateTime      dueDate  = (DateTime)DueDateOfTaskDP.SelectedDate;
                DateTime      endDate  = (DateTime)EndDateOfTaskDP.SelectedDate;
                FileReadWrite file     = new FileReadWrite();


                Task_ editTask = new Task_(taskName, type, reocurring, dueDate, endDate);

                student.TaskList[index] = editTask;
                file.EditTaskToFile(student, editTask, oldTask);
                homeScreen hs = new homeScreen(student);
                this.Close();
                hs.Show();
            }
        }
Beispiel #9
0
        private void AddTaskButton(object sender, RoutedEventArgs e)
        {
            if (NameOfTaskTB.Text == "" || TypeComboBox.Text == "" || DueDateOfTaskDP.SelectedDate == null ||
                EndDateOfTaskDP.SelectedDate == null)
            {
                MessageBox.Show("Please enter all information");
            }
            else
            {
                bool     reocurring = false;
                string   taskName   = NameOfTaskTB.Text;
                string   type       = Convert.ToString(TypeComboBox.Text);
                DateTime dueDate    = (DateTime)DueDateOfTaskDP.SelectedDate;
                DateTime endDate    = (DateTime)EndDateOfTaskDP.SelectedDate;

                if (YesRB.IsChecked == true)
                {
                    reocurring = true;
                }

                Task_ task = new Task_(taskName, type, reocurring, dueDate, endDate);
                student.AddTask(task);
                FileReadWrite file = new FileReadWrite();
                file.AddTaskToFile(student, task);
                homeScreen home = new homeScreen(student);

                this.Close();
                home.Show();
            }
        }
Beispiel #10
0
    public static void GoToYipli(string direction = "NoDir")
    {
        // add ios part also
#if UNITY_ANDROID || UNITY_IOS
        switch (direction)
        {
        case ProductMessages.noMatCase:
            Debug.LogError("case : " + ProductMessages.noMatCase);
            Application.OpenURL(ProductMessages.AddMatAppPageUrl);
            break;

        case ProductMessages.noUserFound:
            Debug.LogError("case : " + ProductMessages.noUserFound);
            Application.OpenURL(ProductMessages.UserFoundAppPageUrl);
            break;

        case ProductMessages.noPlayerAdded:
            Debug.LogError("case : " + ProductMessages.noPlayerAdded);
            Application.OpenURL(ProductMessages.AddPlayerAppPageUrl);
            break;

        case ProductMessages.relaunchGame:
            Debug.LogError("case : " + ProductMessages.relaunchGame);
            Application.OpenURL(ProductMessages.RelaunchGameUrl + Application.identifier);
            break;

        case ProductMessages.openYipliApp:
            Debug.LogError("case : " + ProductMessages.openYipliApp);
            Application.OpenURL(ProductMessages.OpenYipliAppUrl);
            break;

        default:
            Debug.LogError("case : default");
            Application.OpenURL(ProductMessages.OpenYipliAppUrl);

            /*
             * try
             * {
             *  AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
             *  AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
             *  AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager");
             *
             *  AndroidJavaObject launchIntent = null;
             *  launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage", yipliAppBundleId);
             *  ca.Call("startActivity", launchIntent);
             * }
             * catch (AndroidJavaException e)
             * {
             *  Debug.Log(e);
             *  Application.OpenURL("market://details?id=" + yipliAppBundleId);
             * }
             */
            break;
        }
#elif UNITY_STANDALONE_WIN && UNITY_EDITOR
        FileReadWrite.OpenYipliApp();
#else
        Debug.Log("Unsupported os");
#endif
    }
Beispiel #11
0
        private void FileWrite(string fileName, string templateName, string templateFile, string templatePath)
        {
            var context  = templateFile.Replace("{{Template}}", templateName);
            var filePath = Path.Combine(templatePath, fileName);

            FileReadWrite.FileWrite(filePath, context);
        }
Beispiel #12
0
        private void Add_Course_Button(object sender, RoutedEventArgs e)
        {
            if (CourseNumberTB.Text == "" || courseNameTB.Text == "" ||
                MeetingTimeTB.Text == "" || DateOfCourse.SelectedDate == null)
            {
                MessageBox.Show("Please enter all information");
            }
            else
            {
                FileReadWrite file        = new FileReadWrite();
                int           courseNum   = Convert.ToInt32(CourseNumberTB.Text);
                string        courseName  = courseNameTB.Text;
                string        meetingTime = MeetingTimeTB.Text;
                DateTime      courseDate  = (DateTime)DateOfCourse.SelectedDate;


                Course course = new Course(courseNum, courseName, meetingTime, courseDate);
                student.AddCourse(course);
                file.AddCourseToFile(student, course);
                ViewCourses viewCourse = new ViewCourses(student);

                this.Close();
                viewCourse.Show();
            }
        }
Beispiel #13
0
 public ReminderManager(string _userID)
 {
     fileRW        = new FileReadWrite();
     remindersPath = "reminders.csv";
     userID        = _userID;
     remList       = new List <Remind>();
     LoadReminders();
 }
Beispiel #14
0
        private void FileWriteSql(string templateName, string templateFile, string templatePath)
        {
            var sqlStr   = DbSql.Replace("{{Template}}", templateName);
            var filePath = Path.Combine(templatePath, templateFile);
            var context  = FileReadWrite.FileRead(filePath);

            context = $"{context}{sqlStr}";
            FileReadWrite.FileWrite(filePath, context);
        }
Beispiel #15
0
    public void TroubleshootSystem()
    {
        FileReadWrite.WriteToFileForDriverSetup(currentYipliConfig.gameId);
        FileReadWrite.ReadFromFile();

        StartCoroutine(StartValidationUI());

        FileReadWrite.CheckIfMatDriverIsInstalled(currentYipliConfig.gameId);
    }
Beispiel #16
0
    public static List <MyConfiguration> LoadItems(string path)
    {
        string filePath = baseSavePath + "/" + path + ".dat";

        if (System.IO.File.Exists(filePath))
        {
            return(FileReadWrite.ReadFromBinaryFile <List <MyConfiguration> >(filePath));
        }
        return(null);
    }
Beispiel #17
0
    public static GameProgressSaveData LoadGameProgress()
    {
        var filePath = Path.Combine(baseSavePath, "progress.dat");

        if (File.Exists(filePath))
        {
            return(FileReadWrite.ReadFromBinaryFile <GameProgressSaveData>(filePath));
        }
        return(null);
    }
Beispiel #18
0
        public void SerializeSerializablePlayer()
        {
            SerializablePlayer actualPlayer = new SerializablePlayer("Emil", 2);

            FileReadWrite.Serialize(actualPlayer, @"..\..\actualPlayer.bin");
            SerializablePlayer expectedPlayer = (SerializablePlayer)FileReadWrite.Deserialize(@"..\..\expectedPlayer.bin");

            Assert.AreEqual(expectedPlayer.Name, actualPlayer.Name);
            Assert.AreEqual(expectedPlayer.Score, actualPlayer.Score);
        }
Beispiel #19
0
    public static ItemContainerSaveData _LoadItems(string path)
    {
        string filePath = baseSavePath + "/" + path + ".dat";

        if (System.IO.File.Exists(filePath))
        {
            return(FileReadWrite.ReadFromBinaryFile <ItemContainerSaveData>(filePath));
        }
        return(null);
    }
    public static DataHero LoadData(string fileName)
    {
        string filePath = baseSavePath + "/" + fileName + ".dat";

        if (System.IO.File.Exists(filePath))
        {
            return(FileReadWrite.ReadFromBinaryFile <DataHero>(filePath));
        }
        return(null);
    }
Beispiel #21
0
    public static CurrencySaveData LoadCurrency(string path)
    {
        string filePath = baseSavePath + "/" + path + ".dat";

        if (System.IO.File.Exists(filePath))
        {
            return(FileReadWrite.ReadFromBinaryFile <CurrencySaveData>(filePath));
        }
        return(null);
    }
Beispiel #22
0
        private void FileWriteWithLower(string fileName, string templateName, string templateFile, string templatePath)
        {
            var lowerCaseTemplate = StringHelper.ToSmallHump(templateName);
            var context           = templateFile
                                    .Replace("{{Template}}", templateName)
                                    .Replace("{{LowerCaseTemplate}}", lowerCaseTemplate);
            var filePath = Path.Combine(templatePath, fileName);

            FileReadWrite.FileWrite(filePath, context);
        }
Beispiel #23
0
    public static T loadData <T>(string path)
    {
        string filePath = baseSavePath + "/" + path + ".dat";

        if (System.IO.File.Exists(filePath))
        {
            return(FileReadWrite.ReadFromBinaryFile <T>(filePath));
        }

        return(default(T));
    }
Beispiel #24
0
        public static void Save(List <IPlayer> players)
        {
            var seriazablePlayers = new List <SerializablePlayer>();

            foreach (var player in players)
            {
                seriazablePlayers.Add(new SerializablePlayer(player.Name, player.Score));
            }

            FileReadWrite.Serialize(seriazablePlayers, @"..\..\Scoreboard.bin");
        }
Beispiel #25
0
        private void SaveToFile(int serialNumber)
        {
            try
            {
                string fileName = string.Empty;
                //当天文件名,记录当前流水
                if (SwiftNumberMode != SwiftNumberMode.Normal)
                {
                    fileName = string.Format(FILENAMEFORMAT, Name, DateTime.Now.ToString(DateFormat));
                }
                else
                {
                    fileName = string.Format(FILENAMEFORMAT, Name, string.Empty);
                }
                fileName = Path.Combine(TempFilePath, fileName);
                FileReadWrite.Write(fileName, FileMode.Create, (fs) =>
                {
                    var buffer = BitConverter.GetBytes(serialNumber);
                    fs.Write(buffer, 0, buffer.Length);
                });
                var tempEvent = SwiftNumberChanged;
                if (tempEvent != null)
                {
                    tempEvent(this, new SwiftNumberChangeEventArgs()
                    {
                        Name = Name
                    });
                }

                if (serialNumber == 1 && SwiftNumberMode != SwiftNumberMode.Normal)
                {
                    //清除昨天的流水文件
                    Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            var delfileName = string.Format(FILENAMEFORMAT, Name, DateTime.Now.AddDays(-1).ToString(DateFormat));
                            delfileName     = Path.Combine(TempFilePath, delfileName);
                            if (File.Exists(delfileName))
                            {
                                File.Delete(delfileName);
                            }
                        }
                        catch { }
                    });
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
    public static ItemContainerSaveData LoadItems(string fileName)
    {
        string filePath = baseSavePath + "/" + fileName + ".dat";

        if (System.IO.File.Exists(filePath))
        {
            return(FileReadWrite.ReadFromBinaryFile <ItemContainerSaveData>(filePath));
        }
        else
        {
            Debug.LogError("Save file not found in" + filePath);
            return(null);
        }
    }
Beispiel #27
0
    private void SaveOptions()
    {
        OptionsData options = new OptionsData
                              (
            useGamepadToggle.isOn,
            fullscreenToggle.isOn,
            vSyncToggle.isOn,
            masterVolumeSlider.value,
            soundVolumeSlider.value,
            musicVolumeSlider.value
                              );

        FileReadWrite.WriteToJsonFile(options);
    }
Beispiel #28
0
    private void LoadOptions()
    {
        OptionsData options = FileReadWrite.ReadFromJsonFile <OptionsData>();

        if (options != null)
        {
            useGamepadToggle.isOn    = options.useGamepad;
            fullscreenToggle.isOn    = options.fullScreen;
            vSyncToggle.isOn         = options.vSync;
            masterVolumeSlider.value = options.masterVolumeValue;
            soundVolumeSlider.value  = options.soundVolumeValue;
            musicVolumeSlider.value  = options.musicVolumeValue;
        }
    }
Beispiel #29
0
        private void button1_Click(object sender, EventArgs e)
        {
            bool   a       = Lc.Parse(creTextBox2.Text, creTextBox3.Text);
            string actPath = System.Windows.Forms.Application.StartupPath + @"\actc.reg";
            string regPath = System.Windows.Forms.Application.StartupPath + @"\regc.reg";

            if (a)
            {
                FileReadWrite.WriteFile(actPath, creTextBox2.Text);
                FileReadWrite.WriteFile(regPath, creTextBox3.Text);
                Alert.Show("Đăng kí thành công !\nKhởi động lại chương trình \nđể sử dụng");
                Application.Exit();
            }
        }
Beispiel #30
0
    private void Read(string filePath)
    {
        string content = FileReadWrite.Read(filePath);

        if (string.IsNullOrEmpty(content))
        {
            return;
        }

        string    fileName  = Path.GetFileNameWithoutExtension(filePath);
        TableData tableData = new TableData(fileName);

        tableData.SetData(content);
        _tableDic[fileName] = tableData;
    }