Ejemplo n.º 1
0
        /// <summary>
        /// Replace the object specified by 'path' in 'newSimulation' with the specified 'value'
        /// </summary>
        private static void ApplyModelReplacement(Simulation newSimulation, string path, IModel value)
        {
            IModel newModel = Apsim.Clone(value);

            newSimulation.Locater.Clear();
            IModel modelToReplace = newSimulation.Get(path) as IModel;

            if (modelToReplace == null)
            {
                throw new Exception("Cannot find model to replace. Model path: " + path);
            }

            int index = modelToReplace.Parent.Children.IndexOf(modelToReplace as Model);

            if (index == -1)
            {
                throw new Exception("Cannot find model to replace. Model path: " + path);
            }

            modelToReplace.Parent.Children.RemoveAt(index);
            modelToReplace.Parent.Children.Insert(index, newModel as Model);
            newModel.Name   = modelToReplace.Name;
            newModel.Parent = modelToReplace.Parent;

            Events          events     = new Events(newModel);
            LoadedEventArgs loadedArgs = new LoadedEventArgs();

            events.Publish("Loaded", new object[] { newModel, loadedArgs });
        }
Ejemplo n.º 2
0
        public void DesignSurface_OnLoaded_Invoke_Success(LoadedEventArgs eventArgs)
        {
            var surface = new SubDesignSurface();

            // No handler.
            surface.OnLoaded(eventArgs);

            // Handler.
            int callCount = 0;
            LoadedEventHandler handler = (sender, e) =>
            {
                Assert.Equal(surface, sender);
                Assert.Same(eventArgs, e);
                callCount++;
            };

            surface.Loaded += handler;
            surface.OnLoaded(eventArgs);
            Assert.Equal(1, callCount);

            // Should not call if the handler is removed.
            surface.Loaded -= handler;
            surface.OnLoaded(eventArgs);
            Assert.Equal(1, callCount);
        }
Ejemplo n.º 3
0
        void DesignerLoaded(object sender, LoadedEventArgs e)
        {
            // This method is called when the designer has loaded.
            this.reloadPending = false;
            this.unloading     = false;

            if (e.HasSucceeded)
            {
                // Display the designer on the view content
                Control designView = (Control)this.designSurface.View;

                designView.BackColor   = Color.White;
                designView.RightToLeft = RightToLeft.No;
                // Make sure auto-scaling is based on the correct font.
                // This is required on Vista, I don't know why it works correctly in XP
                designView.Font = System.Windows.Forms.Control.DefaultFont;

                MakeDirty();
                designSurfaceManager.ActiveDesignSurface = this.designSurface;
                this.UserContent = designView;
                this.UpdatePropertyPad();
            }
            else
            {
                // This method can not only be called during initialization,
                // but also when the designer reloads itself because of
                // a language change.
                // When a load error occurs there, we are not somewhere
                // below the Load method which handles load errors.
                // That is why we create an error text box here anyway.
            }
        }
Ejemplo n.º 4
0
        void DesignerLoaded(object sender, LoadedEventArgs e)
        {
            // This method is called when the designer has loaded.
            LoggingService.Debug("Forms designer: DesignerLoader loaded, HasSucceeded=" + e.HasSucceeded.ToString());
            this.reloadPending = false;
            this.unloading     = false;

            if (e.HasSucceeded)
            {
                // Display the designer on the view content
                bool savedIsDirty = this.DesignerCodeFile.IsDirty;
                this.UserControl = (Control)this.designSurface.View;
                LoggingService.Debug("FormsDesigner loaded, setting ActiveDesignSurface to " + this.designSurface.ToString());
                designSurfaceManager.ActiveDesignSurface = this.designSurface;
                this.DesignerCodeFile.IsDirty            = savedIsDirty;
                this.UpdatePropertyPad();
            }
            else
            {
                // This method can not only be called during initialization,
                // but also when the designer reloads itself because of
                // a language change.
                // When a load error occurs there, we are not somewhere
                // below the Load method which handles load errors.
                // That is why we create an error text box here anyway.
                TextBox errorTextBox = new TextBox()
                {
                    Multiline = true, ScrollBars = ScrollBars.Both, ReadOnly = true, BackColor = SystemColors.Window, Dock = DockStyle.Fill
                };
                errorTextBox.Text = String.Concat(this.LoadErrorHeaderText, FormatLoadErrors(designSurface));
                this.UserControl  = errorTextBox;
            }
        }
