Ejemplo n.º 1
0
        public Bitmap Process(Matrix matrix, InterpreterOptions options)
        {
            int height = (int)(matrix.Height * options.Scale);
            int width  = (int)(matrix.Width * options.Scale);

            // Set up the pen
            Pen = new Pen(options.Foreground)
            {
                Width = (float)options.Scale,
                Brush = new SolidBrush(options.Background)
            };

            var bitmap = new Bitmap(height, width);

            var g = Graphics.FromImage(bitmap);

            var matrixReader = new MatrixReader(matrix);

            while (matrixReader.MoveNext())
            {
                if (matrixReader.PeekCharacter() == matrixReader.NextSequentialCharacter)
                {
                    DrawPolygon(matrix, g, matrixReader.CurrentChar);
                }
                else
                {
                    DrawShape(matrix, g, matrixReader.CurrentChar);
                }
            }
            g.Flush();

            return(bitmap);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            const string  LogFile   = "log.txt";
            LogFileWriter logWriter = new LogFileWriter(LogFile);

            if (logWriter.LogFile == null)//throw exception
            {
                Console.WriteLine("LogFile doesn't exist or is readOnly!");
            }

            Console.WriteLine("Choose type of equation you want to solve: 'L' - linear, 'Q' - quadratic\n" +
                              "or any other key to exit and press 'Enter':");
            Equation equation = ChooseEquationType(Console.ReadLine().ToUpper(), logWriter);

            if (equation != null)
            {
                string result = equation.GetEquationAndSolutionRecord();
                Console.WriteLine(result);
                logWriter.WriteEquationToLog(result);
            }


            string       fileNameWithMatrix = ConfigurationManager.AppSettings["fileNameWithMatrix"];
            MatrixReader matrixReader       = new MatrixReader(fileNameWithMatrix);

            double[,] matrix1 = matrixReader.GetMatrix();
            double[,] matrix2 = matrixReader.GetMatrix();
            Console.WriteLine(MatrixCalculator.GetMultiplicationStringResult(matrix1, matrix2));
            Console.ReadKey();
        }
Ejemplo n.º 3
0
        public int GetNextMatrixRows()
        {
            switch (_type)
            {
            case Type.MatrixFile:
                return(MatrixReader.ReadMatrixFromFile(_sourceFile, _networkId).Rows);

            case Type.VectorFile:
                return(MatrixReader.ReadVectorFromFile(_sourceFile, _networkId).Rows);

            case Type.RandomDiagonal:
                return(_rows);

            case Type.RandomSymmetric:
                return(_rows);

            case Type.RandomNonSymmetric:
                return(_rows);

            case Type.RandomVector:
                return(_rows);

            case Type.RandomWithProbRange:
                return(_rows);

            case Type.NullFile:
                return(-1);

            default:
                return(0);
            }
        }
Ejemplo n.º 4
0
        public Matrix ReadNext(bool overwrite)
        {
            Matrix m = null;

            switch (_type)
            {
            case Type.MatrixFile:
                m = MatrixReader.ReadMatrixFromFile(_sourceFile, _networkId);
                break;

            case Type.VectorFile:
                m = MatrixReader.ReadVectorFromFile(_sourceFile, _networkId);
                break;

            case Type.RandomDiagonal:
                m           = RandomMatrix.LoadDiagonal(_rows, true);
                m.NetworkId = _networkId;
                break;

            case Type.RandomSymmetric:
                m           = RandomMatrix.LoadSymmetric(_rows, range, pmin, pmax);
                m.NetworkId = _networkId;
                break;

            case Type.RandomNonSymmetric:
                m           = RandomMatrix.LoadNonSymmetric(_rows, range, pmin, pmax);
                m.NetworkId = _networkId;
                break;

            case Type.RandomVector:
                m           = RandomMatrix.LoadVector(_rows);
                m.NetworkId = _networkId;
                break;

            case Type.RandomWithProbRange:
                m           = RandomMatrix.LoadWithProbabilisticRange(_rows, _cols, _min, _max);
                m.NetworkId = _networkId;
                break;

            case Type.NullFile:
                return(null);
            }

            _networkId = m.NetworkId + 1;

            if (!string.IsNullOrEmpty(_outputFile) && _type != Type.NullFile)
            {
                WriteMatrixToFile(m, _isdyadic, overwrite);
            }

            /*
             * if (m.NetworkId < 1000)
             *  m.NetworkId = int.Parse("1" + m.NetworkId);
             */
            //else
            //  m.NetworkId = int.Parse("2" + m.NetworkId);
            //m.NetworkId = int.Parse("1" + m.NetworkId);
            return(m);
        }
