public void GetandSetFileNameTest() { FileNode file0 = new FileNode("", fileID, modifiedTime, createdTime, executeTime, extension, filePath); FileNode file = new FileNode(fileName, fileID, modifiedTime, createdTime, executeTime, extension, filePath); //test get empty string String actualfileName0 = file0.GetFileName(); Assert.AreEqual("", actualfileName0, "Actual file name is not an empty string"); //test get non-empty string String actualfileName1 = file.GetFileName(); Assert.AreEqual("test.txt", actualfileName1, "Actual file name does not equal to text.txt"); //test set empty string file.SetFileName(""); String actualfileName2 = file.GetFileName(); Assert.AreEqual("", actualfileName2, "Set empty string file name was not successful"); //test set non-empty string file.SetFileName("exam.pdf"); String actualfileName3 = file.GetFileName(); Assert.AreEqual("exam.pdf", actualfileName3, "Set non-empty string file name was not successful"); }
public Conflict(Collection col, Node node) { iFolderID = col.ID; ConflictID = node.ID; Simias.Sync.Conflict conflict = new Simias.Sync.Conflict(col, node); if(conflict.IsFileNameConflict) { IsNameConflict = true; FileNode fileNode = node as FileNode; if (fileNode != null) { string name = Path.GetFileName(conflict.NonconflictedPath); if (name.Equals(Path.GetFileName(conflict.FileNameConflictPath))) { LocalName = name; LocalDate = fileNode.LastWriteTime.ToString(); LocalSize = formatFileSize(fileNode.Length); LocalFullPath = conflict.FileNameConflictPath; } else { ServerName = name; ServerDate = fileNode.LastWriteTime.ToString(); ServerSize = formatFileSize(fileNode.Length); ServerFullPath = conflict.NonconflictedPath; } } else { DirNode dn = node as DirNode; if (dn != null) { if (dn.Name.Equals(Path.GetFileName(conflict.FileNameConflictPath))) { LocalName = dn.Name; LocalDate = null; LocalSize = null; LocalFullPath = conflict.FileNameConflictPath; } else { ServerName = dn.Name; ServerDate = null; ServerSize = null; ServerFullPath = conflict.NonconflictedPath; } } } } else { IsNameConflict = false; FileNode localFileNode = new FileNode(node); Node serverNode = col.GetNodeFromCollision(node); FileNode serverFileNode = new FileNode(serverNode); LocalName = localFileNode.GetFileName(); LocalDate = localFileNode.LastWriteTime.ToString(); LocalSize = formatFileSize(localFileNode.Length); LocalFullPath = conflict.NonconflictedPath; ServerName = serverFileNode.GetFileName(); ServerDate = serverFileNode.LastWriteTime.ToString(); ServerSize = formatFileSize(serverFileNode.Length); ServerFullPath = conflict.UpdateConflictPath; } }
/// <summary> /// process and send the reply for request /// </summary> /// <param name="Context">httpcontext object</param> public void Send(HttpContext Context) { ctx = Context; ctx.Response.Write("<item>"); FileNode fileNode = null; ctx.Response.Write("<title>"); if (node.IsType("Member") == true) { Member collectionMember = new Member(node); ctx.Response.Write(" - " + collectionMember.FN); } else if (node.IsType("FileNode") == true) { fileNode = new FileNode(node); ctx.Response.Write(fileNode.GetFileName()); } else { ctx.Response.Write(node.Name); } ctx.Response.Write("</title>"); ctx.Response.Write("<guid isPermaLink=\"false\">" + node.ID + "</guid>"); Simias.RssFeed.Util.SendPublishDate(ctx, published); if (node.IsType("Member") == true) { Member collectionMember = new Member(node); ctx.Response.Write("<description>"); ctx.Response.Write(" - " + collectionMember.FN); ctx.Response.Write("</description>"); ctx.Response.Write("<type>Member</type>"); } else if (node.IsType("FileNode") == true) { fileNode = new FileNode(node); ctx.Response.Write("<description>"); ctx.Response.Write(fileNode.GetRelativePath()); ctx.Response.Write("</description>"); /* * ctx.Response.Write( * String.Format( * "<link>{0}{1}:{2}{3}/sfile.ashx?fid={4}{5}</link>", * ctx.Request.IsSecureConnection ? "https://" : "http://", * ctx.Request.Url.Host, * ctx.Request.Url.Port.ToString(), * ctx.Request.ApplicationPath, * fileNode.ID, * HttpUtility.UrlEncode( "&name=" + fileNode.Name ) ) ); */ ctx.Response.Write( String.Format( "<link>{0}{1}:{2}{3}{4}?fid={5}</link>", ctx.Request.IsSecureConnection ? "https://" : "http://", ctx.Request.Url.Host, ctx.Request.Url.Port.ToString(), ctx.Request.ApplicationPath, (publicAccess == true) ? "/pubsfile.ashx" : "/sfile.ashx", fileNode.ID)); if (enclosures == true) { ctx.Response.Write( String.Format( "<enclosure url=\"{0}{1}:{2}{3}{4}?fid={5}\" length=\"{6}\" type=\"{7}\"/>", ctx.Request.IsSecureConnection ? "https://" : "http://", ctx.Request.Url.Host, ctx.Request.Url.Port.ToString(), ctx.Request.ApplicationPath, (publicAccess == true) ? "/pubsfile.ashx" : "/sfile.ashx", node.ID, fileNode.Length, Simias.HttpFile.Response.GetMimeType(fileNode.GetFileName()))); } } else if (node.IsType("DirNode") == true) { DirNode dirNode = new DirNode(node); ctx.Response.Write("<description>"); ctx.Response.Write(dirNode.GetRelativePath()); ctx.Response.Write("</description>"); } Domain domain = store.GetDomain(store.DefaultDomain); Member member = domain.GetMemberByID(node.Creator); if (member != null) { ctx.Response.Write("<author>"); if (member.FN != null && member.FN != "") { ctx.Response.Write(member.FN); } else { ctx.Response.Write(member.Name); } ctx.Response.Write("</author>"); } if (strict == false) { ctx.Response.Write("<authorID>" + member.UserID + "</authorID>"); ctx.Response.Write("<type>" + node.Type.ToString() + "</type>"); ctx.Response.Write("<id>" + node.ID + "</id>"); } // Category - use tags and types /* * if (slog.Generator != "") * { * ctx.Response.Write("<generator>"); * ctx.Response.Write(slog.Generator); * ctx.Response.Write("</generator>"); * } * * if (slog.Cloud != "") * { * ctx.Response.Write("<cloud>"); * ctx.Response.Write(slog.Cloud); * ctx.Response.Write("</cloud>"); * } */ ctx.Response.Write("</item>"); }
/// <summary> /// process the http request /// </summary> /// <param name="context">http context</param> public void ProcessRequest(HttpContext context) { HttpRequest request = context.Request; HttpResponse response = context.Response; response.StatusCode = (int)HttpStatusCode.BadRequest; try { // Make sure that there is a session. if (context.Session != null) { //HttpService service = Session[ serviceTag ]; response.Cache.SetCacheability(HttpCacheability.NoCache); string method = request.HttpMethod.ToLower(); log.Debug("Simias.HttpFile.Handler.ProcessRequest called"); log.Debug(" method: " + method); //SyncMethod method = (SyncMethod)Enum.Parse(typeof(SyncMethod), Request.Headers.Get(SyncHeaders.Method), true); if (method == "get") { // Must a query string which contains the domainid and the // filenodeid for the file caller is attempting to download. if (request.QueryString.Count > 0) { Collection collection; Domain domain; FileNode fileNode; Node node; Store store = Store.GetStore(); string domainID = request.QueryString["did"]; if (domainID == null) { domainID = store.DefaultDomain; } string fileID = request.QueryString["fid"]; if (fileID != null) { log.Debug(" domainID: " + domainID); log.Debug(" fileID: " + fileID); domain = Store.GetStore().GetDomain(domainID); node = domain.GetNodeByID(fileID); if (node != null) { Property cid = node.Properties.GetSingleProperty("CollectionId"); collection = store.GetCollectionByID(cid.Value as string); fileNode = new FileNode(node); string fullPath = fileNode.GetFullPath(collection); string fileName = fileNode.GetFileName(); log.Debug(" nodename: " + fileNode.Name); log.Debug(" filename: " + fileName); log.Debug(" fullpath: " + fullPath); response.StatusCode = (int)HttpStatusCode.OK; Property lastModified = node.Properties.GetSingleProperty("LastModified"); if (lastModified != null) { DateTime dt = (DateTime)lastModified.Value; response.AddHeader( "Last-Modified", Util.GetRfc822Date((DateTime)lastModified.Value)); } response.AddHeader( "Content-length", fileNode.Length.ToString()); response.ContentType = Simias.HttpFile.Response.GetMimeType(fileName).ToLower(); if (response.ContentType.Equals("text/plain")) { response.AddHeader( "Content-Disposition", "inline; filename=\"" + fileName + "\""); } else if (response.ContentType.Equals("text/xml")) { response.AddHeader( "Content-Disposition", "inline; filename=\"" + fileName + "\""); } else if (response.ContentType.StartsWith("image")) { response.AddHeader( "Content-Disposition", "inline; filename=\"" + fileName + "\""); } else { response.AddHeader( "Content-Disposition", "attachment; filename=\"" + fileName + "\""); } response.TransmitFile(fullPath); /* * response. * FileStream stream = * File.Open( * fullPath, * System.IO.FileMode.Open, * System.IO.FileAccess.Read, * System.IO.FileShare.Read ); */ } } } } } } catch (Exception ex) { log.Error(ex.Message); log.Error(ex.StackTrace); response.StatusCode = (int)HttpStatusCode.InternalServerError; } finally { response.End(); } }
/// <summary> /// Constructs a Conflict object. /// </summary> /// <param name="col">The collection containing the conflict.</param> /// <param name="node">The conflicting node.</param> public Conflict(Collection col, Node node) { iFolderID = col.ID; ConflictID = node.ID; Simias.Sync.Conflict conflict = new Simias.Sync.Conflict(col, node); if (conflict.IsFileNameConflict) { IsNameConflict = true; FileNode fileNode = node as FileNode; if (fileNode != null) { string name = Path.GetFileName(conflict.NonconflictedPath); if (name.Equals(Path.GetFileName(conflict.FileNameConflictPath))) { LocalName = name; LocalDate = fileNode.LastWriteTime.ToString(); LocalSize = formatFileSize(fileNode.Length); LocalFullPath = conflict.FileNameConflictPath; } else { ServerName = name; ServerDate = fileNode.LastWriteTime.ToString(); ServerSize = formatFileSize(fileNode.Length); ServerFullPath = conflict.NonconflictedPath; } } else { DirNode dn = node as DirNode; if (dn != null) { if (dn.Name.Equals(Path.GetFileName(conflict.FileNameConflictPath))) { LocalName = dn.Name; LocalDate = null; LocalSize = null; LocalFullPath = conflict.FileNameConflictPath; } else { ServerName = dn.Name; ServerDate = null; ServerSize = null; ServerFullPath = conflict.NonconflictedPath; } } } } else { IsNameConflict = false; FileNode localFileNode = new FileNode(node); Node serverNode = col.GetNodeFromCollision(node); FileNode serverFileNode = new FileNode(serverNode); LocalName = localFileNode.GetFileName(); LocalDate = localFileNode.LastWriteTime.ToString(); LocalSize = formatFileSize(localFileNode.Length); LocalFullPath = conflict.NonconflictedPath; ServerName = serverFileNode.GetFileName(); ServerDate = serverFileNode.LastWriteTime.ToString(); ServerSize = formatFileSize(serverFileNode.Length); ServerFullPath = conflict.UpdateConflictPath; } }
/// <summary> /// Initialize the Request /// </summary> /// <param name="context">The HttpContext object.</param> protected void Initialize(HttpContext context) { // query ifolderID = context.Request.QueryString["iFolder"]; entryID = context.Request.QueryString["Entry"]; entryPath = context.Request.QueryString["Path"]; string ppath = entryPath; string [] ConversionTable = { "&", "amp@:quot" }; if (ppath != null) { for (int index = 0; index < ConversionTable.Length; index += 2) { ppath = ppath.Replace(ConversionTable[index + 1], ConversionTable[index]); } } entryPath = ppath; // authentication accessID = context.User.Identity.Name; if ((accessID == null) || (accessID.Length == 0)) { throw new AuthenticationException(); } // store store = Store.GetStore(); // collection collection = store.GetCollectionByID(ifolderID); if (collection == null) { throw new iFolderDoesNotExistException(ifolderID); } // member member = collection.GetMemberByID(accessID); // does member exist? if (member == null && Simias.Service.Manager.LdapServiceEnabled == true) { Domain domain = store.GetDomain(store.DefaultDomain); string[] IDs = domain.GetMemberFamilyList(accessID); foreach (string id in IDs) { member = collection.GetMemberByID(id); if (member != null) { break; } } } if (member == null) { throw new MemberDoesNotExistException(accessID); } // impersonate iFolder.Impersonate(collection, accessID); // log log = new SimiasAccessLogger(member.Name, collection.ID); // node Node n = null; // use the path if ((entryPath != null) && (entryPath.Length != 0)) { n = iFolderEntry.GetEntryByPath(collection, entryPath); } // use the id if ((entryID != null) && (entryID.Length != 0)) { n = collection.GetNodeByID(entryID); } // check node if (n != null) { // is the node a file if (!n.IsBaseType(NodeTypes.FileNodeType)) { throw new FileDoesNotExistException(entryID); } // file node = (FileNode)n; filename = node.GetFileName(); filePath = node.GetFullPath(collection); } }