Beispiel #1
0
 private static void OnGetObject(ObjectBox model)
 {
     if (DateTime.Now.Subtract(model.LastGetTime).TotalSeconds > 3)
     {
         ((SampleModel)model.Value).Value += " +3sec";
     }
 }
Beispiel #2
0
    static Map()
    {
        map = new Tile[5, 5, 4];
        for (int x = 0; x < 5; x++)
        {
            for (int y = 0; y < 5; y++)
            {
                map[x, y, 0] = new Tile(new SimpleCords(x, y, 0))
                {
                    Passable = true, Empty = false
                };
            }
        }

        map[0, 2, 0] = new Tile(new SimpleCords(0, 2, 0))
        {
            Passable = true
        };
        map[0, 2, 1] = new Tile(new SimpleCords(0, 2, 1))
        {
            Passable = true
        };
        map[0, 2, 2] = new Tile(new SimpleCords(0, 2, 2))
        {
            Passable = true
        };
        map[0, 2, 3] = new Tile(new SimpleCords(0, 2, 3))
        {
            Passable = true
        };

        map[1, 1, 1] = new Tile(new SimpleCords(1, 1, 1))
        {
            Passable = true
        };

        map[1, 2, 0] = new Tile(new SimpleCords(1, 2, 0))
        {
            Passable = true
        };
        map[1, 2, 1] = new Tile(new SimpleCords(1, 2, 1))
        {
            Passable = true
        };
        map[1, 2, 1].TileObjects.PlaceObject(ObjectBox.GetObjectByName("CoverPartial"));

        map[1, 3, 0].TileObjects.PlaceObject(ObjectBox.GetObjectByName("WallHigh"), Positioning.West);
        map[1, 4, 0].TileObjects.PlaceObject(ObjectBox.GetObjectByName("WallHigh"), Positioning.West);

        map[4, 4, 0].TileObjects.PlaceObject(ObjectBox.GetObjectByName("WallLow"), Positioning.South);

        map[3, 1, 0].TileObjects.PlaceObject(ObjectBox.GetObjectByName("CoverPartial"));
    }
Beispiel #3
0
        bool GetValue(out object value, out bool isStandard)
        {
            isStandard = false;

            //combo box, just find the active value
            if (store != null && entry == null)
            {
                TreeIter it;
                if (combo.GetActiveIter(out it))
                {
                    value      = ObjectBox.Unbox(store.GetValue(it, 1));
                    isStandard = true;
                    return(true);
                }
                value = null;
                return(false);
            }

            var text = entry.Text;

            // combo plus entry, try to find matching value
            if (store != null)
            {
                TreeIter it;
                if (store.GetIterFirst(out it))
                {
                    do
                    {
                        if ((string)store.GetValue(it, 0) == text)
                        {
                            value      = ObjectBox.Unbox(store.GetValue(it, 1));
                            isStandard = true;
                            return(true);
                        }
                    } while (store.IterNext(ref it));
                }
            }

            //finally, convert the value
            try {
                value = session.Property.Converter.ConvertFromString(session, entry.Text);
                return(true);
            } catch {
                // Invalid format
                value = null;
                return(false);
            }
        }
Beispiel #4
0
        public Level(string name)
        {
            foreach (AbstractEntity entity in entities)
            {
                Console.WriteLine("Loaded entity: " + entity.GetName());
            }

            ObjectBox box = new ObjectBox(128, 128);

            levelObjects.Add(box);

            foreach (LevelObject levelObject in levelObjects)
            {
                Console.WriteLine("Loaded level object: {0} ({1})", levelObject.objectName, levelObject.type.ToString());
            }

            this.name = name;
        }
Beispiel #5
0
        bool FindComboValue(object val, out int index)
        {
            index = 0;
            TreeIter it;

            if (!store.GetIterFirst(out it))
            {
                return(false);
            }
            do
            {
                if (object.Equals(ObjectBox.Unbox(store.GetValue(it, 1)), val))
                {
                    return(true);
                }
                index++;
            } while (store.IterNext(ref it));
            return(false);
        }
