public void LoadShouldThrowExceptionIfStateFileDoesNotExist()
        {
            Expect.Call(executionEnvironment.GetDefaultProgramDataFolder(ApplicationType.Server)).IgnoreArguments().Constraints(Rhino.Mocks.Constraints.Is.NotNull()).Return(applicationDataPath);
            Expect.Call(delegate { fileSystem.EnsureFolderExists(applicationDataPath); });
            Expect.Call(fileSystem.Load(null)).IgnoreArguments().Constraints(Rhino.Mocks.Constraints.Is.NotNull()).Throw(new FileNotFoundException());
            mocks.ReplayAll();

            state              = new FileStateManager(fileSystem, executionEnvironment);
            result             = IntegrationResultMother.CreateSuccessful();
            result.ProjectName = ProjectName;

            Assert.That(delegate { state.LoadState(ProjectName); },
                        Throws.TypeOf <CruiseControlException>().With.Property("InnerException").TypeOf <FileNotFoundException>());
        }
Example #2
0
        public static Canvas LoadGUI(string a_filename, IFileSystem a_fileSystem, Pipeline a_pipeline)
        {
            if (a_fileSystem != null)
            {
                Stream stream;
                if (a_fileSystem.Load(a_filename, out stream))
                {
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.Load(stream);

                    Canvas canv = Load(xmlDocument, a_fileSystem, a_pipeline);

                    if (canv != null)
                    {
                        canv.m_fileSystem = a_fileSystem;
                    }

                    return(canv);
                }
                else
                {
                    InternalConsole.Error("Cannot access canvas file");
                }
            }
            else
            {
                InternalConsole.Error("No filesystem to load from for canvas");
            }

            return(null);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="NSubstituteMockFactory"/> class.
 /// </summary>
 /// <param name="fileSystem">The file system wrapper.</param>
 /// <exception cref="System.InvalidOperationException">Unable to find Type NSubstitute.Substitute in assembly  + assembly.Location</exception>
 public NSubstituteMockFactory(IFileSystem fileSystem)
 {
     var assembly = fileSystem.Load("NSubstitute");
     _mockOpenType = fileSystem.GetTypeFrom(assembly, "NSubstitute.Substitute");
     if (_mockOpenType == null)
         throw new InvalidOperationException("Unable to find Type NSubstitute.Substitute in assembly " + assembly.Location);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FakeItEasyMockFactory"/> class.
 /// </summary>
 /// <param name="fileSystem">The file system.</param>
 /// <exception cref="System.InvalidOperationException">Unable to find Type FakeItEasy.A in assembly  + assembly.Location</exception>
 public FakeItEasyMockFactory(IFileSystem fileSystem)
 {
     var assembly = fileSystem.Load("FakeItEasy");
     _mockOpenType = fileSystem.GetTypeFrom(assembly, "FakeItEasy.A");
     if (_mockOpenType == null)
         throw new InvalidOperationException("Unable to find Type FakeItEasy.A in assembly " + assembly.Location);
 }
Example #5
0
        private FileResult GetImage(int id, Size size)
        {
            var image = ExecuteQuery(session => session.Load <Image>(id));
            var file  = _fileSystem.Load(image.FileName);

            return(File(_imageResizer.Resize(file, size), image.ContentType, image.FileName));
        }
Example #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FakeItEasyMockFactory"/> class.
        /// </summary>
        /// <param name="fileSystem">The file system.</param>
        /// <exception cref="System.InvalidOperationException">Unable to find Type FakeItEasy.A in assembly  + assembly.Location</exception>
        public FakeItEasyMockFactory(IFileSystem fileSystem)
        {
            var assembly = fileSystem.Load("FakeItEasy");

            _mockOpenType = fileSystem.GetTypeFrom(assembly, "FakeItEasy.A");
            if (_mockOpenType == null)
            {
                throw new InvalidOperationException("Unable to find Type FakeItEasy.A in assembly " + assembly.Location);
            }
        }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NSubstituteMockFactory"/> class.
        /// </summary>
        /// <param name="fileSystem">The file system wrapper.</param>
        /// <exception cref="System.InvalidOperationException">Unable to find Type NSubstitute.Substitute in assembly  + assembly.Location</exception>
        public NSubstituteMockFactory(IFileSystem fileSystem)
        {
            var assembly = fileSystem.Load("NSubstitute");

            _mockOpenType = fileSystem.GetTypeFrom(assembly, "NSubstitute.Substitute");
            if (_mockOpenType == null)
            {
                throw new InvalidOperationException("Unable to find Type NSubstitute.Substitute in assembly " + assembly.Location);
            }
        }
Example #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MoqMockFactory"/> class.
        /// </summary>
        /// <param name="fileSystem">The file system.</param>
        /// <exception cref="System.InvalidOperationException">Unable to find Type Moq.Mock`1 in assembly  + assembly.Location</exception>
        public MoqMockFactory(IFileSystem fileSystem)
        {
            var assembly = fileSystem.Load("Moq");

            _mockOpenType = fileSystem.GetTypeFrom(assembly, "Moq.Mock`1");
            if (_mockOpenType == null)
            {
                throw new InvalidOperationException("Unable to find Type Moq.Mock`1 in assembly " + assembly.Location);
            }
        }
Example #9
0
        public void ModifyObject()
        {
            m_texture = GL.GenTexture();
            GL.BindTexture(TextureTarget.TextureCubeMap, m_texture);

            for (int i = 0; i < 6; ++i)
            {
                Bitmap map = null;

                if (m_fileSystem != null)
                {
                    Stream stream;

                    if (m_fileSystem.Load(m_filePaths[i], out stream))
                    {
                        map = new Bitmap(stream);
                    }
                }
                else
                {
                    map = new Bitmap(m_filePaths[i]);
                }

                BitmapData data = map.LockBits(new Rectangle(0, 0, map.Width, map.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

                GL.TexImage2D
                (
                    TextureTarget.TextureCubeMapPositiveX + i,
                    0,
                    PixelInternalFormat.Rgba,
                    map.Width, map.Height,
                    0,
                    OpenTK.Graphics.OpenGL.PixelFormat.Bgra,
                    PixelType.UnsignedByte,
                    data.Scan0
                );

                m_width  = map.Width;
                m_height = map.Height;

                map.UnlockBits(data);
            }

            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, (int)All.Linear);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, (int)All.Linear);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapR, (int)All.ClampToEdge);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, (int)All.ClampToEdge);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, (int)All.ClampToEdge);
        }
        /// <summary>
        /// Loads the state into an <see cref="XmlDocument"/>.
        /// </summary>
        /// <param name="project">The name of the project.</param>
        /// <returns>An <see cref="XmlDocument"/> containing the state.</returns>
        private XmlDocument LoadStateIntoDocument(string project)
        {
            var    document      = new XmlDocument();
            string stateFilePath = GetFilePath(project);

            try
            {
                document.Load(
                    fileSystem.Load(stateFilePath));
                return(document);
            }
            catch (Exception e)
            {
                throw new CruiseControlException(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Unable to read the specified state file: {0}.  The path may be invalid.", stateFilePath), e);
            }
        }
Example #11
0
        void AddVoxelObject(Vector3 a_position)
        {
            GameObject obj = new GameObject();

            obj.Transform.Translation = a_position * VoxelObjectSize;
            obj.Transform.SetStatic();

            Chunk chunk = obj.AddComponent <Chunk>();

            chunk.InitialiseVoxelObject(GridDepth, VoxelSize, m_pipeline);
            chunk.SetMaterial(m_material, m_graphics);

            byte[] bytes = null;

            string filename = "obj/" + GetFileName(chunk);

            if (m_fileSystem != null && m_fileSystem.Exists(filename))
            {
                if (!m_fileSystem.Load(filename, out bytes))
                {
                    bytes = null;
                }
            }

            if (bytes != null)
            {
                LoadObject(bytes, chunk);
            }
            else
            {
                m_worldGenerator.Generate(chunk);
            }

            m_worldGenerator.PostCreate(chunk);

            chunk.UpdateFlag = e_UpdateFlag.Pending;

            m_chunkLookup.TryAdd(a_position, chunk);

            lock (m_reservedKeys)
            {
                m_reservedKeys.Remove(a_position);
            }
        }
Example #12
0
        public static void AddFont(string a_file, IFileSystem a_fileSystem)
        {
            if (Fonts == null)
            {
                Fonts = new PrivateFontCollection();
            }

            byte[] bytes;
            if (a_fileSystem.Load(a_file, out bytes))
            {
                int len = bytes.Length;

                IntPtr ptr = Marshal.AllocHGlobal(len);
                Marshal.Copy(bytes, 0, ptr, len);

                Fonts.AddMemoryFont(ptr, len);

                Marshal.FreeHGlobal(ptr);
            }
        }
Example #13
0
            public void ModifyObject()
            {
                Stream stream;

                if (m_fileSystem.Load(m_filePath, out stream))
                {
                    Bitmap map = new Bitmap(stream);

                    stream.Dispose();

                    int width  = map.Width;
                    int height = map.Height;

                    BitmapData data = map.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

                    m_texture.WriteData(width, height, e_PixelFormat.BGRA, e_InternalPixelFormat.RGBA, e_PixelType.UnsignedByte, data.Scan0);

                    map.UnlockBits(data);
                    map.Dispose();
                }
            }
Example #14
0
        public static void LoadFontTable(string a_file, IFileSystem a_fileSystem)
        {
            Stream stream;

            if (a_fileSystem.Load(a_file, out stream))
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(stream);

                stream.Dispose();

                for (XmlNode node = doc.FirstChild; node != null; node = node.NextSibling)
                {
                    if (node.Name == "FontTable")
                    {
                        AddFontTable(node);

                        break;
                    }
                }
            }
        }
        private void CopyFromIndex(
            string indexFile, 
            string targetFolder, 
            IFileSystem fileSystem, 
            ILogger logger, 
            IIntegrationResult result)
        {
            var basePath = Path.GetDirectoryName(indexFile);
            using (var reader = fileSystem.Load(indexFile))
            {
                XDocument document = null;
                try
                {
                    document = XDocument.Load(reader);
                }
                catch (Exception error)
                {
                    throw new CruiseControlException(
                        "Unable to load index file - " + error.Message ?? string.Empty,
                        error);
                }

                var rootEl = document.Element("ReportResources");
                if (rootEl == null)
                {
                    throw new CruiseControlException("Unable to load contents manifest - unable to find root node");
                }

                var files = new List<string>();
                foreach (var fileEl in rootEl.Elements("File"))
                {
                    var fullPath = fileEl.Value;
                    if (!Path.IsPathRooted(fullPath))
                    {
                        fullPath = Path.Combine(basePath, fileEl.Value);
                    }

                    files.Add(fullPath);
                }

                foreach (var folder in rootEl.Elements("Directory"))
                {
                    var fullPath = folder.Value;
                    if (!Path.IsPathRooted(fullPath))
                    {
                        fullPath = Path.Combine(basePath, fullPath);
                    }

                    files.AddRange(fileSystem.GetFilesInDirectory(fullPath, true));
                }

                var baseLength = basePath.Length;
                foreach (var file in files)
                {
                    logger.Info("Copying file '{0}' to '{1}'", file, targetFolder);
                    var targetFile = file.StartsWith(basePath) ?
                        file.Substring(baseLength) :
                        Path.GetFileName(file);
                    result.BuildProgressInformation.AddTaskInformation(
                        string.Format(CultureInfo.CurrentCulture, "Copying file '{0}' to '{1}'", targetFile, targetFolder));
                    fileSystem.Copy(file, Path.Combine(targetFolder, targetFile));
                }
            }

        }
        /// <summary>
        /// Generate a list of differences in files.
        /// </summary>
        /// <param name="originalList"></param>
        ///<param name="outputDirectory"></param>
        /// <returns></returns>
        private string[] ListFileDifferences(Dictionary <string, DateTime> originalList, string outputDirectory)
        {
            var contentsFile = Path.Combine(outputDirectory, "ReportResources.xml");

            if (fileSystem.FileExists(contentsFile))
            {
                using (var reader = fileSystem.Load(contentsFile))
                {
                    XDocument document = null;
                    try
                    {
                        document = XDocument.Load(reader);
                    }
                    catch (Exception error)
                    {
                        throw new CruiseControlException(
                                  "Unable to load contents manifest - " + error.Message ?? string.Empty,
                                  error);
                    }

                    var rootEl = document.Element("ReportResources");
                    if (rootEl == null)
                    {
                        throw new CruiseControlException("Unable to load contents manifest - unable to find root node");
                    }

                    var files = new List <string>();
                    foreach (var fileEl in rootEl.Elements("File"))
                    {
                        files.Add(Path.Combine(outputDirectory, fileEl.Value));
                    }

                    foreach (var folder in rootEl.Elements("Directory"))
                    {
                        var fullPath = Path.Combine(outputDirectory, folder.Value);
                        files.AddRange(fileSystem.GetFilesInDirectory(fullPath, true));
                    }

                    return(files.ToArray());
                }
            }
            else
            {
                string[] newList = { };
                if (fileSystem.DirectoryExists(outputDirectory))
                {
                    newList = fileSystem.GetFilesInDirectory(outputDirectory);
                }

                var differenceList = new List <string>();

                // For each new file, see if it is in the old file list
                foreach (var newFile in newList)
                {
                    if (originalList.ContainsKey(newFile))
                    {
                        // Check if the times are different
                        if (originalList[newFile] != fileSystem.GetLastWriteTime(newFile))
                        {
                            differenceList.Add(newFile);
                        }
                    }
                    else
                    {
                        // Not in the old file, therefore it's new
                        differenceList.Add(newFile);
                    }
                }

                return(differenceList.ToArray());
            }
        }
        private void CopyFromIndex(
            string indexFile,
            string targetFolder,
            IFileSystem fileSystem,
            ILogger logger,
            IIntegrationResult result)
        {
            var basePath = Path.GetDirectoryName(indexFile);

            using (var reader = fileSystem.Load(indexFile))
            {
                XDocument document = null;
                try
                {
                    document = XDocument.Load(reader);
                }
                catch (Exception error)
                {
                    throw new CruiseControlException(
                              "Unable to load index file - " + error.Message ?? string.Empty,
                              error);
                }

                var rootEl = document.Element("ReportResources");
                if (rootEl == null)
                {
                    throw new CruiseControlException("Unable to load contents manifest - unable to find root node");
                }

                var files = new List <string>();
                foreach (var fileEl in rootEl.Elements("File"))
                {
                    var fullPath = fileEl.Value;
                    if (!Path.IsPathRooted(fullPath))
                    {
                        fullPath = Path.Combine(basePath, fileEl.Value);
                    }

                    files.Add(fullPath);
                }

                foreach (var folder in rootEl.Elements("Directory"))
                {
                    var fullPath = folder.Value;
                    if (!Path.IsPathRooted(fullPath))
                    {
                        fullPath = Path.Combine(basePath, fullPath);
                    }

                    files.AddRange(fileSystem.GetFilesInDirectory(fullPath, true));
                }

                var baseLength = basePath.Length;
                foreach (var file in files)
                {
                    logger.Info("Copying file '{0}' to '{1}'", file, targetFolder);
                    var targetFile = file.StartsWith(basePath) ?
                                     file.Substring(baseLength) :
                                     Path.GetFileName(file);
                    result.BuildProgressInformation.AddTaskInformation(
                        string.Format(CultureInfo.CurrentCulture, "Copying file '{0}' to '{1}'", targetFile, targetFolder));
                    fileSystem.Copy(file, Path.Combine(targetFolder, targetFile));
                }
            }
        }
