예제 #1
0
        public string GetTemplateId(byte[] postData)
        {
            IndexedDB.Serializer.Simple.SimpleConverter <TemplateUpdateModel> converter = new IndexedDB.Serializer.Simple.SimpleConverter <TemplateUpdateModel>();
            var model = converter.FromBytes(postData);

            return(model != null?model.Id.ToString() : "");
        }
예제 #2
0
        // receive the site object...
        public bool Receive(Guid SiteId, ApiCall call)
        {
            var        converter = new IndexedDB.Serializer.Simple.SimpleConverter <SyncObject>();
            SyncObject sync      = converter.FromBytes(call.Context.Request.PostData);

            //must do the user validation here...
            var website = Kooboo.Data.GlobalDb.WebSites.Get(SiteId);

            if (website == null)
            {
                website = InitWebSite(call.Context.Request.IP, SiteId, sync.SenderPort);
            }

            var sitedb = website.SiteDb();

            var manager = sitedb.ClusterManager;

            if (manager != null)
            {
                var node = sitedb.SiteCluster.GetByIp(call.Context.Request.IP);
                if (node == null)
                {
                    return(false);
                }
                manager.Receive(sync, node);
            }
            return(true);
        }
예제 #3
0
        public T Clone <T>() where T : SiteObject
        {
            IndexedDB.Serializer.Simple.SimpleConverter <T> converter = new IndexedDB.Serializer.Simple.SimpleConverter <T>();
            var bytes = converter.ToBytes((T)this);

            return(converter.FromBytes(bytes));
        }
예제 #4
0
        public void Push(ApiCall call)
        {
            //must do the user validation here...
            Guid SiteId = call.GetGuidValue("SiteId");

            Guid Hash = call.GetGuidValue("hash");

            if (Hash != default(Guid))
            {
                var hashback = Kooboo.Lib.Security.Hash.ComputeGuid(call.Context.Request.PostData);

                if (hashback != Hash)
                {
                    throw new Exception(Data.Language.Hardcoded.GetValue("Hash validation failed", call.Context));
                }
            }

            if (SiteId != default(Guid))
            {
                var website = Kooboo.Data.GlobalDb.WebSites.Get(SiteId);
                var sitedb  = website.SiteDb();

                var converter = new IndexedDB.Serializer.Simple.SimpleConverter <SyncObject>();

                SyncObject sync = converter.FromBytes(call.Context.Request.PostData);

                SyncService.Receive(sitedb, sync);
            }
            else
            {
                throw new Exception(Data.Language.Hardcoded.GetValue("Website not found"));
            }
        }
예제 #5
0
        //item push by remote client...
        public void Push(Guid SiteId, ApiCall call)
        {
            Guid Hash = call.GetValue <Guid>("hash");

            Guid userid = default(Guid);

            if (call.Context.User != null)
            {
                userid = call.Context.User.Id;
            }

            if (Hash != default(Guid))
            {
                var hashback = Kooboo.Lib.Security.Hash.ComputeGuid(call.Context.Request.PostData);

                if (hashback != Hash)
                {
                    throw new Exception(Data.Language.Hardcoded.GetValue("Hash validation failed", call.Context));
                }
            }

            var website = Kooboo.Data.GlobalDb.WebSites.Get(SiteId);
            var sitedb  = website.SiteDb();

            var converter = new IndexedDB.Serializer.Simple.SimpleConverter <SyncObject>();

            SyncObject sync = converter.FromBytes(call.Context.Request.PostData);

            SyncService.Receive(sitedb, sync, null, userid);
        }
예제 #6
0
        public static T Deserialize <T>(byte[] bytes)
        {
            var type  = typeof(T);
            var ser   = new IndexedDB.Serializer.Simple.SimpleConverter(type);
            var value = ser.FromBytes(bytes);

            if (value != null)
            {
                return((T)value);
            }
            return(default(T));
        }