Beispiel #6
0
    public Room(String roomFile)
    {
        TextAsset dataAsset = (TextAsset)Resources.Load(roomFile, typeof(TextAsset));

        if (!dataAsset)
        {
            Debug.Log("missing room txt file.");
        }

        Dictionary <string, object> hash = dataAsset.text.dictionaryFromJson();

        // Room Metadata
        _roomWidth  = int.Parse(hash["width"].ToString());
        _roomHeight = int.Parse(hash["height"].ToString());
        _tileSize   = int.Parse(hash["tilewidth"].ToString());

        //Debug.Log(_roomWidth +"||"+ _roomHeight +"||"+ _tileSize);

        //List<object> tilesetsList = (List<object>)hash["tilesets"];
        //Dictionary<string,object> tileset = (Dictionary<string,object>)tilesetsList[0];

        //string elementPath = tileset["image"].ToString();
        //string [] pathSplit = elementPath.Split(new Char [] {'/'});
        //string _tilesetElementName = pathSplit[pathSplit.Length-1];

        string[] pathSplit = roomFile.Split(new Char[] { '/' });
        roomName = pathSplit[pathSplit.Length - 1];

        List <object> layersList = (List <object>)hash["layers"];

        for (int i = 0; i < layersList.Count; i++)
        {
            Dictionary <string, object> layerHash = (Dictionary <string, object>)layersList[i];
            //int layerWidth = int.Parse (layerHash["width"].ToString());
            //int layerHeight = int.Parse (layerHash["height"].ToString());
            //int xOffset = int.Parse (layerHash["x"].ToString());
            //int yOffset = int.Parse (layerHash["y"].ToString());

            if (layerHash["name"].ToString().Equals("Objects"))
            {
                // Load object data if it exists...
                List <object> objectList = (List <object>)layerHash["objects"];

                for (int j = 0; j < objectList.Count; j++)
                {
                    Dictionary <string, object> objHash = (Dictionary <string, object>)objectList[j];

                    if (objHash["type"].ToString().ToUpper().Equals("COLLISION"))
                    {
                        CollisionBox _cbox = new CollisionBox();
                        _cbox.name       = objHash["name"].ToString();
                        _cbox.box.x      = int.Parse(objHash["x"].ToString()) - (GetRoomWidth() / 2);
                        _cbox.box.y      = -(int.Parse(objHash["y"].ToString()) - (GetRoomHeight() / 2));
                        _cbox.box.width  = int.Parse(objHash["width"].ToString());
                        _cbox.box.height = int.Parse(objHash["height"].ToString());
                        _cbox.box.y      = _cbox.box.y - _cbox.box.height;
                        _cbox.active     = true;
                        collisionBoxList.Add(_cbox);
                    }

                    if (objHash["type"].ToString().ToUpper().Equals("PASSAGE"))
                    {
                        CollisionBox _cbox = new CollisionBox();
                        _cbox.name       = objHash["name"].ToString();
                        _cbox.box.x      = int.Parse(objHash["x"].ToString()) - (GetRoomWidth() / 2);
                        _cbox.box.y      = -(int.Parse(objHash["y"].ToString()) - (GetRoomHeight() / 2));
                        _cbox.box.width  = (int.Parse(objHash["width"].ToString()) == 0) ? 1 : int.Parse(objHash["width"].ToString());
                        _cbox.box.height = (int.Parse(objHash["height"].ToString()) == 0) ? 1 : int.Parse(objHash["height"].ToString());
                        _cbox.box.y      = _cbox.box.y - _cbox.box.height;
                        _cbox.active     = true;
                        passageBoxList.Add(_cbox);
                    }

                    if (objHash["type"].ToString().ToUpper().Equals("PASSAGE_OBJECT"))
                    {
                        CollisionBox _cbox = new CollisionBox();
                        _cbox.name       = objHash["name"].ToString();
                        _cbox.box.x      = int.Parse(objHash["x"].ToString()) - (GetRoomWidth() / 2);
                        _cbox.box.y      = -(int.Parse(objHash["y"].ToString()) - (GetRoomHeight() / 2));
                        _cbox.box.width  = int.Parse(objHash["width"].ToString());
                        _cbox.box.height = int.Parse(objHash["height"].ToString());
                        _cbox.box.y      = _cbox.box.y - _cbox.box.height;
                        _cbox.active     = true;
                        passageObjectBoxList.Add(_cbox);
                    }

                    if (objHash["type"].ToString().ToUpper().Equals("ENEMY_SPAWN"))
                    {
                        ObjectBox obox = new ObjectBox();
                        obox.name       = objHash["name"].ToString();
                        obox.box.x      = int.Parse(objHash["x"].ToString()) - (GetRoomWidth() / 2);
                        obox.box.y      = -(int.Parse(objHash["y"].ToString()) - (GetRoomHeight() / 2));
                        obox.box.width  = (int.Parse(objHash["width"].ToString()) == 0) ? 1 : int.Parse(objHash["width"].ToString());
                        obox.box.height = (int.Parse(objHash["height"].ToString()) == 0) ? 1 : int.Parse(objHash["height"].ToString());
                        obox.box.y      = obox.box.y - obox.box.height;
                        enemySpawnBoxList.Add(obox);
                    }

                    if (objHash["type"].ToString().ToUpper().Equals("PLAYER_SPAWN"))
                    {
                        ObjectBox spawn = new ObjectBox();
                        spawn.name       = objHash["name"].ToString();
                        spawn.box.x      = int.Parse(objHash["x"].ToString()) - (GetRoomWidth() / 2);
                        spawn.box.y      = -(int.Parse(objHash["y"].ToString()) - (GetRoomHeight() / 2));
                        spawn.box.width  = (int.Parse(objHash["width"].ToString()) == 0) ? 1 : int.Parse(objHash["width"].ToString());
                        spawn.box.height = (int.Parse(objHash["height"].ToString()) == 0) ? 1 : int.Parse(objHash["height"].ToString());
                        spawn.box.y      = spawn.box.y - spawn.box.height;
                        playerSpawnBox   = spawn;
                    }
                }
            }
        }

        // non json related initiotion
        _floorSprite = new FSprite(roomName + ".png");
        AddChild(_floorSprite);

        // add mobs
        foreach (ObjectBox spawner in enemySpawnBoxList)
        {
            int      mx       = (int)spawner.box.x;
            int      my       = (int)spawner.box.y;
            Skeleton skeleton = new Skeleton(mx, my);
            mobList.Add(skeleton);
            AddChild(skeleton);
        }
    }
