private void PostData(IInputData input) { DataSet postDataSet = input.PostObject.Convert <DataSet>(); FieldErrorInfoCollection errors = new FieldErrorInfoCollection(); MetaDataTableResolver metaResolver = MainResolver as MetaDataTableResolver; if (metaResolver != null) { metaResolver.CheckFirstConstraints(input, errors); } switch (input.Style.Style) { case PageStyle.Insert: MainResolver.Insert(postDataSet, input); break; case PageStyle.Update: MainResolver.Update(postDataSet, input); break; } if (metaResolver != null) { metaResolver.CheckLaterConstraints(input, errors); } errors.CheckError(); }
public void TestSearch(string url) { var audioItem = MainResolver.ResolveQuery(url).GetAwaiter().GetResult(); Assert.NotNull(audioItem); Assert.IsType <YandexMusicSearchResult>(audioItem); }
private void MakeOperateRight(IInputData input) { IEnumerable <Operator> listOpertors = null; var operateRight = Operators.Right.CreateObject(); if (operateRight == null) { var allOpertors = Operators.Operators; if (allOpertors != null) { listOpertors = from item in allOpertors select new Operator(item, this, input, MainResolver.GetKeyFieldArray()); } } else { IEnumerable <string> rights = operateRight.GetOperator( new OperateRightEventArgs(input.Style, input.SourceInfo.Source, MainResolver.HostTable.Rows[0])); var allOpertors = Operators.Operators; if (rights != null && allOpertors != null) { listOpertors = from item in allOpertors join right in rights on item.Id equals right select new Operator(item, this, input, MainResolver.GetKeyFieldArray()); } } if (listOpertors != null) { DataTable table = listOpertors.CreateTable("DetailOperator"); if (table != null) { DataSet.Tables.Add(table); } } }
protected virtual void PreparePostObject(IInputData input) { DataSet postDataSet = input.PostObject.Convert <DataSet>(); MainResolver.PrepareDataSet(postDataSet); OnPreparedPostObject(new PreparePostObjectEventArgs(input)); }
public void SetMetaData(IPageStyle style, IMetaData metaData) { MainResolver.ReadMetaData(metaData.GetTableScheme(MainResolver.TableName)); foreach (var resolver in fDetailResolvers) { resolver.Item1.ReadMetaData(metaData.GetTableScheme(resolver.Item1.TableName)); } }
protected virtual void FillInsertTables() { MainResolver.SelectTableStructure(); foreach (var item in ChildTables) { item.Resolver.SelectTableStructure(); } }
protected virtual void FillUpdateTables(IInputData input) { if (!FillingUpdateArgs.Handled.IsHandled(MainResolver)) { FillUpdateTables(MainResolver, input); if (input.Style.Style != PageStyle.Delete && !input.IsPost) { MainResolver.AddVirtualFields(); } } }
private KeyData DoDeleteAction(IInputData input) { DefaultUpdateAction(input); DataRow row = MainRow; KeyData result = MainResolver.CreateKeyData(row); MainResolver.Delete(input); Commit(input); return(result); }
public void GetTrack(string url) { var audioItem = MainResolver.ResolveQuery(url).GetAwaiter().GetResult(); Assert.NotNull(audioItem); Assert.False(audioItem.IsSearchResult); Assert.NotNull(audioItem.Tracks); Assert.Null(audioItem.Playlists); Assert.Null(audioItem.Albums); Assert.NotEmpty(audioItem.Tracks); Assert.Equal(YandexSearchType.Track, YandexSearchType.Track); }
public virtual void SetMetaData(IPageStyle style, IMetaData metaData) { if (TestPageStyleForMetaData(style)) { ITableSchemeEx scheme = metaData.GetTableScheme(MainResolver.TableName); if (scheme != null) { MainResolver.ReadMetaData(scheme); OnReadMetaData(MainResolver, style, scheme); } } }
protected virtual void PreparePostObject(IInputData input) { DataSet postDataSet = input.PostObject.Convert <DataSet>(); MainResolver.PrepareDataSet(postDataSet); foreach (var item in ChildTables) { item.Resolver.PrepareDataSet(postDataSet); item.SetRelationFieldValue(MainResolver); } OnPreparedPostObject(new PreparePostObjectEventArgs(input)); }
protected override void Dispose(bool disposing) { if (disposing) { MainResolver.Dispose(); foreach (var item in fDetailResolvers) { item.Item1.Dispose(); } } base.Dispose(disposing); }
private void PostData(IInputData input) { DataSet postDataSet = input.PostObject.Convert <DataSet>(); FieldErrorInfoCollection errors = new FieldErrorInfoCollection(); var childResolvers = ChildResolvers.ToArray(); MetaDataTableResolver metaResolver = MainResolver as MetaDataTableResolver; if (metaResolver != null) { metaResolver.CheckFirstConstraints(input, errors); } foreach (var item in childResolvers) { MetaDataTableResolver childResolver = item as MetaDataTableResolver; if (childResolver != null) { childResolver.CheckFirstConstraints(input, errors); } } switch (input.Style.Style) { case PageStyle.Insert: MainResolver.Insert(postDataSet, input); foreach (var item in childResolvers) { item.Insert(postDataSet, input); } break; case PageStyle.Update: MainResolver.Update(postDataSet, input); foreach (var item in childResolvers) { item.Update(postDataSet, input); } break; } if (metaResolver != null) { metaResolver.CheckLaterConstraints(input, errors); } foreach (var item in childResolvers) { MetaDataTableResolver childResolver = item as MetaDataTableResolver; if (childResolver != null) { childResolver.CheckLaterConstraints(input, errors); } } errors.CheckError(); }
private ParamBuilderContainer CreateListCondition(IInputData input) { ParamBuilderContainer condition = new ParamBuilderContainer(); condition.Add(MainResolver.CreateFixCondition()); condition.Add(CreateCustomCondition(input)); condition.Add(GetDataRight(input)); if (FilterSql != null) { string sql = Expression.Execute(FilterSql, this); condition.Add(sql); } return(condition); }
protected void DoInsertAction(IInputData input) { DataTable table = MainResolver.CreateVirtualTable(); DataRow row = table.NewRow(); table.Rows.Add(row); MainResolver.SetDefaultValue(input.QueryString); MainResolver.SetDefaultValue(row); MetaDataTableResolver metaResolver = MainResolver as MetaDataTableResolver; if (metaResolver != null) { metaResolver.FillCodeTable(input.Style); metaResolver.Decode(input.Style); } }
private void CreateRowOperators(IInputData input, IOperateRight operateRight, IEnumerable <OperatorConfig> allOperators) { var rowOperators = from item in allOperators where item.Position == OperatorPosition.Row select new Operator(item, this, input, MainResolver.GetKeyFieldArray()); DataTable operTable = rowOperators.CreateTable("RowOperator"); if (operTable == null) { return; } DataSet.Tables.Add(operTable); string rightStr = string.Empty; if (operateRight == null) { var rowRights = from item in rowOperators select item.Id; rightStr = string.Format(ObjectUtil.SysCulture, "|{0}|", string.Join("|", rowRights)); } DataTable table = DataSet.Tables[FillTableName]; DataColumn operatorColumn = table.Columns.Add("_OPERATOR_RIGHT"); foreach (DataRow row in table.Rows) { if (operateRight == null) { row[operatorColumn] = rightStr; } else { var args = new OperateRightEventArgs(input.Style, input.SourceInfo.Source, row); IEnumerable <string> rights = operateRight.GetOperator(args); if (rights != null) { rightStr = string.Join("|", rights); if (!string.IsNullOrEmpty(rightStr)) { row[operatorColumn] = "|" + rightStr + "|"; } } } } }
public override OutputData DoAction(IInputData input) { if (input.IsPost) { FillData(input); Prepare(); DataSet postDataSet = input.PostObject.Convert <DataSet>(); MainResolver.Update(postDataSet, input); Commit(input); return(OutputData.CreateToolkitObject(new KeyData("Id", string.Empty))); } else { throw new NotSupportedException(); } }
protected virtual void FillData(IInputData input) { ParamBuilderContainer container = new ParamBuilderContainer(); container.Add(GetDataRight(input)); if (FilterSql != null) { string sql = Expression.Execute(FilterSql, this); container.Add(sql); } if (container.IsEmpty) { MainResolver.Select(); } else { MainResolver.Select(container); } }
protected virtual OutputData DoPost(IInputData input) { MainResolver.PrepareDataSet(input.PostObject.Convert <DataSet>()); switch (input.Style.Style) { case PageStyle.Update: DefaultUpdateAction(input); break; default: TkDebug.ThrowImpossibleCode(this); break; } PostData(input); Commit(input); return(OutputData.CreateToolkitObject(KeyData.Empty)); }
protected void DoInsertAction(IInputData input) { DataTable table = MainResolver.CreateVirtualTable(); DataRow row = NewTableRow(table); MainResolver.SetDefaultValue(input.QueryString); MainResolver.SetDefaultValue(row); DecodeResolver(input, MainResolver); foreach (var item in fDetailResolvers) { TableResolver resolver = item.Item1; table = resolver.CreateVirtualTable(); if (!item.Item2) { row = NewTableRow(table); resolver.SetDefaultValue(row); } DecodeResolver(input, resolver); } }
protected virtual void CreateListOperators(IInputData input, ref IOperateRight operateRight) { if (Operators != null) { IEnumerable <Operator> listOpertors = null; operateRight = Operators.Right.CreateObject(); if (operateRight == null) { var allOpertors = Operators.Operators; if (allOpertors != null) { listOpertors = from item in allOpertors where item.Position == OperatorPosition.Global select new Operator(item, this, input, MainResolver.GetKeyFieldArray()); } } else { IEnumerable <string> rights = operateRight.GetOperator( new OperateRightEventArgs(input.Style, input.SourceInfo.Source, null)); var allOpertors = Operators.Operators; if (rights != null && allOpertors != null) { listOpertors = from item in allOpertors join right in rights on item.Id equals right where item.Position == OperatorPosition.Global select new Operator(item, this, input, MainResolver.GetKeyFieldArray()); } } if (listOpertors != null) { DataTable table = listOpertors.CreateTable("ListOperator"); if (table != null) { DataSet.Tables.Add(table); } } } }
private string CreateStatSql() { StringBuilder sql = new StringBuilder("SELECT "); bool appendBefore = false; bool subAfter = false; for (int i = 0; i < fStatFields.Count; ++i) { StatFieldConfigItem field = fStatFields[i]; string nickName = field.NickName; string fieldName = Context.EscapeName(MainResolver.GetFieldInfo(nickName).FieldName); if (appendBefore) { sql.Append(","); } switch (field.Method) { case StatMethod.Count: appendBefore = false; subAfter = true; break; default: sql.AppendFormat("{0}({1}) {2}", field.Method, fieldName, nickName); appendBefore = true; subAfter = false; break; } } if (subAfter) { sql = sql.Remove(sql.Length - 1, 1); } sql.Append(" FROM ").Append(GetTableName(Context)); return(sql.ToString()); }
private OutputData DoPost(IInputData input) { PreparePostObject(input); switch (input.Style.Style) { case PageStyle.Insert: DefaultInsertAction(input); break; case PageStyle.Update: DefaultUpdateAction(input); break; default: TkDebug.ThrowImpossibleCode(this); break; } PostData(input); Commit(input); return(OutputData.CreateToolkitObject(MainResolver.CreateKeyData())); }
public virtual void SetMetaData(IPageStyle style, IMetaData metaData) { ITableSchemeEx scheme; if (TestPageStyleForMetaData(style)) { scheme = metaData.GetTableScheme(MainResolver.TableName); if (scheme != null) { MainResolver.ReadMetaData(scheme); OnReadMetaData(MainResolver, style, scheme); } foreach (var childTable in ChildTables) { scheme = metaData.GetTableScheme(childTable.Resolver.TableName); if (scheme != null) { childTable.Resolver.ReadMetaData(scheme); OnReadMetaData(childTable.Resolver, style, scheme); } } } }
public static void EmbedResource(string assemblyToEmbedTo, string resourceName, Stream streamToEmbed, string hash = null, CompressionMethod compression = CompressionMethod.Auto) { if (hash == null) { hash = streamToEmbed.GetHash(); } double previousTime = GetTime(); while (GetTime() - previousTime <= 10.0) { try { using (var resolver = new MainResolver()) { using (var definition = AssemblyDefinition.ReadAssembly(assemblyToEmbedTo, new ReaderParameters { ReadWrite = true, AssemblyResolver = resolver })) { var finding = definition.MainModule.Resources.FirstOrDefault(r => r.Name == resourceName); if (finding != null) { var metaResource = definition.MainModule.Resources.FirstOrDefault(r => r.Name == (resourceName + "_meta")); if (metaResource != null && metaResource is EmbeddedResource) { var embeddedHash = (EmbeddedResource)metaResource; using (var metaStream = embeddedHash.GetResourceStream()) { var meta = ResourceMetaData.FromStream(metaStream); if (meta.hash == hash) { return; } } } definition.MainModule.Resources.Remove(finding); if (metaResource != null) { definition.MainModule.Resources.Remove(metaResource); } } if (compression == CompressionMethod.Auto || compression == CompressionMethod.UseCompression) { using (var compressedStream = new MemoryStream()) { //Console.WriteLine("E"); using (var compressionStream = new GZipStream(compressedStream, CompressionMode.Compress)) { streamToEmbed.CopyToStream(compressionStream); compressedStream.Position = 0; Stream smallestStream = compressedStream; bool actuallyCompressed = true; if (streamToEmbed.Length < compressedStream.Length && compression == CompressionMethod.Auto) { smallestStream = streamToEmbed; actuallyCompressed = false; } var er = new EmbeddedResource(resourceName, ManifestResourceAttributes.Public, smallestStream); definition.MainModule.Resources.Add(er); using (var metaStream = new ResourceMetaData(actuallyCompressed, hash).ToStream()) { var hashResource = new EmbeddedResource(resourceName + "_meta", ManifestResourceAttributes.Public, metaStream); definition.MainModule.Resources.Add(hashResource); definition.MainModule.Write(); } } } } else { var er = new EmbeddedResource(resourceName, ManifestResourceAttributes.Public, streamToEmbed); definition.MainModule.Resources.Add(er); using (var metaStream = new ResourceMetaData(false, hash).ToStream()) { var hashResource = new EmbeddedResource(resourceName + "_meta", ManifestResourceAttributes.Public, metaStream); definition.MainModule.Resources.Add(hashResource); definition.MainModule.Write(); } } } } break; } catch (Exception e) { if (e.Message.Contains("because it is being used by another process")) { continue; } else { throw; } } } if (GetTime() - previousTime > 10.0) { throw new Exception("Embedding Timeout"); } }
protected virtual void FillInsertTables() { MainResolver.SelectTableStructure(); }
protected void FillListDataSet(IInputData input, int pageNumber, int pageSize, int start) { ParamBuilderContainer condition = CreateListCondition(input); IOperateRight operateRight = null; if (TabSheets != null && TabSheets.Count > 0) { var selectedTab = GetSelectTabSheet(input); selectedTab.Selected = true; condition.Add(selectedTab.ParamBuilder); DataSet.Tables.Add(TabSheets.CreateTable("TabSheet")); } if (input.QueryString["GetData"] != "Page" && !input.IsPost) { MainResolver.FillCodeTable(input.Style); CreateListOperators(input, ref operateRight); } ListSortInfo listInfo = new ListSortInfo(input); string orderby = null; if (input.IsPost) { orderby = SetPostListInfo(input, condition, listInfo); } else { orderby = SetGetListInfo(input, condition, listInfo); } CountInfo pageInfo = CreatePageInfo(input, pageNumber, pageSize, condition); DataSet.Tables.Add(EnumUtil.Convert(pageInfo).CreateTable("Count")); DataSet.Tables.Add(EnumUtil.Convert(listInfo).CreateTable("Sort")); if (pageInfo.TotalCount <= 0) { OnFilledListTables(new FilledListEventArgs(input.IsPost, pageNumber, pageSize, pageInfo.TotalCount, orderby, MainResolver, input.PostObject, condition)); return; } int recCount = pageSize * pageNumber + start; string whereSql = condition.IsEmpty ? string.Empty : "WHERE " + condition.Sql; var listContext = FillListTable(MainResolver.ListFields, GetTableName(Context), MainResolver.GetKeyFieldArray(), whereSql, orderby, recCount, pageSize); SqlSelector selector = new SqlSelector(Context, DataSet); using (selector) { ISimpleAdapter adapter = selector; adapter.SetSql(listContext.ListSql, condition); Context.ContextConfig.SetListData(listContext, adapter, DataSet, recCount, pageSize, FillTableName); MainResolver.AddVirtualFields(); if (Operators != null) { if (operateRight == null) { operateRight = Operators.Right.CreateObject(); } var allOperators = Operators.Operators; if (allOperators != null) { CreateRowOperators(input, operateRight, allOperators); } } MainResolver.Decode(input.Style); OnFilledListTables(new FilledListEventArgs(input.IsPost, pageNumber, pageSize, pageInfo.TotalCount, orderby, MainResolver, input.PostObject, condition)); } }
protected virtual string GetTableName(TkDbContext context) { return(MainResolver.GetSqlTableName(context)); }