예제 #7
0
        public Dictionary <string, object> UpdateTemplate(string domain, byte[] postData, DynamicTableObject obj)
        {
            var oldTemplate = obj.Values;

            IndexedDB.Serializer.Simple.SimpleConverter <TemplateUpdateModel> converter = new IndexedDB.Serializer.Simple.SimpleConverter <TemplateUpdateModel>();
            var model = converter.FromBytes(postData);
            var hash  = Lib.Security.Hash.ComputeGuid(model.Bytes);

            var userId = oldTemplate["userId"];

            if (hash != model.ByteHash ||
                model.UserId.ToString() != userId.ToString())
            {
                return(null);
            }

            oldTemplate["link"]                  = model.Link;
            oldTemplate["description"]           = model.Description;
            oldTemplate["tags"]                  = model.Tags;
            oldTemplate["lastModified"]          = DateTime.UtcNow;
            oldTemplate["lastModifiedTimeStamp"] = DateTime.UtcNow.Ticks;

            var existImages = new List <string>();

            if (oldTemplate["images"] != null && !string.IsNullOrEmpty(oldTemplate["images"].ToString()))
            {
                var oldlist = Kooboo.Lib.Helper.JsonHelper.Deserialize <List <string> >(oldTemplate["images"].ToString());
                var newlist = JsonHelper.Deserialize <List <string> >(model.Images);
                existImages = clearImagePath(oldlist, newlist);
            }

            var images = new List <ScreenshotImage>();

            if (model.Bytes != null && model.Bytes.Length > 0)
            {
                Guid oldsiteid = model.Id;
                // there is a change of zip.
                File.WriteAllBytes(GetFilePath(model.Id.ToString()), model.Bytes);
                oldTemplate["size"] = model.Bytes.Length;
                // update to preview sites.
                var siteDb = ImportBinary(domain, model.Bytes, oldTemplate);

                if (model.NewImages.Count == 0 && existImages.Count() == 0)
                {
                    images = GetScreenshotImages(siteDb);
                }
                // remove the old site.
                Sites.Service.WebSiteService.Delete(oldsiteid);
            }
            foreach (var image in model.NewImages)
            {
                images.Add(new ScreenshotImage
                {
                    Base64   = image.Base64,
                    FileName = Guid.NewGuid().ToString().Replace("-", "") + Kooboo.Lib.Helper.UrlHelper.FileExtension(image.FileName)
                });
            }

            var imagelist = new List <string>();

            foreach (var image in images)
            {
                string relativeurl = image.FileName;
                var    filepath    = GetImagePath(relativeurl);

                File.WriteAllBytes(filepath, image.Bytes);
                imagelist.Add(relativeurl);
            }
            existImages.AddRange(imagelist);
            oldTemplate["images"]    = existImages.ToArray();
            oldTemplate["thumbNail"] = existImages.Count > 0 ? existImages[0] : "";

            return(oldTemplate);
        }
예제 #8
0
        public Dictionary <string, object> UploadOldFormat(string domain, byte[] postData)
        {
            IndexedDB.Serializer.Simple.SimpleConverter <TemplateDataModel> converter = new IndexedDB.Serializer.Simple.SimpleConverter <TemplateDataModel>();
            var model = converter.FromBytes(postData);
            var hash  = Lib.Security.Hash.ComputeGuid(model.Bytes);

            if (hash != model.ByteHash ||
                model.UserId == default(Guid) || model.Bytes.Length == 0)
            {
                return(null);
            }

            var dic = new Dictionary <string, object>();

            dic["name"]        = model.Name;
            dic["link"]        = model.Link;
            dic["description"] = model.Description;
            dic["tags"]        = model.Tags;
            dic["userId"]      = model.UserId;
            var user = Data.GlobalDb.Users.Get(model.UserId);

            if (user != null)
            {
                dic["userName"] = user.FullName;
            }

            dic["lastModified"]          = DateTime.UtcNow;
            dic["lastModifiedTimeStamp"] = DateTime.UtcNow.Ticks;
            dic["downloadCount"]         = 0;
            dic["score"] = 0;
            dic["id"]    = Guid.NewGuid().ToString();

            var filePath = GetFilePath(dic["id"].ToString());

            File.WriteAllBytes(filePath, model.Bytes);
            dic["size"] = model.Bytes.Length;

            var siteDb = ImportBinary(domain, model.Bytes, dic);

            Lib.Helper.IOHelper.EnsureDirectoryExists(ImagePath);

            var images = new List <ScreenshotImage>();

            if (model.Images.Count() == 0)
            {
                images = GetScreenshotImages(siteDb);
            }
            else
            {
                foreach (var image in model.Images)
                {
                    images.Add(new ScreenshotImage
                    {
                        Base64   = image.Base64,
                        FileName = Guid.NewGuid().ToString().Replace("-", "") + Kooboo.Lib.Helper.UrlHelper.FileExtension(image.FileName)
                    });
                }
            }

            var imagelist = new List <string>();

            foreach (var image in images)
            {
                string relativeurl = image.FileName;
                var    filepath    = GetImagePath(relativeurl);

                File.WriteAllBytes(filepath, image.Bytes);
                imagelist.Add(relativeurl);
            }
            dic["images"]    = imagelist.ToArray();
            dic["thumbNail"] = imagelist.Count > 0 ? imagelist[0] : "";

            return(dic);
        }
예제 #9
0
        public static object Deserialize(byte[] bytes, Type ObjectType)
        {
            var ser = new IndexedDB.Serializer.Simple.SimpleConverter(ObjectType);

            return(ser.FromBytes(bytes));
        }