Пример #1
0
        public static ICommand Build(List <Token> tokens, bool forced)
        {
            TokenType type = tokens[0].GetTokenType();

            tokens.RemoveAt(0);

            if (tokens.Where(t => t.GetTokenType().Equals(TokenType.To)).Count() > 1)
            {
                throw new SyntaxErrorException("ERROR! In " + GetName(type) + " command keyword 'to' occurs too many times.");
            }

            List <Token> part1  = new List <Token>();
            List <Token> part2  = new List <Token>();
            bool         pastTo = false;

            foreach (Token tok in tokens)
            {
                if (tok.GetTokenType().Equals(TokenType.To))
                {
                    pastTo = true;
                }
                else
                {
                    if (pastTo)
                    {
                        part2.Add(tok);
                    }
                    else
                    {
                        part1.Add(tok);
                    }
                }
            }

            if (part2.Count == 0)
            {
                throw new SyntaxErrorException("ERROR! Command " + GetName(type) + " is too short and do not contain all necessary information.");
            }

            IStringable expression2 = StringableBuilder.Build(part2);

            if (expression2.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Second part of command " + GetName(type) + " cannot be read as text.");
            }

            if (part1.Count == 0)
            {
                return(BuildSimple(type, expression2, forced));
            }
            else
            {
                IListable expression1 = ListableBuilder.Build(part1);
                if (expression1.IsNull())
                {
                    throw new SyntaxErrorException("ERROR! First part of command " + GetName(type) + " cannot be read as list.");
                }
                return(BuildComplex(type, expression1, expression2, forced));
            }
        }
Пример #2
0
        public static IBoolable BuildStrStr(string name, List <Argument> args)
        {
            if (args.Count != 2)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 2 text arguments.");
            }

            IStringable istr1 = StringableBuilder.Build(args[0].tokens);
            IStringable istr2 = StringableBuilder.Build(args[1].tokens);

            if (istr1.IsNull())
            {
                throw new SyntaxErrorException("ERROR! First argument of function " + name + " cannot be read as text.");
            }
            if (istr2.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Second argument of function " + name + " cannot be read as text.");
            }

            if (name.Equals("existinside") || name.Equals("existsinside"))
            {
                return(new FuncExistinside(istr1, istr2));
            }
            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
Пример #3
0
        public static IBoolable BuildLisStr(string name, List <Argument> args)
        {
            if (args.Count != 2)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 2 arguments: one list and one text.");
            }

            IListable   ilis = ListableBuilder.Build(args[0].tokens);
            IStringable istr = StringableBuilder.Build(args[1].tokens);

            if (ilis.IsNull())
            {
                throw new SyntaxErrorException("ERROR! First argument of function " + name + " cannot be read as list.");
            }
            if (istr.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Second argument of function " + name + " cannot be read as text.");
            }

            if (name.Equals("contain") || name.Equals("contains"))
            {
                return(new FuncContain(ilis, istr));
            }
            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
Пример #4
0
        public static IBoolable BuildIn(List <Token> tokens)
        {
            int index = tokens.TakeWhile(x => !x.GetTokenType().Equals(TokenType.In)).Count();

            if (index == 0 || index == tokens.Count - 1)
            {
                return(null);
            }

            List <Token> leftTokens  = tokens.GetRange(0, index);
            List <Token> rightTokens = tokens.GetRange(index + 1, tokens.Count - index - 1);

            IStringable istr = StringableBuilder.Build(leftTokens);

            if (istr.IsNull())
            {
                return(null);
            }

            IListable ilis = ListableBuilder.Build(rightTokens);

            if (ilis.IsNull())
            {
                return(null);
            }

            return(new In(istr, ilis));
        }
Пример #5
0
        public static ITimeable BuildStr(string name, List <Argument> args)
        {
            if (args.Count != 1)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 1 text argument.");
            }

            IStringable istr = StringableBuilder.Build(args[0].tokens);

            if (istr.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Argument of function " + name + " cannot be read as text.");
            }

            if (name.Equals("access"))
            {
                return(new FuncAccess(istr));
            }
            else if (name.Equals("creation"))
            {
                return(new FuncCreation(istr));
            }
            else if (name.Equals("modification"))
            {
                return(new FuncModification(istr));
            }

            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
