Exemplo n.º 1
0
        private bool TrySplitEntitiesList(string input, Hypermedia parent, out List <string> entities)
        {
            entities = new List <string>();

            string tmpInput = input;

            tmpInput += "\r\n";
            bool isProcessed = false;

            while (!isProcessed)
            {
                bool   isStringValid = false;
                string toReturn      = string.Empty;

                string type = new string(tmpInput.Skip(1).TakeWhile(s => s != ':').ToArray());
                switch (type)
                {
                case "file":
                    toReturn = new string(tmpInput.SkipWhile(s => s != '[').Take(1).ToArray());
                    do
                    {
                        isStringValid = File.IsSerializedStringValid(toReturn, parent);
                        if ((new string(tmpInput.TakeWhile(s => s != '[').ToArray()) + toReturn).Length == tmpInput.Length)
                        {
                            return(false);
                        }
                        if (!isStringValid)
                        {
                            toReturn += new string(tmpInput.Skip(new string(tmpInput.TakeWhile(s => s != '[').ToArray()).Length + toReturn.Length).Take(1).ToArray());
                        }
                    }while (!isStringValid);
                    break;

                case "directory":
                    toReturn = new string(tmpInput.SkipWhile(s => s != '[').Take(1).ToArray());
                    do
                    {
                        isStringValid = Directory.IsSerializedStringValid(toReturn, parent);
                        if ((new string(tmpInput.TakeWhile(s => s != '[').ToArray()) + toReturn).Length == tmpInput.Length)
                        {
                            return(false);
                        }
                        if (!isStringValid)
                        {
                            toReturn += new string(tmpInput.Skip(new string(tmpInput.TakeWhile(s => s != '[').ToArray()).Length + toReturn.Length).Take(1).ToArray());
                        }
                    }while (!isStringValid);
                    break;

                case "hypermedia":
                    toReturn = new string(tmpInput.SkipWhile(s => s != '[').Take(1).ToArray());
                    do
                    {
                        var versions = SerializationVersionTools.GetVersions();
                        foreach (var v in versions)
                        {
                            isStringValid = v.IsSerializedStringValid(toReturn, parent);
                            if (isStringValid)
                            {
                                break;
                            }
                        }

                        if ((new string(tmpInput.TakeWhile(s => s != '[').ToArray()) + toReturn).Length == tmpInput.Length)
                        {
                            return(false);
                        }
                        if (!isStringValid)
                        {
                            toReturn += new string(tmpInput.Skip(new string(tmpInput.TakeWhile(s => s != '[').ToArray()).Length + toReturn.Length).Take(1).ToArray());
                        }
                    }while (!isStringValid);
                    break;

                default:
                    return(false);
                }
                string entity = new string(tmpInput.TakeWhile(s => s != '[').ToArray()) + toReturn;
                entities.Add(entity);
                int il = tmpInput.Length;
                tmpInput = tmpInput.Remove(0, entity.Length + 3);
                if (tmpInput == string.Empty)
                {
                    isProcessed = true;
                }
            }
            if (entities.Count <= 0)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        private List <string> SplitEntitiesList(string input, Hypermedia parent)
        {
            List <string> entities = new List <string>();

            string tmpInput = input;

            tmpInput += "\r\n";
            bool isProcessed = false;

            while (!isProcessed)
            {
                bool   isStringValid = false;
                string toReturn      = string.Empty;

                string type = new string(tmpInput.Skip(1).TakeWhile(s => s != ':').ToArray());
                switch (type)
                {
                case "file":
                    toReturn = new string(tmpInput.SkipWhile(s => s != '[').Take(1).ToArray());
                    do
                    {
                        isStringValid = File.IsSerializedStringValid(toReturn, parent);
                        string tmpEntity = new string(tmpInput.TakeWhile(s => s != '[').ToArray()) + toReturn;
                        if (tmpEntity.Length == tmpInput.Length)
                        {
                            throw new ArgumentException("Possible serialization error encountered. Unexpected input.", "input");
                        }
                        if (!isStringValid)
                        {
                            toReturn += new string(tmpInput.Skip(new string(tmpInput.TakeWhile(s => s != '[').ToArray()).Length + toReturn.Length).Take(1).ToArray());
                        }
                    }while (!isStringValid);
                    break;

                case "directory":
                    toReturn = new string(tmpInput.SkipWhile(s => s != '[').Take(1).ToArray());
                    do
                    {
                        isStringValid = Directory.IsSerializedStringValid(toReturn, parent);
                        string tmpEntity = new string(tmpInput.TakeWhile(s => s != '[').ToArray()) + toReturn;
                        if (tmpEntity.Length == tmpInput.Length)
                        {
                            throw new ArgumentException("Possible serialization error encountered. Unexpected input.", "input");
                        }
                        if (!isStringValid)
                        {
                            toReturn += new string(tmpInput.Skip(new string(tmpInput.TakeWhile(s => s != '[').ToArray()).Length + toReturn.Length).Take(1).ToArray());
                        }
                    }while (!isStringValid);
                    break;

                case "hypermedia":
                    toReturn = new string(tmpInput.SkipWhile(s => s != '[').Take(1).ToArray());
                    do
                    {
                        var versions = SerializationVersionTools.GetVersions();
                        foreach (var v in versions)
                        {
                            isStringValid = v.IsSerializedStringValid(toReturn, parent);
                            if (isStringValid)
                            {
                                break;
                            }
                        }

                        string tmpEntity = new string(tmpInput.TakeWhile(s => s != '[').ToArray()) + toReturn;
                        if (tmpEntity.Length == tmpInput.Length)
                        {
                            throw new ArgumentException("Possible serialization error encountered. Unexpected input.", "input");
                        }
                        if (!isStringValid)
                        {
                            toReturn += new string(tmpInput.Skip(new string(tmpInput.TakeWhile(s => s != '[').ToArray()).Length + toReturn.Length).Take(1).ToArray());
                        }
                    }while (!isStringValid);
                    break;

                default:
                    throw new ArgumentException("Possible serialization error encountered. Unexpected type", "input");
                }
                string entity = new string(tmpInput.TakeWhile(s => s != '[').ToArray()) + toReturn;
                entities.Add(entity);
                tmpInput = tmpInput.Remove(0, entity.Length + 3);
                if (tmpInput == string.Empty)
                {
                    isProcessed = true;
                }
            }
            return(entities);
        }