Exemplo n.º 1
0
 public void Add(Computer computer, int?quantity = 1)
 {
     for (var i = 0; i < quantity; i++)
     {
         Computers.Add(computer);
     }
 }
Exemplo n.º 2
0
        public async Task ScanAsync(string[] folders)
        {
            if (folders != null)
            {
                foreach (string path in folders)
                {
                    DirectoryInfo root = new DirectoryInfo(path).Root;
                    Computer      computer;
                    bool          isNetworkShare = Drive.IsNetworkPath(path);
                    if (isNetworkShare)
                    {
                        string machineName = Drive.GetMachineName(path);
                        computer = Computers.SingleOrDefault(c => c.NameEquals(machineName));
                        if (computer == null)
                        {
                            computer = new Computer()
                            {
                                Name = machineName
                            };
                            computer.Folders = new List <Folder>();
                            Computers.Add(computer);
                        }
                    }
                    else
                    {
                        computer = _localComputer;
                    }

                    bool       isDrive = root.FullName.Equals(path, StringComparison.OrdinalIgnoreCase);
                    DriveModel drive   = computer.Drives.SingleOrDefault(f => f.NameEquals(root.Name));
                    bool       isNew   = drive == null;
                    if (isNew)
                    {
                        string    name;
                        DriveType driveType;
                        if (isNetworkShare)
                        {
                            name      = Drive.GetDriveLetter(path);
                            driveType = Drive.NETWORK_SHARE;
                        }
                        else
                        {
                            name      = root.Name;
                            driveType = DriveType.Network;
                        }
                        drive = new DriveModel(computer, name, DateTime.UtcNow, driveType);
                        drive.Folders.Clear();
                        computer.Folders.Add(drive);
                        computer.Folders = new List <Folder>(computer.Folders);
                        computer.RaiseItemChanges();
                    }
                    if (!isDrive)
                    {
                        drive.Load();
                    }
                    await ScanAsync(path, isDrive, drive, computer);
                }
            }
        }