Ejemplo n.º 5
0
        private void OnLoadedEvent(LoadedEventArgs loadedEvent)
        {
            var thread = new Thread(() =>
            {
                if (loadedEvent.LoadedStarted)
                {
                    if (InvokeRequired)
                    {
                        panel1.Invoke(new Action(() => { panel1.Visible = false; }));
                    }
                    else
                    {
                        panel1.Visible = false;
                    }
                    LoadingAnimator.Wire(panel2);
                }
                if (loadedEvent.LoadedEnded)
                {
                    if (InvokeRequired)
                    {
                        panel1.Invoke(new Action(() => { panel1.Visible = true; }));
                    }
                    else
                    {
                        panel1.Visible = true;
                    }
                    LoadingAnimator.UnWire(panel2);
                }
            });

            thread.Start();
        }
Ejemplo n.º 6
0
 private void OnLoaded(object sender, LoadedEventArgs args)
 {
     Phases = new List <Phase>();
     foreach (Phase phase in Apsim.Children(this, typeof(Phase)))
     {
         Phases.Add(phase);
     }
 }
Ejemplo n.º 7
0
 private void OnLoaded(object sender, LoadedEventArgs args)
 {
     HasLoaded = true;
     if (Script == null && Code != string.Empty)
     {
         RebuildScriptModel(args.errors);
     }
 }
        protected override void Loaded(LoadedEventArgs args)
        {
            base.Loaded(args);
            SetHandler(MessageTags.RegisterRoom, HandleRegisterRoom);
            SetHandler(MessageTags.GetRoomAccess, HandleGetRoomAccess);
            SetHandler(MessageTags.ValidateRoomAccess, HandleValidateRoomAccess);
            SetHandler(MessageTags.GetRooms, HandleGetRooms);

            Task.Run(() => CleanUnconfirmedAccesses());
        }
Ejemplo n.º 9
0
 private void OnLoaded(object sender, LoadedEventArgs args)
 {
     if (phases.Count() == 0) //Need this test to ensure the phases are colated only once
     {
         foreach (IPhase phase in Apsim.Children(this, typeof(IPhase)))
         {
             phases.Add(phase);
         }
     }
 }
Ejemplo n.º 10
0
        internal override void Loaded(LoadedEventArgs args)
        {
            base.Loaded(args);

            httpListener.Start();

            listenThread = new Thread(Listen);
            listenThread.Start();

            Logger.Trace($"HTTP health check started at 'http://{host}:{port}{path}'");
        }
Ejemplo n.º 11
0
        public void TryExtractConfigProtectedData(object s, LoadedEventArgs e)
        {
            TryLoadAppSettings(e.Settings);

            var encr = e.Settings as IXmlEncryptable;

            if (encr != null)
            {
                encr.Providers = Providers;
            }
        }
Ejemplo n.º 12
0
        internal override void Loaded(LoadedEventArgs args)
        {
            Logger.Trace("Setting up timer with " + TickPeriod + "ms period.");

            //Create recurring tick
            timer          = new System.Timers.Timer(TickPeriod);
            timer.Elapsed += Tick;
            timer.Start();

            base.Loaded(args);
        }
 protected override void Loaded(LoadedEventArgs args)
 {
     base.Loaded(args);
     SetHandler(MessageTags.RegisterSpawner, HandleRegisterSpawner);
     SetHandler(MessageTags.RegisterSpawnedProcess, HandleRegisterSpawnedProcess);
     SetHandler(MessageTags.RequestSpawnFromClientToMaster, HandleClientsSpawnRequest);
     SetHandler(MessageTags.RequestSpawnFromMasterToSpawnerSuccess, HandleRequestSpawnFromMasterToSpawnerSuccess);
     SetHandler(MessageTags.RequestSpawnFromMasterToSpawnerFailed, HandleRequestSpawnFromMasterToSpawnerFailed);
     SetHandler(MessageTags.NotifySpawnerKilledProcess, HandleNotifySpawnerKilledProcess);
     SetHandler(MessageTags.CompleteSpawnProcess, HandleCompleteSpawnProcess);
     SetHandler(MessageTags.GetFinalizationData, HandleGetFinalizationData);
 }