Beispiel #7
0
        public void Initialize(EditSession session)
        {
            this.session = session;

            //if standard values are supported by the converter, then
            //we list them in a combo
            if (session.Property.Converter.GetStandardValuesSupported(session))
            {
                store = new ListStore(typeof(string), typeof(object));

                //if converter doesn't allow nonstandard values, or can't convert from strings, don't have an entry
                if (session.Property.Converter.GetStandardValuesExclusive(session) || !session.Property.Converter.CanConvertFrom(session, typeof(string)))
                {
                    combo = new ComboBox(store);
                    var crt = new CellRendererText();
                    combo.PackStart(crt, true);
                    combo.AddAttribute(crt, "text", 0);
                }
                else
                {
                    combo = new ComboBoxEntry(store, 0);
                    entry = ((ComboBoxEntry)combo).Entry;
                    entry.HeightRequest = combo.SizeRequest().Height;
                }

                PackStart(combo, true, true, 0);
                combo.Changed += TextChanged;

                //fill the list
                foreach (object stdValue in session.Property.Converter.GetStandardValues(session))
                {
                    store.AppendValues(session.Property.Converter.ConvertToString(session, stdValue), ObjectBox.Box(stdValue));
                }

                //a value of "--" gets rendered as a --, if typeconverter marked with UsesDashesForSeparator
                object[] atts = session.Property.Converter.GetType()
                                .GetCustomAttributes(typeof(StandardValuesSeparatorAttribute), true);
                if (atts.Length > 0)
                {
                    string separator = ((StandardValuesSeparatorAttribute)atts[0]).Separator;
                    combo.RowSeparatorFunc = (model, iter) => separator == ((string)model.GetValue(iter, 0));
                }
            }
            // no standard values, so just use an entry
            else
            {
                entry            = new Entry();
                entry.IsEditable = !session.Property.IsReadOnly;
                PackStart(entry, true, true, 0);
            }

            //if we have an entry, fix it up a little
            if (entry != null)
            {
                entry.HasFrame       = false;
                entry.Changed       += TextChanged;
                entry.FocusOutEvent += FirePendingChangeEvent;
                if (!entry.IsEditable)
                {
                    entry.ModifyText(StateType.Normal, entry.Style.Text(Gtk.StateType.Insensitive));
                }
            }

            if (entry != null && ShouldShowDialogButton() && entry.IsEditable)
            {
                var button = new Button("...");
                PackStart(button, false, false, 0);
                button.Clicked += ButtonClicked;
            }

            Spacing = 3;
            ShowAll();
        }
