Exemple #1
0
        /// <summary>
        /// Gets the string representation of a file attribute.
        /// </summary>
        /// <param name="attributeType">Type of the attribute.</param>
        /// <param name="file">The file to get the attribute for.</param>
        /// <returns>The file attribute as text.</returns>
        public static string GetAttribute(FileAttributeType attributeType, FileInfo file)
        {
            string attributeString = null;

            if (file != null)
            {
                switch (attributeType)
                {
                case FileAttributeType.Name:
                    attributeString = file.Name;
                    break;

                case FileAttributeType.Path:
                    attributeString = file.FullName;
                    break;

                case FileAttributeType.Attributes:
                    attributeString = EnumUtilities.ToString(file.Attributes);
                    break;

                default:
                    attributeString = string.Empty;
                    break;
                }
            }

            if (attributeString == null)
            {
                attributeString = string.Empty;
            }

            return(attributeString);
        }
Exemple #2
0
        /// <summary>
        /// Gets the string representation of a file attribute.
        /// </summary>
        /// <param name="attributeType">Type of the attribute.</param>
        /// <param name="file">The file to get the attribute for.</param>
        /// <returns>The file attribute as text.</returns>
        public static string GetAttribute(FileAttributeType attributeType, FileInfo file)
        {
            string attributeString = null;

            if (file != null)
            {
                switch (attributeType)
                {
                    case FileAttributeType.Name:
                        attributeString = file.Name;
                        break;

                    case FileAttributeType.Path:
                        attributeString = file.FullName;
                        break;

                    case FileAttributeType.Attributes:
                        attributeString = EnumUtilities.ToString(file.Attributes);
                        break;

                    default:
                        attributeString = string.Empty;
                        break;
                }
            }

            if (attributeString == null)
            {
                attributeString = string.Empty;
            }

            return attributeString;
        }
        public void Add(string name, FileAttributeType type, FileAttributeInfoFlags flags)
        {
            IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup(name);

            g_file_attribute_info_list_add(Handle, native_name, (int)type, (int)flags);
            GLib.Marshaller.Free(native_name);
        }
        public void DownloadFileAttribute_ToStream_Succeeds(FileAttributeType fileAttributeType, string expectedFileContent)
        {
            var node = this.GetNode(AuthenticatedTestContext.Inputs.SharedFile.Id);

            using Stream stream         = Context.Client.DownloadFileAttribute(node, fileAttributeType);
            using Stream expectedStream = new FileStream(GetAbsoluteFilePath(expectedFileContent), FileMode.Open, FileAccess.Read);
            AreStreamsEquivalent(stream, expectedStream);
        }
Exemple #5
0
 /// <summary>
 /// Sets the value.
 /// </summary>
 /// <param name="value">The value.</param>
 public void SetValue(double value)
 {
     ValueLong     = null;
     ValueDouble   = value;
     ValueDateTime = null;
     ValueString   = null;
     ValueType     = FileAttributeType.Double;
 }
Exemple #6
0
 /// <summary>
 /// Sets the value.
 /// </summary>
 /// <param name="value">The value.</param>
 public void SetValue(string value)
 {
     ValueLong     = null;
     ValueDouble   = null;
     ValueDateTime = null;
     ValueString   = value;
     ValueType     = FileAttributeType.String;
 }
        public void Instantiates_With_The_Given_Data(FileAttributeType type, int value)
        {
            var fa = default(FileAttribute);

            var ex = Record.Exception(() => fa = new FileAttribute(type, value));

            Assert.Null(ex);

            Assert.Equal(type, fa.Type);
            Assert.Equal(value, fa.Value);
        }
Exemple #8
0
        public void DownloadFileAttribute_ToStream_Succeeds(FileAttributeType fileAttributeType, string expectedFileContent)
        {
            var node = this.GetNode(((AuthenticatedTestContext)this.context).PermanentFilesNode);

            using (Stream stream = this.context.Client.DownloadFileAttribute(node, fileAttributeType))
            {
                using (Stream expectedStream = new FileStream(this.GetAbsoluteFilePath(expectedFileContent), FileMode.Open, FileAccess.Read))
                {
                    this.AreStreamsEquivalent(stream, expectedStream);
                }
            }
        }
