Inheritance: IdentifiedEntity
Beispiel #1
0
        private void initDataMenuItem_Click(object sender, EventArgs e)
        {
            Log("Инициализация данных");

            using (var session = sessionProvider.OpenSession())
            using (var transaction = session.BeginTransaction())
            {
                Log("Инициализация конфигурации");

                int maxPatch = SchemeState.Patches.Max(x => x.Key);

                var schemeConfig = session.Get<SchemeConfig>(ConfigType.Scheme);
                if (schemeConfig == null)
                {
                    schemeConfig = new SchemeConfig()
                    {
                        Version = maxPatch
                    };
                    session.Save(schemeConfig);
                }

                var defaultConfig = session.Get<DefaultConfig>(ConfigType.Default);
                if (defaultConfig == null)
                {
                    defaultConfig = new DefaultConfig()
                    {
                        QueueName = "Электронная очередь",
                        WorkStartTime = new TimeSpan(10, 0, 0),
                        WorkFinishTime = new TimeSpan(18, 0, 0),
                        MaxClientRequests = 100,
                        MaxRenderingTime = 90
                    };
                    session.Save(defaultConfig);
                }

                var designConfig = session.Get<DesignConfig>(ConfigType.Design);
                if (designConfig == null)
                {
                    designConfig = new DesignConfig();
                    designConfig.LogoSmall = new byte[] { };
                    session.Save(designConfig);
                }

                var couponConfig = session.Get<CouponConfig>(ConfigType.Coupon);
                if (couponConfig == null)
                {
                    couponConfig = new CouponConfig()
                    {
                        Sections = CouponSection.RequestDate
                        | CouponSection.RequestTime
                        | CouponSection.Objects
                        | CouponSection.Position
                        | CouponSection.WaitingTime
                        | CouponSection.Client
                        | CouponSection.Workplaces
                        | CouponSection.Service
                    };
                    session.Save(couponConfig);
                }

                var SMTPConfig = session.Get<SMTPConfig>(ConfigType.SMTP);
                if (SMTPConfig == null)
                {
                    SMTPConfig = new SMTPConfig()
                    {
                        Server = "smtp.junte.ru",
                        User = "******",
                        Password = string.Empty,
                        From = "*****@*****.**"
                    };
                    session.Save(SMTPConfig);
                }

                var portalConfig = session.Get<PortalConfig>(ConfigType.Portal);
                if (portalConfig == null)
                {
                    portalConfig = new PortalConfig()
                    {
                        CurrentDayRecording = true
                    };
                    session.Save(portalConfig);
                }

                var mediaConfig = session.Get<MediaConfig>(ConfigType.Media);
                if (mediaConfig == null)
                {
                    mediaConfig = new MediaConfig()
                    {
                        ServiceUrl = "http://queue:4507/",
                        Ticker = "Добро пожаловать! Вы для нас очень важны!",
                        TickerSpeed = 5
                    };
                    session.Save(mediaConfig);

                    var mediaConfigFile = new MediaConfigFile()
                    {
                        Name = "Демонстрационый файл (файл не загружен)"
                    };
                    session.Save(mediaConfigFile);
                }

                var terminalConfig = session.Get<TerminalConfig>(ConfigType.Terminal);
                if (terminalConfig == null)
                {
                    terminalConfig = new TerminalConfig()
                    {
                        PIN = 1001,
                        CurrentDayRecording = true,
                        Columns = 2,
                        Rows = 5
                    };
                    session.Save(terminalConfig);
                }

                var notificationConfig = session.Get<NotificationConfig>(ConfigType.Notification);
                if (notificationConfig == null)
                {
                    notificationConfig = new NotificationConfig()
                    {
                        ClientRequestsLength = 5
                    };
                    session.Save(notificationConfig);
                }

                Log("Инициализация пользователей");

                Administrator user = session.CreateCriteria<Administrator>()
                    .Add(Restrictions.Eq("Surname", "Администратор"))
                    .SetMaxResults(1)
                    .UniqueResult<Administrator>();
                if (user == null)
                {
                    session.Save(new Administrator()
                    {
                        IsActive = true,
                        Surname = "Администратор",
                        SessionId = Guid.NewGuid(),
                        Permissions = AdministratorPermissions.Config
                            | AdministratorPermissions.Clients
                            | AdministratorPermissions.ClientsRequests
                            | AdministratorPermissions.Users
                            | AdministratorPermissions.DefaultSchedule
                            | AdministratorPermissions.Workplaces
                            | AdministratorPermissions.Services
                            | AdministratorPermissions.CurrentSchedule
                            | AdministratorPermissions.QueuePlan
                            | AdministratorPermissions.Reports
                            | AdministratorPermissions.Offices
                            | AdministratorPermissions.AdditionalServices
                            | AdministratorPermissions.OperatorInterruptions
                            | AdministratorPermissions.LifeSituations
                    });
                }

                user = session.CreateCriteria<Administrator>()
                    .Add(Restrictions.Eq("Surname", "Терминал записи"))
                    .SetMaxResults(1)
                    .UniqueResult<Administrator>();
                if (user == null)
                {
                    session.Save(new Administrator()
                    {
                        IsActive = true,
                        Surname = "Терминал записи",
                        SessionId = Guid.NewGuid(),
                        Permissions = AdministratorPermissions.Clients
                            | AdministratorPermissions.ClientsRequests
                    });
                }

                user = session.CreateCriteria<Administrator>()
                    .Add(Restrictions.Eq("Surname", "Портал"))
                    .SetMaxResults(1)
                    .UniqueResult<Administrator>();
                if (user == null)
                {
                    session.Save(new Administrator()
                    {
                        IsActive = true,
                        Surname = "Портал",
                        SessionId = Guid.NewGuid(),
                        Permissions = AdministratorPermissions.Clients
                            | AdministratorPermissions.ClientsRequests
                    });
                }

                user = session.CreateCriteria<Administrator>()
                    .Add(Restrictions.Eq("Surname", "Медиа-служба"))
                    .SetMaxResults(1)
                    .UniqueResult<Administrator>();
                if (user == null)
                {
                    session.Save(new Administrator()
                    {
                        IsActive = true,
                        Surname = "Медиа-служба",
                        SessionId = Guid.NewGuid()
                    });
                }

                user = session.CreateCriteria<Administrator>()
                    .Add(Restrictions.Eq("Surname", "Метрики"))
                    .SetMaxResults(1)
                    .UniqueResult<Administrator>();
                if (user == null)
                {
                    session.Save(new Administrator()
                    {
                        IsActive = true,
                        Surname = "Метрики",
                        SessionId = Guid.NewGuid()
                    });
                }

                Log("Инициализация расписания по уполчанию");

                foreach (var d in new[] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday,
                        DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday })
                {
                    var s = session.CreateCriteria<DefaultWeekdaySchedule>()
                        .Add(Restrictions.Eq("DayOfWeek", d))
                        .UniqueResult<DefaultWeekdaySchedule>();
                    if (s == null)
                    {
                        session.Save(new DefaultWeekdaySchedule()
                        {
                            DayOfWeek = d,
                            IsWorked = true,
                            LiveClientInterval = TimeSpan.FromMinutes(10),
                            EarlyClientInterval = TimeSpan.FromMinutes(10),
                            StartTime = new TimeSpan(9, 0, 0),
                            FinishTime = new TimeSpan(23, 0, 0),
                            MaxClientRequests = 10,
                            RenderingMode = ServiceRenderingMode.AllRequests,
                            EarlyStartTime = new TimeSpan(9, 0, 0),
                            EarlyFinishTime = new TimeSpan(23, 0, 0),
                            EarlyReservation = 50
                        });
                    }
                }

                transaction.Commit();
            }

            Log("Данные инициализированы");
        }
