private ContentDescriptor m_Descriptor; //The descriptor which this textbox edits.; public DescriptoBox(descriptor ContentDescriptor, ContextMenu ContextMenu, TextChangedHandler EventHandler) { // Builds a DescriptoBox with a specific visual style. It also hooks- // up a TextChanged event handler so the member node and content // descriptor's states can be updated. m_Descriptor = descriptor; this.Multiline = true; this.ContextMenu = ContextMenu; this.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; //Width will be adjusted automatically, but the height will remain static. this.Height = BOX_HEIGHT; //The inital contents of the DescriptoBox is the content of its corresponding content descriptor. this.Text = descriptor.Content; //A descriptor with errors can! be edited, so make the DescriptoBox readonly, otherwise //hook-up the textchanged event handler. if (descriptor.HasErrors) { this.ReadOnly = true; this.ForeColor = Color.Red; } else { this.TextChanged += new System.EventHandler(TextChangedHandler); } }
public DescriptoLabel(string text, ContentDescriptor descriptor, DeleteDescriptorEventHandler DeleteHandler) { // Builds a DescriptoLabel using the text for the label and the // descriptor for which this label represents. The visual style is // also built, which includes a context menu and text alignment. m_Descriptor = descriptor; this.Text = text; this.TextAlign = ContentAlignment.MiddleLeft; this.Size = new Size(this.PreferredWidth, this.PreferredHeight); if (m_Descriptor != null) { if (m_Descriptor.HasErrors) { this.ForeColor = Color.Red; DeleteDescriptor += new EventHandler(DeleteHandler); } //Construct the context menu and menu items. m_MenuDelete = new MenuItem("Delete"); m_LabelContextMenu = new ContextMenu(); m_LabelContextMenu.MenuItems.Add(m_MenuDelete); this.ContextMenu = m_LabelContextMenu; } }
protected void SetAttribute(string name, object value) { if (value == null) { if (zuneTags.ContainsKey(name)) { zuneTags.Remove(name); } return; } ContentDescriptor descriptor = new ContentDescriptor() { Name = name }; descriptor.SetValue(value); if (zuneTags.ContainsKey(name)) { zuneTags[name] = descriptor; } else { zuneTags.Add(name, descriptor); } }
////copy of Dcm.UI.Helpers.DataASyncUploadHelper.SaveFileInContentDiscriptor (adapted) private string SaveFileInContentDiscriptor(DatasetVersion datasetVersion) { try { //XXX put function like GetStorePathOriginalFile or GetDynamicStorePathOriginalFile // the function is available in the abstract class datawriter ExcelWriter excelWriter = new ExcelWriter(); // Move Original File to its permanent location string path = Path.Combine(AppConfiguration.DataPath, "Datasets", datasetVersion.Dataset.Id.ToString(), "DatasetVersions"); // if folder not exist if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } TaskManager TaskManager = (TaskManager)Session["TaskManager"]; String tempPath = TaskManager.Bus[TaskManager.FILEPATH].ToString(); string originalFileName = TaskManager.Bus[TaskManager.FILENAME].ToString(); string storePath = Path.Combine(path, originalFileName); string dynamicStorePath = Path.Combine("Datasets", datasetVersion.Dataset.Id.ToString(), "DatasetVersions", originalFileName); string extention = TaskManager.Bus[TaskManager.EXTENTION].ToString(); Debug.WriteLine("extention : " + extention); //Why using the excel writer, isn't any function available in System.IO.File/ Directory, etc. Javad FileHelper.MoveFile(tempPath, storePath); string mimeType = MimeMapping.GetMimeMapping(originalFileName); //Register the original data as a resource of the current dataset version ContentDescriptor originalDescriptor = new ContentDescriptor() { OrderNo = 1, Name = "unstructuredData", MimeType = mimeType, URI = dynamicStorePath, DatasetVersion = datasetVersion, }; // add current contentdesciptor to list datasetVersion.ContentDescriptors.Add(originalDescriptor); return(storePath); } catch (Exception e) { return(""); } }
private string MoveAndSaveOriginalFileInContentDiscriptor(DatasetVersion datasetVersion) { TaskManager TaskManager = (TaskManager)Session["TaskManager"]; //dataset id and data structure id are available via datasetVersion properties,why you are passing them via the BUS? Javad long datasetId = Convert.ToInt64(TaskManager.Bus[TaskManager.DATASET_ID]); long dataStructureId = Convert.ToInt64(TaskManager.Bus[TaskManager.DATASTRUCTURE_ID]); string title = TaskManager.Bus[TaskManager.DATASET_TITLE].ToString(); string ext = ".xlsm";// TaskManager.Bus[TaskManager.EXTENTION].ToString(); ExcelWriter excelWriter = new ExcelWriter(); // Move Original File to its permanent location String tempPath = TaskManager.Bus[TaskManager.FILEPATH].ToString(); string originalFileName = TaskManager.Bus[TaskManager.FILENAME].ToString(); string storePath = excelWriter.GetFullStorePathOriginalFile(datasetId, datasetVersion.Id, originalFileName); string dynamicStorePath = excelWriter.GetDynamicStorePathOriginalFile(datasetId, datasetVersion.VersionNo, originalFileName); //Why using the excel writer, isn't any function available in System.IO.File/ Directory, etc. Javad FileHelper.MoveFile(tempPath, storePath); //Register the original data as a resource of the current dataset version ContentDescriptor originalDescriptor = new ContentDescriptor() { OrderNo = 1, Name = "original", MimeType = "application/xlsm", URI = dynamicStorePath, DatasetVersion = datasetVersion, }; if (datasetVersion.ContentDescriptors.Count(p => p.Name.Equals(originalDescriptor.Name)) > 0) { // remove the one contentdesciptor foreach (ContentDescriptor cd in datasetVersion.ContentDescriptors) { if (cd.Name == originalDescriptor.Name) { cd.URI = originalDescriptor.URI; } } } else { // add current contentdesciptor to list datasetVersion.ContentDescriptors.Add(originalDescriptor); } return(storePath); }
private ContentDescriptor Generate(ContextualType type, string id, IJsonRpcSerializer serializer, bool isRequired) { var schema = schemaGenerator.GenerateSchema(type, serializer); var contentDescriptor = new ContentDescriptor { Name = id, Schema = schema, Required = isRequired, Description = type.GetXmlDocsRemarks(), // dont get confused: Description is taken from "remarks" tag; Summary = type.GetDescription(), // Summary is taken from attributes or "summary" tag (method should be named "GetSummary"?) Deprecated = type.GetAttribute <ObsoleteAttribute>() != null }; return(contentDescriptor); }
/// <summary> /// Returns the full path for a xmlmetadata xml is exist /// </summary> /// <param name="datasetVersionId"></param> /// <returns></returns> public static string GetMetadataPath(ICollection <ContentDescriptor> contentDescriptors) { string path = ""; DatasetManager datasetManager = new DatasetManager(); ContentDescriptor contentDescriptor = contentDescriptors.ToList().FirstOrDefault(c => c.Name.Equals("metadata")); if (contentDescriptor != null) { path = Path.Combine(AppConfiguration.DataPath, contentDescriptor.URI); if (FileHelper.FileExist(path)) { return(path); } } return(""); }
private string AddFileInContentDiscriptor(DatasetVersion datasetVersion, String fileName, String description) { string dataPath = AppConfiguration.DataPath; string storePath = Path.Combine(dataPath, "Datasets", datasetVersion.Dataset.Id.ToString(), "Attachments"); int lastOrderContentDescriptor = 0; if (datasetVersion.ContentDescriptors.Any()) { lastOrderContentDescriptor = datasetVersion.ContentDescriptors.Max(cc => cc.OrderNo); } ContentDescriptor originalDescriptor = new ContentDescriptor() { OrderNo = lastOrderContentDescriptor + 1, Name = fileName, MimeType = MimeMapping.GetMimeMapping(fileName), URI = Path.Combine("Datasets", datasetVersion.Dataset.Id.ToString(), "Attachments", fileName), DatasetVersion = datasetVersion, }; // replace the URI and description in case they have a same name if (datasetVersion.ContentDescriptors.Count(p => p.Name.Equals(originalDescriptor.Name)) > 0) { // foreach (ContentDescriptor cd in datasetVersion.ContentDescriptors) { if (cd.Name == originalDescriptor.Name) { cd.URI = originalDescriptor.URI; cd.Extra = SetDescription(cd.Extra, description); } } } else { // add file description Node XmlDocument doc = SetDescription(originalDescriptor.Extra, description); originalDescriptor.Extra = doc; //Add current contentdesciptor to list datasetVersion.ContentDescriptors.Add(originalDescriptor); } return(storePath); }
public FileInformation getFileInfo(ContentDescriptor contentDescriptor) { try { if (contentDescriptor.Name.ToLower().Equals("unstructureddata")) { return(getFileInfo(contentDescriptor.URI)); } else { return new FileInformation() { Name = contentDescriptor.Name, Path = contentDescriptor.URI, } }; } catch { return(null); } }
public bool deleteFile(string path) { path = Server.UrlDecode(path); { using (EntityPermissionManager entityPermissionManager = new EntityPermissionManager()) using (DatasetManager datasetManager = new DatasetManager()) { try { DatasetInfo datasetInfo = (DatasetInfo)Session["DatasetInfo"]; string entityType = (string)Session["EntityType"]; DatasetVersion workingCopy = new DatasetVersion(); string status = DatasetStateInfo.NotValid.ToString(); string[] temp = path.Split('\\'); long datasetID = datasetInfo.DatasetId; status = datasetManager.GetDatasetLatestVersion(datasetID).StateInfo.State; bool access = entityPermissionManager.HasEffectiveRight(HttpContext.User.Identity.Name, typeof(Dataset), datasetID, RightType.Delete); if (access && (datasetManager.IsDatasetCheckedOutFor(datasetID, HttpContext.User.Identity.Name) || datasetManager.CheckOutDataset(datasetID, HttpContext.User.Identity.Name))) { try { workingCopy = datasetManager.GetDatasetWorkingCopy(datasetID); using (var unitOfWork = this.GetUnitOfWork()) { workingCopy = unitOfWork.GetReadOnlyRepository <DatasetVersion>().Get(workingCopy.Id); //set StateInfo of the previus version if (workingCopy.StateInfo == null) { workingCopy.StateInfo = new Vaiona.Entities.Common.EntityStateInfo() { State = status }; } else { workingCopy.StateInfo.State = status; } unitOfWork.GetReadOnlyRepository <DatasetVersion>().Load(workingCopy.ContentDescriptors); ContentDescriptor contentDescriptor = workingCopy.ContentDescriptors.Where(cd => cd.URI.Equals(path)).FirstOrDefault(); datasetManager.DeleteContentDescriptor(contentDescriptor); } //set modification workingCopy.ModificationInfo = new EntityAuditInfo() { Performer = HttpContext.User?.Identity?.Name, Comment = "File", ActionType = AuditActionType.Delete }; // set system key values int v = 1; if (workingCopy.Dataset.Versions != null && workingCopy.Dataset.Versions.Count > 1) { v = workingCopy.Dataset.Versions.Count(); } workingCopy.Metadata = setSystemValuesToMetadata(v, workingCopy.Dataset.MetadataStructure.Id, workingCopy.Metadata); datasetManager.EditDatasetVersion(workingCopy, null, null, null); // ToDo: Get Comment from ui and users datasetManager.CheckInDataset(datasetID, temp.Last(), HttpContext.User.Identity.Name, ViewCreationBehavior.None); Session["DatasetInfo"] = datasetInfo; Session["EntityType"] = entityType; return(true); } catch { datasetManager.CheckInDataset(datasetID, "Failed to delete File " + temp.Last(), HttpContext.User.Identity.Name, ViewCreationBehavior.None); Session["DatasetInfo"] = datasetInfo; Session["EntityType"] = entityType; return(false); } } Session["DatasetInfo"] = datasetInfo; Session["EntityType"] = entityType; return(false); } catch { return(false); } } } }
public string GenerateAsciiFile(long id, long versionId, string mimeType, bool withUnits) { DatasetManager datasetManager = new DatasetManager(); DataStructureManager datasetStructureManager = new DataStructureManager(); try { DatasetVersion datasetVersion = datasetManager.GetDatasetVersion(versionId); int versionNr = datasetManager.GetDatasetVersionNr(datasetVersion); string contentDescriptorTitle = ""; string ext = ""; string nameExt = ""; TextSeperator textSeperator = TextSeperator.semicolon; if (withUnits) { nameExt = "_withunits"; } switch (mimeType) { case "text/csv": case "text/comma-separated-values": case "application/octet-stream": /* of course this is a wrong mimetype for csv. * but the c# class MimeMapping.GetMimeMapping(ext) currently returns this as a result for .csv. * since we don't use the datatype at the moment, * it will be rebuilt into the case here*/ { contentDescriptorTitle = "generatedCSV" + nameExt; ext = ".csv"; textSeperator = TextSeperator.semicolon; break; } case "text/tsv": case "text/tab-separated-values": { contentDescriptorTitle = "generatedTSV" + nameExt; ext = ".tsv"; textSeperator = TextSeperator.tab; break; } default: { contentDescriptorTitle = "generatedTXT" + nameExt; ext = ".txt"; textSeperator = TextSeperator.tab; break; } } AsciiWriter writer = new AsciiWriter(textSeperator); string path = ""; //ascii allready exist if (datasetVersion.ContentDescriptors.Count(p => p.Name.Equals(contentDescriptorTitle) && p.URI.Contains(datasetVersion.Id.ToString())) > 0 && !withUnits) { #region FileStream exist ContentDescriptor contentdescriptor = datasetVersion.ContentDescriptors.Where(p => p.Name.Equals(contentDescriptorTitle)).FirstOrDefault(); path = Path.Combine(AppConfiguration.DataPath, contentdescriptor.URI); if (FileHelper.FileExist(path)) { return(path); } #endregion FileStream exist } // not exist, needs to generated - get data first as datatable DataTable data = getData(id, versionId); long datastuctureId = datasetVersion.Dataset.DataStructure.Id; path = createDownloadFile(id, versionNr, datastuctureId, "data", ext, writer, null, withUnits); storeGeneratedFilePathToContentDiscriptor(id, datasetVersion, ext, withUnits); //add units if want string[] units = null; if (withUnits) { units = getUnits(datastuctureId, null); } writer.AddData(data, path, datastuctureId, units); return(path); } finally { datasetManager.Dispose(); datasetStructureManager.Dispose(); } }
//public string GenerateExcelFile(long id, string title, bool createAsTemplate, DataTable data = null, bool withUnits = false) //{ // string mimeType = ""; // string ext = ".xlsx"; // string contentDescriptorTitle = ""; // if (createAsTemplate) // { // ext = ".xlsm"; // contentDescriptorTitle = "generated"; // } // else // { // ext = ".xlsx"; // if (withUnits) contentDescriptorTitle = "generatedExcelWithUnits"; // else contentDescriptorTitle = "generatedExcel"; // } // mimeType = MimeMapping.GetMimeMapping(ext); // DatasetManager datasetManager = new DatasetManager(); // try // { // DatasetVersion datasetVersion = datasetManager.GetDatasetLatestVersion(id); // ExcelWriter writer = new ExcelWriter(createAsTemplate); // string path = ""; // //excel allready exist // if (datasetVersion.ContentDescriptors.Count(p => p.Name.Equals(contentDescriptorTitle) && p.URI.Contains(datasetVersion.Id.ToString())) > 0 && // data == null) // { // #region FileStream exist // ContentDescriptor contentdescriptor = // datasetVersion.ContentDescriptors.Where(p => p.Name.Equals(contentDescriptorTitle)) // .FirstOrDefault(); // path = Path.Combine(AppConfiguration.DataPath, contentdescriptor.URI); // long version = datasetVersion.Id; // long versionNrGeneratedFile = // Convert.ToInt64(contentdescriptor.URI.Split('\\').Last().Split('_')[1]); // // check if FileStream exist // if (FileHelper.FileExist(path) && version == versionNrGeneratedFile) // { // return path; // } // #endregion FileStream exist // } // // not exist needs to generated // #region FileStream not exist // if (data == null) // { // DatasetManager dm = new DatasetManager(); // data = dm.GetLatestDatasetVersionTuples(id); // data.Strip(); // } // long datastuctureId = datasetVersion.Dataset.DataStructure.Id; // int versionNr = datasetManager.GetDatasetVersionNr(datasetVersion); // if (createAsTemplate) // { // string[] columnNames = (from dc in data.Columns.Cast<DataColumn>() // select dc.Caption).ToArray(); // path = createDownloadFile(id, versionNr, datastuctureId, "data", ext, writer, columnNames); // storeGeneratedFilePathToContentDiscriptor(id, datasetVersion, ext, false); // writer.AddData(data.Rows, path, datastuctureId); // } // else // { // path = createDownloadFile(id, versionNr, datastuctureId, "data", ext, writer, null, withUnits); // // the default data is without units, so store the path of the file if it was generated // storeGeneratedFilePathToContentDiscriptor(id, datasetVersion, ext, withUnits); // string[] units = null; // if (withUnits) units = getUnits(datastuctureId, null); // writer.AddData(data, path, datastuctureId, units); // } // return path; // #endregion FileStream not exist // } // catch (Exception ex) // { // throw ex; // } // finally // { // datasetManager.Dispose(); // } //} /// <summary> /// version id = 0 == latest version /// </summary> /// <param name="id"></param> /// <param name="versionId"></param> /// <param name="createAsTemplate"></param> /// <param name="data"></param> /// <param name="withUnits"></param> /// <returns></returns> public string GenerateExcelFile(long id, long versionId, bool createAsTemplate, DataTable data = null, bool withUnits = false) { string mimeType = ""; string ext = ".xlsx"; string contentDescriptorTitle = ""; if (createAsTemplate) { ext = ".xlsm"; contentDescriptorTitle = "generated"; } else { ext = ".xlsx"; if (withUnits) { contentDescriptorTitle = "generatedExcelWithUnits"; } else { contentDescriptorTitle = "generatedExcel"; } } mimeType = MimeMapping.GetMimeMapping(ext); DatasetManager datasetManager = new DatasetManager(); try { DatasetVersion datasetVersion = datasetManager.GetDatasetLatestVersion(id); ExcelWriter writer = new ExcelWriter(createAsTemplate); string path = ""; //excel allready exist if (datasetVersion.ContentDescriptors.Count(p => p.Name.Equals(contentDescriptorTitle) && p.URI.Contains(datasetVersion.Id.ToString())) > 0 && data == null) { #region FileStream exist ContentDescriptor contentdescriptor = datasetVersion.ContentDescriptors.Where(p => p.Name.Equals(contentDescriptorTitle)) .FirstOrDefault(); path = Path.Combine(AppConfiguration.DataPath, contentdescriptor.URI); long version = datasetVersion.Id; long versionNrGeneratedFile = Convert.ToInt64(contentdescriptor.URI.Split('\\').Last().Split('_')[1]); // check if FileStream exist if (FileHelper.FileExist(path) && version == versionNrGeneratedFile) { return(path); } #endregion FileStream exist } // not exist needs to generated #region FileStream not exist if (data == null) { data = getData(id, versionId); } long datastuctureId = datasetVersion.Dataset.DataStructure.Id; int versionNr = datasetManager.GetDatasetVersionNr(datasetVersion); if (createAsTemplate) { string[] columnNames = (from dc in data.Columns.Cast <DataColumn>() select dc.Caption).ToArray(); path = createDownloadFile(id, versionNr, datastuctureId, "data", ext, writer, columnNames); storeGeneratedFilePathToContentDiscriptor(id, datasetVersion, ext, false); writer.AddData(data.Rows, path, datastuctureId); } else { path = createDownloadFile(id, versionNr, datastuctureId, "data", ext, writer, null, withUnits); // the default data is without units, so store the path of the file if it was generated storeGeneratedFilePathToContentDiscriptor(id, datasetVersion, ext, withUnits); string[] units = null; if (withUnits) { units = getUnits(datastuctureId, null); } writer.AddData(data, path, datastuctureId, units); } return(path); #endregion FileStream not exist } catch (Exception ex) { throw ex; } finally { datasetManager.Dispose(); } }
public string GenerateExcelFile(long id, string title) { string mimeType = "application / xlsm"; string contentDescriptorTitle = "generated"; string ext = ".xlsm"; DatasetManager datasetManager = new DatasetManager(); try { DatasetVersion datasetVersion = datasetManager.GetDatasetLatestVersion(id); ExcelWriter writer = new ExcelWriter(); string path = ""; //excel allready exist if (datasetVersion.ContentDescriptors.Count(p => p.Name.Equals("generated") && p.URI.Contains(datasetVersion.Id.ToString())) > 0) { #region FileStream exist ContentDescriptor contentdescriptor = datasetVersion.ContentDescriptors.Where(p => p.Name.Equals("generated")) .FirstOrDefault(); path = Path.Combine(AppConfiguration.DataPath, contentdescriptor.URI); long version = datasetVersion.Id; long versionNrGeneratedFile = Convert.ToInt64(contentdescriptor.URI.Split('\\').Last().Split('_')[1]); // check if FileStream exist if (FileHelper.FileExist(path) && version == versionNrGeneratedFile) { return(path); } // if not generate else { List <long> datatupleIds = datasetManager.GetDatasetVersionEffectiveTupleIds(datasetVersion); long datastuctureId = datasetVersion.Dataset.DataStructure.Id; path = generateDownloadFile(id, datasetVersion.Id, datastuctureId, title, ext, writer); storeGeneratedFilePathToContentDiscriptor(id, datasetVersion, ext); writer.AddDataTuplesToTemplate(datasetManager, datatupleIds, path, datastuctureId); return(path); } #endregion } // not exist needs to generated else { #region FileStream not exist List <long> datatupleIds = datasetManager.GetDatasetVersionEffectiveTupleIds(datasetVersion); long datastuctureId = datasetVersion.Dataset.DataStructure.Id; path = generateDownloadFile(id, datasetVersion.Id, datastuctureId, "data", ext, writer); storeGeneratedFilePathToContentDiscriptor(id, datasetVersion, ext); writer.AddDataTuplesToTemplate(datasetManager, datatupleIds, path, datastuctureId); return(path); #endregion } return(""); } catch (Exception ex) { throw ex; } finally { datasetManager.Dispose(); } }
private string SaveFileInContentDiscriptor(DatasetVersion datasetVersion) { try { //XXX put function like GetStorePathOriginalFile or GetDynamicStorePathOriginalFile // the function is available in the abstract class datawriter ExcelWriter excelWriter = new ExcelWriter(); // Move Original File to its permanent location String tempPath = Bus[TaskManager.FILEPATH].ToString(); string originalFileName = Bus[TaskManager.FILENAME].ToString(); //string storePath = excelWriter.GetFullStorePathOriginalFile(datasetVersion.Dataset.Id, datasetVersion.VersionNo, originalFileName); string storePath = Path.Combine(AppConfiguration.DataPath, "Datasets", datasetVersion.Dataset.Id.ToString(), originalFileName); string dynamicStorePath = Path.Combine("Datasets", datasetVersion.Dataset.Id.ToString(), originalFileName); string extention = Bus[TaskManager.EXTENTION].ToString(); Debug.WriteLine("extention : " + extention); //check if directory exist // if folder not exist var directory = Path.GetDirectoryName(storePath); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } // check if file exist allready and if yes change the name int count = 1; string fileNameOnly = Path.GetFileNameWithoutExtension(storePath); string extension = Path.GetExtension(storePath); while (File.Exists(storePath)) { string tempFileName = string.Format("{0}({1})", fileNameOnly, count++); storePath = Path.Combine(directory, tempFileName + extension); dynamicStorePath = Path.Combine("Datasets", datasetVersion.Dataset.Id.ToString(), tempFileName + extension); Bus[TaskManager.FILENAME] = tempFileName + extension; } FileHelper.MoveFile(tempPath, storePath); string mimeType = MimeMapping.GetMimeMapping(originalFileName); //Register the original data as a resource of the current dataset version ContentDescriptor originalDescriptor = new ContentDescriptor() { OrderNo = 1, Name = "unstructuredData", MimeType = mimeType, URI = dynamicStorePath, DatasetVersion = datasetVersion, }; // add current contentdesciptor to list datasetVersion.ContentDescriptors.Add(originalDescriptor); return(storePath); } catch (Exception e) { return(""); } }
//temporary solution: norman :FinishUpload2 public async Task <List <Error> > FinishUpload() { DataStructureManager dsm = new DataStructureManager(); DatasetManager dm = new DatasetManager(); IOUtility iOUtility = new IOUtility(); List <Error> temp = new List <Error>(); long id = 0; string title = ""; int numberOfRows = 0; int numberOfSkippedRows = 0; try { DatasetVersion workingCopy = new DatasetVersion(); //datatuple list List <DataTuple> rows = new List <DataTuple>(); //Dataset ds = null; bool inputWasAltered = false; if (Bus.ContainsKey(TaskManager.DATASET_ID) && Bus.ContainsKey(TaskManager.DATASTRUCTURE_ID)) { id = Convert.ToInt32(Bus[TaskManager.DATASET_ID]); long iddsd = Convert.ToInt32(Bus[TaskManager.DATASTRUCTURE_ID]); //GetValues from the previus version // Status DatasetVersion latestVersion = dm.GetDatasetLatestVersion(id); title = latestVersion.Title; string status = DatasetStateInfo.NotValid.ToString(); if (latestVersion.StateInfo != null) { status = latestVersion.StateInfo.State; } #region Progress Informations if (Bus.ContainsKey(TaskManager.CURRENTPACKAGESIZE)) { Bus[TaskManager.CURRENTPACKAGESIZE] = 0; } else { Bus.Add(TaskManager.CURRENTPACKAGESIZE, 0); } if (Bus.ContainsKey(TaskManager.CURRENTPACKAGE)) { Bus[TaskManager.CURRENTPACKAGE] = 0; } else { Bus.Add(TaskManager.CURRENTPACKAGE, 0); } #endregion Progress Informations #region structured data if (Bus.ContainsKey(TaskManager.DATASTRUCTURE_TYPE) && Bus[TaskManager.DATASTRUCTURE_TYPE].Equals(DataStructureType.Structured)) { long datasetid = id; XmlDatasetHelper xmlDatasetHelper = new XmlDatasetHelper(); try { // load all data tuple ids from the latest version List <long> datatupleFromDatabaseIds = dm.GetDatasetVersionEffectiveTupleIds(dm.GetDatasetLatestVersion(id)); // load structured data structure StructuredDataStructure sds = dsm.StructuredDataStructureRepo.Get(iddsd); dsm.StructuredDataStructureRepo.LoadIfNot(sds.Variables); #region excel reader if (Bus[TaskManager.EXTENTION].ToString().Equals(".xlsm") || iOUtility.IsSupportedExcelFile(Bus[TaskManager.EXTENTION].ToString())) { int packageSize = 100000; Bus[TaskManager.CURRENTPACKAGESIZE] = packageSize; int counter = 0; //schleife dm.CheckOutDatasetIfNot(id, User.Name); // there are cases, the dataset does not get checked out!! if (!dm.IsDatasetCheckedOutFor(id, User.Name)) { throw new Exception(string.Format("Not able to checkout dataset '{0}' for user '{1}'!", id, User.Name)); } workingCopy = dm.GetDatasetWorkingCopy(id); //set StateInfo of the previus version if (workingCopy.StateInfo == null) { workingCopy.StateInfo = new Vaiona.Entities.Common.EntityStateInfo() { State = status }; } else { workingCopy.StateInfo.State = status; } ExcelReader reader = null; ExcelFileReaderInfo excelFileReaderInfo = null; if (iOUtility.IsSupportedExcelFile(Bus[TaskManager.EXTENTION].ToString())) { excelFileReaderInfo = (ExcelFileReaderInfo)Bus[TaskManager.FILE_READER_INFO]; } reader = new ExcelReader(sds, excelFileReaderInfo); do { counter++; Bus[TaskManager.CURRENTPACKAGE] = counter; //open stream Stream = reader.Open(Bus[TaskManager.FILEPATH].ToString()); rows = new List <DataTuple>(); if (iOUtility.IsSupportedExcelFile(Bus[TaskManager.EXTENTION].ToString())) { if (reader.Position < excelFileReaderInfo.DataEndRow) { rows = reader.ReadFile(Stream, Bus[TaskManager.FILENAME].ToString(), (int)id, packageSize); } } else { rows = reader.ReadTemplateFile(Stream, Bus[TaskManager.FILENAME].ToString(), (int)id, packageSize); } //Debug.WriteLine("ReadFile: " + counter + " Time " + upload.Elapsed.TotalSeconds.ToString()); if (reader.ErrorMessages.Count > 0) { //model.ErrorList = reader.errorMessages; } else { //XXX Add packagesize to excel read function if (Bus.ContainsKey(TaskManager.DATASET_STATUS)) { if (Bus[TaskManager.DATASET_STATUS].ToString().Equals("new") || ((UploadMethod)Bus[TaskManager.UPLOAD_METHOD]).Equals(UploadMethod.Append)) { dm.EditDatasetVersion(workingCopy, rows, null, null); //Debug.WriteLine("EditDatasetVersion: " + counter + " Time " + upload.Elapsed.TotalSeconds.ToString()); //Debug.WriteLine("----"); } else if (Bus[TaskManager.DATASET_STATUS].ToString().Equals("edit")) { if (rows.Count() > 0) { Dictionary <string, List <DataTuple> > splittedDatatuples = new Dictionary <string, List <DataTuple> >(); splittedDatatuples = uploadWizardHelper.GetSplitDatatuples(rows, (List <long>)Bus[TaskManager.PRIMARY_KEYS], workingCopy, ref datatupleFromDatabaseIds); dm.EditDatasetVersion(workingCopy, splittedDatatuples["new"], splittedDatatuples["edit"], null); } } } else { } } Stream?.Close(); //count rows numberOfRows += rows.Count(); } while (rows.Count() > 0 && rows.Count() <= packageSize); numberOfSkippedRows = reader.NumberOSkippedfRows; } #endregion excel reader #region ascii reader if (iOUtility.IsSupportedAsciiFile(Bus[TaskManager.EXTENTION].ToString())) { // open file AsciiReader reader = new AsciiReader(sds, (AsciiFileReaderInfo)Bus[TaskManager.FILE_READER_INFO]); if (dm.IsDatasetCheckedOutFor(id, User.Name) || dm.CheckOutDataset(id, User.Name)) { workingCopy = dm.GetDatasetWorkingCopy(id); //set packagsize for one loop int packageSize = 100000; Bus[TaskManager.CURRENTPACKAGESIZE] = packageSize; //schleife int counter = 0; //set StateInfo of the previus version if (workingCopy.StateInfo == null) { workingCopy.StateInfo = new Vaiona.Entities.Common.EntityStateInfo() { State = status }; } else { workingCopy.StateInfo.State = status; } do { counter++; inputWasAltered = false; Bus[TaskManager.CURRENTPACKAGE] = counter; Stream = reader.Open(Bus[TaskManager.FILEPATH].ToString()); rows = reader.ReadFile(Stream, Bus[TaskManager.FILENAME].ToString(), id, packageSize); Stream.Close(); if (reader.ErrorMessages.Count > 0) { foreach (var err in reader.ErrorMessages) { temp.Add(new Error(ErrorType.Dataset, err.GetMessage())); } //return temp; } if (Bus.ContainsKey(TaskManager.DATASET_STATUS)) //check wheter there is a dataset status in the upload wizard bus { // based the dataset status and/ or the upload method if (Bus[TaskManager.DATASET_STATUS].ToString().Equals("new") || ((UploadMethod)Bus[TaskManager.UPLOAD_METHOD]).Equals(UploadMethod.Append)) { dm.EditDatasetVersion(workingCopy, rows, null, null); // add all datatuples to the datasetversion } else if (Bus[TaskManager.DATASET_STATUS].ToString().Equals("edit")) // datatuples allready exist { if (rows.Count() > 0) { //split the incoming datatuples to (new|edit) based on the primary keys var splittedDatatuples = uploadWizardHelper.GetSplitDatatuples(rows, (List <long>)Bus[TaskManager.PRIMARY_KEYS], workingCopy, ref datatupleFromDatabaseIds); dm.EditDatasetVersion(workingCopy, splittedDatatuples["new"], splittedDatatuples["edit"], null); inputWasAltered = true; } } } else // if there is no dataset status in the bus, use dataset status edit { if (rows.Count() > 0) { //split the incoming datatuples to (new|edit) based on the primary keys Dictionary <string, List <DataTuple> > splittedDatatuples = new Dictionary <string, List <DataTuple> >(); splittedDatatuples = uploadWizardHelper.GetSplitDatatuples(rows, (List <long>)Bus[TaskManager.PRIMARY_KEYS], workingCopy, ref datatupleFromDatabaseIds); dm.EditDatasetVersion(workingCopy, splittedDatatuples["new"], splittedDatatuples["edit"], null); inputWasAltered = true; } } //count rows numberOfRows += rows.Count(); } while ((rows.Count() > 0 && rows.Count() <= packageSize) || inputWasAltered == true); numberOfSkippedRows = reader.NumberOSkippedfRows; } //Stream.Close(); } #endregion ascii reader #region contentdescriptors //remove all contentdescriptors from the old version //generatedTXT if (workingCopy.ContentDescriptors.Any(c => c.Name.Equals("generatedTXT"))) { ContentDescriptor tmp = workingCopy.ContentDescriptors.Where(c => c.Name.Equals("generatedTXT")) .FirstOrDefault(); dm.DeleteContentDescriptor(tmp); } //generatedCSV if (workingCopy.ContentDescriptors.Any(c => c.Name.Equals("generatedCSV"))) { ContentDescriptor tmp = workingCopy.ContentDescriptors.Where(c => c.Name.Equals("generatedCSV")) .FirstOrDefault(); dm.DeleteContentDescriptor(tmp); } //generated if (workingCopy.ContentDescriptors.Any(c => c.Name.Equals("generated"))) { ContentDescriptor tmp = workingCopy.ContentDescriptors.Where(c => c.Name.Equals("generated")) .FirstOrDefault(); dm.DeleteContentDescriptor(tmp); } #endregion contentdescriptors #region set System value into metadata if (Bus.ContainsKey(TaskManager.DATASET_STATUS)) { bool newdataset = Bus[TaskManager.DATASET_STATUS].ToString().Equals("new"); int v = 1; if (workingCopy.Dataset.Versions != null && workingCopy.Dataset.Versions.Count > 1) { v = workingCopy.Dataset.Versions.Count(); } //set modification workingCopy.ModificationInfo = new EntityAuditInfo() { Performer = User.Name, Comment = "Data", ActionType = newdataset ? AuditActionType.Create : AuditActionType.Edit }; setSystemValuesToMetadata(id, v, workingCopy.Dataset.MetadataStructure.Id, workingCopy.Metadata, newdataset); dm.EditDatasetVersion(workingCopy, null, null, null); } #endregion set System value into metadata // ToDo: Get Comment from ui and users MoveAndSaveOriginalFileInContentDiscriptor(workingCopy); dm.CheckInDataset(id, numberOfRows + " rows", User.Name); //send email var es = new EmailService(); es.Send(MessageHelper.GetUpdateDatasetHeader(datasetid), MessageHelper.GetUpdateDatasetMessage(datasetid, title, User.DisplayName), ConfigurationManager.AppSettings["SystemEmail"] ); } catch (Exception e) { temp.Add(new Error(ErrorType.Other, "Can not upload. : " + e.Message)); var es = new EmailService(); es.Send(MessageHelper.GetErrorHeader(), "Can not upload. : " + e.Message, ConfigurationManager.AppSettings["SystemEmail"] ); } finally { } } #endregion structured data #region unstructured data if (Bus.ContainsKey(TaskManager.DATASTRUCTURE_TYPE) && Bus[TaskManager.DATASTRUCTURE_TYPE].Equals(DataStructureType.Unstructured)) { // checkout the dataset, apply the changes, and check it in. if (dm.IsDatasetCheckedOutFor(id, User.Name) || dm.CheckOutDataset(id, User.Name)) { try { workingCopy = dm.GetDatasetWorkingCopy(id); using (var unitOfWork = this.GetUnitOfWork()) { workingCopy.VersionNo += 1; //set StateInfo of the previus version if (workingCopy.StateInfo == null) { workingCopy.StateInfo = new Vaiona.Entities.Common.EntityStateInfo() { State = status }; } else { workingCopy.StateInfo.State = status; } unitOfWork.GetReadOnlyRepository <DatasetVersion>().Load(workingCopy.ContentDescriptors); SaveFileInContentDiscriptor(workingCopy); } if (Bus.ContainsKey(TaskManager.DATASET_STATUS)) { bool newdataset = Bus[TaskManager.DATASET_STATUS].ToString().Equals("new"); int v = 1; if (workingCopy.Dataset.Versions != null && workingCopy.Dataset.Versions.Count > 1) { v = workingCopy.Dataset.Versions.Count(); } //set modification workingCopy.ModificationInfo = new EntityAuditInfo() { Performer = User.Name, Comment = "File", ActionType = AuditActionType.Create }; setSystemValuesToMetadata(id, v, workingCopy.Dataset.MetadataStructure.Id, workingCopy.Metadata, newdataset); dm.EditDatasetVersion(workingCopy, null, null, null); } //filename string filename = ""; if (Bus.ContainsKey(TaskManager.FILENAME)) { filename = Bus[TaskManager.FILENAME]?.ToString(); } // ToDo: Get Comment from ui and users dm.CheckInDataset(id, filename, User.Name, ViewCreationBehavior.None); } catch (Exception ex) { throw ex; } } } #endregion unstructured data } else { temp.Add(new Error(ErrorType.Dataset, "Dataset is not selected.")); } if (temp.Count <= 0) { dm.CheckInDataset(id, "no update on data tuples", User.Name, ViewCreationBehavior.None); } else { dm.UndoCheckoutDataset(id, User.Name); } } catch (Exception ex) { temp.Add(new Error(ErrorType.Dataset, ex.Message)); dm.CheckInDataset(id, "no update on data tuples", User.Name, ViewCreationBehavior.None); } finally { if (RunningASync) { var user = User; if (temp.Any()) { var es = new EmailService(); es.Send(MessageHelper.GetPushApiUploadFailHeader(id, title), MessageHelper.GetPushApiUploadFailMessage(id, user.Name, temp.Select(e => e.ToString()).ToArray()), new List <string> { user.Email }, null, new List <string> { ConfigurationManager.AppSettings["SystemEmail"] }); } else { var es = new EmailService(); es.Send(MessageHelper.GetASyncFinishUploadHeader(id, title), MessageHelper.GetASyncFinishUploadMessage(id, title, numberOfRows, numberOfSkippedRows), new List <string> { user.Email }, null, new List <string> { ConfigurationManager.AppSettings["SystemEmail"] }); } } dm.Dispose(); dsm.Dispose(); } return(temp); }
public string GenerateAsciiFile(long id, long versionId, string title, string mimeType) { DatasetManager datasetManager = new DatasetManager(); try { DatasetVersion datasetVersion = datasetManager.GetDatasetVersion(versionId); string contentDescriptorTitle = ""; string ext = ""; TextSeperator textSeperator = TextSeperator.semicolon; switch (mimeType) { case "text/csv": { contentDescriptorTitle = "generatedCSV"; ext = ".csv"; textSeperator = TextSeperator.semicolon; break; } default: { contentDescriptorTitle = "generatedTXT"; ext = ".txt"; textSeperator = TextSeperator.tab; break; } } AsciiWriter writer = new AsciiWriter(textSeperator); string path = ""; //ascii allready exist if (datasetVersion.ContentDescriptors.Count(p => p.Name.Equals(contentDescriptorTitle) && p.URI.Contains(datasetVersion.Id.ToString())) > 0) { #region FileStream exist ContentDescriptor contentdescriptor = datasetVersion.ContentDescriptors.Where(p => p.Name.Equals(contentDescriptorTitle)).FirstOrDefault(); path = Path.Combine(AppConfiguration.DataPath, contentdescriptor.URI); if (FileHelper.FileExist(path)) { return(path); } else { List <long> datatupleIds = datasetManager.GetDatasetVersionEffectiveTupleIds(datasetVersion); long datastuctureId = datasetVersion.Dataset.DataStructure.Id; path = generateDownloadFile(id, datasetVersion.Id, datastuctureId, "Data", ext, writer); storeGeneratedFilePathToContentDiscriptor(id, datasetVersion, ext); writer.AddDataTuples(datasetManager, datatupleIds, path, datastuctureId); return(path); } #endregion } // not exist needs to generated else { #region FileStream not exist List <long> datatupleIds = datasetManager.GetDatasetVersionEffectiveTupleIds(datasetVersion); long datastuctureId = datasetVersion.Dataset.DataStructure.Id; path = generateDownloadFile(id, datasetVersion.Id, datastuctureId, "data", ext, writer); storeGeneratedFilePathToContentDiscriptor(id, datasetVersion, ext); writer.AddDataTuples(datasetManager, datatupleIds, path, datastuctureId); return(path); #endregion } } finally { datasetManager.Dispose(); } }
//temporary solution: norman :FinishUpload2 public List <Error> FinishUpload(TaskManager taskManager) { DataStructureManager dsm = new DataStructureManager(); DatasetManager dm = new DatasetManager(); try { List <Error> temp = new List <Error>(); DatasetVersion workingCopy = new DatasetVersion(); //datatuple list List <DataTuple> rows = new List <DataTuple>(); Dataset ds = null; bool inputWasAltered = false; if (TaskManager.Bus.ContainsKey(TaskManager.DATASET_ID) && TaskManager.Bus.ContainsKey(TaskManager.DATASTRUCTURE_ID)) { long id = Convert.ToInt32(TaskManager.Bus[TaskManager.DATASET_ID]); long iddsd = Convert.ToInt32(TaskManager.Bus[TaskManager.DATASTRUCTURE_ID]); ds = dm.GetDataset(id); // Javad: Please check if the dataset does exists!! //GetValues from the previus version // Status DatasetVersion latestVersion = dm.GetDatasetLatestVersion(ds); string status = DatasetStateInfo.NotValid.ToString(); if (latestVersion.StateInfo != null) { status = latestVersion.StateInfo.State; } #region Progress Informations if (TaskManager.Bus.ContainsKey(TaskManager.CURRENTPACKAGESIZE)) { TaskManager.Bus[TaskManager.CURRENTPACKAGESIZE] = 0; } else { TaskManager.Bus.Add(TaskManager.CURRENTPACKAGESIZE, 0); } if (TaskManager.Bus.ContainsKey(TaskManager.CURRENTPACKAGE)) { TaskManager.Bus[TaskManager.CURRENTPACKAGE] = 0; } else { TaskManager.Bus.Add(TaskManager.CURRENTPACKAGE, 0); } #endregion #region structured data if (TaskManager.Bus.ContainsKey(TaskManager.DATASTRUCTURE_TYPE) && TaskManager.Bus[TaskManager.DATASTRUCTURE_TYPE].Equals(DataStructureType.Structured)) { string title = ""; long datasetid = ds.Id; XmlDatasetHelper xmlDatasetHelper = new XmlDatasetHelper(); title = xmlDatasetHelper.GetInformation(ds.Id, NameAttributeValues.title); try { //Stopwatch fullTime = Stopwatch.StartNew(); //Stopwatch loadDT = Stopwatch.StartNew(); List <long> datatupleFromDatabaseIds = dm.GetDatasetVersionEffectiveTupleIds(dm.GetDatasetLatestVersion(ds.Id)); //loadDT.Stop(); //Debug.WriteLine("Load DT From Db Time " + loadDT.Elapsed.TotalSeconds.ToString()); StructuredDataStructure sds = dsm.StructuredDataStructureRepo.Get(iddsd); dsm.StructuredDataStructureRepo.LoadIfNot(sds.Variables); #region excel reader if (TaskManager.Bus[TaskManager.EXTENTION].ToString().Equals(".xlsm")) { int packageSize = 10000; TaskManager.Bus[TaskManager.CURRENTPACKAGESIZE] = packageSize; int counter = 0; ExcelReader reader = new ExcelReader(); //schleife dm.CheckOutDatasetIfNot(ds.Id, GetUsernameOrDefault()); // there are cases, the dataset does not get checked out!! if (!dm.IsDatasetCheckedOutFor(ds.Id, GetUsernameOrDefault())) { throw new Exception(string.Format("Not able to checkout dataset '{0}' for user '{1}'!", ds.Id, GetUsernameOrDefault())); } workingCopy = dm.GetDatasetWorkingCopy(ds.Id); //set StateInfo of the previus version if (workingCopy.StateInfo == null) { workingCopy.StateInfo = new Vaiona.Entities.Common.EntityStateInfo() { State = status }; } else { workingCopy.StateInfo.State = status; } do { //Stopwatch packageTime = Stopwatch.StartNew(); counter++; TaskManager.Bus[TaskManager.CURRENTPACKAGE] = counter; // open file Stream = reader.Open(TaskManager.Bus[TaskManager.FILEPATH].ToString()); Stopwatch upload = Stopwatch.StartNew(); rows = reader.ReadFile(Stream, TaskManager.Bus[TaskManager.FILENAME].ToString(), sds, (int)id, packageSize); upload.Stop(); Debug.WriteLine("ReadFile: " + counter + " Time " + upload.Elapsed.TotalSeconds.ToString()); if (reader.ErrorMessages.Count > 0) { //model.ErrorList = reader.errorMessages; } else { //XXX Add packagesize to excel read function if (TaskManager.Bus.ContainsKey(TaskManager.DATASET_STATUS)) { if (TaskManager.Bus[TaskManager.DATASET_STATUS].ToString().Equals("new")) { upload = Stopwatch.StartNew(); dm.EditDatasetVersion(workingCopy, rows, null, null); upload.Stop(); Debug.WriteLine("EditDatasetVersion: " + counter + " Time " + upload.Elapsed.TotalSeconds.ToString()); //Debug.WriteLine("----"); } if (TaskManager.Bus[TaskManager.DATASET_STATUS].ToString().Equals("edit")) { if (rows.Count() > 0) { //Stopwatch split = Stopwatch.StartNew(); Dictionary <string, List <DataTuple> > splittedDatatuples = new Dictionary <string, List <DataTuple> >(); splittedDatatuples = uploadWizardHelper.GetSplitDatatuples(rows, (List <long>)TaskManager.Bus[TaskManager.PRIMARY_KEYS], workingCopy, ref datatupleFromDatabaseIds); //split.Stop(); //Debug.WriteLine("Split : " + counter + " Time " + split.Elapsed.TotalSeconds.ToString()); //Stopwatch upload = Stopwatch.StartNew(); dm.EditDatasetVersion(workingCopy, splittedDatatuples["new"], splittedDatatuples["edit"], null); // upload.Stop(); // Debug.WriteLine("Upload : " + counter + " Time " + upload.Elapsed.TotalSeconds.ToString()); // Debug.WriteLine("----"); } } } else { } } Stream.Close(); //packageTime.Stop(); //Debug.WriteLine("Package : " + counter + " packageTime Time " + packageTime.Elapsed.TotalSeconds.ToString()); } while (rows.Count() > 0); //fullTime.Stop(); //Debug.WriteLine("FullTime " + fullTime.Elapsed.TotalSeconds.ToString()); } #endregion #region ascii reader if (TaskManager.Bus[TaskManager.EXTENTION].ToString().Equals(".csv") || TaskManager.Bus[TaskManager.EXTENTION].ToString().Equals(".txt")) { // open file AsciiReader reader = new AsciiReader(); //Stream = reader.Open(TaskManager.Bus[TaskManager.FILEPATH].ToString()); //DatasetManager dm = new DatasetManager(); //Dataset ds = dm.GetDataset(id); Stopwatch totalTime = Stopwatch.StartNew(); if (dm.IsDatasetCheckedOutFor(ds.Id, GetUsernameOrDefault()) || dm.CheckOutDataset(ds.Id, GetUsernameOrDefault())) { workingCopy = dm.GetDatasetWorkingCopy(ds.Id); int packageSize = 100000; TaskManager.Bus[TaskManager.CURRENTPACKAGESIZE] = packageSize; //schleife int counter = 0; //set StateInfo of the previus version if (workingCopy.StateInfo == null) { workingCopy.StateInfo = new Vaiona.Entities.Common.EntityStateInfo() { State = status }; } else { workingCopy.StateInfo.State = status; } do { counter++; inputWasAltered = false; TaskManager.Bus[TaskManager.CURRENTPACKAGE] = counter; Stream = reader.Open(TaskManager.Bus[TaskManager.FILEPATH].ToString()); rows = reader.ReadFile(Stream, TaskManager.Bus[TaskManager.FILENAME].ToString(), (AsciiFileReaderInfo)TaskManager.Bus[TaskManager.FILE_READER_INFO], sds, id, packageSize); Stream.Close(); if (reader.ErrorMessages.Count > 0) { foreach (var err in reader.ErrorMessages) { temp.Add(new Error(ErrorType.Dataset, err.GetMessage())); } //return temp; } //model.Validated = true; Stopwatch dbTimer = Stopwatch.StartNew(); if (TaskManager.Bus.ContainsKey(TaskManager.DATASET_STATUS)) { if (TaskManager.Bus[TaskManager.DATASET_STATUS].ToString().Equals("new")) { dm.EditDatasetVersion(workingCopy, rows, null, null); } if (TaskManager.Bus[TaskManager.DATASET_STATUS].ToString().Equals("edit")) { if (rows.Count() > 0) { //Dictionary<string, List<DataTuple>> splittedDatatuples = new Dictionary<string, List<AbstractTuple>>(); var splittedDatatuples = uploadWizardHelper.GetSplitDatatuples(rows, (List <long>)TaskManager.Bus[TaskManager.PRIMARY_KEYS], workingCopy, ref datatupleFromDatabaseIds); dm.EditDatasetVersion(workingCopy, splittedDatatuples["new"], splittedDatatuples["edit"], null); inputWasAltered = true; } } } else { if (rows.Count() > 0) { Dictionary <string, List <DataTuple> > splittedDatatuples = new Dictionary <string, List <DataTuple> >(); splittedDatatuples = uploadWizardHelper.GetSplitDatatuples(rows, (List <long>)TaskManager.Bus[TaskManager.PRIMARY_KEYS], workingCopy, ref datatupleFromDatabaseIds); dm.EditDatasetVersion(workingCopy, splittedDatatuples["new"], splittedDatatuples["edit"], null); inputWasAltered = true; } } dbTimer.Stop(); Debug.WriteLine(" db time" + dbTimer.Elapsed.TotalSeconds.ToString()); } while (rows.Count() > 0 || inputWasAltered == true); totalTime.Stop(); Debug.WriteLine(" Total Time " + totalTime.Elapsed.TotalSeconds.ToString()); } //Stream.Close(); } #endregion #region contentdescriptors //remove all contentdescriptors from the old version //generatedTXT if (workingCopy.ContentDescriptors.Any(c => c.Name.Equals("generatedTXT"))) { ContentDescriptor tmp = workingCopy.ContentDescriptors.Where(c => c.Name.Equals("generatedTXT")) .FirstOrDefault(); dm.DeleteContentDescriptor(tmp); } //generatedCSV if (workingCopy.ContentDescriptors.Any(c => c.Name.Equals("generatedCSV"))) { ContentDescriptor tmp = workingCopy.ContentDescriptors.Where(c => c.Name.Equals("generatedCSV")) .FirstOrDefault(); dm.DeleteContentDescriptor(tmp); } //generated if (workingCopy.ContentDescriptors.Any(c => c.Name.Equals("generated"))) { ContentDescriptor tmp = workingCopy.ContentDescriptors.Where(c => c.Name.Equals("generated")) .FirstOrDefault(); dm.DeleteContentDescriptor(tmp); } #endregion // ToDo: Get Comment from ui and users MoveAndSaveOriginalFileInContentDiscriptor(workingCopy); dm.CheckInDataset(ds.Id, "upload data from upload wizard", GetUsernameOrDefault()); //send email var es = new EmailService(); es.Send(MessageHelper.GetUpdateDatasetHeader(), MessageHelper.GetUpdateDatasetMessage(datasetid, title, GetUsernameOrDefault()), ConfigurationManager.AppSettings["SystemEmail"] ); } catch (Exception e) { temp.Add(new Error(ErrorType.Other, "Can not upload. : " + e.Message)); var es = new EmailService(); es.Send(MessageHelper.GetErrorHeader(), "Can not upload. : " + e.Message, ConfigurationManager.AppSettings["SystemEmail"] ); } finally { } } #endregion #region unstructured data if (TaskManager.Bus.ContainsKey(TaskManager.DATASTRUCTURE_TYPE) && TaskManager.Bus[TaskManager.DATASTRUCTURE_TYPE].Equals(DataStructureType.Unstructured)) { // checkout the dataset, apply the changes, and check it in. if (dm.IsDatasetCheckedOutFor(ds.Id, GetUsernameOrDefault()) || dm.CheckOutDataset(ds.Id, GetUsernameOrDefault())) { try { workingCopy = dm.GetDatasetWorkingCopy(ds.Id); using (var unitOfWork = this.GetUnitOfWork()) { workingCopy = unitOfWork.GetReadOnlyRepository <DatasetVersion>().Get(workingCopy.Id); //set StateInfo of the previus version if (workingCopy.StateInfo == null) { workingCopy.StateInfo = new Vaiona.Entities.Common.EntityStateInfo() { State = status }; } else { workingCopy.StateInfo.State = status; } unitOfWork.GetReadOnlyRepository <DatasetVersion>().Load(workingCopy.ContentDescriptors); SaveFileInContentDiscriptor(workingCopy); } dm.EditDatasetVersion(workingCopy, null, null, null); // ToDo: Get Comment from ui and users dm.CheckInDataset(ds.Id, "upload unstructured data", GetUsernameOrDefault(), ViewCreationBehavior.None); } catch (Exception ex) { throw ex; } } } #endregion } else { temp.Add(new Error(ErrorType.Dataset, "Dataset is not selected.")); } if (temp.Count <= 0) { dm.CheckInDataset(ds.Id, "checked in but no update on data tuples", GetUsernameOrDefault(), ViewCreationBehavior.None); } else { dm.UndoCheckoutDataset(ds.Id, GetUsernameOrDefault()); } return(temp); } finally { dm.Dispose(); dsm.Dispose(); } }
/// <summary>Attempts to convert HTTP content to a JSON string.</summary> /// <param name="source">The source.</param> /// <returns>The content as a string.</returns> /// <remarks> /// If the content is not convertible to a string (eg. byte array) then nothing is returned. /// </remarks> public static async Task <string> ToJsonAsync(this HttpContent source) { if (source == null) { return(null); } if (!(source is StringContent)) { if (source is ByteArrayContent) { var data = new ContentDescriptor() { Type = "byte[]", Length = source.Headers.ContentLength ?? -1 }; return(await ToJsonAsync(data).ConfigureAwait(false)); } else if (source is StreamContent) { var data = new ContentDescriptor() { Type = "Stream", Length = source.Headers.ContentLength ?? -1 }; return(await ToJsonAsync(data).ConfigureAwait(false)); } else if (source is MultipartContent mpc) { var data = new ContentDescriptor() { Type = "MultiPart", Length = source.Headers.ContentLength ?? -1 }; var children = from child in mpc select child.ToJsonAsync(); data.Data = await Task.WhenAll(children).ConfigureAwait(false); return(await ToJsonAsync(data).ConfigureAwait(false)); } ; } ; //Try to read the data as a string var value = await source.ReadAsStringAsync().ConfigureAwait(false); //Is this JSON? var mediaType = source.Headers.ContentType?.MediaType ?? ""; if ((mediaType.IndexOf("json", StringComparison.OrdinalIgnoreCase) >= 0) || value.TrimStart().StartsWith("{")) { return(value); } //Possibly XML or something else return("{ \"value\": " + "\"" + value + "\" }"); }