Exemplo n.º 1
0
        /// <summary>
        /// Constructs a DmColumn object based on a DmColumnSurrogate object.
        /// </summary>
        public DmColumn ConvertToDmColumn()
        {
            DmColumn dmColumn = DmColumn.CreateColumn(this.ColumnName, DmUtils.GetTypeFromAssemblyQualifiedName(this.DataType));

            dmColumn.dbTypeAllowed = this.dbTypeAllowed;
            if (dmColumn.dbTypeAllowed)
            {
                dmColumn.DbType = (DbType)this.DbType;
            }

            dmColumn.AllowDBNull        = this.AllowDBNull;
            dmColumn.IsReadOnly         = this.IsReadOnly;
            dmColumn.MaxLength          = this.MaxLength;
            dmColumn.IsAutoIncrement    = this.IsAutoIncrement;
            dmColumn.Precision          = this.Precision;
            dmColumn.PrecisionSpecified = this.PrecisionSpecified;
            dmColumn.Scale            = this.Scale;
            dmColumn.ScaleSpecified   = this.ScaleSpecified;
            dmColumn.IsUnique         = this.IsUnique;
            dmColumn.IsUnicode        = this.IsUnicode;
            dmColumn.IsCompute        = this.IsCompute;
            dmColumn.IsUnsigned       = this.IsUnsigned;
            dmColumn.OriginalDbType   = this.OriginalDbType;
            dmColumn.OriginalTypeName = this.OriginalTypeName;
            dmColumn.SetOrdinal(this.Ordinal);

            return(dmColumn);
        }