Ejemplo n.º 5
0
        public char PeekCharacter()
        {
            var internalReader = new MatrixReader(Matrix, CurrentChar);

            if (internalReader.MoveNext())
            {
                return(internalReader.CurrentChar);
            }
            return('\0');
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            MatrixReader matrixReader = new MatrixReader();

            matrixReader.ReadSize();
            return;
            ////Просим пользователя ввести матрицу
            //Checker.UserInputVerifiable("Введите 1-ую матрицу, разделяя ввод пробелом (чтобы закончить оставьте строку пустой):", input =>
            //{

            //});
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            String input  = Console.ReadLine(),
                   output = Console.ReadLine();

            try {
                Str[][] origin = new MatrixReader <Str>(input).GetResult(),
                result = FloydWarshallExecutor <Str> .Execute(new Matrix <Str>(origin), new StrSemigroup()).GetTable();

                MatrixWriter <Str> .WriteMatrix(result, output);
            } catch (ArgumentException exception) {
                Console.WriteLine(exception.Message);
            }
        }
Ejemplo n.º 8
0
 static void Main(string[] args)
 {
     try
     {
         String path = args[0];
         (IVertexAndEdgeListGraph <int, Edge <int> > graph,
          Func <Edge <int>, double> edgeCost) = GraphCreator.Create(MatrixReader.Read(path));
         TryFunc <int, IEnumerable <Edge <int> > > tryGetPath = graph.ShortestPathsDijkstra(edgeCost, 0);
         PdfGenerator.Generate(DotGenerator <int, Edge <int> > .GetDotCode(graph, tryGetPath), args[1]);
     }
     catch (IndexOutOfRangeException)
     {
         Console.Error.WriteLine("Path to graph matrix must be given");
     }
 }
 static void Main(String[] args)
 {
     try {
         String path = args[0];
         (IVertexAndEdgeListGraph <int, Edge <int> > graph,
          Func <Edge <int>, double> edgeCost) = new GraphCreator(MatrixReader.ReadMatrix(path)).GetResult();
         TryFunc <int, IEnumerable <Edge <int> > > tryGetPath = graph.ShortestPathsDijkstra(edgeCost, 0);
         DotGenerator <int, Edge <int> >           generator  = new DotGenerator <int, Edge <int> >(graph, tryGetPath);
         (new PDFGenerator(generator.GetDotCode(), args[1])).GeneratePDF();
     } catch (IndexOutOfRangeException exn) {
         Console.Error.WriteLine("Path to adjacency matrix should be given.");
     } catch (Exception exn) {
         Console.Error.WriteLine(exn.Message);
     }
 }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            String input   = Console.ReadLine(),
                   output  = Console.ReadLine(),
                   dotfile = output + ".tmp";

            try {
                Boolean[][] origin = new MatrixReader <Boolean>(input).GetResult(),
                result = FloydWarshallExecutor <Boolean> .Execute(new Matrix <Boolean>(origin), new BooleanSemigroup()).GetTable();

                DotMediator.CreateDot(origin, result, dotfile);
                DotMediator.ProcessDot(dotfile, output);
                File.Delete(dotfile);
            } catch (Exception exception) {
                Console.WriteLine(exception.Message);
            }
        }
Ejemplo n.º 11
0
        private void goButton_Click(object sender, EventArgs e)
        {
            if (maxExtraction.Checked)
            {
                net.cet = Network.CliqueExtractionType.Max;
            }
            else if (minExtraction.Checked)
            {
                net.cet = Network.CliqueExtractionType.Min;
            }
            else if (upperExtraction.Checked)
            {
                net.cet = Network.CliqueExtractionType.Upper;
            }
            else if (lowerExtraction.Checked)
            {
                net.cet = Network.CliqueExtractionType.Lower;
            }

            if (inputTypeMatrix.Checked || inputTypeDyadic.Checked || inputTypeAtt.Checked) //(12/12/15) for invalid file selection
            {
                net.CohesionFilename = CohesionFileName;

                if (inputTypeAtt.Checked) //attribute vector
                {
                    //obtains the Network Id from the main Matrix
                    net.CohesionMatrix = MatrixReader.ReadAttributeVector(CohesionFilename, net.GetMatrix("Data").NetworkId);
                }

                else // other options
                {
                    net.CohesionMatrix = MatrixReader.ReadMatrixFromFile(CohesionFilename);
                }
            }
            double tmp;

            if ((binaryCutoff.Text != Constants.FileSelected && !double.TryParse(binaryCutoff.Text, out tmp) ||
                 (densityMax.Text != Constants.FileSelected && !double.TryParse(densityMax.Text, out d))) ||
                (reachNumMatrices.Text != Constants.FileSelected && !int.TryParse(reachNumMatrices.Text, out r)) ||
                (viableCoalitionValue.Text != Constants.FileSelected && !double.TryParse(viableCoalitionValue.Text, out v)) ||
                (cMinMembers.Text != Constants.FileSelected && !int.TryParse(cMinMembers.Text, out m)) ||
                (kCliqueValue.Text != Constants.FileSelected && !int.TryParse(kCliqueValue.Text, out k)) ||
                (!double.TryParse(alphaValue.Text, out a)))
            {
                MessageBox.Show("You have not entered proper real numbers!", "Error!");
            }
            else
            {
                if (densityMax.Text == Constants.FileSelected)
                {
                    d = -1.0;
                }
                if (reachNumMatrices.Text == Constants.FileSelected)
                {
                    r = -1;
                }
                if (viableCoalitionValue.Text == Constants.FileSelected)
                {
                    v = -1;
                }
                if (cMinMembers.Text == Constants.FileSelected)
                {
                    m = -1;
                }
                if (kCliqueValue.Text == Constants.FileSelected)
                {
                    k = -1;
                }
                this.Close();
            }
        }
