コード例 #1
0
ファイル: DbController.cs プロジェクト: QuantumArt/QP
        public FileResult GetRecordedUserActions()
        {
            var fileName = $"{QPContext.CurrentCustomerCode}.xml";
            var stream   = System.IO.File.Open(QPContext.GetRecordXmlFilePath(), FileMode.Open);

            return(File(stream, MediaTypeNames.Application.Octet, fileName));
        }
コード例 #2
0
        /// <summary>
        /// Проверяет текст запроса на корректность
        /// </summary>
        internal static bool IsQueryQueryCorrect(string userQuery, out string errorMessage)
        {
            errorMessage = null;
            using (QPConfiguration.OutOfTransaction())
            {
                try
                {
                    var viewName          = $"uq_v_test_{DateTime.Now.Ticks}";
                    var schema            = SqlQuerySyntaxHelper.DbSchemaName(QPContext.DatabaseType);
                    var createTestViewSql = $"CREATE VIEW {schema}.{viewName} AS {userQuery}";
                    using (var connect = QPContext.CreateDbConnection())
                    {
                        connect.Open();
                        Common.ExecuteSql(connect, createTestViewSql);
                        Common.DropView(connect, viewName);
                    }

                    return(true);
                }
                catch (SqlException ex)
                {
                    errorMessage = ex.ErrorsToString();
                    return(false);
                }
                catch (NpgsqlException ex)
                {
                    errorMessage = ex.Message;
                    return(false);
                }
            }
        }
コード例 #3
0
ファイル: StatusTypeRepository.cs プロジェクト: QuantumArt/QP
        /// <summary>
        /// Возвращает список по ids
        /// </summary>
        /// <returns></returns>
        internal static IEnumerable <StatusType> GetList(IEnumerable <int> IDs)
        {
            var result = new List <StatusType>();
            var cache  = QPContext.GetStatusTypeCache();

            if (cache != null)
            {
                foreach (var id in IDs)
                {
                    if (cache.ContainsKey(id))
                    {
                        result.Add(cache[id]);
                    }
                    else
                    {
                        result.Add(GetRealById(id));
                    }
                }
            }
            else
            {
                IEnumerable <decimal> decIDs = Converter.ToDecimalCollection(IDs).Distinct().ToArray();
                result = MapperFacade.StatusTypeMapper
                         .GetBizList(QPContext.EFContext.StatusTypeSet
                                     .Where(f => decIDs.Contains(f.Id))
                                     .ToList()
                                     );
            }

            return(result);
        }
コード例 #4
0
ファイル: Global.asax.cs プロジェクト: AuthorProxy/QP
        internal static void RegisterUnity()
        {
            var resolver = new UnityDependencyResolver();

            DependencyResolver.SetResolver(resolver);
            QPContext.SetUnityContainer(resolver.UnityContainer);
            GlobalHost.DependencyResolver = new SignalRUnityDependencyResolver(resolver.UnityContainer);
        }
コード例 #5
0
        private static void RemoveRecordsXml()
        {
            var path = QPContext.GetRecordXmlFilePath();

            if (File.Exists(path))
            {
                File.SetAttributes(path, FileAttributes.Normal);
                File.Delete(path);
            }
        }
コード例 #6
0
ファイル: DbController.cs プロジェクト: QuantumArt/QP
        public async Task <ActionResult> Settings(string tabId, int parentId, string successfulActionCode)
        {
            var db    = DbService.ReadSettings();
            var model = EntityViewModel.Create <DbViewModel>(db, tabId, parentId);

            model.SuccesfulActionCode = successfulActionCode;

            ViewBag.IsRecordAvailableForDownload = System.IO.File.Exists(QPContext.GetRecordXmlFilePath());
            return(await JsonHtml("Settings", model));
        }
コード例 #7
0
ファイル: StatusTypeRepository.cs プロジェクト: QuantumArt/QP
        internal static StatusType GetByIdFromCache(int id)
        {
            StatusType result = null;
            var        cache  = QPContext.GetStatusTypeCache();

            if (cache != null && cache.ContainsKey(id))
            {
                result = cache[id];
            }
            return(result);
        }
コード例 #8
0
        public ActionResult LogOut(DirectLinkOptions directLinkOptions)
        {
            var loginUrl = QPContext.LogOut();

            if (directLinkOptions != null)
            {
                loginUrl = directLinkOptions.AddToUrl(loginUrl);
            }

            return(Redirect(loginUrl));
        }
コード例 #9
0
ファイル: Startup.cs プロジェクト: QuantumArt/QP
        public void Configure(IApplicationBuilder app, IServiceProvider provider, IWebHostEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(new GlobalExceptionHandler().Action);
            }

            app.UseStaticFiles(new StaticFileOptions
            {
                FileProvider = new PhysicalFileProvider(Path.Combine(
                                                            AppDomain.CurrentDomain.BaseDirectory,
                                                            "Scripts")),
                RequestPath = "/Scripts"
            });
            app.UseStaticFiles(new StaticFileOptions
            {
                FileProvider = new PhysicalFileProvider(Path.Combine(
                                                            AppDomain.CurrentDomain.BaseDirectory,
                                                            "Static")),
                RequestPath = "/Static"
            });

            app.UseStaticFiles(new StaticFileOptions
            {
                FileProvider = new PhysicalFileProvider(Path.Combine(
                                                            AppDomain.CurrentDomain.BaseDirectory,
                                                            "plugins")),
                RequestPath = "/plugins"
            });

            app.UseForwardedHeaders();
            app.UseAuthentication();
            QPContext.SetServiceProvider(provider);
            RegisterMappings();

            app.Use(async(context, next) =>
            {
                var claim       = context.User.FindFirst("CultureName");
                var cultureName = claim != null ? claim.Value : QPConfiguration.Options.Globalization.DefaultCulture;
                var cultureInfo = new CultureInfo(cultureName);
                CultureInfo.CurrentUICulture = cultureInfo;
                CultureInfo.CurrentCulture   = cultureInfo;

                await next.Invoke();
            });

            app.UseSession();

            app.UseMvc(RegisterRoutes);
        }