Exemplo n.º 2
0
        public override object Deserialize(DmSerializer dmSerializer, Type objType, bool isDebugMode = false)
        {
            Object instance = objType.CreateInstance();

            var currentType = objType;

            while (currentType != null && currentType != typeof(Object))

            {
                List <MemberInfo> members = DmUtils.GetMembers(currentType);

                var membersValue = new object[members.Count];

                for (int i = 0; i < members.Count; i++)
                {
                    var member      = members[i];
                    var memberValue = dmSerializer.GetObject(isDebugMode);

                    if (memberValue != null)
                    {
                        member.SetValue(instance, memberValue);
                    }
                }
                currentType = currentType.GetTypeInfo().BaseType;
            }

            return(instance);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get a row size
        /// </summary>
        public static long GetRowSizeFromDataRow(DmRow row)
        {
            bool isRowDeleted = false;

            if (row.RowState == DmRowState.Deleted)
            {
                row.RejectChanges();
                isRowDeleted = true;
            }

            long byteCount = 0;

            object[] itemArray = row.ItemArray;

            for (int i = 0; i < itemArray.Length; i++)
            {
                // Size for the value
                object obj     = itemArray[i];
                Type   objType = obj != null?obj.GetType() : null;


                if (obj == null)
                {
                    byteCount = byteCount + 5;
                }
                else if (obj is DBNull)
                {
                    byteCount = byteCount + 5;
                }
                else if (objType == stringType)
                {
                    byteCount = byteCount + Encoding.UTF8.GetByteCount((string)obj);
                }
                else if (objType == byteArrayType)
                {
                    byteCount = byteCount + ((byte[])obj).Length;
                }
                else
                {
                    byteCount = byteCount + GetSizeForType(obj.GetType());
                }

                // Size for the type
                var typeofobject    = row.Table.Columns[i].DataType;
                var byteslengthtype = Encoding.UTF8.GetBytes(DmUtils.GetAssemblyQualifiedName(typeofobject)).Length;
                byteCount += byteslengthtype;

                // State
                byteCount += 4L;

                // Index
                byteCount += 4L;
            }
            if (isRowDeleted)
            {
                row.Delete();
            }
            return(byteCount);
        }
Exemplo n.º 4
0
        public async Task Transfer(IGuildUser toUser, [Remainder] string reason = "Tip.")
        {
            var fromUser = (IGuildUser)Context.Message.Author;
            await _buttcoinService.ActivateAccount(fromUser);

            var(fromAccount, toAccount) = await _buttcoinService.Transfer(Context.Message.Author, toUser, 10, reason);

            var embed = EmbedUtils.CreateTransferEmbed((IGuildUser)Context.User, toUser, fromAccount, toAccount, 10, reason, _logoUrl).Build();

            await DmUtils.SendDm(fromUser, embed);

            await DmUtils.SendDm(toUser, embed);

            await Context.Message.AddReactionAsync(_emote);
        }
Exemplo n.º 5
0
        public override void Serialize(DmSerializer dmSerializer, object obj, Type objType)
        {
            // Get the serialized members
            var members = DmUtils.GetMembers(objType);

            //var ctorParameters = objType.GetConstructorParameters(true);
            //if (ctorParameters != null)
            //    members = DmUtils.GetMembersOrderedByParametersForConstructor(members, ctorParameters);

            foreach (MemberInfo member in members)
            {
                object memberValue = member.GetValue(obj);
                var    memberType  = member.GetMemberType();

                dmSerializer.Serialize(memberValue, memberType);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Calculate an estimation of the dictionary values size
        /// </summary>
        public static long GetRowSizeFromDataRow(object[] itemArray)
        {
            long byteCount = 0;

            foreach (var obj in itemArray)
            {
                var objType = obj?.GetType();

                if (obj == null)
                {
                    byteCount += 5;
                }
                else if (obj is DBNull)
                {
                    byteCount += 5;
                }
                else if (objType == stringType)
                {
                    byteCount += Encoding.UTF8.GetByteCount((string)obj);
                }
                else if (objType == byteArrayType)
                {
                    byteCount += ((byte[])obj).Length;
                }
                else
                {
                    byteCount += GetSizeForType(obj.GetType());
                }

                // Size for the type
                if (objType != null)
                {
                    byteCount += Encoding.UTF8.GetBytes(DmUtils.GetAssemblyQualifiedName(objType)).Length;
                }

                // State
                byteCount += 4L;

                // Index
                byteCount += 4L;
            }
            return(byteCount);
        }
Exemplo n.º 7
0
        public override object Deserialize(DmSerializer dmSerializer, Type objType, bool isDebugMode = false)
        {
            Object            instance = objType.CreateInstance();
            List <MemberInfo> members  = DmUtils.GetMembers(objType);

            var membersValue = new object[members.Count];

            for (int i = 0; i < members.Count; i++)
            {
                var member      = members[i];
                var memberValue = dmSerializer.GetObject(isDebugMode);

                if (memberValue != null)
                {
                    member.SetValue(instance, memberValue);
                }
            }


            return(instance);
        }
Exemplo n.º 8
0
 public override object ConvertFromString(string s)
 {
     return(DmUtils.GetTypeFromAssemblyQualifiedName(s));
 }
Exemplo n.º 9
0
        public async Task OnMessageReceived(SocketMessage message)
        {
            if (!(message.Channel is SocketTextChannel) || message.Author.IsBot)
            {
                return;
            }

            // Transfer 1
            var plusPlusMatch = _plusPlus.Match(message.Content);

            if (plusPlusMatch.Success && message.Channel is SocketTextChannel channel)
            {
                var   userSearch = plusPlusMatch.Groups[1].Value;
                IUser?toUser;
                if (MentionUtils.TryParseUser(userSearch, out var userId))
                {
                    toUser = channel.GetUser(userId);
                }
                else
                {
                    toUser = (await channel.Guild.SearchUsersAsync(userSearch, 1)).FirstOrDefault();
                }

                if (toUser != null)
                {
                    try
                    {
                        await _buttcoinService.ActivateAccount(message.Author);

                        var(fromAccount, toAccount) = await _buttcoinService.Transfer(message.Author, toUser, 1, "PlusPlus");

                        var embed = EmbedUtils.CreateTransferEmbed((IGuildUser)message.Author, (IGuildUser)toUser, fromAccount, toAccount, 1, "PlusPlus", _logoUrl).Build();

                        await DmUtils.SendDm(message.Author, embed);

                        await DmUtils.SendDm(toUser, embed);

                        await message.AddReactionAsync(_emote);

                        return;
                    }
                    catch (ButtcoinException ex)
                    {
                        await channel.SendMessageAsync(ex.Message);

                        return;
                    }
                }
            }

            // Fetch words if we don't already have it
            if (_words == null)
            {
                var stringWords = await _configurationService.GetButtWords();

                _words = stringWords.Select(x => new Regex($"\\b{x}\\b"));
                _word  = PickWord();
            }

            // Mine buttcoin
            if (!message.Content.StartsWith(_botPrefix) && _word.IsMatch(message.Content))
            {
                var isBruteForce = _words.All(x => x.IsMatch(message.Content));
                await _buttcoinService.MineCoin(message.Author.Id.ToString(), isBruteForce);

                _word = PickWord();
            }
        }
Exemplo n.º 10
0
        public static ServiceConfiguration DeserializeFromDmSet(DmSet set)
        {
            if (set == null)
            {
                return(null);
            }

            if (!set.Tables.Contains("DotmimSync__ServiceConfiguration"))
            {
                return(null);
            }

            ServiceConfiguration configuration = new ServiceConfiguration();
            var dmRowConfiguration             = set.Tables["DotmimSync__ServiceConfiguration"].Rows[0];

            configuration.BatchDirectory           = dmRowConfiguration["BatchDirectory"] as String;;
            configuration.ConflictResolutionPolicy = (ConflictResolutionPolicy)dmRowConfiguration["ConflictResolutionPolicy"];
            configuration.DownloadBatchSizeInKB    = (int)dmRowConfiguration["DownloadBatchSizeInKB"];
            configuration.EnableDiagnosticPage     = (bool)dmRowConfiguration["EnableDiagnosticPage"];
            configuration.UseBulkOperations        = (bool)dmRowConfiguration["UseBulkOperations"];
            configuration.UseVerboseErrors         = (bool)dmRowConfiguration["UseVerboseErrors"];
            configuration.OverwriteConfiguration   = (bool)dmRowConfiguration["OverwriteConfiguration"];
            configuration.SerializationConverter   = (SerializationFormat)dmRowConfiguration["SerializationConverter"];

            if (set.Tables.Contains("DotmimSync__FilterParameter"))
            {
                configuration.FilterParameters = new List <SyncParameter>();
                var dmTableFilterParameters = set.Tables["DotmimSync__FilterParameter"];

                foreach (var dmRowFilter in dmTableFilterParameters.Rows)
                {
                    SyncParameter syncParameter = new SyncParameter();
                    syncParameter.Name = dmRowFilter["Name"] as String;

                    var valueType = dmRowFilter["ValueType"] as String;
                    var value     = dmRowFilter["Value"] as String;
                    var objType   = DmUtils.GetTypeFromAssemblyQualifiedName(valueType);
                    var converter = objType.GetConverter();
                    var objValue  = converter.ConvertFromInvariantString(valueType);
                    syncParameter.Value = objValue;

                    configuration.FilterParameters.Add(syncParameter);
                }
            }

            if (set.Tables.Contains("DotmimSync__Table"))
            {
                var dmTableTables = set.Tables["DotmimSync__Table"];
                configuration.Tables = new string[dmTableTables.Rows.Count];

                for (int i = 0; i < dmTableTables.Rows.Count; i++)
                {
                    var dmRowTable = dmTableTables.Rows[i];
                    var tableName  = dmRowTable["Name"] as String;
                    configuration.Tables[i] = tableName;
                }
            }

            var configTables = set.Tables.Where(tbl => !tbl.TableName.StartsWith("DotmimSync__"));

            if (configTables != null)
            {
                foreach (var configTable in configTables)
                {
                    configuration.ScopeSet.Tables.Add(configTable.Clone());
                }
            }

            return(configuration);
        }