public BinaryVersion getBinaryVersion(Asset a) { BinaryVersion b = (from BinaryVersion bin in a.Versions where bin.Assets.EntityID == a.EntityID select bin).FirstOrDefault<BinaryVersion>(); return b; }
static void Main(String[] args) { Console.WriteLine("Windchime Importer"); if (args.Length != 1) { usage(); } if (! Directory.Exists(args[0])) { Console.WriteLine("Error: Invalid directory."); usage(); } DirectoryInfo di = new DirectoryInfo(args[0]); FileInfo[] files = di.GetFiles(args[0] + "\\*"); WindchimeEntities wce = new WindchimeEntities(); foreach (FileInfo f in files) { BinaryVersion b = new BinaryVersion(); b.Path = f.FullName; Asset a = new Asset(); a.Versions.Add(b); wce.AddToPermissionableEntities(a); Console.WriteLine("Added binary asset from file " + f.FullName); } wce.SaveChanges(); }
public Boolean publishAsset(Asset a) { if (a.Published) { return false; } a.Published = true; wce.SaveChanges(); return true; }
public void publishAssetToggle(Asset a) { if (a.Published) { a.Published = false; } else { a.Published = true; } wce.SaveChanges(); }
public TextVersion getTextVersion(Asset a) { TextVersion t = (from TextVersion txt in a.Versions where txt.Assets.EntityID == a.EntityID select txt).FirstOrDefault<TextVersion>(); return t; }
void Save_Click(object sender, EventArgs e) { Asset asst = null; using (WindchimeEntities wce = new WindchimeEntities()) { if (id != null) { asst = (from Asset a in wce.PermissionableEntities.OfType<Asset>() where a.EntityID == id select a).FirstOrDefault(); } if (asst == null) { asst = new Asset(); wce.AddToPermissionableEntities(asst); } asst.Headline = Name_box.Text; TextVersion tv = new TextVersion(); tv.Text = Content_box.Text; tv.CreatedDate = DateTime.Now; asst.Versions.Add(tv); wce.AddToVersionSet(tv); wce.SaveChanges(); wce.Refresh(System.Data.Objects.RefreshMode.StoreWins, asst); id = asst.EntityID; } }
protected void LoadTestDataButton_Click(object sender, EventArgs e) { WindchimeEntities wce = new WindchimeEntities(); Creator c = new Creator(); c.FirstName = "EIC"; c.LastName = "EIC"; User u1 = SecurityManager.CreateUser(c, "EIC", "windchime*", true, true); c.FirstName = "Regular"; c.LastName = "Staff"; User u2 = SecurityManager.CreateUser(c, "Staff1", "windchime*", true, true); c.FirstName = "Regular"; c.LastName = "User"; User u3 = SecurityManager.CreateUser(c, "Regular1", "windchime*", false, true); Group g = new Group(); g.Name = "Staff"; g.IsSpecial = false; wce.Attach(u1); wce.Attach(u2); u1.Groups.Load(); u2.Groups.Load(); g.Children.Add(u1.Groups.First()); g.Children.Add(u2.Groups.First()); wce.AddToGroups(g); Asset a1 = new Asset(), a2 = new Asset(), a3 = new Asset(), a4 = new Asset(); AssetType at1 = new AssetType(); TextVersion tv1 = new TextVersion(), tv2 = new TextVersion(), tv3 = new TextVersion(), tv4 = new TextVersion(), tv5 = new TextVersion(); at1.Name = "Text"; a1.Approved = true; a2.Approved = false; a3.Approved = false; a4.Approved = true; a1.CompletedDate = DateTime.Now; a2.CompletedDate = DateTime.Now; a3.CompletedDate = DateTime.Now; a4.CompletedDate = DateTime.Now; a1.Creator = u1; a2.Creator = u1; a3.Creator = u2; a4.Creator = u2; a1.Headline = "Asset1!"; a2.Headline = "Asset2!"; a3.Headline = "Asset3!"; a4.Headline = "Asset4!"; a1.Summary = "An asset"; a2.Summary = "An asset"; a3.Summary = "An asset"; a4.Summary = "An asset"; a1.AssetType = at1; a2.AssetType = at1; a3.AssetType = at1; a4.AssetType = at1; tv1.Text = "Asset1 v1"; tv1.CreatedDate = DateTime.Now; tv1.Log = ""; tv2.Text = "Asset1 v2"; tv2.CreatedDate = DateTime.Now; tv2.Log = ""; tv3.Text = "Asset2 v1"; tv3.CreatedDate = DateTime.Now; tv3.Log = ""; tv4.Text = "Asset3 v1"; tv4.CreatedDate = DateTime.Now; tv4.Log = ""; tv5.Text = "Asset4 v1"; tv5.CreatedDate = DateTime.Now; tv5.Log = ""; a1.Versions.Add(tv1); a1.Versions.Add(tv2); a2.Versions.Add(tv3); a3.Versions.Add(tv4); a4.Versions.Add(tv5); wce.AddToPermissionableEntities(a1); wce.AddToPermissionableEntities(a2); wce.AddToPermissionableEntities(a3); wce.AddToPermissionableEntities(a4); wce.AddToVersionSet(tv1); wce.AddToVersionSet(tv2); wce.AddToVersionSet(tv3); wce.AddToVersionSet(tv4); wce.AddToVersionSet(tv5); Collection col1 = new Collection(), col2 = new Collection(), col3 = new Collection(), col4 = new Collection(); col1.Name = "Text stuff1"; col1.Assets.Add(a1); col2.Name = "Text stuff2"; col2.Assets.Add(a2); col3.Name = "Text stuff3"; col3.Assets.Add(a3); col4.Name = "Text stuff4"; col4.Assets.Add(a4); col1.Children.Add(col2); col1.Children.Add(col3); col4.Children.Add(col3); wce.SaveChanges(); g = (from Group gr in wce.Groups where gr.IsSpecial && gr.Name.CompareTo("EIC") == 0 select gr).First(); g.PolicyEntries.Load(); foreach (Policy p in Enum.GetValues(typeof(Policy))) { PolicyEntry pe = new PolicyEntry(); pe.Policy = p; pe.GroupID = g.GroupID; g.PolicyEntries.Add(pe); wce.SaveChanges(); } LoadTestDataButton.Enabled = false; }