Ejemplo n.º 12
0
		internal ContentTypeReader[] LoadAssetReaders()
        {
#pragma warning disable 0219, 0649
            // Trick to prevent the linker removing the code, but not actually execute the code
            if (falseflag)
            {
                // Dummy variables required for it to work on iDevices ** DO NOT DELETE ** 
                // This forces the classes not to be optimized out when deploying to iDevices
                var hByteReader = new ByteReader();
                var hSByteReader = new SByteReader();
                var hDateTimeReader = new DateTimeReader();
                var hDecimalReader = new DecimalReader();
                var hBoundingSphereReader = new BoundingSphereReader();
                var hBoundingFrustumReader = new BoundingFrustumReader();
                var hRayReader = new RayReader();
                var hCharListReader = new ListReader<Char>();
                var hRectangleListReader = new ListReader<Rectangle>();
                var hVector3ListReader = new ListReader<Vector3>();
                var hStringListReader = new ListReader<StringReader>();
                var hSpriteFontReader = new SpriteFontReader();
                var hTexture2DReader = new Texture2DReader();
                var hCharReader = new CharReader();
                var hRectangleReader = new RectangleReader();
                var hStringReader = new StringReader();
                var hVector2Reader = new Vector2Reader();
                var hVector3Reader = new Vector3Reader();
                var hVector4Reader = new Vector4Reader();
                var hCurveReader = new CurveReader();
                var hIndexBufferReader = new IndexBufferReader();
                var hBoundingBoxReader = new BoundingBoxReader();
                var hMatrixReader = new MatrixReader();
                var hBasicEffectReader = new BasicEffectReader();
                var hVertexBufferReader = new VertexBufferReader();
                var hAlphaTestEffectReader = new AlphaTestEffectReader();
            }
#pragma warning restore 0219, 0649

            int numberOfReaders;
			
            // The first content byte i read tells me the number of content readers in this XNB file
            numberOfReaders = _reader.Read7BitEncodedInt();
            contentReaders = new ContentTypeReader[numberOfReaders];
		
            // For each reader in the file, we read out the length of the string which contains the type of the reader,
            // then we read out the string. Finally we instantiate an instance of that reader using reflection
            for (int i = 0; i < numberOfReaders; i++)
            {
                // This string tells us what reader we need to decode the following data
                // string readerTypeString = reader.ReadString();
				string originalReaderTypeString = _reader.ReadString();
 
				// Need to resolve namespace differences
				string readerTypeString = originalReaderTypeString;
								
				readerTypeString = PrepareType(readerTypeString);

				Type l_readerType = Type.GetType(readerTypeString);
				
            	if(l_readerType !=null)
					contentReaders[i] = (ContentTypeReader)Activator.CreateInstance(l_readerType,true);
            	else
					throw new ContentLoadException("Could not find matching content reader of type " + originalReaderTypeString + " (" + readerTypeString + ")");
				
				// I think the next 4 bytes refer to the "Version" of the type reader,
                // although it always seems to be zero
                int typeReaderVersion = _reader.ReadInt32();
            }

            return contentReaders;
        }
