public static ObservableCollection <SourceTextFile> UpdateSourceTextList(ControlledProject project)
 {
     try
     {
         ObservableCollection <SourceTextFile> originalCollection = ScanFolder(project.WorkingDirectory);
         ObservableCollection <SourceTextFile> savedCollection    = GetFromTextFile(Path.Combine(project.DocumentDirectory, "SourceTexts.csv"));
         foreach (var item in originalCollection)
         {
             foreach (var sItem in savedCollection)
             {
                 if (sItem.FullName.Equals(item.FullName))
                 {
                     item.Description = sItem.Description;
                     item.Owner       = sItem.Owner;
                     break;
                 }
             }
         }
         return(originalCollection);
     }
     catch (Exception ex)
     {
         MainClass.OnErrorInLibrary(string.Format("Ошибка при создании исходных текстов: {0}", ex.Message));
         return(new ObservableCollection <SourceTextFile>());
     }
 }
Exemple #2
0
        public async static Task <List <int> > CheckForEqual(ControlledProject prj)
        {
            try
            {
                List <int> result = new List <int>();
                using (var Connection = await ConnectAsync())
                {
                    var command = Connection.CreateCommand();
                    command.CommandText = string.Format("SELECT ProjectId FROM dbo.Projects WHERE Name='{0}' ", prj.Name);
                    var reader = await command.ExecuteReaderAsync();

                    while (await reader.ReadAsync())
                    {
                        result.Add(Convert.ToInt32(reader["ProjectId"]));
                    }
                    reader.Close();
                    Disconnect(Connection);
                }
                return(result);
            }
            catch (Exception ex)
            {
                MainClass.OnErrorInLibrary(string.Format("Ошибка проверки уникальности проекта в БД: {0}", ex.Message));
                return(new List <int>());
            }
        }
Exemple #3
0
        /// <summary>
        /// Обновить проект в БД
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>
        public async static Task UpdateProject(ControlledProject project)
        {
            try
            {
                ObservableCollection <ControlledProject> result = new ObservableCollection <ControlledProject>();
                using (var Connection = await ConnectAsync())
                {
                    if (Connection != null)
                    {
                        var command = Connection.CreateCommand();
                        command.CommandText = string.Format("UPDATE dbo.Projects SET Name='{1}', ReleaseDirectory='{2}', WorkingDirectory='{3}', DocumentDirectory='{4}', Category={5}, Task={6} WHERE " +
                                                            "ProjectId={0}", project.Id, project.Name, project.ReleaseDirectory, project.WorkingDirectory, project.DocumentDirectory, (int)project.Category, (int)project.Task);
                        await command.ExecuteNonQueryAsync();

                        Disconnect(Connection);
                    }
                    else
                    {
                        throw new Exception("Ошибка подключения!");
                    }
                }
            }
            catch (Exception ex)
            {
                MainClass.OnErrorInLibrary(string.Format("Не удалось обновитб проект в БД: {0}", ex.Message));
            }
        }
Exemple #4
0
        /// <summary>
        /// Добавить проект в БД
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>
        public async static Task AddProject(ControlledProject project)
        {
            try
            {
                ObservableCollection <ControlledProject> result = new ObservableCollection <ControlledProject>();
                using (var Connection = await ConnectAsync())
                {
                    if (Connection != null)
                    {
                        if (!await CheckTableExistance(Connection, "Projects"))
                        {
                            await GenProjectTable();
                        }
                        var command = Connection.CreateCommand();
                        command.CommandText = string.Format("INSERT INTO dbo.Projects (ProjectId, Name, ReleaseDirectory, WorkingDirectory, DocumentDirectory, Category, Task) VALUES (" +
                                                            "{0},'{1}','{2}','{3}','{4}',{5},{6})", project.Id, project.Name, project.ReleaseDirectory, project.WorkingDirectory, project.DocumentDirectory, (int)project.Category, (int)project.Task);
                        await command.ExecuteNonQueryAsync();

                        Disconnect(Connection);
                    }
                    else
                    {
                        throw new Exception("Ошибка подключения!");
                    }
                }
            }
            catch (Exception ex)
            {
                MainClass.OnErrorInLibrary(string.Format("Не удалось сохранить проект в БД: {0}", ex.Message));
            }
        }
Exemple #5
0
 public static ControlledApp GetById(int id, ControlledProject prj)
 {
     foreach (var app in prj.Apps)
     {
         if (app.Id == id)
         {
             return(app);
         }
     }
     return(new ControlledApp());
 }
 public static void CreateSourceTextList(ControlledProject project)
 {
     try
     {
         project.SourceTextFiles = UpdateSourceTextList(project);
         SaveAsExcel(project.SourceTextFiles, Path.Combine(project.DocumentDirectory, "Ведомость исходных текстов.xlsx"));
         SaveAsTextFile(project.SourceTextFiles, Path.Combine(project.DocumentDirectory, "SourceTexts.csv"));
     }
     catch (Exception ex)
     {
         MainClass.OnErrorInLibrary(string.Format("Ошибка при сохранении исходных текстов: {0}", ex.Message));
     }
 }