Example #18
0
        private CustomConfig GetProjectCfg(IFileSystem fileSystem, string projectName)
        {
            var    ccNetCnfig = fileSystem.Load(ccNetConfigFileName);
            string ccNetCnfigTxt;

            using (ccNetCnfig)
            {
                ccNetCnfigTxt = ccNetCnfig.ReadToEnd();
            }
            if (!string.IsNullOrEmpty(ccNetCnfigTxt))
            {
                /*
                 * XmlDocument xmlDocument = new XmlDocument();
                 * xmlDocument.LoadXml(ccNetCnfigTxt);
                 * XmlNodeList includes = xmlDocument.GetElementsByTagName("cb:include");
                 * if (includes.Count > 0)
                 * {
                 *  foreach (XmlNode include in includes)
                 *  {
                 *      string href = "";
                 *      foreach (XmlAttribute atr in include.Attributes)
                 *      {
                 *          if (atr.Name == "href")
                 *          {
                 *              href = atr.Value;
                 *          }
                 *      }
                 *      if (!string.IsNullOrEmpty(href))
                 *      {
                 *          var currentConfig = fileSystem.Load(href);
                 *          string currentConfigTxt;
                 *          using (currentConfig)
                 *          {
                 *              currentConfigTxt = currentConfig.ReadToEnd();
                 *          }
                 *          if (!string.IsNullOrEmpty(currentConfigTxt))
                 *          {
                 *              if (IsCurrentProjectCfg(currentConfigTxt, projectName))
                 *              {
                 *                  CustomConfig cfg = new CustomConfig();
                 *                  cfg.CurrentConfigTxt = currentConfigTxt;
                 *                  cfg.Href = href;
                 *                  return cfg;
                 *              }
                 *          }
                 *      }
                 *  }
                 * }*/

                XDocument doc   = XDocument.Parse(ccNetCnfigTxt);
                var       nodes = doc.Root?.Nodes().Where(x => x.NodeType == XmlNodeType.Element).Select(x => x as XElement)
                                  .Where(v => v.Name.LocalName == "include");
                if (nodes != null)
                {
                    foreach (XElement node in nodes)
                    {
                        var href = node.Attributes().FirstOrDefault(b => b.Name.LocalName == "href");
                        if (href != null)
                        {
                            var    currentConfig = fileSystem.Load(href.Value);
                            string currentConfigTxt;
                            using (currentConfig)
                            {
                                currentConfigTxt = currentConfig.ReadToEnd();
                            }
                            if (!string.IsNullOrEmpty(currentConfigTxt))
                            {
                                if (IsCurrentProjectCfg(currentConfigTxt, projectName))
                                {
                                    CustomConfig cfg = new CustomConfig();
                                    cfg.CurrentConfigTxt = currentConfigTxt;
                                    cfg.Href             = href.Value;
                                    return(cfg);
                                }
                            }
                        }
                    }
                }
            }
            return(null);
        }
