/// <summary>
 /// Deactivate route in all switchboards
 /// </summary>
 private void FrmRouteEditor_FormClosed(object sender, FormClosedEventArgs e)
 {
     foreach (Switchboard switchboard in Switchboard.FindAll())
     {
         switchboard.ClearRoute();
     }
 }
        public void RemindPortfolio(string id)
        {
            var portfolio = this.Mongo.GetConsumerPortfolio(id);

            if (portfolio != null)
            {
                // notify the switchboard
                Switchboard.ConsumerPortfolioReminded(portfolio);

                // update the timestamp
                portfolio.Reminded = new ChangeReceipt
                {
                    On = DateTimeHelper.Now,
                    By = this.AccountSession.MemberId
                };

                // save to the database
                Update(portfolio);

                // log successful update
                this.Logger.Info(string.Format("reminded consumer portfolio for Id {0} via user {1}", id, this.AccountSession.MemberId));
            }
            else
            {
                // log non-existent consumer portfolio
                this.Logger.Warn(string.Format("could not remind consumer portfolio for Id {0} because it does not exist", id));
            }
        }
        /// <summary>
        /// Returns a new instance of <see cref="SwitchboardDesignControl"/>.
        /// </summary>
        /// <param name="switchboard">Switchboard to paint.</param>
        public SwitchboardDesignControl(Switchboard switchboard)
            : base(switchboard, true)
        {
            InitializeComponent();

            this.Initialize();
        }
Example #4
0
        /// <summary>
        /// Returns a new instance of <see cref="SwitchboardCommandControl"/>.
        /// </summary>
        /// <param name="switchboard">Switchboard to paint.</param>
        public SwitchboardCommandControl(Switchboard switchboard)
            : base(switchboard, false)
        {
            InitializeComponent();

            this.Initialize();
        }
Example #5
0
        public SwitchboardControlBase(Switchboard sb, bool designMode)
        {
            InitializeComponent();

            this.Switchboard       = sb;
            this.DesignModeEnabled = designMode;
        }
Example #6
0
        private void ViewRoutePanel(Switchboard panel,
                                    Route route,
                                    XtraTabControl tabControl,
                                    XtraTabPage tabPage,
                                    SwitchboardRouteEditorControl.CellClickedEventHandler cellClickEvent,
                                    SwitchboardRouteEditorControl.BlockClickedEventHandler blockClickEvent)
        {
            XtraTabPage tabPanel;

            tabControl.SuspendLayout();

            // Generate the grid
            SwitchboardRouteEditorControl spcPanel = new SwitchboardRouteEditorControl(panel, route);

            spcPanel.Dock              = DockStyle.Fill;
            spcPanel.Location          = new System.Drawing.Point(5, 5);
            spcPanel.Name              = "grdPanel" + panel.ID;
            spcPanel.BorderStyle       = BorderStyle.FixedSingle;
            spcPanel.DesignModeEnabled = true;

            // Enable grid events
            if (cellClickEvent != null)
            {
                spcPanel.CellClick += cellClickEvent;
            }
            if (blockClickEvent != null)
            {
                spcPanel.ElementClick += blockClickEvent;
            }

            // Generate the tab page
            if (tabPage == null)
            {
                tabPanel = new XtraTabPage();

                // tabPanel.Controls.Add(grdPanel);
                tabPanel.Name    = "tabPanel" + panel.ID;
                tabPanel.Padding = new Padding(5);
                tabPanel.Text    = panel.Name;
                tabPanel.Image   = Switchboard.SmallIcon;
                tabPanel.Tag     = panel;
                tabPanel.Controls.Add(spcPanel);
            }
            else
            {
                // Clear all page contents
                tabPage.Controls.Clear();

                tabPanel = tabPage;
            }

            tabControl.TabPages.Add(tabPanel);

            // Select the new panel
            tabControl.SelectedTabPage = tabPanel;

            tabControl.ResumeLayout(false);
        }
Example #7
0
        public GameData()
        {
            Switchboard b = new Switchboard();
            TickHandler = new Thread(Tickjes);
            TickHandler.IsBackground = true;
            TickHandler.Start();

            /*sp = new SerialPort("COM10", 115200);
            sp.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);
            sp.Open();*/
        }
Example #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InitializeSwitchboard"/> class.
        /// </summary>
        /// <param name="switchboard">The command switchboard.</param>
        /// <param name="id">The command identifier.</param>
        /// <param name="timestamp">The command timestamp.</param>
        public InitializeSwitchboard(
            Switchboard switchboard,
            Guid id,
            ZonedDateTime timestamp)
            : base(EventType, id, timestamp)
        {
            Debug.NotDefault(id, nameof(id));
            Debug.NotDefault(timestamp, nameof(timestamp));

            this.Switchboard = switchboard;
        }