Beispiel #8
0
    public Room(String roomFile)
    {
        TextAsset dataAsset = (TextAsset) Resources.Load (roomFile, typeof(TextAsset));

        if(!dataAsset) Debug.Log("missing room txt file.");

        Dictionary<string,object> hash = dataAsset.text.dictionaryFromJson();

        // Room Metadata
        _roomWidth = int.Parse(hash["width"].ToString());
        _roomHeight = int.Parse(hash["height"].ToString());
        _tileSize = int.Parse(hash["tilewidth"].ToString());

        //Debug.Log(_roomWidth +"||"+ _roomHeight +"||"+ _tileSize);

        //List<object> tilesetsList = (List<object>)hash["tilesets"];
        //Dictionary<string,object> tileset = (Dictionary<string,object>)tilesetsList[0];

        //string elementPath = tileset["image"].ToString();
        //string [] pathSplit = elementPath.Split(new Char [] {'/'});
        //string _tilesetElementName = pathSplit[pathSplit.Length-1];

        string[] pathSplit = roomFile.Split(new Char[] {'/'});
        roomName = pathSplit[pathSplit.Length -1];

        List<object> layersList = (List<object>)hash["layers"];

        for (int i=0; i < layersList.Count; i++)
        {
            Dictionary<string,object> layerHash = (Dictionary<string,object>)layersList[i];
            //int layerWidth = int.Parse (layerHash["width"].ToString());
            //int layerHeight = int.Parse (layerHash["height"].ToString());
            //int xOffset = int.Parse (layerHash["x"].ToString());
            //int yOffset = int.Parse (layerHash["y"].ToString());

            if (layerHash["name"].ToString().Equals("Objects"))
            {
                // Load object data if it exists...
                List<object> objectList = (List<object>)layerHash["objects"];

                for (int j=0; j < objectList.Count; j++)
                {
                    Dictionary<string,object> objHash = (Dictionary<string,object>)objectList[j];

                    if (objHash["type"].ToString().ToUpper().Equals("COLLISION"))
                    {
                        CollisionBox _cbox = new CollisionBox();
                        _cbox.name = objHash["name"].ToString();
                        _cbox.box.x = int.Parse(objHash["x"].ToString()) - (GetRoomWidth() / 2);
                        _cbox.box.y = -(int.Parse(objHash["y"].ToString()) - (GetRoomHeight() / 2));
                        _cbox.box.width = int.Parse(objHash["width"].ToString());
                        _cbox.box.height = int.Parse(objHash["height"].ToString());
                        _cbox.box.y = _cbox.box.y - _cbox.box.height;
                        _cbox.active = true;
                        collisionBoxList.Add(_cbox);
                    }

                    if (objHash["type"].ToString().ToUpper().Equals("PASSAGE"))
                    {
                        CollisionBox _cbox = new CollisionBox();
                        _cbox.name = objHash["name"].ToString();
                        _cbox.box.x = int.Parse(objHash["x"].ToString()) - (GetRoomWidth() / 2);
                        _cbox.box.y = -(int.Parse(objHash["y"].ToString()) - (GetRoomHeight() / 2));
                        _cbox.box.width = (int.Parse(objHash["width"].ToString()) == 0) ? 1 : int.Parse(objHash["width"].ToString());
                        _cbox.box.height = (int.Parse(objHash["height"].ToString()) == 0) ? 1 : int.Parse(objHash["height"].ToString());
                        _cbox.box.y = _cbox.box.y - _cbox.box.height;
                        _cbox.active = true;
                        passageBoxList.Add(_cbox);
                    }

                    if (objHash["type"].ToString().ToUpper().Equals("PASSAGE_OBJECT"))
                    {
                        CollisionBox _cbox = new CollisionBox();
                        _cbox.name = objHash["name"].ToString();
                        _cbox.box.x = int.Parse(objHash["x"].ToString()) - (GetRoomWidth() / 2);
                        _cbox.box.y = -(int.Parse(objHash["y"].ToString()) - (GetRoomHeight() / 2));
                        _cbox.box.width = int.Parse(objHash["width"].ToString());
                        _cbox.box.height = int.Parse(objHash["height"].ToString());
                        _cbox.box.y = _cbox.box.y - _cbox.box.height;
                        _cbox.active = true;
                        passageObjectBoxList.Add(_cbox);
                    }

                    if (objHash["type"].ToString().ToUpper().Equals("ENEMY_SPAWN"))
                    {
                        ObjectBox obox = new ObjectBox();
                        obox.name = objHash["name"].ToString();
                        obox.box.x = int.Parse(objHash["x"].ToString()) - (GetRoomWidth() / 2);
                        obox.box.y = -(int.Parse(objHash["y"].ToString()) - (GetRoomHeight() / 2));
                        obox.box.width = (int.Parse(objHash["width"].ToString()) == 0) ? 1 : int.Parse(objHash["width"].ToString());
                        obox.box.height = (int.Parse(objHash["height"].ToString()) == 0) ? 1 : int.Parse(objHash["height"].ToString());
                        obox.box.y = obox.box.y - obox.box.height;
                        enemySpawnBoxList.Add(obox);
                    }

                    if (objHash["type"].ToString().ToUpper().Equals("PLAYER_SPAWN"))
                    {
                        ObjectBox spawn = new ObjectBox();
                        spawn.name = objHash["name"].ToString();
                        spawn.box.x = int.Parse(objHash["x"].ToString()) - (GetRoomWidth() / 2);
                        spawn.box.y = -(int.Parse(objHash["y"].ToString()) - (GetRoomHeight() / 2));
                        spawn.box.width = (int.Parse(objHash["width"].ToString()) == 0) ? 1 : int.Parse(objHash["width"].ToString());
                        spawn.box.height = (int.Parse(objHash["height"].ToString()) == 0) ? 1 : int.Parse(objHash["height"].ToString());
                        spawn.box.y = spawn.box.y - spawn.box.height;
                        playerSpawnBox = spawn;
                    }
                }
            }
        }

        // non json related initiotion
        _floorSprite = new FSprite(roomName + ".png");
        AddChild(_floorSprite);

        // add mobs
        foreach(ObjectBox spawner in enemySpawnBoxList)
        {
            int mx = (int)spawner.box.x;
            int my = (int)spawner.box.y;
            Skeleton skeleton = new Skeleton(mx, my);
            mobList.Add(skeleton);
            AddChild(skeleton);
        }
    }