コード例 #10
0
ファイル: UserRepository.cs プロジェクト: AuthorProxy/QP
        internal static User GetByIdFromCache(int id)
        {
            User result = null;
            var  cache  = QPContext.GetUserCache();

            if (cache != null && cache.ContainsKey(id))
            {
                result = cache[id];
            }

            return(result);
        }
コード例 #11
0
ファイル: FieldRepository.cs プロジェクト: QuantumArt/QP
        private static Field GetByIdFromCache(int fieldId)
        {
            Field result = null;
            var   cache  = QPContext.GetFieldCache();

            if (cache != null && cache.ContainsKey(fieldId))
            {
                result = cache[fieldId];
            }

            return(result);
        }
コード例 #12
0
ファイル: ContentRepository.cs プロジェクト: AuthorProxy/QP
        private static Content GetByIdFromCache(int id)
        {
            Content result = null;
            var     cache  = QPContext.GetContentCache();

            if (cache != null && cache.ContainsKey(id))
            {
                result = cache[id];
            }

            return(result);
        }
コード例 #13
0
ファイル: UserRepository.cs プロジェクト: AuthorProxy/QP
        /// <summary>
        /// Возвращает список по ids
        /// </summary>
        internal static IEnumerable <User> GetList(IEnumerable <int> ids)
        {
            var result = new List <User>();
            var cache  = QPContext.GetUserCache();

            if (cache != null)
            {
                result.AddRange(ids.Select(id => cache.ContainsKey(id) ? cache[id] : GetRealById(id)));
            }
            else
            {
                IEnumerable <decimal> decIDs = Converter.ToDecimalCollection(ids).Distinct().ToArray();
                result = MapperFacade.UserMapper.GetBizList(QPContext.EFContext.UserSet.Where(f => decIDs.Contains(f.Id)).ToList());
            }

            return(result);
        }
コード例 #14
0
        internal static void ErasePreviouslyRecordedActions(string backendUrl, string currentDbVersion)
        {
            RemoveRecordsXml();
            var root = GetOrCreateRoot(backendUrl, currentDbVersion);
            var doc  = root.Document;

            if (doc != null)
            {
                if (root.HasElements)
                {
                    root.Remove();
                    doc.Add(CreateActionsRoot(backendUrl, currentDbVersion));
                }

                doc.Save(QPContext.GetRecordXmlFilePath());
            }
        }
コード例 #15
0
ファイル: FieldRepository.cs プロジェクト: QuantumArt/QP
        private static List <Field> GetListFromCache(int contentId)
        {
            IList <Field> result = null;
            var           cache  = QPContext.GetFieldCache();
            var           cache2 = QPContext.GetContentFieldCache();

            if (cache != null && cache2 != null && cache2.ContainsKey(contentId))
            {
                var fieldIds     = cache2[contentId];
                var tempFieldIds = fieldIds.Select(n => cache.ContainsKey(n) ? cache[n] : null).ToList();
                if (tempFieldIds.All(n => n != null))
                {
                    result = tempFieldIds;
                }
            }

            return(result?.ToList());
        }
コード例 #16
0
ファイル: RecordAttribute.cs プロジェクト: AuthorProxy/QP
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            try
            {
                var isValid = filterContext.Exception == null && filterContext.Controller.ViewData.ModelState.IsValid && !QPController.IsError(filterContext.HttpContext);
                if (isValid && DbRepository.Get().RecordActions)
                {
                    var currentDbVersion  = new ApplicationInfoRepository().GetCurrentDbVersion();
                    var actionToSerialize = XmlDbUpdateHttpContextHelpers.CreateXmlDbUpdateActionFromHttpContext(filterContext.HttpContext, _code ?? BackendActionContext.Current.ActionCode, _ignoreForm);
                    XmlDbUpdateSerializerHelpers
                    .SerializeAction(actionToSerialize, currentDbVersion, CommonHelpers.GetBackendUrl(filterContext.HttpContext))
                    .Save(QPContext.GetRecordXmlFilePath(), SaveOptions.None);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("There was an error while recording xml actions", ex);
            }

            base.OnActionExecuted(filterContext);
        }
コード例 #17
0
ファイル: DbController.cs プロジェクト: AuthorProxy/QP
        public FileResult GetRecordedUserActions()
        {
            var fileName = $"{QPContext.CurrentCustomerCode}_{System.IO.File.GetLastWriteTime(QPContext.GetRecordXmlFilePath()):yyyy-MM-dd_HH-mm-ss}.xml";

            return(File(QPContext.GetRecordXmlFilePath(), MediaTypeNames.Application.Octet, fileName));
        }
コード例 #18
0
        private static XElement GetOrCreateRoot(string backendUrl, string currentDbVersion)
        {
            var doc = File.Exists(QPContext.GetRecordXmlFilePath()) ? XDocument.Load(QPContext.GetRecordXmlFilePath()) : new XDocument(CreateActionsRoot(backendUrl, currentDbVersion));

            return(doc.Elements(XmlDbUpdateXDocumentConstants.RootElement).Single());
        }
コード例 #19
0
 public ActionResult LogOut(DirectLinkOptions directLinkOptions)
 {
     QPContext.LogOut();
     return(RedirectToAction("Index"));
 }