Beispiel #1
0
        /// <summary>
        /// Model Class constructor, initiate Save Work in a list (no parameters)
        /// </summary>
        public Model()
        {
            //Asign all delegate
            OnSaveWorkUpdate   = UpdateSaveFile;
            OnProgressUpdate   = UpdateAllSaveProgress;
            OnUpdateModelError = SetModelError;
            OnSocketResumeSave = ResumeSave;
            OnSocketPauseSave  = PauseSave;
            OnSocketCancelSave = CancelSave;
            GlobalProgress     = 0;
            //Init new settings
            ModelSettings = new Setting();
            //Check if a setting file already exists, if false then create a new one, if true get the different value from it and apply it to the setting object (ModelSettings).
            if (!File.Exists("settings.json"))
            {
                ModelSettings.MaxTransferSize   = 10000;
                ModelSettings.SoftwareString    = "";
                ModelSettings.PriorityExtension = new List <Extension>();
                UpdateSettingsFile();
            }
            else
            {
                string settingsFile = File.ReadAllText("settings.json");
                var    tempWorkList = JsonConvert.DeserializeObject <Setting>(settingsFile);
                ModelSettings = tempWorkList;
                UpdateSettingsFile();
            }

            WorkList = new List <ISaveWork>();
            //If the state file has not been initialized then create 5 SaveWork object from nothing
            if (!File.Exists("stateFile.json"))
            {
                WorkList.Add(new CompleteSaveWork("Default", "test", "test", null, SaveWorkType.complete));
                UpdateSaveFile();
            }
            //Then if the State file already exist, use the objects in it to create the WorkList
            else
            {
                string stateFile    = File.ReadAllText("stateFile.json");
                var    tempWorkList = JsonConvert.DeserializeObject <List <CompleteSaveWork> >(stateFile);

                foreach (CompleteSaveWork work in tempWorkList)
                {
                    if (work.Type == SaveWorkType.complete)
                    {
                        CreateCompleteWork(work.Name, work.SourcePath, work.DestinationPath, work.ExtentionToEncryptList);
                    }
                    else if (work.Type == SaveWorkType.differencial)
                    {
                        CreateDifferencialWork(work.Name, work.SourcePath, work.DestinationPath, work.ExtentionToEncryptList);
                    }
                }
                UpdateSaveFile();
            }

            EditLog.InitSoftwareLogLine();
        }