예제 #1
0
            public static ValueStrings FromDictionary(Dictionary <string, string> values)
            {
                ValueStrings result = new ValueStrings();

                result.FilePath = values.ContainsKey("filepath") ? values["filepath"] : null;
                return(result);
            }
예제 #2
0
        public override int GetHashCode()
        {
            int hash_code = Name.GetHashCode();

            hash_code += DataLevel.GetHashCode();
            hash_code += ValueStrings.GetHashCode();
            return(hash_code);
        }
예제 #3
0
        public static ErrorMessageModel ToErrorMessage(this Exception exception, string caption, Dictionary <string, string> values)
        {
            StringBuilder shortText    = new StringBuilder();
            Type          t            = exception.GetType();
            ValueStrings  valueStrings = ValueStrings.FromDictionary(values);

            if (typeof(IOException).IsAssignableFrom(t))
            {
                IOException io      = (IOException)exception;
                bool        hasPath = !string.IsNullOrEmpty(valueStrings.FilePath);
                if (hasPath && typeof(FileNotFoundException).IsAssignableFrom(t))
                {
                    shortText.Append($"File by path '{valueStrings.FilePath}' does not exists.");
                }
                else if (hasPath && typeof(DirectoryNotFoundException).IsAssignableFrom(t))
                {
                    shortText.Append($"Directory by path '{valueStrings.FilePath}' does not exists.");
                }
                else if (hasPath && typeof(DriveNotFoundException).IsAssignableFrom(t))
                {
                    shortText.Append($"Drive by path '{valueStrings.FilePath}' does not exists.");
                }
                else if (hasPath && typeof(EndOfStreamException).IsAssignableFrom(t))
                {
                    shortText.Append($"Unexpected end of stream in file '{valueStrings.FilePath}': {exception.Message}");
                }
                else if (hasPath && typeof(FileLoadException).IsAssignableFrom(t))
                {
                    shortText.Append($"Failed to load file '{valueStrings.FilePath}:'{Environment.NewLine}{exception.Message}");
                }
                else if (hasPath && typeof(PathTooLongException).IsAssignableFrom(t))
                {
                    shortText.Append($"The path '{valueStrings.FilePath}' is too long:{Environment.NewLine}{exception.Message}");
                }
                else
                {
                    shortText.Append(exception.Message);
                }
            }
            else if (typeof(UnauthorizedAccessException).IsAssignableFrom(t))
            {
                shortText.Append($"You do not have permissions to access the file/path '{valueStrings.FilePath}'");
            }
            else
            {
                shortText.Append(exception.Message);
            }
            ErrorMessageModel result = new ErrorMessageModel(caption, shortText.ToString())
            {
                Details = exception.ToHumanReadable(values)
            };

            return(result);
        }
예제 #4
0
        private static string ToHumanReadable(this Exception exception, Dictionary <string, string> values)
        {
            StringBuilder result       = new StringBuilder();
            Type          t            = exception.GetType();
            ValueStrings  valueStrings = ValueStrings.FromDictionary(values);

            if (typeof(IOException).IsAssignableFrom(t))
            {
                IOException io      = (IOException)exception;
                bool        hasPath = !string.IsNullOrEmpty(valueStrings.FilePath);
                if (hasPath && typeof(FileNotFoundException).IsAssignableFrom(t))
                {
                    result.Append($"File by path '{valueStrings.FilePath}' does not exists.");
                }
                else if (hasPath && typeof(DirectoryNotFoundException).IsAssignableFrom(t))
                {
                    result.Append($"Directory by path '{valueStrings.FilePath}' does not exists.");
                }
                else if (hasPath && typeof(DriveNotFoundException).IsAssignableFrom(t))
                {
                    result.Append($"Drive by path '{valueStrings.FilePath}' does not exists.");
                }
                else if (hasPath && typeof(EndOfStreamException).IsAssignableFrom(t))
                {
                    result.Append($"Unexpected end of stream in file '{valueStrings.FilePath}': {exception.Message}.");
                }
                else if (hasPath && typeof(FileLoadException).IsAssignableFrom(t))
                {
                    result.Append($"Failed to load file '{valueStrings.FilePath}': {exception.Message}.");
                }
                else if (hasPath && typeof(PathTooLongException).IsAssignableFrom(t))
                {
                    result.Append($"The path '{valueStrings.FilePath}' is too long: {exception.Message}.");
                }
                else
                {
                    int    code = io.HResult & 0x0000FFFF;
                    string r;
                    if (hResultToStringMapping.TryGetValue(code, out r))
                    {
                        r = r.Replace("%FILE%", valueStrings.FilePath);
                        result.Append(r);
                    }
                    else
                    {
                        result.AppendLine($"An exception occurred");
                        result.AppendLine($"Error code: {code}");
                        result.Append($"Message: {exception.Message}");
                    }
                }
            }
            else if (typeof(UnauthorizedAccessException).IsAssignableFrom(t))
            {
                result.Append($"You do not have permissions to access the file/path '{valueStrings.FilePath}'!");
            }
            else
            {
                result.Append(exception.Message);
            }
            result.AppendLine();
            result.AppendLine();
            result.AppendLine("Stack trace:");
            result.Append(exception.StackTrace);
            return(result.ToString());
        }