Exemplo n.º 3
0
        private void GetComputerInfo(string s)
        {
            try
            {
                var name  = tName.Text.Trim();
                var price = int.Parse(tPrice.Text.Trim());
                var piece = int.Parse(tPiece.Text.Trim());
                var date  = tDate.Text.Trim();
                var brand = tBrand.Text.Trim();
                var gpu   = tGPU.Text.Trim();
                var cpu   = tCPU.Text.Trim();
                var ram   = int.Parse(tRAM.Text.Trim());
                var ss    = float.Parse(tSS.Text.Trim());
                var os    = tOS.Text.Trim();
                var fs    = new FileStream(imgLoc, FileMode.Open, FileAccess.Read);
                var br    = new BinaryReader(fs);
                img = br.ReadBytes((int)fs.Length);

                switch (s)
                {
                case "add":
                {
                    var result = _comp.GetByName(name, "Computers");

                    if (result.Rows.Count > 0)
                    {
                        lberror.ForeColor = Color.Red;
                        lberror.Text      = CommonFunctions.ReturnString("exist");
                    }

                    else
                    {
                        _comp.Add(name, gpu, price, piece, date, brand, cpu, ram, ss, os);
                        _product.AddImage(int.Parse(_product.GetByName(name, "Computers").Rows[0][0].ToString()), img, "Computers");
                        lberror.ForeColor = Color.Green;
                        lberror.Text      = CommonFunctions.ReturnString("success");
                    }

                    break;
                }

                case "update":
                {
                    var id = int.Parse(tID.Text.Trim());

                    _comp.Update(id, name, gpu, price, piece, date, brand, cpu, ram, ss, os);
                    _comp.AddImage(id, img, "Computers");
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        public void AddItemCommand()
        {
            Computers = Computers;
            if (Computers == null)
            {
                Computers = new ObservableCollection <ComputerModel>();
            }
            Computers.Add(new ComputerModel());

            _executedComputer = Computers.Count;
            _totalComputer    = Computers.Count;
        }
Exemplo n.º 5
0
        private void CreateComputer()
        {
            var computer = new Computer();

            computer.X = 0;
            computer.Y = 0;

            computer.IsNew = true;

            Computers.Add(computer);

            SelectedObject = computer;
        }
 public string VoegComputerToe(Computer c)
 {
     //GetIpAdres(c);
     if (GetIpAdres(c))
     {
         Computers.Add(c.MAC, c);
         return("De computer werd aan het netwerk gekoppeld");
     }
     else
     {
         c.IPaddress = "0.0.0.0";
         return("Geen IP adres beschikbaar");
     }
 }
Exemplo n.º 7
0
        public void LoadFile()
        {
            var fileName = _dialogService.OpenFileDialog();

            if (fileName != null)
            {
                List <Computer> ComputerList = _xmlComputerReader.ReadBooks(fileName);
                foreach (var computer in ComputerList)
                {
                    Computers.Add(computer);
                }
            }
            saveToOtherFile = true; // po załadowaniu bazy zabraniamy zapisu do bazy podstawowej
        }
Exemplo n.º 8
0
 private void AddNewComputer()
 {
     Computers.Add(new Computer(NewComp));
     if (saveToOtherFile == false)
     {
         var fileName = @"serwis.xml";
         if (fileName != null)
         {
             List <Computer> ComputerList = new List <Computer>();
             foreach (var computer in Computers)
             {
                 ComputerList.Add(computer);
             }
             _xmlComputerWriter.WriteComputers(fileName, ComputerList);
         }
     }
 }
Exemplo n.º 9
0
 public string AddComputer(string indificator, string iP, string description, string name, string domen, int working_GroupID, int peopleID)
 {
     try
     {
         Computer computer = new Computer()
         {
             Indificator     = indificator,
             IP              = iP,
             Description     = description,
             Domen           = domen,
             Name            = name,
             Working_GroupID = working_GroupID,
             PeopleID        = peopleID
         };
         Computers.Add(computer);
         Working_Groups.FirstOrDefault(i => i.Working_GroupID == working_GroupID).Computers.Add(computer);
         SaveChanges();
         return("Запись успешно добавлена");
     }
     catch (Exception ex) { return(ex.Message); }
 }
Exemplo n.º 10
0
        public void LoadFile(string path)
        {
            if (File.Exists(path))
            {
                using (StreamReader sr = new StreamReader(path, Encoding.Default))
                {
                    Computers.Clear();
                    Computer myComputer = new Computer();

                    string line = "";

                    while ((line = sr.ReadLine()) != null)
                    {
                        if (!line.StartsWith("#"))
                        {
                            if (line.IndexOf(";") >= 0)
                            {
                                string[] fields = line.Split(';');
                                myComputer = new Computer();
                                myComputer.ComputerName = fields[0];
                                myComputer.IPAddress    = fields[1];
                                myComputer.MACAddress   = fields[2];
                                myComputer.SubPool      = Convert.ToInt32(fields[3]);
                                myComputer.PreSelected  = false;
                                if (fields.Length == 5)
                                {
                                    if (fields[4].IndexOf("1") >= 0)
                                    {
                                        myComputer.PreSelected = true;
                                    }
                                }
                                Computers.Add(myComputer);
                            }
                        }
                    }
                }
                SetPreselected();
            }
        }
Exemplo n.º 11
0
 public void InputComputers(Computer newComputer)
 {
     Computers.Add(newComputer);
 }
Exemplo n.º 12
0
 public void Add(CtrlComputer ThisComputer)
 {
     Computers.Add(ThisComputer);
 }
Exemplo n.º 13
0
 public void AddComputer(Computer computer)
 {
     Computers.Add(computer);
 }
Exemplo n.º 14
0
        private async Task ScanLan_AsyncBody()
        {
            Status = AddComputersVM.Statuses.IsSearching;
            List <string> list = null;
            string        networkScanMethod = ViewModel.Instance.Workers.NetworkScanMethod;

            CancelSource = new CancellationTokenSource();
            var token = CancelSource.Token;

            switch (networkScanMethod)
            {
            case "NetApi32":
                list = await Task.Run(() =>
                                      (new NetworkBrowser()).GetNetworkComputers()
                                      ).WithCancellation(token);

                break;

            case "ArpTable":
                list = await Task.Run(async() => {
                    var ipList = ArpTable.GetIpAddresses();
                    if (ipList == null)
                    {
                        return(null);
                    }
                    var hostNames = await ArpTable.GetHostNames(ipList).WithCancellation(token);
                    return(hostNames);
                });

                break;
            }
            if (list == null || list.Count == 0)
            {
                Status = AddComputersVM.Statuses.NothingFound;

                string message     = "No LAN computer was detected.";
                string alternative = " Or you may select an alternative network scan method, this will re-initiate the search.";
                switch (networkScanMethod)
                {
                case "NetApi32":
                    message += " Check your cable and network settings and run \"net view\" CMD command to see if Windows actually sees anything on the network."
                               + alternative;
                    break;

                case "ArpTable":
                    message += " Check your cable and network settings and run \"arp -a\" CMD command to see if Windows actually detects any LAN IP."
                               + alternative;
                    break;

                default:
                    message = "Incorrect setting detected. Workers.cfg must contain either \"GetComputerNamesMethod\":\"NetApi32\" or \"GetComputerNamesMethod\":\"ArpTable\".";
                    break;
                }

                await Task.Delay(100);

                MessageBox.Show(message, "Nothing found", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            Computers.Clear();
            foreach (var entry in list)
            {
                dynamic pc = new ExpandoObject();
                pc.Name       = entry as string;
                pc.IsSelected = false;
                Computers.Add(pc);
            }
            Status = Statuses.Ready;
        }