Ejemplo n.º 1
0
        public bool Correct()
        {
            bool changed = false;

            string cleanName = Formating.RemoveSpecialCharactersNotStrict(this.Name);

            if (this.Name != cleanName)
            {
                this.Name = cleanName; changed = true;
            }
            if (this.Type == ScheduleType.Fraction)
            {
                for (int i = 0; i < this.Values.Count; i++)
                {
                    if (this.Values[i] < 0)
                    {
                        this.Values[i] = 0; changed = true;
                    }
                    if (this.Values[i] > 1)
                    {
                        this.Values[i] = 1; changed = true;
                    }
                }
            }
            return(changed);
        }
Ejemplo n.º 2
0
        public static List <bool> MunchToBool(this string str, Formating formating = Formating.Text)
        {
            switch (formating)
            {
            case Formating.Raw:
                throw new NotImplementedException();
            //doesn't work this way
            //System.Collections.BitArray bitArr = new System.Collections.BitArray(Convert.FromBase64String(str));
            //bool[] boolArr = new bool[bitArr.Length];
            //bitArr.CopyTo(boolArr, 0);
            //return boolArr.ToList();

            case Formating.Binary:
            case Formating.Octal:
            case Formating.Decimal:
            case Formating.Hectal:
                string[]    substrs = str.Split(',', ' ', '\t', '\n');
                List <bool> output  = new List <bool>(substrs.Length);
                foreach (var item in substrs)
                {
                    if (item != "")
                    {
                        output.Add(Convert.ToInt32(item, 16) != 0);
                    }
                }
                return(output);

            case Formating.Text:
                throw new NotImplementedException("Munchers.StringMuncher.MunchToBool\nformating = Text not implemented.");

            default:
                throw new Exception("You gave a bad formating value!");
            }
        }
Ejemplo n.º 3
0
        public async Task ExecuteWriting(DbCommand command, Message message, CancellationToken token)
        {
            //try
            //{
            //command.Transaction = transaction;
            command.Parameters["_message_timestamp"].Value       = message.Timestamp.ToDateTime();
            command.Parameters["_message_id"].Value              = message.Id;
            command.Parameters["_chat_id"].Value                 = message.ChatId;
            command.Parameters["_user_id"].Value                 = message.FromId != 0 ? message.FromId : DBNull.Value;
            command.Parameters["_reply_to"].Value                = message.ReplyTo != 0 ? message.ReplyTo : DBNull.Value;
            command.Parameters["_thread_start"].Value            = message.ThreadStart != 0 ? message.ThreadStart : DBNull.Value;
            command.Parameters["_media_group_id"].Value          = message.MediagroupId != 0 ? message.MediagroupId : DBNull.Value;
            command.Parameters["_forward_from_id"].Value         = message.ForwardFromId != 0 ? message.ForwardFromId : DBNull.Value;
            command.Parameters["_forward_from_message_id"].Value = message.ForwardFromMessageId != 0 ? message.ForwardFromMessageId : DBNull.Value;
            command.Parameters["_text"].Value  = !string.IsNullOrEmpty(message.Text) ? message.Text : DBNull.Value;
            command.Parameters["_media"].Value = string.IsNullOrEmpty(message.Media) ? DBNull.Value : message.Media;

            bool   has_form = Formating.ClearEmpty(message.Formating, out List <Formating> res);
            object forms    = !has_form ?
                              DBNull.Value :
                              "{\"formats\":" + Newtonsoft.Json.JsonConvert.SerializeObject(res) + "}";

            command.Parameters["_formatting"].Value = forms;
            await command.ExecuteNonQueryAsync(token);

            return;
            //}
            //catch(Exception ex)
            //{
            //    int q = 0;
            //}
        }
