Exemplo n.º 1
0
        public virtual DriveStatistic UpdateDriveStatistic(DriveStatistic entity)
        {
            if (entity.IsTransient())
            {
                return(entity);
            }
            DriveStatistic other = GetDriveStatistic(entity.DriveStatisticId);

            if (entity.Equals(other))
            {
                return(entity);
            }
            string sql = @"Update DriveStatistic set  [IPAddress]=@IPAddress
							, [DriveSpaceAvailable]=@DriveSpaceAvailable
							, [DriveTotalSpace]=@DriveTotalSpace
							, [DriveName]=@DriveName
							, [CreationDate]=@CreationDate
							, [MachineName]=@MachineName 
							 where DriveStatisticId=@DriveStatisticId"                            ;

            SqlParameter[] parameterArray = new SqlParameter[] {
                new SqlParameter("@IPAddress", entity.IpAddress ?? (object)DBNull.Value)
                , new SqlParameter("@DriveSpaceAvailable", entity.DriveSpaceAvailable ?? (object)DBNull.Value)
                , new SqlParameter("@DriveTotalSpace", entity.DriveTotalSpace ?? (object)DBNull.Value)
                , new SqlParameter("@DriveName", entity.DriveName ?? (object)DBNull.Value)
                , new SqlParameter("@CreationDate", entity.CreationDate ?? (object)DBNull.Value)
                , new SqlParameter("@MachineName", entity.MachineName ?? (object)DBNull.Value)
                , new SqlParameter("@DriveStatisticId", entity.DriveStatisticId)
            };
            SqlHelper.ExecuteNonQuery(this.ConnectionString, CommandType.Text, sql, parameterArray);
            return(GetDriveStatistic(entity.DriveStatisticId));
        }
        public DataTransfer <GetOutput> Get(string _id)
        {
            DataTransfer <GetOutput> tranfer = new DataTransfer <GetOutput>();

            System.Int32 drivestatisticid = 0;
            if (!string.IsNullOrEmpty(_id) && System.Int32.TryParse(_id, out drivestatisticid))
            {
                DriveStatistic drivestatistic = _iDriveStatisticRepository.GetDriveStatistic(drivestatisticid);
                if (drivestatistic != null)
                {
                    tranfer.IsSuccess = true;
                    GetOutput output = new GetOutput();
                    output.CopyFrom(drivestatistic);
                    tranfer.Data = output;
                }
                else
                {
                    tranfer.IsSuccess = false;
                    tranfer.Errors    = new string[1];
                    tranfer.Errors[0] = "Error: No record found.";
                }
            }
            else
            {
                tranfer.IsSuccess = false;
                tranfer.Errors    = new string[1];
                tranfer.Errors[0] = "Error: Invalid request.";
            }
            return(tranfer);
        }
 public virtual DriveStatistic DriveStatisticFromDataRow(DataRow dr)
 {
     if(dr==null) return null;
     DriveStatistic entity=new DriveStatistic();
     if (dr.Table.Columns.Contains("DriveStatisticId"))
     {
     entity.DriveStatisticId = (System.Int32)dr["DriveStatisticId"];
     }
     if (dr.Table.Columns.Contains("IPAddress"))
     {
     entity.IpAddress = dr["IPAddress"].ToString();
     }
     if (dr.Table.Columns.Contains("DriveSpaceAvailable"))
     {
     entity.DriveSpaceAvailable = dr["DriveSpaceAvailable"]==DBNull.Value?(System.Double?)null:(System.Double?)dr["DriveSpaceAvailable"];
     }
     if (dr.Table.Columns.Contains("DriveTotalSpace"))
     {
     entity.DriveTotalSpace = dr["DriveTotalSpace"]==DBNull.Value?(System.Double?)null:(System.Double?)dr["DriveTotalSpace"];
     }
     if (dr.Table.Columns.Contains("DriveName"))
     {
     entity.DriveName = dr["DriveName"].ToString();
     }
     if (dr.Table.Columns.Contains("CreationDate"))
     {
     entity.CreationDate = dr["CreationDate"]==DBNull.Value?(System.DateTime?)null:(System.DateTime?)dr["CreationDate"];
     }
     if (dr.Table.Columns.Contains("MachineName"))
     {
     entity.MachineName = dr["MachineName"].ToString();
     }
     return entity;
 }
