示例#1
0
        public void InsertingNewPackageShouldNotThrow()
        {
            var pack = CreateTestPackage();

            Assert.DoesNotThrow(() => _packageManager.AddPackage(pack));
            Assert.DoesNotThrow(() => _packageManager.RemovePackage(pack));
        }
示例#2
0
        private void Save(object sender, RoutedEventArgs e)
        {
            var pckName      = PackageName.Text;
            var pckCategory  = Cateogry.SelectedItem.ToString();
            var pckIncluded  = Included.Text;
            var pckTransport = Transport.Text;
            var pckPrice     = Convert.ToDouble(Price.Text);
            var pckBeginDate = BeginDate.Date.DateTime;
            var pckEndDate   = EndDate.Date.DateTime;

            if (pckName == null || pckCategory == null || pckIncluded == null || pckTransport == null || pckPrice == null)
            {
                var messageDialog = new MessageDialog("Please complete all fields before saving!");
                messageDialog.ShowAsync();
            }

            if (pckBeginDate.Equals(pckEndDate))
            {
                var messageDialog = new MessageDialog("Begin Date must be different from End Date");
                messageDialog.ShowAsync();
            }

            var package = new Package(pckName, pckCategory, pckIncluded, pckTransport, pckPrice, 0, 0,
                                      pckBeginDate, pckEndDate, _image);


            _packageManager.AddPackage(package);
        }
示例#3
0
    void LocalClientUpdate()
    {
        if (!isLocalPlayer)
        {
            return;
        }
        if ((Input.GetAxis("Horizontal") * moveSpeed) != 0 || (Input.GetAxis("Vertical") * moveSpeed) != 0)
        {
            float timeStep = Time.time;
            PackageManager.AddPackage(new Package
            {
                Horizontal = Input.GetAxis("Horizontal"),
                Vertical   = Input.GetAxis("Vertical"),
                Timestamp  = timeStep
            });

            if (isPredictionEnabled)
            {
                Move((Input.GetAxis("Horizontal") * moveSpeed), (Input.GetAxis("Vertical") * moveSpeed));
                predictedPackages.Add(new ReceivePackage
                {
                    Timestamp = timeStep,
                    X         = transform.position.x,
                    Y         = transform.position.y,
                    Z         = transform.position.z
                });
            }
        }
    }
