Exemple #1
0
    public void CreateLink(Faction faction, KeyInventoryModel inventory, Portal source, Portal target, AchievementModel achievement)
    {
        // Link
        var linkModel = LinkManager.AddLink(faction, inventory, source.Model, target.Model);

        Debug.Log(string.Format("Link {0} created.", linkModel));

        Links.Add(Util.Instantiate(LinkPrefab, LinkLayer).Init(linkModel));
        achievement.CreateLink();

        // CF
        var cfModels = LinkManager.AddCFs(linkModel);

        if (cfModels.Any())
        {
            var mu = cfModels.Sum(cfModel => cfModel.MU);

            Util.Instantiate(FloatingMUPrefab, null).Init(source.Model.Position, Mathf.FloorToInt(mu) + " MU", 0.8f);

            Debug.Log(string.Format("{0} CFs created total {1} MU", cfModels.Count(), mu));
            Scoreboard.DisplayMU(faction, LinkManager.GetMU(faction));

            foreach (var cfModel in cfModels)
            {
                CFs.Add(Util.Instantiate(CFPrefab, LinkLayer).Init(cfModel));
                achievement.CreateCF(Mathf.FloorToInt(cfModel.MU));
            }

            SoundManager.GetInstance().CFCreatedSound.Play();
        }

        UpdateDeadPortals();
    }
        protected void saveButton_Click(object sender, EventArgs e)
        {
            string[] validFileTypes = { ".png", ".jpg", ".jpeg", ".gif", "svg" };
            string   ext            = System.IO.Path.GetExtension(FileUploadControl.PostedFile.FileName);

            bool isValidFile = false;

            for (int i = 0; i < validFileTypes.Length; i++)

            {
                if (ext.ToLower().Equals(validFileTypes[i]))
                {
                    isValidFile = true;

                    break;
                }
            }
            string errorMsg = "Successfull";

            if (isValidFile)
            {
                try
                {
                    string filename = Path.GetFileName(FileUploadControl.FileName);
                    string filePath = Server.MapPath("~/LinkImage/") + DateTime.Now.ToString("ddMMyyyyhhmmss") + filename.Substring(filename.LastIndexOf("."));
                    FileUploadControl.SaveAs(filePath);
                    Dictionary <string, object> inputDic = new Dictionary <string, object>();
                    inputDic.Add("puser_flag", linkUserDropDownListChosen.SelectedValue);
                    inputDic.Add("plink_title", linkTitleTextBox.Text.Trim());
                    inputDic.Add("pcatg_id", categoryDropDownListChosen.SelectedValue);
                    inputDic.Add("plink_url", urlTextBox.Text.Trim());
                    inputDic.Add("plink_img_url", filePath);
                    inputDic.Add("pmake_by", "Admin");
                    try
                    {
                        DataTable dt = linkManager.AddLink(inputDic);
                        errorMsg = "Successfully saved";
                    }
                    catch (Exception ex)
                    {
                        errorMsg = "Error Occured. Enter input data properly";
                    }
                }
                catch (Exception ex)
                {
                    errorMsg = "File Upload Error";
                }
            }
            else
            {
                errorMsg = "Upload Only Image File (.png, .jpg, .jpeg, .svg, .gif)";
            }

            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + errorMsg + "'); window.location='" +
                                               Request.ApplicationPath + "/UI/LinkEntry.aspx';", true);

            //Response.Redirect("LinkEntry.aspx");
        }
        private void btnAddFiles_Click(object sender, EventArgs e)
        {
            if (filesToAdd == null || filesToAdd.Count == 0)
            {
                return;
            }
            int nAdded = 0;
            List <TrackedFile> newFiles = new List <TrackedFile>();

            foreach (var file in filesToAdd)
            {
                FileInfo fi = new FileInfo(file);
                if (!fi.Exists)
                {
                    continue;
                }

                bool alreadyInSystem = FileManager.Exists(file);
                if (!alreadyInSystem)
                {
                    TrackedFile newFile = FileManager.AddFile(
                        Path.GetFileNameWithoutExtension(fi.Name),
                        fi.Extension.Substring(1), fi.DirectoryName,
                        (int)fi.Length, fi.CreationTime, fi.LastWriteTime);
                    if (newFile != null)
                    {
                        LogFileAdded(newFile);
                        newFiles.Add(newFile);
                        nAdded++;
                    }
                }
            }
            bool   wantsLink  = chkLinkFiles.Checked;
            string linkResult = null;

            if (wantsLink && nAdded > 1 && newFiles.Count > 1)
            {
                string memo    = txtMemo.Text.Trim();
                var    fileIDs = from file in newFiles
                                 select file.FileID;
                FileLink newLink = LinkManager.AddLink(fileIDs.ToList(), memo);
                if (newLink != null)
                {
                    // Log link creation and each file joined
                    LogLinkCreation(newLink.LinkMemoID, nAdded, memo);
                    LogLinkJoined(newLink, newLink.GetFiles());
                    linkResult = $"\n\nLinked {nAdded} files" +
                                 (string.IsNullOrEmpty(memo) ? "." : $" as '{memo}'.");
                }
            }
            string resultPrompt = $"Added {nAdded} file(s)." +
                                  linkResult;

            Messenger.Show(resultPrompt, caption);
            DialogResult = DialogResult.OK;
            Close();
        }
