Exemplo n.º 1
0
        internal static DebuggingFileSession Generate(params String[] args)
        {
            // Parse input
            var model = InputModel.Parse(args);

            // Parse procedures
            ProcedureDefinition[] procedures;
            try
            {
                using (var sr = new StreamReader(model.FileName))
                    procedures = ProcedureParser.Parse(sr).ToArray();
            }
            catch (RedisClientException rcex)
            {
                throw new SyntaxException(String.Format("The file \"{0}\" is not a valid vtortola.RedisClient procedures files or there is a syntax problem in it.", model.FileName), rcex);
            }

            var procedure = procedures.SingleOrDefault(p => p.Name.Equals(model.Procedure, StringComparison.InvariantCultureIgnoreCase));

            if (procedure == null)
            {
                throw new SyntaxException(String.Format("Cannot find the specified procedure '{0}' in '{1}'", model.Procedure, model.FileName));
            }

            // generate temporary LUA file with the procedure content
            return(new DebuggingFileSession(model, procedure));
        }
Exemplo n.º 2
0
        private IEnumerable <Command> ValidateOfCreate(ProcedureParser context, string target, string subTarget)
        {
            List <Command>     ret        = new List <Command>();
            CustomPath         path       = new CustomPath(subTarget);
            IProcedureParsable tempTarget = CustomPath.FindAssetWithPath(path);

            if (tempTarget != null)
            {
                Debug.Log($"{path} already exists.");
                return(ret);
            }
            else
            {
                List <string> tempTargets = CustomPath.FindAssetOnlyName(path);
                if (tempTargets.Count > 2)
                {
                    Debug.Log($"{path} : have more than one.");
                    ret.Add(new Command(DefaultCommandType.Log, $"{path} : have more than one.", $"Create {target} in {subTarget}"));
                    return(ret);
                }
                else if (tempTargets.Count == 0)
                {
                    return(null);
                }
                else
                {
                    ret.Add(new Command(DefaultCommandType.Move, tempTargets[0], subTarget));
                    context.ChangeAllCommandPath(path.FilePath, tempTargets[0]);
                    return(ret);
                }
            }
        }
Exemplo n.º 3
0
        private IEnumerable <Command> ReactionOfMove(ProcedureParser context, string target, string subTarget)
        {
            CustomPath targetPath = new CustomPath(target), subTargetPath = new CustomPath(subTarget);

            AssetDatabase.MoveAsset(targetPath.FilePath, subTargetPath.FilePath);
            context.ChangeAllCommandPath(targetPath.FilePath, subTargetPath.FilePath);
            return(null);
        }
