/// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="settingModel">Settings model.</param>
        /// <param name="communicationClient">Communication client.</param>
        public MultiPlayerModel(ISettingsModel settingModel,
                                CommunicationClient communicationClient)
        {
            //Initializes variables.
            int    port = settingModel.Port;
            string ip   = settingModel.IpAddress;
            string serverMessage;

            this.CommunicationClient = communicationClient;
            this.CommunicationClient.ConnectionFailed += HandleConnectionFailed;

            //Sets property changed delegate.
            this.CommunicationClient.PropertyChanged +=
                delegate(Object sender, PropertyChangedEventArgs e)
            {
                serverMessage = communicationClient.CommandFromUser;
                if (!string.IsNullOrEmpty(serverMessage) &&
                    !IsSingleCommand)
                {
                    HandleServerResult(serverMessage);
                }
                else if (serverMessage != null)
                {
                    ServerResponse = serverMessage;
                }
            };
        }
Example #2
0
 public SettingsPresenter(
     ISettingsModel model,
     ISettingsView view)
     : base(model, view)
 {
     Initialize();
 }
 public SettingsWindowViewModel(ISettingsModel model)
 {
     this.model = model;
     model.ReloadSettings();
     this.OKBtnCommand     = new CommandHandler(OnOKClick);
     this.CancelBtnCommand = new CommandHandler(OnCancelClick);
 }
Example #4
0
 public Info()
 {
     ep        = new IPEndPoint(IPAddress.Parse(_settings.FlightServerIP), _settings.FlightInfoPort);
     _settings = ApplicationSettingsModel.Instance;
     _stop     = false;
     ch        = new ClientHandler();
 }
Example #5
0
 public Commands()
 {
     _isConnected = false;
     _client      = new TcpClient();
     _settings    = ApplicationSettingsModel.Instance;
     ep           = new IPEndPoint(IPAddress.Parse(_settings.FlightServerIP), _settings.FlightCommandPort);
 }
        public void Connect()
        {
            ISettingsModel model = ApplicationSettingsModel.Instance;

            server = new Server(model.FlightInfoPort);
            //wait till the server is connected

            Thread thread = new Thread(() =>
            {
                server.Start();
                bool isConnect = true;
                //Read value from the simulator and update lon and lat
                while (isConnect == true)
                {
                    Values = server.Read();
                    try
                    {
                        Lon = Convert.ToDouble(Values[0]);
                        Lat = Convert.ToDouble(Values[1]);
                    }catch (Exception e)
                    {
                        isConnect = false;
                        Client.getInstance().Disconnect();
                        server.Disconnect();
                    }
                }
            });

            thread.Start();

            client = Client.getInstance();
            client.Connect(model.FlightServerIP, model.FlightCommandPort);
        }
Example #7
0
        public string ToCommand(ISettingsModel settingsModel, EepromField eepromField)
        {
            string command = this.TypeToCommand(eepromField.FieldType);
            string value   = this.GetStringValue(settingsModel, eepromField);

            return(string.Format("{0} {1} {2}\n", command, eepromField.FieldOffset, value));
        }
Example #8
0
 /// <summary>
 /// C'tor
 /// </summary>
 public SettingsViewModel()
 {
     m_model = new SettingsModel();
     m_model.PropertyChanged += this.PropertyChanged;
     this.SubmitRemove        = new DelegateCommand <object>(this.OnSubmit, this.CanSubmit);
     this.PropertyChanged    += RemoveCommand;
 }
 /*
  * Constructs a new SettingsWindowModel
  */
 public SettingsWindowModel()
 {
     portAndIp         = ApplicationSettingsModel.Instance;
     flightServerIp    = portAndIp.FlightServerIP;
     flightInfoPort    = portAndIp.FlightInfoPort.ToString();
     flightCommandPort = portAndIp.FlightCommandPort.ToString();
 }
Example #10
0
 public SettingsViewModel()
 {
     this.settingModel = new SettingsModel();
     RemoveCommand     = new DelegateCommand <object>(this.OnRemove, this.CanRemove);
     PropertyChanged  += RemovePropertyChange;
     this.settingModel.PropertyChanged += this.PropertyChanged;
 }
