Exemple #1
0
 private void AddExt_Click(object sender, EventArgs e)
 {
     if (txtExtName.Text != string.Empty && txtExtValue.Text != string.Empty)
     {
         PlantDTO plant = VpnManagerDal.GetPlant(cmbCustomer.Text);
         bool     mustUpdateExtensionObj = false; //added refresh of ext objs if needed
         if (rdPlant.Checked)
         {
             if (plant.Id > 0)
             {
                 mustUpdateExtensionObj = VpnManagerDal.AddExtensionObject(plant.Id, (int)TargetTable.Plant, txtExtName.Text, txtExtValue.Text);
             }
         }
         else
         {
             if (_machineID > 0)
             {
                 mustUpdateExtensionObj = VpnManagerDal.AddExtensionObject(_machineID, (int)TargetTable.Machine, txtExtName.Text, txtExtValue.Text);
             }
         }
         if (mustUpdateExtensionObj)
         {
             extensionObjectDTOBindingSource.DataSource = VpnManagerDal.GetExtensionObjects(_plant, (int)TargetTable.Plant);
         }
     }
 }
Exemple #2
0
 private void Connect(int IDClient)
 {
     if (_IConnection == null)
     {
         ConnectToClient = ListPlants[IDClient];
         VpnTypeDTO vpntype = VpnTypes[ConnectToClient.IdConnectionType];
         if (ConnectToClient != null)
         {
             InitializeAssmebly(vpntype.Name);
             if (_IConnection != null)
             {
                 Dictionary <string, string> temp  = new Dictionary <string, string>(vpntype.Extensions);
                 Dictionary <string, string> temp2 = new Dictionary <string, string>(ConnectToClient.Extensions);
                 _IConnection.ConnectionEntry          = ConnectToClient.Name;
                 _IConnection.Password                 = ConnectToClient.Password;
                 _IConnection.User                     = ConnectToClient.Username;
                 _IConnection.ConnectionHost           = ConnectToClient.ServerAddress;
                 _IConnection.ConnectionStatusChanged += new ConnectionStatusChange(_connetion_Info); //<--- Stato collegato o meno
                 _IConnection.Options                  = (temp.Concat(temp2)).ToDictionary(x => x.Key, x => x.Value);
                 _IConnection.CreateConnection();
                 _IConnection.Connect();
             }
         }
     }
 }
Exemple #3
0
        public static PlantDTO GetPlant(string plantName)
        {
            PlantDTO retVal = null;

            using (VpnManagerEntities entities = new VpnManagerEntities())
            {
                string tbName = TargetTable.Plant.ToString();
                retVal = (from p in entities.Plant
                          where p.Name.Contains(plantName)

                          select new PlantDTO
                {
                    Id = p.Id,
                    Name = p.Name,
                    ServerAddress = p.ServerAddress,
                    Username = p.Username,
                    Password = p.Password,
                    IdConnectionType = p.IdConnectionType,
                    DisplayedName = (from x in entities.Customer where x.Id == p.Id_Customer select x.Name).FirstOrDefault(),
                    ExtensionCollection = (from eo in entities.ExtensionObjects
                                           where eo.IdTargetElement == p.Id && eo.TargetTableName == tbName
                                           select new ExtensionObjectDTO
                    {
                        Name = eo.Name,
                        Value = eo.Value
                    })
                }).FirstOrDefault();
            }

            return(retVal);
        }
Exemple #4
0
        public GetLongIdResponse DoesPlantExist(PlantDTO plantDTO)
        {
            GetLongIdResponse response = new GetLongIdResponse();

            response.returnedId = inventoryManager.DoesPlantExist(plantDTO);
            return(response);
        }
Exemple #5
0
        public AddPlantRequest()
        {
            Inventory = new InventoryDTO();

            Plant = new PlantDTO();

            ServiceCode = new ServiceCodeDTO();
        }
        public async Task Create(PlantDTO plantDto)
        {
            var plant = new Plant
            {
                Name = plantDto.Name,
                ApplicationUserId = plantDto.ApplicationUserId
            };

            Database.Plants.Create(plant);
            await Database.SaveAsync();
        }
        public PlantDTO Get(int plantId)
        {
            var plant  = Database.Plants.Get(plantId);
            var result = new PlantDTO
            {
                Id   = plant.Id,
                Name = plant.Name,
                ApplicationUserId = plant.ApplicationUserId
            };

            return(result);
        }