Example #9
0
        public Form1()
        {
            InitializeComponent();

            string pollSetting = ConfigurationManager.AppSettings["PollIntervalMs"];
            int? pollIntervalMs = pollSetting == null ? (int?) null : int.Parse(pollSetting);
            var servers = ConfigurationManager.AppSettings["HydraServers"].Split(',').Select(s => s.Trim());
            var port = int.Parse(ConfigurationManager.AppSettings["Port"]);
            var hydraService = new StdHydraService(new NearestServerProvider(servers, ConfigurationManager.AppSettings["Database"], port), new ListenerOptions { PollIntervalMs = pollIntervalMs });

            _switchboard = new Switchboard<ConversationDto>(hydraService, MyName);
        }
        /// <summary>
        /// Get an element by its coordinates.
        /// </summary>
        /// <param name="sb">Parent switchboard.</param>
        /// <param name="coords">Coordinates to check.</param>
        /// <returns>The requested element or <c>null</c> if coordinates are empty.</returns>
        public ElementBase Get(Switchboard sb, Coordinates coords)
        {
            foreach (ElementBase element in this)
            {
                if (element.Switchboard == sb && element.IsInCoordinates(coords))
                {
                    return(element);
                }
            }

            return(null);
        }
Example #11
0
        public GameData()
        {
            Switchboard b = new Switchboard();

            TickHandler = new Thread(Tickjes);
            TickHandler.IsBackground = true;
            TickHandler.Start();

            /*sp = new SerialPort("COM10", 115200);
             * sp.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);
             * sp.Open();*/
        }
Example #12
0
        private void imgSwitchboardImage_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            // Get the switchboard to obtain the image
            Switchboard sb = Switchboard.Get(NumericUtils.ToInteger(lblSwitchboardId.Text));

            if (sb == null)
            {
                return;
            }

            // Paint group switchboard
            imgSwitchboardImage.Image = sb.GetImage();
        }
Example #13
0
 /// <summary>
 /// Update an item into the project.
 /// </summary>
 /// <param name="item">Item to update.</param>
 public void Update(Switchboard item)
 {
     try
     {
         // Create the new element into the DB
         OTCProject.LayoutManager.SwitchboardDAO.Update(item);
     }
     catch (Exception ex)
     {
         Logger.LogError(this, ex);
         throw;
     }
 }
Example #14
0
        public FrmPanelEditor(Switchboard panel)
        {
            InitializeComponent();

            this.Switchboard = panel;

            if (panel != null)
            {
                txtName.Text    = this.Switchboard.Name;
                txtNotes.Text   = this.Switchboard.Description;
                txtWidth.Value  = this.Switchboard.Width;
                txtHeight.Value = this.Switchboard.Height;
            }
        }
Example #15
0
    public Call(Switchboard switchboard, List <Call> activeCalls)
    {
        call = switchboard.allCalls[Random.Range(0, switchboard.allCalls.Count)];

        RingToleranceGood    = 10.0f;
        RingToleranceNeutral = 15.0f;
        CallLength           = 5.0f;

        do
        {
            Caller = Random.Range(0, 47);
        } while (activeCalls.Any(x => x.Caller == Caller || x.Callee == Caller));

        Callee = call.Destination;
    }
        private void ViewAddCommandPanel(Switchboard panel,
                                         XtraTabControl tabControl,
                                         XtraTabPage tabPage,
                                         SwitchboardCommandControl.BlockAssignmentChangedEventHandler blockAssignmentChangedEvent)
        {
            XtraTabPage tabPanel;

            tabControl.SuspendLayout();

            // Generate the grid
            SwitchboardCommandControl spcPanel = new SwitchboardCommandControl(panel);

            spcPanel.Dock        = System.Windows.Forms.DockStyle.Fill;
            spcPanel.Location    = new System.Drawing.Point(5, 5);
            spcPanel.Name        = "grdPanel" + panel.ID;
            spcPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;

            // Subscribe required events
            spcPanel.BlockAssignmentChanged += blockAssignmentChangedEvent;

            // Generate the tab page
            if (tabPage == null)
            {
                tabPanel = new XtraTabPage();

                // tabPanel.Controls.Add(grdPanel);
                tabPanel.Name    = "tabPanel" + panel.ID;
                tabPanel.Padding = new System.Windows.Forms.Padding(5);
                tabPanel.Text    = panel.Name;
                tabPanel.Image   = Switchboard.SmallIcon;
                tabPanel.Tag     = panel;
                tabPanel.Controls.Add(spcPanel);
            }
            else
            {
                // Clear all page contents
                tabPage.Controls.Clear();

                tabPanel = tabPage;
            }

            tabControl.TabPages.Add(tabPanel);

            // Select the new panel
            tabControl.SelectedTabPage = tabPanel;

            tabControl.ResumeLayout(false);
        }
Example #17
0
        /// <summary>
        /// Delete the specified item from the project.
        /// </summary>
        /// <param name="item">Item to remove.</param>
        public void Remove(Switchboard item)
        {
            try
            {
                // Create the new element into the DB
                OTCProject.LayoutManager.SwitchboardDAO.Delete(item.ID);

                // Add the new element into the in-memory project
                this.Switchboards.Remove(item);
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);
                throw;
            }
        }
