Example #1
0
		public override ExecuteResult Execute(Space space) {
			if (!IsSuccess(_expression.Execute(space))) {
				ErrorLogger.LogRuntimeError(ErrorRuntimeCode.Echo, "The parameter expression execute failed!");
				return ExecuteResult.Failed;
			}
			var value = _expression.value;
			System0.Echo(ValueTool.ToString(value));

			return ExecuteResult.Successed;
		}
Example #2
0
        private BuiltInFunction()
        {
            Action <string, int, Func <List <Value>, Space, Value> > _Emplace = (string name, int paramSize, Func <List <Value>, Space, Value> func) => {
                var value    = new ValueFunction(paramSize, func);
                var variable = new Variable(name, VariableAttribute.Const, value);
                variables.Add(name, variable);
            };

            // print
            _Emplace.Invoke("print", 1, (List <Value> args, Space s) => {
                string ret = "";
                foreach (var arg in args)
                {
                    ret += ValueTool.ToString(arg);
                }
                System0.Echo(ret);
                return(ValueNull.DEFAULT_VALUE);
            });
            // type
            _Emplace("type", 1, (List <Value> args, Space s) => {
                if (args.Count == 0)
                {
                    return(null);
                }
                return(new ValueString(ValueTool.ToTypeString(args[0])));
            });
            // is_null
            _Emplace("is_null", 1, (List <Value> args, Space s) => {
                if (args.Count == 0)
                {
                    return(null);
                }
                bool ret = true;
                foreach (var arg in args)
                {
                    ret &= ValueTool.IsNull(arg);
                }
                return(new ValueBool(ret));
            });
            // is_number
            _Emplace("is_number", 1, (List <Value> args, Space s) => {
                if (args.Count == 0)
                {
                    return(null);
                }
                bool ret = true;
                foreach (var arg in args)
                {
                    ret &= ValueTool.IsNumber(arg);
                }
                return(new ValueBool(ret));
            });
            // is_bool
            _Emplace("is_bool", 1, (List <Value> args, Space s) => {
                if (args.Count == 0)
                {
                    return(null);
                }
                bool ret = true;
                foreach (var arg in args)
                {
                    ret &= ValueTool.IsBool(arg);
                }
                return(new ValueBool(ret));
            });
            // is_string
            _Emplace("is_string", 1, (List <Value> args, Space s) => {
                if (args.Count == 0)
                {
                    return(null);
                }
                bool ret = true;
                foreach (var arg in args)
                {
                    ret &= ValueTool.IsString(arg);
                }
                return(new ValueBool(ret));
            });
            // is_array
            _Emplace("is_array", 1, (List <Value> args, Space s) => {
                if (args.Count == 0)
                {
                    return(null);
                }
                bool ret = true;
                foreach (var arg in args)
                {
                    ret &= ValueTool.IsArray(arg);
                }
                return(new ValueBool(ret));
            });
            // is_function
            _Emplace("is_function", 1, (List <Value> args, Space s) => {
                if (args.Count == 0)
                {
                    return(null);
                }
                bool ret = true;
                foreach (var arg in args)
                {
                    ret &= ValueTool.IsFunction(arg);
                }
                return(new ValueBool(ret));
            });
            // is_object
            _Emplace("is_object", 1, (List <Value> args, Space s) => {
                if (args.Count == 0)
                {
                    return(null);
                }
                bool ret = true;
                foreach (var arg in args)
                {
                    ret &= ValueTool.IsObject(arg);
                }
                return(new ValueBool(ret));
            });
            // len
            _Emplace("len", 1, (List <Value> args, Space s) => {
                if (args.Count == 0)
                {
                    return(null);
                }
                var value = args[0];
                if (ValueTool.IsArray(value))
                {
                    return(new ValueNumber((double)(value as ValueArray).value.Count));
                }
                else if (ValueTool.IsString(value))
                {
                    return(new ValueNumber((double)(value as ValueString).value.Length));
                }
                return(ValueNull.DEFAULT_VALUE);
            });
            // to_string
            _Emplace("to_string", 1, (List <Value> args, Space s) => {
                if (args.Count == 0)
                {
                    return(null);
                }
                var value = args[0];
                return(new ValueString(ValueTool.ToString(value)));
            });
            // to_number
            _Emplace("to_number", 1, (List <Value> args, Space s) => {
                if (args.Count == 0)
                {
                    return(null);
                }
                var value = args[0];
                if (!ValueTool.IsString(value))
                {
                    return(null);
                }
                double ret = 0;
                if (!double.TryParse((value as ValueString).value, out ret))
                {
                    ret = 0;
                }
                return(new ValueNumber(ret));
            });
        }