示例#4
0
        public void InsertingNewPackageShouldNotThrow()
        {
            var pack = CreateTestPackage();

            Assert.DoesNotThrow(() => _packageManager.AddPackage(pack));
            var idPack = _dbWrapper.QueryValue <int>(string.Format("Select Id From Packages Where Name='{0}'", pack.Name));

            pack.ID = idPack;
            Assert.DoesNotThrow(() => _packageManager.RemovePackage(pack));
        }
        public ActionResult Create(PackageModel package)
        {
            try
            {
                string item = Request.Form.GetValues("Items") != null?Request.Form.GetValues("Items")[0] : "";

                package.Item = ItemManager.GetItemByID(int.Parse(item.ToString()), "nirshan");
                PackageManager.AddPackage(Utility.convertSrcToTarget <PackageModel, Package>(package), "nirshan");

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
示例#6
0
 //Отправка
 private void send(Package package, int port)
 {
     //Проверяем, находится ли получатель в той же подсети
     if (InterfaceAdresses[port].IsInSameSubnet(package.EndIP.Peek()))
     {
         send(port, package);
     }
     else
     {
         string stage = Name + " (" + InterfaceAdresses[port] + ") DIDN'T send package " + package + " to " + ConnectedDevices[port].Name + ": OTHER SUBNET";
         Logger.WriteLine(stage);
         package.AddStage(stage);
         package.PackageState = Package.State.REJECTED;
         PackageManager.AddPackage(package);
     }
 }
示例#7
0
        //----------------------------------------------

        //Отправляет пакет
        protected void send(int port, Package package)
        {
            if (!ConnectedDevices.ContainsKey(port))
            {
                throw new ArgumentException("Device to this port not connected");
            }

            //Логгирование маршрутов пакетов
            PackageManager.AddPackage(package);

            String stage;

            if (InterfaceAdresses != null)
            {
                stage = TraceToString(Name, InterfaceAdresses[port], port, ConnectedDevices[port].Name, package);
            }
            else
            {
                stage = TraceToString(Name, null, port, ConnectedDevices[port].Name, package);
            }

            Logger.WriteLine(stage);
            package.AddStage(stage);

            if (SendingDrawDelay == 0)
            {
                _send(port, package);
            }
            else
            {
                //Используется таймер с задержкй
                var timer = new System.Timers.Timer(SendingDrawDelay);
                timer.Elapsed += new System.Timers.ElapsedEventHandler(delegate(object sender, ElapsedEventArgs args)
                {
                    _send(port, package);
                    timer.Stop();
                });

                //Сообщаем подложке, что надо начать рисовать графон
                if (Drawer is NetDrawer)
                {
                    DrawPackage(port);
                }

                timer.Start();
            }
        }
示例#8
0
        /*
         * Если адрес получителя совпадает - то принимаем пакет,
         * иначе - откланяет
         */
        public override void ProcessPackage(Package package, AbstractNetworkDevice sender)
        {
            string stage;

            //Адресован ли пакет нам
            if (package.EndIP.Peek().Equals(InterfaceAdresses[0].IP))
            {
                package.PackageState = Package.State.RECEIVED;
                stage = Name + " (" + InterfaceAdresses[0] + ") received package " + package + " from " + package.StartIP;
            }
            else
            {
                package.PackageState = Package.State.REJECTED;
                stage = Name + " (" + InterfaceAdresses[0] + ") rejected package " + package;
            }

            Logger.WriteLine(stage);
            package.AddStage(stage);
            PackageManager.AddPackage(package);
        }
示例#9
0
        public Task PushPackage(HttpContext context)
        {
            if (context.Request.Method.ToLower() != "put")
            {
                context.Response.StatusCode = 400;
                return(Task.CompletedTask);
            }

            var fileName = context.Request.Path.ToString().Trim('/');
            var file     = context.Request.Form.Files.FirstOrDefault();

            if (string.IsNullOrWhiteSpace(fileName) || file == null)
            {
                context.Response.StatusCode = 400;
                return(Task.CompletedTask);
            }

            _packageManager.AddPackage(fileName, file.OpenReadStream());
            context.Response.StatusCode = 204;
            return(Task.CompletedTask);
        }
示例#10
0
        public static bool Process(string command)
        {
            return(parser.ParseArguments <ExitOption, ConfigOption, SwitchOption, ClientOption, ImportOption, LsOption, ShowOption, AddpkgOption, EditpkgOption, DelpkgOption, AddverOption, EditverOption, DelverOption, HelpOption>(
                       CommandSplitter.Split(command))
                   .MapResult(
                       (ExitOption opt) => {
                if (opt.IsForce)
                {
                    return true;
                }
                else
                {
                    if (!General.IsMaintaining)
                    {
                        General.CoreTcpProcessor.StopListen();
                        Console.WriteLine("Waiting the release of resources...");
                        if (General.ManualResetEventList.Count != 0)
                        {
                            WaitHandle.WaitAll(General.ManualResetEventList.ToArray());
                        }
                    }
                    else
                    {
                        General.GeneralDatabase.Close();
                    }

                    General.RecordFileManager.Close();
                    return true;
                }
            },
                       (ConfigOption opt) => {
                if (opt.Key is null)
                {
                    foreach (var item in General.ConfigManager.Configuration.Keys)
                    {
                        Console.Write($"{item}: ");
                        Console.Write($"{General.ConfigManager.Configuration[item]}\n");
                    }
                }
                else
                {
                    if (opt.NewValue is null)
                    {
                        if (General.ConfigManager.Configuration.Keys.Contains(opt.Key))
                        {
                            Console.WriteLine(General.ConfigManager.Configuration[opt.Key]);
                        }
                    }
                    else
                    {
                        if (General.ConfigManager.Configuration.Keys.Contains(opt.Key))
                        {
                            General.ConfigManager.Configuration[opt.Key] = opt.NewValue;
                            General.ConfigManager.Save();
                            Console.WriteLine("New value has been applied");
                        }
                    }
                }
                return false;
            },
                       (SwitchOption opt) => {
                if (!General.IsMaintaining)
                {
                    General.CoreTcpProcessor.StopListen();
                    Console.WriteLine("Waiting the release of resources...");
                    if (General.ManualResetEventList.Count != 0)
                    {
                        WaitHandle.WaitAll(General.ManualResetEventList.ToArray());
                    }

                    General.GeneralDatabase.Open();

                    General.IsMaintaining = true;
                    ConsoleAssistance.WriteLine("Switch to maintain mode successfully.", ConsoleColor.Yellow);
                }
                else
                {
                    General.GeneralDatabase.Close();
                    //force update verify code
                    ConsoleAssistance.WriteLine("Updating verify code....", ConsoleColor.White);
                    General.VerifyBytes = SignVerifyHelper.SignData(Information.WorkPath.Enter("package.db").Path, Information.WorkPath.Enter("pri.key").Path);
                    General.ConfigManager.Configuration["VerifyBytes"] = Convert.ToBase64String(General.VerifyBytes);
                    General.ConfigManager.Save();

                    General.CoreTcpProcessor.StartListen();

                    General.IsMaintaining = false;
                    ConsoleAssistance.WriteLine("Switch to running mode successfully.", ConsoleColor.Yellow);
                }
                return false;
            },
                       (ClientOption opt) => {
                if (!CheckStatus(false))
                {
                    return false;
                }

                ConsoleAssistance.WriteLine($"Current client: {General.ManualResetEventList.Count}", ConsoleColor.Yellow);
                return false;
            },
                       (ImportOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }

                ConsoleAssistance.WriteLine("import is a dangerous command. It will load all script and run it without any error judgement! It couldn't be stopped before all of commands has been executed!", ConsoleColor.Yellow);
                var confirm = new Random().Next(100, 9999);
                ConsoleAssistance.WriteLine($"Type this random number to confirm your operation: {confirm}", ConsoleColor.Yellow);
                if (Console.ReadLine() == confirm.ToString())
                {
                    if (System.IO.File.Exists(opt.FilePath))
                    {
                        ImportStack.AppendImportedCommands(opt.FilePath);
                    }
                    else
                    {
                        ConsoleAssistance.WriteLine("Cannot find specific file", ConsoleColor.Red);
                    }
                }
                return false;
            },
                       (LsOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }

                if (opt.Condition is null)
                {
                    PackageManager.Ls(General.GeneralDatabase, "");
                }
                else
                {
                    PackageManager.Ls(General.GeneralDatabase, opt.Condition);
                }
                return false;
            },
                       (ShowOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }
                PackageManager.Show(General.GeneralDatabase, opt.FullPackageName);
                return false;
            },
                       (AddpkgOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }
                PackageManager.AddPackage(General.GeneralDatabase, opt);
                return false;
            },
                       (EditpkgOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }
                PackageManager.EditPackage(General.GeneralDatabase, opt);
                return false;
            },
                       (DelpkgOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }
                PackageManager.RemovePackage(General.GeneralDatabase, opt.Name);
                return false;
            },
                       (AddverOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }
                PackageManager.AddVersion(General.GeneralDatabase, opt);
                return false;
            },
                       (EditverOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }
                PackageManager.EditVersion(General.GeneralDatabase, opt);
                return false;
            },
                       (DelverOption opt) => {
                if (!CheckStatus(true))
                {
                    return false;
                }
                PackageManager.RemoveVersion(General.GeneralDatabase, opt.Name);
                return false;
            },
                       (HelpOption opt) => {
                OutputHelp();
                return false;
            },
                       errs => { ConsoleAssistance.WriteLine("Unknow command. Use help to find the correct command", ConsoleColor.Red); return false; }));
        }