Example #18
0
        public MockMessageBusProvider(IComponentryContainer container)
        {
            var adapter = new MessageBusAdapter(
                new MessageBus <Command>(container),
                new MessageBus <Event>(container),
                new MessageBus <Message>(container));

            this.Adapter = adapter;

            var initializeSwitchboard = new InitializeSwitchboard(
                Switchboard.Empty(),
                Guid.NewGuid(),
                container.Clock.TimeNow());

            adapter.Send(initializeSwitchboard);
        }
Example #19
0
//      /// <summary>
//      /// Adds a new panel into the current project.
//      /// </summary>
//      /// <param name="element">An implementation of <see cref="ElementBase"/> containing the data for new object.</param>
//      public void Add(Element element)
//      {
//         string sql = string.Empty;

//         Logger.LogDebug(this, "[CLASS].Add([{0}])", element);

//         try
//         {
//            // Remove element in the current position
//            this.DeleteByCoords(element.Switchboard, element.Coordinates);

//            Connect();

//            // Create the new element
//            sql = @"INSERT INTO
//                        " + ElementDAO.SQL_TABLE + @" (" + ElementDAO.SQL_FIELDS_INSERT + @")
//                    VALUES
//                        (@switchboardid, @name, @x, @y, @rotation, @type, @status)";

//            SetParameter("switchboardid", element.Switchboard.ID);
//            SetParameter("name", element.Name);
//            SetParameter("x", element.X);
//            SetParameter("y", element.Y);
//            SetParameter("rotation", element.Rotation);
//            SetParameter("type", element.Properties.ID);
//            SetParameter("status", element.AccessoryStatus);

//            ExecuteNonQuery(sql);

//            // Obtiene el nuevo ID
//            sql = @"SELECT
//                        Max(id) As id
//                    FROM
//                        " + ElementDAO.SQL_TABLE;

//            element.ID = (int)ExecuteScalar(sql, 0);
//         }
//         catch (Exception ex)
//         {
//            Logger.LogError(this, ex);

//            throw;
//         }
//         finally
//         {
//            Disconnect();
//         }
//      }

//      /// <summary>
//      /// Update the specified element data.
//      /// </summary>
//      /// <param name="element">An instance with the updated data.</param>
//      public void Update(Element element)
//      {
//         string sql = string.Empty;

//         Logger.LogDebug(this, "[CLASS].Update([{0}])", element);

//         try
//         {
//            Connect();

//            sql = @"UPDATE
//                        " + ElementDAO.SQL_TABLE + @"
//                    SET
//                        switchboardid = @switchboardid,
//                        name = @name,
//                        x = @x,
//                        y = @y,
//                        rotation = @rotation,
//                        type = @type,
//                        status = @status
//                    WHERE
//                        id = @id";

//            SetParameter("switchboardid", element.Switchboard.ID);
//            SetParameter("name", element.Name);
//            SetParameter("x", element.X);
//            SetParameter("y", element.Y);
//            SetParameter("rotation", element.Rotation);
//            SetParameter("type", element.Properties.ID);
//            SetParameter("status", element.AccessoryStatus);
//            SetParameter("id", element.ID);

//            ExecuteNonQuery(sql);
//         }
//         catch (Exception ex)
//         {
//            Logger.LogError(this, ex);

//            throw;
//         }
//         finally
//         {
//            Disconnect();
//         }
//      }

//      /// <summary>
//      /// Update the state of the specified element.
//      /// </summary>
//      /// <param name="element">Element with the updated status.</param>
//      public void UpdateStatus(Element element)
//      {
//         string sql = string.Empty;

//         Logger.LogDebug(this, "[CLASS].UpdateStatus([{0}])", element);

//         try
//         {
//            Connect();

//            sql = @"UPDATE
//                        " + ElementDAO.SQL_TABLE + @"
//                    SET
//                        status = @status
//                    WHERE
//                        id = @id";

//            SetParameter("status", element.AccessoryStatus);
//            SetParameter("id", element.ID);

//            ExecuteNonQuery(sql);
//         }
//         catch (Exception ex)
//         {
//            Logger.LogError(this, ex);

//            throw;
//         }
//         finally
//         {
//            Disconnect();
//         }
//      }

//      /// <summary>
//      /// Delete a element and all its related data.
//      /// </summary>
//      /// <param name="id">Element unique identifier (DB).</param>
//      public int Delete(long id)
//      {
//         string sql = string.Empty;
//         Element element = null;

//         Logger.LogDebug(this, "[CLASS].Delete({0})", id);

//         try
//         {
//            // Get the element
//            element = Element.Get(id);
//            if (element == null) return 0;

//            // Unassign module connections
//            OTCContext.Project.LayoutManager.DeviceConnectionDAO.Unassign(element);

//            // Delete route elements
//            OTCContext.Project.LayoutManager.RouteElementDAO.DeleteByElement(element);

//            // Unassign route activators
//            OTCContext.Project.LayoutManager.RouteDAO.Unassign(element);

//            Connect();

//            // Delete element
//            sql = @"DELETE
//                    FROM
//                        " + ElementDAO.SQL_TABLE + @"
//                    WHERE
//                        id = @id";