Ejemplo n.º 14
0
        protected override void Loaded(LoadedEventArgs loadedArgs)
        {
            base.Loaded(loadedArgs);

            _game = PluginManager.GetPluginByType <GamePlugin>();

            WriteEvent("Connecting to " + MasterIpAddress + ":" + MasterPort, LogType.Info);
            _client.MessageReceived += OnMessageFromMaster;
            _client.ConnectInBackground(MasterIpAddress, MasterPort, IPVersion.IPv4, OnConnectedToMaster);

            ClientManager.ClientConnected += OnPlayerConnected;
        }
Ejemplo n.º 15
0
        public void Ctor_Bool_ICollection(bool succeeded, ICollection errors)
        {
            var e = new LoadedEventArgs(succeeded, errors);

            Assert.Equal(succeeded, e.HasSucceeded);
            if (errors is null)
            {
                Assert.Empty(e.Errors);
            }
            else
            {
                Assert.Same(errors, e.Errors);
            }
        }
Ejemplo n.º 16
0
        /// <summary>Gets the next job to run</summary>
        public Simulation NextSimulationToRun()
        {
            if (allCombinations == null || allCombinations.Count == 0)
            {
                return(null);
            }

            if (serialisedBase == null)
            {
                allCombinations   = AllCombinations();
                parentSimulations = Apsim.Parent(this, typeof(Simulations)) as Simulations;
                Simulation baseSimulation = Apsim.Child(this, typeof(Simulation)) as Simulation;
                serialisedBase = Apsim.SerialiseToStream(baseSimulation) as Stream;
            }

            var combination = allCombinations[0];

            allCombinations.RemoveAt(0);
            string newSimulationName = Name;

            foreach (FactorValue value in combination)
            {
                newSimulationName += value.Name;
            }

            Simulation newSimulation = Apsim.DeserialiseFromStream(serialisedBase) as Simulation;

            newSimulation.Name     = newSimulationName;
            newSimulation.Parent   = null;
            newSimulation.FileName = parentSimulations.FileName;
            Apsim.ParentAllChildren(newSimulation);

            // Make substitutions.
            parentSimulations.MakeSubstitutions(newSimulation);

            // Call OnLoaded in all models.
            Events          events     = new Events(newSimulation);
            LoadedEventArgs loadedArgs = new LoadedEventArgs();

            events.Publish("Loaded", new object[] { newSimulation, loadedArgs });

            foreach (FactorValue value in combination)
            {
                value.ApplyToSimulation(newSimulation);
            }

            PushFactorsToReportModels(newSimulation, combination);
            StoreFactorsInDataStore(newSimulation, combination);
            return(newSimulation);
        }
Ejemplo n.º 17
0
        void DesignerLoaded(object sender, LoadedEventArgs e)
        {
            // This method is called when the designer has loaded.
            LoggingService.Debug("Report designer: DesignerLoader loaded, HasSucceeded=" + e.HasSucceeded.ToString());
//			this.reloadPending = false;
            this.unloading = false;

            if (e.HasSucceeded)
            {
                Control c = null;
                c        = this.designSurface.View as Control;
                c.Parent = this.panel;
                c.Dock   = DockStyle.Fill;
                this.IsFormsDesignerVisible = true;
                // to set ReportFileContent initially, we need to manually call MergeFormChanges.
                // updates to ReportFileContent will be done using the normal Save support in OpenedFile
                // (that just doesn't work initially because the file isn't dirty)
                generator.MergeFormChanges(null);
                StartReportExplorer();
                // Display the designer on the view content
//				bool savedIsDirty = this.DesignerCodeFile.IsDirty;
//				Control designView = (Control)this.designSurface.View;

//				designView.BackColor = Color.White;
//				designView.RightToLeft = RightToLeft.No;
                // Make sure auto-scaling is based on the correct font.
                // This is required on Vista, I don't know why it works correctly in XP
//				designView.Font = Control.DefaultFont;

//				this.UserContent = designView;
                LoggingService.Debug("FormsDesigner loaded, setting ActiveDesignSurface to " + this.designSurface.ToString());
                designSurfaceManager.ActiveDesignSurface = this.designSurface;
//				this.DesignerCodeFile.IsDirty = savedIsDirty;
                this.UpdatePropertyPad();
            }
            else
            {
                // This method can not only be called during initialization,
                // but also when the designer reloads itself because of
                // a language change.
                // When a load error occurs there, we are not somewhere
                // below the Load method which handles load errors.
                // That is why we create an error text box here anyway.


//				TextBox errorTextBox = new TextBox() { Multiline=true, ScrollBars=ScrollBars.Both, ReadOnly=true, BackColor=SystemColors.Window, Dock=DockStyle.Fill };
//				errorTextBox.Text = String.Concat(this.LoadErrorHeaderText, FormatLoadErrors(designSurface));
//				this.UserContent = errorTextBox;
            }
        }