Ejemplo n.º 4
0
        public bool Correct()
        {
            bool changed = false;

            string cleanName = Formating.RemoveSpecialCharactersNotStrict(this.Name);

            if (this.Name != cleanName)
            {
                this.Name = cleanName; changed = true;
            }

            if (this.SHGF < 0.0)
            {
                this.SHGF = 0.0; changed = true;
            }
            if (this.SHGF > 1.0)
            {
                this.SHGF = 1.0; changed = true;
            }

            if (this.VisibleTransmittance < 0.0)
            {
                this.VisibleTransmittance = 0.0; changed = true;
            }
            if (this.VisibleTransmittance > 1.0)
            {
                this.VisibleTransmittance = 1.0; changed = true;
            }

            return(changed);
        }
Ejemplo n.º 5
0
        //private void reportInvalidWeekSchedules(ref string errorReport)
        //{
        //    try
        //    {
        //        foreach (WeekSchedule op in this.WeekSchedules)
        //        {

        //            // find strange names
        //            string cleanName = Formating.RemoveSpecialCharactersNotStrict(op.Name);
        //            if (op.Name != cleanName)
        //            {
        //                errorReport += op.Name + " --> " + cleanName + " invalid characters have been removed" + "\r\n";
        //                op.Name = cleanName;
        //            }

        //            // autocorrect values out of range // extract as method
        //            if (op.Correct())
        //            {
        //                errorReport += "Schedule " + op.Name + " contained invalid entries that have been auto corrected \r\n";
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        errorReport += ("reportInvalidWeekSchedules failed: " + ex.Message);// + " " + ex.InnerException.Message); }
        //    }
        //}
        private void reportInvalidYearSchedules(ref string errorReport)
        {
            try
            {
                foreach (YearSchedule op in this.YearSchedules)
                {
                    // find strange names
                    string cleanName = Formating.RemoveSpecialCharactersNotStrict(op.Name);
                    if (op.Name != cleanName)
                    {
                        errorReport += op.Name + " --> " + cleanName + " invalid characters have been removed" + "\r\n";
                        op.Name      = cleanName;
                    }

                    // autocorrect values out of range // extract as method
                    if (op.Correct())
                    {
                        errorReport += "Schedule " + op.Name + " contained invalid entries that have been auto corrected \r\n";
                    }
                }
            }
            catch (Exception ex)
            {
                errorReport += ("reportInvalidYearSchedules failed: " + ex.Message);// + " " + ex.InnerException.Message); }
            }
        }
Ejemplo n.º 6
0
        private void reportInvalidOpaqueMaterials(ref string errorReport)
        {
            //Dictionary<string, string> invalidNames = new Dictionary<string, string>();
            try
            {
                foreach (OpaqueMaterial op in this.OpaqueMaterials)
                {
                    // find strange names
                    string cleanName = Formating.RemoveSpecialCharactersNotStrict(op.Name);
                    if (op.Name != cleanName)
                    {
                        errorReport += op.Name + " --> " + cleanName + " invalid characters have been removed" + "\r\n";
                        op.Name      = cleanName;
                    }

                    // autocorrect values out of range // extract as method
                    if (op.Correct())
                    {
                        errorReport += "Material " + op.Name + " contained invalid entries that have been auto corrected \r\n";
                    }
                }
            }
            catch (Exception ex)
            {
                errorReport += ("reportInvalidOpaqueMaterials failed: " + ex.Message);// + " " + ex.InnerException.Message); }
            }
        }
Ejemplo n.º 7
0
        public object PreparateFormatting(string formatting)
        {
            if (string.IsNullOrEmpty(formatting))
            {
                return(DBNull.Value);
            }

            object result = DBNull.Value;

            try
            {
                List <Formating> fmt = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Formating> >(formatting);
                if (Formating.TryGetNonEmpty(fmt, out List <Formating> fmt2))
                {
                    result = "{\"formats\": " + Newtonsoft.Json.JsonConvert.SerializeObject(fmt2) + "}";
                }
            }
            catch { }
            return(result);
        }
Ejemplo n.º 8
0
        public bool Correct()
        {
            bool changed = false;

            string cleanName = Formating.RemoveSpecialCharactersNotStrict(this.Name);

            if (this.Name != cleanName)
            {
                this.Name = cleanName; changed = true;
            }

            foreach (var l in Layers)
            {
                if (l.Correct())
                {
                    changed = true;
                }
            }

            return(changed);
        }
