public async Task <string> createJobManagerAsync(string listIdName, tb_JobManager oJobManager, string LoginUserName) { string sMsg = string.Empty; string DateFormat = string.Empty; try { DateFormat = "MM/dd/yyyy HH:mm"; // "dd/MM/yyyy HH:mm"; // "yyyy/MM/dd"; // "yyyyMMdHHmmss"; List list = web.Lists.GetById(new Guid(listIdName)); // adds the new item to the list with ListItemCreationInformation ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation(); ListItem newListItem = list.AddItem(itemCreateInfo); newListItem["GUID0"] = oJobManager.GUID; newListItem["Nome"] = oJobManager.Nome; newListItem["Descrizione"] = oJobManager.Descrizione; newListItem["Data_x0020_Inizio_x0020_Job"] = oJobManager.DataInizioJob.ToString(DateFormat); newListItem["Data_x0020_Fine_x0020_Job"] = oJobManager.DataFineJob.ToString(DateFormat); newListItem["Tipo_x0020_Job"] = oJobManager.TipoJob; newListItem["Ripetizione"] = oJobManager.Ripetizione; newListItem["Stato_x0020_Job"] = oJobManager.StatoJob; FieldLookupValue spvReferente1 = new FieldLookupValue(); spvReferente1.LookupId = oJobManager.Referente1; newListItem["Referente1"] = spvReferente1; newListItem.Update(); FieldLookupValue spvReferente2 = new FieldLookupValue(); spvReferente2.LookupId = oJobManager.Referente2; newListItem["Referente2"] = spvReferente2; newListItem.Update(); FieldLookupValue spvReferente3 = new FieldLookupValue(); spvReferente3.LookupId = oJobManager.Referente3; newListItem["Referente3"] = spvReferente3; newListItem.Update(); FieldLookupValue spvReferente4 = new FieldLookupValue(); spvReferente4.LookupId = oJobManager.Referente4; newListItem["Referente4"] = spvReferente4; newListItem.Update(); FieldLookupValue spvReferente5 = new FieldLookupValue(); spvReferente5.LookupId = oJobManager.Referente5; newListItem["Referente5"] = spvReferente5; newListItem.Update(); // VEDERE SE FUNZIONA newListItem["Author"] = oJobManager.Autore; newListItem["Editor"] = oJobManager.AutoreUltimaModifica; //if (oJobManager.DataCreazione != null) //{ // newListItem["Created_x0020_Date"] = oJobManager.DataCreazione.ToString(DateFormat); //} //if (oJobManager.DataUltimaModifica != null) //{ // newListItem["Last_x0020_Modified"] = oJobManager.DataUltimaModifica.ToString(DateFormat); //} newListItem.Update(); // executes the creation of the new list item on SharePoint await ctx.ExecuteQueryAsync(); } catch (Exception ex) { sMsg = string.Format("Source: {0}{3} Message: {1}{3} StackTrace: {2}{3}", ex.Source, ex.Message, ex.StackTrace, System.Environment.NewLine); SeriLogging.LogFatal(LoginUserName, sMsg); } return(sMsg); }
public async Task <IEnumerable <tb_JobManager> > createManager([FromBody] string value) { List <tb_JobScheduler> listRetJobScheduler = null; List <tb_JobManager> listRetJobManager = null; string siteUrl = Helper.SiteUrlSpOnline; // "https://vivasoft.sharepoint.com/"; string LoginUserName = "******"; // TODO string statoJob = string.Empty; tb_JobManager oJobManager = null; try { statoJob = value; // DA PUBBLICARE oSP = new SPHelper(); string sRet = await oSP.getContextAsync(siteUrl); if (string.IsNullOrEmpty(sRet)) { listRetJobScheduler = await oSP.getJobsByStatoJob(Helper.ListaJobSchedulerGuid, LoginUserName, statoJob); if (listRetJobScheduler == null) { SeriLogging.LogError(LoginUserName, "listRetJobScheduler == null"); } else { SeriLogging.LogInformation(LoginUserName, "listRetJobScheduler ok"); string ret = string.Empty; foreach (var item in listRetJobScheduler) { int numRipetizioni = 0; switch (item.Ripetizione) { case "Singola": oJobManager = new tb_JobManager(); oJobManager.GUID = item.GUID; oJobManager.Nome = item.Nome; oJobManager.Descrizione = item.Descrizione; oJobManager.DataInizioJob = item.DataInizioJob; oJobManager.DataFineJob = item.DataFineJob; oJobManager.TipoJob = item.TipoJob; oJobManager.Ripetizione = item.Ripetizione; oJobManager.StatoJob = "Pubblicato"; oJobManager.Referente1 = item.Referente1; oJobManager.Referente1Valore = item.Referente1Valore; oJobManager.Referente2 = item.Referente2; oJobManager.Referente2Valore = item.Referente2Valore; oJobManager.Referente3 = item.Referente3; oJobManager.Referente3Valore = item.Referente3Valore; oJobManager.Referente4 = item.Referente4; oJobManager.Referente4Valore = item.Referente4Valore; oJobManager.Referente5 = item.Referente5; oJobManager.Referente5Valore = item.Referente5Valore; oJobManager.Autore = item.Autore; oJobManager.DataCreazione = item.DataCreazione; oJobManager.AutoreUltimaModifica = item.AutoreUltimaModifica; oJobManager.DataUltimaModifica = item.DataUltimaModifica; ret = await oSP.createJobManagerAsync(Helper.ListaJobManagerGuid, oJobManager, LoginUserName); break; case "Giornaliera": numRipetizioni = getNumRipetizioniGiornaliera(item.DataInizioJob, item.DataFineJob); oJobManager = new tb_JobManager(); oJobManager.GUID = item.GUID; oJobManager.Nome = item.Nome; oJobManager.Descrizione = item.Descrizione; oJobManager.TipoJob = item.TipoJob; oJobManager.Ripetizione = item.Ripetizione; oJobManager.StatoJob = "Pubblicato"; oJobManager.Referente1 = item.Referente1; oJobManager.Referente1Valore = item.Referente1Valore; oJobManager.Referente2 = item.Referente2; oJobManager.Referente2Valore = item.Referente2Valore; oJobManager.Referente3 = item.Referente3; oJobManager.Referente3Valore = item.Referente3Valore; oJobManager.Referente4 = item.Referente4; oJobManager.Referente4Valore = item.Referente4Valore; oJobManager.Referente5 = item.Referente5; oJobManager.Referente5Valore = item.Referente5Valore; oJobManager.Autore = item.Autore; oJobManager.DataCreazione = item.DataCreazione; oJobManager.AutoreUltimaModifica = item.AutoreUltimaModifica; oJobManager.DataUltimaModifica = item.DataUltimaModifica; for (int i = 0; i < numRipetizioni; i++) { if (i == 0) { oJobManager.DataInizioJob = item.DataInizioJob; } else { oJobManager.DataInizioJob = item.DataInizioJob.AddDays(i); } oJobManager.DataFineJob.AddDays(i + 1); ret = await oSP.createJobManagerAsync(Helper.ListaJobManagerGuid, oJobManager, LoginUserName); } break; case "Settimanale": numRipetizioni = getNumRipetizioniSettimanale(item.DataInizioJob, item.DataFineJob); oJobManager = new tb_JobManager(); oJobManager.GUID = item.GUID; oJobManager.Nome = item.Nome; oJobManager.Descrizione = item.Descrizione; oJobManager.TipoJob = item.TipoJob; oJobManager.Ripetizione = item.Ripetizione; oJobManager.StatoJob = "Pubblicato"; oJobManager.Referente1 = item.Referente1; oJobManager.Referente1Valore = item.Referente1Valore; oJobManager.Referente2 = item.Referente2; oJobManager.Referente2Valore = item.Referente2Valore; oJobManager.Referente3 = item.Referente3; oJobManager.Referente3Valore = item.Referente3Valore; oJobManager.Referente4 = item.Referente4; oJobManager.Referente4Valore = item.Referente4Valore; oJobManager.Referente5 = item.Referente5; oJobManager.Referente5Valore = item.Referente5Valore; oJobManager.Autore = item.Autore; oJobManager.DataCreazione = item.DataCreazione; oJobManager.AutoreUltimaModifica = item.AutoreUltimaModifica; oJobManager.DataUltimaModifica = item.DataUltimaModifica; for (int i = 0; i < numRipetizioni; i++) { if (i == 0) { oJobManager.DataInizioJob = item.DataInizioJob; } else { oJobManager.DataInizioJob = item.DataInizioJob.AddDays(i + 7); } oJobManager.DataFineJob.AddDays(i + 8); ret = await oSP.createJobManagerAsync(Helper.ListaJobManagerGuid, oJobManager, LoginUserName); } break; case "Mensile": numRipetizioni = getNumRipetizioniMensile(item.DataInizioJob, item.DataFineJob); oJobManager = new tb_JobManager(); oJobManager.GUID = item.GUID; oJobManager.Nome = item.Nome; oJobManager.Descrizione = item.Descrizione; oJobManager.TipoJob = item.TipoJob; oJobManager.Ripetizione = item.Ripetizione; oJobManager.StatoJob = "Pubblicato"; oJobManager.Referente1 = item.Referente1; oJobManager.Referente1Valore = item.Referente1Valore; oJobManager.Referente2 = item.Referente2; oJobManager.Referente2Valore = item.Referente2Valore; oJobManager.Referente3 = item.Referente3; oJobManager.Referente3Valore = item.Referente3Valore; oJobManager.Referente4 = item.Referente4; oJobManager.Referente4Valore = item.Referente4Valore; oJobManager.Referente5 = item.Referente5; oJobManager.Referente5Valore = item.Referente5Valore; oJobManager.Autore = item.Autore; oJobManager.DataCreazione = item.DataCreazione; oJobManager.AutoreUltimaModifica = item.AutoreUltimaModifica; oJobManager.DataUltimaModifica = item.DataUltimaModifica; for (int i = 0; i < numRipetizioni; i++) { if (i == 0) { oJobManager.DataInizioJob = item.DataInizioJob; } else { oJobManager.DataInizioJob = item.DataInizioJob.AddMonths(i); } oJobManager.DataFineJob.AddMonths(i + 1); ret = await oSP.createJobManagerAsync(Helper.ListaJobManagerGuid, oJobManager, LoginUserName); } break; case "Annuale": numRipetizioni = getNumRipetizioniAnnuale(item.DataInizioJob, item.DataFineJob); oJobManager = new tb_JobManager(); oJobManager.GUID = item.GUID; oJobManager.Nome = item.Nome; oJobManager.Descrizione = item.Descrizione; oJobManager.TipoJob = item.TipoJob; oJobManager.Ripetizione = item.Ripetizione; oJobManager.StatoJob = "Pubblicato"; oJobManager.Referente1 = item.Referente1; oJobManager.Referente1Valore = item.Referente1Valore; oJobManager.Referente2 = item.Referente2; oJobManager.Referente2Valore = item.Referente2Valore; oJobManager.Referente3 = item.Referente3; oJobManager.Referente3Valore = item.Referente3Valore; oJobManager.Referente4 = item.Referente4; oJobManager.Referente4Valore = item.Referente4Valore; oJobManager.Referente5 = item.Referente5; oJobManager.Referente5Valore = item.Referente5Valore; oJobManager.Autore = item.Autore; oJobManager.DataCreazione = item.DataCreazione; oJobManager.AutoreUltimaModifica = item.AutoreUltimaModifica; oJobManager.DataUltimaModifica = item.DataUltimaModifica; for (int i = 0; i < numRipetizioni; i++) { if (i == 0) { oJobManager.DataInizioJob = item.DataInizioJob; } else { oJobManager.DataInizioJob = item.DataInizioJob.AddYears(i); } oJobManager.DataFineJob.AddYears(i + 1); ret = await oSP.createJobManagerAsync(Helper.ListaJobManagerGuid, oJobManager, LoginUserName); } break; } } } listRetJobManager = await oSP.getJobManagerAsync(Helper.ListaJobManagerGuid, LoginUserName); if (listRetJobManager == null) { SeriLogging.LogError(LoginUserName, "listRetJobManager == null"); } else { SeriLogging.LogInformation(LoginUserName, "listRetJobManager ok"); } } else { SeriLogging.LogError(LoginUserName, sRet); } } catch (Exception ex) { string sMsg = string.Empty; sMsg = string.Format("Source: {0}{3} Message: {1}{3} StackTrace: {2}{3}", ex.Source, ex.Message, ex.StackTrace, System.Environment.NewLine); SeriLogging.LogFatal(LoginUserName, sMsg); } oSP.clearContext(); return(listRetJobManager); }
public async Task <List <tb_JobManager> > getJobManagerAsync(string listIdName, string LoginUserName) { List <tb_JobManager> listJobManager = null; try { List list = web.Lists.GetById(new Guid(listIdName)); // var q = new CamlQuery() { ViewXml = "<View><Query><Where><IsNotNull><FieldRef Name='GUID0' /></IsNotNull></Where></Query></View>" }; var q = new CamlQuery() { ViewXml = "<View><Query><Where><And><IsNotNull><FieldRef Name='GUID0' /></IsNotNull><Eq><FieldRef Name='Stato_x0020_Processo' /><Value Type='Choice'>Pubblicato</Value></Eq></And></Where></Query></View>" }; var listData = list.GetItems(q); ctx.Load(listData); await ctx.ExecuteQueryAsync(); listJobManager = new List <tb_JobManager>(); foreach (var item in listData) { oJobManager = new tb_JobManager(); oJobManager.ID = Convert.ToInt32(item.FieldValues["ID"].ToString()); if (item.FieldValues["GUID0"] != null) { oJobManager.GUID = item.FieldValues["GUID0"].ToString(); } if (item.FieldValues["Nome"] != null) { oJobManager.Nome = System.Web.HttpUtility.HtmlDecode(item.FieldValues["Nome"].ToString()); } if (item.FieldValues["Descrizione"] != null) { oJobManager.Descrizione = System.Web.HttpUtility.HtmlDecode(item.FieldValues["Descrizione"].ToString()); } if (item.FieldValues["Data_x0020_Inizio_x0020_Job"] != null) { oJobManager.DataInizioJob = Convert.ToDateTime(item.FieldValues["Data_x0020_Inizio_x0020_Job"].ToString()); } if (item.FieldValues["Data_x0020_Fine_x0020_Job"] != null) { oJobManager.DataFineJob = Convert.ToDateTime(item.FieldValues["Data_x0020_Fine_x0020_Job"].ToString()); } if (item.FieldValues["Tipo_x0020_Job"] != null) { oJobManager.TipoJob = System.Web.HttpUtility.HtmlDecode(item.FieldValues["Tipo_x0020_Job"].ToString()); } if (item.FieldValues["Ripetizione"] != null) { oJobManager.Ripetizione = System.Web.HttpUtility.HtmlDecode(item.FieldValues["Ripetizione"].ToString()); } if (item.FieldValues["Stato_x0020_Job"] != null) { oJobManager.StatoJob = System.Web.HttpUtility.HtmlDecode(item.FieldValues["Stato_x0020_Job"].ToString()); } if (item.FieldValues["Author"] != null) { //Get Lookup Field - Single Value var childIdField = item.FieldValues["Author"] as FieldLookupValue; string childId_Value = string.Empty; int childId_Id = 0; if (childIdField != null) { childId_Value = childIdField.LookupValue; childId_Id = childIdField.LookupId; } oJobManager.Autore = childId_Value; } if (item.FieldValues["Created_x0020_Date"] != null) { oJobManager.DataCreazione = Convert.ToDateTime(item.FieldValues["Created_x0020_Date"].ToString()); } if (item.FieldValues["Editor"] != null) { //Get Lookup Field - Single Value var childIdField = item.FieldValues["Editor"] as FieldLookupValue; string childId_Value = string.Empty; int childId_Id = 0; if (childIdField != null) { childId_Value = childIdField.LookupValue; childId_Id = childIdField.LookupId; } oJobManager.AutoreUltimaModifica = childId_Value; } if (item.FieldValues["Last_x0020_Modified"] != null) { oJobManager.DataUltimaModifica = Convert.ToDateTime(item.FieldValues["Last_x0020_Modified"].ToString()); } if (item.FieldValues["Referente1"] != null) { //Get Lookup Field - Single Value var childIdField = item.FieldValues["Referente1"] as FieldLookupValue; string childId_Value = string.Empty; int childId_Id = 0; if (childIdField != null) { childId_Value = childIdField.LookupValue; childId_Id = childIdField.LookupId; } oJobManager.Referente1Valore = childId_Value; oJobManager.Referente1 = childId_Id; } if (item.FieldValues["Referente2"] != null) { //Get Lookup Field - Single Value var childIdField = item.FieldValues["Referente2"] as FieldLookupValue; string childId_Value = string.Empty; int childId_Id = 0; if (childIdField != null) { childId_Value = childIdField.LookupValue; childId_Id = childIdField.LookupId; } oJobManager.Referente2Valore = childId_Value; oJobManager.Referente2 = childId_Id; } if (item.FieldValues["Referente3"] != null) { //Get Lookup Field - Single Value var childIdField = item.FieldValues["Referente3"] as FieldLookupValue; string childId_Value = string.Empty; int childId_Id = 0; if (childIdField != null) { childId_Value = childIdField.LookupValue; childId_Id = childIdField.LookupId; } oJobManager.Referente3Valore = childId_Value; oJobManager.Referente3 = childId_Id; } if (item.FieldValues["Referente4"] != null) { //Get Lookup Field - Single Value var childIdField = item.FieldValues["Referente4"] as FieldLookupValue; string childId_Value = string.Empty; int childId_Id = 0; if (childIdField != null) { childId_Value = childIdField.LookupValue; childId_Id = childIdField.LookupId; } oJobManager.Referente4Valore = childId_Value; oJobManager.Referente4 = childId_Id; } if (item.FieldValues["Referente5"] != null) { //Get Lookup Field - Single Value var childIdField = item.FieldValues["Referente5"] as FieldLookupValue; string childId_Value = string.Empty; int childId_Id = 0; if (childIdField != null) { childId_Value = childIdField.LookupValue; childId_Id = childIdField.LookupId; } oJobManager.Referente5Valore = childId_Value; oJobManager.Referente5 = childId_Id; } listJobManager.Add(oJobManager); } } catch (Exception ex) { listJobManager = null; string sMsg = string.Format("Source: {0}{3} Message: {1}{3} StackTrace: {2}{3}", ex.Source, ex.Message, ex.StackTrace, System.Environment.NewLine); SeriLogging.LogFatal(LoginUserName, sMsg); } return(listJobManager); }