Example #19
0
        public OBJLoader(string a_fileName, IFileSystem a_fileSystem)
        {
            m_vertices = new List <Vertex>();
            m_indices  = new List <uint>();

            byte[] bytes;
            if (a_fileSystem.Load(a_fileName, out bytes))
            {
                string[] lines = Encoding.UTF8.GetString(bytes).Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);

                List <Vector3> vertexPosition      = new List <Vector3>();
                List <Vector3> vertexNormal        = new List <Vector3>();
                List <Vector2> vertexTextureCoords = new List <Vector2>();

                Dictionary <Vertex, uint> vertexLookup = new Dictionary <Vertex, uint>();

                float lengthSqr = 0.0f;

                foreach (string line in lines)
                {
                    string l = line.ToLower();

                    int index = l.IndexOf(' ');

                    string data = l.Substring(index + 1, l.Length - (index + 1));

                    switch (l.Substring(0, index))
                    {
                    case "#":
                    case "o":
                    {
                        break;
                    }

                    case "v":
                    {
                        Vector3 vertex = Vector3.Zero;

                        string[] strings = data.Split(' ');

                        vertex.X = float.Parse(strings[0]);
                        vertex.Y = float.Parse(strings[1]);
                        vertex.Z = float.Parse(strings[2]);

                        lengthSqr = Math.Max(lengthSqr, vertex.LengthSquared);

                        vertexPosition.Add(vertex);

                        break;
                    }

                    case "vn":
                    {
                        Vector3 vertex = Vector3.Zero;

                        string[] strings = data.Split(' ');

                        vertex.X = float.Parse(strings[0]);
                        vertex.Y = float.Parse(strings[1]);
                        vertex.Z = float.Parse(strings[2]);

                        vertexNormal.Add(vertex);

                        break;
                    }

                    case "vt":
                    {
                        Vector2 vertex = Vector2.Zero;

                        string[] strings = data.Split(' ');

                        vertex.X = float.Parse(strings[0]);
                        vertex.Y = 1 - float.Parse(strings[1]);

                        vertexTextureCoords.Add(vertex);

                        break;
                    }

                    case "f":
                    {
                        string[] strings = data.Split(' ');

                        foreach (string s in strings)
                        {
                            string[] ind = s.Split('/');

                            Vertex vert = new Vertex()
                            {
                                Position = new Vector4(vertexPosition[int.Parse(ind[0]) - 1], 1)
                            };

                            if (ind.Length == 2)
                            {
                                if (s.Count(f => f == '/') == 2)
                                {
                                    vert.Normal = vertexNormal[int.Parse(ind[1]) - 1];
                                }
                                else
                                {
                                    vert.TexCoords = vertexTextureCoords[int.Parse(ind[1]) - 1];
                                }
                            }
                            else
                            {
                                vert.TexCoords = vertexTextureCoords[int.Parse(ind[1]) - 1];
                                vert.Normal    = vertexNormal[int.Parse(ind[2]) - 1];
                            }

                            uint val = 0;

                            if (!vertexLookup.TryGetValue(vert, out val))
                            {
                                m_vertices.Add(vert);
                                val = (ushort)(m_vertices.Count - 1);
                                vertexLookup.Add(vert, val);
                            }

                            m_indices.Add(val);
                        }

                        break;
                    }
                    }
                }

                m_length = (float)Math.Sqrt(lengthSqr);
            }
            else
            {
                InternalConsole.Warning("Failed to Load: " + a_fileName);
            }
        }