Beispiel #9
0
        public static IHtmlControl GetRegisterView(SiteState state)
        {
            return(new HPanel(
                       Decor.Title("Регистрация"),
                       Decor.AuthEdit("login", "Логин (*):"),
                       Decor.AuthEdit("yourname", "Ваше имя (*):"),
                       Decor.AuthEdit("email", "E-mail (*):"),
                       Decor.AuthEdit(new HPasswordEdit("password"), "Пароль (*):"),
                       Decor.AuthEdit(new HPasswordEdit("passwordRepeat"), "Введите пароль ещё раз (*):"),
                       new HPanel(
                           Decor.Button("Зарегистрироваться").Event("user_register", "registerData",
                                                                    delegate(JsonData json)
            {
                string login = json.GetText("login");
                string name = json.GetText("yourname");
                string email = json.GetText("email");
                string password = json.GetText("password");
                string passwordRepeat = json.GetText("passwordRepeat");

                WebOperation operation = state.Operation;

                if (!operation.Validate(login, "Не задан логин"))
                {
                    return;
                }
                if (!operation.Validate(email, "Не задана электронная почта"))
                {
                    return;
                }
                if (!operation.Validate(!email.Contains("@"), "Некорректный адрес электронной почты"))
                {
                    return;
                }
                if (!operation.Validate(name, "Не задано имя"))
                {
                    return;
                }
                if (!operation.Validate(password, "Не задан пароль"))
                {
                    return;
                }
                if (!operation.Validate(password != passwordRepeat, "Повтор не совпадает с паролем"))
                {
                    return;
                }

                foreach (LightObject userObj in context.UserStorage.All)
                {
                    if (!operation.Validate(userObj.Get(UserType.Email)?.ToLower() == email?.ToLower(),
                                            "Пользователь с такой электронной почтой уже существует"))
                    {
                        return;
                    }
                }

                ObjectBox box = new ObjectBox(context.UserConnection, "1=0");

                int?createUserId = box.CreateUniqueObject(UserType.User,
                                                          UserType.Login.CreateXmlIds("", login), null);
                if (!operation.Validate(createUserId == null,
                                        "Пользователь с таким логином уже существует"))
                {
                    return;
                }

                LightObject user = new LightObject(box, createUserId.Value);
                FabricHlp.SetCreateTime(user);
                user.Set(UserType.Email, email);
                user.Set(UserType.FirstName, name);
                user.Set(UserType.Password, password);
                user.Set(UserType.NotConfirmed, true);

                box.Update();

                SiteContext.Default.UserStorage.Update();

                Logger.AddMessage("Зарегистрирован пользователь: {0}, {1}, {2}", user.Id, login, email);

                try
                {
                    BasketballHlp.SendRegistrationConfirmation(user.Id, login, email);

                    Logger.AddMessage("Отправлено письмо с подтверждением регистрации.");
                }
                catch (Exception ex)
                {
                    Logger.WriteException(ex);

                    //operation.Validate(true, string.Format("Непредвиденная ошибка при отправке подтверждения: {0}", ex.Message));
                    //return;
                }

                //string xmlLogin = UserType.Login.CreateXmlIds("", login);
                //HttpContext.Current.SetUserAndCookie(xmlLogin);

                //operation.Complete("Вы успешно зарегистрированы!", "");

                state.RedirectUrl = "/confirmation";
            }
                                                                    )
                           )
                       ).EditContainer("registerData"));
        }