Ejemplo n.º 13
0
 internal ContentTypeReader[] LoadAssetReaders()
 {
   if (ContentTypeReaderManager.falseflag)
   {
     ByteReader byteReader = new ByteReader();
     SByteReader sbyteReader = new SByteReader();
     DateTimeReader dateTimeReader = new DateTimeReader();
     DecimalReader decimalReader = new DecimalReader();
     BoundingSphereReader boundingSphereReader = new BoundingSphereReader();
     BoundingFrustumReader boundingFrustumReader = new BoundingFrustumReader();
     RayReader rayReader = new RayReader();
     ListReader<char> listReader1 = new ListReader<char>();
     ListReader<Rectangle> listReader2 = new ListReader<Rectangle>();
     ArrayReader<Rectangle> arrayReader1 = new ArrayReader<Rectangle>();
     ListReader<Vector3> listReader3 = new ListReader<Vector3>();
     ListReader<StringReader> listReader4 = new ListReader<StringReader>();
     ListReader<int> listReader5 = new ListReader<int>();
     SpriteFontReader spriteFontReader = new SpriteFontReader();
     Texture2DReader texture2Dreader = new Texture2DReader();
     CharReader charReader = new CharReader();
     RectangleReader rectangleReader = new RectangleReader();
     StringReader stringReader = new StringReader();
     Vector2Reader vector2Reader = new Vector2Reader();
     Vector3Reader vector3Reader = new Vector3Reader();
     Vector4Reader vector4Reader = new Vector4Reader();
     CurveReader curveReader = new CurveReader();
     IndexBufferReader indexBufferReader = new IndexBufferReader();
     BoundingBoxReader boundingBoxReader = new BoundingBoxReader();
     MatrixReader matrixReader = new MatrixReader();
     BasicEffectReader basicEffectReader = new BasicEffectReader();
     VertexBufferReader vertexBufferReader = new VertexBufferReader();
     AlphaTestEffectReader testEffectReader = new AlphaTestEffectReader();
     EnumReader<SpriteEffects> enumReader1 = new EnumReader<SpriteEffects>();
     ArrayReader<float> arrayReader2 = new ArrayReader<float>();
     ArrayReader<Vector2> arrayReader3 = new ArrayReader<Vector2>();
     ListReader<Vector2> listReader6 = new ListReader<Vector2>();
     ArrayReader<Matrix> arrayReader4 = new ArrayReader<Matrix>();
     EnumReader<Blend> enumReader2 = new EnumReader<Blend>();
     NullableReader<Rectangle> nullableReader = new NullableReader<Rectangle>();
     EffectMaterialReader effectMaterialReader = new EffectMaterialReader();
     ExternalReferenceReader externalReferenceReader = new ExternalReferenceReader();
   }
   int length = this._reader.Read7BitEncodedInt();
   this.contentReaders = new ContentTypeReader[length];
   for (int index = 0; index < length; ++index)
   {
     string str = this._reader.ReadString();
     Func<ContentTypeReader> func;
     if (ContentTypeReaderManager.typeCreators.TryGetValue(str, out func))
     {
       this.contentReaders[index] = func();
     }
     else
     {
       string typeName = ContentTypeReaderManager.PrepareType(str);
       Type type = Type.GetType(typeName);
       if (type != (Type) null)
       {
         try
         {
           this.contentReaders[index] = ContentExtensions.GetDefaultConstructor(type).Invoke((object[]) null) as ContentTypeReader;
         }
         catch (TargetInvocationException ex)
         {
           throw new InvalidOperationException("Failed to get default constructor for ContentTypeReader. To work around, add a creation function to ContentTypeReaderManager.AddTypeCreator() with the following failed type string: " + str);
         }
       }
       else
         throw new ContentLoadException("Could not find matching content reader of type " + str + " (" + typeName + ")");
     }
     this._reader.ReadInt32();
   }
   return this.contentReaders;
 }