Пример #6
0
        public static INumerable BuildStr(string name, List <Argument> args)
        {
            if (args.Count != 1)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 1 text argument.");
            }

            IStringable istr = StringableBuilder.Build(args[0].tokens);

            if (istr.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Argument of function " + name + " cannot be read as text.");
            }

            if (name.Equals("number"))
            {
                return(new FuncNumber(istr));
            }
            if (name.Equals("length"))
            {
                return(new FuncLength(istr));
            }
            if (name.Equals("year"))
            {
                return(new FuncYear(istr));
            }
            if (name.Equals("size"))
            {
                return(new FuncSize(istr));
            }
            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
Пример #7
0
        public static IBoolable BuildLike(List <Token> tokens)
        {
            int index = tokens.TakeWhile(x => !x.GetTokenType().Equals(TokenType.Like)).Count();

            if (index == 0 || index == tokens.Count - 1)
            {
                return(null);
            }

            List <Token> leftTokens  = tokens.GetRange(0, index);
            List <Token> rightTokens = tokens.GetRange(index + 1, tokens.Count - index - 1);

            IStringable istr = StringableBuilder.Build(leftTokens);

            if (istr.IsNull())
            {
                return(null);
            }

            if (rightTokens.Count == 1 && rightTokens[0].GetTokenType().Equals(TokenType.StringConstant))
            {
                string phrase = rightTokens[0].GetContent();
                CheckLikePhraseCorrectness(phrase);
                return(new Like(istr, phrase));
            }
            else
            {
                return(null);
            }
        }
Пример #8
0
        public static IStringable BuildStrStr(string name, List <Argument> args)
        {
            if (args.Count != 2)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 2 arguments: two texts.");
            }

            IStringable istr1 = StringableBuilder.Build(args[0].tokens);
            IStringable istr2 = StringableBuilder.Build(args[1].tokens);

            if (istr1.IsNull())
            {
                throw new SyntaxErrorException("ERROR! First argument of function " + name + " cannot be read as text.");
            }
            if (istr2.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Second argument of function " + name + " cannot be read as text.");
            }

            if (name.Equals("beforetext") || name.Equals("textbefore"))
            {
                return(new FuncBeforeText(istr1, istr2));
            }
            else if (name.Equals("aftertext") || name.Equals("textafter"))
            {
                return(new FuncAfterText(istr1, istr2));
            }
            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
Пример #9
0
        public static IStringable BuildStringTernary(List <Token> tokens)
        {
            IBoolable condition = BoolableBuilder.Build(GetTernaryCondition(tokens));

            if (condition.IsNull())
            {
                return(null);
            }

            IStringable confirmationCase = StringableBuilder.Build(GetTernaryConfirmation(tokens));

            if (confirmationCase.IsNull())
            {
                return(null);
            }

            IStringable negationCase = StringableBuilder.Build(GetTernaryNegation(tokens));

            if (negationCase.IsNull())
            {
                return(null);
            }

            return(new StringTernary(condition, confirmationCase, negationCase));
        }
Пример #10
0
        public static IStringable BuildStrNumNum(string name, List <Argument> args)
        {
            if (args.Count != 3)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 3 arguments: one text and two numbers.");
            }

            IStringable istr = StringableBuilder.Build(args[0].tokens);
            INumerable  inu1 = NumerableBuilder.Build(args[1].tokens);
            INumerable  inu2 = NumerableBuilder.Build(args[2].tokens);

            if (istr.IsNull())
            {
                throw new SyntaxErrorException("ERROR! First argument of function " + name + " cannot be read as text.");
            }
            if (inu1.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Second argument of function " + name + " cannot be read as number.");
            }
            if (inu2.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Third argument of function " + name + " cannot be read as number.");
            }

            if (name.Equals("substring"))
            {
                return(new FuncSubstring__3args(istr, inu1, inu2));
            }
            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
Пример #11
0
        public static IStringable BuildStrNum(string name, List <Argument> args)
        {
            if (args.Count != 2)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 2 arguments: one text and one number.");
            }

            IStringable istr = StringableBuilder.Build(args[0].tokens);
            INumerable  inu  = NumerableBuilder.Build(args[1].tokens);

            if (istr.IsNull())
            {
                throw new SyntaxErrorException("ERROR! First argument of function " + name + " cannot be read as text.");
            }
            if (inu.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Second argument of function " + name + " cannot be read as number.");
            }

            if (name.Equals("filled") || name.Equals("fill"))
            {
                return(new FuncFilled(istr, inu));
            }
            else if (name.Equals("repeat") || name.Equals("repeated"))
            {
                return(new FuncRepeat(istr, inu));
            }
            else if (name.Equals("substring"))
            {
                return(new FuncSubstring__2args(istr, inu));
            }
            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
