Наследование: HierarchyNode
        /// <summary>
        /// Public constructor.
        /// </summary>
        /// <param name="project">Automation project.</param>
        /// <param name="node">Custom file node.</param>
        public OATeXProjectFileItem(OAProject project, FileNode node)
            : base(project, node)
        {
            try
            {
                if (node != null && project.IsDirty)
                {
                    var prop = (node.NodeProperties as FileNodeProperties);
                    switch (prop.Extension.ToLower())
                    {
                        case ".tex":
                            prop.BuildAction = BuildAction.Compile;
                            break;
                        case ".jpg":
                        case ".png":
                        case ".jpeg":
                        case ".bmp":
                        case ".gif":
                            prop.BuildAction = BuildAction.Picture;
                            break;
                        default:
                            prop.BuildAction = BuildAction.Content;
                            break;

                    }
                }
            }
            catch { }
        }
Пример #2
0
        /// <summary>
        ///     Rename all childnodes
        /// </summary>
        /// <param name="newFileNode">The newly added Parent node.</param>
        protected virtual void RenameChildNodes(FileNode parentNode)
        {
            foreach (var child in GetChildNodes())
            {
                var childNode = child as FileNode;
                if (null == childNode)
                {
                    continue;
                }
                string newfilename;
                if (childNode.HasParentNodeNameRelation)
                {
                    var relationalName = childNode.Parent.GetRelationalName();
                    var extension = childNode.GetRelationNameExtension();
                    newfilename = relationalName + extension;
                    newfilename = Path.Combine(Path.GetDirectoryName(childNode.Parent.GetMkDocument()), newfilename);
                }
                else
                {
                    newfilename = Path.Combine(Path.GetDirectoryName(childNode.Parent.GetMkDocument()),
                        childNode.Caption);
                }

                childNode.RenameDocument(childNode.GetMkDocument(), newfilename);

                //We must update the DependsUpon property since the rename operation will not do it if the childNode is not renamed
                //which happens if the is no name relation between the parent and the child
                var dependentOf = childNode.ItemNode.GetMetadata(ProjectFileConstants.DependentUpon);
                if (!string.IsNullOrEmpty(dependentOf))
                {
                    childNode.ItemNode.SetMetadata(ProjectFileConstants.DependentUpon,
                        childNode.Parent.ItemNode.GetMetadata(ProjectFileConstants.Include));
                }
            }
        }
Пример #3
0
 /// <summary>
 ///     Update the ChildNodes after the parent node has been renamed
 /// </summary>
 /// <param name="newFileNode">The new FileNode created as part of the rename of this node</param>
 private void SetNewParentOnChildNodes(FileNode newFileNode)
 {
     foreach (var childNode in GetChildNodes())
     {
         childNode.Parent = newFileNode;
     }
 }
Пример #4
0
 public FileDocumentManager(FileNode node)
     : base(node)
 {
 }
Пример #5
0
        /// <summary>
        ///     This is called after the single file generator has been invoked to create or update the code file.
        /// </summary>
        /// <param name="fileNode">The node associated to the generator</param>
        /// <param name="data">data to update the file with</param>
        /// <param name="size">size of the data</param>
        /// <param name="fileName">Name of the file to update or create</param>
        /// <returns>full path of the file</returns>
        protected virtual string UpdateGeneratedCodeFile(FileNode fileNode, byte[] data, int size, string fileName)
        {
            var filePath = Path.Combine(Path.GetDirectoryName(fileNode.GetMkDocument()), fileName);
            var rdt = projectMgr.GetService(typeof (SVsRunningDocumentTable)) as IVsRunningDocumentTable;

            // (kberes) Shouldn't this be an InvalidOperationException instead with some not to annoying errormessage to the user?
            if (rdt == null)
            {
                ErrorHandler.ThrowOnFailure(VSConstants.E_FAIL);
            }

            IVsHierarchy hier;
            uint cookie;
            uint itemid;
            var docData = IntPtr.Zero;
            ErrorHandler.ThrowOnFailure(rdt.FindAndLockDocument((uint) _VSRDTFLAGS.RDT_NoLock, filePath, out hier,
                out itemid, out docData, out cookie));
            if (docData != IntPtr.Zero)
            {
                Marshal.Release(docData);
                IVsTextStream srpStream = null;
                if (srpStream != null)
                {
                    var oldLen = 0;
                    var hr = srpStream.GetSize(out oldLen);
                    if (ErrorHandler.Succeeded(hr))
                    {
                        var dest = IntPtr.Zero;
                        try
                        {
                            dest = Marshal.AllocCoTaskMem(data.Length);
                            Marshal.Copy(data, 0, dest, data.Length);
                            ErrorHandler.ThrowOnFailure(srpStream.ReplaceStream(0, oldLen, dest, size/2));
                        }
                        finally
                        {
                            if (dest != IntPtr.Zero)
                            {
                                Marshal.Release(dest);
                            }
                        }
                    }
                }
            }
            else
            {
                using (var generatedFileStream = File.Open(filePath, FileMode.OpenOrCreate))
                {
                    generatedFileStream.Write(data, 0, size);
                }

                var projectItem = fileNode.GetAutomationObject() as ProjectItem;
                if (projectItem != null && (projectMgr.FindChild(fileNode.FileName) == null))
                {
                    projectItem.ProjectItems.AddFromFile(filePath);
                }
            }
            return filePath;
        }