Beispiel #10
0
        public static IHtmlControl GetActualArticleBlock(SiteState state, LightObject currentUser)
        {
            IHtmlControl[] items = ViewArticleHlp.GetArticleItems(state, context.ActualArticles);

            HPanel editBlock = null;

            if (state.BlockHint == "articleAdd")
            {
                editBlock = new HPanel(
                    Decor.PropertyEdit("addArticleTitle", "Заголовок статьи"),
                    Decor.Button("Добавить статью").MarginTop(10)
                    .Event("article_add_save", "addArticleData",
                           delegate(JsonData json)
                {
                    string title = json.GetText("addArticleTitle");

                    WebOperation operation = state.Operation;

                    if (!operation.Validate(title, "Не задан заголовок"))
                    {
                        return;
                    }

                    ObjectBox editBox = new ObjectBox(context.FabricConnection, "1=0");

                    int addArticleId = editBox.CreateObject(
                        ArticleType.Article, ArticleType.Title.CreateXmlIds(title), DateTime.UtcNow
                        );
                    LightObject editArticle = new LightObject(editBox, addArticleId);

                    editArticle.Set(ArticleType.PublisherId, currentUser.Id);

                    editBox.Update();
                    context.UpdateArticles();

                    state.BlockHint = "";

                    state.RedirectUrl = UrlHlp.ShopUrl("article", addArticleId);
                }
                           )
                    ).EditContainer("addArticleData")
                            .Padding(5, 10).MarginTop(10).Background(Decor.pageBackground);
            }

            HButton addButton = null;

            if (currentUser != null && !BasketballHlp.NoRedactor(currentUser))
            {
                addButton = Decor.Button("Добавить").Hide(currentUser == null).MarginLeft(10)
                            .Event("article_add", "", delegate
                {
                    state.SetBlockHint("articleAdd");
                }
                                   );
            }

            return(new HPanel(
                       Decor.Subtitle("Статьи").MarginBottom(12),
                       new HPanel(
                           items.ToArray()
                           ),
                       new HPanel(
                           new HLink("/stati",
                                     "Все статьи",
                                     new HBefore().ContentIcon(5, 12).BackgroundImage(UrlHlp.ImageUrl("pointer.gif")).MarginRight(5).VAlign(-2)
                                     ).FontBold(),
                           addButton
                           ).MarginTop(15),
                       editBlock
                       ).MarginTop(10));
        }
