Пример #1
0
        public int Save <T>(T entity) where T : Entity.Entity
        {
            int result;

            using (var session = Factory.OpenSession())
            {
                using (var tran = session.BeginTransaction())
                {
                    try
                    {
                        session.Save(entity);

                        tran.Commit();
                        result = entity.Id;
                    }
                    catch (Exception ex)
                    {
                        MonitorLog.WriteLog("Ошибка выполнения процедуры Save<" + typeof(T) + "> : " + ex.Message, MonitorLog.typelog.Error, true);
                        tran.Rollback();
                        result = 0;
                    }
                }
            }
            return(result);
        }
Пример #2
0
        public static MailUserModel GetUser(HttpRequestBase request)
        {
            var model = new MailUserModel {
                IsAutharization = false
            };

            try
            {
                var userCookie = request.Cookies["mail_token"];
                if (userCookie != null)
                {
                    var stream = HttpTools.PostStream(InfoUrl,
                                                      string.Format("oauth_token={0}&client_id={1}&format=json&method=users.getInfo&sig={2}",
                                                                    userCookie.Value, SiteId, ""));
                    model = SerializeTools.Deserialize <MailUserModel>(stream);
                    model.IsAutharization = true;
                }
            }
            catch (Exception ex)
            {
                MonitorLog.WriteLog(ex.InnerException + ex.Message, MonitorLog.typelog.Error, true);
                model.IsAutharization = false;
            }

            return(model);
        }
Пример #3
0
 public T Get <T>(int id) where T : Entity.Entity
 {
     using (var session = Factory.OpenSession())
     {
         try
         {
             return(session.Get <T>(id));
         }
         catch (Exception ex)
         {
             MonitorLog.WriteLog("Ошибка выполнения процедуры Get<" + typeof(T) + "> : " + ex.Message,
                                 MonitorLog.typelog.Error, true);
             throw;
         }
     }
 }
Пример #4
0
        public T GetMessage <T>(int msgId)
        {
            T result;

            using (var session = Factory.OpenSession())
            {
                try
                {
                    result = session.Get <T>(msgId);
                }
                catch (Exception ex)
                {
                    MonitorLog.WriteLog("Ошибка выполнения процедуры GetMessage : " + ex.Message,
                                        MonitorLog.typelog.Error, true);
                    throw;
                }
            }
            return(result);
        }
Пример #5
0
        public T SingleOrDefault <T>(Expression <Func <T, bool> > expression) where T : Entity.Entity
        {
            T result;

            using (var session = Factory.OpenSession())
            {
                try
                {
                    var query = session.QueryOver <T>().Where(expression).SingleOrDefault();
                    result = query;
                }
                catch (Exception ex)
                {
                    MonitorLog.WriteLog("Ошибка выполнения процедуры SingleOrDefault<" + typeof(T) + "> : " + ex.Message,
                                        MonitorLog.typelog.Error, true);
                    throw;
                }
            }
            return(result);
        }
Пример #6
0
        private IEnumerable <string> GetFilesFrom(string searchFolder)
        {
            var directory = new DirectoryInfo(searchFolder);
            var files     = new List <string>();

            try
            {
                var filters = new[] { "jpg", "jpeg", "png", "gif", "tiff", "bmp", "svg" };
                foreach (var filter in filters)
                {
                    files.AddRange(directory.GetFiles($"*.{filter}", SearchOption.TopDirectoryOnly).Select(f => f.Name));
                }
                return(files);
            }
            catch (Exception ex)
            {
                MonitorLog.WriteLog("Ошибка выполнения CarouselViewModel : " + ex.Message, MonitorLog.typelog.Error, true);
                return(new string[1]);
            }
        }
Пример #7
0
 private ISessionFactory CreatePostgreSessionFactory(string connectionString)
 {
     try
     {
         var factory = Fluently.Configure()
                       .Database(PostgreSQLConfiguration.PostgreSQL82
                                 .ConnectionString(connectionString))
                       .ExposeConfiguration(c => c.Properties.Add("current_session_context_class",
                                                                  typeof(CallSessionContext).FullName))
                       .Mappings(x => x.FluentMappings.AddFromAssemblyOf <NewsMap>())
                       .BuildSessionFactory();
         return(factory);
     }
     catch (Exception ex)
     {
         var msg = string.Format("{0} [InnerException]: {1}", ex.Message, ex.InnerException);
         MonitorLog.WriteLog(msg, MonitorLog.typelog.Error, true);
         throw new Exception();
     }
 }
