/// <summary>
        /// Fills the arguments by getter.
        /// </summary>
        /// <param name="current">Current.</param>
        /// <param name="info">Info.</param>
        /// <param name="args">Arguments.</param>
        public static void FillArgumentsByGetter(Component current, MethodInfo info, IParameterList args, int index = -1)
        {
            if (current == null || info == null || !info.IsSpecialName || args == null)
            {
                return;
            }

            object    defaultValue;
            var       getMethodInfo = info.ReflectedType.GetMethod("get_" + info.Name.Substring(4));
            Component component     = current.GetComponent(info.ReflectedType);

            if (getMethodInfo != null && component)
            {
                defaultValue = getMethodInfo.Invoke(current.GetComponent(getMethodInfo.ReflectedType), new object[0]);

                for (int i = 0; i < args.count; i++)
                {
                    if (0 <= index && index != i)
                    {
                        continue;
                    }

                    GUI.changed = GUI.changed || !object.Equals(args.GetObject(i), defaultValue);
                    args.SetObject(i, defaultValue);
                }
            }
        }
        /// <summary>
        /// Switchs the target.
        /// </summary>
        /// <param name="info">Info.</param>
        public static void ActivatePropetyTarget(Component current, List <Property> activedTargets, MethodInfo info, string id, int count)
        {
            //
            Type argumentType, argumentArrayType;

            if (!Property.TryGetParameterListType(info, out argumentType, out argumentArrayType))
            {
                return;
            }

            // The target is deactive now and switch to be active.
            // Add target to toggle, with its arguments.
            if (Property.TryGetParameterListType(argumentType, out argumentArrayType))
            {
                IParameterList args = (argumentArrayType != typeof(ObjectParameterList)) ? (IParameterList)JsonUtility.FromJson("{}", argumentArrayType) : new ObjectParameterList();
                args.FitSize(count);

                if (current)
                {
                    FillArgumentsByGetter(current, info, args);
                }

                activedTargets.Add(new Property(id, args));

                // Sorting
                activedTargets.Sort((x, y) => x.methodId.CompareTo(y.methodId));
            }

            if (current)
            {
                UnityEditor.EditorUtility.SetDirty(current);
            }

            onPropertyChanged();
        }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RabbitEventedExchangeGenerator" /> class.
 /// </summary>
 /// <param name="dependencyUtility">The dependency utility.</param>
 /// <param name="connectionParameters">The connection parameters.</param>
 /// <param name="connection">The connection.</param>
 public RabbitEventedExchangeGenerator(IDependencyUtility dependencyUtility, IParameterList connectionParameters, IConnection connection = null)
 {
     _dependencyUtility = dependencyUtility;
     _logger            = _dependencyUtility.Resolve <ILogger>();
     _exchangeCache     = _dependencyUtility.Resolve <ICacheHandler>().AddCache("rabbitmq-exchanges", CacheService.InMemory, -1);
     _connection        = connection ?? RabbitConnectionGenerator.CreateConnection(_dependencyUtility, connectionParameters);
 }
Exemple #4
0
        internal static void RenderAndPlay(IParameterList parameterList, Song song, string fileName)
        {
            song.Generate(parameterList);
            var score      = song.Render();
            var outputPath = Path.Combine(Dir, fileName);

            score.ExportMidi(outputPath);
            Process.Start(outputPath);
        }
        private IExperiment parseExperiment(IJsonReader <TokenType> jreader)
        {
            if (jreader.getCurrentTokenType() == TokenType.StartObject)
            {
                jreader.readNextToken();
            }
            String         eid   = "";
            String         name  = "";
            String         desc  = "";
            IParameterList plist = null;

            do
            {
                TokenType type  = jreader.getCurrentTokenType();
                object    value = jreader.getCurrentValue();
                bool      isOk  = ((type == TokenType.PropertyName) &&
                                   (value != null) &&
                                   (value is String));
                if (isOk)
                {
                    if (String.Compare((String)value, "experiment_id") == 0)
                    {
                        jreader.readNextToken();
                        eid = (String)jreader.getCurrentValue();
                    }
                    else if (String.Compare((String)value, "name") == 0)
                    {
                        jreader.readNextToken();
                        name = (String)jreader.getCurrentValue();
                    }
                    else if (String.Compare((String)value, "description") == 0)
                    {
                        jreader.readNextToken();
                        desc = (String)jreader.getCurrentValue();
                    }
                    else if (String.Compare((String)value, "parametercollection") == 0)
                    {
                        jreader.readNextToken();
                        plist = this.parseParameterList(jreader);
                    }
                    else
                    {
                        this.skipJsonField(jreader);
                    }
                    jreader.readNextToken();
                }
                else
                {
                    throw new ArgumentException("Argument 'type' must be a TokenType " +
                                                "with option of PropertyName.\n" +
                                                "Argument 'value' must be not null " +
                                                "and of type String.");
                }
            } while(TokenType.EndObject != jreader.getCurrentTokenType());
            return(Experiment.create(eid, name, desc, plist));
        }