Exemple #9
0
 public FileAttribute(string name, long?valueLong, double?valueDouble, DateTime?valueDateTime, string valueString, FileAttributeType valueType)
 {
     Name      = Name;
     ValueType = valueType;
     if (ValueType == FileAttributeType.Long)
     {
         ValueLong = valueLong;
     }
     else if (ValueType == FileAttributeType.Double)
     {
         ValueDouble = valueDouble;
     }
     else if (ValueType == FileAttributeType.DateTime)
     {
         ValueDateTime = valueDateTime;
     }
     else
     {
         ValueString = valueString;
     }
 }
Exemple #10
0
 /// <summary>
 ///     Returns the value of the specified attribute <paramref name="type"/>.
 /// </summary>
 /// <param name="type">The attribute to return.</param>
 /// <returns>The value of the specified attribute.</returns>
 public int?GetAttributeValue(FileAttributeType type)
 {
     return(AttributeList.FirstOrDefault(a => a.Type == type)?.Value);
 }
 /// <summary>
 /// Creates a new element attribute expression.
 /// </summary>
 /// <param name="fileAttribute">The file attribute.</param>
 public FileAttributeExpression(FileAttributeType fileAttribute)
 {
     _fileAttributeType = fileAttribute;
 }
Exemple #12
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="FileAttribute"/> class.
 /// </summary>
 /// <param name="type">The attribute type.</param>
 /// <param name="value">The attribute value.</param>
 public FileAttribute(FileAttributeType type, int value)
 {
     Type  = type;
     Value = value;
 }
 public Task <Stream> DownloadFileAttributeAsync(INode node, FileAttributeType fileAttributeType, CancellationToken?cancellationToken = null)
 {
     return(_client.DownloadFileAttributeAsync(node, fileAttributeType, cancellationToken));
 }
 public Stream DownloadFileAttribute(INode node, FileAttributeType fileAttributeType, CancellationToken?cancellationToken = null)
 {
     return(UnwrapException(() => _client.DownloadFileAttributeAsync(node, fileAttributeType, cancellationToken).Result));
 }
Exemple #15
0
 public Task <Stream> DownloadFileAttributeAsync(INode node, FileAttributeType fileAttributeType, CancellationToken?cancellationToken = null)
 {
     return(Task.Run(() => this.DownloadFileAttribute(node, fileAttributeType, cancellationToken)));
 }
