public static byte[] Serialize(object Model) { var type = Model.GetType(); var ser = new IndexedDB.Serializer.Simple.SimpleConverter(type); return(ser.ToBytes(Model)); }
public static byte[] Serialize <T>(T Model) { var type = typeof(T); var ser = new IndexedDB.Serializer.Simple.SimpleConverter(type); return(ser.ToBytes(Model)); }
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)); }
public virtual void ShareBatch(ApiCall call) { SiteDb siteDb = call.WebSite != null?call.WebSite.SiteDb() : null; var formreader = Kooboo.Lib.NETMultiplePart.FormReader.ReadForm(call.Context.Request.PostData); if (siteDb == null) { Guid siteId; if (!Guid.TryParse(formreader.FormData["SiteId"], out siteId)) { return; } var website = Kooboo.Data.GlobalDb.WebSites.Get(siteId); siteDb = website.SiteDb(); } if (siteDb == null) { return; } var tempFolder = Kooboo.Data.AppSettings.TempDataPath; var exportfile = ImportExport.ExportInter(siteDb); if (!File.Exists(exportfile)) { return; } var postdata = InitData(formreader, call); var zipbytes = IOHelper.ReadAllBytes(exportfile); postdata.Bytes = zipbytes; if (zipbytes.Length > AppSettings.MaxTemplateSize) { throw new Exception(Data.Language.Hardcoded.GetValue("Exceed max template size", call.Context)); } postdata.ByteHash = Kooboo.Lib.Security.Hash.ComputeGuid(zipbytes); Kooboo.IndexedDB.Serializer.Simple.SimpleConverter <TemplateDataModel> converter = new IndexedDB.Serializer.Simple.SimpleConverter <TemplateDataModel>(); var postbytes = converter.ToBytes(postdata); string url = UrlHelper.Combine(AppSettings.ThemeUrl, "/_api/receiver/template"); var response = HttpHelper.PostData(url, new Dictionary <string, string>(), postbytes); if (!response) { throw new Exception(Data.Language.Hardcoded.GetValue("Share template failed", call.Context)); } }
public bool Execute(SiteDb SiteDb, string JsonModel) { var item = Lib.Helper.JsonHelper.Deserialize <PostSyncObject>(JsonModel); //var stringcontent = Newtonsoft.Json.JsonConvert.SerializeObject(item.SyncObject); var converter = new IndexedDB.Serializer.Simple.SimpleConverter <SyncObject>(); var bytes = converter.ToBytes(item.SyncObject); Guid websiteid = item.RemoteSiteId; var hash = Lib.Security.Hash.ComputeGuid(bytes); string fullurl = item.RemoteUrl + "?" + DataConstants.SiteId + "=" + item.RemoteSiteId.ToString() + "&hash=" + hash.ToString(); return(Kooboo.Lib.Helper.HttpHelper.PostData(fullurl, null, bytes, item.UserName, item.Password)); }
public void Update(ApiCall call) { var formResult = Kooboo.Lib.NETMultiplePart.FormReader.ReadForm(call.Context.Request.PostData); TemplateUpdateModel update = new TemplateUpdateModel(); update.UserId = call.Context.User.Id; if (formResult.FormData.ContainsKey("id")) { string strid = formResult.FormData["id"]; Guid id; if (System.Guid.TryParse(strid, out id)) { update.Id = id; } else { throw new Exception(Data.Language.Hardcoded.GetValue("Invalid package id", call.Context)); } } else { throw new Exception(Data.Language.Hardcoded.GetValue("Missing package id", call.Context)); } if (formResult.FormData.ContainsKey("category")) { update.Category = formResult.FormData["category"]; } if (formResult.FormData.ContainsKey("link")) { update.Link = formResult.FormData["link"]; } if (formResult.FormData.ContainsKey("description")) { update.Description = formResult.FormData["description"]; } if (formResult.FormData.ContainsKey("tags")) { update.Tags = formResult.FormData["tags"]; } if (formResult.FormData.ContainsKey("Images")) { update.Images = formResult.FormData["Images"]; } if (formResult.FormData.ContainsKey("IsPrivate")) { string strisprivae = formResult.FormData["IsPrivate"]; bool isprivate = false; bool.TryParse(strisprivae, out isprivate); if (isprivate) { update.OrganizationId = call.Context.User.CurrentOrgId; } else { update.OrganizationId = default(Guid); } } foreach (var item in formResult.Files) { string contenttype = item.ContentType; if (contenttype == null) { contenttype = "image"; } else { contenttype = contenttype.ToLower(); } if (contenttype.Contains("image")) { TemplateUserImages image = new TemplateUserImages(); image.FileName = item.FileName; image.Base64 = Convert.ToBase64String(item.Bytes); update.NewImages.Add(image); } else if (contenttype.Contains("zip")) { update.Bytes = item.Bytes; } } if (formResult.FormData.ContainsKey("defaultimg")) { string defaultimage = formResult.FormData["defaultimg"]; update.NewDefault = defaultimage; } if (formResult.FormData.ContainsKey("thumbnail")) { string defaultimage = formResult.FormData["thumbnail"]; update.NewDefault = defaultimage; } if (update.NewImages.Count() > 0) { if (formResult.FormData.ContainsKey("defaultfile")) { string defaultimg = formResult.FormData["defaultfile"]; int index = 0; if (int.TryParse(defaultimg, out index)) { if (update.NewImages.Count() > index) { update.NewImages[index].IsDefault = true; } } } } IndexedDB.Serializer.Simple.SimpleConverter <TemplateUpdateModel> converter = new IndexedDB.Serializer.Simple.SimpleConverter <TemplateUpdateModel>(); var allbytes = converter.ToBytes(update); string Url = Kooboo.Lib.Helper.UrlHelper.Combine(Kooboo.Data.AppSettings.ThemeUrl, "/_api/receiver/updatetemplate"); var response = HttpHelper.PostData(Url, null, allbytes); if (!response) { throw new Exception(Data.Language.Hardcoded.GetValue("Update template failed", call.Context)); } }