Пример #6
0
        /// <summary>
        ///     Invokes the specified generator
        /// </summary>
        /// <param name="fileNode">The node on which to invoke the generator.</param>
        protected internal virtual void InvokeGenerator(FileNode fileNode)
        {
            if (fileNode == null)
            {
                throw new ArgumentNullException("fileNode");
            }

            var nodeproperties = fileNode.NodeProperties as SingleFileGeneratorNodeProperties;
            if (nodeproperties == null)
            {
                throw new InvalidOperationException();
            }

            var customToolProgID = nodeproperties.CustomTool;
            if (string.IsNullOrEmpty(customToolProgID))
            {
                return;
            }

            try
            {
                if (!runningGenerator)
                {
                    //Get the buffer contents for the current node
                    var moniker = fileNode.GetMkDocument();

                    runningGenerator = true;

                    //Get the generator
                    IVsSingleFileGenerator generator;
                    int generateDesignTimeSource;
                    int generateSharedDesignTimeSource;
                    int generateTempPE;
                    var factory = new SingleFileGeneratorFactory(projectMgr.ProjectGuid, projectMgr.Site);
                    ErrorHandler.ThrowOnFailure(factory.CreateGeneratorInstance(customToolProgID,
                        out generateDesignTimeSource, out generateSharedDesignTimeSource, out generateTempPE,
                        out generator));

                    //Check to see if the generator supports siting
                    var objWithSite = generator as IObjectWithSite;
                    if (objWithSite != null)
                    {
                        objWithSite.SetSite(fileNode.OleServiceProvider);
                    }

                    //Run the generator
                    var output = new IntPtr[1];
                    output[0] = IntPtr.Zero;
                    uint outPutSize;
                    string extension;
                    ErrorHandler.ThrowOnFailure(generator.DefaultExtension(out extension));

                    //Find if any dependent node exists
                    var dependentNodeName = Path.GetFileNameWithoutExtension(fileNode.FileName) + extension;
                    var dependentNode = fileNode.FirstChild;
                    while (dependentNode != null)
                    {
                        if (
                            string.Compare(dependentNode.ItemNode.GetMetadata(ProjectFileConstants.DependentUpon),
                                fileNode.FileName, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            dependentNodeName = ((FileNode) dependentNode).FileName;
                            break;
                        }

                        dependentNode = dependentNode.NextSibling;
                    }

                    //If you found a dependent node. 
                    if (dependentNode != null)
                    {
                        //Then check out the node and dependent node from SCC
                        if (!CanEditFile(dependentNode.GetMkDocument()))
                        {
                            throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
                        }
                    }
                    else //It is a new node to be added to the project
                    {
                        // Check out the project file if necessary.
                        if (!projectMgr.QueryEditProjectFile(false))
                        {
                            throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
                        }
                    }
                    IVsTextStream stream;
                    var inputFileContents = GetBufferContents(moniker, out stream);

                    ErrorHandler.ThrowOnFailure(generator.Generate(moniker, inputFileContents, "", output,
                        out outPutSize, this));
                    var data = new byte[outPutSize];

                    if (output[0] != IntPtr.Zero)
                    {
                        Marshal.Copy(output[0], data, 0, (int) outPutSize);
                        Marshal.FreeCoTaskMem(output[0]);
                    }

                    //Todo - Create a file and add it to the Project
                    UpdateGeneratedCodeFile(fileNode, data, (int) outPutSize, dependentNodeName);
                }
            }
            finally
            {
                runningGenerator = false;
            }
        }