Ejemplo n.º 18
0
        protected override void Loaded(LoadedEventArgs args)
        {
            base.Loaded(args);
            _mailPlugin = PluginManager.GetPluginByType <MailPlugin>();
            _database   = PluginManager.GetPluginByType <MySqlPlugin>();

            SetHandler(MessageTags.LogIn, HandleLogin);
            SetHandler(MessageTags.ConfirmEmail, HandleConfirmEmail);
            SetHandler(MessageTags.RequestAesKey, HandleRequestAesKey);
            SetHandler(MessageTags.ResetPassword, HandleResetPassword);
            SetHandler(MessageTags.RegisterAccount, HandleRegisterAccount);
            SetHandler(MessageTags.RequestPermissionLevel, HandleRequestPermissionLevel);
            SetHandler(MessageTags.RequestPasswordResetCode, HandleRequestPasswordResetCode);
            SetHandler(MessageTags.RequestNewEmailConfirmationCode, HandleRequestNewEmailConfirmationCode);
        }
Ejemplo n.º 19
0
        private void OnLoaded(object sender, LoadedEventArgs args)
        {
            if (XYPairs != null)
            {
                for (int i = 1; i < XYPairs.Y.Length; i++)
                {
                    if (XYPairs.Y[i] != XYPairs.Y[i - 1])
                    {
                        YsAreAllTheSame = false;
                        return;
                    }
                }

                // If we get this far then the Y values must all be the same.
                YsAreAllTheSame = XYPairs.Y.Length > 0;
            }
        }
Ejemplo n.º 20
0
        void DesignerLoaded(object sender, LoadedEventArgs e)
        {
            LoggingService.Debug("ReportDesigner: Event > DesignerLoaded...");
            this.unloading = false;

            if (e.HasSucceeded)
            {
                SetupDesignSurface();
                isFormsDesignerVisible = true;
                generator.MergeFormChanges(null);
//				StartReportExplorer ();

                LoggingService.Debug("FormsDesigner loaded, setting ActiveDesignSurface to " + this.designSurface.ToString());
                designSurfaceManager.ActiveDesignSurface = this.designSurface;
                UpdatePropertyPad();
            }
        }