Example #3
0
        public static Root CreateMediaStore(int factor, out System.Action[] manipulations)
        {
            var repository = new Repository();

            manipulations = new System.Action[3 * factor];

            var iAudioStore = new Interface()
            {
                Name = "AudioStoreInterface"
            };

            repository.Interfaces.Add(iAudioStore);

            var iEncoder = new Interface()
            {
                Name = "EncoderInterface"
            };

            repository.Interfaces.Add(iEncoder);

            var iAudioDB = new Interface()
            {
                Name = "AudioDBInterface"
            };

            repository.Interfaces.Add(iAudioDB);

            var iUserManagement = new Interface()
            {
                Name = "UserManagementInterface"
            };

            repository.Interfaces.Add(iUserManagement);

            var iUserDB = new Interface()
            {
                Name = "UserDBInterface"
            };

            repository.Interfaces.Add(iUserDB);

            var iCommand = new Interface()
            {
                Name = "CommandInterface"
            };

            repository.Interfaces.Add(iCommand);

            var iConnection = new Interface()
            {
                Name = "ConnectionInterface"
            };

            repository.Interfaces.Add(iConnection);

            var iDataReaderInterface = new Interface()
            {
                Name = "DataReaderInterface"
            };

            repository.Interfaces.Add(iDataReaderInterface);

            var http = new Interface()
            {
                Name = "HTTP"
            };

            repository.Interfaces.Add(http);

            var webBrowser = new Component()
            {
                Name = "WebBrowser"
            };

            webBrowser.RequiredInterfaces.Add(http);
            repository.Components.Add(webBrowser);

            var webForm = new Component()
            {
                Name = "WebForm"
            };

            webForm.ProvidedInterfaces.Add(http);
            webForm.RequiredInterfaces.Add(iAudioStore);
            repository.Components.Add(webForm);

            var audioStore = new Component()
            {
                Name = "AudioStore"
            };

            audioStore.ProvidedInterfaces.Add(iAudioStore);
            audioStore.RequiredInterfaces.Add(iAudioDB);
            audioStore.RequiredInterfaces.Add(iUserManagement);
            repository.Components.Add(audioStore);

            var encodingAdapter = new Component()
            {
                Name = "EncodingAdapter"
            };

            encodingAdapter.ProvidedInterfaces.Add(iAudioDB);
            encodingAdapter.RequiredInterfaces.Add(iEncoder);

            encodingAdapter.RequiredInterfaces.Add(iAudioDB);
            repository.Components.Add(encodingAdapter);

            var oggEncoder = new Component()
            {
                Name = "OggEncoder"
            };

            oggEncoder.ProvidedInterfaces.Add(iEncoder);
            repository.Components.Add(oggEncoder);

            var userMgmt = new Component()
            {
                Name = "UserManagement"
            };

            userMgmt.ProvidedInterfaces.Add(iUserManagement);
            userMgmt.RequiredInterfaces.Add(iUserDB);
            repository.Components.Add(userMgmt);

            var dbadapter = new Component()
            {
                Name = "DBAdapter"
            };

            dbadapter.ProvidedInterfaces.Add(iUserDB);
            dbadapter.ProvidedInterfaces.Add(iAudioDB);
            dbadapter.RequiredInterfaces.Add(iCommand);
            dbadapter.RequiredInterfaces.Add(iConnection);
            dbadapter.RequiredInterfaces.Add(iDataReaderInterface);
            repository.Components.Add(dbadapter);

            var database = new Component()
            {
                Name = "MySqlClient"
            };

            database.ProvidedInterfaces.Add(iCommand);
            database.ProvidedInterfaces.Add(iConnection);
            database.ProvidedInterfaces.Add(iDataReaderInterface);
            repository.Components.Add(database);

            var encrypt = new Signature()
            {
                Name = "Encrypt"
            };
            var decrypt = new Signature()
            {
                Name = "Decrypt"
            };

            iEncoder.Signatures.Add(encrypt);
            iEncoder.Signatures.Add(decrypt);

            var upload = new Signature()
            {
                Name = "Upload"
            };
            var download = new Signature()
            {
                Name = "Download"
            };

            iAudioStore.Signatures.Add(upload);
            iAudioStore.Signatures.Add(download);

            oggEncoder.Services.Add(new Service()
            {
                Signature = encrypt
            });
            oggEncoder.Services.Add(new Service()
            {
                Signature = decrypt
            });

            audioStore.Services.Add(new Service()
            {
                Signature = upload
            });
            audioStore.Services.Add(new Service()
            {
                Signature = download
            });
            var environment = new Environment();
            var system      = new System0 {
                Name = "MediaStore"
            };
            var allocation = new Allocation
            {
                AllocatedSystem = system,
                Environment     = environment
            };
            var isolatedContainer = new Container {
                Name = "IsolatedContainer"
            };

            environment.Containers.Add(isolatedContainer);
            for (int i = 0; i < factor; i++)
            {
                var suffix    = i.ToString();
                var appServer = new Container {
                    Name = "AppServer" + suffix
                };
                var databaseServer = new Container {
                    Name = "Database" + suffix
                };
                environment.Containers.Add(appServer);
                environment.Containers.Add(databaseServer);
                var network = new Link {
                    Name = "Network" + suffix
                };
                network.ConnectedContainers.Add(appServer);
                network.ConnectedContainers.Add(databaseServer);
                environment.Links.Add(network);

                var webFormAssembly = new AssemblyContext
                {
                    Name       = "WebForm" + suffix,
                    Implements = webForm
                };
                var audioStoreAssembly = new AssemblyContext
                {
                    Name       = "AudioStore" + suffix,
                    Implements = audioStore
                };
                var encodingAdapterAssembly = new AssemblyContext
                {
                    Name       = "EncodingAdapter" + suffix,
                    Implements = encodingAdapter
                };
                var encoderAssembly = new AssemblyContext
                {
                    Name       = "EncodingAdapter" + suffix,
                    Implements = encodingAdapter
                };
                var oggEncoderAssembly = new AssemblyContext
                {
                    Name       = "OggEncoder" + suffix,
                    Implements = oggEncoder
                };
                var userMgmtAssembly = new AssemblyContext
                {
                    Name       = "UserMgmt" + suffix,
                    Implements = userMgmt
                };
                var dbAdapterAssembly = new AssemblyContext
                {
                    Name       = "DBAdapter" + suffix,
                    Implements = dbadapter
                };
                var mysqlAssembly = new AssemblyContext
                {
                    Name       = "MySql" + suffix,
                    Implements = database
                };

                system.EncapsulatedContexts.Add(webFormAssembly);
                system.EncapsulatedContexts.Add(audioStoreAssembly);
                system.EncapsulatedContexts.Add(encoderAssembly);
                system.EncapsulatedContexts.Add(oggEncoderAssembly);
                system.EncapsulatedContexts.Add(userMgmtAssembly);
                system.EncapsulatedContexts.Add(dbAdapterAssembly);
                system.EncapsulatedContexts.Add(mysqlAssembly);

                allocation.AllocationContexts.Add(new AllocationContext {
                    Assembly = webFormAssembly, Container = appServer
                });
                allocation.AllocationContexts.Add(new AllocationContext {
                    Assembly = audioStoreAssembly, Container = appServer
                });
                allocation.AllocationContexts.Add(new AllocationContext {
                    Assembly = encoderAssembly, Container = appServer
                });
                allocation.AllocationContexts.Add(new AllocationContext {
                    Assembly = oggEncoderAssembly, Container = appServer
                });
                allocation.AllocationContexts.Add(new AllocationContext {
                    Assembly = userMgmtAssembly, Container = appServer
                });
                allocation.AllocationContexts.Add(new AllocationContext {
                    Assembly = dbAdapterAssembly, Container = appServer
                });
                var databaseDeployment = new AllocationContext {
                    Assembly = mysqlAssembly, Container = databaseServer
                };
                allocation.AllocationContexts.Add(databaseDeployment);

                manipulations[i]              = () => databaseDeployment.Container = isolatedContainer;
                manipulations[factor + i]     = () => databaseDeployment.Container = databaseServer;
                manipulations[2 * factor + i] = () => network.ConnectedContainers.Remove(databaseServer);

                system.Connectors.Add(new AssemblyConnector {
                    Interface = iAudioStore, ProvidingComponent = audioStoreAssembly, UsingComponent = webFormAssembly
                });
                system.Connectors.Add(new AssemblyConnector {
                    Interface = iUserManagement, ProvidingComponent = userMgmtAssembly, UsingComponent = audioStoreAssembly
                });
                system.Connectors.Add(new AssemblyConnector {
                    Interface = iEncoder, ProvidingComponent = encoderAssembly, UsingComponent = audioStoreAssembly
                });
                system.Connectors.Add(new AssemblyConnector {
                    Interface = iUserDB, ProvidingComponent = dbAdapterAssembly, UsingComponent = userMgmtAssembly
                });
                system.Connectors.Add(new AssemblyConnector {
                    Interface = iEncoder, ProvidingComponent = oggEncoderAssembly, UsingComponent = encoderAssembly
                });
                system.Connectors.Add(new AssemblyConnector {
                    Interface = iAudioDB, ProvidingComponent = dbAdapterAssembly, UsingComponent = encoderAssembly
                });
                system.Connectors.Add(new AssemblyConnector {
                    Interface = iCommand, ProvidingComponent = mysqlAssembly, UsingComponent = dbAdapterAssembly
                });
                system.Connectors.Add(new AssemblyConnector {
                    Interface = iConnection, ProvidingComponent = mysqlAssembly, UsingComponent = dbAdapterAssembly
                });
                system.Connectors.Add(new AssemblyConnector {
                    Interface = iDataReaderInterface, ProvidingComponent = mysqlAssembly, UsingComponent = dbAdapterAssembly
                });
            }

            system.ProvidedInterfaces.Add(http);

            return(new Root
            {
                Environment = environment,
                System = system,
                Repository = repository,
                Allocation = allocation
            });
        }