예제 #1
0
 public MasterController(IOptions <LocalNetwork> _network)
 {
     if (_network != null)
     {
         this.network = _network.Value;
     }
 }
예제 #2
0
        public bool Exec(LocalNetwork network, long id, ref DtoBrand dto)
        {
            try
            {
                using (var db = GetConnection(network))
                {
                    var u = repository.GetBrand(db, id);

                    dto = new DtoBrand
                    {
                        id   = u.id,
                        name = u.stName
                    };
                }

                return(true);
            }
            catch (Exception ex)
            {
                Error = new DtoServiceError
                {
                    message   = getLanguage("0", 0),
                    debugInfo = ex.ToString()
                };

                return(false);
            }
        }
예제 #3
0
        public void EmailNOK()
        {
            #region - code -

            var network = new LocalNetwork()
            {
                sqlServer = connStr
            };
            var auth = new DtoAuthenticatedUser();
            var repo = new FakeRepo_User();

            var tu_obj = new DtoLoginInformation
            {
                email    = Base_Ut_user.stEmail + "....",
                password = Base_Ut_user.stPassword
            };

            var srv = new SrvAuthenticateV1(repo);

            if (srv.Exec(network, tu_obj, ref auth))
            {
                Assert.Fail();
            }

            #endregion
        }
예제 #4
0
        public LocalNetwork GetProfileNetworkForBrowser(int profileId)
        {
            //Debug logging
            XmlUtilities.logit("Line1: profileid:" + profileId);

            NetworkBrowserBL nb = new NetworkBrowserBL();


            try
            {
                using (XmlReaderScope scope = nb.GetProfileNetworkForBrowser(profileId))
                {
                    Type type = typeof(LocalNetwork);

                    string responseXML;

                    scope.Reader.Read();

                    responseXML = scope.Reader.ReadOuterXml();


                    LocalNetwork ln = XmlUtilities.DeserializeObject(responseXML, type) as LocalNetwork;

                    return(ln);
                }
            }
            catch (Exception ex)
            {
                XmlUtilities.logit("ERROR: " + ex.Message + " " + ex.StackTrace + " ,,,, INNER EXCEPTION: " + ex.InnerException.Message + ex.InnerException.StackTrace);
                throw ex;
            }
        }
예제 #5
0
        public async Task Run(CancellationToken cancellationToken)
        {
            _PrivateIPAddresses = LocalNetwork.GetIPAddresses(new[] { AddressType.IPv4 }, true);

            try
            {
                await RegisterClients(cancellationToken).ConfigureAwait(false);

                try
                {
                    await JoinChannels(cancellationToken).ConfigureAwait(false);

                    try
                    {
                        await OpenConnections(cancellationToken).ConfigureAwait(false);
                        await Pause(cancellationToken).ConfigureAwait(false);
                    }
                    finally
                    {
                        await CloseConnections().ConfigureAwait(false);
                    }
                }
                finally
                {
                    await LeaveChannels().ConfigureAwait(false);
                }
            }
            finally
            {
                await UnregisterClients().ConfigureAwait(false);
            }
        }