Ejemplo n.º 14
0
        private void BackgroundWorkerReader_DoWork(object sender, DoWorkEventArgs e)
        {
            var path = e.Argument as string;

            e.Result = MatrixReader.Read(path);
        }
		internal ContentTypeReader[] LoadAssetReaders()
        {
#pragma warning disable 0219, 0649
            // Trick to prevent the linker removing the code, but not actually execute the code
            if (falseflag)
            {
                // Dummy variables required for it to work on iDevices ** DO NOT DELETE ** 
                // This forces the classes not to be optimized out when deploying to iDevices
                var hByteReader = new ByteReader();
                var hSByteReader = new SByteReader();
                var hDateTimeReader = new DateTimeReader();
                var hDecimalReader = new DecimalReader();
                var hBoundingSphereReader = new BoundingSphereReader();
                var hBoundingFrustumReader = new BoundingFrustumReader();
                var hRayReader = new RayReader();
                var hCharListReader = new ListReader<Char>();
                var hRectangleListReader = new ListReader<Rectangle>();
                var hRectangleArrayReader = new ArrayReader<Rectangle>();
                var hVector3ListReader = new ListReader<Vector3>();
                var hStringListReader = new ListReader<StringReader>();
				var hIntListReader = new ListReader<Int32>();
                var hSpriteFontReader = new SpriteFontReader();
                var hTexture2DReader = new Texture2DReader();
                var hCharReader = new CharReader();
                var hRectangleReader = new RectangleReader();
                var hStringReader = new StringReader();
                var hVector2Reader = new Vector2Reader();
                var hVector3Reader = new Vector3Reader();
                var hVector4Reader = new Vector4Reader();
                var hCurveReader = new CurveReader();
                var hIndexBufferReader = new IndexBufferReader();
                var hBoundingBoxReader = new BoundingBoxReader();
                var hMatrixReader = new MatrixReader();
                var hBasicEffectReader = new BasicEffectReader();
                var hVertexBufferReader = new VertexBufferReader();
                var hAlphaTestEffectReader = new AlphaTestEffectReader();
                var hEnumSpriteEffectsReader = new EnumReader<Graphics.SpriteEffects>();
                var hArrayFloatReader = new ArrayReader<float>();
                var hArrayVector2Reader = new ArrayReader<Vector2>();
                var hListVector2Reader = new ListReader<Vector2>();
                var hArrayMatrixReader = new ArrayReader<Matrix>();
                var hEnumBlendReader = new EnumReader<Graphics.Blend>();
                var hNullableRectReader = new NullableReader<Rectangle>();
				var hEffectMaterialReader = new EffectMaterialReader();
				var hExternalReferenceReader = new ExternalReferenceReader();
                var hSoundEffectReader = new SoundEffectReader();
                var hSongReader = new SongReader();
            }
#pragma warning restore 0219, 0649

            int numberOfReaders;
			
            // The first content byte i read tells me the number of content readers in this XNB file
            numberOfReaders = _reader.Read7BitEncodedInt();
            contentReaders = new ContentTypeReader[numberOfReaders];
		
            // For each reader in the file, we read out the length of the string which contains the type of the reader,
            // then we read out the string. Finally we instantiate an instance of that reader using reflection
            for (int i = 0; i < numberOfReaders; i++)
            {
                // This string tells us what reader we need to decode the following data
                // string readerTypeString = reader.ReadString();
				string originalReaderTypeString = _reader.ReadString();

                Func<ContentTypeReader> readerFunc;
                if (typeCreators.TryGetValue(originalReaderTypeString, out readerFunc))
                {
                    contentReaders[i] = readerFunc();
                }
                else
                {
                    //System.Diagnostics.Debug.WriteLine(originalReaderTypeString);

    				// Need to resolve namespace differences
    				string readerTypeString = originalReaderTypeString;

    				readerTypeString = PrepareType(readerTypeString);

    				var l_readerType = Type.GetType(readerTypeString);
                    if (l_readerType != null)
                    {
                        try
                        {
                            contentReaders[i] = l_readerType.GetDefaultConstructor().Invoke(null) as ContentTypeReader;
                        }
                        catch (TargetInvocationException ex)
                        {
                            // If you are getting here, the Mono runtime is most likely not able to JIT the type.
                            // In particular, MonoTouch needs help instantiating types that are only defined in strings in Xnb files. 
                            throw new InvalidOperationException(
                                "Failed to get default constructor for ContentTypeReader. To work around, add a creation function to ContentTypeReaderManager.AddTypeCreator() " +
                                "with the following failed type string: " + originalReaderTypeString);
                        }
                    }
                    else
                        throw new ContentLoadException(
                                "Could not find ContentTypeReader Type. Please ensure the name of the Assembly that contains the Type matches the assembly in the full type name: " + 
                                originalReaderTypeString + " (" + readerTypeString + ")");
                }

				// I think the next 4 bytes refer to the "Version" of the type reader,
                // although it always seems to be zero
                int typeReaderVersion = _reader.ReadInt32();
            }

            return contentReaders;
        }
