public static void DemoRun() { // We have defined an interface IRepository // And we implement 2 classes SQL and SharePoint // which does serve the common purpose to Save and Retrieve the recods. // Observe, with this design, we are making the classes // to be extendible but not modifiable. // These classes can be further extended to add more features // but need not have to be modified. // SQL way IRepositoryConnection connection = new SQLRepositoryConnection(); IRepository repository = new SQLRepository(connection); AppData data = repository.Retrieve(1); repository.Save(data); // SharePoint way connection = new SharePointRepositoryConnection(); repository = new SharePointRepository(connection); data = repository.Retrieve(1); repository.Save(data); }
private static void Main() { const string urlSharePointOnpremise = "urlsiteSharePoint"; const string listName = "Employed"; using (var site = new SPSite(urlSharePointOnpremise)) { var web = site.OpenWeb(); var list = web.Lists.TryGetList(listName); if (list == null) { var createList= web.CreateList(listName, "List of Employed of my Company", TypeList.GenericList, false, typeof (Employed)); Console.WriteLine(string.Concat("List Employed Created", createList)); } var employed = new Employed { Country = "Spain", DateBorn = new DateTime(1981, 5, 10), Job = "Sofware Architect", LastName = "Diaz Cervera", Name = "Adrian" }; var employed2 = new Employed { Country = "Spain", DateBorn = new DateTime(1979, 5, 10), Job = "Head of Innovation", LastName = "Diaz Martin", Name = "Alberto" }; var logger = new LogManager().GetLogger(new System.Diagnostics.StackTrace().GetFrame(0)); ; var repository= new SharePointRepository<Employed>(web,logger,listName,10); var resultInsert= repository.Insert(employed); Console.WriteLine(string.Concat("Insertado el elemento: ", resultInsert)); resultInsert = repository.Insert(employed2); Console.WriteLine(string.Concat("Insertado el elemento: ", resultInsert)); var employed3= repository.Get(resultInsert); Console.WriteLine(string.Concat("Return employed: ", employed3.Name)); var employedCollection= repository.GetAll(); Console.WriteLine(string.Concat("Count Employed: ", employedCollection.Count)); var resultBool = repository.Delete(resultInsert); Console.WriteLine(string.Concat("Elemento Eliminado ", resultBool)); employedCollection = repository.GetAll(); Console.WriteLine(string.Concat("Count Employed: ", employedCollection.Count)); var queryCaml = @"<Where> <Eq> <FieldRef Name='Name' /> <Value Type='Text'>Adrian</Value> </Eq> </Where>"; var queryCollection = repository.Query(queryCaml, 1); Console.WriteLine(string.Concat("Count Employed: ", queryCollection.Count)); var query = new Query().Where().Field("Name",string.Empty).Operator(TypeOperators.Eq).Value("Text","Adrian"); queryCollection = repository.Query(query, 1); Console.WriteLine(string.Concat("Count Employed: ", queryCollection.Count)); var firstEmployed = queryCollection.FirstOrDefault(); firstEmployed.Name = "Alberto Javier"; var updateOperation= repository.Save(Convert.ToInt32(firstEmployed.ID), firstEmployed); Console.WriteLine(string.Concat("Update Employed: ", updateOperation)); Console.ReadLine(); } }
private static void Main() { const string urlSharePointOnpremise = "urlsiteSharePoint"; const string listName = "Employed"; using (var site = new SPSite(urlSharePointOnpremise)) { var web = site.OpenWeb(); var list = web.Lists.TryGetList(listName); if (list == null) { var createList = web.CreateList(listName, "List of Employed of my Company", TypeList.GenericList, false, typeof(Employed)); Console.WriteLine(string.Concat("List Employed Created", createList)); } var employed = new Employed { Country = "Spain", DateBorn = new DateTime(1981, 5, 10), Job = "Sofware Architect", LastName = "Diaz Cervera", Name = "Adrian" }; var employed2 = new Employed { Country = "Spain", DateBorn = new DateTime(1979, 5, 10), Job = "Head of Innovation", LastName = "Diaz Martin", Name = "Alberto" }; var logger = new LogManager().GetLogger(new System.Diagnostics.StackTrace().GetFrame(0));; var repository = new SharePointRepository <Employed>(web, logger, listName, 10); var resultInsert = repository.Insert(employed); Console.WriteLine(string.Concat("Insertado el elemento: ", resultInsert)); resultInsert = repository.Insert(employed2); Console.WriteLine(string.Concat("Insertado el elemento: ", resultInsert)); var employed3 = repository.Get(resultInsert); Console.WriteLine(string.Concat("Return employed: ", employed3.Name)); var employedCollection = repository.GetAll(); Console.WriteLine(string.Concat("Count Employed: ", employedCollection.Count)); var resultBool = repository.Delete(resultInsert); Console.WriteLine(string.Concat("Elemento Eliminado ", resultBool)); employedCollection = repository.GetAll(); Console.WriteLine(string.Concat("Count Employed: ", employedCollection.Count)); var queryCaml = @"<Where> <Eq> <FieldRef Name='Name' /> <Value Type='Text'>Adrian</Value> </Eq> </Where>"; var queryCollection = repository.Query(queryCaml, 1); Console.WriteLine(string.Concat("Count Employed: ", queryCollection.Count)); var query = new Query().Where().Field("Name", string.Empty).Operator(TypeOperators.Eq).Value("Text", "Adrian"); queryCollection = repository.Query(query, 1); Console.WriteLine(string.Concat("Count Employed: ", queryCollection.Count)); var firstEmployed = queryCollection.FirstOrDefault(); firstEmployed.Name = "Alberto Javier"; var updateOperation = repository.Save(Convert.ToInt32(firstEmployed.ID), firstEmployed); Console.WriteLine(string.Concat("Update Employed: ", updateOperation)); Console.ReadLine(); } }