Exemple #6
0
        private static void RenderAndPlay(IParameterList parameterList)
        {
            var song = new GeneratedSong();

            Common.RenderAndPlay(parameterList, song, "output.mid");
            foreach (var section in song.Sections)
            {
                Console.WriteLine("{0}: {1} meas, {2}", section.Type, section.Measures, string.Join(" - ", section.Chords.Select(c => c.Item2)));
            }
        }
Exemple #7
0
        public Property(string methodId, IParameterList args)
        {
            var names = methodId.Split(ID_SEPERATOR);

            m_MethodTargetType = names[0];
            m_ParameterType    = names[1];
            m_MethodName       = names[2];

            parameterList         = args;
            m_ObjectParameterList = (args as ObjectParameterList);

            OnBeforeSerialize();
            OnAfterDeserialize();
        }
Exemple #8
0
        public override void Generate(IParameterList parameterList)
        {
            var param = (ParameterList)parameterList;
            var time  = param.TimeSignatureFunc();
            var feel  = param.FeelFunc(time);

            _songInfo = new SongInfo(time, feel)
            {
                Parameters = param
            };

            var sections                = new SectionLayoutGenerator().GetSectionLayout(_songInfo).ToList();
            var chordProgressions       = GetDistinctChordProgressions(param, sections.Distinct().Count());
            var mappedChordProgressions = sections.Distinct().Select((s, i) => new Tuple <int, SectionType>(i, s));
            var sectionTypes            = mappedChordProgressions.Distinct()
                                          .ToDictionary(s => s.Item2, s => new SongSection(_songInfo, s.Item2, chordProgressions[s.Item1]));

            Sections = sections.Select(s => sectionTypes[s]).ToList();
        }
Exemple #9
0
        /// <summary>
        /// Adds the queue.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="queueParameters">The queue parameters.</param>
        public void AddQueue <T>(IParameterList queueParameters)
        {
            string exchangeId = queueParameters["ExchangeId"];
            string queueId    = queueParameters["QueueId"];
            string routingKey = queueParameters["RouteKey"];

            bool queueDurable    = queueParameters["Durable"];
            bool queueTransient  = queueParameters["Transient"];
            bool queueAutoDelete = queueParameters["AutoDelete"];

            IModel channel = null;

            lock (_connectionLock)
                channel = _connection.CreateModel();

            channel.QueueDeclare(queueId, queueDurable, queueTransient, queueAutoDelete, null);
            channel.QueueBind(queueId, exchangeId, routingKey);

            IEventedQueue <T> queue = new RabbitEventedQueue <T>(exchangeId, queueId, routingKey, channel, _dependencyUtility);

            _queueCache.Set($"{exchangeId}/{queueId}", queue);
        }
Exemple #10
0
        /// <summary>
        /// Adds the exchange.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="exchangeParameters">The exchange parameters.</param>
        public void AddExchange <T>(IParameterList exchangeParameters)
        {
            string exchangeId   = exchangeParameters["ExchangeId"];
            string exchangeType = exchangeParameters["ExchangeType"];
            string routeKey     = exchangeParameters["RouteKey"];

            bool durable    = exchangeParameters["ExchangeDurable"] ?? false;
            bool autoDelete = exchangeParameters["ExchangeAutoDelete"] ?? false;

            IModel channel = null;

            lock (_connectionLock)
                channel = _connection.CreateModel();

            _logger.Debug($"Declaring RabbitMQ exchange: {exchangeId}");

            channel.ExchangeDeclare(exchangeId, exchangeType, durable, autoDelete);

            IEventedExchange <T> exchange = new RabbitEventedExchange <T>(exchangeId, routeKey, channel, _dependencyUtility);

            _exchangeCache.Set(exchangeId, exchange);
        }
        private Experiment(String id, String name, String description,
                           IParameterList parameters)
        {
            bool isOK = ((parameters != null) && (isValidId(id)) &&
                         (name != null) && (description != null));

            if (isOK)
            {
                this.id          = id;
                this.name        = name;
                this.description = description;
                this.parameters  = parameters;
            }
            else
            {
                throw new ArgumentException("Arguments 'id', 'name', 'description', " +
                                            " and 'parameters' must be not null.\n" +
                                            "Argument 'id' must have a length between " +
                                            "1 and 60 characters and must consist " +
                                            "the characters 0-9a-zA-Z only.\n" +
                                            "Argument 'parameters' must be a " +
                                            "valid implemented IParameterList.");
            }
        }