Ejemplo n.º 16
0
        internal ContentTypeReader[] LoadAssetReaders(ContentReader reader)
        {
            #pragma warning disable 0219, 0649
            /* Trick to prevent the linker removing the code, but not actually execute the code
             * FIXME: Do we really need this in FNA?
             */
            if (falseflag)
            {
                /* Dummy variables required for it to work on iDevices ** DO NOT DELETE **
                 * This forces the classes not to be optimized out when deploying to iDevices
                 */
                ByteReader hByteReader = new ByteReader();
                SByteReader hSByteReader = new SByteReader();
                DateTimeReader hDateTimeReader = new DateTimeReader();
                DecimalReader hDecimalReader = new DecimalReader();
                BoundingSphereReader hBoundingSphereReader = new BoundingSphereReader();
                BoundingFrustumReader hBoundingFrustumReader = new BoundingFrustumReader();
                RayReader hRayReader = new RayReader();
                ListReader<char> hCharListReader = new ListReader<Char>();
                ListReader<Rectangle> hRectangleListReader = new ListReader<Rectangle>();
                ArrayReader<Rectangle> hRectangleArrayReader = new ArrayReader<Rectangle>();
                ListReader<Vector3> hVector3ListReader = new ListReader<Vector3>();
                ListReader<StringReader> hStringListReader = new ListReader<StringReader>();
                ListReader<int> hIntListReader = new ListReader<Int32>();
                SpriteFontReader hSpriteFontReader = new SpriteFontReader();
                Texture2DReader hTexture2DReader = new Texture2DReader();
                CharReader hCharReader = new CharReader();
                RectangleReader hRectangleReader = new RectangleReader();
                StringReader hStringReader = new StringReader();
                Vector2Reader hVector2Reader = new Vector2Reader();
                Vector3Reader hVector3Reader = new Vector3Reader();
                Vector4Reader hVector4Reader = new Vector4Reader();
                CurveReader hCurveReader = new CurveReader();
                IndexBufferReader hIndexBufferReader = new IndexBufferReader();
                BoundingBoxReader hBoundingBoxReader = new BoundingBoxReader();
                MatrixReader hMatrixReader = new MatrixReader();
                BasicEffectReader hBasicEffectReader = new BasicEffectReader();
                VertexBufferReader hVertexBufferReader = new VertexBufferReader();
                AlphaTestEffectReader hAlphaTestEffectReader = new AlphaTestEffectReader();
                EnumReader<Microsoft.Xna.Framework.Graphics.SpriteEffects> hEnumSpriteEffectsReader = new EnumReader<Graphics.SpriteEffects>();
                ArrayReader<float> hArrayFloatReader = new ArrayReader<float>();
                ArrayReader<Vector2> hArrayVector2Reader = new ArrayReader<Vector2>();
                ListReader<Vector2> hListVector2Reader = new ListReader<Vector2>();
                ArrayReader<Matrix> hArrayMatrixReader = new ArrayReader<Matrix>();
                EnumReader<Microsoft.Xna.Framework.Graphics.Blend> hEnumBlendReader = new EnumReader<Graphics.Blend>();
                NullableReader<Rectangle> hNullableRectReader = new NullableReader<Rectangle>();
                EffectMaterialReader hEffectMaterialReader = new EffectMaterialReader();
                ExternalReferenceReader hExternalReferenceReader = new ExternalReferenceReader();
                SoundEffectReader hSoundEffectReader = new SoundEffectReader();
                SongReader hSongReader = new SongReader();
            }
            #pragma warning restore 0219, 0649

            /* The first content byte i read tells me the number of
             * content readers in this XNB file.
             */
            int numberOfReaders = reader.Read7BitEncodedInt();
            ContentTypeReader[] newReaders = new ContentTypeReader[numberOfReaders];
            BitArray needsInitialize = new BitArray(numberOfReaders);
            contentReaders = new Dictionary<Type, ContentTypeReader>(numberOfReaders);

            /* Lock until we're done allocating and initializing any new
             * content type readers... this ensures we can load content
             * from multiple threads and still cache the readers.
             */
            lock (locker)
            {
                /* For each reader in the file, we read out the
                 * length of the string which contains the type
                 * of the reader, then we read out the string.
                 * Finally we instantiate an instance of that
                 * reader using reflection.
                 */
                for (int i = 0; i < numberOfReaders; i += 1)
                {
                    /* This string tells us what reader we
                     * need to decode the following data.
                     */
                    string originalReaderTypeString = reader.ReadString();

                    Func<ContentTypeReader> readerFunc;
                    if (typeCreators.TryGetValue(originalReaderTypeString, out readerFunc))
                    {
                        newReaders[i] = readerFunc();
                        needsInitialize[i] = true;
                    }
                    else
                    {
                        // Need to resolve namespace differences
                        string readerTypeString = originalReaderTypeString;
                        readerTypeString = PrepareType(readerTypeString);

                        Type l_readerType = Type.GetType(readerTypeString);
                        if (l_readerType != null)
                        {
                            ContentTypeReader typeReader;
                            if (!contentReadersCache.TryGetValue(l_readerType, out typeReader))
                            {
                                try
                                {
                                    typeReader = l_readerType.GetDefaultConstructor().Invoke(null) as ContentTypeReader;
                                }
                                catch (TargetInvocationException ex)
                                {
                                    /* If you are getting here, the Mono runtime
                                     * is most likely not able to JIT the type.
                                     * In particular, MonoTouch needs help
                                     * instantiating types that are only defined
                                     * in strings in Xnb files.
                                     */
                                    throw new InvalidOperationException(
                                        "Failed to get default constructor for ContentTypeReader. " +
                                        "To work around, add a creation function to ContentTypeReaderManager.AddTypeCreator() " +
                                        "with the following failed type string: " + originalReaderTypeString,
                                        ex
                                    );
                                }

                                needsInitialize[i] = true;

                                contentReadersCache.Add(l_readerType, typeReader);
                            }

                            newReaders[i] = typeReader;
                        }
                        else
                        {
                            throw new ContentLoadException(
                                    "Could not find ContentTypeReader Type. " +
                                    "Please ensure the name of the Assembly that " +
                                    "contains the Type matches the assembly in the full type name: " +
                                    originalReaderTypeString + " (" + readerTypeString + ")"
                            );
                        }
                    }

                    contentReaders.Add(newReaders[i].TargetType, newReaders[i]);

                    /* I think the next 4 bytes refer to the "Version" of the type reader,
                     * although it always seems to be zero.
                     */
                    reader.ReadInt32();
                }

                // Initialize any new readers.
                for (int i = 0; i < newReaders.Length; i += 1)
                {
                    if (needsInitialize.Get(i))
                    {
                        newReaders[i].Initialize(this);
                    }
                }
            } // lock (locker)

            return newReaders;
        }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            String path         = args[0],
                   output       = args[1];
            var adjacencyMatrix = MatrixReader.Reader(path);

            (BidirectionalMatrixGraph <Edge <int> > graph,
             Func <Edge <int>, double> edgeWeights, int vertexCount) = new Graph(adjacencyMatrix).GetResult();

            int root = 0;

            TryFunc <int, IEnumerable <Edge <int> > > tryGetPaths = graph.ShortestPathsDijkstra(edgeWeights, root);

            var graphShort = new BidirectionalMatrixGraph <Edge <int> >(vertexCount);

            // query path for given vertices
            foreach (var target in graph.Vertices)
            {
                IEnumerable <Edge <int> > pathShort;
                if (tryGetPaths(target, out pathShort))
                {
                    foreach (var edge in pathShort)
                    {
                        if (!graphShort.ContainsEdge(edge))
                        {
                            graphShort.AddEdge(edge);
                        }
                    }
                }
            }

            // render
            String GetDotCode(BidirectionalMatrixGraph <Edge <int> > shortestTree, BidirectionalMatrixGraph <Edge <int> > graph)
            {
                StringBuilder builder = new StringBuilder();

                builder.AppendLine("digraph G {");
                foreach (var vertex in graph.Vertices)
                {
                    builder.Append(vertex.ToString());
                    builder.AppendLine(";");
                }
                foreach (var edge in graph.Edges)
                {
                    builder.Append(edge.ToString());
                    if (shortestTree.ContainsEdge(edge))
                    {
                        builder.AppendLine(" [color = red];");
                    }
                    else
                    {
                        builder.AppendLine(" [];");
                    }
                }
                builder.AppendLine("}");
                return(builder.ToString());
            }

            void GeneratePDF(String output, String dot)
            {
                String dotFile = output + ".dot";

                using (StreamWriter writer = File.CreateText(dotFile))
                    writer.Write(dot);
                using (Process process = new Process())
                {
                    process.StartInfo.FileName  = "dot";
                    process.StartInfo.Arguments = "-Tpdf -o" + output + " " + dotFile;
                    process.Start();
                    while (!process.HasExited)
                    {
                        process.Refresh();
                    }
                }
                File.Delete(dotFile);
            }

            string outputDot = GetDotCode(graphShort, graph);

            GeneratePDF(output, outputDot);
        }
		internal ContentTypeReader[] LoadAssetReaders(ContentReader reader)
        {
#pragma warning disable 0219, 0649
            // Trick to prevent the linker removing the code, but not actually execute the code
            if (falseflag)
            {
                // Dummy variables required for it to work on iDevices ** DO NOT DELETE ** 
                // This forces the classes not to be optimized out when deploying to iDevices
                var hByteReader = new ByteReader();
                var hSByteReader = new SByteReader();
                var hDateTimeReader = new DateTimeReader();
                var hDecimalReader = new DecimalReader();
                var hBoundingSphereReader = new BoundingSphereReader();
                var hBoundingFrustumReader = new BoundingFrustumReader();
                var hRayReader = new RayReader();
                var hCharListReader = new ListReader<Char>();
                var hRectangleListReader = new ListReader<Rectangle>();
                var hRectangleArrayReader = new ArrayReader<Rectangle>();
                var hVector3ListReader = new ListReader<Vector3>();
                var hStringListReader = new ListReader<StringReader>();
				var hIntListReader = new ListReader<Int32>();
                var hSpriteFontReader = new SpriteFontReader();
                var hTexture2DReader = new Texture2DReader();
                var hCharReader = new CharReader();
                var hRectangleReader = new RectangleReader();
                var hStringReader = new StringReader();
                var hVector2Reader = new Vector2Reader();
                var hVector3Reader = new Vector3Reader();
                var hVector4Reader = new Vector4Reader();
                var hCurveReader = new CurveReader();
                var hIndexBufferReader = new IndexBufferReader();
                var hBoundingBoxReader = new BoundingBoxReader();
                var hMatrixReader = new MatrixReader();
                var hBasicEffectReader = new BasicEffectReader();
                var hVertexBufferReader = new VertexBufferReader();
                var hAlphaTestEffectReader = new AlphaTestEffectReader();
                var hEnumSpriteEffectsReader = new EnumReader<Graphics.SpriteEffects>();
                var hArrayFloatReader = new ArrayReader<float>();
                var hArrayVector2Reader = new ArrayReader<Vector2>();
                var hListVector2Reader = new ListReader<Vector2>();
                var hArrayMatrixReader = new ArrayReader<Matrix>();
                var hEnumBlendReader = new EnumReader<Graphics.Blend>();
                var hNullableRectReader = new NullableReader<Rectangle>();
				var hEffectMaterialReader = new EffectMaterialReader();
				var hExternalReferenceReader = new ExternalReferenceReader();
                var hSoundEffectReader = new SoundEffectReader();
                var hSongReader = new SongReader();
                var hModelReader = new ModelReader();
                var hInt32Reader = new Int32Reader();

                // At the moment the Video class doesn't exist
                // on all platforms... Allow it to compile anyway.
#if ANDROID || IOS || MONOMAC || (WINDOWS && !OPENGL) || (WINRT && !WINDOWS_PHONE)
                var hVideoReader = new VideoReader();
#endif
            }
#pragma warning restore 0219, 0649

		    // The first content byte i read tells me the number of content readers in this XNB file
            var numberOfReaders = reader.Read7BitEncodedInt();
            var contentReaders = new ContentTypeReader[numberOfReaders];
            var needsInitialize = new BitArray(numberOfReaders);
            _contentReaders = new Dictionary<Type, ContentTypeReader>(numberOfReaders);

            // Lock until we're done allocating and initializing any new
            // content type readers...  this ensures we can load content
            // from multiple threads and still cache the readers.
            lock (_locker)
            {
                // For each reader in the file, we read out the length of the string which contains the type of the reader,
                // then we read out the string. Finally we instantiate an instance of that reader using reflection
                for (var i = 0; i < numberOfReaders; i++)
                {
                    // This string tells us what reader we need to decode the following data
                    // string readerTypeString = reader.ReadString();
                    string originalReaderTypeString = reader.ReadString();

                    Func<ContentTypeReader> readerFunc;
                    if (typeCreators.TryGetValue(originalReaderTypeString, out readerFunc))
                    {
                        contentReaders[i] = readerFunc();
                        needsInitialize[i] = true;
                    }
                    else
                    {
                        //System.Diagnostics.Debug.WriteLine(originalReaderTypeString);

                        // Need to resolve namespace differences
                        string readerTypeString = originalReaderTypeString;

                        readerTypeString = PrepareType(readerTypeString);

                        var l_readerType = Type.GetType(readerTypeString);
                        if (l_readerType != null)
                        {
                            ContentTypeReader typeReader;
                            if (!_contentReadersCache.TryGetValue(l_readerType, out typeReader))
                            {
                                try
                                {
                                    typeReader = l_readerType.GetDefaultConstructor().Invoke(null) as ContentTypeReader;
                                }
                                catch (TargetInvocationException ex)
                                {
                                    // If you are getting here, the Mono runtime is most likely not able to JIT the type.
                                    // In particular, MonoTouch needs help instantiating types that are only defined in strings in Xnb files. 
                                    throw new InvalidOperationException(
                                        "Failed to get default constructor for ContentTypeReader. To work around, add a creation function to ContentTypeReaderManager.AddTypeCreator() " +
                                        "with the following failed type string: " + originalReaderTypeString, ex);
                                }

                                needsInitialize[i] = true;

                                _contentReadersCache.Add(l_readerType, typeReader);
                            }

                            contentReaders[i] = typeReader;
                        }
                        else
                            throw new ContentLoadException(
                                    "Could not find ContentTypeReader Type. Please ensure the name of the Assembly that contains the Type matches the assembly in the full type name: " +
                                    originalReaderTypeString + " (" + readerTypeString + ")");
                    }

                    var targetType = contentReaders[i].TargetType;
                    if (targetType != null)
                      _contentReaders.Add(targetType, contentReaders[i]);

                    // I think the next 4 bytes refer to the "Version" of the type reader,
                    // although it always seems to be zero
                    reader.ReadInt32();
                }

                // Initialize any new readers.
                for (var i = 0; i < contentReaders.Length; i++)
                {
                    if (needsInitialize.Get(i))
                        contentReaders[i].Initialize(this);
                }

            } // lock (_locker)

		    return contentReaders;
        }