Пример #12
0
 public MoveToAs(IListable list, IStringable destination, IStringable newName, bool forced)
 {
     this.list        = list;
     this.destination = destination;
     this.newName     = newName;
     this.forced      = forced;
 }
Пример #13
0
        private static INumerable BuildCountInside(List <Token> tokens)
        {
            int index = TokenGroups.IndexOfTokenOutsideBrackets(tokens, TokenType.Inside);

            if (index == tokens.Count - 1)
            {
                throw new SyntaxErrorException("ERROR! Expression 'count inside' do not contain information about referent location.");
            }

            if (index == 0)
            {
                throw new SyntaxErrorException("ERROR! Expression 'count inside' do not contain information about referent list of elements.");
            }

            IListable ilist = ListableBuilder.Build(tokens.Take(index).ToList());

            if (ilist.IsNull())
            {
                return(null);
            }

            IStringable istr = StringableBuilder.Build(tokens.Skip(index + 1).ToList());

            if (istr.IsNull())
            {
                return(null);
            }

            return(new CountInside(ilist, istr));
        }
Пример #14
0
 /// <summary>
 /// dehydrates hydrateable into the type prefix format
 /// </summary>
 /// <param name="hyd"></param>
 /// <returns></returns>
 public string Dehydrate(IStringable hyd)
 {
     if (hyd == null)
         return null;
     
     string data = hyd.Dehydrate();
     return LengthEncoder.LengthEncodeList(hyd.GetType().AssemblyQualifiedName, data);
 }
Пример #15
0
        public string DehydrateValue(object obj, IGraph uow)
        {
            Condition.Requires(obj).IsNotNull();
            var         name = obj.GetType().AssemblyQualifiedName;
            IStringable s    = obj as IStringable;
            var         data = s.GetValue();

            return(LengthEncoder.LengthEncodeList(name, data));
        }
        // Token: 0x060063D6 RID: 25558 RVA: 0x001531CC File Offset: 0x001513CC
        internal static string ToString(object obj)
        {
            IStringable stringable = obj as IStringable;

            if (stringable != null)
            {
                return(stringable.ToString());
            }
            return(obj.ToString());
        }
Пример #17
0
        /// <summary>
        /// dehydrates hydrateable into the type prefix format
        /// </summary>
        /// <param name="hyd"></param>
        /// <returns></returns>
        public string Dehydrate(IStringable hyd)
        {
            if (hyd == null)
            {
                return(null);
            }

            string data = hyd.Dehydrate();

            return(LengthEncoder.LengthEncodeList(hyd.GetType().AssemblyQualifiedName, data));
        }
Пример #18
0
 public void Array_Stringable()
 {
     IStringable[] a = new IStringable[] {
         Windows.Data.Json.JsonValue.CreateNumberValue(3),
         Windows.Data.Json.JsonValue.CreateNumberValue(4),
         Windows.Data.Json.JsonValue.CreateNumberValue(5.0)
     };
     IStringable[] b = new IStringable[a.Length];
     IStringable[] c;
     IStringable[] d = Tests.Array16(a, b, out c);
     Assert.True(AllEqual(a, b, c, d));
 }
Пример #19
0
        internal static string ToString(object obj)
        {
            // Check whether the type implements IStringable.
            IStringable stringableType = obj as IStringable;

            if (stringableType != null)
            {
                return(stringableType.ToString());
            }

            return(obj.ToString());
        }