Exemplo n.º 4
0
 public void FailsOnMissingEndProc_2()
 {
     var procedure = ProcedureParser.Parse(new StringReader(@"
            proc AddStore($key, a, b)
             local result = a + b
             redis.call('SET', key, result) endproc
     ")).Single();
 }
Exemplo n.º 5
0
 public void FailsOnWrongKeyParameterNaming_4()
 {
     var procedure = ProcedureParser.Parse(new StringReader(@"
            proc AddStore($key, a, b])
             local result = a + b
             redis.call('SET', key, result)
         endproc
     ")).Single();
 }
Exemplo n.º 6
0
 public void FailsOnBadParameterDefinition_DuplicateParameters_2()
 {
     var procedure = ProcedureParser.Parse(new StringReader(@"
            proc AddStore ($key, key, a)
             local result = a + b
             redis.call('SET', key, result)
         endproc
     ")).Single();
 }
Exemplo n.º 7
0
        private static IEnumerable <Command> ValidateOfSet(ProcedureParser context, string target, string subTarget)
        {
            List <Command> ret = new List <Command>();

            ret.Add(new Command(DefaultCommandType.Set, target, subTarget));
            CustomPath         path       = new CustomPath(target);
            IProcedureParsable tempTarget = CustomPath.FindAssetWithPath(path);

            if (tempTarget == null)
            {
                if (context.WillBeCreated(new CustomPath(path.FilePath)))
                {
                    Command buff = ret[0];
                    buff.PastValue = Command.NaN;
                    ret[0]         = buff;
                    return(ret);
                }
                ret.Clear();
                ret.Add(new Command(DefaultCommandType.Log, "CannotFoundTarget", $"Set {target} into {subTarget}"));
                return(ret);
            }
            if (path.FromLast(1).StartsWith(CustomPath.RefPrefix))
            {
                string tempValue = tempTarget.Get($"{path.FromLast(1)}/{path.FromLast(0)}");
                if (tempValue == subTarget)
                {
                    ret.Clear();
                }
                else
                {
                    Command buff = ret[0];
                    buff.PastValue = tempValue;
                    ret[0]         = buff;
                }
            }
            else
            {
                string tempValue = tempTarget.Get(path.FromLast(0));
                if (tempValue == subTarget)
                {
                    ret.Clear();
                }
                else
                {
                    Command buff = ret[0];
                    buff.PastValue = tempValue;
                    ret[0]         = buff;
                }
            }
            return(ret);
        }
Exemplo n.º 8
0
        private IEnumerable <Command> ReactionOfCreate(ProcedureParser context, string target, string subTarget)
        {
            List <Command>     ret         = new List <Command>();
            IProcedureParsable targetAsset = CreateNewObject(target);
            CustomPath         targetPath  = new CustomPath(subTarget);
            CustomPath         assetPath   = null;

            {
                int altIndex = 0;
                for (; altIndex < targetPath.Length; altIndex++)
                {
                    if (targetPath.FromLast(altIndex).Contains(CustomPath.ExtensionDiff))
                    {
                        break;
                    }
                }
                assetPath = targetPath.GenerateHigherPath(altIndex);
            }
            Debug.LogWarning(assetPath?.FullPath);

            CustomPath tempPath = new CustomPath(Empty);

            for (int i = 0; i < assetPath.Length - 1; i++)
            {
                tempPath = tempPath.GenerateLowerPath(assetPath[i]);
                if (!AssetDatabase.IsValidFolder(tempPath.FullPath))
                {
                    Debug.Log($"{tempPath} creating directory");
                    AssetDatabase.CreateFolder(tempPath.GenerateHigherPath(1).FullPath, tempPath.FromLast(0));
                }
            }
            if (targetAsset is ScriptableObject)
            {
                AssetDatabase.CreateAsset(targetAsset as ScriptableObject, assetPath.FullPath);
                targetAsset.InitializeAsset();
            }
            else if (targetAsset is Component)
            {
                targetAsset.InitializeAsset();
                PrefabUtility.SaveAsPrefabAsset((targetAsset as Component).gameObject, assetPath.FullPath);
                Object.DestroyImmediate((targetAsset as Component).gameObject);
            }
            else
            {
                ret.Add(new Command(DefaultCommandType.Log, "Invalid Type"));
                return(ret);
            }

            return(null);
        }
Exemplo n.º 9
0
        public void ParameterLessProcedure_WithSpaces()
        {
            var procedure = ProcedureParser.Parse(new StringReader(@"
                   proc AddStore(   )
                    local result = a + b
                    redis.call('SET', key, result)
                endproc
            ")).Single();

            Assert.AreEqual("AddStore", procedure.Name);
            Assert.IsNotNull(procedure.Parameters);
            Assert.AreEqual(0, procedure.Parameters.Length);
            Assert.IsNotNull(procedure.Body);
        }
Exemplo n.º 10
0
        public void MultipleTest()
        {
            var procedures = ProcedureParser.Parse(new StringReader(@"
                   proc  AddStore($key, a, b)
                    local result = a + b
                    redis.call('SET', key, result)
                endproc
                proc  AddStore2 ($key[],  a,  b[] )
                    local result = a + b
                    redis.call('SET', key, result)
                endproc
            ")).ToArray();

            var procedure = procedures[0];

            Assert.AreEqual("AddStore", procedure.Name);
            Assert.IsNotNull(procedure.Parameters);
            Assert.AreEqual(3, procedure.Parameters.Length);
            Assert.AreEqual("key", procedure.Parameters[0].Name);
            Assert.IsTrue(procedure.Parameters[0].IsKey);
            Assert.IsFalse(procedure.Parameters[0].IsArray);
            Assert.AreEqual("a", procedure.Parameters[1].Name);
            Assert.IsFalse(procedure.Parameters[1].IsKey);
            Assert.IsFalse(procedure.Parameters[1].IsArray);
            Assert.AreEqual("b", procedure.Parameters[2].Name);
            Assert.IsFalse(procedure.Parameters[2].IsKey);
            Assert.IsFalse(procedure.Parameters[2].IsArray);
            Assert.IsNotNull(procedure.Body);

            procedure = procedures[1];
            Assert.AreEqual("AddStore2", procedure.Name);
            Assert.IsNotNull(procedure.Parameters);
            Assert.AreEqual(3, procedure.Parameters.Length);
            Assert.AreEqual("key", procedure.Parameters[0].Name);
            Assert.IsTrue(procedure.Parameters[0].IsKey);
            Assert.IsTrue(procedure.Parameters[0].IsArray);
            Assert.AreEqual("a", procedure.Parameters[1].Name);
            Assert.IsFalse(procedure.Parameters[1].IsKey);
            Assert.IsFalse(procedure.Parameters[1].IsArray);
            Assert.AreEqual("b", procedure.Parameters[2].Name);
            Assert.IsFalse(procedure.Parameters[2].IsKey);
            Assert.IsTrue(procedure.Parameters[2].IsArray);
            Assert.IsNotNull(procedure.Body);
        }
Exemplo n.º 11
0
        private static IEnumerable <Command> ReactionOfSet(ProcedureParser context, string target, string subTarget)
        {
            List <Command>     ret        = new List <Command>();
            CustomPath         path       = new CustomPath(target);
            IProcedureParsable tempTarget = CustomPath.FindAssetWithPath(path);

            if (tempTarget == null)
            {
                ret.Add(new Command(DefaultCommandType.Log, "CannotFoundTarget", $"Set {target} into {subTarget}"));
                return(ret);
            }

            if (path.FromLast(1).StartsWith(CustomPath.RefPrefix))
            {
                tempTarget.Set($"{path.FromLast(1)}/{path.FromLast(0)}", subTarget);
            }
            else
            {
                tempTarget.Set(path.FromLast(0), subTarget);
            }
            return(null);
        }
Exemplo n.º 12
0
        public void BasicTestWithArrays()
        {
            var procedure = ProcedureParser.Parse(new StringReader(@"
                proc  AddStore ($key[],  a,  b[] )
                    local result = a + b
                    redis.call('SET', key, result)
                endproc
            ")).Single();

            Assert.AreEqual("AddStore", procedure.Name);
            Assert.IsNotNull(procedure.Parameters);
            Assert.AreEqual(3, procedure.Parameters.Length);
            Assert.AreEqual("key", procedure.Parameters[0].Name);
            Assert.IsTrue(procedure.Parameters[0].IsKey);
            Assert.IsTrue(procedure.Parameters[0].IsArray);
            Assert.AreEqual("a", procedure.Parameters[1].Name);
            Assert.IsFalse(procedure.Parameters[1].IsKey);
            Assert.IsFalse(procedure.Parameters[1].IsArray);
            Assert.AreEqual("b", procedure.Parameters[2].Name);
            Assert.IsFalse(procedure.Parameters[2].IsKey);
            Assert.IsTrue(procedure.Parameters[2].IsArray);
            Assert.IsNotNull(procedure.Body);
        }
Exemplo n.º 13
0
        public static SidCollection Parse(IEnumerable <string> allLines)
        {
            var parseResult = new ProcedureParser(SectionSplitter.Type.Sid).Parse(allLines);

            return(new SidCollection(parseResult.Select(r => Convert(r))));
        }
Exemplo n.º 14
0
 private IEnumerable <Command> ValidateOfMove(ProcedureParser context, string target, string subTarget)
 {
     return(null);
 }
Exemplo n.º 15
0
 public IEnumerable <Command> DoNothing(ProcedureParser context, string Target, string Subtarget)
 {
     return(null);
 }