Exemple #12
0
            private static void ProxyInvoke(ICode c, Type returnType, IParameterList args,
                                            Func <FactoryPair, IOperand[], IOperand> callTarget)
            {
                bool hasRef = false;

                IOperand[]    vars       = new IOperand[args.Count];
                IOperand[]    parameters = new IOperand[args.Count];
                FactoryPair[] pairs      = new FactoryPair[args.Count];
                for (int i = 0; i < args.Count; i++)
                {
                    var arg  = args[i];
                    var pair = GetFactoryPair(arg.Type);
                    if (pair == null)
                    {
                        parameters[i] = arg; continue;
                    }
                    pairs[i] = pair;
                    if (arg.Direction == ParameterDirection.In)
                    {
                        parameters[i] = c.Invoke(pair.GetTarget, arg);
                        continue;
                    }
                    hasRef  = true;
                    vars[i] = c.Variable(arg.Type.GetElementType(), arg.Name + "Target");
                    if (arg.Direction == ParameterDirection.Ref)
                    {
                        c.Assign(vars[i], c.Invoke(pair.GetTarget, arg));
                    }
                    parameters[i] = vars[i];
                }
                var  returnPair = GetFactoryPair(returnType);
                var  result     = callTarget(returnPair, parameters);
                bool isVoid     = returnType == typeof(void) || result == null;

                if (hasRef)
                {
                    if (!isVoid)
                    {
                        result = c.Variable(returnType, "result", result);
                    }
                    for (int i = 0; i < args.Count; i++)
                    {
                        if (vars[i] == null)
                        {
                            continue;
                        }
                        c.Assign(args[i], c.Invoke(pairs[i].GetProxy, vars[i]));
                    }
                }
                if (result == null)
                {
                    c.Return();
                }
                else if (returnPair == null)
                {
                    c.Return(result);
                }
                else
                {
                    c.Return(c.Invoke(returnPair.GetProxy, result));
                }
            }
Exemple #13
0
 /// <summary>
 /// Convert <see cref="IParameterList"/> to an enumerable of
 /// <see cref="IOperand"/>.
 /// </summary>
 /// <param name="parameters">
 /// An <see cref="IParameterList"/>
 /// </param>
 /// <returns>
 /// An enumerable of <see cref="IOperand"/>.
 /// </returns>
 public static IEnumerable <IOperand> AsOperands(this IParameterList parameters)
 {
     return(from p in parameters.All select(IOperand) p);
 }
 public ParameterSyntaxReader(IParameterList parameters, SemanticModel semantic) : base(semantic)
 {
     _parameters = parameters;
 }
Exemple #15
0
 /// <summary>
 /// Generates the song.
 /// Any input parameters would be collected by the Song implementation's constructor.
 /// </summary>
 public abstract void Generate(IParameterList parameterList);
 public ParameterSymbolReader(IParameterList parameters)
 {
     _parameters = parameters;
 }
Exemple #17
0
        /// <summary>
        /// Creates the connection.
        /// </summary>
        /// <param name="dependencyUtility">The dependency utility.</param>
        /// <param name="connectionParameters">The connection parameters.</param>
        /// <returns></returns>
        public static IConnection CreateConnection(IDependencyUtility dependencyUtility, IParameterList connectionParameters)
        {
            string host        = connectionParameters["Host"];
            string virtualHost = connectionParameters["VirtualHost"];
            string username    = connectionParameters["Username"];
            string password    = connectionParameters["Password"];

            IConnectionFactory connectionFactory = new ConnectionFactory
            {
                UserName    = username,
                Password    = password,
                VirtualHost = virtualHost,
                Endpoint    = new AmqpTcpEndpoint(host)
            };

            ILogger     logger = dependencyUtility.Resolve <ILogger>();
            IConnection connection;

            try
            {
                connection = connectionFactory.CreateConnection();
                logger.Debug($"Connected to RabbitMQ service: {host}{virtualHost}");
            }
            catch (Exception exception)
            {
                logger.Error(exception);
                throw;
            }

            return(connection);
        }
 public static Experiment create(String id, String name, String description,
                                 IParameterList parameters)
 {
     return(new Experiment(id, name, description, parameters));
 }