Ejemplo n.º 1
0
        public string LoadForUser(string userName)
        {
            var storage          = new ShapeStorage();
            var shapesCollection = storage.QueryShapesCollection(userName);

            return(shapesCollection);
        }
Ejemplo n.º 2
0
        public double RegisterShape(string id, int typeParam, double width, int idx, string userName)
        {
            var shape = _shapeFactory.CreateShape((ShapeTypeEnum)typeParam, width);

            lock (_shapesCollection)
            {
                _shapesCollection.Add(
                    new ShapeDTO()
                {
                    Id        = id,
                    ShapeType = typeParam.ToString(),
                    Width     = width.ToString(),
                    Idx       = idx
                });

                var shapesCollectionJson = JsonConvert.SerializeObject(_shapesCollection);
                var storage = new ShapeStorage();
                if (!string.IsNullOrEmpty(userName))
                {
                    storage.SaveShapesCollection(shapesCollectionJson, userName);
                }
            }

            return(Math.Round(shape.CalculateArea(), 1));
        }
Ejemplo n.º 3
0
        public void RemoveShape(string id, string userName)
        {
            _shapesCollection.RemoveAll(x => x.Id == id);

            var shapesCollectionJson = JsonConvert.SerializeObject(_shapesCollection);

            var storage = new ShapeStorage();

            if (!string.IsNullOrEmpty(userName))
            {
                storage.SaveShapesCollection(shapesCollectionJson, userName);
            }
        }
Ejemplo n.º 4
0
        public void SaveAndRestore()
        {
            // Configure DataDirectory
            var    solutionDir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName;
            string dataPath    = Path.Combine(solutionDir, "WebShapes\\App_Data");

            AppDomain.CurrentDomain.SetData("DataDirectory", dataPath);

            var shapeStorage = new ShapeStorage();

            var etalonString = "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...";
            var key4Storage  = "user@contoso";

            shapeStorage.SaveShapesCollection(etalonString, key4Storage);
            var valueFromDb = shapeStorage.QueryShapesCollection(key4Storage).Trim();

            Assert.IsTrue(etalonString.Equals(valueFromDb));
        }