예제 #6
0
        public bool Exec(LocalNetwork network, DtoCheckNewSocial_ID obj)
        {
            try
            {
                using (var db = GetConnection(network))
                {
                    var user = repository.GetUserBySocial(db, obj.sID);

                    if (user != null)
                    {
                        Error = new DtoServiceError
                        {
                            message   = getLanguage(obj._language, 1),
                            debugInfo = "[1]"
                        };

                        return(false);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                Error = new DtoServiceError
                {
                    message   = getLanguage(obj._language, 0),
                    debugInfo = ex.ToString()
                };

                return(false);
            }
        }
예제 #7
0
        public void SidEmpty()
        {
            #region - code -

            var network = new LocalNetwork()
            {
                sqlServer = connStr
            };
            var repo = new FakeRepo_User();
            var srv  = new SrvResendTokenV1(repo)
            {
                _sendEmail = true
            };

            if (srv.Exec(network, new DtoResendToken
            {
                sID = null,
                _language = 0
            }))
            {
                Assert.Fail();
            }

            #endregion
        }
예제 #8
0
        public void OK()
        {
            #region - code -

            var network = new LocalNetwork()
            {
                sqlServer = connStr
            };
            var repoProduct = new FakeRepo_Product();
            var repoAdmin   = new FakeRepo_Admin();

            var srv = new SrvProductListingV1(repoProduct, repoAdmin, null)
            {
                _sendEmail = false
            };

            DtoProductListingResult ret = new DtoProductListingResult();

            if (!srv.Exec(network, new DtoProductListing
            {
                tag = "Livro",
                category = 1,
                page = 0,
                pageSize = 99,
                orderBy = 1,
                _language = 0
            }, ref ret))
            {
                Assert.Fail();
            }

            #endregion
        }
예제 #9
0
        public void EmailNotExists()
        {
            #region - code -

            var network = new LocalNetwork()
            {
                sqlServer = connStr
            };
            var repo = new FakeRepo_User();
            var srv  = new SrvPasswordRecoveryV1(repo)
            {
                _sendEmail = false
            };

            if (srv.Exec(network, new DtoPasswordRecovery
            {
                email = "*****@*****.**",
                _language = 0
            }))
            {
                Assert.Fail();
            }

            #endregion
        }
예제 #10
0
        public void OK()
        {
            #region - code -

            var network = new LocalNetwork()
            {
                sqlServer = connStr
            };
            var repo = new FakeRepo_User();
            var srv  = new SrvPasswordRecoveryV1(repo)
            {
                _sendEmail = false
            };

            if (!srv.Exec(network, new DtoPasswordRecovery
            {
                email = new UTstUserBase().Base_Ut_user.stEmail,
                _language = 0
            }))
            {
                Assert.Fail();
            }

            #endregion
        }
예제 #11
0
        public void OK()
        {
            #region - code -

            var network = new LocalNetwork()
            {
                sqlServer = connStr
            };
            var repo = new FakeRepo_User();

            var srv = new SrvOnboardingV1(repo)
            {
                _sendEmail = false
            };

            if (!srv.Exec(network, new DtoOnboarding
            {
                sEmail = "*****@*****.**",
                sID = "102030405060",
                sName = "One",
                sPass = "******",
                _language = 0
            }))
            {
                Assert.Fail();
            }

            #endregion
        }
예제 #12
0
        public LocalNetwork GetProfileNetworkForBrowser(int profileId)
        {
            //Debug logging
            Connects.Profiles.Service.ServiceImplementation.DebugLogging.Log("Line1: profileid:" + profileId);

            DataIO nb = new DataIO();


            try
            {
                Type type = typeof(LocalNetwork);

                string responseXML;

                responseXML = nb.GetProfileNetworkForBrowser(profileId).OuterXml;

                LocalNetwork ln = XmlUtilities.DeserializeObject(responseXML, type) as LocalNetwork;

                return(ln);
            }
            catch (Exception ex)
            {
                DebugLogging.Log("ERROR: " + ex.Message + " " + ex.StackTrace + " ,,,, INNER EXCEPTION: " + ex.InnerException.Message + ex.InnerException.StackTrace);
                throw ex;
            }
        }
예제 #13
0
        public bool Exec(LocalNetwork network, DtoAuthenticatedUser au, string pesquisa, ref DtoUserList dto)
        {
            try
            {
                using (var db = GetConnection(network))
                {
                    var lstClient = repository.GetUsers(db, "%" + pesquisa + "%");

                    dto.total   = lstClient.Count;
                    dto.results = lstClient;

                    foreach (var item in dto.results)
                    {
                        // extra processing
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                Error = new DtoServiceError
                {
                    message   = getLanguage("0", 0),
                    debugInfo = ex.ToString()
                };

                return(false);
            }
        }
예제 #14
0
        public bool Exec(LocalNetwork network, DtoCheckToken obj)
        {
            try
            {
                using (var db = GetConnection(network))
                {
                    var user = repository.GetUserBySocial(db, obj.sID);

                    if (user == null)
                    {
                        Error = new DtoServiceError
                        {
                            message   = getLanguage(obj._language, 1),
                            debugInfo = "[1]"
                        };

                        return(false);
                    }

                    if (user.stToken != obj.sToken)
                    {
                        Error = new DtoServiceError
                        {
                            message   = getLanguage(obj._language, 2),
                            debugInfo = "[1]"
                        };

                        return(false);
                    }

                    if (DateTime.Now > user.dtTokenExpires)
                    {
                        Error = new DtoServiceError
                        {
                            message   = getLanguage(obj._language, 3),
                            debugInfo = "[1]"
                        };

                        return(false);
                    }

                    user.bTokenized = true;

                    repository.UpdateUser(db, user);
                }

                return(true);
            }
            catch (Exception ex)
            {
                Error = new DtoServiceError
                {
                    message   = getLanguage(obj._language, 0),
                    debugInfo = ex.ToString()
                };

                return(false);
            }
        }
예제 #15
0
 protected override IEnumerable <XElement> getSpecificData(WebContext context)
 {
     return(new XElement[] {
         new XElement("isLocalNetwork", LocalNetwork.IsLocalNetwork(context.remoteHost).ToPlainString()),
         new XElement("ip", context.remoteHost.ToString()),
         new XElement("isMigrationEnabled", Config.instance.IsMigrationEnabled.ToPlainString()),
     });
 }
 public void Initialize()
 {
     infectedComputers = new List <int> {
         11, 3
     };
     file = new System.IO.StreamReader(@"..\..\matrix.txt");
     LAN  = new LocalNetwork(file, infectedComputers);
     file.Close();
 }
예제 #17
0
        public NpgsqlConnection GetConnection(LocalNetwork network)
        {
            #region - code -

            var ret = new NpgsqlConnection(network.sqlServer);
            ret.Open();
            return(ret);

            #endregion
        }
        public void CheckSystemStatusTest()
        {
            Assert.IsFalse(LAN.IsUnhealthy());

            file = new System.IO.StreamReader(@"..\..\matrix.txt");
            var UnhealthyLAN = new LocalNetwork(file, new List <int> {
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
            });

            file.Close();
            Assert.IsTrue(UnhealthyLAN.IsUnhealthy());
        }
예제 #19
0
        public MasterController(IOptions <LocalNetwork> _network, IMemoryCache _cache)
        {
            if (_network != null)
            {
                this.network = _network.Value;
            }

            if (_cache != null)
            {
                cache = _cache;
            }
        }
예제 #20
0
        public bool Exec(LocalNetwork network, DtoPasswordRecovery obj)
        {
            try
            {
                if (String.IsNullOrEmpty(obj.email))
                {
                    Error = new DtoServiceError
                    {
                        message   = getLanguage(obj._language, 4),
                        debugInfo = "[1]"
                    };

                    return(false);
                }

                var email = obj.email.ToLower();

                using (var db = GetConnection(network))
                {
                    var user = repository.GetUserByEmail(db, email);

                    if (user == null)
                    {
                        Error = new DtoServiceError
                        {
                            message   = getLanguage(obj._language, 1),
                            debugInfo = "[1]"
                        };

                        return(false);
                    }

                    SendEmail(email,
                              getLanguage(obj._language, 2),
                              getLanguage(obj._language, 3) + user.stPassword);
                }

                return(true);
            }
            catch (Exception ex)
            {
                Error = new DtoServiceError
                {
                    message   = getLanguage(obj._language, 0),
                    debugInfo = ex.ToString()
                };

                return(false);
            }
        }
        override protected IEnumerable <XElement> getSpecificData(WebContext context)
        {
            IEnumerable <LocalNetwork> localNetworks = LocalNetwork.LoadByIds(
                from stringId in Config.instance.mainConnection.LoadIdsByConditions(
                    LocalNetwork.TableSpec.instance,
                    new Web.Core.DB.conditions.EmptyCondition(),
                    Diapasone.unlimited
                    ) select int.Parse(stringId)
                );

            return(new XElement[] {
                new XElement("localNetworks", from localNetwork in localNetworks select localNetwork.exportToXml(context)),
            });
        }
예제 #22
0
        public bool Exec(LocalNetwork network, DtoResendToken obj)
        {
            try
            {
                using (var db = GetConnection(network))
                {
                    var user = repository.GetUserBySocial(db, obj.sID);

                    if (user == null)
                    {
                        Error = new DtoServiceError
                        {
                            message   = getLanguage(obj._language, 1),
                            debugInfo = "[1]"
                        };

                        return(false);
                    }



                    var token = "";
                    var rnd   = new Random();
                    for (int i = 0; i < 4; i++)
                    {
                        token += rnd.Next(0, 9);
                        Thread.Sleep(1);
                    }

                    user.stToken = token;

                    repository.UpdateUser(db, user);

                    SendEmail(user.stEmail, getLanguage(obj._language, 2), getLanguage(obj._language, 3) + token);
                }

                return(true);
            }
            catch (Exception ex)
            {
                Error = new DtoServiceError
                {
                    message   = getLanguage(obj._language, 0),
                    debugInfo = ex.ToString()
                };

                return(false);
            }
        }
예제 #23
0
        public void StepOfVirusTest()
        {
            mat = new bool[, ] {
                { false, true, false }, { true, false, true }, { true, true, false }
            };
            comp = new List <Computer>
            {
                new Computer(new Windows(), true),
                new Computer(new Linux(), false),
                new Computer(new MacOS(), false)
            };
            var net = new LocalNetwork(comp, mat);

            net.StepOfVirusInfection();
            Assert.IsFalse(net.Check());
        }
예제 #24
0
        private void SetupProxyDetails(DeviceViewModel deviceViewModel)
        {
            proxyInfoPanel.Visible = false;
            if (deviceViewModel.Kind == DeviceKind.PXY)
            {
                string[] ports = deviceViewModel.Path.Split(':');
                if (ports.Length == 2)
                {
                    string localIPAddress = LocalNetwork.GetLocalIPAddress();
                    proxyGetworkLabel.Text = String.Format("http://{0}:{1}", localIPAddress, ports[0]);
                    proxyStratumLabel.Text = String.Format("stratum+tcp://{0}:{1}", localIPAddress, ports[1]);

                    proxyInfoPanel.BringToFront();
                    proxyInfoPanel.Visible = true;
                }
            }
        }
예제 #25
0
        /// <summary>
        /// Build connector for multicast mode
        /// </summary>
        /// <param name="docOut">Xmldocument output</param>
        /// <param name="transitions">trans contain channels instance</param>
        /// <param name="arcs">arcs xmlelement</param>
        /// <param name="mapData">map id to data</param>
        /// <param name="_sensors">sensor list</param>
        /// <param name="channels">channel list</param>
        public static void buildConnOutSensorMU(XmlDocument docOut, XmlElement arcs, LocalNetwork localNetwork)
        {
            int       fromId, toId;
            WSNPNData fromData, toData;

            foreach (WSNChannel channel in localNetwork.mChannels)
            {
                if (channel.Neighbor)
                {
                    continue;
                }

                fromId = ((WSNSensor)channel.From).ID;
                toId   = ((WSNSensor)channel.To).ID;

                // arc from
                fromData = localNetwork.getMapping(fromId);
                toData   = localNetwork.getMapping(channel.ID);

                // first arc
                arcs.AppendChild(buildArc(docOut, fromData.getOutNodeName(),
                                          toData.getInNodeName(), computeCenterXY(fromData, toData)));

                fromData = localNetwork.getMapping(channel.ID);
                toData   = localNetwork.getMapping(toId);

                // second arc
                arcs.AppendChild(buildArc(docOut,
                                          fromData.getOutNodeName(),
                                          toData.getInNodeName(), computeCenterXY(fromData, toData)));

                foreach (int item in channel.SubIdList)
                {
                    toData = localNetwork.getMapping(item);
                    if (item == fromId || toData == null)
                    {
                        continue;
                    }

                    arcs.AppendChild(buildArc(docOut, fromData.getOutNodeName(),
                                              toData.getInNodeName(), computeCenterXY(fromData, toData)));
                }
            }
        }
예제 #26
0
        public bool Exec(LocalNetwork network, DtoAuthenticatedUser au, long id, ref User dto)
        {
            try
            {
                using (var db = GetConnection(network))
                {
                    dto = repository.GetUser(db, id);
                }

                return(true);
            }
            catch (Exception ex)
            {
                Error = new DtoServiceError
                {
                    message   = getLanguage("0", 0),
                    debugInfo = ex.ToString()
                };

                return(false);
            }
        }
예제 #27
0
        public void UserCantExist()
        {
            #region - code -

            var network = new LocalNetwork()
            {
                sqlServer = connStr
            };
            var repo = new FakeRepo_User();

            var srv = new SrvCheckNewSocial_IDV1(repo);

            if (srv.Exec(network, new DtoCheckNewSocial_ID
            {
                sID = "1",
                _language = 0
            }))
            {
                Assert.Fail();
            }

            #endregion
        }
예제 #28
0
        public void Initialize()
        {
            StreamWriter writer = new StreamWriter(fileName);

            writer.Write("5" + '\n'
                         + "0 1 0 0 0" + '\n'
                         + "1 0 1 0 0" + '\n'
                         + "0 1 0 1 0" + '\n'
                         + "0 0 1 0 1" + '\n'
                         + "0 0 0 1 0" + '\n'
                         + "3" + '\n'
                         + "mac 20" + '\n'
                         + "win 70" + '\n'
                         + "lin 50" + '\n'
                         + "mac" + '\n'
                         + "win" + '\n'
                         + "lin" + '\n'
                         + "lin" + '\n'
                         + "mac" + '\n'
                         + "1");
            writer.Close();
            network = new LocalNetwork(fileName);
        }
예제 #29
0
        private static void StartProgram()
        {
            Console.WriteLine("[function] TurnOnDevices(...)");

            Factory factoryPhone  = new FactoryPhone("Apple", "IT Corp. IPhone");
            Factory factoryLaptop = new FactoryLaptop("Apple", "IT Corp. Macbook");

            var phone  = factoryPhone.Create();
            var laptop = factoryLaptop.Create();

            LocalNetwork     network        = new LocalNetwork(phone, laptop);
            GMSProtocol      mobileProtocol = new GMSProtocol();
            EthernetProtocol laptopProtocol = new EthernetProtocol();

            Console.WriteLine();
            Console.WriteLine("[function] CallToTheFriends(...)");

            phone.CallToTheFriends("Bill", new GMSProtocol());
            laptop.CallToTheFriends("Walter", new EthernetProtocol());

            Console.WriteLine();
            Console.WriteLine("[function] ConnectionToTheNetwork(...)");

            mobileProtocol.ConnectionToTheNetwork(phone);
            laptopProtocol.ConnectionToTheNetwork(laptop);

            Console.WriteLine();
            Console.WriteLine("[function] SendMessage(...)");

            network.SendMessageToTheFirstDevice();
            network.SendMessageToTheSecondDevice();

            Console.WriteLine("Программа завершила свою работу!");

            Console.ReadLine();
        }
예제 #30
0
        protected override Account DoCreateAccount(WebContext context)
        {
            if (Config.instance.IsMigrationEnabled)
            {
                try {
                    Account tmpAccount = Account.LoadByName(context.httprequest.Form["login"]);
                    if (tmpAccount.needsMigration)
                    {
                        throw new RedirectException("/My/Login/MigrateAccount/" + context.httprequest.Form["login"]);
                    }
                } catch (NotFoundInDBException) {
                }
            }

            if (!LocalNetwork.IsLocalNetwork(context.remoteHost))
            {
                throw new FLocalException("IP '" + context.remoteHost.ToString() + "' is not allowed");
            }
            if (context.httprequest.Form["password"] != context.httprequest.Form["password2"])
            {
                throw new FLocalException("Passwords mismatch");
            }
            return(Account.createAccount(context.httprequest.Form["login"], context.httprequest.Form["password"], context.httprequest.UserHostAddress, context.httprequest.Form["registrationEmail"]));
        }