Пример #1
0
        // GET api/account
        public List<Customer> GetCustomers(Boolean populateComputers = false, Boolean populateUsage = false, String vault = null)
        {
            Result result = new Result();
            try
            {

                ConnectionInfo connInfo = setConnectionInfo(vault);

                SbeAccountManager.CManagerClass com = new SbeAccountManager.CManagerClass();
                SbeAccountManager.ICustomerCollection customerList;
                SbeAccountManager.CVaultConnectionClass v = new SbeAccountManager.CVaultConnectionClass();

                v.Address = connInfo.Address;
                v.DefaultRaidArea = connInfo.DefaultRaidArea;
                v.DefaultWorkArea = connInfo.DefaultWorkArea;
                v.Description = connInfo.Description;
                v.Domain = connInfo.Domain;
                v.Password = connInfo.ConnectionPassword;
                v.userName = connInfo.ConnectionUser;

                com.LogFileName = connInfo.LogFileName;
                com.AuditFileName = connInfo.AuditFileName;

                customerList = (SbeAccountManager.ICustomerCollection)com.getCustomerList(v);

                List<Customer> customers = new List<Customer>();

                //unfortunately we have to iterate through the list to find the match
                foreach (SbeAccountManager.ICustomer cust in customerList)
                {
                    Customer customer = new Customer();

                    // set account properties
                    customer.CustomerName = cust.Name;
                    customer.ShortName = cust.ShortName;
                    customer.CustomerEmail = cust.Email;
                    customer.Address = cust.Address;
                    customer.CustomerCity = cust.City;
                    customer.CustomerContactName =cust.ContactPerson;
                    customer.CustomerZipCode = cust.ZipCode;
                    customer.VaultName = connInfo.VaultName;
                    customer.CustomerState = cust.State;
                    customer.CustomerCountry = cust.Country;

                    customers.Add(customer);

                    //int qty = 0;
                    //List<Product> products = new List<Product>();
                    //foreach (Product product in GetProductList())
                    //{

                    //    qty = 0;
                    //    qty = (int)com.GetCustomerQuota(v, customer, product.QuotaType);
                    //    if (qty < 0) qty = 0;
                    //    product.Quantity = qty;
                    //    products.Add(product);

                    //}

                    //customer.Products = products;

                    if (populateComputers == false) continue;

                    SbeAccountManager.ICollection locations;
                    locations = com.getLocationList(v, cust.Id);
                    List<Computer> computerList = new List<Computer>();

                    foreach (SbeAccountManager.ILocation location in locations)
                    {
                        // get computers
                        SbeAccountManager.ICollection computers = com.getComputerList(v, location.Id);

                        customer.BillingCode = location.BillingCode;

                        foreach (SbeAccountManager.IComputer comp in computers)
                        {
                            Computer computer = new Computer();
                            computer.AgentType = comp.AgentType.ToString();
                            computer.AgentVersion = comp.AgentVersion;
                            computer.IpAddress = comp.IpAddress;
                            computer.Domain = comp.Domain;
                            computer.Name = comp.Name;
                            computer.OsType = comp.OsType;
                            computer.OsVersion = comp.OsVersion;

                            computerList.Add(computer);

                            if (populateUsage == false) continue;

                            // get tasks
                            SbeAccountManager.ICollection tasks_ = com.getTaskList(v, comp.Id);
                            List<Task> tasks = new List<Task>();
                            long totalCompressedSize = 0;
                            long totalOriginalSize = 0;
                            foreach (SbeAccountManager.ITask task_ in tasks_)
                            {
                                Task task = new Task();
                                task.Name = task_.Name;
                                task.Id = task_.Id;
                                task.IsActive = task_.IsActive;
                                task.PhysicalPoolSize = task_.PhysicalPoolSize;
                                task.UsedPoolSize = task_.UsedPoolSize;
                                tasks.Add(task);

                                // get safe set
                                SbeAccountManager.ICollection safeSets = com.getSafesetList(v, task_.Id);

                                foreach (SbeAccountManager.ISafeset safeSet in safeSets)
                                {
                                    totalCompressedSize += safeSet.StorageBytes;
                                    totalOriginalSize += safeSet.OriginalBytes;

                                }

                            }

                            computer.Tasks = tasks;
                            computer.TotalCompressedSize = totalCompressedSize;
                            computer.TotalOriginalSize = totalOriginalSize;

                        }

                        customer.Computers = computerList;
                    }

                }

                return customers;
            }
            catch (Exception exception)
            {

                throw exception;

            }
        }