Ejemplo n.º 21
0
        void DesignerLoaded(object sender, LoadedEventArgs e)
        {
            // This method is called when the designer has loaded.
            LoggingService.Debug("Report designer: DesignerLoader loaded, HasSucceeded=" + e.HasSucceeded.ToString());
            this.unloading = false;

            if (e.HasSucceeded)
            {
                SetupDesignSurface();
                this.IsFormsDesignerVisible = true;
                generator.MergeFormChanges(null);
                StartReportExplorer();

                LoggingService.Debug("FormsDesigner loaded, setting ActiveDesignSurface to " + this.designSurface.ToString());
                designSurfaceManager.ActiveDesignSurface = this.designSurface;
                this.UpdatePropertyPad();
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Create a specific simulation.
        /// </summary>
        public Simulation CreateSpecificSimulation(string name)
        {
            List <List <FactorValue> > allCombinations = AllCombinations();
            Simulation  baseSimulation    = Apsim.Child(this, typeof(Simulation)) as Simulation;
            Simulations parentSimulations = Apsim.Parent(this, typeof(Simulations)) as Simulations;

            foreach (List <FactorValue> combination in allCombinations)
            {
                string newSimulationName = Name;
                foreach (FactorValue value in combination)
                {
                    newSimulationName += value.Name;
                }

                if (newSimulationName == name)
                {
                    Simulation newSimulation = Apsim.Clone(baseSimulation) as Simulation;
                    newSimulation.Name     = newSimulationName;
                    newSimulation.Parent   = null;
                    newSimulation.FileName = parentSimulations.FileName;
                    Apsim.ParentAllChildren(newSimulation);

                    // Make substitutions.
                    parentSimulations.MakeSubstitutions(newSimulation);

                    // Connect events and links in our new  simulation.
                    Events          events     = new Events(newSimulation);
                    LoadedEventArgs loadedArgs = new LoadedEventArgs();
                    events.Publish("Loaded", new object[] { newSimulation, loadedArgs });

                    foreach (FactorValue value in combination)
                    {
                        value.ApplyToSimulation(newSimulation);
                    }

                    PushFactorsToReportModels(newSimulation, combination);

                    return(newSimulation);
                }
            }

            return(null);
        }
Ejemplo n.º 23
0
 protected internal override void Loaded(LoadedEventArgs args)
 {
     if (File.Exists(listLocation))
     {
         try
         {
             ReloadBadWordList();
         }
         catch
         {
             //File may be corrupt, redownload from source
             UpdateBadWordList(false);
         }
     }
     else
     {
         UpdateBadWordList(false);
     }
 }
Ejemplo n.º 24
0
        private void NeuronService_Loaded(object sender, LoadedEventArgs e)
        {
            if (e.IsLoaded)
            {
                this.IsBusy = false;

                this.UiDispatcher.BeginInvokeOnMainThread(async() =>
                {
                    if (this.tagProfile.IsComplete())
                    {
                        await this.navigationService.GoToAsync($"///{nameof(MainPage)}");
                    }
                    else
                    {
                        await this.navigationService.GoToAsync($"/{nameof(RegistrationPage)}");
                    }
                });
            }
        }
    protected override void OnLoaded(LoadedEventArgs e)
    {
        base.OnLoaded(e);
        var svc       = (IExtenderProviderService)this.ServiceContainer.GetService(typeof(IExtenderProviderService));
        var providers = (ArrayList)svc.GetType().GetField("_providers",
                                                          System.Reflection.BindingFlags.NonPublic |
                                                          System.Reflection.BindingFlags.Instance).GetValue(svc);

        foreach (IExtenderProvider p in providers.ToArray())
        {
            if (p.ToString().Contains("NameExtenderProvider") ||
                p.ToString().Contains("NameInheritedExtenderProvider"))
            {
                svc.RemoveExtenderProvider(p);
            }
        }

        svc.AddExtenderProvider(new NameExtenderProvider());
        svc.AddExtenderProvider(new NameInheritedExtenderProvider());
    }
Ejemplo n.º 26
0
        void OnDesignSurfaceLoaded(object pSender, LoadedEventArgs pArgs)
        {
            if (pArgs.HasSucceeded)
            {
                DesignTimeView designView = _DesignSurface.View as DesignTimeView;

                Application.AddMessageFilter(designView);
                designView.DirtyEvent += OnDirtyEvent;
                designView.Dock        = DockStyle.Fill;
                DesignerPanel.Controls.Add(designView);

                // set PropertyGrid.Site, so IDataErrorInfo could work properly.
                _PropertyGrid.Site           = DesignerHost.RootComponent.Site;
                _PropertyGrid.SelectedObject = designView;
            }
            else
            {
                // log errors
                foreach (object error in _DesignSurface.LoadErrors)
                {
                    Exception ex = error as Exception;
                    string    errorString;

                    if (ex != null)
                    {
                        errorString = ex.Message;
                    }
                    else
                    {
                        errorString = error.ToString();
                    }

                    cLog.Error(errorString);
                }
            }
        }
 /// <summary>
 /// Called when the item is Loaded
 /// </summary>
 /// <param name="e">LoadedEventArgs item</param>
 /// <param name="sender">Sender item</param>
 protected static void OnLoaded(object sender, LoadedEventArgs e)
 {
     Utilities.Events.EventHelper.Raise <LoadedEventArgs>(Loaded, sender, e);
 }
Ejemplo n.º 28
0
        /// <summary>Called to start the job.</summary>
        /// <param name="cancelToken">The token to check if job has been cancelled</param>
        public void Run(CancellationTokenSource cancelToken)
        {
            if (simulationEngine != null)
            {
                fileName = simulationEngine.FileName;
                Console.Write("File: " + Path.GetFileNameWithoutExtension(fileName) + ", ");
            }
            Console.WriteLine("Simulation " + simulationToRun.Name + " has commenced.");

            // Start timer to record how long it takes to run
            timer = new Stopwatch();
            timer.Start();

            Events events = null;
            Links  links  = null;

            try
            {
                // Clone simulation
                if (cloneSimulationBeforeRun)
                {
                    simulationToRun = Apsim.Clone(simulationToRun) as Simulation;
                    events          = new Events(simulationToRun);
                    simulationEngine.MakeSubstitutions(simulationToRun);
                    LoadedEventArgs loadedArgs = new LoadedEventArgs();
                    events.Publish("Loaded", new object[] { simulationToRun, loadedArgs });
                }
                else
                {
                    events = new Events(simulationToRun);
                }

                // Get an event and links service
                if (simulationEngine != null)
                {
                    links = simulationEngine.Links;
                }
                else
                {
                    links = new Core.Links(Services);
                }

                // Resolve links and events.
                links.Resolve(simulationToRun);
                events.ConnectEvents();

                simulationToRun.ClearCaches();

                // Send a commence event so the simulation runs
                object[] args         = new object[] { null, new EventArgs() };
                object[] commenceArgs = new object[] { null, new CommenceArgs()
                                                       {
                                                           CancelToken = cancelToken
                                                       } };
                events.Publish("Commencing", args);
                events.Publish("DoCommence", commenceArgs);
            }
            catch (Exception err)
            {
                string errorMessage = "ERROR in file: " + fileName + "\r\n" +
                                      "Simulation name: " + simulationToRun.Name + "\r\n";
                if (err.InnerException == null)
                {
                    errorMessage += err.ToString();
                }
                else
                {
                    errorMessage += err.InnerException.ToString();
                }

                ISummary summary = Apsim.Find(simulationToRun, typeof(Summary)) as ISummary;
                if (summary != null)
                {
                    summary.WriteMessage(simulationToRun, errorMessage);
                }

                throw new Exception(errorMessage);
            }
            finally
            {
                events.Publish("Completed", new object[] { null, new EventArgs() });

                // Cleanup the simulation
                if (events != null)
                {
                    events.DisconnectEvents();
                }
                links.Unresolve(simulationToRun);

                timer.Stop();
                Console.WriteLine("File: " + Path.GetFileNameWithoutExtension(fileName) +
                                  ", Simulation " + simulationToRun.Name + " complete. Time: " + timer.Elapsed.TotalSeconds.ToString("0.00 sec"));
                simulationEngine = null;
                simulationToRun  = null;
            }
        }
Ejemplo n.º 29
0
		protected virtual void OnLoaded (LoadedEventArgs e)
		{
			_loadErrors = e.Errors;
			_isLoaded = e.HasSucceeded;
			
			if (Loaded != null)
				Loaded (this, e);
		}
 /// <summary>
 /// Called when the item is Loaded
 /// </summary>
 /// <param name="e">LoadedEventArgs item</param>
 protected virtual void OnLoaded(LoadedEventArgs e)
 {
     Utilities.Events.EventHelper.Raise <LoadedEventArgs>(Loaded, this, e);
 }
Ejemplo n.º 31
0
		private void OnDesignerHost_Loaded (object sender, LoadedEventArgs e)
		{		   
			if (_loadErrors == null)
				_loadErrors = new object[0];
			
			this.OnLoaded (new LoadedEventArgs (e.HasSucceeded, _loadErrors));
		}
Ejemplo n.º 32
0
        protected override void Loaded(LoadedEventArgs args)
        {
            base.Loaded(args);

            _connectionString = DatabaseManager.GetConnectionString("MySQL");
        }