public CentralFileWarningWindow(CentralFileInfo info)
        {
            fileInfo = info;

            InitializeComponent();
            this.Title = "Central File Opened!  v." + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
            if (!string.IsNullOrEmpty(fileInfo.DocCentralPath))
            {
                textBlockFilePath.Text = "Central File Path:\n" + fileInfo.DocCentralPath;
            }
            else
            {
                textBlockFilePath.Text = "";
            }
        }
Exemplo n.º 2
0
        public static bool RunFMEWorkspaceHTTP(CentralFileInfo info, string repository, string workspace, out Dictionary <string, string> properties)
        {
            var result = false;

            properties = new Dictionary <string, string>();
            try
            {
                var settingsString = Resources.StreamEmbeddedResource("HOK.Core.Resources.Settings.json");
                var settings       = Json.Deserialize <Settings>(settingsString);

                apiToken = settings.FileOnOpeningFmeApiToken;
                host     = settings.FileOnOpeningFmeHost;
                var baseUrl  = $"http://{host}/fmerest/v3/";
                var resource = $"transformations/submit/{repository}/{workspace}";
                var body     = new Transformation
                {
                    publishedParameters = new List <PublishedParameter>
                    {
                        new PublishedParameter {
                            name = "FileName_pp", value = info.DocCentralPath
                        },
                        new PublishedParameter {
                            name = "Username_pp", value = info.UserName
                        },
                        new PublishedParameter {
                            name = "Office_pp", value = info.UserLocation
                        }
                    }
                };

                var client  = new RestClient(baseUrl);
                var request = new RestRequest(resource, Method.POST);
                request.AddHeader("Authorization", $"fmetoken token={apiToken}");
                request.AddJsonBody(body);
                var response = client.Execute(request);

                if (response.StatusCode == HttpStatusCode.Accepted)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to run FME workspace from the FME Server.\n" + ex.Message, "Run FME Workspace", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(result);
        }
Exemplo n.º 3
0
        public static bool RunFMEWorkspace(CentralFileInfo info, string repository, string workspace, out Dictionary <string, string> properties)
        {
            var result = false;

            properties = new Dictionary <string, string>();
            try
            {
                if (null == serverSession)
                {
                    serverSession = ConnectToFMEServer();
                }

                if (null != serverSession)
                {
                    var transformationMgr = serverSession.GetTransformationManager();

                    var request = serverSession.CreateTransformationRequest("SERVER_CONSOLE_CLIENT", repository, workspace);
                    request.SetPublishedParameter("Office_pp", info.UserLocation);
                    request.SetPublishedParameter("Username_pp", info.UserName);
                    request.SetPublishedParameter("FileName_pp", info.DocCentralPath);

                    var transformationResult = serverSession.CreateTransformationResult();
                    var jobId = transformationMgr.SubmitJob(request);
                    Thread.Sleep(500);

                    if (transformationMgr.GetJobResult(jobId, transformationResult))
                    {
                        result = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to run FME workspace from the FME Server.\n" + ex.Message, "Run FME Workspace", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(result);
        }
Exemplo n.º 4
0
        private void Application_DocumentOpened(object sender, DocumentOpenedEventArgs args)
        {
            try
            {
                openedDocument = args.Document;
                if (null == openedDocument.ActiveView)
                {
                    return;                                    // to distinguish linked model
                }
                if (!openedDocument.IsWorkshared)
                {
                    return;
                }
                if (string.IsNullOrEmpty(openedDocument.PathName))
                {
                    return;
                }
                if (openedDocument.IsDetached)
                {
                    return;
                }
                var isOnNetwork = IsNetworkDrive(openedDocument.PathName);
                if (!isOnNetwork)
                {
                    return;
                }
                isCentral = IsCentralFile(openedDocument);
                if (!isCentral)
                {
                    return;
                }

                var fileInfo = new CentralFileInfo(openedDocument);
                var unused   = new Dictionary <string, string>();

                FMEServerUtil.RunFMEWorkspaceHTTP(fileInfo, "buildingSMART Notifications", "OpenCentralFileNotification.fmw", out unused);

                if (!openedCentralFiles.ContainsKey(fileInfo.DocCentralPath))
                {
                    openedCentralFiles.Add(openedDocument.PathName, fileInfo);
                }

                var firstWindow = new CentralFileWarningWindow(fileInfo);
                if (firstWindow.ShowDialog() != true)
                {
                    return;
                }

                timerCount = 1;
                var timedWindow = new TimedWarningWindow(timerCount, openedCentralFiles);
                if (timedWindow.ShowDialog() == true)
                {
                    timerOn = false;
                }
                else
                {
                    timerOn = true;
                    if (null != dispatcherTimer)
                    {
                        dispatcherTimer.IsEnabled = false;
                        dispatcherTimer.Tick     -= DispatcherTimer_Tick;
                        dispatcherTimer           = null;
                    }

                    dispatcherTimer           = new DispatcherTimer();
                    dispatcherTimer.Tick     += DispatcherTimer_Tick;
                    dispatcherTimer.Interval  = new TimeSpan(0, 0, 30);
                    dispatcherTimer.IsEnabled = true;
                    dispatcherTimer.Start();
                }
            }
            catch (Exception ex)
            {
                Log.AppendLog(LogMessageType.EXCEPTION, ex.Message);
            }
        }