Example #11
0
        public IList <ISetting> Parse(ISettingsModel settingModel)
        {
            Contract.Requires(settingModel != null);
            Contract.Ensures(Contract.Result <IList <ISetting> >() != null);

            if (string.IsNullOrWhiteSpace(settingModel.SettingsInJson))
            {
                return(Enumerable.Empty <ISetting>().ToList());
            }

            var settings = new Dictionary <string, ISetting>();

            try {
                var dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(settingModel.SettingsInJson);
                dict.DoForEach(x =>
                               settings.Add(
                                   x.Key,
                                   (ISetting)
                                   JsonConvert.DeserializeObject(
                                       x.Value,
                                       _settings.First(setting => setting.Name == x.Key).GetType())));
            }
            catch (Exception e) {
                LogManager.Log.Debug(
                    new ParserSettingException("Invalidate json: {0}".StringFormat(settingModel.SettingsInJson), e));
                return(Enumerable.Empty <ISetting>().ToList());
            }

            var settingsCollection = new List <ISetting>();

            settings.DoForEach(temp => settingsCollection.Add(temp.Value));

            return(settingsCollection);
        }
Example #12
0
 public Task<bool> LogoutAsync(ISettingsModel settings)
 {
     bool result = settings.Remove("currentUser");
     TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
     tcs.SetResult(result);
     return tcs.Task;
 }