Exemple #7
0
        /// <summary>
        /// Удалить проект
        /// </summary>
        /// <param name="prj"></param>
        /// <returns></returns>
        public async static Task DeleteProject(ControlledProject prj)
        {
            try
            {
                foreach (var app in prj.Apps)
                {
                    await DeleteApp(app);
                }
                using (var Connection = await ConnectAsync())
                {
                    var command = Connection.CreateCommand();
                    command.CommandText = string.Format("DELETE FROM dbo.Projects WHERE ProjectId={0}", prj.Id);
                    await command.ExecuteNonQueryAsync();

                    Disconnect(Connection);
                }
            }
            catch (Exception ex)
            {
                MainClass.OnErrorInLibrary(string.Format("Не удалось удалить данные по проекту {0} в БД: {1}", prj.Name, ex.Message));
            }
        }
Exemple #8
0
        /// <summary>
        /// Получить перечень приложений для указанного проекта
        /// </summary>
        /// <param name="prj"></param>
        /// <returns></returns>
        public async static Task <ControlledProject> GetAppsForProject(ControlledProject prj)
        {
            try
            {
                using (var Connection = await ConnectAsync())
                {
                    if (Connection != null)
                    {
                        if (!await CheckTableExistance(Connection, "Applications"))
                        {
                            await CreateAppTable();

                            Disconnect(Connection);
                            return(prj);
                        }
                        var command = Connection.CreateCommand();
                        command.CommandText = string.Format("SELECT AppId, ProjectId, Name, ReleaseDirectory, SourceDirectory, DocumentDirectory,Description,MainFileName" +
                                                            ",MainFileReleaseHash,MainFileReleaseVersion,MainFileReleaseDate,Status,CompatibleOSs,CompatibleScadas,CompatibleSZI,IdentificationType,Installer,Report" +
                                                            ",BuildingComponents,FunctionalComponents,DataStoringMechanism,SUBD,LocalData,AuthorizationType,Platform,OtherSoft,IsInReestr, UserCategories  FROM dbo.Applications WHERE ProjectId={0}", prj.Id);
                        var reader = await command.ExecuteReaderAsync();

                        while (await reader.ReadAsync())
                        {
                            prj.Apps.Add(new ControlledApp
                            {
                                Parent                 = prj,
                                Id                     = Convert.ToInt32(reader["AppId"]),
                                Name                   = reader["Name"].ToString(),
                                ReleaseDirectory       = reader["ReleaseDirectory"].ToString(),
                                SourceDirectory        = reader["SourceDirectory"].ToString(),
                                DocumentDirectory      = reader["DocumentDirectory"].ToString(),
                                Description            = reader["Description"].ToString(),
                                MainFileName           = reader["MainFileName"].ToString(),
                                MainFileReleaseHash    = reader["MainFileReleaseHash"].ToString(),
                                MainFileReleaseVersion = reader["MainFileReleaseVersion"].ToString(),
                                MainFileReleaseDate    = reader["MainFileReleaseDate"].ToString(),
                                Status                 = (PPOReestrStatus)Convert.ToInt32(reader["Status"]),
                                CompatibleOSs          = reader["CompatibleOSs"].ToString(),
                                CompatibleScadas       = reader["CompatibleScadas"].ToString(),
                                CompatibleSZI          = reader["CompatibleSZI"].ToString(),
                                IdentificationType     = reader["IdentificationType"].ToString(),
                                Installer              = reader["Installer"].ToString(),
                                Report                 = reader["Report"].ToString(),
                                BuildingComponents     = reader["BuildingComponents"].ToString(),
                                FunctionalComponents   = reader["FunctionalComponents"].ToString(),
                                DataStoringMechanism   = reader["DataStoringMechanism"].ToString(),
                                SUBD                   = reader["SUBD"].ToString(),
                                LocalData              = reader["LocalData"].ToString(),
                                AuthorizationType      = reader["AuthorizationType"].ToString(),
                                Platform               = reader["Platform"].ToString(),
                                OtherSoft              = reader["OtherSoft"].ToString(),
                                IsInReestr             = Convert.ToBoolean(reader["IsInReestr"]),
                                UserCategories         = reader["UserCategories"].ToString(),
                            });
                        }
                        Disconnect(Connection);
                    }
                    else
                    {
                        throw new Exception("Ошибка подключения!");
                    }
                }

                foreach (var app in prj.Apps)
                {
                    await app.UpdateMainFileInfoAsync();
                }
                prj.UpdateState();
                return(prj);
            }
            catch (Exception ex)
            {
                MainClass.OnErrorInLibrary(string.Format("Не удалось получить перечень приложений для проекта {0} из БД: {1}", prj.Name, ex.Message));
                return(prj);
            }
        }