예제 #5
0
        private Field ParseField(XmlElement E)
        {
            string        Label        = XML.Attribute(E, "label");
            string        Type         = XML.Attribute(E, "type");
            string        Var          = XML.Attribute(E, "var");
            List <string> ValueStrings = null;
            List <KeyValuePair <string, string> > OptionStrings = null;
            string           Description      = string.Empty;
            string           DataTypeName     = null;
            DataType         DataType         = null;
            ValidationMethod ValidationMethod = null;
            Media            Media            = null;
            Field            Field;
            string           Error    = null;
            bool             Required = false;
            bool             PostBack = false;
            bool             ReadOnly = false;
            bool             NotSame  = false;

            foreach (XmlNode N2 in E.ChildNodes)
            {
                switch (N2.LocalName)
                {
                case "desc":
                    Description = N2.InnerText;
                    break;

                case "required":
                    Required = true;
                    break;

                case "value":
                    if (ValueStrings == null)
                    {
                        ValueStrings = new List <string>();
                    }

                    ValueStrings.Add(N2.InnerText);
                    break;

                case "option":
                    if (OptionStrings == null)
                    {
                        OptionStrings = new List <KeyValuePair <string, string> >();
                    }

                    string OptionLabel = XML.Attribute((XmlElement)N2, "label");
                    string OptionValue = string.Empty;

                    foreach (XmlNode N3 in N2.ChildNodes)
                    {
                        if (N3.LocalName == "value")
                        {
                            OptionValue = N3.InnerText;
                            break;
                        }
                    }

                    OptionStrings.Add(new KeyValuePair <string, string>(OptionLabel, OptionValue));
                    break;

                case "validate":
                    DataTypeName = XML.Attribute((XmlElement)N2, "datatype");

                    foreach (XmlNode N3 in N2.ChildNodes)
                    {
                        switch (N3.LocalName)
                        {
                        case "basic":
                            ValidationMethod = new BasicValidation();
                            break;

                        case "open":
                            ValidationMethod = new OpenValidation();
                            break;

                        case "range":
                            XmlElement E3 = (XmlElement)N3;

                            ValidationMethod = new RangeValidation(
                                XML.Attribute(E3, "min"),
                                XML.Attribute(E3, "max"));
                            break;

                        case "regex":
                            ValidationMethod = new RegexValidation(N3.InnerText);
                            break;

                        case "list-range":
                            E3 = (XmlElement)N3;

                            ValidationMethod = new ListRangeValidation(ValidationMethod,
                                                                       XML.Attribute(E3, "min", 0),
                                                                       XML.Attribute(E3, "max", int.MaxValue));
                            break;
                        }
                    }
                    break;

                case "media":
                    Media = new Media((XmlElement)N2);
                    break;

                case "postBack":
                    PostBack = true;
                    break;

                case "readOnly":
                    ReadOnly = true;
                    break;

                case "notSame":
                    NotSame = true;
                    break;

                case "error":
                    Error = N2.InnerText;
                    break;
                }
            }

            if (string.IsNullOrEmpty(DataTypeName))
            {
                if (Type == "boolean")
                {
                    DataTypeName = "xs:boolean";
                }
                else
                {
                    DataTypeName = "xs:string";
                }
            }

            switch (DataTypeName.ToLower())
            {
            case "xs:boolean":
                DataType = BooleanDataType.Instance;
                break;

            case "xs:string":
            default:
                DataType = StringDataType.Instance;
                break;

            case "anyuri":
                DataType = AnyUriDataType.Instance;
                break;

            case "xs:byte":
                DataType = ByteDataType.Instance;
                break;

            case "xs:date":
                DataType = DateDataType.Instance;
                break;

            case "xs:datetime":
                DataType = DateTimeDataType.Instance;
                break;

            case "xs:decimal":
                DataType = DecimalDataType.Instance;
                break;

            case "xs:double":
                DataType = DoubleDataType.Instance;
                break;

            case "xs:int":
                DataType = IntDataType.Instance;
                break;

            case "xs:integer":
                DataType = IntegerDataType.Instance;
                break;

            case "xs:language":
                DataType = LanguageDataType.Instance;
                break;

            case "xs:long":
                DataType = LongDataType.Instance;
                break;

            case "xs:short":
                DataType = ShortDataType.Instance;
                break;

            case "xs:time":
                DataType = TimeDataType.Instance;
                break;

            case "xdc:Color":
                DataType = ColorDataType.Instance;
                break;

            case "xdc:ColorAlpha":
                DataType = ColorAlphaDataType.Instance;
                break;
            }

            if (ValidationMethod == null)
            {
                ValidationMethod = new BasicValidation();
            }

            switch (Type)
            {
            case "boolean":
                Field = new BooleanField(this, Var, Label, Required,
                                         ValueStrings?.ToArray(), OptionStrings?.ToArray(),
                                         Description, DataType, ValidationMethod, Error, PostBack, ReadOnly, NotSame);
                break;

            case "fixed":
                Field = new FixedField(this, Var, Label, Required,
                                       ValueStrings?.ToArray(), OptionStrings?.ToArray(),
                                       Description, DataType, ValidationMethod, Error, PostBack, ReadOnly, NotSame);
                break;

            case "hidden":
                Field = new HiddenField(this, Var, Label, Required,
                                        ValueStrings?.ToArray(), OptionStrings?.ToArray(),
                                        Description, DataType, ValidationMethod, Error, PostBack, ReadOnly, NotSame);
                break;

            case "jid-multi":
                Field = new JidMultiField(this, Var, Label, Required,
                                          ValueStrings?.ToArray(), OptionStrings?.ToArray(),
                                          Description, DataType, ValidationMethod, Error, PostBack, ReadOnly, NotSame);
                break;

            case "jid-single":
                Field = new JidSingleField(this, Var, Label, Required,
                                           ValueStrings?.ToArray(), OptionStrings?.ToArray(),
                                           Description, DataType, ValidationMethod, Error, PostBack, ReadOnly, NotSame);
                break;

            case "list-multi":
                Field = new ListMultiField(this, Var, Label, Required,
                                           ValueStrings?.ToArray(), OptionStrings?.ToArray(),
                                           Description, DataType, ValidationMethod, Error, PostBack, ReadOnly, NotSame);
                break;

            case "list-single":
                Field = new ListSingleField(this, Var, Label, Required,
                                            ValueStrings?.ToArray(), OptionStrings?.ToArray(),
                                            Description, DataType, ValidationMethod, Error, PostBack, ReadOnly, NotSame);
                break;

            case "text-multi":
                Field = new TextMultiField(this, Var, Label, Required,
                                           ValueStrings?.ToArray(), OptionStrings?.ToArray(),
                                           Description, DataType, ValidationMethod, Error, PostBack, ReadOnly, NotSame);
                break;

            case "text-private":
                Field = new TextPrivateField(this, Var, Label, Required,
                                             ValueStrings?.ToArray(), OptionStrings?.ToArray(),
                                             Description, DataType, ValidationMethod, Error, PostBack, ReadOnly, NotSame);
                break;

            case "text-single":
                Field = new TextSingleField(this, Var, Label, Required,
                                            ValueStrings?.ToArray(), OptionStrings?.ToArray(),
                                            Description, DataType, ValidationMethod, Error, PostBack, ReadOnly, NotSame);
                break;

            default:
                if (Media == null)
                {
                    Field = new TextSingleField(this, Var, Label, Required,
                                                ValueStrings?.ToArray(), OptionStrings?.ToArray(),
                                                Description, DataType, ValidationMethod, Error, PostBack, ReadOnly, NotSame);
                }
                else
                {
                    Field = new MediaField(this, Var, Label, Required,
                                           ValueStrings?.ToArray(), OptionStrings?.ToArray(),
                                           Description, DataType, ValidationMethod, Media, Error, PostBack, ReadOnly, NotSame);
                }
                break;
            }

            return(Field);
        }