Exemplo n.º 1
0
        // All of these async method will periodically execute instructions to the underlying database
        //  For that reasons, they all take some optional action parameters


        // populate a list of DiskDriveInfoEx with information about the actual drives connected to the computer
        // pass in an Action that will populate a storage location with the information
        public async Task PopulateDiskInfoExs(IEnumerable <int?> diskNumbers, CrudType cRUD, Action <IEnumerable <DiskDriveInfoEx> > storeDiskInfoExs, Action <DiskDriveInfoEx> storePartitionInfoExs)
        {
            Log.Debug($"starting PopulateDiskInfoExs: cRUD = {cRUD.ToString()}, diskNumbers = {diskNumbers.Dump()}");
            var diskInfoExs = new List <DiskDriveInfoEx>();

            foreach (var d in diskNumbers)
            {
                var diskInfoEx = new DiskDriveInfoEx();
                // ToDo: get from current ComputerInventory
                diskInfoEx.DriveNumber    = d;
                diskInfoEx.DiskDriveMaker = DiskDriveMaker.Generic;                      // ToDo: read disk diskDriveMaker via WMI
                diskInfoEx.DiskDriveType  = DiskDriveType.Generic;                       // ToDo: read disk diskDriveType via WMI
                diskInfoEx.SerialNumber   = "DummyDiskSerialNumber";                     // ToDo: read disk serial number via WMI
                await PopulatePartitionInfoExs(cRUD, diskInfoEx, storePartitionInfoExs); // wait for the

                diskInfoExs.Add(diskInfoEx);
            }

            // Store the information using the Action delegate
            storeDiskInfoExs.Invoke(diskInfoExs);
            // Todo: see if the DiskDriveMaker and SerialNumber already exist in the DB
            // async (cRUD, diskInfoEx) => { await Task.Yield(); }
            // Task< DiskDriveInfoEx> t = await DBFetch.Invoke(cRUD, diskInfoEx);
            // diskInfoEx = await DBFetch.Invoke(cRUD, diskInfoEx);
            Log.Debug($"leaving PopulateDiskInfoExs");
        }
Exemplo n.º 2
0
        // populate a list of PartitionInfoEx with information about the actual partitions on a DiskDrive
        // pass in an Action that will populate a storage location with the information
        public async Task PopulatePartitionInfoExs(CrudType cRUD, DiskDriveInfoEx diskInfoEx, Action <DiskDriveInfoEx> storePartitionInfoExs)
        {
            Log.Debug($"starting PopulatePartitionInfoExs: cRUD = {cRUD.ToString()}, diskInfoEx = {diskInfoEx.Dump()}");

            // ToDo: Get the list of partitions from the Disk hardware
            await new Task(() => Thread.Sleep(500));
            // Until real partitions are available, mock up the current laptop configuration as of 4/15/19
            // No partitions on drives 0 and 1, and one partition on drive 2, one drive letter E
            var partitionInfoExs = new List <PartitionInfoEx>();

            switch (diskInfoEx.DriveNumber)
            {
            case 2: {
                var partitionInfoEx = new PartitionInfoEx()
                {
                    PartitionDbId = new Id <PartitionInfoEx>(),
                    DriveLetters  = new List <string>()
                    {
                        "E"
                    }
                };
                partitionInfoExs.Add(partitionInfoEx);
                break;
            }

            default:
                break;
            }
            storePartitionInfoExs.Invoke(diskInfoEx);
            // ToDo: see if the disk already has partitions in the DB
            var dBPartitions = new List <PartitionInfoEx>();

            Log.Debug($"leaving PopulatePartitionInfoExs");
        }
