public ApiOutputModel DeleteAll(Guid appId)
        {
            var app = new ApplicationProcessor(Path.GetDirectoryName(_repositoryPath)).Get(appId);

            if (app == null)
            {
                return new ApiOutputModel {
                           Result = EnumSpProcessorCallResult.SourceNotFound
                }
            }
            ;

            using (var db = new LiteDatabase(_repositoryPath))
            {
                var lQue = db.GetCollection <QueryModel>(TableName);

                lQue.Delete(x => x.ApplicationId == appId);
                db.Shrink();
            }

            return(new ApiOutputModel {
                Result = EnumSpProcessorCallResult.Success
            });
        }

        #endregion PUBLIC
    }
        public ApiOutputModel Update(Guid appId, Guid id, QueryModel data)
        {
            if (data == null)
            {
                return new ApiOutputModel {
                           Result = EnumSpProcessorCallResult.InvalidSuppliedData
                }
            }
            ;

            var app = new ApplicationProcessor(Path.GetDirectoryName(_repositoryPath)).Get(appId);

            if (app == null)
            {
                return new ApiOutputModel {
                           Result = EnumSpProcessorCallResult.SourceNotFound
                }
            }
            ;

            if (GetByName(app.Name, data.Name) != null)
            {
                return new ApiOutputModel {
                           Result = EnumSpProcessorCallResult.DataConflict
                }
            }
            ;

            data.Id            = id;
            data.ApplicationId = appId;

            // make sure we not lost any old data fields
            var oldData = Get(appId, id);

            if (oldData == null)
            {
                return new ApiOutputModel {
                           Result = EnumSpProcessorCallResult.SourceNotFound
                }
            }
            ;

            data.Name  = data.Name ?? oldData.Name;
            data.Query = data.Query ?? oldData.Query;

            using (var db = new LiteDatabase(_repositoryPath))
            {
                var lQue = db.GetCollection <QueryModel>(TableName);

                lQue.Update(data);
            }

            return(new ApiOutputModel {
                Result = EnumSpProcessorCallResult.Success, Supplement = data
            });
        }
        public QueryModel GetByName(string appName, string queryName)
        {
            QueryModel lQue;
            var        app = new ApplicationProcessor(_repositoryPath).GetByName(appName);

            using (var db = new LiteDatabase(_repositoryPath))
            {
                lQue = db
                       .GetCollection <QueryModel>(TableName)
                       .FindOne(x => x.ApplicationId == app.Id && x.Name == queryName);
            }

            return(lQue);
        }
        public SpExecutor(string repositoryPath)
        {
            if (repositoryPath.IsNullOrEmpty())
            {
                throw new Exception("RepositoryPath is not defined.");
            }

            if (!Directory.Exists(repositoryPath))
            {
                Directory.CreateDirectory(repositoryPath);
            }

            repositoryPath = Path.Combine(repositoryPath, "SPStorage.DB");

            _appProcessor   = new ApplicationProcessor(repositoryPath);
            _queryProcessor = new QueryProcessor(repositoryPath);
        }
        public ApiOutputModel Insert(Guid appId, QueryModel data)
        {
            if (data == null)
            {
                return new ApiOutputModel {
                           Result = EnumSpProcessorCallResult.InvalidSuppliedData
                }
            }
            ;

            var app = new ApplicationProcessor(Path.GetDirectoryName(_repositoryPath)).Get(appId);

            if (app == null)
            {
                return new ApiOutputModel {
                           Result = EnumSpProcessorCallResult.SourceNotFound
                }
            }
            ;

            if (GetByName(app.Name, data.Name) != null)
            {
                return new ApiOutputModel {
                           Result = EnumSpProcessorCallResult.DataConflict
                }
            }
            ;

            using (var db = new LiteDatabase(_repositoryPath))
            {
                var lQue = db.GetCollection <QueryModel>(TableName);

                data.Id            = new Guid();
                data.ApplicationId = appId;

                lQue.Insert(data);
                DoIndexing(lQue);
            }

            return(new ApiOutputModel {
                Result = EnumSpProcessorCallResult.Success, Supplement = data
            });
        }