Beispiel #2
0
        public async Task<DTO.MediaConfigFile> EditMediaConfigFile(DTO.MediaConfigFile source)
        {
            return await Task.Run(() =>
            {
                CheckPermission(UserRole.Administrator, AdministratorPermissions.Config);

                using (var session = SessionProvider.OpenSession())
                using (var transaction = session.BeginTransaction())
                {
                    MediaConfigFile mediaConfigFile;

                    if (!source.Empty())
                    {
                        var mediaConfigFileId = source.Id;
                        mediaConfigFile = session.Get<MediaConfigFile>(mediaConfigFileId);
                        if (mediaConfigFile == null)
                        {
                            throw new FaultException<ObjectNotFoundFault>(new ObjectNotFoundFault(mediaConfigFileId), string.Format("Медиафайл [{0}] не найден", mediaConfigFileId));
                        }
                    }
                    else
                    {
                        mediaConfigFile = new MediaConfigFile();
                    }

                    mediaConfigFile.Name = source.Name;

                    var errors = mediaConfigFile.Validate();
                    if (errors.Length > 0)
                    {
                        throw new FaultException(errors.First().Message);
                    }

                    session.Save(mediaConfigFile);
                    transaction.Commit();

                    return Mapper.Map<MediaConfigFile, DTO.MediaConfigFile>(mediaConfigFile);
                }
            });
        }