//            SetParameter("id", id);

//            return ExecuteNonQuery(sql);
//         }
//         catch (Exception ex)
//         {
//            Logger.LogError(this, ex);

//            throw;
//         }
//         finally
//         {
//            Disconnect();
//         }
//      }

//      /// <summary>
//      /// Delete the element ubicated in the specified coordinates (and all its related information).
//      /// </summary>
//      /// <param name="sb">Switchboard where the element is placed.</param>
//      /// <param name="coords">The element position.</param>
//      public void DeleteByCoords(Switchboard sb, Coordinates coords)
//      {
//         int id;
//         string sql = string.Empty;

//         Logger.LogDebug(this, "[CLASS].DeleteByCoords([{0}], [{1}])", sb, coords);

//         try
//         {
//            Connect();

//            sql = @"SELECT
//                        id
//                    FROM
//                        " + ElementDAO.SQL_TABLE + @"
//                    WHERE
//                        switchboardid = @switchboardid And
//                        x             = @x             And
//                        y             = @y";

//            SetParameter("switchboardid", sb.ID);
//            SetParameter("x", coords.X);
//            SetParameter("y", coords.Y);

//            id = (int)ExecuteScalar(sql, 0);

//            Disconnect();

//            if (id != 0)
//            {
//               this.Delete(id);
//            }
//         }
//         catch (Exception ex)
//         {
//            Logger.LogError(this, ex);

//            throw;
//         }
//         finally
//         {
//            Disconnect();
//         }
//      }

//      /// <summary>
//      /// Rotate a element and update the data into project database.
//      /// </summary>
//      /// <param name="element">The element that's being rotated.</param>
//      public void Rotate(Element element)
//      {
//         string sql = string.Empty;

//         Logger.LogDebug(this, "[CLASS].Rotate([{0}])", element);

//         try
//         {
//            element.Rotate();

//            Connect();

//            sql = @"UPDATE
//                        " + ElementDAO.SQL_TABLE + @"
//                    SET
//                        rotation = @rotation
//                    WHERE
//                        id = @id";

//            SetParameter("rotation", element.Rotation);
//            SetParameter("id", element.ID);

//            ExecuteNonQuery(sql);
//         }
//         catch (Exception ex)
//         {
//            Logger.LogError(this, ex);

//            throw;
//         }
//         finally
//         {
//            Disconnect();
//         }
//      }

        /// <summary>
        /// Move all switchboard blocks to the specified orientation.
        /// </summary>
        /// <param name="sb">Switchboard to move.</param>
        /// <param name="dir">Movement orientation.</param>
        public void Move(Switchboard sb, Switchboard.MoveDirection dir)
        {
            string dirSql;
            string sql = string.Empty;

            Logger.LogDebug(this, "[CLASS].Move([{0}], {1})", sb, dir);

            try
            {
                switch (dir)
                {
                case Switchboard.MoveDirection.Up: dirSql = "y = y-1"; break;

                case Switchboard.MoveDirection.Down: dirSql = "y = y+1"; break;

                case Switchboard.MoveDirection.Left: dirSql = "x = x-1"; break;

                case Switchboard.MoveDirection.Right: dirSql = "x = x+1"; break;

                default: dirSql = string.Empty; break;
                }

                Connect();

                sql = @"UPDATE 
                        " + Element.TableName + @" 
                    SET 
                        " + dirSql + @"
                    WHERE 
                        switchboardid = @switchboardid";

                SetParameter("switchboardid", sb.ID);

                ExecuteNonQuery(sql);
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);

                throw;
            }
            finally
            {
                Disconnect();
            }
        }
Example #20
0
        public MessageBusTests(ITestOutputHelper output)
        {
            // Fixture Setup
            this.container  = TestComponentryContainer.Create(output);
            this.receiver   = new MockComponent(this.container, "1");
            this.messageBus = new MessageBus <Event>(this.container);

            var addresses = new Dictionary <Address, IEndpoint>
            {
                { ComponentAddress.DataService, this.receiver.Endpoint },
                { ComponentAddress.Scheduler, this.receiver.Endpoint },
            };

            this.messageBus.Endpoint.SendAsync(new InitializeSwitchboard(
                                                   Switchboard.Create(addresses),
                                                   this.container.GuidFactory.Generate(),
                                                   this.container.Clock.TimeNow()));

            this.receiver.RegisterHandler <IEnvelope>(this.receiver.OnMessage);
        }
Example #21
0
    // Use this for initialization
    void Start()
    {
        // Set jack name
        gameObject.name = "Jack_" + Id;
        if (!Board)
        {
            GameObject  goBoard = GameObject.Find("switchboard");
            Switchboard brd     = goBoard.GetComponent <Switchboard>();
            if (brd)
            {
                _board = brd;
            }
        }
        _board.RegisterJack(this);
        _lightControl = GetComponent <LightController>();
        _audioSource  = GetComponent <AudioSource>();

        // Subscribe to snapzone events
        _snapDropZone = GetComponentInChildren <VRTK_SnapDropZone>();
        _snapDropZone.ObjectSnappedToDropZone     += new SnapDropZoneEventHandler(OnSnap);
        _snapDropZone.ObjectUnsnappedFromDropZone += new SnapDropZoneEventHandler(OnUnsnap);
    }
