Пример #1
0
        /// <summary>
        /// Adds or aggergates to already available data an information present in the given model
        /// </summary>
        /// <param name="mi"></param>
        /// <returns></returns>
        public static int AddModel(ModelInfo mi)
        {
            lock (_lock)
            {
                List<string> temp = null;
                var key = KeyFromModel(mi);

                if (mi.ExpiresOn != default(DateTime))
                    expiresOn[key] = mi.ExpiresOn;

                if (!vertexData.TryGetValue(key, out temp))
                    vertexData[key] = new List<string>();

                if (mi.Vertices == null)
                    return 0;

                vertexData[key].AddRange(mi.Vertices);

                if (!faceColorData.TryGetValue(key, out temp))
                    faceColorData[key] = new List<string>();

                if (!string.IsNullOrEmpty(mi.ModelImage))
                    modelImages[key] = mi.ModelImage;

                if (mi.Notes != null)
                    notes[key] = mi.Notes;

                return vertexData[key].Count;
            }
        }
Пример #2
0
 public static void Add(string key, ModelInfo mi)
 {
     lock (_lock)
     {
         internalDic[key] = mi;
     }
 }
Пример #3
0
        /// <summary>
        /// Saves Modelnfo in the base
        /// </summary>
        /// <param name="mi"></param>
        /// <returns></returns>
        public bool Save(ModelInfo mi)
        {
            if (mi == null)
                return false;

            mi.UniqueID = GetUniqueID(mi);
            mi.SaveDate = DateTime.Now;
            return SaveToMongo(mi);
        }
Пример #4
0
        public static string GenerateTempLink(ModelInfo mi, HttpRequestBase  request)
        {
            var tempName = Path.GetFileNameWithoutExtension(Path.GetTempFileName());
            #if DEBUG
            var baseUrl = request.Url.GetLeftPart(UriPartial.Authority);

            #else
            var baseUrl = request.Url.Scheme + "://" + request.Url.Host;
            #endif
            return baseUrl + "/" + mi.Format + "/LoadModel/" + tempName;
        }
Пример #5
0
        public ActionResult DeleteSession(ModelInfo model)
        {
            try
            {
                var collection = model.ID.Split('/').Last();

                IData access = GetDataAccess();
                access.DeleteModelCollection(collection);

                return Json(true);
            }
            catch (Exception ex)
            {
                string link = (model.ID != null) ? model.ID : string.Empty;
                LogEntry.logger.ErrorException("Exception on deleting " + link, ex);
                return Json(false);
            }
        }
Пример #6
0
        public static DateTime GetExpiredDateOfModel(ModelInfo mi)
        {
            var key = KeyFromModel(mi);
            DateTime expires = default(DateTime);
            expiresOn.TryGetValue(key, out expires);

            return expires;
        }
Пример #7
0
        private void UpdateBsonInfo(BsonDocument bson, ModelInfo mi)
        {
            bson["ModelName"] = mi.ModelName;
            bson["Size"] = mi.Size;
            bson["ID"] = mi.ID;
            bson["Format"] = mi.Format;
            bson["VertexCount"] = mi.VertexCount;
            bson["Color"] = mi.Color;
            bson["User"] = mi.User;
            bson["ModelImage"] = Compressor.Compress(mi.ModelImage);
            bson["SessionName"] = mi.SessionName;
            bson["SavedOn"] = mi.SavedOn.ToString(System.Globalization.CultureInfo.InvariantCulture);

            var array = BsonArrayFromEnumerable(mi.Vertices);
            bson["Vertices"] =  array;

            var notes = BsonArrayFromEnumerableNotes(mi.Notes);
            bson["Notes"] =  notes;
        }