Exemplo n.º 3
0
 public RepositoryEventArgs(Type repositoryType, ParentPath?parentPath, string?id, CrudType action)
 {
     RepositoryType = repositoryType ?? throw new ArgumentNullException(nameof(repositoryType));
     ParentPath     = parentPath;
     Id             = id;
     Action         = action;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Validates if the current user can do the given action.
 /// Override this if you want to controll the actions a given user can do
 /// in this controller, you can switch the CrudType and use the "Can(string)"
 /// method to validate if the current logged user has a given permission.
 /// </summary>
 /// <param name="action">The CRUD action being performed</param>
 /// <returns>If the current user is authorized to perform the action</returns>
 protected virtual bool ValidateAuthFor(CrudType action)
 {
     //we dont mind the action here,
     //lets consider all the same
     //and any user can access
     return(true);
 }
 public CollectionRepositoryEventArgs(string collectionAlias, string repositoryAlias, ParentPath?parentPath, IEnumerable <string>?ids, CrudType action)
 {
     CollectionAlias = collectionAlias ?? throw new ArgumentNullException(nameof(collectionAlias));
     RepositoryAlias = repositoryAlias ?? throw new ArgumentNullException(nameof(repositoryAlias));
     ParentPath      = parentPath;
     Ids             = ids;
     Action          = action;
 }
Exemplo n.º 6
0
        public void PaneHandled(CrudType crudType)
        {
            _tcs.SetResult(crudType);

            OnPaneFinished?.Invoke(null, new EventArgs());

            // reset tcs
            _tcs = new TaskCompletionSource <CrudType>();
        }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CrudEventArgs{T}"/> class.
 /// </summary>
 /// <param name="crudType">Type of the crud.</param>
 private CrudEventArgs(CrudType crudType) : base(crudType)
 {
     OldItem      = default;
     NewItem      = default;
     UpdatedItem  = default;
     OldItems     = default;
     NewItems     = default;
     UpdatedItems = default;
 }
Exemplo n.º 8
0
 // C/R/U/D a list of DiskDriveInfoEx with data in a DB
 // pass in an Action that will interact with the DB
 public async Task DiskInfoExsToDB(List <DiskDriveInfoEx> diskInfoExs, CrudType cRUD, Func <CrudType, DiskDriveInfoEx, Task> interact)
 {
     Log.Debug($"starting DiskInfoExsToDB: cRUD = {cRUD.ToString()}, diskInfoExs = {diskInfoExs.Dump()}");
     foreach (var diskInfoEx in diskInfoExs)
     {
         // invoke the Action delegate to C/R/U/D each DiskDriveInfoEx to the DB
         await interact.Invoke(cRUD, diskInfoEx);
     }
     Log.Debug($"leaving DiskInfoExsToDB");
 }
Exemplo n.º 9
0
        public CpuSensorForm(CrudType crudType, CpuSensor sensor, List <ISensor> existingSensors)
        {
            Sensor          = sensor;
            ExistingSensors = existingSensors;
            this.crudType   = crudType;
            InitializeComponent();
            InitCustomCode();
            if (crudType == CrudType.Add)
            {
                cmbTimeType.SelectedIndex = (int)CheckIntervalType.Minutes;
                Sensor.Id = Guid.NewGuid();
            }

            UpdateUIFromData();
        }
Exemplo n.º 10
0
        private string sentenceSqlFrom(CrudType type, string[] fields)
        {
            string sqlBegin = "";

            switch (type)
            {
            case CrudType.Select:
                sqlBegin = string.Format("SELECT {0} FROM {1}", separator(fields.ToList()), obj.Name);
                break;

            case CrudType.Insert:
                sqlBegin = string.Format("INSERT INTO {0} ({1})", obj.Name, separator(fields.ToList()));
                break;
            }
            return(sqlBegin);
        }
Exemplo n.º 11
0
        private string sentenceSqlFrom(CrudType type)
        {
            string sqlBegin = "";

            switch (type)
            {
            case CrudType.Select:
                sqlBegin = "SELECT * FROM ";
                break;

            case CrudType.Insert:
                sqlBegin = "INSERT INTO ";
                break;
            }
            return(sqlBegin + obj.Name + " ");
        }
Exemplo n.º 12
0
        public FolderCheckSensorForm(CrudType crudType, FolderCheckSensor sensor, List <ISensor> existingSensors)
        {
            Sensor          = sensor;
            ExistingSensors = existingSensors;
            this.crudType   = crudType;
            InitializeComponent();
            InitCustomCode();

            if (crudType == CrudType.Add)
            {
                cmbTimeType.SelectedIndex = 0;
                Sensor.Id = Guid.NewGuid();
            }

            UpdateUIFromData();
        }
        private void ShowView(CrudType action, Cep target)
        {
            this._container.RegisterInstance <Cep>(target);
            IZipCodePresenter presenter = this._container.Resolve <IZipCodePresenter>("IZipCodePresenter");

            presenter.CloseViewRequested += delegate(object sender, EventArgs eventArgs)
            {
                if (eventArgs is CloseViewEventArgs)
                {
                    if ((eventArgs as CloseViewEventArgs).CloseViewOption == CloseViewType.Submit)
                    {
                        if ((eventArgs as CloseViewEventArgs).CloseViewOption == CloseViewType.Submit)
                        {
                            var repository = _container.Resolve <IZipCodeRepository>();

                            switch (action)
                            {
                            case CrudType.Create:
                                repository.Add(presenter.Cep);
                                break;

                            case CrudType.Update:
                                repository.Update(presenter.Cep);
                                break;
                            }
                            SearchCommand.Execute(this);
                        }
                        else
                        {
                            if (action == CrudType.Update)
                            {
                                SearchCommand.Execute(this);
                            }
                        }
                    }
                }
            };

            IBreadCrumbPresenter breadCrumb = this._container.Resolve <IBreadCrumbPresenter>();

            if (breadCrumb != null)
            {
                breadCrumb.AddCrumb(action.GetDescription(), presenter);
            }
        }
Exemplo n.º 14
0
        public static string GetCrudMessage(string crudObjectName, CrudType crudType)
        {
            switch (crudType)
            {
            case CrudType.Create:
                break;

            case CrudType.Update:
                break;

            case CrudType.Read:
                break;

            case CrudType.Delete:
                break;

            default:
                break;
            }
            return("");
        }
Exemplo n.º 15
0
        /// <summary>
        /// Tracks the changes and saves them
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="obj"></param>
        /// <param name="crudType">Either insert/update or delete</param>
        /// <param name="tableName"></param>
        /// <param name="snapshot">a copy</param>
        public void TrackChange <TModel, TId>(object obj, CrudType crudType, string tableName, object snapshot, object primaryKey)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            ChangeTracking requestChange = new ChangeTracking
            {
                UserId          = sessionService.CurrentSession.UserId,
                TableName       = tableName,
                TimeStampChange = DateTime.Now,
                CrudType        = crudType,
            };

            requestChange = SetPrimaryKey <TModel, TId>(requestChange, primaryKey);

            if (obj is ITrackable trackable && trackable.Snapshot != null)
            {
                requestChange.JsonObject = DetailedCompare <TModel>((TModel)trackable.Snapshot, (TModel)obj);
            }
Exemplo n.º 16
0
 protected void ButtonClicked(CrudType crudType)
 {
     SidePaneService.PaneHandled(crudType);
 }
Exemplo n.º 17
0
        private void AddOrEditEditSensor(CrudType crudType, ISensor iSensor)
        {
            switch (iSensor.SensorType)
            {
            case SensorType.Cpu:
            {
                var sensor = iSensor as CpuSensor;
                using (var dlg = new CpuSensorForm(crudType, sensor, appConfig.MonitorSettings.GetAllSensors()))
                {
                    if (dlg.ShowDialog(this) != DialogResult.OK)
                    {
                        return;
                    }
                }
                break;
            }

            case SensorType.Http:
            {
                var sensor = iSensor as HttpSensor;
                using (var dlg = new HttpSensorForm(crudType, sensor, appConfig.MonitorSettings.GetAllSensors()))
                {
                    if (dlg.ShowDialog(this) != DialogResult.OK)
                    {
                        return;
                    }
                }
                break;
            }

            case SensorType.Ftp:
            {
                var sensor = iSensor as FtpSensor;
                using (var dlg = new FtpSensorForm(crudType, sensor, appConfig.MonitorSettings.GetAllSensors()))
                {
                    if (dlg.ShowDialog(this) != DialogResult.OK)
                    {
                        return;
                    }
                }
                break;
            }

            case SensorType.Drivespace:
            {
                var sensor = iSensor as DriveSpaceSensor;
                using (var dlg = new DriveSpaceSensorForm(crudType, sensor, appConfig.MonitorSettings.GetAllSensors()))
                {
                    if (dlg.ShowDialog(this) != DialogResult.OK)
                    {
                        return;
                    }
                }
                break;
            }

            case SensorType.FolderSize:
            {
                var sensor = iSensor as FolderSizeSensor;
                using (var dlg = new FolderSizeSensorForm(crudType, sensor, appConfig.MonitorSettings.GetAllSensors()))
                {
                    if (dlg.ShowDialog(this) != DialogResult.OK)
                    {
                        return;
                    }
                }
                break;
            }

            case SensorType.FolderCheck:
            {
                var sensor = iSensor as FolderCheckSensor;
                using (var dlg = new FolderCheckSensorForm(crudType, sensor, appConfig.MonitorSettings.GetAllSensors()))
                {
                    if (dlg.ShowDialog(this) != DialogResult.OK)
                    {
                        return;
                    }
                }
                break;
            }

            case SensorType.FileSize:
            {
                var sensor = iSensor as FileSizeSensor;
                using (var dlg = new FileSizeSensorForm(crudType, sensor, appConfig.MonitorSettings.GetAllSensors()))
                {
                    if (dlg.ShowDialog(this) != DialogResult.OK)
                    {
                        return;
                    }
                }
                break;
            }

            case SensorType.FileCheck:
            {
                var sensor = iSensor as FileCheckSensor;
                using (var dlg = new FileCheckSensorForm(crudType, sensor, appConfig.MonitorSettings.GetAllSensors()))
                {
                    if (dlg.ShowDialog(this) != DialogResult.OK)
                    {
                        return;
                    }
                }
                break;
            }

            case SensorType.Ram:
            {
                var sensor = iSensor as RamSensor;
                using (var dlg = new RamSensorForm(crudType, sensor, appConfig.MonitorSettings.GetAllSensors()))
                {
                    if (dlg.ShowDialog(this) != DialogResult.OK)
                    {
                        return;
                    }
                }
                break;
            }

            case SensorType.Service:
            {
                var sensor = iSensor as ServiceSensor;
                using (var dlg = new ServiceSensorForm(crudType, sensor, appConfig.MonitorSettings.GetAllSensors()))
                {
                    if (dlg.ShowDialog(this) != DialogResult.OK)
                    {
                        return;
                    }
                }
                break;
            }

            case SensorType.Process:
            {
                var sensor = iSensor as ProcessSensor;
                using (var dlg = new ProcessSensorForm(crudType, sensor, appConfig.MonitorSettings.GetAllSensors()))
                {
                    if (dlg.ShowDialog(this) != DialogResult.OK)
                    {
                        return;
                    }
                }
                break;
            }

            case SensorType.SqlConnection:
            {
                var sensor = iSensor as SqlConnectionSensor;
                using (var dlg = new SqlConnectionSensorForm(crudType, sensor, appConfig.MonitorSettings.GetAllSensors()))
                {
                    if (dlg.ShowDialog(this) != DialogResult.OK)
                    {
                        return;
                    }
                }
                break;
            }

            case SensorType.IISApplicationPool:
            {
                var sensor = iSensor as IISApplicationPoolSensor;
                using (var dlg = new IISApplicationPoolSensorForm(crudType, sensor, appConfig.MonitorSettings.GetAllSensors()))
                {
                    if (dlg.ShowDialog(this) != DialogResult.OK)
                    {
                        return;
                    }
                }
                break;
            }

            case SensorType.IISWebsite:
            {
                var sensor = iSensor as IISWebsiteSensor;
                using (var dlg = new IISWebsiteSensorForm(crudType, sensor, appConfig.MonitorSettings.GetAllSensors()))
                {
                    if (dlg.ShowDialog(this) != DialogResult.OK)
                    {
                        return;
                    }
                }
                break;
            }

            case SensorType.Ping:
            {
                var sensor = iSensor as PingSensor;
                using (var dlg = new PingSensorForm(crudType, sensor, appConfig.MonitorSettings.GetAllSensors()))
                {
                    if (dlg.ShowDialog(this) != DialogResult.OK)
                    {
                        return;
                    }
                }
                break;
            }

            default:
            {
                MessageBox.Show("Unable to determine the Sensor Type");
                return;
            }
            }

            if (crudType == CrudType.Add)
            {
                appConfig.AddMonitor(iSensor);
            }

            appConfig.SaveMonitorSettings();
            LoadMonitorSensors();
        }
Exemplo n.º 18
0
 protected CrudEvent(CrudType crudType, Guid entityId)
 {
     CrudType = crudType;
     EntityId = entityId;
 }
Exemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CrudEventArgs{T}"/> class.
 /// </summary>
 /// <param name="crudType">Type of the crud.</param>
 /// <param name="oldItem">The old item.</param>
 /// <param name="newItem">The new item.</param>
 /// <param name="updatedItem">The updated item.</param>
 internal CrudEventArgs(CrudType crudType, T oldItem, T newItem, T updatedItem) : this(crudType)
 {
     OldItem     = oldItem;
     NewItem     = newItem;
     UpdatedItem = updatedItem;
 }
Exemplo n.º 20
0
 public StockCrudEvent(CrudType crudType, Guid entityId) : base(crudType, entityId)
 {
 }
Exemplo n.º 21
0
 public StockCrudEvent(CrudType crudType, Guid entityId, PurchasedStock purchasedStock) : base(crudType, entityId)
 {
     PurchasedStock = purchasedStock;
 }
Exemplo n.º 22
0
        public CrudStatus SaveSetting(SalesSettingModel model, CrudType crudType)
        {
            myshopDb = new MyshopDb();
            int _result = 0;

            if (model.Id < 1 && crudType == CrudType.Insert)
            {
                var _oldSetting = myshopDb.Sale_Setting.Where(x => !x.IsDeleted && x.ShopId.Equals(WebSession.ShopId)).FirstOrDefault();
                if (_oldSetting != null)
                {
                    _oldSetting.IsDeleted             = true;
                    _oldSetting.IsSync                = false;
                    _oldSetting.ModifiedBy            = WebSession.UserId;
                    _oldSetting.ModifiedDate          = DateTime.Now;
                    myshopDb.Entry(_oldSetting).State = EntityState.Modified;
                    _result = myshopDb.SaveChanges();
                }

                Sale_Setting _newSetting = new Sale_Setting();
                _newSetting.CreatedBy             = WebSession.UserId;
                _newSetting.CreatedDate           = DateTime.Now;
                _newSetting.GSTIN                 = model.GSTIN;
                _newSetting.IsDeleted             = false;
                _newSetting.IsSync                = false;
                _newSetting.ReturnPolicy          = model.ReturnPolicy;
                _newSetting.GstRate               = model.GstRate;
                _newSetting.WeeklyClosingDay      = model.WeeklyClosingDay;
                _newSetting.ExchangeDayTime       = model.ExchangeDayTime;
                _newSetting.SalesClosingTime      = model.SalesClosingTime;
                _newSetting.SalesOpeningTime      = model.SalesOpeningTime;
                _newSetting.ShopId                = WebSession.ShopId;
                myshopDb.Entry(_newSetting).State = EntityState.Added;
                _result = myshopDb.SaveChanges();
            }
            else
            {
                var _setting = myshopDb.Sale_Setting.Where(x => !x.IsDeleted && x.Id.Equals(model.Id) && x.ShopId.Equals(WebSession.ShopId)).FirstOrDefault();
                if (_setting != null)
                {
                    _setting.IsSync       = false;
                    _setting.ModifiedBy   = WebSession.UserId;
                    _setting.ModifiedDate = DateTime.Now;
                    if (crudType == CrudType.Delete)
                    {
                        _setting.IsDeleted = true;
                        goto Save;
                    }

                    _setting.GSTIN            = model.GSTIN;
                    _setting.GstRate          = model.GstRate;
                    _setting.ReturnPolicy     = model.ReturnPolicy;
                    _setting.SalesClosingTime = model.SalesClosingTime;
                    _setting.SalesOpeningTime = model.SalesOpeningTime;
                    _setting.WeeklyClosingDay = model.WeeklyClosingDay;
                    _setting.ExchangeDayTime  = model.ExchangeDayTime;

                    #region Set Sales Session
                    WebSession.GstRate          = model.GstRate;
                    WebSession.ShopClosingTime  = Convert.ToInt32(model.SalesClosingTime);
                    WebSession.ShopOpeningTime  = Convert.ToInt32(model.SalesOpeningTime);
                    WebSession.ShopReturnPolicy = model.ReturnPolicy;
                    #endregion

Save:
                    myshopDb.Entry(_setting).State = EntityState.Modified;
                    _result = myshopDb.SaveChanges();
                }
            }

            return(Utility.CrudStatus(_result, crudType));
        }
Exemplo n.º 23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CrudEventArgs{T}"/> class.
 /// </summary>
 /// <param name="crudType">Type of the crud.</param>
 /// <param name="oldItems">The old items.</param>
 /// <param name="newItems">The new items.</param>
 /// <param name="updatedItems">The updated items.</param>
 internal CrudEventArgs(CrudType crudType, IEnumerable <T> oldItems, IEnumerable <T> newItems, IEnumerable <T> updatedItems) : this(crudType)
 {
     OldItems     = oldItems;
     NewItems     = newItems;
     UpdatedItems = updatedItems;
 }
Exemplo n.º 24
0
 protected void ButtonClicked(CrudType crudType)
 {
     Mediator.NotifyEvent(this, new PaneResponseEventArgs(RequestId, crudType));
 }
Exemplo n.º 25
0
 public EntityChangedEventArgs(CrudType crudType, Entity entity)
 {
     this._crudType = crudType;
     this._entity   = entity;
 }
Exemplo n.º 26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CrudEventArgs"/> class.
 /// </summary>
 /// <param name="crudType">Type of the crud.</param>
 protected CrudEventArgs(CrudType crudType)
 {
     CrudType = crudType;
 }