예제 #1
0
        public void LoadPopulation(string filename)
        {
            XmlTextReader xr = new XmlTextReader(filename);
            XmlSerializer xs = new XmlSerializer(typeof(Generation[]));


            Generation[] lol  = ((Generation[])xs.Deserialize(xr));
            int          test = lol.First().NumGeneration + 1;

            Generation.GenerationCpt = test;
            Individu.NbIndividus     = test * 10;


            Gens.Clear();
            foreach (Generation gen in lol)
            {
                Gens.Add(gen);
            }
        }
예제 #2
0
        public void CommandExecuted(ICommand command)
        {
            if (command is ApplyRenameCommand)
            {
                RenameApplied(command as ApplyRenameCommand);
            }
            if (!(command is IFileSyncCommand))
            {
                return;
            }
            var items   = Container.Resolve <IRepository>().AllOf <IDataRecord>().ToArray();
            var gensNow = new Dictionary <string, GenFileInfo>();

            foreach (var p in InvertGraphEditor.GetAllCodeGenerators(
                         Container.Resolve <DatabaseService>().CurrentConfiguration, items))
            {
                var key = Path.GetFileName(p.Filename);
                if (!gensNow.ContainsKey(key))
                {
                    gensNow.Add(key, new GenFileInfo(Path.Combine(Application.dataPath, p.RelativeFullPathName), p));
                }
            }

            var deleteList = new List <string>();

            foreach (var item in Gens)
            {
                if (!gensNow.ContainsKey(item.Key))
                {
                    // Its been removed or renamed

                    if (File.Exists(item.Value.FullPath))
                    {
                        deleteList.Add(item.Value.FullPath);
                    }
                }
                else
                {
                    var nowItem = gensNow[item.Key];
                    if (nowItem.Generator.ObjectData == item.Value.Generator.ObjectData)
                    {
                        // It has been moved
                        if (File.Exists(item.Value.FullPath))
                        {
                            File.Move(item.Value.FullPath, nowItem.FullPath);
                        }
                    }
                }
            }

            Gens.Clear();
            GC.Collect();
            IsRename = false;
            if (deleteList.Count > 0)
            {
                if (InvertGraphEditor.Platform.MessageBox("Warning",
                                                          string.Format("You've deleted a record that has {0} file(s) associated with it.  Would you like to remove them?", deleteList.Count),
                                                          "YES (Recommended)", "NO they are special!"))
                {
                    foreach (var item in deleteList)
                    {
                        File.Delete(item);
                    }
                }
                this.Execute(new SaveAndCompileCommand()
                {
                    ForceCompileAll = true
                });
            }
        }