Example #13
0
 private SimulatorModel()
 {
     stop          = false;
     settingsModel = ApplicationSettingsModel.Instance;
     getter        = new InfoGetter(settingsModel);
     sender        = new CommandsSender(settingsModel);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SettingsViewModel"/> class.
 /// </summary>
 public SettingsViewModel()
 {
     this.canRemove     = false;
     this.RemoveCommand = new DelegateCommand(this.OnRemove, this.CanRemove);
     model = new SettingsModel();
     model.PropertyChanged += this.OnPropertyChanged;
 }
Example #15
0
 public void Init()
 {
     _fakeView           = Substitute.For <ISettingsView>();
     _fakeModel          = Substitute.For <ISettingsModel>();
     _fakeUserPreference = Substitute.For <IUserPreference>();
     _uut = new SettingsPresenter(_fakeView, _fakeModel, _fakeUserPreference);
 }
 private Connect()
 {
     //getting the instance from the APSM
     _apsm   = ApplicationSettingsModel.Instance;
     listner = new TcpListener(_apsm.FlightInfoPort);
     listner.Start();
     commands = Commands.Instance;
 }
        public FlightDisplayVM(IMainModel main, ISettingsModel settings)
        {
            MainModel     = main;
            SettingsModel = settings;

            // connect the server and client upon initialization
            ConnectCommand.Execute(null);
        }
 public void Initialize()
 {
     if (_currentSettings == null)
     {
         _currentSettings = new ActiveSettings();
         NotifySettingsChanged();
     }
 }
Example #19
0
 public SettingsViewModel(ISettingsModel model)
 {
     this.settingsModel     = model;
     model.PropertyChanged += delegate(Object sender, PropertyChangedEventArgs e)
     {
         NotifyPropertyChanged("VM_" + e.PropertyName);
     };
 }
Example #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SettingsViewModel"/> class.
 /// </summary>
 public SettingsViewModel()
 {
     this.settingsModel              = new SettingsModel();
     settingsModel.changeInModel    += this.SettingsEvent;
     settingsModel.OnHandlerRemoved += RemoveSelectedHandler;
     handlers           = new ObservableCollection <HandlerDir>();
     this.RemoveHandler = new DelegateCommand <object>(this.OnRemoveHandler, this.CanRemoveHandler);
 }
Example #21
0
 /// <summary>
 /// Default constructor that acquires model instance and retrieves values from it
 /// </summary>
 /// <param name="_model">Settings model</param>
 public SettingsViewModel(ISettingsModel _model)
 {
     model   = _model;
     style   = _model.Style;
     gap     = _model.Gap.ToString();
     symbols = _model.Symbols;
     range   = _model.Range;
 }
        public void InitConnections(ISettingsModel settings)
        {
            /* set connection parameters */
            ClientModel.IP   = settings.FlightServerIP;
            ClientModel.Port = (uint)settings.FlightCommandPort;

            ServerModel.Port = (uint)settings.FlightInfoPort;
        }
Example #23
0
        private void OnDataChanged(object sender, System.EventArgs e)
        {
            ISettingsView  view  = base._view as ISettingsView;
            ISettingsModel model = base._model as ISettingsModel;

            PresenterBase.SetModelPropertiesFromView <ISettingsModel, ISettingsView>(
                ref model, view
                );
        }
 public LoadCommand(
     ISettingsModel settingsModel,
     ICommandLink commandLink,
     EepromFieldToLoadCommandConverter fieldToCommandConverter)
 {
     this.commandLink             = commandLink;
     this.settingsModel           = settingsModel;
     this.fieldToCommandConverter = fieldToCommandConverter;
 }
Example #25
0
        public UserAccount LoadCurrentUser(ISettingsModel settings)
        {
            string currentUser = settings.GetValueOrDefault<string>("currentUser", string.Empty);
            UserAccount currentAccount = this.Accounts.SingleOrDefault(item => item.Username.Equals(currentUser));
            if (currentAccount == null)
                currentAccount = new UserAccount();

            return currentAccount;
        }
        // Connect method:
        // First i get the ip address
        // After this i connect by TCP protocol
        public void Connect(ISettingsModel settings)
        {
            IPAddress ipAddress = IPAddress.Parse(settings.FlightServerIP);

            this.endPoint  = new IPEndPoint(ipAddress, settings.FlightCommandPort);
            this.tcpClient = new TcpClient();
            this.tcpClient.Connect(endPoint);
            Console.WriteLine("Connected to Commands server");
        }
 public Controller(ILogModel logModel, ISettingsModel settingModel)
 {
     this.commands = new Dictionary <int, ICommand>();
     this.commands.Add((int)CommandsEnum.GetConfigCommand, new GetConfigCommand(settingModel));
     this.commands.Add((int)CommandsEnum.LogsCommand, new LogsCommand(logModel));
     this.commands.Add((int)CommandsEnum.LogCommand, new LogCommand(logModel));
     this.commands.Add((int)CommandsEnum.RemoveDirCommand, new RemoveDirCommand(settingModel));
     this.commands.Add((int)CommandsEnum.CloseCommand, new CloseCommand(settingModel));
 }
Example #28
0
        private TcpListener GetServerConfiguration()
        {
            //get server IP and port
            ISettingsModel appSettings = ApplicationSettingsModel.Instance;
            IPAddress      serverIP    = IPAddress.Parse(appSettings.FlightServerIP);
            int            serverPort  = appSettings.FlightInfoPort;

            return(new TcpListener(serverIP, serverPort));
        }
Example #29
0
        public void SaveSetting(ISettingsModel settingModel)
        {
            string json = JsonConvert.SerializeObject(settingModel);

            using (var streamWriter = new StreamWriter(Path))
            {
                streamWriter.Write(json);
            }
        }
Example #30
0
 /// <summary>
 /// C'tor.
 /// </summary>
 public VM_Settings()
 {
     model = new SettingsModel();
     model.PropertyChanged += delegate(Object sender, PropertyChangedEventArgs e) {
         NotifyPropertyChanged("VM_" + e.PropertyName);
     };
     CloseHandler     = new DelegateCommand <object>(this.removeHandler, this.canRemoveHandler);
     PropertyChanged += RemoveSelectedHandler;
 }
Example #31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SettingsViewModel"/> class.
 /// </summary>
 public SettingsViewModel()
 {
     this.model = new SettingsModel();
     this.model.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
     {
         this.NotifyPropertyChanged("VM_" + e.PropertyName);
     };
     this.RemoveCommand = new DelegateCommand <object>(this.OnRemove, this.CanRemove);
 }
Example #32
0
 public void SaveChanges(UserAccount account, ISettingsModel settings)
 {
     if (!isLoggedOut && !string.IsNullOrEmpty(account.Username))
     {
         settings.AddOrUpdate("currentUser", account.Username);
         settings.SaveSettings();
         this.SubmitChanges();
     }
 }
Example #33
0
 /// <summary>
 /// the constructor
 /// </summary>
 public SettingsViewModel()
 {
     this.settingsModel             = SettingsModel.getModel();
     settingsModel.PropertyChanged +=
         delegate(Object sender, PropertyChangedEventArgs e) {
         NotifyPropertyChanged(e.PropertyName);
     };
     this.RemoveCommand = new DelegateCommand <object>(this.RemoveHandler, this.CanRemoveHandler);
 }
        public SettingsViewModel(IUnityContainer container, ISettingsView view, ISettingsModel model)
            : base(container)
        {
            this.Initialize();

            this.Model = model;

            _view = view;
            this._view.DataContext = this;
            this._view.ShowDialog();
        }
Example #35
0
        /// <summary>
        /// Generates the preferences XML for a settings model
        /// </summary>
        /// <param name="settingsModel">
        /// The settings model
        /// </param>
        /// <param name="entityId">
        /// The ID of the entity to which the settings refer
        /// </param>
        /// <returns>
        /// The generated XML
        /// </returns>
        private XElement GeneratePreferncesElement(ISettingsModel settingsModel, string entityId)
        {
            var preferences = new XElement(PreferencesElementName, new XAttribute(EncryptionModeAttributeName, DpapiEncriptionModeValue));
            var payload = new XElement(PayloadElementName, new XAttribute(PayloadTypeAttributeName, KeyValuePairPayloadTypeValue));

            if (settingsModel != null)
            {
                foreach (var setting in settingsModel.Values)
                {
                    var settingsElement = new XElement(SettingElementName);
                    var key = new XAttribute(KeyAttributeName, setting.Key);

                    var entropy = Encoding.Unicode.GetBytes(entityId);
                    var unprotectedPointer = Marshal.SecureStringToGlobalAllocUnicode(setting.Value);
                    var encrypted = Convert.ToBase64String(ProtectedData.Protect(Encoding.Unicode.GetBytes(Marshal.PtrToStringUni(unprotectedPointer)), entropy, DataProtectionScope.CurrentUser));

                    var value = new XAttribute(ValueAttributeName, encrypted);

                    // Zero out the unprotected string
                    Marshal.ZeroFreeGlobalAllocUnicode(unprotectedPointer);

                    settingsElement.Add(key);
                    settingsElement.Add(value);
                    payload.Add(settingsElement);
                }
            }

            preferences.Add(payload);
            return preferences;
        }
Example #36
0
        /// <inheritdoc />
        public void SaveProject(IProjectModel project, ISettingsModel settings)
        {
            if (project.InternalUrn != settings.EntityUrn)
            {
                throw new ArgumentException("Settings model does not belong to the supplied project");
            }

            this.projectSettings.RemoveAll(ps => ps.EntityUrn == settings.EntityUrn);
            this.projectSettings.Add(settings);
            this.SaveProject(project);
        }
Example #37
0
 public async Task SaveChangesAsync(UserAccount account, ISettingsModel settings)
 {
     if (!isLoggedOut && !string.IsNullOrEmpty(account.Username))
     {
         settings.AddOrUpdate("currentUser", account.Username);
         settings.SaveSettings();
         await StorageModelFactory.GetStorageModel().SaveToStorageAsync(ConnectionString, this);
     }
 }
Example #38
0
 /// <inheritdoc />
 public IEnumerable<ITaskModel> GetQuery(IQueryModel query, ISettingsModel projectSettings, ISettingsModel querySettings)
 {
     return this.taskTracker.GetQuery(projectSettings.Values, querySettings.Values).Select(t => new TaskModel(t, query.Project));
 }
Example #39
0
 public void Logout(ISettingsModel settings)
 {
     isLoggedOut = true;
     bool result = settings.Remove("currentUser");
     settings.SaveSettings();
 }
Example #40
0
 public StockViewModel(IStock stock)
 {
     _stock = stock;
     _stockDataManager = Composition.Compose<IStockDataManager>();
     _settingsModel = Composition.Compose<ISettingsModel>();
 }
Example #41
0
        public async Task<UserAccount> LoadCurrentUser(ISettingsModel settings)
        {
            string currentUser = settings.GetValueOrDefault<string>("currentUser", string.Empty);
            UserAccount currentAccount = UserAccounts
                .Where(item => item.Username.Equals(currentUser))
                .SingleOrDefault();

            if (currentAccount == null)
            {
                // return an anonymous, public user.
                settings.AddOrUpdate("currentUser", string.Empty);
                settings.SaveSettings();
                currentAccount = new UserAccount();
            }
            else
            {
                // attach tokens and favorites
                currentAccount = await AttachAssociationsAsync(currentAccount);

                if (!currentAccount.AsForumAccessToken().IsActiveAccount)
                {
                    settings.AddOrUpdate("currentUser", string.Empty);
                    settings.SaveSettings();
                }
            }

            return currentAccount;
        }
Example #42
0
        /// <inheritdoc />
        public void SaveQuery(IQueryModel query, ISettingsModel settings)
        {
            if (query.InternalUrn != settings.EntityUrn)
            {
                throw new ArgumentException("Settings model does not belong to the supplied query");
            }

            this.querySettings.RemoveAll(qs => qs.EntityUrn == settings.EntityUrn);
            this.querySettings.Add(settings);
            this.SaveQuery(query);
        }
Example #43
0
 /// <inheritdoc />
 public IEnumerable<ITaskModel> GetAssignedToUser(IProjectModel project, ISettingsModel projectSettings)
 {
     return this.taskTracker.GetAssignedToUser(projectSettings.Values).Select(t => new TaskModel(t, project));
 }
 public SettingsPresenter(ISettingsModel model, ISettingsView view)
     : base(model, view) {
     Initialize();
 }