Пример #8
0
        private ISessionFactory CreateSqLiteSessionFactory(string connectionString)
        {
            try
            {
                var str     = string.Format("Data Source={0}{1};Version=3;", AppDomain.CurrentDomain.BaseDirectory.Replace("\\", "/"), connectionString);
                var factory = Fluently.Configure()
                              .Database(SQLiteConfiguration.Standard.ConnectionString(str))
                              .ExposeConfiguration(c => c.Properties.Add("current_session_context_class",
                                                                         typeof(CallSessionContext).FullName))
                              .Mappings(x => x.FluentMappings.AddFromAssemblyOf <NewsMap>())
                              .BuildSessionFactory();

                return(factory);
            }
            catch (Exception ex)
            {
                var msg = string.Format("{0} [InnerException]: {1}", ex.Message, ex.InnerException);
                MonitorLog.WriteLog(msg, MonitorLog.typelog.Error, true);
                return(null);
            }
        }
Пример #9
0
        public List <T> Where <T>(Expression <Func <T, bool> > expression) where T : Entity.Entity
        {
            List <T> result;

            using (var session = Factory.OpenSession())
            {
                try
                {
                    var query = session.QueryOver <T>().Where(expression);
                    result = (List <T>)query
                             .OrderBy(p => p.Id).Asc
                             .List <T>();
                }
                catch (Exception ex)
                {
                    MonitorLog.WriteLog("Ошибка выполнения процедуры Where<" + typeof(T) + "> : " + ex.Message,
                                        MonitorLog.typelog.Error, true);
                    throw;
                }
            }
            return(result);
        }
Пример #10
0
        public void SaveList <T>(List <T> list) where T : Entity.Entity
        {
            using (var session = Factory.OpenSession())
            {
                using (var tran = session.BeginTransaction())
                {
                    try
                    {
                        foreach (var entity in list)
                        {
                            session.SaveOrUpdate(entity);
                        }

                        tran.Commit();
                    }
                    catch (Exception ex)
                    {
                        MonitorLog.WriteLog("Ошибка выполнения процедуры SaveList<" + typeof(T) + "> : " + ex.Message, MonitorLog.typelog.Error, true);
                        tran.Rollback();
                    }
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Создание карусели из папки с фото
        /// </summary>
        /// <param name="folder">Папка с фото</param>
        /// <param name="path">Путь</param>
        /// <param name="header">Заголовок карусели</param>
        /// <param name="interval">Интервал листания</param>
        public CarouselViewModel(string folder, string path, string header, string interval = "5000")
        {
            var directory = new DirectoryInfo(path);
            IEnumerable <string> files;

            try
            {
                files = directory.GetFiles().Select(f => f.Name);
            }
            catch (Exception ex)
            {
                MonitorLog.WriteLog("Ошибка выполнения CarouselViewModel : " + ex.Message, MonitorLog.typelog.Error, true);
                files = new string[1];
            }
            Header = header;
            Files  = files.Select(f => new NodeViewModel {
                Path = folder + f, Description = ""
            });
            Folder   = folder;
            Interval = interval;

            CarouselId = Guid.NewGuid().ToString();
        }
Пример #12
0
        public static YandexUserModel GetUser(HttpRequestBase request)
        {
            var model = new YandexUserModel {
                IsAutharization = false
            };

            try
            {
                var userCookie = request.Cookies["yandex_token"];
                if (userCookie != null)
                {
                    var stream = HttpTools.PostStream(InfoUrl, string.Format("oauth_token={0}", userCookie.Value));
                    model = SerializeTools.Deserialize <YandexUserModel>(stream);
                    model.IsAutharization = true;
                }
            }
            catch (Exception ex)
            {
                MonitorLog.WriteLog(ex.InnerException + ex.Message, MonitorLog.typelog.Error, true);
                model.IsAutharization = false;
            }

            return(model);
        }
Пример #13
0
        /// <summary>
        /// Получить ИД предыдущего сообщения
        /// </summary>
        /// <typeparam name="T">Тип сообщения</typeparam>
        /// <param name="messageId">ИД сообщения</param>
        /// <returns></returns>
        public int GetPrevMessageId <T>(int messageId) where T : Entity.Entity
        {
            List <int> result;

            using (var session = Factory.OpenSession())
            {
                try
                {
                    result = (List <int>)session.QueryOver <T>()
                             .Where(p => p.Id < messageId)
                             .Select(p => p.Id)
                             .OrderBy(p => p.Id).Desc
                             .Take(1)
                             .List <int>();
                }
                catch (Exception ex)
                {
                    MonitorLog.WriteLog("Ошибка выполнения процедуры GetPrevMessageId : " + ex.Message,
                                        MonitorLog.typelog.Error, true);
                    throw;
                }
            }
            return(!result.Any() ? 0 : result.First());
        }