Пример #8
0
        /// <summary>
        /// Generates Bson document from provided ModelInfo object
        /// </summary>
        /// <param name="mi"></param>
        /// <returns></returns>
        private BsonDocument BsonFromModelInfo(ModelInfo mi)
        {
            var bson = new BsonDocument();
            bson["ModelName"] = mi.ModelName;
            bson["Size"] = mi.Size;
            bson["ID"] = mi.ID;
            bson["Format"] = mi.Format;
            bson["VertexCount"] = mi.VertexCount;
            bson["Color"] = mi.Color;
            bson["User"] = mi.User;
            bson["ModelImage"] = Compressor.Compress(mi.ModelImage);
            bson["SessionName"] = mi.SessionName;
            bson["SavedOn"] = mi.SavedOn.ToString(System.Globalization.CultureInfo.InvariantCulture);

            var array = BsonArrayFromEnumerable(mi.Vertices);
            bson.Add("Vertices", array);

            var notes = BsonArrayFromEnumerableNotes(mi.Notes);
            bson.Add("Notes", notes);

            return bson;
        }
Пример #9
0
 /// <summary>
 /// Removes face colors from the internal dic
 /// </summary>
 /// <param name="mi"></param>
 public static void RemoveFaceColorsData(ModelInfo mi)
 {
     lock (_lock)
     {
         var key = KeyFromModel(mi);
         faceColorData.Remove(key);
     }
 }
Пример #10
0
 /// <summary>
 /// Removes all internal information associated to a given model
 /// </summary>
 /// <param name="mi"></param>
 public static void Remove(ModelInfo mi)
 {
     var key = KeyFromModel(mi);
     Remove(key);
 }
Пример #11
0
        public static List<string> GetVertices(ModelInfo mi)
        {
            lock (_lock)
            {
                var key = KeyFromModel(mi);
                if (!vertexData.ContainsKey(key))
                    return new List<string>();

                return vertexData[key];
            }
        }
Пример #12
0
        public static List<Note> GetNotes(ModelInfo mi)
        {
            lock (_lock)
            {
                var key = KeyFromModel(mi);
                if (!notes.ContainsKey(key))
                    return new List<Note>();

                return notes[key];
            }
        }
Пример #13
0
        public static string GetImageData(ModelInfo mi)
        {
            lock (_lock)
            {
                var key = KeyFromModel(mi);
                if (!modelImages.ContainsKey(key))
                    return string.Empty;

                return modelImages[key];
            }
        }
Пример #14
0
        public static List<string> GetFaceColors(ModelInfo mi)
        {
            lock (_lock)
            {
                var key = KeyFromModel(mi);
                if (!faceColorData.ContainsKey(key))
                    return new List<string>();

                return faceColorData[key];
            }
        }
Пример #15
0
 /// <summary>
 /// Removes image data from the internal dic
 /// </summary>
 /// <param name="mi"></param>
 public static void RemoveImageData(ModelInfo mi)
 {
     lock (_lock)
     {
         var key = KeyFromModel(mi);
         modelImages.Remove(key);
     }
 }
