示例#1
0
        /// <summary>
        /// Handles when a statechage is noticed by the external source
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void ExternalSourceInput(object sender, ConnectionStateChangedEventHandlerArgs args)
        {
            //find all the rules that say something this connection. fire then collect the changes to be made to the states.
            var statechangedirectives =
                AllRules.Where(r => r.Connections.Any(c => c.Name == args.Connection.Name))
                .Select(r => r.Fire(r.Connections.First(r1 => r1.Name == args.Connection.Name), args.NewState))
                .SelectMany(s => s);


            //do not only send the message back to the source it came from also check if others want to know
            //about it.
            var externals = ExternalSources.SelectMany(e => e.Connections, (e1, c1) => new { ExternalSource = e1, Connection = c1 }).ToList();

            foreach (var stateChangeDirective in statechangedirectives.Where(s => s != StateChangeDirective.NoOperation))
            {
                var directive = stateChangeDirective;
                foreach (var external in externals.Where(e => e.Connection.Name == directive.Connection.Name).Select(e => e.ExternalSource))
                {
                    external.SetState(directive.Connection, directive.NewState.Name);
                }
            }

            if (args.Connection.Copied)
            {
                externals.First(t => t.Connection.Name == args.Connection.Name && !t.Connection.Copied).ExternalSource.
                SetState(args.Connection, args.NewState.Name);
            }
            else
            {
                ((IExternalSource)sender).SetState(args.Connection, args.NewState.Name);
            }
        }
示例#2
0
 /// <summary>
 /// resolve the connections to their real ones by their name.
 /// </summary>
 /// <param name="connectionNames">connection names</param>
 /// <returns>a list of connections.</returns>
 public IEnumerable <Connection> ResolveConnections(IEnumerable <string> connectionNames)
 {
     return(ExternalSources.SelectMany(e => e.Connections)
            .Where(c => !c.Copied)
            .Join(connectionNames, c => c.Name, s => s, (c, s) => c)
            .ToList());
 }
示例#3
0
        internal AstVariable GetExternalVariable(ExternalDataSourceNode <TInstruction> external)
        {
            if (ExternalSources.TryGetValue(external, out var variable))
            {
                return(variable);
            }

            variable = new AstVariable(external.Name);
            ExternalSources.Add(external, variable);

            return(variable);
        }
示例#4
0
        public static void SaveSourcesFromList(ExternalSources items, string filePath)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(ExternalSources));

            try
            {
                serializer.Serialize(new StreamWriter(filePath, false), items);
            }
            catch (Exception)
            {
                Console.WriteLine("Error");
            }
        }
示例#5
0
        public ExternalSourcesViewModel(SettingViewModel setting, IProfilesProvider profilesProvider)
        {
            _setting          = setting;
            _profilesProvider = profilesProvider;

            ExternalSourcesProfiles = new Dictionary <Guid, List <Profile> >();

            if (_setting.ExternalSources == null)
            {
                _setting.ExternalSources = new List <ExternalSource>();
            }

            _ExternalSources = new BindingList <ExternalSource>();

            NavigateToProfilesPageCommand = new DelegateCommand(async o => await NavigateToProfilesPage(null));
            SaveSourcesCommand            = new DelegateCommand(async o => await SaveSources());
            AddNewExternalSourceCommand   = new DelegateCommand(o => AddNewExternalSource());
            DeleteSourceCommand           = new DelegateCommand(o => DeleteSource(o), c => { return(c is Guid id && ExternalSources.Any(x => x.Id == id)); });
        }