Ejemplo n.º 1
0
        /// <summary>
        /// Для всех полученных новых рецептов проверить наличие рецептов с такими же именами
        /// и проверить состояние их бита архивности. Для синхронизации архивных рецептов.
        /// </summary>
        /// <param name="importedRecipes">Список полученных рецептов.</param>
        private void TryMarkRecipsAsArchived(List<RecipeInfo> importedRecipes)
        {
            // получаем все рецепты с одинаковыми именами и устанавливаем для них бит архивности
            try {
                sqlConnection.LockConnection();
                selectGetRecipesUpdateArcived.Connection = sqlConnection.GetSqlConnection();
                Logger.Debug("Проверка на изменение архивности рецептов");
                foreach (var recipe in importedRecipes) {
                    selectGetRecipesUpdateArcived.Parameters["Name"].Value = recipe.Name;
                    selectGetRecipesUpdateArcived.Parameters["Revision"].Value = recipe.Revision;
                    using (var reader = selectGetRecipesUpdateArcived.ExecuteReader()) {
                        sqlConnection.UpdateLastOperationTime();
                        while (reader.Read()) {
                            var recipeInfo = new RecipeInfo {
                                Name = reader.GetString(0),
                                Revision = Convert.ToInt32(reader.GetValue(1)),
                                IsArchived = Convert.ToInt32(reader.GetValue(2)) == 1
                            };

                            MarkRecipeAsArchived(recipeInfo);
                        }
                    }
                }
            }
            catch (Exception ex) {
                sqlConnection.ProcessError(ex);
            }
            finally {
                sqlConnection.ReleaseConnection();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Пометить указанный рецепт как архивный в таблице ИТЦ.
        /// </summary>
        /// <param name="aRecipeInfo">Рецепт.</param>
        private void MarkRecipeAsArchived(RecipeInfo aRecipeInfo)
        {
            try {
                Logger.Debug("Получен рецепт для изменения бита архивности");

                oracleConnection.LockConnection();
                updateRecipeArchived.Connection = oracleConnection.GetOracleConnection();
                updateRecipeArchived.Parameters["Archived"].Value = aRecipeInfo.IsArchived ? 1 : 0;
                updateRecipeArchived.Parameters["Name"].Value = aRecipeInfo.Name;
                updateRecipeArchived.Parameters["Revision"].Value = aRecipeInfo.Revision;

                updateRecipeArchived.ExecuteNonQuery();
            }
            catch (Exception ex) {
                oracleConnection.ProcessError(ex);
            }
            finally {
                oracleConnection.ReleaseConnection();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Записать новый рецепт в ИТЦ.
        /// </summary>
        /// <param name="aRecipeInfo">Рецепт.</param>
        /// <returns>True - если запись прошла успешно, false - иначе.</returns>
        private bool TryImportNewRecipe(RecipeInfo aRecipeInfo)
        {
            try {
                oracleConnection.LockConnection();
                insertImportNewRecipe.Connection = oracleConnection.GetOracleConnection();
                insertImportNewRecipe.Parameters["Name"].Value = aRecipeInfo.Name;
                insertImportNewRecipe.Parameters["Revision"].Value = aRecipeInfo.Revision;
                insertImportNewRecipe.Parameters["Archived"].Value = aRecipeInfo.IsArchived ? 1 : 0;
                Logger.Debug("Импортируется рецепт");
                // сделать новую запись в таблицу RECIPE_INFO

                insertImportNewRecipe.ExecuteNonQuery();
                oracleConnection.UpdateLastOperationTime();

                return true;
            }
            catch (Exception ex) {
                oracleConnection.ProcessError(ex);
                return false;
            }
            finally {
                oracleConnection.ReleaseConnection();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Сканировать таблицу в Wagstaff на наличие новых рецептов. Если появились,
        /// то записать в ИТЦ. Метод вызывается таймером.
        /// </summary>
        /// <param name="sender">Object.</param>
        /// <param name="e">ElapsedEventArgs.</param>
        private void CheckNewRecipes(object sender = null, ElapsedEventArgs e = null)
        {
            var importedRecipes = new List<RecipeInfo>();

            try {
                sqlConnection.LockConnection();
                Logger.Debug("Проверка новых рецептов");
                // загружаем все записи, которые появились после lastImportedTime
                selectGetNewRicipes.Connection = sqlConnection.GetSqlConnection();

                selectGetNewRicipes.Parameters["DateCreated"].Value = lastImportedTime;
                using (var reader = selectGetNewRicipes.ExecuteReader()) {
                    sqlConnection.UpdateLastOperationTime();
                    while (reader.Read()) {
                        var recipeInfo = new RecipeInfo {
                            Name = reader.GetString(0),
                            Revision = Convert.ToInt32(reader.GetValue(1)),
                            Technology = reader.GetString(2),
                            Alloy = reader.GetString(3),
                            CreationTime = reader.GetDateTime(4),
                            IsArchived = Convert.ToInt32(reader.GetValue(5)) == 1
                        };

                        Logger.Debug("Новый рецепт получен");

                        if (TryImportNewRecipe(recipeInfo)) {
                            SetLastImportedTime(recipeInfo.CreationTime);
                            SaveLastImportedTime();
                            importedRecipes.Add(recipeInfo);
                        }
                        else {
                            Logger.Debug("Новый рецепт не сохранен");
                        }
                    }
                }
            }
            catch (Exception ex) {
                sqlConnection.ProcessError(ex);
            }
            finally {
                sqlConnection.ReleaseConnection();
            }

            TryMarkRecipsAsArchived(importedRecipes);
        }