public static int Add(FoldersDS.FoldersRow dr, string SQLConnectionName) { try { SqlConnection SQLConn = new SqlConnection(getConnstring(SQLConnectionName)); SqlCommand iSqlCommand = GenerateSqlCommandfromDataRow(dr, SP_Add); iSqlCommand.Connection = SQLConn; //Set the ID column as output as the GenerateSQLCommand would not have done this. iSqlCommand.Parameters["@ID"].Direction = ParameterDirection.InputOutput; iSqlCommand.UpdatedRowSource = UpdateRowSource.OutputParameters; SQLConn.Open(); iSqlCommand.ExecuteNonQuery(); int newID = (int)iSqlCommand.Parameters["@ID"].Value; iSqlCommand.Dispose(); SQLConn.Close(); return newID; } catch { return -1; } }
public int Handle() { if (_httpApplication==null) return (int)ServerResponseCode.BadRequest; this._requestPath = WebDavHelper.getRelativePath(this._httpApplication, this._httpApplication.Request.FilePath); //Check to see if the RequestPath is already a resource if (WebDavHelper.ValidResourceByPath(this._requestPath)) return (int)DavMKColResponseCode.MethodNotAllowed; else { //Check to see if the we can create a new folder FoldersDS.FoldersRow _dirInfo = WebDavHelper.getParentFolder(this._requestPath); //The parent folder does not exist if (_dirInfo == null) return (int)DavMKColResponseCode.Conflict; else { string _requestedFolder = WebDavHelper.getResourceName(this._requestPath); try { FoldersDS fds = new FoldersDS(); FoldersDS.FoldersRow fdr = fds.Folders.NewFoldersRow(); fdr.ParentID = _dirInfo.ID; fdr.FolderName = _requestedFolder; fdr.update_user_stamp = HttpContext.Current.User.Identity.Name; if ((FolderBLC.SaveFolder(fdr) == -1)){ return (int)DavMKColResponseCode.InsufficientStorage; } } catch (Exception) { return (int)DavMKColResponseCode.InsufficientStorage; } } } return (int)DavMKColResponseCode.Created; }
/// <summary> /// Generates the D:Response for a given backend Folder Row /// <param name="_fdr">A FolderDS.FolderRow of a file record in the Files Table</param> /// <param name="xmlWriter">The xmlWriter to add the xml to</param> /// <param name="ReqProps">The list of request properties in the PROPFIND request if any</param> /// <param name="isPropOnly">If this is a PROPFIND request for properties only. If true then ReqProps must be null</param> /// </summary> public static void GetXML(FoldersDS.FoldersRow _fdr, XmlTextWriter xmlWriter, RequestedPropertyCollection ReqProps, PropertyRequestType RequestType) { //Load the Valid Properties for the file resource ArrayList ValidProps = new ArrayList(); ValidProps.Add("contentlanguage"); ValidProps.Add("contentlength"); ValidProps.Add("contenttype"); ValidProps.Add("creationdate"); ValidProps.Add("displayname"); ValidProps.Add("filepath"); ValidProps.Add("ishidden"); ValidProps.Add("lastaccessed"); ValidProps.Add("lastmodified"); ValidProps.Add("resourcetype"); ValidProps.Add("supportedlock"); RequestedPropertyCollection InValidProps = new RequestedPropertyCollection(); if (RequestType == PropertyRequestType.PropertyNames && ReqProps != null) return; if (_fdr == null) return; //Open the response element xmlWriter.WriteStartElement("response", "DAV:"); //Load the valid items HTTP/1.1 200 OK xmlWriter.WriteElementString("href", "DAV:", _fdr.FolderName); //Open the propstat element section xmlWriter.WriteStartElement("propstat", "DAV:"); xmlWriter.WriteElementString("status", "DAV:", WebDavHelper.getEnumHttpResponse(ServerResponseCode.Ok)); //Open the prop element section xmlWriter.WriteStartElement("prop", "DAV:"); //If there are no requested Properties then return all props for File. if (ReqProps == null) { ReqProps = new RequestedPropertyCollection(); for (int _vPe = 0; _vPe < ValidProps.Count; _vPe++) { ReqProps.Add(new RequestedProperty((string)ValidProps[_vPe], "DAV:")); } } foreach (RequestedProperty _ReqProp in ReqProps) { string _propertyName = _ReqProp.LocalName; if (_propertyName.ToLower(CultureInfo.InvariantCulture).StartsWith("get")) _propertyName = _propertyName.Substring(3); if ((_ReqProp.NS != "DAV:") || (ValidProps.IndexOf(_propertyName.ToLower()) == -1)) { InValidProps.Add(_ReqProp); } else { if (RequestType == PropertyRequestType.PropertyNames) { //if this is a request for property names only then just return the named elements: xmlWriter.WriteElementString(_propertyName, _ReqProp.NS, ""); } else { //Map the property to the Row Data and return the PropStat XML. switch (_propertyName.ToLower()) { case "contentlanguage": xmlWriter.WriteElementString(_ReqProp.LocalName, "DAV:", "en-us"); break; case "contentlength": //To do, calculate Contenlength xmlWriter.WriteElementString(_ReqProp.LocalName, "DAV:", "0"); break; case "contenttype": xmlWriter.WriteElementString(_ReqProp.LocalName, "DAV:", "application/webdav-collection"); break; case "displayname": xmlWriter.WriteElementString(_ReqProp.LocalName, "DAV:", _fdr.FolderName); break; case "filepath": xmlWriter.WriteElementString(_ReqProp.LocalName, "DAV:", _fdr.FolderName); break; case "ishidden": //May adjust later to allow hidden files xmlWriter.WriteElementString(_ReqProp.LocalName, "DAV:", "0"); break; case "resourcetype": //May adjust later to allow hidden files xmlWriter.WriteStartElement(_ReqProp.LocalName, "DAV:"); xmlWriter.WriteElementString("collection", "DAV:", ""); xmlWriter.WriteEndElement(); break; case "lastaccessed": xmlWriter.WriteStartElement(_ReqProp.LocalName, "DAV:"); xmlWriter.WriteAttributeString("b:dt", "dateTime.rfc1123"); //This change is outside the spec for MS. If you set this date is set to the rfc1123 compliant dateformat //the Windows Explorer errors out. // xmlWriter.WriteString(_fdr.update_date_stamp.ToUniversalTime().ToString("r", CultureInfo.InvariantCulture)); xmlWriter.WriteString(_fdr.update_date_stamp.ToUniversalTime().ToString("dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture)); xmlWriter.WriteEndElement(); break; case "lastmodified": xmlWriter.WriteStartElement(_ReqProp.LocalName, "DAV:"); xmlWriter.WriteAttributeString("b:dt", "dateTime.rfc1123"); xmlWriter.WriteString(_fdr.update_date_stamp.ToUniversalTime().ToString("r", CultureInfo.InvariantCulture)); xmlWriter.WriteEndElement(); break; case "creationdate": xmlWriter.WriteStartElement(_ReqProp.LocalName, "DAV:"); xmlWriter.WriteAttributeString("b:dt", "dateTime.tz"); xmlWriter.WriteString(_fdr.create_date_stamp.ToUniversalTime().ToString("s", CultureInfo.InvariantCulture)); xmlWriter.WriteEndElement(); break; case "supportedlock": xmlWriter.WriteStartElement("D", _ReqProp.LocalName, "DAV:"); xmlWriter.WriteStartElement("lockentry", "DAV:"); xmlWriter.WriteStartElement("lockscope", "DAV:"); xmlWriter.WriteElementString("exclusive", "DAV:", ""); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("locktype", "DAV:"); xmlWriter.WriteElementString("write", "DAV:", ""); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("lockentry", "DAV:"); xmlWriter.WriteStartElement("lockscope", "DAV:"); xmlWriter.WriteElementString("shared", "DAV:", ""); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("locktype", "DAV:"); xmlWriter.WriteElementString("write", "DAV:", ""); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); break; default: break; } } } } //Close the prop element section xmlWriter.WriteEndElement(); //Close the propstat element section xmlWriter.WriteEndElement(); //END Load the valid items HTTP/1.1 200 OK //Load the invalid items HTTP/1.1 404 Not Found if (InValidProps.Count > 0) { xmlWriter.WriteStartElement("propstat", "DAV:"); xmlWriter.WriteElementString("status", "DAV:", WebDavHelper.getEnumHttpResponse(ServerResponseCode.NotFound)); //Open the prop element section xmlWriter.WriteStartElement("prop", "DAV:"); //Load all the invalid properties foreach (RequestedProperty _InValidProp in InValidProps) xmlWriter.WriteElementString(_InValidProp.LocalName, _InValidProp.NS, ""); //Close the prop element section xmlWriter.WriteEndElement(); //Close the propstat element section xmlWriter.WriteEndElement(); } //END Load the invalid items HTTP/1.1 404 Not Found //Close the response element xmlWriter.WriteEndElement(); }
// <summary> /// Saves a Folder /// </summary> /// <param name="rdr">The folder row to save</param> /// <returns></returns> public static int SaveFolder(FoldersDS.FoldersRow rdr) { return FolderBLC.SaveFolder(rdr); }
private void DelFolder(FoldersDS.FoldersRow _sourceDirectory,int oSourceID) { if (_sourceDirectory != null) { //Check that the directory we are about to delete and transverse is not in fact the //orginal source of the move. This can occur if the source folder already lies under the destination //and a folder of the same name exists in the destination folder. if (_sourceDirectory.ID != oSourceID) { try { //Move over the directory files Search_FilesDS _filelist = WebDavHelper.getFolderFiles(_sourceDirectory.ID); foreach (Search_FilesDS.FilesRow sfr in _filelist.Files) WebDavHelper.RemoveFile(sfr.ID); FoldersDS _dirlist = WebDavHelper.getSubFolders(_sourceDirectory.ID); foreach (FoldersDS.FoldersRow _dir in _dirlist.Folders) { DelFolder(_dir,oSourceID); if (oSourceID!=_dir.ID) WebDavHelper.RemoveFolder(_dir.ID); } } catch (Exception) { //To do exception on delete handling } } } }
private void CheckforDestinationLocks(FoldersDS.FoldersRow _sourceDirectory, string destination) { //loop through the destination and determine if there are any filelocks // if they exist then add the error to the errorlist if (_sourceDirectory != null) { try { FoldersDS.FoldersRow _destFolder = WebDavHelper.getFolder(destination); if (_destFolder == null) return; Search_FilesDS _filelist = WebDavHelper.getFolderFiles(_sourceDirectory.ID); foreach (Search_FilesDS.FilesRow sfr in _filelist.Files) { Search_FilesDS.FilesRow destfile = WebDavHelper.getFileAttribsOnly(destination + "/" + sfr.FileName); if (destfile != null) { if (WebDavHelper.getLock(destfile.ID) != null) { this._Errors.Add(new ProcessingError(sfr.FileName, WebDavHelper.getEnumHttpResponse(DavMoveResponseCode.Locked))); //We already have an error so leave now return; } } } FoldersDS _dirlist = WebDavHelper.getSubFolders(_sourceDirectory.ID); foreach (FoldersDS.FoldersRow _dir in _dirlist.Folders) CheckforDestinationLocks(_dir, destination + "/" + _dir.FolderName); } catch (Exception) { this._Errors.Add(new ProcessingError(_sourceDirectory.FolderName, WebDavHelper.getEnumHttpResponse(DavMoveResponseCode.Forbidden))); } } }
private void CreateDirectory(string path) { FoldersDS fds = new FoldersDS(); FoldersDS.FoldersRow fdr; FoldersDS.FoldersRow pdr; try { pdr = WebDavHelper.getParentFolder(path); fdr = fds.Folders.NewFoldersRow(); fdr.ParentID = pdr.ID; fdr.FolderName = WebDavHelper.getResourceName(path); fdr.update_user_stamp = HttpContext.Current.User.Identity.Name; WebDavHelper.SaveFolder(fdr); } catch (Exception) { this._Errors.Add(new ProcessingError(WebDavHelper.getResourceName(path), WebDavHelper.getEnumHttpResponse(DavCopyResponseCode.InsufficientStorage))); } }
private void CloneDirectory(FoldersDS.FoldersRow _sourceDirectory, string destination) { if (_sourceDirectory != null) { try { FoldersDS.FoldersRow _destFolder = WebDavHelper.getFolder(destination); if (!this._overwriteResource && _destFolder != null) { this._Errors.Add(new ProcessingError(_sourceDirectory.FolderName, WebDavHelper.getEnumHttpResponse(DavCopyResponseCode.PreconditionFailed))); } else { //Create the destination directory if (_destFolder == null) { CreateDirectory(destination); } //Move over the directory files Search_FilesDS _filelist = WebDavHelper.getFolderFiles(_sourceDirectory.ID); foreach (Search_FilesDS.FilesRow sfr in _filelist.Files) { FilesDS.FilesRow _file = WebDavHelper.getFile(sfr.ID); CopyFile(_file, destination + "/" + _file.FileName); } FoldersDS _dirlist = WebDavHelper.getSubFolders(_sourceDirectory.ID); foreach (FoldersDS.FoldersRow _dir in _dirlist.Folders) CloneDirectory(_dir, destination + "/" + _dir.FolderName); } } catch (Exception) { this._Errors.Add(new ProcessingError(_sourceDirectory.FolderName, WebDavHelper.getEnumHttpResponse(DavCopyResponseCode.Forbidden))); } } }
public static FoldersDS.FoldersRow Get(int KeyValue, string SQLConnectionName) { FoldersDS ds = new FoldersDS(); try { SqlConnection SQLConn = new SqlConnection(getConnstring(SQLConnectionName)); SqlDataAdapter iDataAdapter = new SqlDataAdapter(SP_Get, SQLConn); iDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure; iDataAdapter.SelectCommand.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int)); iDataAdapter.SelectCommand.Parameters["@ID"].Value = KeyValue; SQLConn.Open(); //Fill the DataSet with the rows that are returned. iDataAdapter.Fill(ds, ds.Folders.TableName); iDataAdapter.Dispose(); SQLConn.Close(); } catch { return null; } if (ds.Folders.Rows.Count == 1) { return (FoldersDS.FoldersRow)ds.Folders.Rows[0]; } else { return null; } }
public static bool Del(FoldersDS.FoldersRow dr, string SQLConnectionName) { return Del(dr.ID,SQLConnectionName); }
private static SqlCommand GenerateSqlCommandfromDataRow(FoldersDS.FoldersRow Data, string StoredProcName) { SqlCommand retCom = new SqlCommand(StoredProcName); retCom.CommandType = CommandType.StoredProcedure; for (int Eni = 0; Eni < Data.ItemArray.Length; Eni++) { string stype = Data[Eni].GetType().ToString(); switch (stype) { case "System.Int32": retCom.Parameters.Add("@" + Data.Table.Columns[Eni].ColumnName, SqlDbType.Int); retCom.Parameters["@" + Data.Table.Columns[Eni].ColumnName].Value = Data[Eni]; break; case "System.Int64": retCom.Parameters.Add("@" + Data.Table.Columns[Eni].ColumnName, SqlDbType.BigInt); retCom.Parameters["@" + Data.Table.Columns[Eni].ColumnName].Value = Data[Eni]; break; case "System.String": retCom.Parameters.Add("@" + Data.Table.Columns[Eni].ColumnName, SqlDbType.VarChar); retCom.Parameters["@" + Data.Table.Columns[Eni].ColumnName].Value = Data[Eni]; break; case "System.Byte[]": retCom.Parameters.Add("@" + Data.Table.Columns[Eni].ColumnName, SqlDbType.Image); retCom.Parameters["@" + Data.Table.Columns[Eni].ColumnName].Value = Data[Eni]; break; case "System.DateTime": retCom.Parameters.Add("@" + Data.Table.Columns[Eni].ColumnName, SqlDbType.DateTime); retCom.Parameters["@" + Data.Table.Columns[Eni].ColumnName].Value = Data[Eni]; break; } } return retCom; }
public static int Update(FoldersDS.FoldersRow dr, string SQLConnectionName) { try { SqlConnection SQLConn = new SqlConnection(getConnstring(SQLConnectionName)); SqlCommand iSqlCommand = GenerateSqlCommandfromDataRow(dr, SP_Update); iSqlCommand.Connection = SQLConn; //Set the ID column as output as the GenerateSQLCommand would not have done this. SQLConn.Open(); iSqlCommand.ExecuteNonQuery(); iSqlCommand.Dispose(); SQLConn.Close(); return 1; } catch { return -1; } }
public static FoldersDS List(int ParentID, string SQLConnectionName) { FoldersDS ds = new FoldersDS(); try { SqlConnection SQLConn = new SqlConnection(getConnstring(SQLConnectionName)); SqlDataAdapter iDataAdapter = new SqlDataAdapter(SP_List, SQLConn); iDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure; iDataAdapter.SelectCommand.Parameters.Add(new SqlParameter("@ParentID", SqlDbType.Int)); iDataAdapter.SelectCommand.Parameters["@ParentID"].Value = ParentID; iDataAdapter.SelectCommand.Parameters.Add(new SqlParameter("@sort_col", SqlDbType.VarChar, 120)); iDataAdapter.SelectCommand.Parameters["@sort_col"].Value = "FolderName"; SQLConn.Open(); //Fill the DataSet with the rows that are returned. iDataAdapter.Fill(ds, ds.Folders.TableName); iDataAdapter.Dispose(); SQLConn.Close(); } catch { return null; } return ds; }
private void DelFolder(FoldersDS.FoldersRow _sourceDirectory, bool JustCheckforLocks) { if (_sourceDirectory != null) { try { //Move over the directory files Search_FilesDS _filelist = WebDavHelper.getFolderFiles(_sourceDirectory.ID); foreach (Search_FilesDS.FilesRow sfr in _filelist.Files) { if (JustCheckforLocks) { if (WebDavHelper.getLock(sfr.ID) != null) { this._Errors.Add(new ProcessingError(WebDavHelper.getFolderFullPath(sfr.ParentID) + sfr.FileName, WebDavHelper.getEnumHttpResponse(DavDeleteResponseCode.Locked))); } } else { WebDavHelper.RemoveFile(sfr.ID); } } FoldersDS _dirlist = WebDavHelper.getSubFolders(_sourceDirectory.ID); foreach (FoldersDS.FoldersRow _dir in _dirlist.Folders) { DelFolder(_dir, JustCheckforLocks); if (!(JustCheckforLocks)) WebDavHelper.RemoveFolder(_dir.ID); } } catch (Exception) { //To do exception on delete handling } } }