Ejemplo n.º 9
0
        public bool Correct()
        {
            bool changed = false;

            string cleanName = Formating.RemoveSpecialCharactersNotStrict(this.Name);

            if (this.Name != cleanName)
            {
                this.Name = cleanName; changed = true;
            }


            // clean up all refereced names
            //for (int i = 0; i < WeekSchedules.Count; i++)
            //{
            //    string cleanref = Formating.RemoveSpecialCharactersNotStrict(WeekSchedules[i].Name);
            //    if (WeekSchedules[i].Name != cleanref) { WeekSchedules[i].Name = cleanref; changed = true; }
            //}


            return(changed);
        }
Ejemplo n.º 10
0
        private void reportInvalidGCons(ref string errorReport)
        {
            foreach (GlazingConstruction op in this.GlazingConstructions)
            {
                string cleanName = Formating.RemoveSpecialCharactersNotStrict(op.Name);
                if (cleanName != op.Name)
                {
                    //op.Name = Formating.RemoveSpecialCharactersNotStrict(op.Name);
                    errorReport += "Construction  " + op.Name + " name contained invalid characters and has been auto corrected to " + cleanName + "\r\n";
                    op.Name      = cleanName;
                }

                foreach (var ol in op.Layers)
                {
                    ol.SetMaterialName(Formating.RemoveSpecialCharactersNotStrict(ol.GetMaterialName()));// fix as in materials
                    if (ol.Correct())
                    {
                        errorReport += "Layer in  " + op.Name + " contained invalid thickness \r\n";
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public bool Correct()
        {
            bool changed = false;

            string cleanName = Formating.RemoveSpecialCharactersNotStrict(this.Name);

            if (this.Name != cleanName)
            {
                this.Name = cleanName; changed = true;
            }


            if (this.SolarTransmittance < 0.0)
            {
                this.SolarTransmittance = 0.0; changed = true;
            }
            if (this.SolarTransmittance > 1.0)
            {
                this.SolarTransmittance = 1.0; changed = true;
            }

            if (this.SolarReflectanceFront < 0.0)
            {
                this.SolarReflectanceFront = 0.0; changed = true;
            }
            if (this.SolarReflectanceFront > 1.0)
            {
                this.SolarReflectanceFront = 1.0; changed = true;
            }

            if (this.SolarReflectanceBack < 0.0)
            {
                this.SolarReflectanceBack = 0.0; changed = true;
            }
            if (this.SolarReflectanceBack > 1.0)
            {
                this.SolarReflectanceBack = 1.0; changed = true;
            }

            if (this.VisibleTransmittance < 0.0)
            {
                this.VisibleTransmittance = 0.0; changed = true;
            }
            if (this.VisibleTransmittance > 1.0)
            {
                this.VisibleTransmittance = 1.0; changed = true;
            }

            if (this.VisibleReflectanceFront < 0.0)
            {
                this.VisibleReflectanceFront = 0.0; changed = true;
            }
            if (this.VisibleReflectanceFront > 1.0)
            {
                this.VisibleReflectanceFront = 1.0; changed = true;
            }

            if (this.VisibleReflectanceBack < 0.0)
            {
                this.VisibleReflectanceBack = 0.0; changed = true;
            }
            if (this.VisibleReflectanceBack > 1.0)
            {
                this.VisibleReflectanceBack = 1.0; changed = true;
            }

            if (this.IRTransmittance < 0.0)
            {
                this.IRTransmittance = 0.0; changed = true;
            }
            if (this.IRTransmittance > 1.0)
            {
                this.IRTransmittance = 1.0; changed = true;
            }

            if (this.IREmissivityFront < 0.0)
            {
                this.IREmissivityFront = 0.0; changed = true;
            }
            if (this.IREmissivityFront > 1.0)
            {
                this.IREmissivityFront = 1.0; changed = true;
            }

            if (this.IREmissivityBack < 0.0)
            {
                this.IREmissivityBack = 0.0; changed = true;
            }
            if (this.IREmissivityBack > 1.0)
            {
                this.IREmissivityBack = 1.0; changed = true;
            }

            if (this.Density < 10)
            {
                this.Density = 10; changed = true;
            }
            if (this.Density > 5000)
            {
                this.Density = 5000; changed = true;
            }

            if (this.Conductivity < 0.001)
            {
                this.Conductivity = 0.001; changed = true;
            }
            if (this.Conductivity > 5000)
            {
                this.Conductivity = 5000; changed = true;
            }

            return(changed);
        }
Ejemplo n.º 12
0
        public bool Correct()
        {
            bool changed = false;

            string cleanName = Formating.RemoveSpecialCharactersNotStrict(this.Name);

            if (this.Name != cleanName)
            {
                this.Name = cleanName; changed = true;
            }

            if (this.VisibleAbsorptance < 0.001)
            {
                this.VisibleAbsorptance = 0.001; changed = true;
            }
            if (this.VisibleAbsorptance > 0.999)
            {
                this.VisibleAbsorptance = 0.999; changed = true;
            }
            if (this.SolarAbsorptance < 0.001)
            {
                this.SolarAbsorptance = 0.001; changed = true;
            }
            if (this.SolarAbsorptance > 0.999)
            {
                this.SolarAbsorptance = 0.999; changed = true;
            }
            if (this.ThermalAbsorptance < 0.001)
            {
                this.ThermalAbsorptance = 0.001; changed = true;
            }
            if (this.ThermalAbsorptance > 0.999)
            {
                this.ThermalAbsorptance = 0.999; changed = true;
            }
            if (this.SpecificHeat < 100)
            {
                this.SpecificHeat = 100; changed = true;
            }
            if (this.SpecificHeat > 5000)
            {
                this.SpecificHeat = 2000; changed = true;
            }
            if (this.Density < 10)
            {
                this.Density = 10; changed = true;
            }
            if (this.Density > 5000)
            {
                this.Density = 5000; changed = true;
            }
            if (this.Conductivity < 0.001)
            {
                this.Conductivity = 0.001; changed = true;
            }
            if (this.Conductivity > 5000)
            {
                this.Conductivity = 5000; changed = true;
            }

            return(changed);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// To read line as number or regular line with blocked keys
        /// </summary>
        /// <param name="format"></param>
        /// <returns></returns>
        public string ReadLine(Formating format)
        {
            Write(">>> ");

            bool   isCommand = false;
            string buf       = "";
            string regex     = Format.GetValueOrDefault(format, @"^[a-zA-Z0-9]+$");
            string oldRegex  = regex;

            bool endRead = false;

            while (!endRead)
            {
                var keyInfo   = System.Console.ReadKey(true);
                var key       = keyInfo.Key;
                var keyString = keyInfo.KeyChar.ToString();

                string write = "";

                switch (key)
                {
                case ConsoleKey.Enter:
                {
                    if (buf.Length != 0)
                    {
                        write   = "\n";
                        endRead = true;
                    }
                    break;
                }

                case ConsoleKey.Backspace:
                {
                    if (buf.Length != 0)
                    {
                        buf   = buf.Remove(buf.Length - 1, 1);
                        write = "\b \b";
                    }
                    break;
                }

                case ConsoleKey.Oem2:                         // is '/'
                {
                    if (buf.Length == 0)
                    {
                        if (!regex.Contains("a-zA-Z"))
                        {
                            regex = @"^[a-zA-Z0-9]+$";
                        }
                        isCommand = true;
                        buf      += keyString;
                        write     = keyString;
                    }
                    break;
                }

                case ConsoleKey.OemMinus:
                {
                    if (buf.Length > 0 && isCommand)
                    {
                        buf  += keyString;
                        write = keyString;
                    }
                    break;
                }

                case ConsoleKey.Spacebar:
                {
                    break;
                }

                default:
                {
                    if (Regex.IsMatch(keyString, regex) && (buf.Length > 0 || keyString != "0"))
                    {
                        buf  += keyString;
                        write = keyString;
                    }
                    break;
                }
                }
                if (isCommand)
                {
                    Write(write, ConsoleColor.Yellow);
                    if (buf.Length == 0)
                    {
                        isCommand = false;
                        regex     = oldRegex;
                    }
                }
                else
                {
                    Write(write);
                }
            }
            return(buf);
        }
Ejemplo n.º 14
0
        public void WriteSingleObject(object data, DbTransaction transaction)
        {
            if (data is Message message && AddMessageCommand != null)
            {
                DbCommand command = AddMessageCommand;
                command.Transaction = transaction;
                command.Parameters["_message_timestamp"].Value       = message.Timestamp.ToDateTime();
                command.Parameters["_message_id"].Value              = message.Id;
                command.Parameters["_chat_id"].Value                 = message.ChatId;
                command.Parameters["_user_id"].Value                 = message.FromId != 0 ? message.FromId : DBNull.Value;
                command.Parameters["_reply_to"].Value                = message.ReplyTo != 0 ? message.ReplyTo : DBNull.Value;
                command.Parameters["_thread_start"].Value            = message.ThreadStart != 0 ? message.ThreadStart : DBNull.Value;
                command.Parameters["_media_group_id"].Value          = message.MediagroupId != 0 ? message.MediagroupId : DBNull.Value;
                command.Parameters["_forward_from_id"].Value         = message.ForwardFromId != 0 ? message.ForwardFromId : DBNull.Value;
                command.Parameters["_forward_from_message_id"].Value = message.ForwardFromMessageId != 0 ? message.ForwardFromMessageId : DBNull.Value;
                command.Parameters["_text"].Value       = !string.IsNullOrEmpty(message.Text) ? message.Text : DBNull.Value;
                command.Parameters["_media"].Value      = string.IsNullOrEmpty(message.Media) ? DBNull.Value : message.Media;
                command.Parameters["_formatting"].Value = message.Formating.Count == 0 || Formating.IsEmpty(message.Formating) ?
                                                          DBNull.Value :
                                                          "{\"formats\":" + Newtonsoft.Json.JsonConvert.SerializeObject(message.Formating) + "}";
                command.ExecuteNonQuery();
                return;
            }

            if (data is Chat chat && AddChatCommand != null)
            {
                DbCommand command = AddChatCommand;
                command.Transaction = transaction;
                command.Parameters["_chat_id"].Value     = chat.Entity.Id;
                command.Parameters["_username"].Value    = chat.Entity.Link.Equals(string.Empty) ? DBNull.Value : chat.Entity.Link;
                command.Parameters["_title"].Value       = chat.Entity.FirstName;
                command.Parameters["pair_chat_id"].Value = chat.Entity.PairId != 0 ? chat.Entity.PairId : DBNull.Value;
                command.Parameters["_is_group"].Value    = chat.Entity.Type == EntityType.Group;
                command.Parameters["_is_channel"].Value  = chat.Entity.Type == EntityType.Channel;
                command.ExecuteNonQuery();
                return;
            }

            if (data is User user && AddUserCommand != null)
            {
                DbCommand command = AddUserCommand;
                command.Transaction = transaction;
                command.Parameters["_user_id"].Value          = user.Entity.Id;
                command.Parameters["sender_username"].Value   = user.Entity.Link;
                command.Parameters["sender_first_name"].Value = user.Entity.FirstName;
                command.Parameters["sender_last_name"].Value  = user.Entity.LastName;
                command.ExecuteNonQuery();
                return;
            }

            if (data is Ban ban && BanChatCommand != null)
            {
                DbCommand command = BanChatCommand;
                command.Transaction             = transaction;
                command.Parameters["_id"].Value = ban.Entity.Id;
                command.ExecuteNonQuery();
                return;
            }

            if (data is Deleting del && DelMessageCommand != null)
            {
                DbCommand command = DelMessageCommand;
                command.Transaction             = transaction;
                command.Parameters["_id"].Value = del.message_db_id;
                int q = command.ExecuteNonQuery();
                return;
            }
        }