Exemple #8
0
        public ActionResult <Plant> PostPlant(int id, PlantDTO plant)
        {
            if (!_tuinRepository.TryGetTuin(id, out var tuin))
            {
                return(NotFound());
            }

            var PlantToCreate = new Plant(plant.Naam, Convert.ToDateTime(plant.DatumGeplant), plant.DagenTotOogst);

            tuin.AddPlant(PlantToCreate);
            _tuinRepository.SaveChanges();
            return(CreatedAtAction("GetPlant", new { id = tuin.Id, plantId = PlantToCreate.Id }, PlantToCreate));
        }
        public void Connect(int IDClient)
        {
            if (_connetion == null)
            {
                ConnectToClient = ListPlants[IDClient];
                VpnTypeDTO vpntype = VpnTypes[ConnectToClient.IdConnectionType];
                if (ConnectToClient != null)
                {
                    OnInfoFromCore(String.Format("Connecting To {0}", ConnectToClient.Name), false);

                    if (!System.Diagnostics.Debugger.IsAttached)
                    {
                        InitializeAssmebly(vpntype.Name);
                    }
                    else
                    {
                        _connetion = new CiscoVPN.CiscoAnyConnect();
                    }

                    if (_connetion != null)
                    {
                        Log = new LogConenction();
                        Log.Id_ConnectionPlant = IDClient;
                        Log.UserName           = !_BypassMSAutantication ?  Security.LoggedUser.ActualUser.user : "******";
                        Log.VirtualMachineName = ComputerName;
                        Log.LastConenctionTime = DateTime.Now;
                        VpnManagerDal.AddLog(Log);
                        Machines = VpnManagerDAL.VpnManagerDal.GetMachinesByPlant(ConnectToClient.Name).ToDictionary(f => f.Id);
                        Dictionary <string, string> temp  = new Dictionary <string, string>(vpntype.Extensions);
                        Dictionary <string, string> temp2 = new Dictionary <string, string>(ConnectToClient.Extensions);
                        _connetion.ConnectionEntry          = ConnectToClient.Name;
                        _connetion.Password                 = ConnectToClient.Password;
                        _connetion.User                     = ConnectToClient.Username;
                        _connetion.ConnectionHost           = ConnectToClient.ServerAddress;
                        _connetion.ConnectionStatusChanged += new ConnectionStatusChange(_connetion_Info);
                        _connetion.Options                  = (temp.Concat(temp2)).ToDictionary(x => x.Key, x => x.Value);
                        _connetion.CreateConnection();
                        _connetion.Connect();
                        _Connected = false;
                        tTimeout   = new Thread(new ThreadStart(CheckTimeoutConnetcion));
                        tTimeout.Start();
                        ConnectionChanged(eConnectionState.Connecting);
                    }
                }
            }
            else
            {
                OnInfoFromCore(String.Format("Controller : You are alredy Connected  to {0} !!!", _connetion.ConnectionEntry), true);
            }
        }
