Inheritance: MonoBehaviour
Example #1
0
        public void GenerateSomeReport0701()
        {
            string report = "EN,Vol_DET(V),Energy(eV)\n";
            List <(string detVol, string[] ene)> entries = new List <(string, string[] ene)>();

            foreach (var nnTask in Tasks)
            {
                var param = nnTask.Key;
                var task  = nnTask.Value;

                if (task.GetEnergies() is string[] taskEnergies)
                {
                    if (param.GetValue("Vol_DET") is string volDet)
                    {
                        entries.Add((volDet, taskEnergies));
                    }
                }
            }

            foreach (var i in new int[] { 0, 1, 2 })
            {
                foreach (var entry in entries)
                {
                    report += i + "," + entry.detVol + "," + entry.ene[i] + "\n";
                }
            }

            File.WriteAllText(FSPath.SubPath("AntiCrossing.txt"), report);
        }
 public void MoveFile(FSPath src, FSPath dest)
 {
     if (_GetStorage(src).Kind != _StorageKind.File)
         throw new ArgumentException("path", string.Format("Attempted to move file {0}, which is not a file.", src.Absolute));
     if (_GetStorage(dest).Kind != _StorageKind.Missing)
         throw new ArgumentException("path", string.Format("Attempted to move file to destination {0}, which already exists.", dest.Absolute));
     _data[dest] = _data[src];
     _data.Remove(src);
 }
Example #3
0
        void Save()
        {
            Util.SerializeToFile(
                new SaveData(this),
                FSPath.SubPath(NnAgent.planFileName)
                );

            Template.Save(FSPath);
        }
Example #4
0
 public void Save(RPath?path = null)
 {
     Util.SerializeToFile(
         new SaveData(this),
         path == null ?
         FSPath.SubPath(NnAgent.tempFileName):
         path.SubPath(NnAgent.tempFileName)
         );
 }
 public void CreateDir(FSPath path)
 {
     while (true)
     {
         _data[path] = new _Node(_StorageKind.Directory);
         if (path.IsRoot)
             return;
         path = path.Parent;
     }
 }
Example #6
0
        public List <NnTask> AddTask(
            List <NnParam> pars
            )
        {
            var newTasks = new Dictionary <NnParam, NnTask>();

            try {
                foreach (var param in pars)
                {
                    if (!param.Pad(Template))
                    {
                        continue;
                    }

                    string tag     = param.GetTag(Template.Variables);
                    NnTask newTask =
                        new NnTask(
                            tag,
                            Template.Type,
                            FSPath.SubPath("tasks").SubPath(tag),
                            Template.GenerateContent(param.Variables),
                            Template.GenerateContent(param.Variables, true),
                            Template.GenerateModuleOptions(param.Variables)
                            );

                    if (tasks.All(x => !x.Value.Equals(newTask)))
                    {
                        newTasks[param] = newTask;
                    }
                }
            } catch {
                Util.ErrorHappend("Error while creating task!");
                return(new List <NnTask>());
            }

            try {
                foreach (var newTask in newTasks)
                {
                    tasks[newTask.Key] = newTask.Value;
                }

                UpdateCommonData(newTasks.Keys.ToList());

                OnPropertyChanged("Plan - AddTask");
                OnPropertyChanged("TaskAmount");
                OnPropertyChanged("BusyTaskAmount");

                Save();
                return(newTasks.Values.ToList());
            } catch {
                Util.ErrorHappend("Error while adding task!");
                return(newTasks.Values.ToList());
            }
        }
Example #7
0
        public void GenerateCSDReport0906()
        {
            string report  = "Vol_L(V),Vol_R(V),Chg_L,Chg_R,L,R\n";
            var    entries =
                new List <(string volL, string volR, string chgL, string chgR, string l, string r)>();

            Func <double, string> ChgType = (double chg) => {
                if (chg < 0.5)
                {
                    return("0");
                }
                if (chg < 1.5)
                {
                    return("1");
                }
                if (chg < 2.5)
                {
                    return("2");
                }
                return("3");
            };

            foreach (var nnTask in Tasks)
            {
                var param = nnTask.Key;
                var task  = nnTask.Value;

                // if (task.NnDQDJCS is int nnDQDJCS)
                if (task.NnDQDReportChgs() is (double l, double r)chgs)
                {
                    if (param.GetValue("Vol_L") is string volL)
                    {
                        if (param.GetValue("Vol_R") is string volR)
                        {
                            entries.Add(
                                (
                                    volL, volR,
                                    chgs.l.ToString(), chgs.r.ToString(),
                                    ChgType(chgs.l), ChgType(chgs.r)));
                        }
                    }
                }
            }

            foreach ((string volL, string volR, string chgL, string chgR, string l, string r) in entries)
            {
                report += volL + "," + volR + "," + chgL + "," + chgR + "," + l + "," + r + "\n";
            }

            File.WriteAllText(FSPath.SubPath("CSD.txt"), report);
        }
 public override void Overwrote(FSPath path)
 {
     if (!_fileSystem._Disk.FileExists(path))
     {
         _undoActions.Add(() => _fileSystem._Disk.DeleteFile(path));
         return;
     }
     var randomFileName = FSPath.TempFolder/Guid.NewGuid().ToString("N");
     _fileSystem._Disk.MoveFile(path, randomFileName);
     _undoActions.Add(() =>
     {
         _fileSystem._Disk.DeleteFile(path);
         _fileSystem._Disk.MoveFile(randomFileName, path);
     });
 }
