Esempio n. 1
0
        public static bool SaveUserCacheData(int user, string cacheName, byte[] data, long cacheTime, string username, int ownerType, int fakeNodeID)
        {
            // First of all convert the cache data into a string
            char[] cData = new char[data.Length];

            for (int i = 0; i < data.Length; i++)
            {
                cData[i] = (char)data[i];
            }

            string cacheData = new string(cData);

            uint version = Crc32.Checksum(data);

            string query = "DELETE FROM usercache WHERE cacheType='" + cacheName + "'";

            Database.Query(query);
            query = "INSERT INTO usercache(cacheType, cacheOwner, cacheOwnerName, cacheOwnerType, cacheData, cacheTime, nodeID, version)VALUES('" + cacheName + "', " + user + ", '" + username + "', " + ownerType + ", '" + cacheData + "', " + cacheTime + ", " + fakeNodeID + ", " + version + ");";

            if (Database.Query(query) == false)
            {
                Log.Error("CacheDB", "Cannot insert cache data for cache " + cacheName);
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        public static bool SaveCacheData(string cacheName, byte[] data, long cacheTime)
        {
            // First of all convert the cache data into a string
            char[] cData = Encoding.ASCII.GetChars(data);

            string cacheData = new string(cData);

            uint version = Crc32.Checksum(data);

            string query = "DELETE FROM cacheinfo WHERE cacheName='" + cacheName + "'";

            Database.Query(query);
            query = "INSERT INTO cacheinfo(cacheName, cacheData, cacheTime, nodeID, version)VALUES('" + cacheName + "', '" + cacheData + "', " + cacheTime + ", " + Program.GetNodeID() + ", " + version + ");";

            if (Database.Query(query) == false)
            {
                Log.Error("CacheDB", "Cannot insert cache data for cache " + cacheName);
                return(false);
            }

            return(true);
        }
Esempio n. 3
0
        private void SubmitTags()
        {
            var tags = _tagsWrapper.Children.OfType <TagField>().Where(p => p.Tag != null).ToArray();

            var newTags     = tags.Where(p => p.Tag != null && p.Tag.Id == 0).Select(p => new { p.Tag.Name, p.Tag.ChineseName });
            var changedTags = (
                from tagElm in tags
                let tag = tagElm.Tag
                          let dbTags = (
                    from dbTag in _materialTagsDb
                    where dbTag.Id == tag.Id &&
                    (
                        dbTag.Name != tag.Name || dbTag.ChineseName != tag.ChineseName
                    )
                    select dbTag
                    )
                                       where tagElm.Tag != null &&
                                       tag.Id > 0 &&
                                       tagElm.Delete == false &&
                                       dbTags.Any()
                                       select tag
                );
            var deletedTags = tags.Where(p => p.Tag != null && p.Delete).Select(p => p.Tag.Id);

            if (newTags.Any() == false && changedTags.Any() == false && deletedTags.Any() == false)
            {
                return;
            }

            var user = Login.GetGlobal();

            var req = JesusWebRequest.Post(TagsUrl, new {
                NewTags     = newTags,
                ChangedTags = changedTags,
                DeletedTags = deletedTags,
                UserName    = user.Username,
                Password    = Crc32.Checksum(user.Password)
            });

            req.SendWait();
            var resp = req.GetResponse <TagsResponse>();

            if (resp.Error)
            {
                Debug.LogError("Error in webserver response");
            }


            var ids = resp.NewIds.GetEnumerator();

            foreach (var tag in tags.Where(p => p.Tag != null && p.Tag.Id == 0))
            {
                ids.MoveNext();
                if (ids.Current != null)
                {
                    tag.Tag.Id = (int)ids.Current;
                }
            }

            _tagsWrapper.Children.RemoveAll(p => ((TagField)p).Delete);
            _materialTagsDb = tags.Select(p => p.Tag).Select(p => new MaterialTag {
                Id = p.Id, Name = p.Name, ChineseName = p.ChineseName
            }).ToList();
        }
Esempio n. 4
0
        private void ModelFieldOnChange(GameObject gameObject)
        {
            // make db model
            var model = new Model {
                Name         = gameObject.name,
                ModelCreator = new ModelCreator {
                    Name = Login.GetGlobal().Username
                }
            };
            var modelFile = model.ModelFile = new ModelFile();

            model.ModelFile = modelFile;

            var meshRenderers = gameObject.GetComponentInChildren <MeshRenderer>();
            var meshFilters   = gameObject.GetComponentInChildren <MeshFilter>();
            var mesh          = meshFilters.sharedMesh;
            var submeshes     = meshFilters.sharedMesh.subMeshCount;

            modelFile.Name         = mesh.name;
            modelFile.BinaryStream = UnityBinaryMesh.GetMeshBinary(mesh);
            modelFile.Checksum     = Crc32.Checksum(modelFile.BinaryStream);

            var materials = meshRenderers.sharedMaterials.Select(p => new MaterialConverter(p).GetDbMaterial()).ToArray();

            var dataSubmeshes = materials.Select((p, i) => new SubMesh {
                Material   = p,
                Channel    = i,
                OwnerModel = model,
            });

            var textures = materials.SelectMany(p => new[] {
                p.MapAlbedo,
                p.MapNormal,
                p.MapOcclusion,
                p.MapSmooth,
                p.MapMetal,
                p.MapHeight,
                p.MapEmissive
            }).Where(p => p != null).ToArray();

            _previewDataStruct.Content = string.Format(
                "Model: {0}\n" +
                "FileSize: {1}kb\n" +
                "SubMeshes: {2}\n" +
                "Materials: {3}\n" +
                "Textures: {4}\n",
                model,
                Math.Round(modelFile.BinaryStream.Length / 1024f),
                dataSubmeshes.Count(),
                materials.Count(),
                string.Join("", textures.Select(p => "\n\t" + p.Name).ToArray())
                );


            Func <Stream, byte[]> getBytes = p => {
                p.Seek(0, SeekOrigin.Begin);
                var binaryReader = new BinaryReader(p);
                return(binaryReader.ReadBytes((int)p.Length));
            };

            Thread.Sleep(500);

            var newForm = new WWWForm();

            for (var i = 0; i < textures.Length; i++)
            {
                newForm.AddBinaryData("texture[" + i + "]", getBytes(textures[i].BinaryStream), textures[i].Name,
                                      "application/octet-stream");
            }
            newForm.AddBinaryData("modelFile", getBytes(modelFile.BinaryStream), "modelFile", "application/octet-stream");

            newForm.AddBinaryData("jsonData", Encoding.UTF8.GetBytes(Json.Serialize(new{
                textures,
                materials,
                Submeshes = dataSubmeshes,
                model,
                materialTags = _tagsWrapper.CheckedTags.Select(p => p.Id)
            })), "jsonData", "application/json");

            _formData = newForm;

            _uploadButton.Hidden = false;
        }