Example #22
0
        public IActionResult Calculate(string visitortype)
        {
            ISwitchboardVisitor visitor = null;

            if (visitortype == "Normal")
            {
                visitor = new NormalVisitor();
            }
            else
            {
                visitor = new SpecialVisitor();
            }

            Switchboard switchboard = new Switchboard(visitor);

            switchboard.Items.Add(new Enclosure()
            {
                Cost = 50000
            });
            switchboard.Items.Add(new Transformer()
            {
                Cost = 10000
            });
            switchboard.Items.Add(new Busbars()
            {
                Cost = 5000
            });
            switchboard.Items.Add(new CircuitBreaker()
            {
                Cost = 20000
            });
            double totalCost = switchboard.Calculate();

            ViewBag.PackingShippingType = visitortype;
            ViewBag.TotalCost           = totalCost;
            return(View());
        }
        public static void ViewAddPanel(Switchboard panel,
                                        XtraTabControl tabControl,
                                        XtraTabPage tabPage,
                                        SwitchboardDesignControl.CellClickedEventHandler cellClickEvent,
                                        SwitchboardDesignControl.BlockClickedEventHandler blockClickEvent,
                                        SwitchboardDesignControl.BlockDoubleClickedEventHandler blockDoubleClickEvent)
        {
            XtraTabPage tabPanel;

            tabControl.SuspendLayout();

            // Generate the grid
            SwitchboardDesignControl spcPanel = new SwitchboardDesignControl(panel);

            spcPanel.Dock        = DockStyle.Fill;
            spcPanel.Location    = new System.Drawing.Point(5, 5);
            spcPanel.Name        = "grdPanel" + panel.ID;
            spcPanel.BorderStyle = BorderStyle.FixedSingle;

            // Enable grid events
            if (cellClickEvent != null)
            {
                spcPanel.CellClick += cellClickEvent;
            }
            if (blockClickEvent != null)
            {
                spcPanel.ElementClick += blockClickEvent;
            }
            if (blockDoubleClickEvent != null)
            {
                spcPanel.BlockDoubleClick += blockDoubleClickEvent;
            }

            // Generate the tab page
            if (tabPage == null)
            {
                tabPanel = new XtraTabPage();

                // tabPanel.Controls.Add(grdPanel);
                tabPanel.Name    = "tabPanel" + panel.ID;
                tabPanel.Padding = new Padding(5);
                tabPanel.Text    = panel.Name;
                tabPanel.Image   = Properties.Resources.ICO_PANEL_16;
                tabPanel.Tag     = panel;
                tabPanel.Controls.Add(spcPanel);
            }
            else
            {
                // Clear all page contents
                tabPage.Controls.Clear();

                tabPanel = tabPage;
            }

            tabControl.TabPages.Add(tabPanel);

            // Select the new panel
            tabControl.SelectedTabPage = tabPanel;

            tabControl.ResumeLayout(false);
        }