Example #20
0
        public static VoxelManager Load(IFileSystem a_fileSystem, bool a_threaded, Material a_material, IGenerator a_generator, Pipeline a_pipeline, Graphics.Graphics a_grapics)
        {
            byte[] bytes = null;

            if (a_fileSystem != null)
            {
                if (!a_fileSystem.Load(VoxelManagerFileName, out bytes))
                {
                    bytes = null;
                }
            }

            if (bytes != null)
            {
                VoxelManager voxelManager = new VoxelManager
                {
                    m_pipeline = a_pipeline,
                    m_graphics = a_grapics,

                    m_worldGenerator = a_generator,

                    m_material = a_material
                };

                int off = 0;

                voxelManager.m_voxelWidth = BitConverter.ToInt32(bytes, off);
                off += sizeof(int);

                voxelManager.m_stackSize = BitConverter.ToInt32(bytes, off);
                off += sizeof(int);

                voxelManager.m_voxelSize = BitConverter.ToSingle(bytes, off);
                off += sizeof(float);

                voxelManager.m_scanDistance = BitConverter.ToInt32(bytes, off);
                off += sizeof(int);

                voxelManager.m_destroyDistance = BitConverter.ToSingle(bytes, off);
                off += sizeof(float);

                byte[] genBytes = new byte[bytes.Length - off];

                Array.Copy(bytes, off, genBytes, 0, genBytes.Length);

                a_generator.SetVoxelManager(voxelManager);

                voxelManager.m_worldGenerator.LoadGenerator(genBytes);
                voxelManager.m_threaded = a_threaded;

                if (a_threaded)
                {
                    voxelManager.m_voxelThread = new Thread(voxelManager.VoxelThread)
                    {
                        Name = "Voxel Manager"
                    };

                    voxelManager.m_voxelThread.Start();
                }

                voxelManager.m_fileSystem = a_fileSystem;

                return(voxelManager);
            }

            return(null);
        }
