Esempio n. 1
0
        //------------------------------------------------------------------------------------------
        //------------------------------------------------------------------------------------------
        private void _ChangeWidget(ActiveBoard b, Change change)
        {
            /*verificam ce s-a schimbat */
            var jss             = new JavaScriptSerializer();
            ChangeDataWidget cd = null;

            try {
                cd = jss.Deserialize <ChangeDataWidget>(change.ChangeString);
            } catch {
                return;
            }

            /*cautam activelayer-ul parinte*/
            if (!b.Layers.ContainsKey(cd.LayerId))
            {
                throw new Exception("Parent layer id for changed widget not found");
            }

            ActiveLayer  l = b.Layers[cd.LayerId];
            ActiveWidget w = null;

            /*cautam activewidget-ul corespunzator*/
            if (!l.Widgets.ContainsKey(cd.Id))
            {
                throw new Exception("Changed widget id not found");
            }
            try {
                w = l.Widgets[cd.Id];
            } catch (KeyNotFoundException) {
                return;
            }


            /*modificam campurile*/
            w.Name = (w.WidgetEntity.Name = cd.Name);
            w.Type = (w.WidgetEntity.Type = cd.Type);
            w.Data = (w.WidgetEntity.Data = cd.Data);

            /*  daca e schimbat orderul, trebuie refacut stack-ul */
            if (cd.Order != w.WidgetEntity.Order)
            {
                w.WidgetEntity.Order = cd.Order;
                /*il stergem din pozitia existenta*/
                l.WidgetsStack.Remove(w);
                /*il reinseram*/
                if (l.WidgetsStack.Count <= cd.Order)
                {
                    l.WidgetsStack.Add(w);
                }
                else
                {
                    l.WidgetsStack.Insert(cd.Order, w);
                }
            }
        }
Esempio n. 2
0
        //------------------------------------------------------------------------------------------
        //------------------------------------------------------------------------------------------
        private void _AddWidget(ActiveBoard b, Change change)
        {
            ActiveWidget newActiveWidget = new ActiveWidget();
            var          jss             = new JavaScriptSerializer();

            ChangeDataWidget cd = jss.Deserialize <ChangeDataWidget>(change.ChangeString);

            newActiveWidget.WidgetId = cd.Id;
            newActiveWidget.Name     = cd.Name;
            newActiveWidget.Type     = cd.Type;
            newActiveWidget.Data     = cd.Data;

            /*creem si o entitate in bd*/
            Widget newWidget = new Widget();

            newActiveWidget.WidgetEntity = newWidget;
            newWidget.WidgetId           = cd.Id;
            newWidget.Order   = cd.Order;
            newWidget.LayerId = cd.LayerId;
            newWidget.Name    = cd.Name;
            newWidget.Data    = cd.Data;

            /*inseram in listele de widgeturi din layer*/
            try {
                lock (b.Layers[cd.LayerId].Widgets) {
                    b.Layers[cd.LayerId].Widgets.Add(cd.Id, newActiveWidget);
                }
                lock (b.Layers[cd.LayerId].WidgetsStack) {
                    b.Layers[cd.LayerId].WidgetsStack.Insert(cd.Order, newActiveWidget);
                }
            } catch (KeyNotFoundException ex) {
                Console.WriteLine(ex.ToString());
            }

            this._em.AddToWidgets(newWidget);
        }
Esempio n. 3
0
        //------------------------------------------------------------------------------------------
        //------------------------------------------------------------------------------------------
        public void PushChange(int boardId, Change change, IPrincipal user)
        {
            /*punem la ceialti utilizatori modificarea produsa*/
            if (!this._activeBoards.ContainsKey(boardId))
            {
                throw new Exception("Board id not found in ActiveBoards");
            }

            ActiveBoard board = null;

            try {
                board = this.GetBoard(boardId);
            } catch (KeyNotFoundException ex) {
                return;
            }
            if (!board.UsersTable.ContainsKey(user.Identity.Name))
            {
                throw new Exception("Username not found in board's userlist");
            }

            switch (change.Operation)
            {
            case "add":
                if (change.Obj == "layer")
                {
                    this._AddLayer(board, change);
                }
                else if (change.Obj == "widget")
                {
                    this._AddWidget(board, change);
                }
                else if (change.Obj == "user")
                {
                    this._AddUser(board, change);
                }
                break;

            case "remove":     /*il stergem din entities si din dictionar*/
                if (change.Obj == "layer")
                {
                    ActiveLayer layer = board.Layers[change.Id];

                    /*scoatem widgets entities pt acest layer si le stergem din _em*/
                    foreach (ActiveWidget w in layer.WidgetsStack)
                    {
                        this._em.DeleteObject(w.WidgetEntity);
                    }

                    /*stergem si acest layer din board din _em*/
                    this._em.DeleteObject(layer.LayerEntity);

                    /*stergem layerul din activelayers pt acest board*/
                    lock (board.Layers) {
                        board.Layers.Remove(change.Id);
                    }
                    lock (board.LayerStack) {
                        board.LayerStack.Remove(layer);
                    }
                }
                else if (change.Obj == "widget")
                {
                    /*get the layer id*/
                    var jss             = new JavaScriptSerializer();
                    ChangeDataWidget cd = jss.Deserialize <ChangeDataWidget>(change.ChangeString);

                    /*delete from entities*/
                    Widget entity = board.Layers[cd.LayerId].GetWidget(cd.Id).WidgetEntity;
                    this._em.Widgets.DeleteObject(entity);
                    /*delete the widget from the layer of that board*/
                    board.Layers[cd.LayerId].RemoveWidget(cd.Id);
                }
                else if (change.Obj == "user")
                {
                    /*get the layer id*/
                    var            jss = new JavaScriptSerializer();
                    ChangeDataUser cd  = jss.Deserialize <ChangeDataUser>(change.ChangeString);

                    ActiveUser auser = board.UsersTable[cd.Name];
                    /*delete from entities*/
                    this._em.DeleteObject(auser.Entity);
                    /*delete the widget from the layer of that board*/
                    lock (board.Users) {
                        board.Users.Remove(auser);
                    }
                    lock (board.UsersTable) {
                        board.UsersTable.Remove(auser.Username);
                    }
                }

                break;

            case "change":
                if (change.Obj == "layer")
                {
                    this._ChangeLayer(board, change);
                }
                else if (change.Obj == "widget")
                {
                    this._ChangeWidget(board, change);
                }
                /*pentru user nu avem ce modifica*/
                break;
            }
            foreach (KeyValuePair <string, ActiveUser> uPair in board.UsersTable)
            {
                if (uPair.Value.Username != user.Identity.Name)
                {
                    uPair.Value.Changes.Add(change);
                }
            }
        }