Exemple #4
0
    private void SpawnTestCreature()
    {
        var creature = _activeWorld.CreateNewCreature(10, 30000, Color.black);

        creature.MoveTo(Camera.main.ScreenToWorldPoint(Input.mousePosition));

        _activeWorld.AddCreatureToWorld(creature);

        var sensors = new CreatureSensor[] {
            new RandomizeSensor(creature)
        };
        var actions = new CreatureAction[] {
            new Mouth(creature)
        };

        int networkID = _networkManager.AddNetwork(sensors, actions, 50);

        _linkManager.AddLink(creature, networkID);
    }
Exemple #5
0
        public ActionResult Post(Link linktoPost)
        {
            LinkManager lm = new LinkManager(ConnectionString);

            Link l1 = lm.AddLink(linktoPost);

            //l = l1;

            //maybe return to users?
            //maybe change all redirect to users
            return(RedirectToAction("secret"));
        }
Exemple #6
0
        public void GetLinksTest()
        {
            // Add link
            LinkManager.AddLink(new List <int> {
                1
            }, "Test Get Links");

            // Get all links
            List <FileLink> linkList = LinkManager.GetLinks();

            // Verify there is at least one link
            Assert.IsNotNull(linkList);
        }
Exemple #7
0
        public void AddLinkTest()
        {
            int linkCount = 0;

            LinkManager.AddLink(new List <int> {
                1
            }, "Test Add Link");
            List <FileLink> linkList = LinkManager.GetLinks();

            linkCount = linkList.Count;

            // Add Link
            LinkManager.AddLink(new List <int> {
                1
            }, "Test Add Link");

            // Verify the link was added
            linkList = LinkManager.GetLinks();
            Assert.AreEqual(linkCount + 1, linkList.Count);
        }
Exemple #8
0
        private void btnAddLink_Click(object sender, EventArgs e)
        {
            if (filesToLink.Count < 2)
            {
                return;                        // Need 2+ files to link
            }
            List <int> memberIDs = new List <int>();

            foreach (var file in filesToLink)
            {
                memberIDs.Add(file.FileID);
            }

            if (memberIDs.Count < 2)
            {
                return;                      // Just in case
            }
            string   linkMemo = txtLinkMemo.Text.Trim();
            FileLink newLink  = null;

            if (string.IsNullOrEmpty(linkMemo))
            {
                newLink = LinkManager.AddLink(memberIDs);
            }
            else
            {
                newLink = LinkManager.AddLink(memberIDs, linkMemo);
            }
            if (newLink == null)
            {
                return;                  // Didn't create
            }
            // Log link creation
            LogLinkCreation(newLink.LinkMemoID, memberIDs.Count, linkMemo);
            LogLinkJoined(newLink, newLink.GetFiles());
            Messenger.Show($"New link created between the {memberIDs.Count} files.", caption);
            DialogResult = DialogResult.OK;
            Close();
        }
