public override global::System.Data.DataSet Clone() { ClientDataSet cln = ((ClientDataSet)(base.Clone())); cln.InitVars(); cln.SchemaSerializationMode = this.SchemaSerializationMode; return(cln); }
internal static string CreateAvgFunction(string avgExpression, ClientDataSet dataSet) { StringBuilder sb = new StringBuilder("function(v){var s=0;"); sb.AppendFormat("for(var i=0;i<v.{0}.length;i++){{", dataSet); var compiledExpr = Template.CompileExpression(avgExpression, "v", string.Format("{0}[i]", dataSet)); sb.AppendFormat("if ((({0})!=null)&&(({0})!=undefined)) s+=(({0}));}}return ((v.{1}.length==0)?0:(s/(v.{1}.length)));}}", compiledExpr, dataSet); return(sb.ToString()); }
/// <summary> /// Adds client total calculator that produces count of rows /// </summary> /// <param name="conf">Configuration</param> /// <param name="name">Name of field to be added to existing ResponseInfo template model</param> /// <param name="clientDataSet">Client data set to perform calculations on</param> /// <returns></returns> public static PluginConfigurationWrapper <ResponseInfoClientConfiguration> AddClientCount( this PluginConfigurationWrapper <ResponseInfoClientConfiguration> conf, string name, ClientDataSet clientDataSet ) { var function = string.Format("function(v){{ return v.{0}.length; }}", clientDataSet); conf.Configuration.ClientCalculators.Add(name, new JRaw(function)); return(conf); }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs) { ClientDataSet ds = new ClientDataSet(); global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); global::System.Xml.Schema.XmlSchemaAny any = new global::System.Xml.Schema.XmlSchemaAny(); any.Namespace = ds.Namespace; sequence.Items.Add(any); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte()));) { ; } if ((s1.Position == s1.Length)) { return(type); } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return(type); }
/// <summary> /// Adds client total calculator that produces sum amount of supplied row values /// </summary> /// <param name="conf">Configuration</param> /// <param name="name">Name of field to be added to existing ResponseInfo template model</param> /// <param name="sumExpression">`{@}`-syntax expression that will be calculated for each row and summarized</param> /// <param name="clientDataSet">Client data set to perform calculations on</param> /// <returns></returns> public static PluginConfigurationWrapper <ResponseInfoClientConfiguration> AddClientSum( this PluginConfigurationWrapper <ResponseInfoClientConfiguration> conf, string name, string sumExpression, ClientDataSet clientDataSet ) { var function = TotalClientFunctionsExtensions.CreateSumFunction(sumExpression, clientDataSet); conf.Configuration.ClientCalculators.Add(name, new JRaw(function)); return(conf); }
/// <summary> /// Adds client total calculator that produces count of rows that match supplied predicate function /// </summary> /// <param name="conf">Configuration</param> /// <param name="name">Name of field to be added to existing ResponseInfo template model</param> /// <param name="predicate">`{@}`-syntax expression that specifies predicate</param> /// <param name="clientDataSet">Client data set to perform calculations on</param> /// <returns></returns> public static PluginConfigurationWrapper <ResponseInfoClientConfiguration> AddClientCountPredicate( this PluginConfigurationWrapper <ResponseInfoClientConfiguration> conf, string name, string predicate, ClientDataSet clientDataSet ) { var function = TotalClientFunctionsExtensions.CreateSumFunctionWithPredicate("1", predicate, clientDataSet); conf.Configuration.ClientCalculators.Add(name, new JRaw(function)); return(conf); }
/// <summary> /// Adds client total calculator that produces weighted average of supplied row values /// </summary> /// <param name="conf">Configuration</param> /// <param name="name">Name of field to be added to existing ResponseInfo template model</param> /// <param name="avgExpression">`{@}`-syntax expression that will be calculated for each row and averaged</param> /// <param name="weightExpression">`{@}`-syntax expression for weight coefficient</param> /// <param name="clientDataSet">Client data set to perform calculations on</param> /// <returns></returns> public static PluginConfigurationWrapper <ResponseInfoClientConfiguration> AddClientWeightedAverage( this PluginConfigurationWrapper <ResponseInfoClientConfiguration> conf, string name, string avgExpression, string weightExpression, ClientDataSet clientDataSet ) { var function = TotalClientFunctionsExtensions.CreateWeightedAvgFunction(avgExpression, weightExpression, clientDataSet); conf.Configuration.ClientCalculators.Add(name, new JRaw(function)); return(conf); }
/// <summary> /// Adds client total calculator that produces count of rows /// </summary> /// <param name="conf">Configuration</param> /// <param name="column">Table column to provide total with</param> /// <param name="clientDataSet">Client data set to perform calculations on</param> /// <param name="template">Tempalte for total cell</param> /// <returns></returns> public static TotalCalculatorBuilder <TSourceData, TTableData> AddClientCount <TSourceData, TTableData, TTableColumn>( this TotalCalculatorBuilder <TSourceData, TTableData> conf, Expression <Func <TTableData, TTableColumn> > column, ClientDataSet clientDataSet, Action <CellTemplateBuilder> template = null ) where TTableData : new() { var name = LambdaHelpers.ParsePropertyLambda(column).Name; var function = string.Format("function(v){{ return v.{0}.length; }}", clientDataSet); conf.ClientCalculators.Add(name, function); if (template != null) { conf.AddTemplate(column, template); } return(conf); }
internal static string CreateExtremumFunction(string expression, bool isMax, ClientDataSet dataSet) { StringBuilder sb = new StringBuilder("function(v){var r="); if (isMax) { sb.Append("(0-Infinity);"); } else { sb.Append("Infinity;"); } sb.AppendFormat("for(var i=0;i<v.{0}.length;i++){{", dataSet); var compiledExpr = Template.CompileExpression(expression, "v", string.Format("{0}[i]", dataSet)); sb.AppendFormat("if ((({0})!=null)&&(({0})!=undefined)) r=(({0}){1}r?({0}):r);}}return r;}}", compiledExpr, isMax ? ">" : "<"); return(sb.ToString()); }
/// <summary> /// Adds client total calculator that produces maximum of supplied row values /// </summary> /// <param name="conf">Configuration</param> /// <param name="column">Table column to provide total with</param> /// <param name="expression">`{@}`-syntax expression minimum of which will be found</param> /// <param name="clientDataSet">Client data set to perform calculations on</param> /// <param name="template">Tempalte for total cell</param> /// <returns></returns> public static TotalCalculatorBuilder <TSourceData, TTableData> AddClientMax <TSourceData, TTableData, TTableColumn>( this TotalCalculatorBuilder <TSourceData, TTableData> conf, Expression <Func <TTableData, TTableColumn> > column, string expression, ClientDataSet clientDataSet, Action <CellTemplateBuilder> template = null ) where TTableData : new() { var name = LambdaHelpers.ParsePropertyLambda(column).Name; var function = CreateExtremumFunction(expression, true, clientDataSet); conf.ClientCalculators.Add(name, function); if (template != null) { conf.AddTemplate(column, template); } return(conf); }
public ClientFormViewModel() { ClientDataSet dataset = new ClientDataSet(); ClientDataSetTableAdapters.ClientsTableAdapter Client = new ClientDataSetTableAdapters.ClientsTableAdapter(); ClientDataSetTableAdapters.Clients_ObsTableAdapter Client_obs = new ClientDataSetTableAdapters.Clients_ObsTableAdapter(); Countries = new ObservableCollection <ClientDataSet.System_Data_CountriesRow>(); LoadCountries(); Provinces = new ObservableCollection <ClientDataSet.System__Data_ProvincesRow>(); LoadProvinces(); _row = dataset.Clients.NewClientsRow(); _row_obs = dataset.Clients_Obs.NewClients_ObsRow(); //cliente _row.Code = ""; _row.Name = ""; _row.Cif = ""; _row.CreatedDate = DateTime.Now; _row.ModifiedDate = DateTime.Now; _row.Address = ""; _row.City = ""; _row.PostCode = ""; _row.Province = ""; _row.Country = ""; _row.Contact = ""; _row.Phone = ""; _row.Phone2 = ""; _row.PhoneMobile = ""; _row.Fax = ""; _row.Email = ""; _row.Latitude = 0; _row.Longitude = 0; _row.Enabled = true; _row.Id = 0; //observaciones _row_obs.Observations = ""; SaveCommand = new RelayCommand(Save, CanSave); }
public static QueryClientsResponse QueryClientsForWs(QueryClientsForWsRequest request) { QueryClientsResponse response; if (request == null) { response = ResponseBase.InvalidInput <QueryClientsResponse>("参数错误"); } else { request.PagingTrim(); try { var user = UserSet.GetUser(UserId.CreateLoginNameUserId(request.LoginName)); if (user == null) { response = ResponseBase.InvalidInput <QueryClientsResponse>("用户不存在"); } else { var data = ClientDataSet.QueryClients( user, request, out int total, out CoinSnapshotData[] latestSnapshots, out int totalOnlineCount, out int totalMiningCount) ?? new List <ClientData>(); response = QueryClientsResponse.Ok(data, total, latestSnapshots, totalMiningCount, totalOnlineCount); } } catch (Exception e) { Logger.ErrorDebugLine(e); response = ResponseBase.ServerError <QueryClientsResponse>(e.Message); } } return(response); }
static void Main() { NTMinerConsole.DisbleQuickEditMode(); HomePath.SetHomeDirFullName(AppDomain.CurrentDomain.BaseDirectory); try { bool mutexCreated; try { // 锁名称上带上本节点的端口号,从而允许一个服务器上运行多个WebApiServer节点,这在软升级服务端程序时有用。 // 升级WebApiServer程序的时候步骤是: // 1,在另一个端口启动新版本的程序; // 2,让Widnows将来自旧端口的所有tcp请求转发到新端口; // 3,退出旧版本的程序并更新到新版本; // 4,删除第2步添加的Windows的端口转发; // 5,退出第1步运行的节点; // TODO:实现软升级策略 _sMutexApp = new Mutex(true, $"NTMinerServicesMutex{ServerRoot.HostConfig.GetServerPort().ToString()}", out mutexCreated); } catch { mutexCreated = false; } if (mutexCreated) { try { // 用本节点的地址作为队列名,消费消息时根据路由键区分消息类型 string queue = $"{ServerAppType.WebApiServer.GetName()}.{ServerRoot.HostConfig.ThisServerAddress}"; string durableQueue = queue + MqKeyword.DurableQueueEndsWith; AbstractMqMessagePath[] mqMessagePaths = new AbstractMqMessagePath[] { new UserMqMessagePath(durableQueue), new MinerClientMqMessagePath(queue) }; _serverContext = ServerContext.Create(mqClientTypeName: ServerAppType.WebApiServer.GetName(), mqMessagePaths); if (_serverContext == null) { Write.UserError("启动失败,无法继续,因为服务器上下文创建失败"); return; } Console.Title = $"{ServerAppType.WebApiServer.GetName()}_{ServerRoot.HostConfig.ThisServerAddress}"; _ossClient = new OssClient(ServerRoot.HostConfig.OssEndpoint, ServerRoot.HostConfig.OssAccessKeyId, ServerRoot.HostConfig.OssAccessKeySecret); var minerClientMqSender = new MinerClientMqSender(_serverContext.Channel); var userMqSender = new UserMqSender(_serverContext.Channel); var wsServerNodeMqSender = new WsServerNodeMqSender(_serverContext.Channel); var minerRedis = new MinerRedis(_serverContext.RedisConn); var speedDataRedis = new SpeedDataRedis(_serverContext.RedisConn); var userRedis = new UserRedis(_serverContext.RedisConn); var captchaRedis = new CaptchaRedis(_serverContext.RedisConn); WsServerNodeSet = new WsServerNodeSet(wsServerNodeMqSender); UserSet = new UserSet(userRedis, userMqSender); UserAppSettingSet = new UserAppSettingSet(); CaptchaSet = new CaptchaSet(captchaRedis); CalcConfigSet = new CalcConfigSet(); NTMinerWalletSet = new NTMinerWalletSet(); ClientDataSet clientDataSet = new ClientDataSet(minerRedis, speedDataRedis, minerClientMqSender); ClientDataSet = clientDataSet; CoinSnapshotSet = new CoinSnapshotSet(clientDataSet); MineWorkSet = new UserMineWorkSet(); MinerGroupSet = new UserMinerGroupSet(); NTMinerFileSet = new NTMinerFileSet(); OverClockDataSet = new OverClockDataSet(); KernelOutputKeywordSet = new KernelOutputKeywordSet(SpecialPath.LocalDbFileFullName, isServer: true); ServerMessageSet = new ServerMessageSet(SpecialPath.LocalDbFileFullName, isServer: true); UpdateServerMessageTimestamp(); if (VirtualRoot.LocalAppSettingSet.TryGetAppSetting(nameof(KernelOutputKeywordTimestamp), out IAppSetting appSetting) && appSetting.Value is DateTime value) { KernelOutputKeywordTimestamp = value; } else { KernelOutputKeywordTimestamp = Timestamp.UnixBaseTime; } } catch (Exception e) { Write.UserError(e.Message); Write.UserError(e.StackTrace); Write.UserInfo("按任意键退出"); Console.ReadKey(); return; } VirtualRoot.StartTimer(); NTMinerRegistry.SetAutoBoot("NTMinerServices", true); Type thisType = typeof(WebApiRoot); Run(); } } catch (Exception e) { Logger.ErrorDebugLine(e); } }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs) { global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); ClientDataSet ds = new ClientDataSet(); global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny(); any1.Namespace = "http://www.w3.org/2001/XMLSchema"; any1.MinOccurs = new decimal(0); any1.MaxOccurs = decimal.MaxValue; any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any1); global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny(); any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1"; any2.MinOccurs = new decimal(1); any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any2); global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute(); attribute1.Name = "namespace"; attribute1.FixedValue = ds.Namespace; type.Attributes.Add(attribute1); global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute(); attribute2.Name = "tableTypeName"; attribute2.FixedValue = "borrowarInfotblDataTable"; type.Attributes.Add(attribute2); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte()));) { ; } if ((s1.Position == s1.Length)) { return(type); } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return(type); }
static void Main() { VirtualRoot.SetOut(new ConsoleOut()); NTMinerConsole.MainUiOk(); NTMinerConsole.DisbleQuickEditMode(); DevMode.SetDevMode(); Windows.ConsoleHandler.Register(Exit); try { bool mutexCreated; try { // 锁名称上带上本节点的端口号,从而允许一个服务器上运行多个WebApiServer节点,这在软升级服务端程序时有用。 // 升级WebApiServer程序的时候步骤是: // 1,在另一个端口启动新版本的程序; // 2,让Widnows将来自旧端口的所有tcp请求转发到新端口; // 3,退出旧版本的程序并更新到新版本; // 4,删除第2步添加的Windows的端口转发; // 5,退出第1步运行的节点; // TODO:实现软升级策略 _sMutexApp = new Mutex(true, $"NTMinerServicesMutex{ServerRoot.HostConfig.GetServerPort().ToString()}", out mutexCreated); } catch { mutexCreated = false; } if (mutexCreated) { try { // 用本节点的地址作为队列名,消费消息时根据路由键区分消息类型 string queue = $"{nameof(ServerAppType.WebApiServer)}.{ServerRoot.HostConfig.ThisServerAddress}"; string durableQueue = queue + MqKeyword.DurableQueueEndsWith; string wsBreathQueue = queue + MqKeyword.WsBreathQueueEndsWith; AbstractMqMessagePath[] mqMessagePaths = new AbstractMqMessagePath[] { new UserMqMessagePath(durableQueue), new CalcConfigMqMessagePath(queue), new MinerClientMqMessagePath(queue), new WsBreathMqMessagePath(wsBreathQueue), new OperationMqMessagePath(queue), new MqCountMqMessagePath(queue), new ClientTestIdMqMessagePath(queue) }; if (!MqRedis.Create(ServerAppType.WebApiServer, mqMessagePaths, out IMqRedis mqRedis)) { NTMinerConsole.UserError("启动失败,无法继续,因为服务器上下文创建失败"); return; } Console.Title = $"{nameof(ServerAppType.WebApiServer)}_{ServerRoot.HostConfig.ThisServerAddress}"; // 阿里云OSS坑爹比七牛Kodo贵一半 CloudFileUrlGenerater = new AliCloudOSSFileUrlGenerater(); IRedis redis = mqRedis; IMq mq = mqRedis; AdminMqSender = new AdminMqSender(mq); ClientTestIdDataRedis = new ClientTestIdDataRedis(redis); var minerClientMqSender = new MinerClientMqSender(mq); var userMqSender = new UserMqSender(mq); var calcConfigMqSender = new CalcConfigMqSender(mq); var minerRedis = new MinerDataRedis(redis); var clientActiveOnRedis = new ClientActiveOnRedis(redis); var speedDataRedis = new SpeedDataRedis(redis); var userRedis = new UserDataRedis(redis); var captchaRedis = new CaptchaDataRedis(redis); var calcConfigRedis = new CalcConfigDataRedis(redis); MqCountSet = new MqCountSet(); WsServerNodeRedis = new WsServerNodeRedis(redis); WsServerNodeAddressSet = new WsServerNodeAddressSet(WsServerNodeRedis); UserSet = new UserSet(userRedis, userMqSender); UserAppSettingSet = new UserAppSettingSet(); CaptchaSet = new CaptchaSet(captchaRedis); CalcConfigSet = new CalcConfigSet(calcConfigRedis, calcConfigMqSender); NTMinerWalletSet = new NTMinerWalletSet(); GpuNameSet = new GpuNameSet(); ClientDataSet clientDataSet = new ClientDataSet(minerRedis, clientActiveOnRedis, speedDataRedis, minerClientMqSender); ClientDataSet = clientDataSet; var operationMqSender = new OperationMqSender(mq); MineWorkSet = new UserMineWorkSet(operationMqSender); MinerGroupSet = new UserMinerGroupSet(); NTMinerFileSet = new NTMinerFileSet(); OverClockDataSet = new OverClockDataSet(); KernelOutputKeywordSet = new KernelOutputKeywordSet(SpecialPath.LocalDbFileFullName); ServerMessageSet = new ServerMessageSet(SpecialPath.LocalDbFileFullName); if (VirtualRoot.LocalAppSettingSet.TryGetAppSetting(nameof(KernelOutputKeywordTimestamp), out IAppSetting appSetting) && appSetting.Value is DateTime value) { KernelOutputKeywordTimestamp = value; } else { KernelOutputKeywordTimestamp = Timestamp.UnixBaseTime; } } catch (Exception e) { NTMinerConsole.UserError(e.Message); NTMinerConsole.UserError(e.StackTrace); NTMinerConsole.UserInfo("按任意键退出"); Console.ReadKey(); return; } VirtualRoot.StartTimer(); NTMinerRegistry.SetAutoBoot("NTMinerServices", true); Type thisType = typeof(AppRoot); Run(); } } catch (Exception e) { Logger.ErrorDebugLine(e); } }
internal static string CreateSumFunctionWithPredicate(string sumExpression, string predicateExpression, ClientDataSet dataSet) { StringBuilder sb = new StringBuilder("function(v){var s=0;"); sb.AppendFormat("for(var i=0;i<v.{0}.length;i++){{", dataSet); var compiledExpr = Template.CompileExpression(sumExpression, "v", string.Format("{0}[i]", dataSet)); var compiledPredicate = Template.CompileExpression(predicateExpression, string.Format("v.{0}[i]", dataSet), string.Empty); sb.AppendFormat("if ((({0})!=null)&&(({0})!=undefined)) s+=(({1})?({0}):0);}}return s;}}", compiledExpr, compiledPredicate); return(sb.ToString()); }