Example #24
0
        static Bus ConfigureBus()
        {
            var b = new Switchboard();

            // Personal plan
            b.RegisterHandler <CreatePersonalPlan>((c) =>
            {
                var repository = new RepositoryFactory(bus, container).Build <Plan>();
                var plan       = new Plan((PlanId)c.Id, c.Name, c.Description, c.Owner, PlanType.Personal);
                plan.AssignOwnership(c.Owner);
                repository.Save(plan);
            });

            b.RegisterSubscriber <PersonalPlanCreated>((c) =>
            {
                Persist <Plans, PlanDto>(new PlanDto
                {
                    PlanId        = c.Id,
                    Name          = c.Name,
                    Description   = c.Description,
                    Owner         = c.Owner,
                    NumberOfTasks = 0,
                    PlanType      = PlanType.Personal.ToString()
                });
            });



            //
            // Collab plan
            b.RegisterHandler <CreateCollaborativePlan>((c) =>
            {
                var repository = new RepositoryFactory(bus, container).Build <Plan>();
                var plan       = new Plan((PlanId)c.Id, c.Name, c.Description, c.Owner, PlanType.Collaborative);
                plan.AssignOwnership(c.Owner);
                repository.Save(plan);
            });

            b.RegisterSubscriber <CollaborativePlanCreated>((c) =>
            {
                Persist <Plans, PlanDto>(new PlanDto
                {
                    PlanId      = c.Id,
                    Name        = c.Name,
                    Description = c.Description,
                    Owner       = c.Owner, NumberOfTasks = 0,
                    PlanType    = PlanType.Collaborative.ToString()
                });
            });


            //
            // Distributable plan
            b.RegisterHandler <CreateDistributablePlan>((c) =>
            {
                var repository = new RepositoryFactory(bus, container).Build <Plan>();
                var plan       = new Plan((PlanId)c.Id, c.Name, c.Description, c.Owner, PlanType.Distributable);
                plan.AssignOwnership(c.Owner);

                repository.Save(plan);
            });

            b.RegisterSubscriber <DistributablePlanCreated>((c) =>
            {
                Persist <Plans, PlanDto>(new PlanDto
                {
                    PlanId        = c.Id,
                    Name          = c.Name,
                    Description   = c.Description,
                    Owner         = c.Owner,
                    NumberOfTasks = 0,
                    PlanType      = PlanType.Distributable.ToString()
                });
            });



            //
            // Task creation
            b.RegisterHandler <CreateTask>((c) =>
            {
                var repository = new RepositoryFactory(bus, container).Build <Task>();
                var task       = new Task((TaskId)c.TaskId, (PlanId)c.PlanId, c.Name, c.Interval);
                repository.Save(task);
            });

            b.RegisterSubscriber <TaskCreated>((c) =>
            {
                var plan     = FindById <Plans, PlanDto>(c.PlanId);
                var planName = (plan != null) ? plan.Name : "Undefined plan";
                Persist <Tasks, TaskDto>(new TaskDto
                {
                    PlanId      = c.PlanId,
                    TaskTitle   = c.Title,
                    TaskId      = c.Id,
                    Reccurence  = c.Interval.ToString(),
                    Description = "",
                    PlanName    = planName
                });

                // Add number of tasks
                // REVISIT This might nde to be an scalar query.
                Mutate <Plans, PlanDto>(c.PlanId,
                                        (dto) =>
                {
                    dto.NumberOfTasks += 1;
                }
                                        );
            });



            //
            // Task creation
            b.RegisterHandler <MarkTaskCompleted>((c) =>
            {
                var repository = new RepositoryFactory(bus, container).Build <Task>();
                var task       = repository.GetById(c.TaskId);
                task.MarkCompleted(c.CompletedBy, DateTimeOffset.Parse(c.Timestamp));
                repository.Save(task);
            });

            b.RegisterSubscriber <TaskMarkedCompleted>((c) =>
            {
                var task   = FindById <Tasks, TaskDto>(c.Id);
                var planId = (task != null) ? task.PlanId : Guid.Empty;

                Persist <Tasks, CompletedTaskDto>(new CompletedTaskDto
                {
                    CompletedBy   = c.User,
                    LastCompleted = c.Timestamp,
                    PlanId        = planId,
                    TaskId        = c.Id
                });

                // Add number of tasks
                // REVISIT This might nde to be an scalar query.
                Mutate <Tasks, TaskDto>(c.Id,
                                        (dto) =>
                {
                    if (dto.LastCompletion == null ||
                        DateTimeOffset.Parse(dto.LastCompletion) < DateTimeOffset.Parse(c.Timestamp))
                    {
                        dto.LastCompletion = c.Timestamp;
                    }
                }
                                        );
            });


            // Task creation
            b.RegisterHandler <RevokeTaskCompletion>((c) =>
            {
                var repository = new RepositoryFactory(bus, container).Build <Task>();
                var task       = repository.GetById(c.TaskId);
                task.RevokeCompletion(c.RevokedBy, DateTimeOffset.Parse(c.RevocationTimestamp));
                repository.Save(task);
            });



            b.RegisterHandler <AddCollaborator>((c) =>
            {
                var repository = new RepositoryFactory(bus, container).Build <Plan>();
                var plan       = repository.GetById(c.PlanId);
                plan.AddCollaborator(c.Collaborator, (CollaboratorRole)Enum.Parse(typeof(CollaboratorRole), c.Role));
                repository.Save(plan);
            });

            b.RegisterSubscriber <PlanCollaboratorAdded>((c) =>
            {
                Persist <CollaborationRepo, CollaboratorDto>(new CollaboratorDto
                {
                    PlanId         = c.PlanId,
                    Username       = c.Name,
                    Role           = c.Role,
                    DisplayName    = c.Name,
                    CollaboratorId = Guid.NewGuid()
                });
            });

            return(b);
        }
 /// <summary>
 /// Get an element by its coordinates.
 /// </summary>
 /// <param name="sb">Parent switchboard.</param>
 /// <param name="col">Coordinates to check (X).</param>
 /// <param name="row">Coordinates to check (Y).</param>
 /// <returns>The requested element or <c>null</c> if coordinates are empty.</returns>
 public ElementBase Get(Switchboard sb, int col, int row)
 {
     return(this.Get(sb, new Coordinates(col, row)));
 }
Example #26
0
 /// <summary>
 /// Returns a new instance of <see cref="SwitchboardRouteEditorControl"/>.
 /// </summary>
 /// <param name="switchboard">Switchboard to paint.</param>
 /// <param name="route">Route to edit in control.</param>
 public SwitchboardRouteEditorControl(Switchboard switchboard, Route route = null)
     : base(switchboard, false)
 {
     this.Route = route;
 }
 /// <summary>
 /// Returns a new instance of <see cref="SwitchboardRouteEditorControl"/>.
 /// </summary>
 /// <param name="switchboard">Switchboard to paint.</param>
 /// <param name="route">Route to edit in control.</param>
 public SwitchboardRouteEditorControl(Switchboard switchboard, Route route)
     : base(switchboard, true)
 {
     this.Initialize(route);
 }