Exemple #9
0
        public void GetLinkTest()
        {
            // Add link
            LinkManager.AddLink(new List <int> {
                1
            }, "Test Get Link");

            // Get all links
            List <FileLink> linkList = LinkManager.GetLinks();

            // Verify there is at least one link
            Assert.IsNotNull(linkList);

            // Store some data for one of the files
            int    linkId   = linkList[0].LinkMemoID;
            string linkMemo = linkList[0].LinkMemo;

            // Get file link by id
            FileLink link = LinkManager.GetLink(linkId);

            // Verify the expected link was returned
            Assert.IsNotNull(link);
        }
Exemple #10
0
        /// <summary>
        /// continued browse on this site...
        /// </summary>
        private void DeepBrowse()
        {
            if (_stickiness > 0)
            {
                var random = new Random();
                // some percentage of the time, we should stay on this site
                if (random.Next(100) < _stickiness)
                {
                    var loops = random.Next(_depthMin, _depthMax);
                    for (var loopNumber = 0; loopNumber < loops; loopNumber++)
                    {
                        try
                        {
                            //get all links from results
                            var doc = new HtmlDocument();
                            doc.LoadHtml(this.Result.ToLower());

                            var nodes = doc.DocumentNode.SelectNodes("//a");
                            if (nodes == null || !nodes.Any())
                            {
                                return;
                            }

                            var linkManager = new LinkManager(this._currentHost);
                            foreach (var node in nodes)
                            {
                                if (!node.HasAttributes ||
                                    node.Attributes["href"] == null ||
                                    string.IsNullOrEmpty(node.Attributes["href"].Value) ||
                                    node.Attributes["href"].Value.ToLower().StartsWith("//"))
                                {
                                    //skip, these seem ugly
                                }
                                // http|s links
                                else if (node.Attributes["href"].Value.ToLower().StartsWith("http"))
                                {
                                    linkManager.AddLink(node.Attributes["href"].Value.ToLower());
                                }
                                // relative links - prefix the scheme and host
                                else
                                {
                                    linkManager.AddLink($"{this._currentHost}{node.Attributes["href"].Value.ToLower()}");
                                }
                            }

                            var link = linkManager.Choose();
                            if (link == null)
                            {
                                return;
                            }
                            var href = link.Url.ToString();

                            if (!string.IsNullOrEmpty(href))
                            {
                                this.Result = "";
                                Command(href);
                            }
                        }
                        catch (Exception e)
                        {
                            _log.Error(e);
                        }

                        if (_wait > 0)
                        {
                            Thread.Sleep(_wait);
                        }
                    }
                }
            }
        }
        public void ExecuteEvents(TimelineHandler handler)
        {
            try
            {
                foreach (TimelineEvent timelineEvent in handler.TimeLineEvents)
                {
                    WorkingHours.Is(handler);

                    if (timelineEvent.DelayBefore > 0)
                    {
                        Thread.Sleep(timelineEvent.DelayBefore);
                    }

                    RequestConfiguration config;

                    IWebElement element;
                    Actions     actions;

                    switch (timelineEvent.Command)
                    {
                    case "random":

                        // setup
                        if (handler.HandlerArgs.ContainsKey("stickiness"))
                        {
                            int.TryParse(handler.HandlerArgs["stickiness"], out _stickiness);
                        }
                        if (handler.HandlerArgs.ContainsKey("stickiness-depth-min"))
                        {
                            int.TryParse(handler.HandlerArgs["stickiness-depth-min"], out _depthMin);
                        }
                        if (handler.HandlerArgs.ContainsKey("stickiness-depth-max"))
                        {
                            int.TryParse(handler.HandlerArgs["stickiness-depth-max"], out _depthMax);
                        }

                        while (true)
                        {
                            if (Driver.CurrentWindowHandle == null)
                            {
                                throw new Exception("Browser window handle not available");
                            }

                            config = RequestConfiguration.Load(timelineEvent.CommandArgs[new Random().Next(0, timelineEvent.CommandArgs.Count)]);
                            if (config.Uri.IsWellFormedOriginalString())
                            {
                                MakeRequest(config);
                                Report(handler.HandlerType.ToString(), timelineEvent.Command, config.ToString(), timelineEvent.TrackableId);

                                if (this._stickiness > 0)
                                {
                                    var random = new Random();
                                    //now some percentage of the time should stay on this site
                                    if (random.Next(100) < this._stickiness)
                                    {
                                        var loops = random.Next(this._depthMin, this._depthMax);
                                        for (var loopNumber = 0; loopNumber < loops; loopNumber++)
                                        {
                                            try
                                            {
                                                var linkManager = new LinkManager(config.GetHost());


                                                //get all links
                                                var links = Driver.FindElements(By.TagName("a"));
                                                foreach (var l in links)
                                                {
                                                    var node = l.GetAttribute("href");
                                                    if (string.IsNullOrEmpty(node) ||
                                                        node.ToLower().StartsWith("//"))
                                                    {
                                                        //skip, these seem ugly
                                                    }
                                                    // http|s links
                                                    else if (node.ToLower().StartsWith("http"))
                                                    {
                                                        linkManager.AddLink(node.ToLower());
                                                    }
                                                    // relative links - prefix the scheme and host
                                                    else
                                                    {
                                                        linkManager.AddLink($"{config.GetHost()}{node.ToLower()}");
                                                    }
                                                }

                                                var link = linkManager.Choose();
                                                if (link == null)
                                                {
                                                    return;
                                                }

                                                config.Method = "GET";
                                                config.Uri    = link.Url;

                                                MakeRequest(config);
                                                Report(handler.HandlerType.ToString(), timelineEvent.Command, config.ToString(), timelineEvent.TrackableId);
                                            }
                                            catch (Exception e)
                                            {
                                                _log.Error(e);
                                            }

                                            Thread.Sleep(timelineEvent.DelayAfter);
                                        }
                                    }
                                }
                            }
                            Thread.Sleep(timelineEvent.DelayAfter);
                        }

                    case "browse":
                        config = RequestConfiguration.Load(timelineEvent.CommandArgs[0]);
                        if (config.Uri.IsWellFormedOriginalString())
                        {
                            MakeRequest(config);
                            Report(handler.HandlerType.ToString(), timelineEvent.Command, config.ToString(), timelineEvent.TrackableId);
                        }
                        break;

                    case "download":
                        if (timelineEvent.CommandArgs.Count > 0)
                        {
                            element = Driver.FindElement(By.XPath(timelineEvent.CommandArgs[0].ToString()));
                            element.Click();
                            Report(handler.HandlerType.ToString(), timelineEvent.Command, string.Join(",", timelineEvent.CommandArgs), timelineEvent.TrackableId);
                            Thread.Sleep(1000);
                        }
                        break;

                    case "type":
                        element = Driver.FindElement(By.Name(timelineEvent.CommandArgs[0].ToString()));
                        actions = new Actions(Driver);
                        actions.SendKeys(element, timelineEvent.CommandArgs[1].ToString()).Build().Perform();
                        break;

                    case "typebyid":
                        element = Driver.FindElement(By.Id(timelineEvent.CommandArgs[0].ToString()));
                        actions = new Actions(Driver);
                        actions.SendKeys(element, timelineEvent.CommandArgs[1].ToString()).Build().Perform();
                        break;

                    case "click":
                        element = Driver.FindElement(By.Name(timelineEvent.CommandArgs[0].ToString()));
                        actions = new Actions(Driver);
                        actions.MoveToElement(element).Click().Perform();
                        break;

                    case "clickbyid":
                        element = Driver.FindElement(By.Id(timelineEvent.CommandArgs[0].ToString()));
                        actions = new Actions(Driver);
                        actions.MoveToElement(element).Click().Perform();
                        break;
                    }

                    if (timelineEvent.DelayAfter > 0)
                    {
                        Thread.Sleep(timelineEvent.DelayAfter);
                    }
                }
            }
            catch (Exception e)
            {
                _log.Error(e);
            }
        }