Exemplo n.º 4
0
        public PerformanceStatistic GetPCPerformance()
        {
            PerformanceStatistic stats = new PerformanceStatistic();
            PerformanceCounter   cpuCounter;
            PerformanceCounter   ramCounter;

            cpuCounter = new PerformanceCounter();

            cpuCounter.CategoryName = "Processor";
            cpuCounter.CounterName  = "% Processor Time";
            cpuCounter.InstanceName = "_Total";

            ramCounter = new PerformanceCounter("Memory", "Available MBytes");
            Int64 phav = PerformanceInfo.GetPhysicalAvailableMemoryInMiB();
            Int64 tot  = PerformanceInfo.GetTotalMemoryInMiB();

            stats.Memory = Math.Round((double)(100 - (((decimal)phav / (decimal)tot) * 100)), 2);
            stats.Cpu    = cpuCounter.NextValue();
            Thread.Sleep(1000);
            stats.Cpu          = cpuCounter.NextValue();
            stats.CreationDate = DateTime.UtcNow;

            stats.MachineName = System.Environment.MachineName.ToString();

            DriveInfo[] allDrives = DriveInfo.GetDrives();
            DriveStatisticRepository driveRepo = new DriveStatisticRepository();

            if (allDrives.Count() > 0)
            {
                stats.DriveSpaceAvailable = 0;
                stats.DriveTotalSpace     = 0;
                for (int i = 0; i < allDrives.Count(); i++)
                {
                    try
                    {
                        DriveStatistic dS = new DriveStatistic();
                        dS.CreationDate        = stats.CreationDate;
                        dS.DriveName           = allDrives[i].Name;
                        dS.MachineName         = stats.MachineName + ":" + allDrives[i].Name;
                        dS.DriveSpaceAvailable = Math.Round(((allDrives[i].TotalFreeSpace / 1024.0) / 1024.0) / 1024.0, 2);
                        dS.DriveTotalSpace     = Math.Round(((allDrives[i].TotalSize / 1024.0) / 1024.0) / 1024.0, 2);
                        string hostNames = Dns.GetHostName();
                        string myIPs     = Dns.GetHostByName(hostNames).AddressList[0].ToString();
                        dS.IpAddress = myIPs + ":" + allDrives[i].Name;
                        driveRepo.InsertDriveStatistic(dS);
                        stats.DriveSpaceAvailable += dS.DriveSpaceAvailable;
                        stats.DriveTotalSpace     += dS.DriveTotalSpace;
                    }
                    catch (Exception exp)
                    { }
                }
            }

            string hostName = Dns.GetHostName();
            string myIP     = Dns.GetHostByName(hostName).AddressList[0].ToString();

            stats.IpAddress = myIP;

            return(stats);
        }
Exemplo n.º 5
0
 public virtual void CopyFrom(DriveStatistic other)
 {
     if (other != null)
     {
         this.DriveStatisticId    = other.DriveStatisticId;
         this.IpAddress           = other.IpAddress;
         this.DriveSpaceAvailable = other.DriveSpaceAvailable;
         this.DriveTotalSpace     = other.DriveTotalSpace;
         this.DriveName           = other.DriveName;
         this.CreationDate        = other.CreationDate;
         this.MachineName         = other.MachineName;
     }
 }
        public DataTransfer <PutOutput> Update(PutInput Input)
        {
            DataTransfer <PutOutput> transer = new DataTransfer <PutOutput>();
            IList <string>           errors  = Validator.Validate(Input);

            if (errors.Count == 0)
            {
                DriveStatistic drivestatisticinput  = new DriveStatistic();
                DriveStatistic drivestatisticoutput = new DriveStatistic();
                PutOutput      output = new PutOutput();
                drivestatisticinput.CopyFrom(Input);
                DriveStatistic drivestatistic = _iDriveStatisticRepository.GetDriveStatistic(drivestatisticinput.DriveStatisticId);
                if (drivestatistic != null)
                {
                    drivestatisticoutput = _iDriveStatisticRepository.UpdateDriveStatistic(drivestatisticinput);
                    if (drivestatisticoutput != null)
                    {
                        output.CopyFrom(drivestatisticoutput);
                        transer.IsSuccess = true;
                        transer.Data      = output;
                    }
                    else
                    {
                        transer.IsSuccess = false;
                        transer.Errors    = new string[1];
                        transer.Errors[0] = "Error: Could not update.";
                    }
                }
                else
                {
                    transer.IsSuccess = false;
                    transer.Errors    = new string[1];
                    transer.Errors[0] = "Error: Record not found.";
                }
            }
            else
            {
                transer.IsSuccess = false;
                transer.Errors    = errors.ToArray <string>();
            }
            return(transer);
        }
        public DataTransfer <PostOutput> Insert(PostInput Input)
        {
            DataTransfer <PostOutput> transer = new DataTransfer <PostOutput>();
            IList <string>            errors  = Validator.Validate(Input);

            if (errors.Count == 0)
            {
                DriveStatistic drivestatistic = new DriveStatistic();
                PostOutput     output         = new PostOutput();
                drivestatistic.CopyFrom(Input);
                drivestatistic = _iDriveStatisticRepository.InsertDriveStatistic(drivestatistic);
                output.CopyFrom(drivestatistic);
                transer.IsSuccess = true;
                transer.Data      = output;
            }
            else
            {
                transer.IsSuccess = false;
                transer.Errors    = errors.ToArray <string>();
            }
            return(transer);
        }
