Exemplo n.º 1
0
 // INDIXERS
 public int this[int edgeIndex]
 {
     get
     {
         if (closedSet.ContainsKey(edgeIndex))
         {
             return(closedSet[edgeIndex]);
         }
         else
         {
             throw new System.ArgumentException("The shortest path has not been found");
         }
     }
 }
        private void QRCodeWatcher_Removed(object sender, QRCodeRemovedEventArgs args)
        {
            Debug.Log("QRCodesManager QRCodeWatcher_Removed");


            lock (qrCodesList)
            {
                if (qrCodesList.ContainsKey(args.Code.Id))
                {
                    qrCodesList.Remove(args.Code.Id);
                }
            }
            if (OnQRCode != null)
            {
                OnQRCode(args.Code, QREventType.Removed);
            }
        }
Exemplo n.º 3
0
 private void HandleEvents()
 {
     lock (pendingActions)
     {
         while (pendingActions.Count > 0)
         {
             var action = pendingActions.Dequeue();
             if (action.type == ActionData.Type.Added)
             {
                 GameObject qrCodeObject = Instantiate(qrCodePrefab, new Vector3(0, 0, 0), Quaternion.identity);
                 qrCodeObject.GetComponent <SpatialGraphCoordinateSystem>().Id = action.qrCode.Id;
                 qrCodeObject.GetComponent <QRCode>().qrCode = action.qrCode;
                 qrCodesObjectsList.Add(action.qrCode.Id, qrCodeObject);
             }
             else if (action.type == ActionData.Type.Updated)
             {
                 if (!qrCodesObjectsList.ContainsKey(action.qrCode.Id))
                 {
                     GameObject qrCodeObject = Instantiate(qrCodePrefab, new Vector3(0, 0, 0), Quaternion.identity);
                     qrCodeObject.GetComponent <SpatialGraphCoordinateSystem>().Id = action.qrCode.Id;
                     qrCodeObject.GetComponent <QRCode>().qrCode = action.qrCode;
                     qrCodesObjectsList.Add(action.qrCode.Id, qrCodeObject);
                 }
             }
             else if (action.type == ActionData.Type.Removed)
             {
                 if (qrCodesObjectsList.ContainsKey(action.qrCode.Id))
                 {
                     Destroy(qrCodesObjectsList[action.qrCode.Id]);
                     qrCodesObjectsList.Remove(action.qrCode.Id);
                 }
             }
         }
     }
     if (clearExisting)
     {
         clearExisting = false;
         foreach (var obj in qrCodesObjectsList)
         {
             Destroy(obj.Value);
         }
         qrCodesObjectsList.Clear();
     }
 }
Exemplo n.º 4
0
        private void QrTracker_Removed(QRCodeRemovedEventArgs args)
        {
            Debug.Log("QRCodesManager QrTracker_Removed");

            bool found = false;

            lock (qrCodesList)
            {
                if (qrCodesList.ContainsKey(args.Code.Id))
                {
                    qrCodesList.Remove(args.Code.Id);
                }
            }
            if (found)
            {
                var handlers = QRCodeRemoved;
                if (handlers != null)
                {
                    handlers(this, QRCodeEventArgs.Create(args.Code));
                }
            }
        }
Exemplo n.º 5
0
            public System.Collections.Generic.SortedDictionary <decimal, table_row> GroupByDecimal(T ur_col)
            {
                var ret_table = new System.Collections.Generic.SortedDictionary <decimal, table_row>();

                foreach (var row_entry in this)
                {
                    var key_val = row_entry.GetDecimal(ur_col);
                    if (ret_table.ContainsKey(key_val) == false)
                    {
                        ret_table.Add(key_val, new table_row());
                    }

                    ret_table[key_val].Add(row_entry);
                }

                return(ret_table);
            }
Exemplo n.º 6
0
        static void FindTeamAffiliations(string input)
        {
            // key=team
            // value=list of countries that support this team
            System.Collections.Generic.SortedDictionary<int, System.Collections.Generic.SortedSet<int>> teamSupporters = new System.Collections.Generic.SortedDictionary<int, System.Collections.Generic.SortedSet<int>>();

            string[] teamsSupportedByCountries = input.Split(new char[] { '|' }, System.StringSplitOptions.RemoveEmptyEntries);

            int countryId = 0;
            foreach( string teamsSupportedByThisCountryString in teamsSupportedByCountries)
            {
                countryId++;

                string[] teamsSupportedByThisCountry = teamsSupportedByThisCountryString.Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries);
                foreach( string teamSupportedByThisCountry in teamsSupportedByThisCountry)
                {
                    int teamId = System.Int32.Parse(teamSupportedByThisCountry);
                    if (!teamSupporters.ContainsKey(teamId))
                    {
                        teamSupporters.Add(teamId, new System.Collections.Generic.SortedSet<int>());
                    }

                    teamSupporters[teamId].Add(countryId);
                }
            }

            System.Collections.Generic.List<string> output = new System.Collections.Generic.List<string>();
            foreach( int teamId in teamSupporters.Keys )
            {
                System.Collections.Generic.SortedSet<int> countriesThatSupportTeam = teamSupporters[teamId];
                int[] countryList = new int[countriesThatSupportTeam.Count];
                countriesThatSupportTeam.CopyTo(countryList);

                output.Add(teamId + ":" + string.Join(",", countryList) + ";");
            }

            System.Console.WriteLine(string.Join(" ", output.ToArray()));
        }