Example #28
0
    private void MoveMarble(int x, int y)
    {
        int addx = selectedMarble.CurrentX - x;
        int addy = selectedMarble.CurrentY - y;

        if (allowedMoves[x, y] == false)
        {
            BoardHighlights.Instance.HideHighlights();
            selectedMarble = null;
            return;
        }
        if (selectedMarble.GetType() == typeof(EntangledMarble))
        {
            Marble        c            = null;
            List <Marble> existingOnes = new List <Marble>();
            existingOnes.Add(selectedMarble);
            foreach (Marble mar in Marbles)
            {
                if (mar != null && mar != selectedMarble)
                {
                    existingOnes.Add(mar);
                }
                //existingOnes.Reverse();
            }
            if (addx == 1)
            {
                existingOnes.Sort((a, b) => a.CurrentX.CompareTo(b.CurrentX));
            }
            if (addx == -1)
            {
                existingOnes.Sort((a, b) => a.CurrentX.CompareTo(b.CurrentX));
                existingOnes.Reverse();
            }
            if (addy == 1)
            {
                existingOnes.Sort((a, b) => a.CurrentY.CompareTo(b.CurrentY));
            }
            if (addy == -1)
            {
                existingOnes.Sort((a, b) => a.CurrentY.CompareTo(b.CurrentY));
                existingOnes.Reverse();
            }
            foreach (Marble mar in existingOnes)
            {
                if (mar != null && mar != c)
                {
                    if (mar.GetType() == typeof(EntangledMarble))
                    {
                        int newx = mar.CurrentX - addx;
                        int newy = mar.CurrentY - addy;
                        if (newx >= 0 && newx < GridSize && newy >= 0 && newy < GridSize && leveldesign[(GridSize - 1) - newy, newx] != 3)
                        {
                            if (mar.PossibleMove()[newx, newy])
                            {
                                Marbles[mar.CurrentX, mar.CurrentY] = null;
                                mar.transform.position = GetTileCenter(newx, newy);
                                mar.SetPosition(newx, newy);
                                Marbles[newx, newy] = mar;
                                if (leveldesign[(GridSize - 1) - newy, newx] == 2)
                                {
                                    activePiece.Remove(mar.gameObject);
                                    Marbles[newx, newy] = null;
                                    Destroy(mar.gameObject);
                                }
                            }
                        }
                    }
                    c = mar;
                }
            }
            moves_left -= 1;
        }
        else if (selectedMarble.GetType() == typeof(MagneticMarbleRed))
        {
            Marble        c            = null;
            List <Marble> existingOnes = new List <Marble>();
            existingOnes.Add(selectedMarble);
            foreach (Marble mar in Marbles)
            {
                if (mar != null && mar != selectedMarble)
                {
                    existingOnes.Add(mar);
                }
            }
            if (addx == 1)
            {
                existingOnes.Sort((a, b) => a.CurrentX.CompareTo(b.CurrentX));
            }
            if (addx == -1)
            {
                existingOnes.Sort((a, b) => a.CurrentX.CompareTo(b.CurrentX));
                existingOnes.Reverse();
            }
            if (addy == 1)
            {
                existingOnes.Sort((a, b) => a.CurrentY.CompareTo(b.CurrentY));
            }
            if (addy == -1)
            {
                existingOnes.Sort((a, b) => a.CurrentY.CompareTo(b.CurrentY));
                existingOnes.Reverse();
            }
            foreach (Marble mar in existingOnes)
            {
                if (mar != null && mar != c)
                {
                    if (mar.GetType() == typeof(MagneticMarbleRed))
                    {
                        int newx = mar.CurrentX - addx;
                        int newy = mar.CurrentY - addy;
                        if (newx >= 0 && newx < GridSize && newy >= 0 && newy < GridSize && leveldesign[(GridSize - 1) - newy, newx] != 3)
                        {
                            if (mar.PossibleMove()[newx, newy])
                            {
                                Marbles[mar.CurrentX, mar.CurrentY] = null;
                                mar.transform.position = GetTileCenter(newx, newy);
                                mar.SetPosition(newx, newy);
                                Marbles[newx, newy] = mar;
                                if (leveldesign[(GridSize - 1) - newy, newx] == 2)
                                {
                                    activePiece.Remove(mar.gameObject);
                                    Marbles[newx, newy] = null;
                                    Destroy(mar.gameObject);
                                }
                            }
                        }
                    }
                    if (mar.GetType() == typeof(MagneticMarbleBlue))
                    {
                        int newx = mar.CurrentX + addx;
                        int newy = mar.CurrentY + addy;
                        if (newx >= 0 && newx < GridSize && newy >= 0 && newy < GridSize && leveldesign[(GridSize - 1) - newy, newx] != 3)
                        {
                            if (mar.PossibleMove()[newx, newy])
                            {
                                Marbles[mar.CurrentX, mar.CurrentY] = null;
                                mar.transform.position = GetTileCenter(newx, newy);
                                mar.SetPosition(newx, newy);
                                Marbles[newx, newy] = mar;
                                if (leveldesign[(GridSize - 1) - newy, newx] == 2)
                                {
                                    activePiece.Remove(mar.gameObject);
                                    Marbles[newx, newy] = null;
                                    Destroy(mar.gameObject);
                                }
                            }
                        }
                    }
                    c = mar;
                }
            }
            moves_left -= 1;
        }
        else if (selectedMarble.GetType() == typeof(MagneticMarbleBlue))
        {
            Marble        c            = null;
            List <Marble> existingOnes = new List <Marble>();
            existingOnes.Add(selectedMarble);
            foreach (Marble mar in Marbles)
            {
                if (mar != null && mar != selectedMarble)
                {
                    existingOnes.Add(mar);
                }
            }
            if (addx == 1)
            {
                existingOnes.Sort((a, b) => a.CurrentX.CompareTo(b.CurrentX));
            }
            if (addx == -1)
            {
                existingOnes.Sort((a, b) => a.CurrentX.CompareTo(b.CurrentX));
                existingOnes.Reverse();
            }
            if (addy == 1)
            {
                existingOnes.Sort((a, b) => a.CurrentY.CompareTo(b.CurrentY));
            }
            if (addy == -1)
            {
                existingOnes.Sort((a, b) => a.CurrentY.CompareTo(b.CurrentY));
                existingOnes.Reverse();
            }
            foreach (Marble mar in existingOnes)
            {
                if (mar != null && mar != c)
                {
                    if (mar.GetType() == typeof(MagneticMarbleBlue))
                    {
                        int newx = mar.CurrentX - addx;
                        int newy = mar.CurrentY - addy;
                        if (newx >= 0 && newx < GridSize && newy >= 0 && newy < GridSize && leveldesign[(GridSize - 1) - newy, newx] != 3)
                        {
                            if (mar.PossibleMove()[newx, newy])
                            {
                                Marbles[mar.CurrentX, mar.CurrentY] = null;
                                mar.transform.position = GetTileCenter(newx, newy);
                                mar.SetPosition(newx, newy);
                                Marbles[newx, newy] = mar;
                                if (leveldesign[(GridSize - 1) - newy, newx] == 2)
                                {
                                    activePiece.Remove(mar.gameObject);
                                    Marbles[newx, newy] = null;
                                    Destroy(mar.gameObject);
                                }
                            }
                        }
                    }
                    if (mar.GetType() == typeof(MagneticMarbleRed))
                    {
                        int newx = mar.CurrentX + addx;
                        int newy = mar.CurrentY + addy;
                        if (newx >= 0 && newx < GridSize && newy >= 0 && newy < GridSize && leveldesign[(GridSize - 1) - newy, newx] != 3)
                        {
                            if (mar.PossibleMove()[newx, newy])
                            {
                                Marbles[mar.CurrentX, mar.CurrentY] = null;
                                mar.transform.position = GetTileCenter(newx, newy);
                                mar.SetPosition(newx, newy);
                                Marbles[newx, newy] = mar;
                                if (leveldesign[(GridSize - 1) - newy, newx] == 2)
                                {
                                    activePiece.Remove(mar.gameObject);
                                    Marbles[newx, newy] = null;
                                    Destroy(mar.gameObject);
                                }
                            }
                        }
                    }
                    c = mar;
                }
            }
            moves_left -= 1;
        }
        else if (allowedMoves[x, y] && leveldesign[(GridSize - 1) - y, x] != 3)
        {
            Marbles[selectedMarble.CurrentX, selectedMarble.CurrentY] = null;
            selectedMarble.transform.position = GetTileCenter(x, y);
            selectedMarble.SetPosition(x, y);
            Marbles[x, y] = selectedMarble;
            if (leveldesign[(GridSize - 1) - y, x] == 2)
            {
                activePiece.Remove(selectedMarble.gameObject);
                Destroy(selectedMarble.gameObject);
            }
            moves_left -= 1;
        }
        BoardHighlights.Instance.HideHighlights();
        selectedMarble = null;
        if (isPath(Marbles, strtx, strty, finx, finy, GridSize))
        {
            if (level_number <= 5)
            {
                level_number += 5;
                GridSize      = 10;
                Switchboard.HideEight();
                gob.SetActive(true);
                foreach (GameObject ob in activePiece)
                {
                    Destroy(ob);
                }
            }
            else if (level_number == 6)
            {
                SceneManager.LoadScene(3);
            }
            else if (level_number == 7)
            {
                SceneManager.LoadScene(4);
            }
            else if (level_number == 8)
            {
                SceneManager.LoadScene(5);
            }
            else if (level_number == 9)
            {
                SceneManager.LoadScene(6);
            }
            else if (level_number == 10)
            {
                SceneManager.LoadScene(12);
            }
            LevelMovesLeft.movesl += 111;
            NumOfLevel.leveln      = level_number;
            SpawnAllLevel();
        }
        LevelMovesLeft.movesl = moves_left;
    }