Exemple #16
0
        /// <summary>
        /// Parses and expression to an expression tree.
        /// </summary>
        /// <param name="expression">Condition expression text.</param>
        /// <returns>A condition expression instance.</returns>
        public IConditionExpression Parse(string expression)
        {
            const int            DefaultExpressionLength = 128;
            IConditionExpression conditionExpression     = null;

            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }
            else if (expression.Trim().Length == 0)
            {
                throw new ArgumentException("expression");
            }

            List <IConditionExpression> nodes = new List <IConditionExpression>();

            StringReader reader = new StringReader(expression);

            StringBuilder expressionBuilder = new StringBuilder(DefaultExpressionLength);

            bool inString    = false;
            bool inAttribute = false;
            int  depth       = 0;

            int data = reader.Read();

            while (data > 0)
            {
                char ch     = (char)data;
                char nextCh = (char)reader.Peek();

                if (inString && ch != '\'')
                {
                    expressionBuilder.Append(ch);
                }
                else
                {
                    switch (ch)
                    {
                    case ' ':
                    case '\t':
                    case '\r':
                    case '\n':
                        // Eat whitespace
                        break;

                    case ExpressionPrefix:
                        CheckForInvalidOperator(expression, expressionBuilder);
                        if (nextCh == ExpressionStart)
                        {
                            inAttribute = true;
                            reader.Read();
                        }
                        break;

                    case '=':
                        if (nextCh == '=')
                        {
                            nodes.Add(new OperatorExpressionPlaceholder(BinaryExpressionOperator.Equal));
                            reader.Read();
                        }
                        else if (nextCh == '~')
                        {
                            nodes.Add(new OperatorExpressionPlaceholder(BinaryExpressionOperator.Matches));
                            reader.Read();
                        }
                        break;

                    case '!':
                        if (nextCh == '=')
                        {
                            nodes.Add(new OperatorExpressionPlaceholder(BinaryExpressionOperator.NotEqual));
                            reader.Read();
                        }
                        else
                        {
                            expressionBuilder.Append(ch);
                        }
                        break;

                    case ':':
                        nodes.Add(new OperatorExpressionPlaceholder(BinaryExpressionOperator.Contains));
                        reader.Read();
                        break;

                    case 'O':
                        if (nextCh == 'r' && !inAttribute && !inString)
                        {
                            nodes.Add(new OperatorExpressionPlaceholder(BinaryExpressionOperator.Or));
                            reader.Read();
                        }
                        else
                        {
                            expressionBuilder.Append(ch);
                        }
                        break;

                    case 'A':
                        if (nextCh == 'n' && !inAttribute && !inString)
                        {
                            reader.Read();
                            nextCh = (char)reader.Peek();
                            if (nextCh == 'd')
                            {
                                nodes.Add(new OperatorExpressionPlaceholder(BinaryExpressionOperator.And));
                                reader.Read();
                            }
                        }
                        else
                        {
                            expressionBuilder.Append(ch);
                        }
                        break;

                    case ExpressionEnd:
                        if (inAttribute)
                        {
                            string attribute = expressionBuilder.ToString();
                            expressionBuilder = new StringBuilder(DefaultExpressionLength);
                            ElementAttributeScope elementScope = ElementAttributeScope.Element;
                            bool isFileExpression = false;

                            int separatorIndex = attribute.LastIndexOf(ScopeSeparator);
                            if (separatorIndex > 0)
                            {
                                try
                                {
                                    string attributeScope = attribute.Substring(0, separatorIndex);
                                    attribute = attribute.Substring(separatorIndex + 1);

                                    if (attributeScope == FileAttributeScope)
                                    {
                                        isFileExpression = true;
                                    }
                                    else
                                    {
                                        elementScope = (ElementAttributeScope)
                                                       Enum.Parse(typeof(ElementAttributeScope), attributeScope);
                                    }
                                }
                                catch (ArgumentException ex)
                                {
                                    OnInvalidExpression(expression, "Unknown attribute scope: {0}", ex.Message);
                                }
                            }

                            if (isFileExpression)
                            {
                                FileAttributeType fileAttribute = FileAttributeType.None;

                                try
                                {
                                    fileAttribute = (FileAttributeType)
                                                    Enum.Parse(typeof(FileAttributeType), attribute);
                                }
                                catch (ArgumentException ex)
                                {
                                    OnInvalidExpression(expression, "Unknown attribute: {0}", ex.Message);
                                }

                                FileAttributeExpression attributeExpresion = new FileAttributeExpression(
                                    fileAttribute);
                                nodes.Add(attributeExpresion);
                            }
                            else
                            {
                                ElementAttributeType elementAttribute = ElementAttributeType.None;

                                try
                                {
                                    elementAttribute = (ElementAttributeType)
                                                       Enum.Parse(typeof(ElementAttributeType), attribute);
                                }
                                catch (ArgumentException ex)
                                {
                                    OnInvalidExpression(expression, "Unknown attribute: {0}", ex.Message);
                                }

                                ElementAttributeExpression attributeExpresion = new ElementAttributeExpression(
                                    elementAttribute, elementScope);
                                nodes.Add(attributeExpresion);
                            }

                            inAttribute = false;
                        }
                        else if (expressionBuilder.Length > 0 && nodes.Count > 0)
                        {
                            IConditionExpression innerExpression = nodes[nodes.Count - 1];
                            nodes.RemoveAt(nodes.Count - 1);

                            string unaryOperatorString = expressionBuilder.ToString().Trim();
                            expressionBuilder = new StringBuilder(DefaultExpressionLength);

                            UnaryExpressionOperator?unaryOperator = null;

                            if (unaryOperatorString == "!")
                            {
                                unaryOperator = UnaryExpressionOperator.Negate;
                            }
                            else
                            {
                                OnInvalidExpression(expression,
                                                    "Invalid operator {0}", unaryOperatorString);
                            }

                            UnaryOperatorExpression unaryOperatorExpression = new UnaryOperatorExpression(
                                unaryOperator.Value, innerExpression);

                            nodes.Add(unaryOperatorExpression);
                            depth--;
                        }
                        else
                        {
                            depth--;
                        }
                        break;

                    case ExpressionStart:
                        IConditionExpression nestedExpression       = null;
                        StringBuilder        childExpressionBuilder = new StringBuilder(DefaultExpressionLength);
                        data   = reader.Read();
                        ch     = (char)data;
                        nextCh = (char)reader.Peek();
                        depth++;
                        while (data > 0)
                        {
                            if (ch == ExpressionPrefix && nextCh == ExpressionStart)
                            {
                                inAttribute = true;
                                childExpressionBuilder.Append(ExpressionPrefix);
                                data = reader.Read();
                                childExpressionBuilder.Append(ExpressionStart);
                            }
                            else if (ch == ExpressionStart && !inAttribute)
                            {
                                depth++;
                                childExpressionBuilder.Append(ExpressionStart);
                            }
                            else if (nextCh == ExpressionEnd)
                            {
                                childExpressionBuilder.Append(ch);

                                if (inAttribute || depth > 1)
                                {
                                    if (inAttribute)
                                    {
                                        inAttribute = false;
                                    }
                                    else if (depth > 1)
                                    {
                                        depth--;
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }
                            else
                            {
                                childExpressionBuilder.Append(ch);
                            }

                            data   = reader.Read();
                            ch     = (char)data;
                            nextCh = (char)reader.Peek();
                        }

                        try
                        {
                            nestedExpression = Parse(childExpressionBuilder.ToString());
                        }
                        catch (ArgumentException)
                        {
                            OnInvalidExpression(expression);
                        }
                        nodes.Add(nestedExpression);
                        break;

                    case '\'':
                        if (inString)
                        {
                            if (nextCh == '\'')
                            {
                                expressionBuilder.Append(ch);
                                reader.Read();
                            }
                            else
                            {
                                string str = expressionBuilder.ToString();
                                expressionBuilder = new StringBuilder(DefaultExpressionLength);
                                StringExpression stringExpression = new StringExpression(str);
                                nodes.Add(stringExpression);
                                inString = false;
                            }
                        }
                        else
                        {
                            CheckForInvalidOperator(expression, expressionBuilder);
                            inString = true;
                        }

                        break;

                    default:
                        expressionBuilder.Append(ch);
                        break;
                    }
                }

                data = reader.Read();
            }

            if (inString)
            {
                OnInvalidExpression(expression, "Expected '");
            }
            else if (inAttribute || depth > 0)
            {
                OnInvalidExpression(expression, "Expected )");
            }
            else if (depth < 0)
            {
                OnInvalidExpression(expression, "Unmatched )");
            }

            //
            // Assembly the flat list of expressions and expression placeholders into an
            // expression tree.
            //
            conditionExpression = AssembleExpressionTree(nodes.AsReadOnly(), expression);

            return(conditionExpression);
        }
Exemple #17
0
        public void GetAttributeValue_Returns_Value_When_Value(int code, string filename, long size, string extension, FileAttributeType type, int value)
        {
            var list = new List <FileAttribute>()
            {
                new FileAttribute(type, value)
            };

            var f = new File(code, filename, size, extension, 1, list);

            Assert.Equal(value, f.GetAttributeValue(type));
        }
Exemple #18
0
 public FileAttribute(int id, FileAttributeType type, string handle)
 {
     this.Id     = id;
     this.Type   = type;
     this.Handle = handle;
 }
Exemple #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FileAttribute"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="value">The value.</param>
 public FileAttribute(string name, string value)
 {
     Name        = name;
     ValueString = value;
     ValueType   = FileAttributeType.String;
 }
Exemple #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FileAttribute"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="value">The value.</param>
 public FileAttribute(string name, DateTime value)
 {
     Name          = name;
     ValueDateTime = value;
     ValueType     = FileAttributeType.DateTime;
 }
Exemple #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FileAttribute"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="value">The value.</param>
 public FileAttribute(string name, double value)
 {
     Name        = name;
     ValueDouble = value;
     ValueType   = FileAttributeType.Double;
 }
Exemple #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FileAttribute"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="value">The value.</param>
 public FileAttribute(string name, long value)
 {
     Name      = name;
     ValueLong = value;
     ValueType = FileAttributeType.Long;
 }
Exemple #23
0
 /// <summary>
 /// Creates a new element attribute expression.
 /// </summary>
 /// <param name="fileAttribute">The file attribute.</param>
 public FileAttributeExpression(FileAttributeType fileAttribute)
 {
     _fileAttributeType = fileAttribute;
 }
Exemple #24
0
 public FileAttribute(int id, FileAttributeType type, string handle)
 {
     Id     = id;
     Type   = type;
     Handle = handle;
 }