Exemplo n.º 7
0
        private void HandleEvents()
        {
            lock (pendingActions)
            {
                while (pendingActions.Count > 0)
                {
                    var action = pendingActions.Dequeue();
                    if (action.type == ActionData.Type.Added)
                    {
                        GameObject qrCodeObject = Instantiate(qrCodePrefab, new Vector3(0, 0, 0), Quaternion.identity);
                        qrCodeObject.GetComponent <SpatialGraphNodeTracker>().Id = action.qrCode.SpatialGraphNodeId;
                        qrCodeObject.GetComponent <QRCode>().qrCode = action.qrCode;
                        qrCodesObjectsList.Add(action.qrCode.Id, qrCodeObject);

                        //AROA EDIT - Assign object to QRCode script
                        Debug.Log("Action.qrCode.Data = " + action.qrCode.Data);
                        qrCodeObject.GetComponent <QRCode>().textToSpeech    = textToSpeech;
                        qrCodeObject.GetComponent <QRCode>().obstacleManager = obstacleManager;

                        if (action.qrCode.Data == "QR Code 1")
                        {
                            layout = "Layout 1";
                        }

                        else if (action.qrCode.Data == "QR Code 2")
                        {
                            layout = "Layout 2";
                        }

                        else if (action.qrCode.Data == "QR Code 3")
                        {
                            layout = "Layout 3";
                        }

                        else if (action.qrCode.Data == "QR Code 4")
                        {
                            layout = "Layout 4";
                        }

                        else if (action.qrCode.Data == "QR Code 5")
                        {
                            layout = "Layout 5";
                        }

                        else if (action.qrCode.Data == "QR Code 6")
                        {
                            layout = "Layout 6";
                        }

                        else if (action.qrCode.Data == "QR Code 7")
                        {
                            layout = "Layout 7";
                        }

                        else if (action.qrCode.Data == "QR Code 8")
                        {
                            layout = "Layout 8";
                        }

                        else if (action.qrCode.Data == "Demo")
                        {
                            layout = "Demo Layout";
                        }

                        else
                        {
                            layout = "Unrecognized Layout";
                        }

                        experimentLogger.layout = layout;
                        qrCodeObject.GetComponent <QRCode>().layout           = layout;
                        qrCodeObject.GetComponent <QRCode>().trackedObject    = obstacleCollection;
                        qrCodeObject.GetComponent <QRCode>().experimentLogger = experimentLogger;

                        //Assign obstacles to QR Code object
                        qrCodeObject.GetComponent <QRCode>().obstLow1  = obstLow1;
                        qrCodeObject.GetComponent <QRCode>().obstLow2  = obstLow2;
                        qrCodeObject.GetComponent <QRCode>().obstHigh1 = obstHigh1;
                        qrCodeObject.GetComponent <QRCode>().obstHigh2 = obstHigh2;
                        qrCodeObject.GetComponent <QRCode>().obstWide1 = obstWide1;
                        qrCodeObject.GetComponent <QRCode>().obstWide2 = obstWide2;
                    }
                    else if (action.type == ActionData.Type.Updated)
                    {
                        if (!qrCodesObjectsList.ContainsKey(action.qrCode.Id))
                        {
                            GameObject qrCodeObject = Instantiate(qrCodePrefab, new Vector3(0, 0, 0), Quaternion.identity);
                            qrCodeObject.GetComponent <SpatialGraphNodeTracker>().Id = action.qrCode.SpatialGraphNodeId;
                            qrCodeObject.GetComponent <QRCode>().qrCode = action.qrCode;
                            qrCodesObjectsList.Add(action.qrCode.Id, qrCodeObject);

                            //AROA EDIT
                            //QR codes created using https://www.qr-code-generator.com/
                            Debug.Log("Action.qrCode.Data = " + action.qrCode.Data);
                            qrCodeObject.GetComponent <QRCode>().textToSpeech    = textToSpeech;
                            qrCodeObject.GetComponent <QRCode>().obstacleManager = obstacleManager;


                            if (action.qrCode.Data == "QR Code 1")
                            {
                                layout = "Layout 1";
                            }

                            else if (action.qrCode.Data == "QR Code 2")
                            {
                                layout = "Layout 2";
                            }

                            else if (action.qrCode.Data == "QR Code 3")
                            {
                                layout = "Layout 3";
                            }

                            else if (action.qrCode.Data == "QR Code 4")
                            {
                                layout = "Layout 4";
                            }

                            else if (action.qrCode.Data == "QR Code 5")
                            {
                                layout = "Layout 5";
                            }

                            else if (action.qrCode.Data == "QR Code 6")
                            {
                                layout = "Layout 6";
                            }

                            else if (action.qrCode.Data == "QR Code 7")
                            {
                                layout = "Layout 7";
                            }

                            else if (action.qrCode.Data == "QR Code 8")
                            {
                                layout = "Layout 8";
                            }

                            else if (action.qrCode.Data == "Demo")
                            {
                                layout = "Demo Layout";
                            }

                            else
                            {
                                layout = "Unrecognized Layout";
                            }

                            qrCodeObject.GetComponent <QRCode>().layout           = layout;
                            qrCodeObject.GetComponent <QRCode>().trackedObject    = obstacleCollection;
                            qrCodeObject.GetComponent <QRCode>().experimentLogger = experimentLogger;

                            //Assign obstacles to QR Code object
                            qrCodeObject.GetComponent <QRCode>().obstLow1  = obstLow1;
                            qrCodeObject.GetComponent <QRCode>().obstLow2  = obstLow2;
                            qrCodeObject.GetComponent <QRCode>().obstHigh1 = obstHigh1;
                            qrCodeObject.GetComponent <QRCode>().obstHigh2 = obstHigh2;
                            qrCodeObject.GetComponent <QRCode>().obstWide1 = obstWide1;
                            qrCodeObject.GetComponent <QRCode>().obstWide2 = obstWide2;
                        }
                    }
                    else if (action.type == ActionData.Type.Removed)
                    {
                        if (qrCodesObjectsList.ContainsKey(action.qrCode.Id))
                        {
                            Destroy(qrCodesObjectsList[action.qrCode.Id]);
                            qrCodesObjectsList.Remove(action.qrCode.Id);
                        }
                    }
                }
            }
            if (clearExisting)
            {
                clearExisting = false;
                foreach (var obj in qrCodesObjectsList)
                {
                    Destroy(obj.Value);
                }
                qrCodesObjectsList.Clear();
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Resolves a schema-complete address for a usable host.
        /// </summary>
        /// <exception cref="URLError">
        /// Thrown if resolution fails.
        /// </exception>
        public string GetHost()
        {
            if(this.srv){
                System.Collections.Generic.IDictionary<uint, System.Collections.Generic.IList<Heijden.DNS.RecordSRV>> candidates = new System.Collections.Generic.SortedDictionary<uint, System.Collections.Generic.IList<Heijden.DNS.RecordSRV>>();
                try{
                    foreach(Heijden.DNS.AnswerRR response in new Heijden.DNS.Resolver().Query(this.host, Heijden.DNS.QType.SRV).Answers){
                        Heijden.DNS.RecordSRV record = (Heijden.DNS.RecordSRV)response.RECORD;
                        System.Collections.Generic.IList<Heijden.DNS.RecordSRV> container;
                        if(candidates.ContainsKey(record.PRIORITY)){
                         	container = candidates[record.PRIORITY];
                        }else{
                            container = new System.Collections.Generic.List<Heijden.DNS.RecordSRV>();
                            candidates.Add(record.PRIORITY, container);
                        }
                        container.Add(record);
                    }
                }catch(System.Exception e){
                    throw new MediaStorage.Exceptions.URLError("Unable to resolve SRV record: " + e.Message);
                }

                foreach(System.Collections.Generic.KeyValuePair<uint, System.Collections.Generic.IList<Heijden.DNS.RecordSRV>> c in candidates){
                    while(c.Value.Count > 0){
                        uint weight_total = 0;
                        foreach(Heijden.DNS.RecordSRV option in c.Value){
                            weight_total += option.WEIGHT;
                        }
                        uint selection = (uint)((new System.Random()).NextDouble() * weight_total);
                        Heijden.DNS.RecordSRV choice = null;
                        foreach(Heijden.DNS.RecordSRV option in c.Value){
                            selection -= option.WEIGHT;
                            if(selection <= 0){
                                choice = option;
                                break;
                            }
                        }

                        if(choice == null){ //Should never happen, but C# is a mystery I don't care to understand.
                            break;
                        }

                        string address = this.Assemble(choice.TARGET, choice.PORT, this.ssl);
                        try{
                            System.Net.HttpWebRequest request = Libraries.Communication.AssembleRequest(address + Libraries.Communication.SERVER_PING, new System.Collections.Generic.Dictionary<string, object>());
                            Libraries.Communication.SendRequest(request, timeout:1).ToDictionary();
                            return address;
                        }catch(System.Exception){
                            c.Value.Remove(choice);
                        }
                    }
                }
                throw new MediaStorage.Exceptions.URLError("Unable to resolve a viable server via SRV lookup");
            }else{
                return this.Assemble(this.host, this.port, this.ssl);
            }
        }
Exemplo n.º 9
0
 private bool WeightIsShorter(int edgeIndex, int currentWeight, int[] weights)
 {
     return(!openSet.ContainsKey(edgeIndex) || openSet[edgeIndex] > weights[edgeIndex] + currentWeight);
 }
Exemplo n.º 10
0
        private void importAll()
        {
            mDelegate       dcUpdateStatus = new mDelegate(updateStatus);
            controlDelegate cDisable       = new controlDelegate(disableControls);
            controlDelegate cEnable        = new controlDelegate(enableControls);

            this.Invoke(cDisable);

            DirectoryInfo directoryInfo = new DirectoryInfo(importPath);

            FileInfo[] fileInfos = directoryInfo.GetFiles("*.png", SearchOption.TopDirectoryOnly);
            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("Texture-([0-9]+).(PNG)");
            System.Collections.Generic.SortedDictionary <uint, string> dictionary = new System.Collections.Generic.SortedDictionary <uint, string>();
            uint highestID = 0;

            foreach (FileInfo fileInfo in fileInfos)
            {
                if (regex.IsMatch(fileInfo.Name))
                {
                    string[] tokens = regex.Split(fileInfo.Name);
                    if (tokens.Length == 4 && UInt32.TryParse(tokens[1], out uint index))
                    {
                        dictionary.Add(index, fileInfo.Name);
                        if (index > highestID)
                        {
                            highestID = index;
                        }
                    }
                }
            }

            if (dictionary.Count > 0)
            {
                totalTextures    = highestID;
                fStream.Position = 0;

                int    iEA, jEA;
                Bitmap tempBitmap = null;

                for (iEA = 0; iEA <= totalTextures; iEA++)
                {
                    this.Invoke(dcUpdateStatus, "Exporting texture " + iEA + " of " + totalTextures);

                    if (dictionary.ContainsKey((uint)iEA))
                    {
                        tempBitmap = new Bitmap(Path.Combine(importPath, dictionary[(uint)iEA]));
                        if ((tempBitmap.Size.Width != textureWidth) || (tempBitmap.Size.Height != textureHeight))
                        {
                            tempBitmap.Dispose();
                            tempBitmap = new Bitmap(textureWidth, textureHeight);
                        }
                    }
                    else
                    {
                        tempBitmap = new Bitmap(textureWidth, textureHeight);
                    }

                    int    iGT, jGT;
                    ushort a, r, g, b, pixelData;
                    int    aFactor, rFactor, gFactor, bFactor;
                    Color  colour;

                    aFactor = 1;
                    rFactor = 3;
                    gFactor = 3;
                    bFactor = 3;

                    colour = new Color();

                    fStream.Seek(getTextureOffset(iEA), SeekOrigin.Begin);

                    for (iGT = 0; iGT < textureHeight; iGT++)
                    {
                        for (jGT = 0; jGT < textureWidth; jGT++)
                        {
                            colour = tempBitmap.GetPixel(jGT, iGT);
                            a      = (ushort)(colour.A >> aFactor);
                            r      = (ushort)(colour.R >> rFactor);
                            g      = (ushort)(colour.G >> gFactor);
                            b      = (ushort)(colour.B >> bFactor);

                            a <<= 15;
                            r <<= 10;
                            g <<= 5;

                            pixelData = (ushort)(a | r | g | b);

                            bWriter.Write(pixelData);
                        }
                    }

                    tempBitmap.Dispose();
                }

                fileLength = fStream.Length;

                fStream.Seek(2, SeekOrigin.Begin);
                bWriter.Write((ushort)dictionary.Count);
                fStream.Seek(0, SeekOrigin.Begin);

                //bufferImage = getTexture(getTextureOffset(currentTexture));
                //imageUpdated = true;
            }

            this.Invoke(cEnable);
            this.Invoke(dcUpdateStatus, "Ready");
        }