Exemplo n.º 8
0
        public virtual DriveStatistic DriveStatisticFromDataRow(DataRow dr)
        {
            if (dr == null)
            {
                return(null);
            }
            DriveStatistic entity = new DriveStatistic();

            if (dr.Table.Columns.Contains("DriveStatisticId"))
            {
                entity.DriveStatisticId = (System.Int32)dr["DriveStatisticId"];
            }
            if (dr.Table.Columns.Contains("IPAddress"))
            {
                entity.IpAddress = dr["IPAddress"].ToString();
            }
            if (dr.Table.Columns.Contains("DriveSpaceAvailable"))
            {
                entity.DriveSpaceAvailable = dr["DriveSpaceAvailable"] == DBNull.Value?(System.Double?)null : (System.Double?)dr["DriveSpaceAvailable"];
            }
            if (dr.Table.Columns.Contains("DriveTotalSpace"))
            {
                entity.DriveTotalSpace = dr["DriveTotalSpace"] == DBNull.Value?(System.Double?)null : (System.Double?)dr["DriveTotalSpace"];
            }
            if (dr.Table.Columns.Contains("DriveName"))
            {
                entity.DriveName = dr["DriveName"].ToString();
            }
            if (dr.Table.Columns.Contains("CreationDate"))
            {
                entity.CreationDate = dr["CreationDate"] == DBNull.Value?(System.DateTime?)null : (System.DateTime?)dr["CreationDate"];
            }
            if (dr.Table.Columns.Contains("MachineName"))
            {
                entity.MachineName = dr["MachineName"].ToString();
            }
            return(entity);
        }