Example #21
0
        void UpdateElement(Element a_element, Vector2 a_resolution, MouseState a_mouseState, Vector2 a_cursorPos, Rectangle a_activeRegion)
        {
            if (a_element.Visible)
            {
                Vector2 truePos = a_element.TruePosition;

                Vector2 pos      = (truePos + a_resolution) * 0.5f;
                Vector2 size     = a_element.TrueSize;
                Vector2 halfSize = size * 0.5f;

                if (pos == Vector2.Zero && size == Vector2.Zero)
                {
                    return;
                }

                Vector2 regionPos      = new Vector2(a_activeRegion.X, a_activeRegion.Y);
                Vector2 regionSize     = new Vector2(a_activeRegion.Width, a_activeRegion.Height);
                Vector2 regionHalfSize = regionSize * 0.5f;

                pos.X += regionPos.X;

                Vector2 regionDiff = a_cursorPos - (regionPos + regionHalfSize);

                if (Math.Abs(regionDiff.X) > regionHalfSize.X || Math.Abs(regionDiff.Y) > regionHalfSize.Y)
                {
                    a_element.State = Element.e_State.Normal;
                    if (a_element.Normal != null)
                    {
                        a_element.Normal(this, a_element);
                    }

                    return;
                }

                Vector2 cursorDiff = pos - a_cursorPos;

                if (Math.Abs(cursorDiff.X) < halfSize.X && Math.Abs(cursorDiff.Y) < halfSize.Y)
                {
                    if (a_mouseState.IsButtonDown(MouseButton.Left) && m_prevMouseState.IsButtonUp(MouseButton.Left))
                    {
                        Input.BlockButton(MouseButton.Left);

                        a_element.State = Element.e_State.Click;
                        if (a_element.Click != null)
                        {
                            a_element.Click(this, a_element);
                        }
                    }
                    else if (a_mouseState.IsButtonUp(MouseButton.Left) && m_prevMouseState.IsButtonDown(MouseButton.Left))
                    {
                        Input.BlockButton(MouseButton.Left);

                        a_element.State = Element.e_State.Release;
                        if (a_element.Release != null)
                        {
                            a_element.Release(this, a_element);
                        }

                        if (!string.IsNullOrEmpty(a_element.SubMenuDirectory))
                        {
                            Stream stream;

                            if (m_fileSystem != null && m_fileSystem.Load(a_element.SubMenuDirectory, out stream))
                            {
                                XmlDocument xmlDocument = new XmlDocument();
                                xmlDocument.Load(stream);

                                stream.Dispose();

                                m_childCanvas = LoadCanvasInternal(xmlDocument, m_fileSystem, m_pipeline);
                                m_childCanvas.m_parentCanvas  = this;
                                m_childCanvas.m_paintedCanvas = false;
                            }
                        }
                    }
                    else if (a_element.State == Element.e_State.Release || a_element.State == Element.e_State.Normal)
                    {
                        a_element.State = Element.e_State.Hover;
                        if (a_element.Hover != null)
                        {
                            a_element.Hover.Invoke(this, a_element);
                        }
                    }
                }
                else if (a_element.State != Element.e_State.Normal)
                {
                    a_element.State = Element.e_State.Normal;
                    if (a_element.Normal != null)
                    {
                        a_element.Normal(this, a_element);
                    }
                }

                foreach (Element child in a_element.Children)
                {
                    UpdateElement(child, a_resolution, a_mouseState, a_cursorPos, a_element.GetActiveRect(a_resolution));
                }
            }
        }
        /// <summary>
        /// Executes the specified result.
        /// </summary>
        /// <param name="result">The result.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        protected override bool Execute(IIntegrationResult result)
        {
            List <string> filesToDelete = new List <string>();

            result.BuildProgressInformation.SignalStartRunTask(!string.IsNullOrEmpty(Description) ? Description : "Reading Modifications");


            System.Collections.ArrayList allModifications = new System.Collections.ArrayList();


            foreach (string file in GetModificationFiles(result))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(Modification[]));
                StringReader  reader     = new StringReader(fileSystem.Load(file).ReadToEnd());
                object        dummy      = serializer.Deserialize(reader);
                reader.Close();
                System.Collections.ArrayList currentModification = new System.Collections.ArrayList((Modification[])dummy);

                allModifications.AddRange(currentModification);

                if (deleteAfterRead)
                {
                    filesToDelete.Add(file);
                }
            }

            Modification[] newMods = new Modification[result.Modifications.Length + allModifications.Count];

            //copy existing modifications
            result.Modifications.CopyTo(newMods, 0);

            // copy modifications read from the file(s)
            int modificationCounter = result.Modifications.Length;

            foreach (Modification mod in allModifications)
            {
                newMods[modificationCounter] = mod;
                modificationCounter++;
            }

            result.Modifications = newMods;

            // Delete all the files
            foreach (string file in filesToDelete)
            {
                try
                {
                    File.Delete(file);
                }
                catch (IOException error)
                {
                    Log.Warning(
                        string.Format(
                            CultureInfo.CurrentCulture, "Unable to delete file '{0}' - {1}",
                            file,
                            error.Message));
                }
            }

            return(true);
        }