Beispiel #1
0
        public static int Add(LocksDS.LocksRow 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;
            }
        }
Beispiel #2
0
        public static void GetXML(LocksDS.LocksRow ldr, XmlWriter xmlWriter)
        {
            if (ldr == null) return;

            xmlWriter.WriteStartElement("activelock", "DAV:");

            xmlWriter.WriteStartElement("locktype", "DAV:");
            switch ((LockType)ldr.LockType)
            {
                case LockType.Read:
                    xmlWriter.WriteElementString("read", "DAV:");
                    break;

                case LockType.Write:
                    xmlWriter.WriteElementString("write", "DAV:");
                    break;
            }
            xmlWriter.WriteEndElement();

            xmlWriter.WriteStartElement("lockscope", "DAV:");
            switch ((LockScope)ldr.LockScope)
            {
                case LockScope.Exclusive:
                    xmlWriter.WriteElementString("exclusive", "DAV:");
                    break;

                case LockScope.Shared:
                    xmlWriter.WriteElementString("shared", "DAV:");
                    break;
            }
            xmlWriter.WriteEndElement();

            DepthType LockDepth = (DepthType)ldr.LockDepth;

            if (LockDepth == DepthType.Infinity)
                xmlWriter.WriteElementString("depth", "DAV:", LockDepth.ToString());
            else
                xmlWriter.WriteElementString("depth", "DAV:", (string)System.Enum.Parse(LockDepth.GetType(), LockDepth.ToString(), true));

            //Append the owner
            xmlWriter.WriteElementString("owner", "DAV:", ldr.LockOwner);
            xmlWriter.WriteElementString("timeout", "DAV:", "Seconds-" + ldr.Timeout.ToString());

            //Append all the tokens
            xmlWriter.WriteStartElement("locktoken", "DAV:");

            //Get LockTokens from the DB

            Locks_TokensDS _ltds = WebDavHelper.getLockTokens(ldr.ID);
            foreach (Locks_TokensDS.Locks_TokensRow _ltr in _ltds.Locks_Tokens)
            {
                xmlWriter.WriteElementString("href", "DAV:", "opaquelocktoken:" + _ltr.Token);
            }

            xmlWriter.WriteEndElement();

            //End ActiveLock
            xmlWriter.WriteEndElement();
        }
Beispiel #3
0
 /// <summary>
 /// Saves a Lock
 /// </summary>
 /// <param name="FolderID">The ID of the Lock in the Database</param>
 /// <returns></returns>   
 public static int SaveLock(LocksDS.LocksRow nlr)
 {
     return FileBLC.SaveLock(nlr);
 }
Beispiel #4
0
 public static int SaveLock(LocksDS.LocksRow nlr)
 {
     if (nlr.ID == 0)
     {
         return LocksDLC.Add(nlr, DBConnName);
     }
     else
     {
         return LocksDLC.Update(nlr, DBConnName);
     }
 }
Beispiel #5
0
        private int saveLock(int FileID)
        {
            int retval = 1;
            Locks_TokensDS ltds = new Locks_TokensDS();
            LocksDS lds = new LocksDS();

            LocksDS.LocksRow ltr = lds.Locks.NewLocksRow();

            //ResType=0 as we aren't supporting Locked Collections

            ltr.ResType = 0;

            ltr.LockDepth = (int)this._LockDepth;
            ltr.LockOwner = _LockOwner;
            ltr.LockOwnerType = (int)_LockOwnerType;
            ltr.LockScope = (int)_LockScope;
            ltr.LockType = (int)_LockType;
            ltr.ResID = FileID;
            ltr.Timeout = _LockTimeOut;
            ltr.update_user_stamp = HttpContext.Current.User.Identity.Name;

            retval = WebDavHelper.SaveLock(ltr);

            if (retval!=-1)
            {
                Locks_TokensDS.Locks_TokensRow nltr = ltds.Locks_Tokens.NewLocks_TokensRow();
                nltr.Token = this._LockToken;
                nltr.LockID = retval;
                nltr.update_user_stamp = HttpContext.Current.User.Identity.Name;
                retval = WebDavHelper.SaveLockToken(nltr);
            }
            return retval;
        }
Beispiel #6
0
 private void DeserialiseLock(LocksDS.LocksRow _lockrow)
 {
     this._LockOwner = _lockrow.LockOwner;
     this._LockDepth = (DepthType)_lockrow.LockDepth;
     this._LockOwnerType = (LockOwnerType)_lockrow.LockOwnerType;
     this._LockType = (LockType)_lockrow.LockType;
     this._LockScope = (LockScope)_lockrow.LockScope;
 }
Beispiel #7
0
        public static LocksDS.LocksRow Get(int KeyValue, string SQLConnectionName)
        {
            LocksDS ds = new LocksDS();

            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.Locks.TableName);
                iDataAdapter.Dispose();

                SQLConn.Close();

            }
            catch
            {
                return null;
            }

            if (ds.Locks.Rows.Count == 1)
            {

                return (LocksDS.LocksRow)ds.Locks.Rows[0];
            }
            else
            {
                return null;
            }
        }
Beispiel #8
0
        private static SqlCommand GenerateSqlCommandfromDataRow(LocksDS.LocksRow 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;
        }
Beispiel #9
0
        public static int Update(LocksDS.LocksRow 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;
            }
        }
Beispiel #10
0
        public static LocksDS List(int ResID, string SQLConnectionName)
        {
            LocksDS ds = new LocksDS();

            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("@ResID", SqlDbType.Int));
                iDataAdapter.SelectCommand.Parameters["@ResID"].Value = ResID;

                SQLConn.Open();
                //Fill the DataSet with the rows that are returned.
                iDataAdapter.Fill(ds, ds.Locks.TableName);
                iDataAdapter.Dispose();

                SQLConn.Close();

            }
            catch
            {
                return null;
            }

            return ds;
        }