Пример #1
0
        public string CheckSettings()
        {
            bool[] b = new bool[4];


            var ipAddresses = new List <Ip>();

            foreach (var dest in Destinations)
            {
                if (Destinations.Count(d => d.IOAPrefix == dest.IOAPrefix) > 1)
                {
                    b[1] = true;
                }
                if (Destinations.Count(d => d.Name == dest.Name) > 1)
                {
                    b[2] = true;
                }

                ipAddresses.AddRange(dest.IpAddresses);
            }

            foreach (var ipAddress in AllowedIPAddresses)
            {
                if (AllowedIPAddresses.Count(ip => Equals(ip, ipAddress)) > 1)
                {
                    b[3] = true;
                }
            }

            foreach (var ipAddress in ipAddresses)
            {
                if (ipAddresses.Count(ip => Equals(ip, ipAddress)) > 1)
                {
                    b[3] = true;
                }
            }

            string result = "";

            if (b[1])
            {
                result += $"Несколько направлений с одним префиксом.{Environment.NewLine}";
            }
            if (b[2])
            {
                result += $"Несколько направлений с одним названием.{Environment.NewLine}";
            }
            if (b[3])
            {
                result += $"IP-адреса не должны дублироваться.{Environment.NewLine}";
            }

            if (result == "")
            {
                return(null);
            }

            return(result);
        }
Пример #2
0
        internal async Task <bool> CheckDestinationsConnection(bool promptWithDialogToContinue)
        {
            int missingDestinations = 0;

            foreach (string destination in Destinations)
            {
                if (!System.IO.Directory.Exists(destination))
                {
                    missingDestinations++;
                }
            }


            if (missingDestinations == Destinations.Count())
            {
                var view = new AlertView
                {
                    DataContext = new AlertViewModel("All destinations are missing. Add a destination.")
                };
                await DialogHost.Show(view, "RootDialog");

                return(false);
            }

            if (missingDestinations > 0)
            {
                var view = new ConfirmChoiceView
                {
                    DataContext = new ConfirmChoiceViewModel("Bachup With Missing?",
                                                             "There are destinations missing. You can choose to bachup with connected destinations.")
                };
                return((bool)await DialogHost.Show(view, "RootDialog"));
            }

            int brokenDestinaitons = 0;

            foreach (var tempFile in from string destination in Destinations
                     let tempFile = Path.Combine(destination, "bachup.tmp")
                                    select tempFile)
            {
                try
                {
                    using (FileStream fs = new FileStream(tempFile, FileMode.Create, FileAccess.Write))
                    {
                        fs.WriteByte(0xFF);
                    }

                    if (File.Exists(tempFile))
                    {
                        File.Delete(tempFile);
                    }
                    else
                    {
                        brokenDestinaitons++;
                    }
                }
                catch
                {
                    brokenDestinaitons++;
                }
            }



            if (brokenDestinaitons == Destinations.Count())
            {
                var view = new AlertView
                {
                    DataContext = new AlertViewModel("All destinations are broken. Add a destination.")
                };
                await DialogHost.Show(view, "RootDialog");

                return(false);
            }

            if (brokenDestinaitons > 0)
            {
                var view = new ConfirmChoiceView
                {
                    DataContext = new ConfirmChoiceViewModel("Continue?",
                                                             "There are destinations that have no access. Continue with ones that do?")
                };
                return((bool)await DialogHost.Show(view, "RootDialog"));
            }

            return(true);
        }