示例#11
0
        public override void ProcessPackage(Package package, AbstractNetworkDevice sender)
        {
            //Порт, на который пришел пакет
            int    port = ConnectedDevices.First(x => x.Value == sender).Key;
            string stage;

            //Адресован ли пакет нам
            if (package.EndIP.Peek().Equals(InterfaceAdresses[port].IP))
            {
                //Убираем верхний адрес в пакете
                //Если ничего нет больше - пакет адресован роутеру,
                //если есть - надо слать дальше

                package.EndIP.Pop();
                if (package.EndIP.Count == 0)
                {
                    package.EndIP.Push(InterfaceAdresses[port].IP);

                    stage = Name + " (" + InterfaceAdresses[port] + ") received package " + package + "from " + package.StartIP;
                    Logger.WriteLine(stage);
                    package.AddStage(stage);
                    package.PackageState = Package.State.RECEIVED;
                    PackageManager.AddPackage(package);
                    return;
                }

                //Пересылка дальше
                //проверка по PROXY-таблице
                bool ispass = is_pass(package);
                if (!ispass)
                {
                    stage = Name + " (" + InterfaceAdresses[port] + ") DENIED package " + package;
                    Logger.WriteLine(stage);
                    package.AddStage(stage);
                    package.PackageState = Package.State.DENIED;
                    PackageManager.AddPackage(package);
                    return;
                }


                //Проверка по таблице маршрутизации
                Route route = get_route(package.EndIP.Peek());
                if (route == null)
                {
                    stage = Name + " (" + InterfaceAdresses[port] + ") DON'T find route for package " + package;
                    Logger.WriteLine(stage);
                    package.AddStage(stage);
                    package.PackageState = Package.State.NO_ROUTE;
                    PackageManager.AddPackage(package);

                    return;
                }


                if (route.NextRouter != null)
                {
                    package.EndIP.Push(route.NextRouter);
                }


                send(package, route.PortNo);
            }
            else
            {
                package.PackageState = Package.State.REJECTED;
                stage = Name + " (" + InterfaceAdresses[0] + ") rejected package " + package;

                Logger.WriteLine(stage);
                package.AddStage(stage);
                PackageManager.AddPackage(package);
            }
        }