Пример #16
0
        /// <summary>
        /// Saves model in Mongo DB
        /// </summary>
        /// <param name="mi"></param>
        /// <returns></returns>
        public bool SaveModel(ModelInfo mi)
        {
            try
            {
                var unique = mi.ID.Split('/').Last();   //get last string (uniqeud ID) in the path
                var collection = ReadCollection(unique); //get collection
                var savedDocument = ReadDocument(unique, mi.ModelName);
                mi.SavedOn = DateTime.Now;

                if (savedDocument != null)
                {
                    UpdateBsonInfo(savedDocument, mi);

                    /*var bsonArraySaved = savedDocument["Vertices"].AsString;
                    var bsonArrayNew = BsonArrayFromEnumerable(mi.Vertices);
                    bsonArraySaved +=bsonArrayNew;*/
                    collection.Save(savedDocument); //update document
                }
                else
                {
                    // a NEW document
                         //generate BSON document
                    savedDocument = BsonFromModelInfo(mi);
                    collection.Insert(savedDocument);   //insert
                }

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
Пример #17
0
 /// <summary>
 /// Removes notes from the internal dic
 /// </summary>
 /// <param name="mi"></param>
 public static void RemoveNotes(ModelInfo mi)
 {
     lock (_lock)
     {
         var key = KeyFromModel(mi);
         notes.Remove(key);
     }
 }
Пример #18
0
        /// <summary>
        /// Generates ModelInfo from provided Bson document object
        /// </summary>
        /// <param name="bson"></param>
        /// <param name="verticesToo"></param>
        /// <returns></returns>
        private ModelInfo ModelInfoFromBson(BsonDocument bson, bool verticesToo = true)
        {
            ModelInfo mi = new ModelInfo();
            mi.ModelName = bson["ModelName"].AsString;
            mi.Size = bson["Size"].AsInt32;
            mi.ID = bson["ID"].AsString;
            mi.Format = bson["Format"].AsString;
            mi.VertexCount = bson["VertexCount"].AsInt32;
            mi.Color = bson["Color"].AsInt32;
            mi.User = bson["User"].AsString;
            mi.ModelImage = Compressor.Decompress(bson["ModelImage"].AsString);
            mi.SessionName = bson["SessionName"].ToString();

            DateTime dt = default(DateTime);
            if (DateTime.TryParse(bson["SavedOn"].ToString(),System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
                mi.SavedOn = dt;

            if (verticesToo)
            {
                var deCompressed = Compressor.Decompress(bson["Vertices"].AsString).Split(new char[]{SEPARATOR}, StringSplitOptions.RemoveEmptyEntries);
                var vertices = new List<string>();
                for (int i = 0; i < deCompressed.Length; i ++)
                    vertices.Add(deCompressed[i]);

                mi.Vertices = vertices;

                var notesString = bson["Notes"].AsString.Split(new char[] { SEPARATOR_NOTES }, StringSplitOptions.RemoveEmptyEntries);
                var notes = new List<Note>();
                for (int i = 0; i < notesString.Length; i++)
                {
                    try
                    {
                        notes.Add(JsonHelper.JsonDeserialize<Note>(notesString[i]));
                    }
                    catch (Exception ex)
                    {
                        LogEntry.logger.FatalException("Decompressing note " + i, ex);
                    }
                }
                mi.Notes = notes;
            }

            return mi;
        }
Пример #19
0
 /// <summary>
 /// Removes vertices from the internal dic
 /// </summary>
 /// <param name="mi"></param>
 public static void RemoveVerticesData(ModelInfo mi)
 {
     lock (_lock)
     {
         var key = KeyFromModel(mi);
         vertexData.Remove(key);
     }
 }
Пример #20
0
 public object GetUniqueID(ModelInfo mi)
 {
     string randomUrl = GetBaseUrl() + "//" + mi.Format + "//" + Path.GetFileNameWithoutExtension(Path.GetTempFileName());
     return GetShortedUrl(randomUrl);
 }
Пример #21
0
 private static string KeyFromModel(ModelInfo mi)
 {
     return mi.SessionName + "_" + mi.ID + "_" + mi.ModelName;
 }
Пример #22
0
        private bool SaveToMongo(ModelInfo mi)
        {
            MongoServerSettings settings = new MongoServerSettings();
            settings.Server = new MongoServerAddress("localhost", 27017);
            // Create server object to communicate with our server
            MongoServer server = new MongoServer(settings);
            // Get our database instance to reach collections and data
            var database = server.GetDatabase("MessageDB");
               // database.

            return true;
        }
Пример #23
0
        public ActionResult SaveModel(ModelInfo model)
        {
            model.User = User.Identity.Name;

            //generate unique link for the model
            if (string.IsNullOrEmpty(model.ID))
            {
                model.ID = LinkGenerator.GenerateTempLink(model, HttpContext.Request);
                model.ExpiresOn = GetExpiredDate();
            }

            var savedCount = SendCache.AddModel(model);
            if (savedCount == model.VertexCount)
            {
                IData access = GetDataAccess();

                model.Vertices = SendCache.GetVertices(model);
                model.ModelImage = SendCache.GetImageData(model);
                model.Notes = SendCache.GetNotes(model);

                bool saveResult = access.SaveModel(model);

                SendCache.Remove(model);

                if (!saveResult)
                    return Json(false);
            }

            return Json(model.ID);
        }