Пример #20
0
        public static ICommand Build(List <Token> tokens, bool forced)
        {
            TokenType type = tokens[0].GetTokenType();

            tokens.RemoveAt(0);

            int toIndex = TokenGroups.IndexOfTokenOutsideBrackets(tokens, TokenType.To);
            int asIndex = TokenGroups.IndexOfTokenOutsideBrackets(tokens, TokenType.As);

            if (asIndex < toIndex)
            {
                return(null);
            }
            if (toIndex == asIndex - 1)
            {
                throw new SyntaxErrorException("ERROR! Command " + GetName(type) + " do not have definition of destination directory.");
            }
            if (asIndex == tokens.Count - 1)
            {
                throw new SyntaxErrorException("ERROR! Command " + GetName(type) + " do not have definition of new name for file/directory.");
            }

            List <Token> listTokens        = tokens.Take(toIndex).ToList();
            List <Token> destinationTokens = tokens.GetRange(toIndex + 1, asIndex - toIndex - 1);
            List <Token> nameTokens        = tokens.Skip(asIndex + 1).ToList();

            IStringable destination = StringableBuilder.Build(destinationTokens);

            if (destination.IsNull())
            {
                throw new SyntaxErrorException("ERROR! In command " + GetName(type) + " definition of destination directory cannot be read as text.");
            }
            IStringable name = StringableBuilder.Build(nameTokens);

            if (name.IsNull())
            {
                throw new SyntaxErrorException("ERROR! In command " + GetName(type) + " definition of new name for file/directory cannot be read as text.");
            }

            if (listTokens.Count == 0)
            {
                return(BuildSimple(type, destination, name, forced));
            }
            else
            {
                IListable list = ListableBuilder.Build(listTokens);
                if (list.IsNull())
                {
                    throw new SyntaxErrorException("ERROR! In command " + GetName(type) + " definition of list of files and directories is not correct.");
                }
                return(BuildComplex(type, list, destination, name, forced));
            }
        }
Пример #21
0
 public override string ToString()
 {
     if (AppDomain.IsAppXModel())
     {
         IStringable stringable = this as IStringable;
         if (stringable != null)
         {
             return(stringable.ToString());
         }
     }
     return(base.ToString());
 }
Пример #22
0
        public static IStringable BuildStr(string name, List <Argument> args)
        {
            if (args.Count != 1)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 1 text argument.");
            }

            IStringable istr = StringableBuilder.Build(args[0].tokens);

            if (istr.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Argument of function " + name + " cannot be read as text.");
            }

            if (name.Equals("upper") || name.Equals("toupper"))
            {
                return(new FuncUpper(istr));
            }
            else if (name.Equals("lower") || name.Equals("tolower"))
            {
                return(new FuncLower(istr));
            }
            else if (name.Equals("digits"))
            {
                return(new FuncDigits(istr));
            }
            else if (name.Equals("letters"))
            {
                return(new FuncLetters(istr));
            }
            else if (name.Equals("trim"))
            {
                return(new FuncTrim(istr));
            }
            else if (name.Equals("name"))
            {
                return(new FuncName(istr));
            }
            else if (name.Equals("fullname"))
            {
                return(new FuncFullname(istr));
            }
            else if (name.Equals("extension"))
            {
                return(new FuncExtension(istr));
            }

            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
Пример #23
0
        private static ICommand BuildComplex(TokenType type, IListable ilist, IStringable destination, IStringable newName, bool forced)
        {
            switch (type)
            {
            case TokenType.Copy:
                return(new CopyToAs(ilist, destination, newName, forced));

            case TokenType.Cut:
                return(new MoveToAs(ilist, destination, newName, forced));

            case TokenType.Move:
                return(new MoveToAs(ilist, destination, newName, forced));
            }
            throw new SyntaxErrorException("ERROR! Command not indentified."); // this is never thrown
        }
Пример #24
0
        public override string ToString()
        {
            IStringable stringable = this as IStringable;

            if (stringable != null)
            {
                return(stringable.ToString());
            }
            IntPtr redirectedToStringMd = this.GetRedirectedToStringMD();

            if (redirectedToStringMd == IntPtr.Zero)
            {
                return(base.ToString());
            }
            return(this.RedirectToString(redirectedToStringMd));
        }
Пример #25
0
        private static ICommand BuildSimple(TokenType type, IStringable destination, bool forced)
        {
            switch (type)
            {
            case TokenType.Copy:
                return(new CopyTo(new StringVariableRefer("this"), destination, forced));

            case TokenType.Cut:
                return(new MoveTo(new StringVariableRefer("this"), destination, forced));

            case TokenType.Move:
                return(new MoveTo(new StringVariableRefer("this"), destination, forced));

            case TokenType.Rename:
                return(new RenameTo(new StringVariableRefer("this"), destination, forced));
            }
            throw new SyntaxErrorException("ERROR! Command not indentified."); // this is never thrown
        }
