NetIde.Services.Shell.NiShell.SaveDocDataToFile C# (CSharp) Method

SaveDocDataToFile() public method

public SaveDocDataToFile ( NiSaveMode mode, INiPersistFile persistFile, string fileName, string &newFileName, bool &saved ) : HResult
mode NiSaveMode
persistFile INiPersistFile
fileName string
newFileName string
saved bool
return HResult
        public HResult SaveDocDataToFile(NiSaveMode mode, INiPersistFile persistFile, string fileName, out string newFileName, out bool saved)
        {
            newFileName = null;
            saved = false;

            try
            {
                bool isDirty;
                ErrorUtil.ThrowOnFailure(persistFile.IsDirty(out isDirty));

                if (!isDirty)
                {
                    newFileName = fileName;
                    saved = true;

                    return HResult.OK;
                }

                switch (mode)
                {
                    case NiSaveMode.SaveAs:
                    case NiSaveMode.SaveCopyAs:
                        throw new NotImplementedException();

                    case NiSaveMode.Save:
                        INiHierarchy hier;
                        INiWindowFrame windowFrame;
                        ErrorUtil.ThrowOnFailure(((INiOpenDocumentManager)GetService(typeof(INiOpenDocumentManager))).IsDocumentOpen(
                            fileName,
                            out hier,
                            out windowFrame
                        ));

                        if (hier != null)
                        {
                            NiQuerySaveResult querySaveResult;
                            var hr = QuerySaveViaDialog(new[] { hier }, out querySaveResult);

                            if (ErrorUtil.Failure(hr))
                                return hr;

                            switch (querySaveResult)
                            {
                                case NiQuerySaveResult.Cancel:
                                    return HResult.OK;

                                case NiQuerySaveResult.DoNotSave:
                                    // We pretend the document was saved if the
                                    // user asked us not to save the document.

                                    saved = true;
                                    return HResult.OK;
                            }
                        }
                        break;
                }

                newFileName = fileName;
                saved = true;

                return persistFile.Save(newFileName, true);
            }
            catch (Exception ex)
            {
                return ErrorUtil.GetHResult(ex);
            }
        }