/// <summary>
        /// Creates a new output file or updates it's contents if it already exists.
        /// </summary>
        /// <param name="output">An <see cref="OutputFile"/> object.</param>
        private static void UpdateOutputFile(OutputFile output)
        {
            if (File.Exists(output.File))
            {
                // Don't do anything unless the output file has changed and needs to be overwritten
                if (output.Content.ToString() == File.ReadAllText(output.File, output.Encoding))
                {
                    return;
                }

                // Don't do anything if the file should be preserved.
                if (output.PreserveExistingFile)
                {
                    return;
                }
            }

            // Check out the file if it is under source control
            SourceControl sourceControl = GetDte().SourceControl;

            if (sourceControl.IsItemUnderSCC(output.File) && !sourceControl.IsItemCheckedOut(output.File))
            {
                sourceControl.CheckOutItem(output.File);
            }

            Directory.CreateDirectory(Path.GetDirectoryName(output.File));
            File.WriteAllText(output.File, output.Content.ToString(), output.Encoding);
        }
Beispiel #2
0
        private bool CheckoutFile(string fileName)
        {
            Debug.WriteLine("CheckoutFile: file = '{0}'", fileName);

            SourceControl sourceControl = applicationObject.SourceControl;

            if (sourceControl == null)
            {
                Debug.WriteLine("CheckoutFile: SourceControl is null");
                return(true);
            }
            Debug.WriteLine("CheckoutFile: SourceControl is not null");

            if (!sourceControl.IsItemUnderSCC(fileName))
            {
                Debug.WriteLine("CheckoutFile: file is not under source control");
                return(true);
            }

            Debug.WriteLine("CheckoutFile: file is under source control");
            if (sourceControl.IsItemCheckedOut(fileName))
            {
                Debug.WriteLine("CheckoutFile: file is already checked out");
                return(true);
            }

            var result = sourceControl.CheckOutItem(fileName);

            Debug.WriteLine(result ? "CheckoutFile: file successfully checked out" : "CheckoutFile: failed check out file");
            return(result);
            //return sourceControl.IsItemCheckedOut(fileName);
        }
 /// <summary>
 /// Check out file from source control.
 /// </summary>
 /// <param name="sourceControl">Source control object</param>
 /// <param name="file">The name of the file to check out</param>
 private static void CheckOutFile(SourceControl sourceControl, string file)
 {
     if (sourceControl != null && sourceControl.IsItemUnderSCC(file) &&
         !sourceControl.IsItemCheckedOut(file))
     {
         sourceControl.CheckOutItem(file);
     }
 }
Beispiel #4
0
                private void CheckoutFileIfRequired(string fileName)
                {
                    SourceControl sc = dte.SourceControl;

                    if (sc != null && sc.IsItemUnderSCC(fileName) && !sc.IsItemCheckedOut(fileName))
                    {
                        sc.CheckOutItem(fileName);
                    }
                }
        private void CheckoutFileIfRequired(String fileName)
        {
            SourceControl sc = dte.SourceControl;

            if (sc != null && sc.IsItemUnderSCC(fileName) && !sc.IsItemCheckedOut(fileName))
            {
                checkOutAction.EndInvoke(checkOutAction.BeginInvoke(fileName, null, null));
            }
        }
Beispiel #6
0
        public static bool CheckOutItemSafely(this SourceControl scc, string filePath)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (scc.IsItemUnderSCC(filePath) && !scc.IsItemCheckedOut(filePath))
            {
                return(scc.CheckOutItem(filePath));
            }

            return(false);
        }
        public static bool CheckOutItemIfNeeded(this SourceControl sourceControl, string itemName)
        {
            DebugCheck.NotNull(sourceControl);
            DebugCheck.NotEmpty(itemName);

            if (sourceControl.IsItemUnderSCC(itemName) && !sourceControl.IsItemCheckedOut(itemName))
            {
                return(sourceControl.CheckOutItem(itemName));
            }

            return(false);
        }
        public static bool CheckOutItemIfNeeded(this SourceControl sourceControl, string itemName)
        {
            Contract.Requires(sourceControl != null);
            Contract.Requires(!string.IsNullOrWhiteSpace(itemName));

            if (sourceControl.IsItemUnderSCC(itemName) && !sourceControl.IsItemCheckedOut(itemName))
            {
                return(sourceControl.CheckOutItem(itemName));
            }

            return(false);
        }
Beispiel #9
0
        protected void CreateFile(string fileName, string contents)
        {
            if (File.Exists(fileName) && File.ReadAllText(fileName) == contents)
            {
                return;
            }
            SourceControl sourceControl = TransformContext.Current.Dte.SourceControl;

            if (null != sourceControl && sourceControl.IsItemUnderSCC(fileName) && !sourceControl.IsItemCheckedOut(fileName))
            {
                sourceControl.CheckOutItem(fileName);
            }
            File.WriteAllText(fileName, contents);
        }
Beispiel #10
0
        public static void EnsureCheckedOutIfExists(SourceControl sourceControl, string fullPath)
        {
            if (File.Exists(fullPath))
            {
                FileSystemUtility.MakeWriteable(fullPath);

                if (sourceControl != null &&
                    sourceControl.IsItemUnderSCC(fullPath) &&
                    !sourceControl.IsItemCheckedOut(fullPath))
                {
                    // Check out the item
                    sourceControl.CheckOutItem(fullPath);
                }
            }
        }
Beispiel #11
0
        private void CheckoutFileIfNeeded(string fileName, out bool abortOperation)
        {
            abortOperation = false;

            if (QtVSIPSettings.GetDisableCheckoutFiles())
            {
                return;
            }

            SourceControl sourceControl = dte.SourceControl;

            if (sourceControl == null)
            {
                return;
            }

            if (!sourceControl.IsItemUnderSCC(fileName))
            {
                return;
            }

            if (sourceControl.IsItemCheckedOut(fileName))
            {
                return;
            }

            if (QtVSIPSettings.GetAskBeforeCheckoutFile())
            {
                string       shortFileName = System.IO.Path.GetFileName(fileName);
                DialogResult dr            = MessageBox.Show(
                    SR.GetString("QuestionSCCCheckoutOnOpen", shortFileName),
                    Resources.msgBoxCaption, MessageBoxButtons.YesNoCancel,
                    MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (dr == DialogResult.Cancel)
                {
                    abortOperation = true;
                }
                if (dr != DialogResult.Yes)
                {
                    return;
                }
            }

            sourceControl.CheckOutItem(fileName);
        }
Beispiel #12
0
        private bool HandleSourceControl(SolutionItem solutionItem, string filename)
        {
            if (solutionItem.DTE != null)
            {
                SourceControl sc = solutionItem.DTE.SourceControl;

                if (sc != null && sc.IsItemUnderSCC(filename) && !sc.IsItemCheckedOut(filename))
                {
                    _connect.Log("The file \"" + filename + "\" is under source control. Checking out ...", LogLevel.Info);

                    if (!sc.CheckOutItem(filename))
                    {
                        _connect.Log("Failed to check out \"" + filename + "\".", LogLevel.Error, filename, 1);
                        return(false);
                    }
                }
            }

            return(true);
        }
 /// <summary>
 /// Check out file from source control.
 /// </summary>
 /// <param name="sourceControl">Source control object</param>
 /// <param name="file">The name of the file to check out</param>
 private static void CheckOutFile(SourceControl sourceControl, string file)
 {
     if (sourceControl != null && sourceControl.IsItemUnderSCC(file)
         && !sourceControl.IsItemCheckedOut(file))
     {
         sourceControl.CheckOutItem(file);
     }
 }