Пример #26
0
        // functions are grouped by their arguments
        // every set of arguments is one method below

        public static IBoolable BuildStr(string name, List <Argument> args)
        {
            if (args.Count != 1)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 1 text argument.");
            }

            IStringable istr = StringableBuilder.Build(args[0].tokens);

            if (istr.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Argument of function " + name + " cannot be read as text.");
            }
            if (name.Equals("exist") || name.Equals("exists"))
            {
                return(new FuncExist(istr));
            }
            else if (name.Equals("empty") || name.Equals("emptydirectory"))
            {
                return(new FuncEmpty(istr));
            }
            else if (name.Equals("iscorrect"))
            {
                return(new FuncIscorrect(istr));
            }
            else if (name.Equals("isdirectory"))
            {
                return(new FuncIsdirectory(istr));
            }
            else if (name.Equals("isfile"))
            {
                return(new FuncIsfile(istr));
            }
            else if (name.Equals("hidden"))
            {
                return(new FuncHidden(istr));
            }
            else if (name.Equals("readonly"))
            {
                return(new FuncReadonly(istr));
            }

            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
Пример #27
0
        //====================================================================
        // Overrides ToString() to make sure we call to IStringable if the
        // COM object implements it in the case of weakly typed RCWs
        //====================================================================
        public override string ToString()
        {
            //
            // Only do the IStringable cast when running under AppX for better compat
            // Otherwise we could do a IStringable cast in classic apps which could introduce
            // a thread transition which would lead to deadlock
            //
            if (AppDomain.IsAppXModel())
            {
                // Check whether the type implements IStringable.
                IStringable stringableType = this as IStringable;
                if (stringableType != null)
                {
                    return(stringableType.ToString());
                }
            }

            return(base.ToString());
        }
Пример #28
0
        internal static string ToString(object obj)
        {
            IGetProxyTarget proxy = obj as IGetProxyTarget;

            if (proxy != null)
            {
                obj = proxy.GetTarget();
            }

            // Check whether the type implements IStringable.
            IStringable stringableType = obj as IStringable;

            if (stringableType != null)
            {
                return(stringableType.ToString());
            }

            return(obj.ToString());
        }
Пример #29
0
        public object HydrateValue(string nodeText, IGraph uow)
        {
            var list = LengthEncoder.LengthDecodeList(nodeText);

            Condition.Requires(list).HasLength(2);
            var typeName = list.ElementAt(0);
            var serData  = list.ElementAt(1);

            //instantiate the type, uninitialized
            Type type = TheTypeLocator.Instance.Locator.FindAssemblyQualifiedType(typeName);
            var  obj  = ReflectionUtil.CreateUninitializedObject(type);

            //since it's stringable, we use stringable's parsing to initialize
            IStringable s = obj as IStringable;

            s.Parse(serData);

            return(obj);
        }
Пример #30
0
        public override string ToString()
        {
            // Check whether the type implements IStringable.
            IStringable stringableType = this as IStringable;

            if (stringableType != null)
            {
                return(stringableType.ToString());
            }
            else
            {
                IntPtr pMD = GetRedirectedToStringMD();

                if (pMD == IntPtr.Zero)
                {
                    return(base.ToString());
                }

                return(RedirectToString(pMD));
            }
        }
Пример #31
0
        public static ICommand Build(List <Token> tokens)
        {
            string name = tokens[0].GetContent();

            tokens.RemoveAt(0);
            tokens.RemoveAt(0);

            List <Token> indexTokens = new List <Token>();

            while (tokens.First().GetTokenType() != TokenType.SquareBracketOff)
            {
                indexTokens.Add(tokens.First());
                tokens.RemoveAt(0);
            }
            tokens.RemoveAt(0);

            INumerable index = NumerableBuilder.Build(indexTokens);

            if (index.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Index of element of list " + name + " cannot be read as number.");
            }
            if (tokens.First().GetTokenType() != TokenType.Equals)
            {
                return(null);
            }

            tokens.RemoveAt(0);

            IStringable newValue = StringableBuilder.Build(tokens);

            if (newValue.IsNull())
            {
                return(null);
            }

            return(new ListElementDeclaration(name, newValue, index));
        }
 public override IDecorationOf<IStringable> ApplyThisDecorationTo(IStringable thing)
 {
     return new FileableStringableDecoration(thing);
 }
Пример #33
0
        public LengthDecoration(IStringable decorated)
            : base(decorated)
        {

        }
 public FileableStringableDecoration(IStringable decorated)
     : base(decorated)
 {
 }
 public override IDecorationOf<IStringable> ApplyThisDecorationTo(IStringable thing)
 {
     return new EncryptedStringableDecoration(thing, this.CipherPair);
 }
 public EncryptedStringableDecoration(IStringable decorated, SymmetricCipherPair cipherPair)
     : base(decorated)
 {
     Condition.Requires(cipherPair).IsNotNull();
     this.CipherPair = cipherPair;
 }