public static bool add_file(Guid applicationId, Guid ownerId, FileOwnerTypes ownerType, DocFileInfo attachment, Guid currentUserId) { List <DocFileInfo> atts = new List <DocFileInfo>(); atts.Add(attachment); return(add_files(applicationId, ownerId, ownerType, ref atts, currentUserId)); }
public static bool AddFiles(Guid applicationId, Guid ownerId, FileOwnerTypes ownerType, ref List <DocFileInfo> attachments, Guid currentUserId) { SqlConnection con = new SqlConnection(ProviderUtil.ConnectionString); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; //Add Attachments DataTable attachmentsTable = new DataTable(); attachmentsTable.Columns.Add("FileID", typeof(Guid)); attachmentsTable.Columns.Add("FileName", typeof(string)); attachmentsTable.Columns.Add("Extension", typeof(string)); attachmentsTable.Columns.Add("MIME", typeof(string)); attachmentsTable.Columns.Add("Size", typeof(long)); attachmentsTable.Columns.Add("OwnerID", typeof(Guid)); attachmentsTable.Columns.Add("OwnerType", typeof(string)); foreach (DocFileInfo _att in attachments) { attachmentsTable.Rows.Add(_att.FileID, _att.FileName, _att.Extension, _att.MIME(), _att.Size, _att.OwnerID, _att.OwnerType); } SqlParameter attachmentsParam = new SqlParameter("@Attachments", SqlDbType.Structured); attachmentsParam.TypeName = "[dbo].[DocFileInfoTableType]"; attachmentsParam.Value = attachmentsTable; //end of Add Attachments cmd.Parameters.AddWithValue("@ApplicationID", applicationId); cmd.Parameters.AddWithValue("@OwnerID", ownerId); cmd.Parameters.AddWithValue("@OwnerType", ownerType.ToString()); cmd.Parameters.Add(attachmentsParam); cmd.Parameters.AddWithValue("@CurrentUserID", currentUserId); cmd.Parameters.AddWithValue("@Now", DateTime.Now); string spName = GetFullyQualifiedName("AddFiles"); string sep = ", "; string arguments = "@ApplicationID" + sep + "@OwnerID" + sep + "@OwnerType" + sep + "@Attachments" + sep + "@CurrentUserID" + sep + "@Now"; cmd.CommandText = ("EXEC" + " " + spName + " " + arguments); con.Open(); try { return(ProviderUtil.succeed((IDataReader)cmd.ExecuteReader())); } catch (Exception ex) { LogController.save_error_log(applicationId, null, spName, ex, ModuleIdentifier.DCT); return(false); } finally { con.Close(); } }
public static bool CopyFile(Guid applicationId, Guid ownerId, Guid fileId, FileOwnerTypes ownerType, Guid currentUserId) { string spName = GetFullyQualifiedName("CopyFile"); try { return(ProviderUtil.succeed(ProviderUtil.execute_reader(spName, applicationId, ownerId, fileId, ownerType.ToString(), currentUserId, DateTime.Now))); } catch (Exception ex) { LogController.save_error_log(applicationId, null, spName, ex, ModuleIdentifier.DCT); return(false); } }
private static void _parse_files(Guid applicationId, ref IDataReader reader, ref List <DocFileInfo> lstFiles) { while (reader.Read()) { try { DocFileInfo file = new DocFileInfo(); if (!string.IsNullOrEmpty(reader["OwnerID"].ToString())) { file.OwnerID = (Guid)reader["OwnerID"]; } if (!string.IsNullOrEmpty(reader["FileID"].ToString())) { file.FileID = (Guid)reader["FileID"]; } if (!string.IsNullOrEmpty(reader["FileName"].ToString())) { file.FileName = (string)reader["FileName"]; } if (!string.IsNullOrEmpty(reader["Extension"].ToString())) { file.Extension = (string)reader["Extension"]; } if (!string.IsNullOrEmpty(reader["Size"].ToString())) { file.Size = (long)reader["Size"]; } FileOwnerTypes fot = FileOwnerTypes.None; if (Enum.TryParse <FileOwnerTypes>(reader["OwnerType"].ToString(), out fot)) { file.OwnerType = fot; } lstFiles.Add(file); } catch { } } if (!reader.IsClosed) { reader.Close(); } }
private static FolderNames get_folder_name(FileOwnerTypes ownerType) { switch (ownerType) { case FileOwnerTypes.Node: case FileOwnerTypes.Wiki: case FileOwnerTypes.Message: case FileOwnerTypes.WorkFlow: case FileOwnerTypes.FormElement: return(FolderNames.Attachments); case FileOwnerTypes.WikiContent: return(FolderNames.WikiContent); case FileOwnerTypes.PDFCover: return(FolderNames.PDFCovers); default: return(FolderNames.TemporaryFiles); } }
protected static DocFileInfo _get_file_info(Dictionary <string, object> dic) { if (dic == null) { return(null); } Guid? fileId = !dic.ContainsKey("FileID") ? null : PublicMethods.parse_guid(dic["FileID"].ToString()); string extension = !dic.ContainsKey("Extension") ? null : PublicMethods.parse_string(dic["Extension"].ToString()); string fileName = !dic.ContainsKey("FileName") ? null : PublicMethods.parse_string(dic["FileName"].ToString()); long? size = !dic.ContainsKey("Size") ? null : PublicMethods.parse_long(dic["Size"].ToString()); Guid? ownerId = !dic.ContainsKey("OwnerID") ? null : PublicMethods.parse_guid(dic["OwnerID"].ToString()); FileOwnerTypes ownerType = FileOwnerTypes.None; if (dic.ContainsKey("OwnerType")) { Enum.TryParse <FileOwnerTypes>(dic["OwnerType"].ToString(), true, out ownerType); } DocFileInfo fi = new DocFileInfo() { FileID = fileId, FileName = fileName, Extension = extension, Size = size }; if (ownerId.HasValue && ownerId != Guid.Empty) { fi.OwnerID = ownerId; } if (ownerType != FileOwnerTypes.None) { fi.OwnerType = ownerType; } return(!fileId.HasValue ? null : fi); }
public static bool copy_file(Guid applicationId, Guid ownerId, Guid fileId, FileOwnerTypes ownerType, Guid currentUserId) { return(DataProvider.CopyFile(applicationId, ownerId, fileId, ownerType, currentUserId)); }
public static List <DocFileInfo> get_owner_files(Guid applicationId, List <Guid> ownerIds, FileOwnerTypes ownerType = FileOwnerTypes.None) { return(get_owner_files(applicationId, ref ownerIds, ownerType)); }
public static bool add_files(Guid applicationId, Guid ownerId, FileOwnerTypes ownerType, ref List <DocFileInfo> attachments, Guid currentUserId) { return(DataProvider.AddFiles(applicationId, ownerId, ownerType, ref attachments, currentUserId)); }
public static DocFileInfo decode_base64_file_content(Guid applicationId, Guid?ownerId, string base64FileContent, FileOwnerTypes ownerType) { if (string.IsNullOrEmpty(base64FileContent)) { return(null); } byte[] theData = null; try { theData = Convert.FromBase64String(base64FileContent); } catch { return(null); } int FIXED_HEADER = 16; DocFileInfo ret = new DocFileInfo() { FileID = Guid.NewGuid(), OwnerID = ownerId, OwnerType = ownerType, FolderName = FolderNames.TemporaryFiles }; try { using (MemoryStream ms = new MemoryStream(theData)) { using (BinaryReader theReader = new BinaryReader(ms)) { //Position the reader to get the file size. byte[] headerData = new byte[FIXED_HEADER]; headerData = theReader.ReadBytes(headerData.Length); ret.Size = (int)theReader.ReadUInt32(); int fileNameLength = (int)theReader.ReadUInt32() * 2; if (fileNameLength <= 0 || fileNameLength > 255) { throw new Exception("what the fuzz!!"); } byte[] fileNameBytes = theReader.ReadBytes(fileNameLength); //InfoPath uses UTF8 encoding. Encoding enc = Encoding.Unicode; string fullFileName = enc.GetString(fileNameBytes, 0, fileNameLength - 2); int dotIndex = fullFileName.LastIndexOf("."); if (dotIndex > 0 && dotIndex < (fullFileName.Length - 1)) { ret.Extension = fullFileName.Substring(dotIndex + 1); } ret.FileName = string.IsNullOrEmpty(ret.Extension) ? fullFileName : fullFileName.Substring(0, dotIndex); byte[] fileBytes = theReader.ReadBytes((int)ret.Size.Value); if (!ret.store(applicationId, fileBytes)) { return(null); } } } return(ret); } catch (Exception ex) { //maybe the file is a base64 image!! try { Image img = PublicMethods.image_from_byte_array(theData); if (img == null) { return(null); } byte[] imageBytes = PublicMethods.image_to_byte_array(img, System.Drawing.Imaging.ImageFormat.Jpeg); if (imageBytes == null || imageBytes.Length == 0) { return(null); } ret.Size = imageBytes.Length; ret.FileName = "img"; ret.Extension = "jpg"; if (!ret.store(applicationId, imageBytes)) { return(null); } return(ret); } catch { return(null); } } }
private static void sync_nodes(Guid applicationId) { string baseUrl = "http://10.110.11.53"; //login NameValueCollection vals = new NameValueCollection(); vals.Add("username", "developer"); vals.Add("password", "9B1aLrYSC_E^"); string res = PublicMethods.web_request(baseUrl + "/Ajax/API.ashx?command=authenticate", vals); Dictionary <string, object> jsonRes = PublicMethods.fromJSON(res); string ticket = jsonRes.ContainsKey("Ticket") ? (string)jsonRes["Ticket"] : null; string accessToken = jsonRes.ContainsKey("AccessToken") ? (string)jsonRes["AccessToken"] : null; if (string.IsNullOrEmpty(ticket) || string.IsNullOrEmpty(accessToken)) { return; } //end of login List <Node> nodes = CNController.get_nodes(applicationId, null, null, null, null, null, 10, null, null, null); List <NodeInfo> nodeInfo = CNController.get_node_info(applicationId, nodes.Select(u => u.NodeID.Value).ToList(), null, true, true, null, null, null, null, null, null, null, null, null); List <DocFileInfo> attachments = DocumentsController.get_owner_files(applicationId, nodes.Select(u => u.NodeID.Value).ToList()); foreach (Node nd in nodes) { NodeInfo inf = nodeInfo.Where(u => u.NodeID == nd.NodeID).FirstOrDefault(); string newNodeUrl = baseUrl + "/Ajax/ManageNodes.ashx" + "?timeStamp=" + DateTime.Now.Ticks.ToString() + "&Command=RegisterNewNode"; vals.Clear(); vals.Add("Ticket", ticket); vals.Add("acstkn", accessToken); vals.Add("CurrentUserID", nd.Creator.UserID.ToString()); vals.Add("CreationDate", nd.CreationDate.Value.Year.ToString() + "-" + nd.CreationDate.Value.Month.ToString() + "-" + nd.CreationDate.Value.Day.ToString()); vals.Add("NodeID", nd.NodeID.ToString()); vals.Add("NodeTypeID", nd.NodeTypeID.ToString()); vals.Add("Name", Base64.encode(nd.Name)); if (inf != null && !string.IsNullOrEmpty(inf.Description)) { vals.Add("Description", Base64.encode(inf.Description)); } if (inf != null && inf.Tags.Count > 0) { vals.Add("Tags", string.Join("|", inf.Tags.Select(u => Base64.encode(u)))); } res = PublicMethods.web_request(newNodeUrl, vals); jsonRes = PublicMethods.fromJSON(res); if (jsonRes.ContainsKey("AccessToken")) { accessToken = (string)jsonRes["AccessToken"]; } foreach (DocFileInfo f in attachments.Where(u => u.OwnerID == nd.NodeID)) { string fileUploadUrl = baseUrl + "/Ajax/FileUpload.ashx" + "?timeStamp=" + DateTime.Now.Ticks.ToString() + "&command=uploadfile" + "&Ticket=" + ticket + "&acstkn=" + accessToken + "&FileID=" + f.FileID.ToString() + "&OwnerID=" + nd.NodeID.ToString() + "&OwnerType=" + f.OwnerType.ToString() + "&aa=2"; FileOwnerTypes attachmentType = f.OwnerType == FileOwnerTypes.WikiContent.ToString() ? FileOwnerTypes.WikiContent : FileOwnerTypes.Node; FolderNames folderName = DocumentUtilities.get_folder_name(attachmentType); string subFolder = !DocumentUtilities.has_sub_folder(folderName) ? string.Empty : "\\" + DocumentUtilities.get_sub_folder(f.FileID.ToString()); string fileAddress = DocumentUtilities.map_path(applicationId, folderName) + subFolder + "\\" + f.FileName + (string.IsNullOrEmpty(f.Extension) ? string.Empty : "." + f.Extension); res = PublicMethods.upload_file(applicationId, fileUploadUrl, fileAddress); jsonRes = PublicMethods.fromJSON(res); if (jsonRes.ContainsKey("AccessToken")) { accessToken = (string)jsonRes["AccessToken"]; } } CNController.remove_node(applicationId, nd.NodeID.Value, false, nd.Creator.UserID.Value); } }
public void ProcessRequest(HttpContext context) { paramsContainer = new ParamsContainer(context, nullTenantResponse: false); if (!paramsContainer.CurrentUserID.HasValue) { paramsContainer.return_response(PublicConsts.BadRequestResponse); return; } if (ProcessTenantIndependentRequest(context)) { return; } if (!paramsContainer.ApplicationID.HasValue) { paramsContainer.return_response(PublicConsts.NullTenantResponse); return; } string responseText = string.Empty; string command = !string.IsNullOrEmpty(context.Request.Params["cmd"]) ? context.Request.Params["cmd"].ToLower() : (string.IsNullOrEmpty(context.Request.Params["Command"]) ? "uploadfile" : context.Request.Params["Command"].ToLower()); Guid userId = string.IsNullOrEmpty(context.Request.Params["UserID"]) ? PublicMethods.get_current_user_id() : Guid.Parse(context.Request.Params["UserID"]); Guid ownerId = string.IsNullOrEmpty(context.Request.Params["OwnerID"]) ? Guid.Empty : Guid.Parse(context.Request.Params["OwnerID"]); Guid fileId = string.IsNullOrEmpty(context.Request.Params["FileID"]) ? Guid.Empty : Guid.Parse(context.Request.Params["FileID"]); string fileName = string.IsNullOrEmpty(context.Request.Params["FileName"]) ? string.Empty : context.Request.Params["FileName"]; FileOwnerTypes ownerType = FileOwnerTypes.None; if (!Enum.TryParse <FileOwnerTypes>(context.Request.Params["OwnerType"], out ownerType)) { ownerType = FileOwnerTypes.None; } switch (command) { case "uploadfile": case "upload_file": { DocFileInfo file = new DocFileInfo() { FileID = fileId != Guid.Empty ? fileId : Guid.NewGuid(), OwnerID = ownerId, OwnerType = ownerType }; byte[] fileContent = new byte[0]; _attach_file_command(paramsContainer.ApplicationID, file, ref responseText, ref fileContent); _return_response(ref responseText); return; } case "deletefile": responseText = remove_file(fileId, ref responseText) ? "yes" : "no"; _return_response(ref responseText); return; case "removefile": remove_file(fileId, ref responseText); _return_response(ref responseText); return; case "uploadpicture": { int maxWidth = 100, maxHeight = 100; FolderNames imageFolder = FolderNames.Pictures; Guid?pictureId = PublicMethods.parse_guid(context.Request.Params["PictureID"]); bool hasId = pictureId.HasValue; if (!pictureId.HasValue) { pictureId = Guid.NewGuid(); } string imageType = string.IsNullOrEmpty(context.Request.Params["Type"]) ? "" : context.Request.Params["Type"].ToLower(); string errorMessage = string.Empty; switch (imageType) { case "post": maxWidth = maxHeight = 640; imageFolder = FolderNames.Pictures; break; default: _return_response(ref responseText); return; } DocFileInfo uploaded = new DocFileInfo() { FileID = Guid.NewGuid(), OwnerType = ownerType, FolderName = FolderNames.TemporaryFiles }; if (ownerId != Guid.Empty) { uploaded.OwnerID = ownerId; } byte[] fileContent = new byte[0]; bool succeed = _attach_file_command(paramsContainer.ApplicationID, uploaded, ref responseText, ref fileContent, dontStore: true); if (succeed) { DocFileInfo destFile = new DocFileInfo() { FileID = hasId ? pictureId : uploaded.FileID, OwnerType = ownerType, Extension = "jpg", FolderName = hasId ? imageFolder : FolderNames.TemporaryFiles }; if (ownerId != Guid.Empty) { destFile.OwnerID = ownerId; } byte[] destContent = new byte[0]; RVGraphics.make_thumbnail(paramsContainer.Tenant.Id, fileContent, destFile, ref destContent, maxWidth, maxHeight, 0, 0, ref errorMessage, "jpg"); if (string.IsNullOrEmpty(errorMessage)) { responseText = responseText.Replace(uploaded.FileID.ToString(), destFile.FileID.ToString()); } } responseText = responseText.Replace("\"~[[MSG]]\"", string.IsNullOrEmpty(errorMessage) ? "\"\"" : errorMessage); _return_response(ref responseText); return; } } paramsContainer.return_response(PublicConsts.BadRequestResponse); }
public bool ProcessTenantIndependentRequest(HttpContext context) { if (!RaaiVanSettings.SAASBasedMultiTenancy && !paramsContainer.ApplicationID.HasValue) { paramsContainer.return_response(PublicConsts.NullTenantResponse); return(true); } string responseText = string.Empty; string command = !string.IsNullOrEmpty(context.Request.Params["cmd"]) ? context.Request.Params["cmd"].ToLower() : (string.IsNullOrEmpty(context.Request.Params["Command"]) ? "uploadfile" : context.Request.Params["Command"].ToLower()); Guid userId = string.IsNullOrEmpty(context.Request.Params["UserID"]) ? PublicMethods.get_current_user_id() : Guid.Parse(context.Request.Params["UserID"]); Guid ownerId = string.IsNullOrEmpty(context.Request.Params["OwnerID"]) ? Guid.Empty : Guid.Parse(context.Request.Params["OwnerID"]); FileOwnerTypes ownerType = FileOwnerTypes.None; if (!Enum.TryParse <FileOwnerTypes>(context.Request.Params["OwnerType"], out ownerType)) { ownerType = FileOwnerTypes.None; } Guid?applicationId = paramsContainer.ApplicationID; switch (command) { case "uploadicon": { Guid iconId = string.IsNullOrEmpty(context.Request.Params["IconID"]) ? Guid.Empty : Guid.Parse(context.Request.Params["IconID"]); IconType iconType = IconType.None; if (!Enum.TryParse <IconType>(context.Request.Params["Type"], true, out iconType)) { iconType = IconType.None; } if (iconType == IconType.ApplicationIcon || (RaaiVanSettings.SAASBasedMultiTenancy && (iconType == IconType.ProfileImage || iconType == IconType.CoverPhoto))) { applicationId = null; } else if (!applicationId.HasValue) { responseText = PublicConsts.NullTenantResponse; break; } DocFileInfo uploaded = new DocFileInfo() { FileID = iconId, OwnerID = ownerId, OwnerType = ownerType, FolderName = FolderNames.TemporaryFiles }; byte[] fileContent = new byte[0]; bool succeed = _attach_file_command(applicationId, uploaded, ref responseText, ref fileContent, dontStore: true); if (!succeed || fileContent == null || fileContent.Length == 0) { break; } if (iconType == IconType.ProfileImage && iconId == Guid.Empty) { iconId = userId; } string errorMessage = string.Empty; IconMeta meta = null; succeed = RVGraphics.create_icon(applicationId, iconId, iconType, fileContent, ref errorMessage, ref meta); if (succeed && meta != null) { responseText = responseText.Replace("\"~[[MSG]]\"", meta.toJson(applicationId)); } else { responseText = responseText.Replace("\"~[[MSG]]\"", errorMessage); } try { string tempRes = string.Empty; if (succeed) { remove_file(uploaded, ref tempRes); } } catch { } break; } case "deleteicon": { Guid iconId = string.IsNullOrEmpty(context.Request.Params["IconID"]) ? Guid.Empty : Guid.Parse(context.Request.Params["IconID"]); IconType iconType = IconType.None; if (!Enum.TryParse <IconType>(context.Request.Params["Type"], true, out iconType)) { iconType = IconType.None; } if (iconType == IconType.ApplicationIcon || (RaaiVanSettings.SAASBasedMultiTenancy && (iconType == IconType.ProfileImage || iconType == IconType.CoverPhoto))) { applicationId = null; } else if (!applicationId.HasValue) { responseText = PublicConsts.NullTenantResponse; break; } if (iconType == IconType.ProfileImage && iconId == Guid.Empty) { iconId = userId; } FolderNames folderName = FolderNames.ProfileImages; FolderNames highQualityFolderName = FolderNames.HighQualityProfileImage; string defaultIconUrl = string.Empty; bool isValid = DocumentUtilities.get_icon_parameters(applicationId, iconType, ref folderName, ref highQualityFolderName, ref defaultIconUrl); if (!isValid) { responseText = PublicConsts.NullTenantResponse; break; } new DocFileInfo() { FileID = iconId, Extension = "jpg", OwnerID = ownerId, OwnerType = ownerType, FolderName = folderName }.delete(paramsContainer.ApplicationID); new DocFileInfo() { FileID = iconId, Extension = "jpg", OwnerID = ownerId, OwnerType = ownerType, FolderName = highQualityFolderName }.delete(paramsContainer.ApplicationID); responseText = "{\"Succeed\":\"" + Messages.OperationCompletedSuccessfully + "\"" + ",\"DefaultIconURL\":\"" + defaultIconUrl + "\"}"; break; } case "cropicon": { Guid iconId = string.IsNullOrEmpty(context.Request.Params["IconID"]) ? Guid.Empty : Guid.Parse(context.Request.Params["IconID"]); IconType iconType = IconType.None; if (!Enum.TryParse <IconType>(context.Request.Params["Type"], true, out iconType)) { iconType = IconType.None; } if (iconType == IconType.ApplicationIcon || (RaaiVanSettings.SAASBasedMultiTenancy && (iconType == IconType.ProfileImage || iconType == IconType.CoverPhoto))) { applicationId = null; } else if (!applicationId.HasValue) { responseText = PublicConsts.NullTenantResponse; break; } int iconWidth = 100, iconHeight = 100; FolderNames imageFolder = FolderNames.ProfileImages, highQualityImageFolder = FolderNames.HighQualityProfileImage; if (iconType == IconType.ProfileImage && iconId == Guid.Empty) { iconId = userId; } bool isValid = DocumentUtilities.get_icon_parameters(applicationId, iconType, ref iconWidth, ref iconHeight, ref imageFolder, ref highQualityImageFolder); if (!isValid) { break; } DocFileInfo highQualityFile = new DocFileInfo() { FileID = iconId, Extension = "jpg", FolderName = highQualityImageFolder }; DocFileInfo file = new DocFileInfo() { FileID = iconId, Extension = "jpg", FolderName = imageFolder }; int x = string.IsNullOrEmpty(context.Request.Params["X"]) ? -1 : int.Parse(context.Request.Params["X"]); int y = string.IsNullOrEmpty(context.Request.Params["Y"]) ? -1 : int.Parse(context.Request.Params["Y"]); int width = string.IsNullOrEmpty(context.Request.Params["Width"]) ? -1 : (int)double.Parse(context.Request.Params["Width"]); int height = string.IsNullOrEmpty(context.Request.Params["Height"]) ? -1 : (int)double.Parse(context.Request.Params["Height"]); IconMeta meta = null; RVGraphics.extract_thumbnail(applicationId, highQualityFile, highQualityFile.toByteArray(applicationId), file, x, y, width, height, iconWidth, iconHeight, ref responseText, ref meta); break; } } if (!string.IsNullOrEmpty(responseText)) { paramsContainer.return_response(ref responseText); } return(!string.IsNullOrEmpty(responseText)); }
public static void GetOwnerFiles(Guid applicationId, ref List <DocFileInfo> retFiles, ref List <Guid> ownerIds, FileOwnerTypes ownerType) { string spName = GetFullyQualifiedName("GetOwnerFiles"); try { if (ownerIds.Count == 0) { return; } string strOwnerType = null; if (ownerType != FileOwnerTypes.None) { strOwnerType = ownerType.ToString(); } IDataReader reader = ProviderUtil.execute_reader(spName, applicationId, ProviderUtil.list_to_string <Guid>(ref ownerIds), ',', strOwnerType); _parse_files(applicationId, ref reader, ref retFiles); } catch (Exception ex) { LogController.save_error_log(applicationId, null, spName, ex, ModuleIdentifier.DCT); } }