Beispiel #11
0
        public BasketballContext(string rootPath,
                                 EditorSelector sectionEditorSelector, EditorSelector unitEditorSelector,
                                 IDataLayer userConnection, IDataLayer fabricConnection,
                                 IDataLayer messageConnection, IDataLayer forumConnection)
        {
            this.rootPath              = rootPath;
            this.imagesPath            = Path.Combine(RootPath, "Images");
            this.userConnection        = userConnection;
            this.fabricConnection      = fabricConnection;
            this.messageConnection     = messageConnection;
            this.forumConnection       = forumConnection;
            this.sectionEditorSelector = sectionEditorSelector;
            this.unitEditorSelector    = unitEditorSelector;

            this.userStorage     = new UserStorage(userConnection);
            this.NewsStorages    = new TopicStorageCache(fabricConnection, messageConnection, NewsType.News);
            this.ArticleStorages = new TopicStorageCache(fabricConnection, messageConnection, ArticleType.Article);
            this.Forum           = new ForumStorageCache(fabricConnection, forumConnection);

            string settingsPath = Path.Combine(rootPath, "SiteSettings.config");

            if (!File.Exists(settingsPath))
            {
                this.siteSettings = new SiteSettings();
            }
            else
            {
                this.siteSettings = XmlSerialization.Load <SiteSettings>(settingsPath);
            }

            this.pull = new TaskPull(
                new ThreadLabel[] { Labels.Service },
                TimeSpan.FromMinutes(15)
                );

            this.newsCache = new Cache <Tuple <ObjectHeadBox, LightHead[]>, long>(
                delegate
            {
                ObjectHeadBox newsBox = new ObjectHeadBox(fabricConnection,
                                                          string.Format("{0} order by act_from desc", DataCondition.ForTypes(NewsType.News))
                                                          );

                int[] allNewsIds = newsBox.AllObjectIds;

                List <LightHead> actualNews = new List <LightHead>();
                for (int i = 0; i < Math.Min(22, allNewsIds.Length); ++i)
                {
                    int newsId = allNewsIds[i];
                    actualNews.Add(new LightHead(newsBox, newsId));
                }

                return(_.Tuple(newsBox, actualNews.ToArray()));
            },
                delegate { return(newsChangeTick); }
                );

            this.articlesCache = new Cache <Tuple <ObjectBox, LightObject[]>, long>(
                delegate
            {
                ObjectBox articleBox = new ObjectBox(fabricConnection,
                                                     string.Format("{0} order by act_from desc", DataCondition.ForTypes(ArticleType.Article))
                                                     );

                int[] allArticleIds = articleBox.AllObjectIds;

                ObjectBox actualBox = new ObjectBox(FabricConnection,
                                                    string.Format("{0} order by act_from desc limit 5", DataCondition.ForTypes(ArticleType.Article))
                                                    );

                List <LightObject> actualArticles = new List <LightObject>();
                foreach (int articleId in actualBox.AllObjectIds)
                {
                    actualArticles.Add(new LightObject(actualBox, articleId));
                }

                return(_.Tuple(articleBox, actualArticles.ToArray()));
            },
                delegate { return(articleChangeTick); }
                );

            this.lightStoreCache = new Cache <IStore, long>(
                delegate
            {
                LightObject contacts = DataBox.LoadOrCreateObject(fabricConnection,
                                                                  ContactsType.Contacts, ContactsType.Kind.CreateXmlIds, "main");

                LightObject seo = DataBox.LoadOrCreateObject(fabricConnection,
                                                             SEOType.SEO, SEOType.Kind.CreateXmlIds, "main");

                SectionStorage sections = SectionStorage.Load(fabricConnection);

                WidgetStorage widgets = WidgetStorage.Load(fabricConnection, siteSettings.DisableScripts);

                RedirectStorage redirects = RedirectStorage.Load(fabricConnection);

                SiteStore store = new SiteStore(sections, null, widgets, redirects, contacts, seo);
                store.Links.AddLink("register", null);
                store.Links.AddLink("passwordreset", null);

                return(store);
            },
                delegate { return(dataChangeTick); }
                );

            this.lastPublicationCommentsCache = new Cache <RowLink[], long>(
                delegate
            {
                DataTable table = messageConnection.GetTable("",
                                                             "Select Distinct article_id From message order by create_time desc limit 10"
                                                             );

                List <RowLink> lastComments = new List <RowLink>(10);
                foreach (DataRow row in table.Rows)
                {
                    int topicId = ConvertHlp.ToInt(row[0]) ?? -1;

                    if (News.ObjectById.Exist(topicId))
                    {
                        TopicStorage topic  = NewsStorages.ForTopic(topicId);
                        RowLink lastMessage = _.Last(topic.MessageLink.AllRows);
                        if (lastMessage != null)
                        {
                            lastComments.Add(lastMessage);
                        }
                    }
                    else if (Articles.ObjectById.Exist(topicId))
                    {
                        TopicStorage topic  = ArticleStorages.ForTopic(topicId);
                        RowLink lastMessage = _.Last(topic.MessageLink.AllRows);
                        if (lastMessage != null)
                        {
                            lastComments.Add(lastMessage);
                        }
                    }
                }

                return(lastComments.ToArray());
            },
                delegate { return(publicationCommentChangeTick); }
                );

            this.lastForumCommentsCache = new Cache <RowLink[], long>(
                delegate
            {
                DataTable table = forumConnection.GetTable("",
                                                           "Select Distinct article_id From message order by create_time desc limit 7"
                                                           );

                List <RowLink> lastComments = new List <RowLink>(7);
                foreach (DataRow row in table.Rows)
                {
                    int topicId = ConvertHlp.ToInt(row[0]) ?? -1;

                    TopicStorage topic  = Forum.TopicsStorages.ForTopic(topicId);
                    RowLink lastMessage = _.Last(topic.MessageLink.AllRows);
                    if (lastMessage != null)
                    {
                        lastComments.Add(lastMessage);
                    }
                }

                return(lastComments.ToArray());
            },
                delegate { return(forumCommentChangeTick); }
                );

            this.tagsCache = new Cache <TagStore, long>(
                delegate
            {
                ObjectHeadBox tagBox = new ObjectHeadBox(fabricConnection, DataCondition.ForTypes(TagType.Tag) + " order by xml_ids asc");

                return(new TagStore(tagBox));
            },
                delegate { return(tagChangeTick); }
                );

            //this.tagsCache = new Cache<Tuple<ObjectHeadBox, Dictionary<string, int>>, long>(
            //  delegate
            //  {
            //    ObjectHeadBox tagBox = new ObjectHeadBox(fabricConnection, DataCondition.ForTypes(TagType.Tag) + " order by xml_ids asc");

            //    Dictionary<string, int> tagIdByKey = new Dictionary<string, int>();
            //    foreach (int tagId in tagBox.AllObjectIds)
            //    {
            //      string tagName = TagType.DisplayName.Get(tagBox, tagId);
            //      if (StringHlp.IsEmpty(tagName))
            //        continue;

            //      string tagKey = tagName.ToLower();
            //      tagIdByKey[tagKey] = tagId;
            //    }

            //    return _.Tuple(tagBox, tagIdByKey);
            //  },
            //  delegate { return tagChangeTick; }
            //);

            this.unreadDialogCache = new Cache <TableLink, long>(
                delegate
            {
                return(DialogueHlp.LoadUnreadLink(forumConnection));
            },
                delegate { return(unreadChangeTick); }
                );

            Pull.StartTask(Labels.Service,
                           SiteTasks.SitemapXmlChecker(this, rootPath,
                                                       delegate(LinkInfo[] sectionlinks)
            {
                List <LightLink> allLinks = new List <LightLink>();
                allLinks.AddRange(
                    ArrayHlp.Convert(sectionlinks, delegate(LinkInfo link)
                {
                    return(new LightLink(link.Directory, null));
                })
                    );

                foreach (int articleId in Articles.AllObjectIds)
                {
                    LightHead article = new LightHead(Articles, articleId);
                    allLinks.Add(
                        new LightLink(UrlHlp.ShopUrl("article", articleId),
                                      article.Get(ObjectType.ActTill) ?? article.Get(ObjectType.ActFrom)
                                      )
                        );
                }

                foreach (int newsId in News.AllObjectIds)
                {
                    LightHead news = new LightHead(News, newsId);
                    allLinks.Add(
                        new LightLink(UrlHlp.ShopUrl("news", newsId),
                                      news.Get(ObjectType.ActTill) ?? news.Get(ObjectType.ActFrom)
                                      )
                        );
                }

                //foreach (int tagId in Tags.AllObjectIds)
                //{
                //  LightHead tag = new LightHead(Tags, tagId);
                //  allLinks.Add(
                //    new LightLink(string.Format("/tags?tag={0}", tagId)
                //    )
                //  );
                //}

                return(allLinks.ToArray());
            }
                                                       )
                           );
        }