Exemple #1
0
        public static SourceControlData FromPath(string path)
        {
            var projectData = JsonInterface.DeserializeObject <SourceControlData>(path);

            if (projectData != null)
            {
                projectData.SourceFile     = path;
                projectData.RepositoryPath = Path.GetDirectoryName(path);
            }
            return(projectData);
        }
        public static void LoadManagedProjects(DOS2ModuleData Data, bool ClearExisting = true)
        {
            if (Data.ManagedProjects == null)
            {
                Data.ManagedProjects = new ObservableImmutableList <ModProjectData>();
                BindingOperations.EnableCollectionSynchronization(Data.ManagedProjects, Data.ManagedProjectsLock);
            }
            else
            {
                if (ClearExisting)
                {
                    Data.ManagedProjects.DoOperation(data => data.Clear());
                    BindingOperations.EnableCollectionSynchronization(Data.ManagedProjects, Data.ManagedProjectsLock);
                }
            }

            string projectsAppDataPath = DefaultPaths.ModuleAddedProjectsFile(Data);

            if (Data.Settings != null && File.Exists(Data.Settings.AddedProjectsFile))
            {
                projectsAppDataPath = Data.Settings.AddedProjectsFile;
            }

            if (!String.IsNullOrEmpty(projectsAppDataPath) && File.Exists(projectsAppDataPath))
            {
                //projectsAppDataPath = Path.GetFullPath(projectsAppDataPath);
                try
                {
                    Data.ManagedProjectsData = JsonInterface.DeserializeObject <ManagedProjectsData>(projectsAppDataPath);
                }
                catch (Exception ex)
                {
                    Log.Here().Error("Error deserializing managed projects data at {0}: {1}", projectsAppDataPath, ex.ToString());
                }
            }


            if (Data.ManagedProjectsData == null)
            {
                Data.ManagedProjectsData = new ManagedProjectsData();
            }
            else
            {
                foreach (var project in Data.ManagedProjectsData.SavedProjects.Items)
                {
                    //var modProject = Data.ModProjects.Where(x => x.Name == project.Name && x.ModuleInfo.UUID == project.GUID).FirstOrDefault();
                    var modProject = Data.ModProjects.Where(x => x.UUID == project.UUID).FirstOrDefault();
                    if (modProject != null)
                    {
                        ModProjectData existingData = null;

                        if (!ClearExisting)
                        {
                            existingData = Data.ManagedProjects.Where(p => p.ProjectName == project.Name && p.UUID == project.UUID).FirstOrDefault();
                        }

                        if (ClearExisting || existingData == null)
                        {
                            Data.ManagedProjects.Add(modProject);

                            if (!String.IsNullOrWhiteSpace(project.LastBackupUTC))
                            {
                                DateTime lastBackup;

                                var success = DateTime.TryParse(project.LastBackupUTC, out lastBackup);
                                if (success)
                                {
                                    //Log.Here().Activity($"Successully parsed {modProject.LastBackup} to DateTime.");
                                    modProject.LastBackup = lastBackup.ToLocalTime();
                                }
                                else
                                {
                                    Log.Here().Error($"Could not convert {project.LastBackupUTC} to DateTime.");
                                }
                            }
                        }
                        else if (existingData != null)
                        {
                            existingData.ReloadData();
                        }
                    }
                }
            }
        }