Esempio n. 1
0
        public ActionResult Edit(TenantLocations tenantwarehouse)
        {
            if (ModelState.IsValid)
            {
                // get properties of tenant
                caTenant tenant = caCurrent.CurrentTenant();
                // get properties of user
                caUser user = caCurrent.CurrentUser();

                _tenantLocationServices.UpdateTenantLocation(tenantwarehouse, user.UserId, tenant.TenantId);

                return(RedirectToAction("Index"));
            }
            ViewBag.TenantLocations = LookupServices.GetAllWarehousesForTenant(CurrentTenantId, (int)tenantwarehouse.TenantId);

            ViewBag.AllTerminals = _terminalServices.GetAllTerminalsWithoutMobileLocationLinks(CurrentTenantId, tenantwarehouse.SalesTerminalId).Select(m => new SelectListItem()
            {
                Value = m.TerminalId.ToString(), Text = m.TerminalName + " " + m.TermainlSerial
            });
            ViewBag.AllDrivers = _employeeServices.GetAllEmployeesWithoutResourceLinks(CurrentTenantId, tenantwarehouse.SalesManUserId).Select(m => new SelectListItem()
            {
                Value = m.AuthUserId.ToString(), Text = m.SurName + " " + m.FirstName
            });

            return(View(tenantwarehouse));
        }
        public ActionResult Edit([Bind(Include = "TerminalId,TerminalName,TermainlSerial,WarehouseId,IsActive")] Terminals terminals)
        {
            // get properties of tenant
            caTenant tenant = caCurrent.CurrentTenant();

            // get properties of user
            caUser user = caCurrent.CurrentUser();

            // get current warehouse
            TenantLocations Warehouse = caCurrent.CurrentWarehouse();

            if (ModelState.IsValid)
            {
                Terminals newTerminal = _terminalServices.GetTerminalById(terminals.TerminalId);

                newTerminal.TerminalName   = terminals.TerminalName;
                newTerminal.TermainlSerial = terminals.TermainlSerial;
                newTerminal.WarehouseId    = terminals.WarehouseId;
                newTerminal.IsActive       = terminals.IsActive;

                _terminalServices.UpdateTerminal(newTerminal, user.UserId, tenant.TenantId);
                return(RedirectToAction("Index"));
            }
            ViewBag.WarehouseId = new SelectList(_tenantLocationServices.GetTenantLocationListById(Warehouse.WarehouseId, tenant.TenantId), "WarehouseId", "WarehouseName", terminals.WarehouseId);
            return(View(terminals));
        }
        // GET: Terminals/Edit/5
        public ActionResult Edit(int?id)
        {
            if (!caSession.AuthoriseSession())
            {
                return(Redirect((string)Session["ErrorUrl"]));
            }

            // get properties of tenant
            caTenant tenant = caCurrent.CurrentTenant();

            // get current warehouse
            TenantLocations Warehouse = caCurrent.CurrentWarehouse();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Terminals terminals = _terminalServices.GetTerminalById((int)id);

            if (terminals == null)
            {
                return(HttpNotFound());
            }

            ViewBag.WarehouseId = new SelectList(_tenantLocationServices.GetTenantLocationListById(Warehouse.WarehouseId, tenant.TenantId), "WarehouseId", "WarehouseName", terminals.WarehouseId);
            return(View(terminals));
        }
        public bool TryCreateTenantDirectory(string tenantName, Tenant tenantDetails)
        {
            try
            {
                if (Directory.Exists(TenantLocations.GetTenantDirectory(tenantName)) == true)
                {
                    // Update the file from the Server
                    tenantConfigFilesQueue.Enqueue(tenantDetails);
                    InitializeTenantConfigFileProcessor();
                    return(true);
                }

                Directory.CreateDirectory(TenantLocations.GetTenantDirectory(tenantName));
                Directory.CreateDirectory(TenantLocations.GetProductRootDirectory(tenantName));
                Directory.CreateDirectory(TenantLocations.GetTenantLogsRootDirectory(tenantName));

                tenantConfigFilesQueue.Enqueue(tenantDetails);
                InitializeTenantConfigFileProcessor();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 5
0
 public void DeleteTenantLocation(TenantLocations tenantLocations, int userId)
 {
     tenantLocations.IsDeleted   = true;
     tenantLocations.UpdatedBy   = userId;
     tenantLocations.DateUpdated = DateTime.UtcNow;
     _currentDbContext.Entry(tenantLocations).State = EntityState.Modified;
     _currentDbContext.SaveChanges();
 }
Esempio n. 6
0
 public void UpdateTenantLocation(TenantLocations tenantLocations, int userId, int tenantId)
 {
     tenantLocations.DateUpdated                    = DateTime.UtcNow;
     tenantLocations.UpdatedBy                      = userId;
     tenantLocations.TenantId                       = tenantId;
     tenantLocations.PalletTrackingScheme           = tenantLocations.PalletTrackingScheme;
     _currentDbContext.Entry(tenantLocations).State = EntityState.Modified;
     _currentDbContext.SaveChanges();
 }
 public async static void WriteInTenantLog(string tenantName, string rowLog)
 {
     try
     {
         await File.AppendAllTextAsync(TenantLocations.GetTenantTodayLogFile(tenantName), $"{rowLog}\n");
     }
     catch (Exception)
     {
         // TODO: handle this exception
     }
 }
Esempio n. 8
0
        public int SaveTenantLocation(TenantLocations tenantLocations, int userId, int tenantId)
        {
            tenantLocations.DateCreated = DateTime.UtcNow;
            tenantLocations.DateUpdated = DateTime.UtcNow;
            tenantLocations.CreatedBy   = userId;
            tenantLocations.UpdatedBy   = userId;
            tenantLocations.TenantId    = tenantId;

            _currentDbContext.Entry(tenantLocations).State = EntityState.Added;
            _currentDbContext.SaveChanges();
            return(tenantLocations.WarehouseId);
        }
Esempio n. 9
0
        public static TenantLocations CurrentWarehouse()
        {
            var context = DependencyResolver.Current.GetService <IApplicationContext>();

            int             CurrentWarehouseId;
            TenantLocations Warehouse = new TenantLocations();

            if (HttpContext.Current.Session["CurrentWarehouseId"] != null)
            {
                CurrentWarehouseId = (int)HttpContext.Current.Session["CurrentWarehouseId"];
                Warehouse          = context.TenantWarehouses.FirstOrDefault(e => e.WarehouseId == CurrentWarehouseId && e.IsDeleted != true);
            }
            return(Warehouse);
        }
        public bool TryUpdateTopicDirectory(string tenant, string product, string component, Topic topic)
        {
            try
            {
                if (Directory.Exists(TenantLocations.GetTopicDirectory(tenant, product, component, topic.Name)) != true)
                {
                    Directory.CreateDirectory(TenantLocations.GetTopicDirectory(tenant, product, component, topic.Name));
                }
                if (Directory.Exists(TenantLocations.GetConsumerRootDirectory(tenant, product, component, topic.Name)) != true)
                {
                    Directory.CreateDirectory(TenantLocations.GetConsumerRootDirectory(tenant, product, component, topic.Name));
                }
                if (Directory.Exists(TenantLocations.GetProducerRootDirectory(tenant, product, component, topic.Name)) != true)
                {
                    Directory.CreateDirectory(TenantLocations.GetProducerRootDirectory(tenant, product, component, topic.Name));
                }
                if (Directory.Exists(TenantLocations.GetTopicLogRootDirectory(tenant, product, component, topic.Name)) != true)
                {
                    Directory.CreateDirectory(TenantLocations.GetTopicLogRootDirectory(tenant, product, component, topic.Name));
                }
                if (Directory.Exists(TenantLocations.GetIndexRootDirectory(tenant, product, component, topic.Name)) != true)
                {
                    Directory.CreateDirectory(TenantLocations.GetIndexRootDirectory(tenant, product, component, topic.Name));
                }
                if (Directory.Exists(TenantLocations.GetMessageRootDirectory(tenant, product, component, topic.Name)) != true)
                {
                    Directory.CreateDirectory(TenantLocations.GetMessageRootDirectory(tenant, product, component, topic.Name));
                }

                if (File.Exists(TenantLocations.GetTopicConfigFile(tenant, product, component, topic.Name)) != true)
                {
                    // Because this call is triggered by XNode in only in an agent in storage, it doesn't need to go thru a queue.
                    TenantWriter.WriteTopicConfigFile(tenant, product, component, topic);
                    return(true);
                }

                // Do not update the topic schema
                //Topic fromFile = TenantReader.ReadTopicConfigFile(tenant, product, component, topic.Name);
                //fromFile.Schema = topic.Schema;
                //TenantWriter.WriteTopicConfigFile(tenant, product, component, fromFile);

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
        }
        // GET: Terminals/Create
        public ActionResult Create()
        {
            if (!caSession.AuthoriseSession())
            {
                return(Redirect((string)Session["ErrorUrl"]));
            }

            // get properties of tenant
            caTenant tenant = caCurrent.CurrentTenant();

            // get current warehouse
            TenantLocations Warehouse = caCurrent.CurrentWarehouse();

            ViewBag.WarehouseId = new SelectList(_tenantLocationServices.GetTenantLocationListById(Warehouse.WarehouseId, tenant.TenantId), "WarehouseId", "WarehouseName", Warehouse.WarehouseId);
            return(View());
        }
Esempio n. 12
0
        public static bool WriteTopicConfigFile(string tenant, string product, string component, Topic topic)
        {
            try
            {
                if (File.Exists(TenantLocations.GetTopicConfigFile(tenant, product, component, topic.Name)))
                {
                    File.Delete(TenantLocations.GetTopicConfigFile(tenant, product, component, topic.Name));
                }

                File.WriteAllText(TenantLocations.GetTopicConfigFile(tenant, product, component, topic.Name), topic.ToPrettyJson());
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 13
0
        public static bool WriteProductConfigFile(string tenant, Product product)
        {
            try
            {
                if (File.Exists(TenantLocations.GetProductConfigFile(tenant, product.Name)))
                {
                    File.Delete(TenantLocations.GetProductConfigFile(tenant, product.Name));
                }

                File.WriteAllText(TenantLocations.GetProductConfigFile(tenant, product.Name), product.ToPrettyJson());
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 14
0
        public static bool WriteTenantConfigFile(Tenant tenant)
        {
            try
            {
                if (File.Exists(TenantLocations.GetTenantConfigFile(tenant.Name)))
                {
                    File.Delete(TenantLocations.GetTenantConfigFile(tenant.Name));
                }

                File.WriteAllText(TenantLocations.GetTenantConfigFile(tenant.Name), tenant.ToPrettyJson());
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 15
0
        public static List <Consumer> ReadAllConsumers()
        {
            List <Consumer> consumersResult = new List <Consumer>();

            if (Directory.Exists(SystemLocations.GetTenantRootDirectory()) != true)
            {
                return(consumersResult);
            }

            string[] tenants = Directory.GetDirectories(SystemLocations.GetTenantRootDirectory());
            foreach (var tenantLocation in tenants)
            {
                // go on every product
                string   tenant   = Path.GetFileName(tenantLocation);
                string[] products = Directory.GetDirectories(TenantLocations.GetProductRootDirectory(tenant));
                foreach (var productLocation in products)
                {
                    string product = Path.GetFileName(productLocation);
                    if (product == "logs")
                    {
                        continue;
                    }

                    string[] components = Directory.GetDirectories(TenantLocations.GetComponentRootDirectory(tenant, product));
                    foreach (var componentLocation in components)
                    {
                        string component = Path.GetFileName(componentLocation);

                        string[] topics = Directory.GetDirectories(TenantLocations.GetTopicRootDirectory(tenant, product, component));
                        foreach (var topicLocation in topics)
                        {
                            string   topic     = Path.GetFileName(topicLocation);
                            string[] consumers = Directory.GetDirectories(TenantLocations.GetConsumerRootDirectory(tenant, product, component, topic));
                            foreach (var consumerLocation in consumers)
                            {
                                string consumer = Path.GetFileName(consumerLocation);
                                consumersResult.Add(ReadConsumerConfigFile(tenant, product, component, topic, consumer));
                            }
                        }
                    }
                }
            }

            return(consumersResult);
        }
Esempio n. 16
0
        public ActionResult DeleteConfirmed(int id)
        {
            if (!caSession.AuthoriseSession())
            {
                return(Redirect((string)Session["ErrorUrl"]));
            }


            TenantLocations tenantwarehouse = _tenantLocationServices.GetTenantLocationById((int)id);


            // get properties of tenant
            caTenant tenant = caCurrent.CurrentTenant();
            // get properties of user
            caUser user = caCurrent.CurrentUser();

            _tenantLocationServices.DeleteTenantLocation(tenantwarehouse, user.UserId);
            return(RedirectToAction("Index"));
        }
Esempio n. 17
0
        // GET: /Warehouse/Delete/5
        public ActionResult Delete(int?id)
        {
            if (!caSession.AuthoriseSession())
            {
                return(Redirect((string)Session["ErrorUrl"]));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TenantLocations tenantwarehouse = _tenantLocationServices.GetTenantLocationById((int)id);

            if (tenantwarehouse == null)
            {
                return(HttpNotFound());
            }
            return(View(tenantwarehouse));
        }
        public bool TryCreateComponentDirectory(string tenant, string product, Component component)
        {
            try
            {
                if (Directory.Exists(TenantLocations.GetComponentDirectory(tenant, product, component.Name)) == false)
                {
                    Directory.CreateDirectory(TenantLocations.GetComponentDirectory(tenant, product, component.Name));
                    Directory.CreateDirectory(TenantLocations.GetTopicRootDirectory(tenant, product, component.Name));

                    // Because this call is triggered by XNode in only in an agent in storage, it doesn't need to go thru a queue.
                    TenantWriter.WriteComponentConfigFile(tenant, product, component);
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 19
0
        // GET: /Warehouse/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (!caSession.AuthoriseSession())
            {
                return(Redirect((string)Session["ErrorUrl"]));
            }

            TenantLocations tenantwarehouse = _tenantLocationServices.GetTenantLocationById((int)id);

            if (tenantwarehouse == null)
            {
                return(HttpNotFound());
            }
            ViewBag.TenantLocations = LookupServices.GetAllWarehousesForTenant(CurrentTenantId, (int)id).Select(m => new SelectListItem()
            {
                Value = m.WarehouseId.ToString(), Text = m.WarehouseName
            });
            ViewBag.AllVehicles = _marketServices.GetAllValidMarketVehicles(CurrentTenantId).MarketVehicles.Select(m => new SelectListItem()
            {
                Value = m.Id.ToString(), Text = m.Name
            });
            ViewBag.CountryId = new SelectList(LookupServices.GetAllGlobalCountries(), "CountryId", "CountryName", tenantwarehouse.CountryID);

            ViewBag.AllTerminals = _terminalServices.GetAllTerminalsWithoutMobileLocationLinks(CurrentTenantId, tenantwarehouse.SalesTerminalId).Select(m => new SelectListItem()
            {
                Value = m.TerminalId.ToString(), Text = m.TerminalName + " " + m.TermainlSerial
            });
            ViewBag.AllDrivers = _employeeServices.GetAllEmployeesWithoutResourceLinks(CurrentTenantId, tenantwarehouse.SalesManUserId).Select(m => new SelectListItem()
            {
                Value = m.AuthUserId.ToString(), Text = m.SurName + " " + m.FirstName
            });

            return(View(tenantwarehouse));
        }
Esempio n. 20
0
        public ActionResult Create(TenantLocations tenantwarehouse)
        {
            if (!caSession.AuthoriseSession())
            {
                return(Redirect((string)Session["ErrorUrl"]));
            }

            if (ModelState.IsValid)
            {
                // get properties of tenant
                caTenant tenant = caCurrent.CurrentTenant();
                // get properties of user
                caUser user = caCurrent.CurrentUser();

                _tenantLocationServices.SaveTenantLocation(tenantwarehouse, user.UserId, tenant.TenantId);

                return(RedirectToAction("Index"));
            }
            ViewBag.TenantLocations = LookupServices.GetAllWarehousesForTenant(CurrentTenantId).Select(m => new SelectListItem()
            {
                Value = m.WarehouseId.ToString(), Text = m.WarehouseName
            });
            ViewBag.CountryId   = new SelectList(LookupServices.GetAllGlobalCountries(), "CountryId", "CountryName");
            ViewBag.AllVehicles = _marketServices.GetAllValidMarketVehicles(CurrentTenantId).MarketVehicles.Select(m => new SelectListItem()
            {
                Value = m.Id.ToString(), Text = m.Name
            });

            ViewBag.AllTerminals = _terminalServices.GetAllTerminalsWithoutMobileLocationLinks(CurrentTenantId).Select(m => new SelectListItem()
            {
                Value = m.TerminalId.ToString(), Text = m.TerminalName + " " + m.TermainlSerial
            });
            ViewBag.AllDrivers = _employeeServices.GetAllEmployeesWithoutResourceLinks(CurrentTenantId).Select(m => new SelectListItem()
            {
                Value = m.AuthUserId.ToString(), Text = m.SurName + " " + m.FirstName
            });

            return(View(tenantwarehouse));
        }
Esempio n. 21
0
        private List <MessageFile> GetPartitionFiles(string tenant, string product, string component, string topic)
        {
            List <MessageFile> messages = new List <MessageFile>();

            string[] partitions = Directory
                                  .GetFiles(TenantLocations.GetMessageRootDirectory(tenant, product, component, topic), "*.xandy");

            Array.ForEach(partitions, partition =>
            {
                string fileName = Path.GetFileNameWithoutExtension(partition);
                string[] partitionNameSplited = fileName.Split("_");

                var partitionDate = DateTime.Parse($"{partitionNameSplited[2]}-{partitionNameSplited[3]}-{partitionNameSplited[4]}");

                messages.Add(new MessageFile()
                {
                    Path = partition, PartitionDate = partitionDate
                });
            });

            List <MessageFile> sorted = messages.OrderBy(m => m.PartitionDate).ToList();

            return(sorted);
        }
Esempio n. 22
0
 public static Topic ReadTopicConfigFile(string tenant, string product, string component, string topic)
 {
     return(File
            .ReadAllText(TenantLocations.GetTopicConfigFile(tenant, product, component, topic))
            .JsonToObjectAndDecrypt <Topic>());
 }