Exemplo n.º 9
0
        public virtual DriveStatistic InsertDriveStatistic(DriveStatistic entity)
        {
            DriveStatistic other = new DriveStatistic();

            other = entity;
            if (entity.IsTransient())
            {
                string         sql            = @"Insert into DriveStatistic ( [IPAddress]
				,[DriveSpaceAvailable]
				,[DriveTotalSpace]
				,[DriveName]
				,[CreationDate]
				,[MachineName] )
				Values
				( @IPAddress
				, @DriveSpaceAvailable
				, @DriveTotalSpace
				, @DriveName
				, @CreationDate
				, @MachineName );
				Select scope_identity()"                ;
                SqlParameter[] parameterArray = new SqlParameter[] {
                    new SqlParameter("@IPAddress", entity.IpAddress ?? (object)DBNull.Value)
                    , new SqlParameter("@DriveSpaceAvailable", entity.DriveSpaceAvailable ?? (object)DBNull.Value)
                    , new SqlParameter("@DriveTotalSpace", entity.DriveTotalSpace ?? (object)DBNull.Value)
                    , new SqlParameter("@DriveName", entity.DriveName ?? (object)DBNull.Value)
                    , new SqlParameter("@CreationDate", entity.CreationDate ?? (object)DBNull.Value)
                    , new SqlParameter("@MachineName", entity.MachineName ?? (object)DBNull.Value)
                };
                var identity = SqlHelper.ExecuteScalar(this.ConnectionString, CommandType.Text, sql, parameterArray);
                if (identity == DBNull.Value)
                {
                    throw new DataException("Identity column was null as a result of the insert operation.");
                }
                return(GetDriveStatistic(Convert.ToInt32(identity)));
            }
            return(entity);
        }
 public DriveStatistic UpdateDriveStatistic(DriveStatistic entity)
 {
     return _iDriveStatisticRepository.UpdateDriveStatistic(entity);
 }
 public DataTransfer<PutOutput> Update(PutInput Input)
 {
     DataTransfer<PutOutput> transer = new DataTransfer<PutOutput>();
     IList<string> errors = Validator.Validate(Input);
     if (errors.Count == 0)
     {
         DriveStatistic drivestatisticinput = new DriveStatistic();
         DriveStatistic drivestatisticoutput = new DriveStatistic();
         PutOutput output = new PutOutput();
         drivestatisticinput.CopyFrom(Input);
         DriveStatistic drivestatistic = _iDriveStatisticRepository.GetDriveStatistic(drivestatisticinput.DriveStatisticId);
         if (drivestatistic!=null)
         {
             drivestatisticoutput = _iDriveStatisticRepository.UpdateDriveStatistic(drivestatisticinput);
             if(drivestatisticoutput!=null)
             {
                 output.CopyFrom(drivestatisticoutput);
                 transer.IsSuccess = true;
                 transer.Data = output;
             }
             else
             {
                 transer.IsSuccess = false;
                 transer.Errors = new string[1];
                 transer.Errors[0] = "Error: Could not update.";
             }
         }
         else
         {
             transer.IsSuccess = false;
             transer.Errors = new string[1];
             transer.Errors[0] = "Error: Record not found.";
         }
     }
     else
     {
         transer.IsSuccess = false;
         transer.Errors = errors.ToArray<string>();
     }
     return transer;
 }
 public DriveStatistic InsertDriveStatistic(DriveStatistic entity)
 {
     return _iDriveStatisticRepository.InsertDriveStatistic(entity);
 }
 public DataTransfer<PostOutput> Insert(PostInput Input)
 {
     DataTransfer<PostOutput> transer = new DataTransfer<PostOutput>();
     IList<string> errors = Validator.Validate(Input);
     if(errors.Count==0)
     {
         DriveStatistic drivestatistic = new DriveStatistic();
         PostOutput output = new PostOutput();
         drivestatistic.CopyFrom(Input);
         drivestatistic = _iDriveStatisticRepository.InsertDriveStatistic(drivestatistic);
         output.CopyFrom(drivestatistic);
         transer.IsSuccess = true;
         transer.Data = output;
     }
     else
     {
         transer.IsSuccess = false;
         transer.Errors = errors.ToArray<string>();
     }
     return transer;
 }
        public PerformanceStatistic GetPCPerformance()
        {
            PerformanceStatistic stats = new PerformanceStatistic();
            PerformanceCounter cpuCounter;
            PerformanceCounter ramCounter;
            cpuCounter = new PerformanceCounter();

            cpuCounter.CategoryName = "Processor";
            cpuCounter.CounterName = "% Processor Time";
            cpuCounter.InstanceName = "_Total";

            ramCounter = new PerformanceCounter("Memory", "Available MBytes");
            Int64 phav = PerformanceInfo.GetPhysicalAvailableMemoryInMiB();
            Int64 tot = PerformanceInfo.GetTotalMemoryInMiB();
            stats.Memory = Math.Round((double)(100 - (((decimal)phav / (decimal)tot) * 100)), 2);
            stats.Cpu = cpuCounter.NextValue();
            Thread.Sleep(1000);
            stats.Cpu = cpuCounter.NextValue();
            stats.CreationDate = DateTime.UtcNow;

            stats.MachineName = System.Environment.MachineName.ToString();

            DriveInfo[] allDrives = DriveInfo.GetDrives();
            DriveStatisticRepository driveRepo = new DriveStatisticRepository();
            if (allDrives.Count() > 0)
            {
                stats.DriveSpaceAvailable = 0;
                stats.DriveTotalSpace = 0;
                for (int i = 0; i < allDrives.Count(); i++)
                {
                    try
                    {
                        DriveStatistic dS = new DriveStatistic();
                        dS.CreationDate = stats.CreationDate;
                        dS.DriveName = allDrives[i].Name;
                        dS.MachineName = stats.MachineName + ":" + allDrives[i].Name;
                        dS.DriveSpaceAvailable = Math.Round(((allDrives[i].TotalFreeSpace / 1024.0) / 1024.0) / 1024.0, 2);
                        dS.DriveTotalSpace = Math.Round(((allDrives[i].TotalSize / 1024.0) / 1024.0) / 1024.0, 2);
                        string hostNames = Dns.GetHostName();
                        string myIPs = Dns.GetHostByName(hostNames).AddressList[0].ToString();
                        dS.IpAddress = myIPs + ":" + allDrives[i].Name;
                        driveRepo.InsertDriveStatistic(dS);
                        stats.DriveSpaceAvailable += dS.DriveSpaceAvailable;
                        stats.DriveTotalSpace += dS.DriveTotalSpace;
                    }
                    catch (Exception exp)
                    { }
                }
            }

            string hostName = Dns.GetHostName();
            string myIP = Dns.GetHostByName(hostName).AddressList[0].ToString();

            stats.IpAddress = myIP;

            return stats;
        }
 public virtual DriveStatistic DeleteDriveStatistic(DriveStatistic entity)
 {
     this.DeleteDriveStatistic(entity.DriveStatisticId);
     return entity;
 }
 public virtual DriveStatistic UpdateDriveStatistic(DriveStatistic entity)
 {
     if (entity.IsTransient()) return entity;
     DriveStatistic other = GetDriveStatistic(entity.DriveStatisticId);
     if (entity.Equals(other)) return entity;
     string sql=@"Update DriveStatistic set  [IPAddress]=@IPAddress
                     , [DriveSpaceAvailable]=@DriveSpaceAvailable
                     , [DriveTotalSpace]=@DriveTotalSpace
                     , [DriveName]=@DriveName
                     , [CreationDate]=@CreationDate
                     , [MachineName]=@MachineName
                      where DriveStatisticId=@DriveStatisticId";
     SqlParameter[] parameterArray=new SqlParameter[]{
              new SqlParameter("@IPAddress",entity.IpAddress ?? (object)DBNull.Value)
             , new SqlParameter("@DriveSpaceAvailable",entity.DriveSpaceAvailable ?? (object)DBNull.Value)
             , new SqlParameter("@DriveTotalSpace",entity.DriveTotalSpace ?? (object)DBNull.Value)
             , new SqlParameter("@DriveName",entity.DriveName ?? (object)DBNull.Value)
             , new SqlParameter("@CreationDate",entity.CreationDate ?? (object)DBNull.Value)
             , new SqlParameter("@MachineName",entity.MachineName ?? (object)DBNull.Value)
             , new SqlParameter("@DriveStatisticId",entity.DriveStatisticId)};
     SqlHelper.ExecuteNonQuery(this.ConnectionString,CommandType.Text,sql,parameterArray);
     return GetDriveStatistic(entity.DriveStatisticId);
 }
 public virtual DriveStatistic InsertDriveStatistic(DriveStatistic entity)
 {
     DriveStatistic other=new DriveStatistic();
     other = entity;
     if(entity.IsTransient())
     {
         string sql=@"Insert into DriveStatistic ( [IPAddress]
         ,[DriveSpaceAvailable]
         ,[DriveTotalSpace]
         ,[DriveName]
         ,[CreationDate]
         ,[MachineName] )
         Values
         ( @IPAddress
         , @DriveSpaceAvailable
         , @DriveTotalSpace
         , @DriveName
         , @CreationDate
         , @MachineName );
         Select scope_identity()";
         SqlParameter[] parameterArray=new SqlParameter[]{
              new SqlParameter("@IPAddress",entity.IpAddress ?? (object)DBNull.Value)
             , new SqlParameter("@DriveSpaceAvailable",entity.DriveSpaceAvailable ?? (object)DBNull.Value)
             , new SqlParameter("@DriveTotalSpace",entity.DriveTotalSpace ?? (object)DBNull.Value)
             , new SqlParameter("@DriveName",entity.DriveName ?? (object)DBNull.Value)
             , new SqlParameter("@CreationDate",entity.CreationDate ?? (object)DBNull.Value)
             , new SqlParameter("@MachineName",entity.MachineName ?? (object)DBNull.Value)};
         var identity=SqlHelper.ExecuteScalar(this.ConnectionString,CommandType.Text,sql,parameterArray);
         if(identity==DBNull.Value) throw new DataException("Identity column was null as a result of the insert operation.");
         return GetDriveStatistic(Convert.ToInt32(identity));
     }
     return entity;
 }
Exemplo n.º 18
0
 public virtual DriveStatistic DeleteDriveStatistic(DriveStatistic entity)
 {
     this.DeleteDriveStatistic(entity.DriveStatisticId);
     return(entity);
 }
 public DriveStatistic UpdateDriveStatistic(DriveStatistic entity)
 {
     return(_iDriveStatisticRepository.UpdateDriveStatistic(entity));
 }
 public DriveStatistic InsertDriveStatistic(DriveStatistic entity)
 {
     return(_iDriveStatisticRepository.InsertDriveStatistic(entity));
 }