コード例 #1
0
ファイル: LinkUtil.cs プロジェクト: brickjia/Common
        /// <summary>
        ///     Opens the central file.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="serverPath"></param>
        /// <param name="localPath"></param>
        public static Document OpenCentralFile(this Application app, string serverPath, string localPath)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            if (serverPath == null)
            {
                throw new ArgumentNullException(nameof(serverPath));
            }

            if (localPath == null)
            {
                throw new ArgumentNullException(nameof(localPath));
            }

            var serverPathl = new FilePath(serverPath);
            var localPathl  = new FilePath(localPath);

            WorksharingUtils.CreateNewLocal(serverPathl, localPathl);

            var option = new OpenOptions
            {
                DetachFromCentralOption = DetachFromCentralOption.DoNotDetach,
                Audit = false
            };

            return(app.OpenDocumentFile(localPathl, option));
        }
コード例 #2
0
        public UIDocument DoOpenNewLocalFromModelPath(ModelPath centralPath, ModelPath localPath)
        {
            List <WorksetId> worksetsToOpen = new List <WorksetId>();
            // First set to close all worksets
            WorksetConfiguration worksetConfig  = new WorksetConfiguration(WorksetConfigurationOption.CloseAllWorksets);
            OpenOptions          theOpenOptions = new OpenOptions();

            try {
                // Create the new local at the given path
                WorksharingUtils.CreateNewLocal(centralPath, localPath);
                // Select specific worksets to open
                // Get a list of worksets from the unopened document
                IList <WorksetPreview> worksets = WorksharingUtils.GetUserWorksetInfo(localPath);
                foreach (WorksetPreview preview in worksets)
                {
                    bool Include = true;
                    ////// The inverse list is the inverse of the worksets checked. In other
                    ////// words an exclusion list.
                    //////foreach (string ws in InverseWorksetList) {
                    //////    if (ws == "") { continue; }
                    //////    if (preview.Name.StartsWith(ws)) {
                    //////        Include = false;
                    //////        continue;
                    //////    } else {
                    //////    }
                    //////}
                    if (Include)
                    {
                        worksetsToOpen.Add(preview.Id);
                    }
                    else
                    {
                        //System.Windows.MessageBox.Show("Excluding " + preview.Name);
                    }
                }
                // Setup option to open the target worksets
                // then set specific ones to open
                worksetConfig.Open(worksetsToOpen);
                theOpenOptions.SetOpenWorksetsConfiguration(worksetConfig);
                // Now open the new local
                UIDocument openedDoc = _uiApp.OpenAndActivateDocument(localPath, theOpenOptions, false);
                return(openedDoc);
            } catch (Exception ex) {
                System.Windows.MessageBox.Show("Opening the file from its location.\n\n" + ex.Message, "This Is Not A Workshared File");
            }
            // If here then not a workshared file.
            string     fname      = ModelPathUtils.ConvertModelPathToUserVisiblePath(centralPath);
            UIDocument openedDocN = _uiApp.OpenAndActivateDocument(fname);

            return(openedDocN);
        }
コード例 #3
0
ファイル: LinkUtil.cs プロジェクト: leshui1991/Common
        /// <summary>
        /// Opens the central file.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="serverPath"></param>
        /// <param name="localPath"></param>
        public static Document OpenCentralFile(this Application app, string serverPath, string localPath)
        {
            var serverPathl = new FilePath(serverPath);
            var localPathl  = new FilePath(localPath);

            WorksharingUtils.CreateNewLocal(serverPathl, localPathl);

            var option = new OpenOptions
            {
                DetachFromCentralOption = DetachFromCentralOption.DoNotDetach,
                Audit = false
            };

            return(app.OpenDocumentFile(localPathl, option));
        }
コード例 #4
0
        private Document CreateLocal(UIApplication uiapp, string path)
        {
            string modelname = Path.GetFileNameWithoutExtension(path);

            ModelPath modelpath = ModelPathUtils.ConvertUserVisiblePathToModelPath(path);

            Directory.CreateDirectory(TempPath);

            ModelPath targetpath = ModelPathUtils.ConvertUserVisiblePathToModelPath(TempPath + modelname);

            WorksharingUtils.CreateNewLocal(modelpath, targetpath);

            OpenOptions openoptions = new OpenOptions
            {
                DetachFromCentralOption = DetachFromCentralOption.DoNotDetach
            };

            Document doc = uiapp.Application.OpenDocumentFile(targetpath, openoptions);

            return(doc);
        }