Example #9
0
        public bool DeleteTask(
            NnTask task
            )
        {
            bool success = false;

            try {
                if (task.IsBusy())
                {
                    if (Util.WarnAndDecide("Selected task is busy rn. Terminate and delete?"))
                    {
                        task.Terminate();
                    }
                    else
                    {
                        return(false);
                    }
                }

                foreach (var item in tasks.Where(kvp => kvp.Value == task).ToList())
                {
                    tasks.Remove(item.Key);
                    string path = FSPath.SubPath("tasks").SubPath("_removed").SubPath(task.Name);
                    while (Directory.Exists(path))
                    {
                        path += "_";
                    }
                    Directory.Move(task.FSPath, path);
                    DeleteParamInCommonData(item.Key);
                }
                success = true;
            } catch {
                Util.ErrorHappend("Error while deleting task!");
                success = false;
            } finally {
                OnPropertyChanged("Plan - DeleteTask");
                OnPropertyChanged("TaskAmount");
                OnPropertyChanged("BusyTaskAmount");

                Save();
            }
            return(success);
        }
 public string TextContents(FSPath path)
 {
     var storage = _GetStorage(path);
     _ValidateStorage(path, storage);
     return storage.TextContents;
 }
 public byte[] RawContents(FSPath path)
 {
     var storage = _GetStorage(path);
     _ValidateStorage(path, storage);
     return storage.RawContents;
 }
 public void Overwrite(FSPath path, string newContents)
 {
     _data[path] = new _Node(_StorageKind.File) {
         TextContents = newContents
     };
 }
 public void DeleteDir(FSPath path)
 {
     Directory.Delete(path.Absolute);
 }
 public bool FileExists(FSPath path)
 {
     return _GetStorage(path).Kind == _StorageKind.File;
 }
 public bool DirExists(FSPath path)
 {
     return _GetStorage(path).Kind == _StorageKind.Directory;
 }
 public void MoveFile(FSPath src, FSPath dest)
 {
     File.Move(src.Absolute, dest.Absolute);
 }
 public void DeleteFile(FSPath path)
 {
     File.Delete(path.Absolute);
 }
 private void _ValidateStorage(FSPath path, _Node storage)
 {
     if (storage.Kind == _StorageKind.Missing)
         throw new FileNotFoundException(string.Format("Could not find file '{0}'.", path.Absolute), path.Absolute);
     if (storage.Kind == _StorageKind.Directory)
         throw new UnauthorizedAccessException(string.Format("Access to the path '{0}' is denied.", path.Absolute));
 }
 public bool DirExists(FSPath path)
 {
     return Directory.Exists(path.Absolute);
 }
 public string TextContents(FSPath path)
 {
     return File.ReadAllText(path.Absolute);
 }
 public byte[] RawContents(FSPath path)
 {
     return File.ReadAllBytes(path.Absolute);
 }
 public void Overwrite(FSPath path, string newContents)
 {
     File.WriteAllText(path.Absolute, newContents);
 }
 public override void CreatedDirectory(FSPath path)
 {
     _undoActions.Add(() => _fileSystem._Disk.DeleteDir(path));
 }
 public void DeleteFile(FSPath path)
 {
     if (_GetStorage(path).Kind == _StorageKind.Directory)
         throw new ArgumentException("path", string.Format("Path {0} was a directory, and you attempted to delete a file.", path.Absolute));
     _data.Remove(path);
 }
 public void CreateDir(FSPath path)
 {
     Directory.CreateDirectory(path.Absolute);
 }
 public bool FileExists(FSPath path)
 {
     return File.Exists(path.Absolute);
 }