Exemple #10
0
        // POST: api/Plant
        public async Task <IHttpActionResult> Post(PlantModel plant)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var userId = await UserService.GetUserId(User.Identity.Name);

            var plantDTO = new PlantDTO
            {
                Name = plant.Name,
                ApplicationUserId = userId
            };
            await PlantService.Create(plantDTO);

            return(Ok());
        }
        public async Task <ActionResult <bool> > Post([FromBody] PlantDTO plant)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var existingPlant = await _plantsServices.GetPlantByCommonName(plant.CommonName);

                if (existingPlant != null)
                {
                    return(Conflict());
                }
                _plantsServices.SavePlant(plant);
                return(Ok(true));
            }
            catch (Exception ex)
            {
                return(StatusCode(Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Exemple #12
0
 private void _connetion_Info(eConnectionState state)
 {
     try
     {
         ConnectionChanged(state);
         if (state == eConnectionState.Disconnected)
         {
             _connetion              = null;
             ConnectToClient         = null;
             _Connected              = false;
             Log.ConncetionSuccesful = true;
             VpnManagerDal.UpdateLog(Log);
             tTimeout.Abort();
             tTimeout = null;
         }
         else if (state == eConnectionState.Connected)
         {
             _Connected = true;
         }
     }
     catch { }
 }
Exemple #13
0
        public AddConnection(int Plant)
        {
            InitializeComponent();
            vpnTypeDTOBindingSource.DataSource        = VpnManagerDal.GetVpnTypes();
            connectionTypeDTOBindingSource.DataSource = VpnManagerDal.GetConnectionTypes();
            machineDTOBindingSource.DataSource        = VpnManagerDal.GetMachinesByPlant(Plant);
            PlantDTO plant = VpnManagerDal.GetPlant(Plant);

            cmbCustomer.DataSource = VpnManagerDal.GetCustomersList();
            cmbCustomer.Text       = plant.DisplayedName;
            //cmbCustomer.Text = plant.Name;
            txtServerHost.Text       = plant.ServerAddress;
            txtUser.Text             = plant.Username;
            txtPassword.Text         = plant.Password;
            txtConfrimPassword.Text  = plant.Password;
            cmbVpnType.SelectedValue = plant.IdConnectionType;
            Loading            = false;
            Modifing           = true;
            grpMachine.Enabled = true;
            _plant             = Plant;
            cmdNext.Text       = "Modify Plant";
            extensionObjectDTOBindingSource.DataSource = VpnManagerDal.GetExtensionObjects(_plant, (int)TargetTable.Plant);
            // cmdMachine.Text = "Edit";
        }
Exemple #14
0
        public async Task <IHttpActionResult> PostPlant(Plant plant)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Plants.Add(plant);
            await db.SaveChangesAsync();

            var dto = new PlantDTO()
            {
                Id          = plant.Id,
                Name        = plant.Name,
                Price       = plant.Price,
                Harvest     = plant.Harvest,
                Water       = plant.Water,
                Description = plant.Description,
                Space       = plant.Space,
                Germination = plant.Germination
            };

            return(CreatedAtRoute("DefaultApi", new { id = plant.Id }, dto));
        }
Exemple #15
0
 public void RemovePlant([FromBody] PlantDTO plant)
 {
     _plantService.RemovePlant(plant);
 }
Exemple #16
0
 public PlantDTO AddPlant([FromBody] PlantDTO plant)
 {
     return(_plantService.AddPlant(plant));
 }
 public ClientConnectionViewModel(Controller controller, PlantDTO plant, IEventAggregator eventAggregator)
 {
     _events    = eventAggregator;
     Controller = controller;
     Plant      = plant;
 }
Exemple #18
0
 public void Update(PlantDTO item)
 {
     item.TimeStamps = DateTime.Now;
     _unitOfWork.EFRepository <Plant>().Update(_mapper.Map <Plant>(item));
 }
Exemple #19
0
 public void SavePlant(PlantDTO plant)
 {
     _plantsContext.Plant.Add(_mapper.Map <Plant>(plant));
     _plantsContext.SaveChanges();
 }
        private void ImportPlant(KeyValuePair <int, List <ExcelRowData> > kvp, ExcelPicture img)
        {
            //check for presence of plantName - add if not present
            long plantNameId = 0;

            int column = columnIndicesAndNames.Where(a => a.Value == "NAME").Select(b => b.Key).First();

            string plantName = rowData[kvp.Key].Where(a => a.column == column).Select(b => b.data).FirstOrDefault() as string;

            string result = Get("DoesPlantNameExist", "plantName=" + plantName);

            GetLongIdResponse r = JsonConvert.DeserializeObject <GetLongIdResponse>(result);

            plantNameId = r.returnedId;

            //check for presence of plantType - add if not present

            long plantTypeId = 0;

            column = columnIndicesAndNames.Where(a => a.Value == "TYPE").Select(b => b.Key).First();

            string plantType = rowData[kvp.Key].Where(a => a.column == column).Select(b => b.data).FirstOrDefault() as string;

            result = Get("DoesPlantTypeExist", "plantType=" + plantType);

            r           = JsonConvert.DeserializeObject <GetLongIdResponse>(result);
            plantTypeId = r.returnedId;

            column = columnIndicesAndNames.Where(a => a.Value.ToUpper() == "SIZE").Select(b => b.Key).First();

            string plantSize = rowData[kvp.Key].Where(a => a.column == column).Select(b => b.data).FirstOrDefault() as string;

            ////using cost, retail, plantName and plant Type, check for presence of service code - add if not present

            //ServiceCodeDTO serviceCode = GetServiceCodeDTO(kvp);

            //string jsonData = JsonConvert.SerializeObject(serviceCode);
            //var content = new StringContent(jsonData, Encoding.UTF8, "application/json");

            //result = Post("DoesServiceCodeExist", content);

            long serviceCodeId = 0;

            column = columnIndicesAndNames.Where(a => a.Value == "CODE").Select(b => b.Key).First();

            string serviceCode = rowData[kvp.Key].Where(a => a.column == column).Select(b => b.data).FirstOrDefault() as string;

            result = Get("ServiceCodeIsNotUnique", "serviceCode=" + serviceCode);

            r             = JsonConvert.DeserializeObject <GetLongIdResponse>(result);
            serviceCodeId = r.returnedId;

            //check for presence of plant - add if not present

            long plantId = 0;

            PlantDTO plantDTO = GetPlantDTO(kvp);

            string        jsonData = JsonConvert.SerializeObject(plantDTO);
            StringContent content  = new StringContent(jsonData, Encoding.UTF8, "application/json");

            result = Post("DoesPlantExist", content);

            r       = JsonConvert.DeserializeObject <GetLongIdResponse>(result);
            plantId = r.returnedId;

            //check for presence of inventory - add if not present

            ImportPlantRequest request = new ImportPlantRequest();

            request.PlantSize = plantSize;
            request.AddPlantRequest.Plant.PlantSize = plantSize;

            //add image if present
            if (img != null)
            {
                ImageConverter imgCon = new ImageConverter();
                request.imageBytes = (byte[])imgCon.ConvertTo(img.Image, typeof(byte[]));
            }

            //create DTO - send to service - backend will do the hookup

            if (plantNameId == 0)
            {
                request.PlantName = plantName;
            }
            else
            {
                request.AddPlantRequest.Plant.PlantNameId = plantNameId;
            }

            if (plantTypeId == 0)
            {
                request.PlantType = plantType;
            }
            else
            {
                request.AddPlantRequest.Plant.PlantTypeId = plantTypeId;
            }


            request.ServiceCode = GetServiceCodeDTO(kvp);

            if (serviceCodeId > 0)
            {
                ServiceCodeDTO original = GetServiceCodeById(serviceCodeId);
                UpdateServiceCode(original, request.ServiceCode);
                request.ServiceCode = original;
                request.ServiceCode.ServiceCodeId = serviceCodeId;
                request.AddPlantRequest.Inventory.ServiceCodeId = serviceCodeId;
            }

            jsonData = JsonConvert.SerializeObject(request);
            content  = new StringContent(jsonData, Encoding.UTF8, "application/json");

            if (request.PlantSize == "5")
            {
                int debug = 1;
            }

            Post("ImportPlant", content);
        }
Exemple #21
0
 public PlantDTO AddPlant(PlantDTO plant)
 {
     throw new NotImplementedException();
 }
Exemple #22
0
        public void AddPlant()
        {
            long image_id = 0;

            try
            {
                List <string> errorMsgs = new List <string>();

                KeyValuePair <long, string> p = (KeyValuePair <long, string>) this.PlantNames.SelectedValue;

                long   plantNameId            = p.Key;
                String plantName              = p.Value;
                long   selectedPlantTypeIndex = ((KeyValuePair <long, string>) this.PlantTypes.SelectedValue).Key;
                //long selectedServiceCode = ((KeyValuePair<long, string>)this.ServiceCodes.SelectedValue).Key;

                if (String.IsNullOrEmpty(plantName))
                {
                    errorMsgs.Add("You must enter a plant name.");
                }

                if (selectedPlantTypeIndex == 0)
                {
                    errorMsgs.Add("You must select a plant type.");
                }

                //if(selectedServiceCode == 0)
                //{
                //    errorMsgs.Add("You must select a service code.");
                //}

                if (fileStreamContent == null)
                {
                    MessageBoxResult msgBoxResult = MessageBox.Show("Do you want to add an image?");

                    if (msgBoxResult == MessageBoxResult.Yes)
                    {
                        return;
                    }
                }

                if (errorMsgs.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (string msg in errorMsgs)
                    {
                        sb.AppendLine(msg);
                    }

                    MessageBox.Show(sb.ToString());
                    return;
                }

                AddPlantRequest addPlantRequest = new AddPlantRequest();

                //save image if the user has selected one
                if (fileStreamContent != null)
                {
                    var url = "http://localhost:9000/api/Login/UploadPlantImage";
                    fileStreamContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data")
                    {
                        Name = "file", FileName = fileName
                    };
                    fileStreamContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
                    using (var client1 = new HttpClient())
                    {
                        using (var formData = new MultipartFormDataContent())
                        {
                            client1.DefaultRequestHeaders.Add("EO-Header", wnd.User + " : " + wnd.Pwd);

                            formData.Add(fileStreamContent);
                            var    response   = client1.PostAsync(url, formData).Result;
                            string strImageId = response.Content.ReadAsStringAsync().Result;

                            Int64.TryParse(strImageId, out image_id);
                        }
                    }
                }

                PlantDTO pDTO = new PlantDTO();
                pDTO.PlantName        = plantName;
                pDTO.PlantTypeId      = selectedPlantTypeIndex;
                addPlantRequest.Plant = pDTO;

                InventoryDTO iDTO = new InventoryDTO();
                iDTO.InventoryName   = plantName;
                iDTO.InventoryTypeId = 1; //"Plants"
                //iDTO.ServiceCodeId = selectedServiceCode;

                addPlantRequest.Plant     = pDTO;
                addPlantRequest.Inventory = iDTO;
                if (image_id > 0)
                {
                    addPlantRequest.ImageId = image_id;
                }

                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri(((App)App.Current).LAN_Address);
                client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/json"));

                client.DefaultRequestHeaders.Add("EO-Header", wnd.User + " : " + wnd.Pwd);

                string jsonData = JsonConvert.SerializeObject(addPlantRequest);
                var    content  = new StringContent(jsonData, Encoding.UTF8, "application/json");
                HttpResponseMessage httpResponse = client.PostAsync("api/Login/AddPlant", content).Result;
                if (httpResponse.IsSuccessStatusCode)
                {
                    Stream       streamData = httpResponse.Content.ReadAsStreamAsync().Result;
                    StreamReader strReader  = new StreamReader(streamData);
                    string       strData    = strReader.ReadToEnd();
                    strReader.Close();
                    GetPlantResponse apiResponse = JsonConvert.DeserializeObject <GetPlantResponse>(strData);

                    if (apiResponse.Messages.Count > 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (KeyValuePair <string, List <string> > messages in apiResponse.Messages)
                        {
                            foreach (string msg in messages.Value)
                            {
                                sb.AppendLine(msg);
                            }
                        }

                        MessageBox.Show(sb.ToString());
                    }
                    else
                    {
                        list3.Add(apiResponse.PlantInventoryList.First());
                        this.PlantInventoryListView.ItemsSource = null;
                        this.PlantInventoryListView.ItemsSource = list3;
                    }
                }
                else
                {
                    MessageBox.Show("Error adding plant");
                }

                fileStreamContent = null;
            }
            catch (Exception ex)
            {
            }
        }
Exemple #23
0
 public void Post([FromBody] PlantDTO value)
 {
     _plantManager.Create(value);
 }
Exemple #24
0
 public void Create(PlantDTO item)
 {
     item.Id         = Guid.NewGuid().ToString();
     item.TimeStamps = DateTime.Now;
     _unitOfWork.EFRepository <Plant>().CreateAsync(_mapper.Map <Plant>(item));
 }
Exemple #25
0
 public void Put(string id, [FromBody] PlantDTO value)
 {
     _plantManager.Update(value);
 }
Exemple #26
0
 public long DoesPlantExist(PlantDTO plantDTO)
 {
     return(persistence.PlantExists(plantDTO));
 }
Exemple #27
0
 public void RemovePlant(PlantDTO plant)
 {
     throw new NotImplementedException();
 }
        private PlantDTO GetPlantDTO(KeyValuePair <int, List <ExcelRowData> > kvp)
        {
            PlantDTO dto = new PlantDTO();

            return(dto);
        }
 public void OpenInfo(PlantDTO context)
 {
     _events.PublishOnUIThread(new ClientConnectionViewModel(Controller, context, _events));
 }