private void ConnectToRuntime()
        {
            var runtimeOptions = new Fin.RuntimeOptions
            {
                UUID                  = "stub",
                Version               = RuntimeVersion,
                LicenseKey            = "dotnettest",
                EnableRemoteDevTools  = true,
                RuntimeConnectTimeout = 20000,
//                Port = 9696,
//                RuntimeConnectOptions = Fin.RuntimeConnectOptions.DirectLaunch | Fin.RuntimeConnectOptions.UseExternal,
            };

            _fin        = Fin.Runtime.GetRuntimeInstance(runtimeOptions);
            _fin.Error += (sender, e) =>
            {
                Console.WriteLine("Error om stub", e);
            };

            _fin.Connect(() =>
            {
                Application.Current.Dispatcher.Invoke(new Action(() => {
                    Connect.IsEnabled = true;
                    Console.WriteLine("Connected to Runtime");
                }));
            });
        }
Example #2
0
        public static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                return;
            }

            NativeMethods.SetProcessDpiAwareness(NativeMethods.ProcessDPIAwareness.ProcessPerMonitorDPIAware);

            var layoutEngine = new LayoutEngine();

            var opts = new Fin.RuntimeOptions()
            {
                Version = args[0],
                RuntimeConnectOptions = Fin.RuntimeConnectOptions.NonPersistent
            };

            var runtime = Fin.Runtime.GetRuntimeInstance(opts);

            runtime.Connect(() =>
            {
                Console.WriteLine("Connected to OpenFin");

                var provider = runtime.InterApplicationBus.Channel.CreateProvider("native-platform-helper");

                provider.RegisterTopic <Snapshot, Snapshot>("getSnapshotEx", (snapshot) =>
                {
                    return(layoutEngine.ProcessGetSnapshot(snapshot));
                });

                provider.RegisterTopic <Snapshot, object>("applySnapshotEx", (snapshot) =>
                {
                    layoutEngine.ProcessApplySnapshot(snapshot);
                    return(null);
                });

                provider.RegisterTopic <DragEventArgs, object>("dragStart", (e) =>
                {
                    layoutEngine.ProcessDragStart(e);
                    return(null);
                });

                provider.RegisterTopic <DragEventArgs, object>("dragEnd", (e) =>
                {
                    layoutEngine.ProcessDragEnd();
                    return(null);
                });

                provider.OpenAsync();
            });

            var runtimeConnectedTsc = new TaskCompletionSource <object>();

            runtime.Disconnected += (s, e) => runtimeConnectedTsc.SetResult(null);
            runtimeConnectedTsc.Task.Wait();
        }
        static OpenFinGlobals()
        {
            var openfinOptions = new Fin.RuntimeOptions()
            {
                Version = "9.*"
            };

            RuntimeInstance = Fin.Runtime.GetRuntimeInstance(openfinOptions);
            DefaultAppUrl   = "http://flatlogic.github.io/angular-material-dashboard/#/dashboard";
            //DefaultAppUrl = "about:blank";
        }
        public MainForm()
        {
            InitializeComponent();

            IntPtr downloadFolderPathHandle;

            SHGetKnownFolderPath(DownloadsFolderId, 0, IntPtr.Zero, out downloadFolderPathHandle);

            DownloadFolderPath = Marshal.PtrToStringUni(downloadFolderPathHandle);
            Marshal.FreeCoTaskMem(downloadFolderPathHandle);

            var openFileDialog = new OpenFileDialog();

            var opts = new Fin.RuntimeOptions()
            {
                Version = "stable",
                RuntimeConnectOptions = Fin.RuntimeConnectOptions.NonPersistent
            };

            runtime = Fin.Runtime.GetRuntimeInstance(opts);

            runtime.Connect(() =>
            {
                var provider = runtime.InterApplicationBus.Channel.CreateProvider("native-helper");

                provider.RegisterTopic <JObject, string>("save-file", (args) =>
                {
                    var fileId = Guid.NewGuid().ToString();

                    var fileName = args.Value <string>("fileName");
                    var content  = args.Value <string>("content");

                    var target = Path.Combine(DownloadFolderPath, fileName);

                    File.WriteAllBytes(
                        target,
                        Convert.FromBase64String(content));

                    downloads[fileId] = target;

                    return(fileId);
                });

                provider.RegisterTopic <JObject>("open-file", (args) =>
                {
                    var fileId   = args.Value <string>("fileId");
                    var fileName = downloads[fileId];

                    Process.Start(fileName);
                });

                provider.OpenAsync();
            });
        }
        public SnippingWindow(int port, string uuid, string topic) : this()
        {
            openfinUuid  = uuid;
            openfinTopic = topic;

            var options = new Fin.RuntimeOptions()
            {
                UUID = null,
                Port = port,
                RuntimeConnectOptions = Fin.RuntimeConnectOptions.UseExternal,
                PortDiscoveryMode     = Fin.PortDiscoveryMode.None
            };

            openfinRuntime = Fin.Runtime.GetRuntimeInstance(options);
            openfinRuntime.Connect(() => { });
        }
        public MainForm()
        {
            InitializeComponent();

            var openFileDialog = new OpenFileDialog();

            var opts = new Fin.RuntimeOptions()
            {
                Version = "stable",
                RuntimeConnectOptions = Fin.RuntimeConnectOptions.NonPersistent
            };

            runtime = Fin.Runtime.GetRuntimeInstance(opts);

            runtime.Connect(() =>
            {
                var provider = runtime.InterApplicationBus.Channel.CreateProvider("native-helper");

                provider.RegisterTopic("file-picker", () =>
                {
                    object result = null;
                    Invoke(new Action(() =>
                    {
                        var dialogResult = openFileDialog.ShowDialog();

                        if (dialogResult == DialogResult.OK)
                        {
                            result = new
                            {
                                fileName = openFileDialog.FileName,
                                filePath = openFileDialog.FileName,
                                fileData = Convert.ToBase64String(System.IO.File.ReadAllBytes(openFileDialog.FileName))
                            };
                        }
                    }));

                    return(result);
                });

                provider.OpenAsync();
            });
        }
Example #7
0
        public Form1()
        {
            InitializeComponent();

            // Connect to the runtime
            var runtimeOptions = new Fin.RuntimeOptions
            {
                Version = "beta",
                EnableRemoteDevTools = true,
                RemoteDevToolsPort   = 9090
            };

            _runtime = Fin.Runtime.GetRuntimeInstance(runtimeOptions);
            _runtime.Connect(RuntimeConnectedCallback);


            var appOptions = new Fin.ApplicationOptions("webproj", "webproj", "file:///C:/OpenfinPOC/OpenFinInteroperatability/OpenFinInteroperatability/webproj/public/index.html");

            embeddedview = new EmbeddedView();
            panel1.Controls.Add(embeddedview);
            embeddedview.Initialize(runtimeOptions, appOptions);

            embeddedview.OnReady += embeddedView_OnReady;
        }
Example #8
0
        public MainWindow()
        {
            InitializeComponent();

            // Connect to the runtime
            var runtimeOptions = new Fin.RuntimeOptions()
            {
                Version       = string.IsNullOrEmpty(App.RuntimeVersion) ? "stable" : App.RuntimeVersion,
                SecurityRealm = string.IsNullOrEmpty(App.SecurityRealm) ? null : App.SecurityRealm
            };

            _runtime = Fin.Runtime.GetRuntimeInstance(runtimeOptions);
            _runtime.Connect(RuntimeConnectedCallback);

            // Initialize the embedded view
            var htmlRootPath = Path.GetFullPath(@"chartiq-html\stx-basic.html");
            var htmlRootUrl  = new Uri(htmlRootPath).ToString();

            var appOptions = new Fin.ApplicationOptions("chartIQDemo", "chartIQUuid", htmlRootPath);

            embeddedview.Initialize(runtimeOptions, appOptions);

            embeddedview.OnReady += embeddedView_OnReady;
        }
Example #9
0
        public FileHelper(String id)
        {
            logger.Debug("Initializing FileHelper");

            // Read all the keys from the config file
            NameValueCollection configuredFileTypes;

            configuredFileTypes = ConfigurationManager.AppSettings;

            foreach (string supportedExtension in configuredFileTypes.AllKeys)
            {
                try
                {
                    if (Convert.ToBoolean(configuredFileTypes.Get(supportedExtension)))
                    {
                        approvedFileExtensions.Add(supportedExtension);
                    }
                } catch (Exception parseError)
                {
                    logger.Error("Invalid value specified for supported file extension in App.config. Value must be True or False. Key: " + supportedExtension, parseError);
                }
            }

            if (id == null)
            {
                logger.Debug("No unique id passed to the filehelper to link to a specific application.");
            }
            else
            {
                logger.Debug("Unique id passed to the filehelper to link to a specific application: " + id);
            }

            InitializeComponent();

            logger.Debug("Fetching Download Folder Path.");

            try
            {
                IntPtr downloadFolderPathHandle;
                SHGetKnownFolderPath(DownloadsFolderId, 0, IntPtr.Zero, out downloadFolderPathHandle);

                DownloadFolderPath = Marshal.PtrToStringUni(downloadFolderPathHandle);
                Marshal.FreeCoTaskMem(downloadFolderPathHandle);
            }
            catch (Exception downloadsFolderError)
            {
                logger.Error("Unable to lookup Downloads Folder", downloadsFolderError);
                throw new Exception("Unable to lookup DownloadsFolder", downloadsFolderError);
            }

            logger.Debug("Fetched Download Folder Path: " + DownloadFolderPath);

            logger.Debug("Setting up file handling capability.");
            var openFileDialog = new OpenFileDialog();

            logger.Debug("File handling capability setup.");

            logger.Debug("Setting up OpenFin Runtime connection to runtime version 'stable'.");

            var opts = new Fin.RuntimeOptions()
            {
                Version = "stable",
                RuntimeConnectOptions = Fin.RuntimeConnectOptions.NonPersistent
            };

            runtime = Fin.Runtime.GetRuntimeInstance(opts);

            logger.Debug("OpenFin Runtime instance created. About to connect.");

            runtime.Connect(() =>
            {
                logger.Debug("OpenFin Runtime instance connected.");
                var defaultChannelId = "native-helper";
                var channelId        = "";

                if (id != null && id.Trim().Length > 0)
                {
                    logger.Debug("Custom identity passed: " + id);
                    channelId = id.ToLower();
                }
                else
                {
                    logger.Debug("No Custom identity passed. Using default channel: " + defaultChannelId);
                    channelId = defaultChannelId;
                }

                try
                {
                    logger.Debug("Creating channel:" + channelId);
                    var provider = runtime.InterApplicationBus.Channel.CreateProvider(channelId);
                    logger.Debug("Channel:" + channelId + " created.");

                    provider.ClientConnected += (s, e) =>
                    {
                        logger.Debug("Client Request Received. Request to connect to channel: " + channelId + " from application with UUID: " + e.Client.RemoteEndpoint.Uuid);
                        if (channelId != defaultChannelId && channelId != e.Client.RemoteEndpoint.Uuid.ToLower())
                        {
                            logger.Error("Client UUID (" + e.Client.RemoteEndpoint.Uuid.ToLower() + ") Request  to connect to channel: " + channelId + " denied. Only the app that launches the helper can connect to it.");
                            throw new Exception("Only the application that created the helper can connect to it. UUID/Channel Mismatch.");
                        }
                        logger.Debug("Client Request to connect to channel: " + channelId + " from application with UUID: " + e.Client.RemoteEndpoint.Uuid.ToLower() + " successful.");
                    };

                    logger.Debug("Registering: save-file topic.");
                    provider.RegisterTopic <JObject, string>("save-file", (args) =>
                    {
                        var logPrefix = "save-file: ";
                        logger.Debug(logPrefix + "save-file: Called");
                        var fileId   = Guid.NewGuid().ToString();
                        var fileName = args.Value <string>("fileName");

                        if (fileName == null || fileName.Length == 0)
                        {
                            logger.Error(logPrefix + "No filename was passed.");
                            return(ErrorList.ERROR_NO_FILE_NAME);
                        }

                        if (isValidFileType(fileName))
                        {
                            logger.Debug(logPrefix + "Filename retrieved: " + fileName);
                            var content = args.Value <string>("content");
                            logger.Debug(logPrefix + "Content retrieved.");

                            if (content == null || content.Length == 0)
                            {
                                logger.Error(logPrefix + "No data was passed.");
                                return(ErrorList.ERROR_NO_DATA_PASSED);
                            }

                            var target = Path.Combine(DownloadFolderPath, fileName);
                            logger.Debug(logPrefix + "Looking to write to: " + target);
                            byte[] passedData;
                            try
                            {
                                logger.Debug(logPrefix + "About to convert passed data from Base64 string");
                                passedData = Convert.FromBase64String(content);
                            }
                            catch (Exception convertingDataError)
                            {
                                logger.Error(logPrefix + "Error converting passed data: ", convertingDataError);
                                return(ErrorList.ERROR_CONVERTING_DATA);
                            }

                            try
                            {
                                logger.Debug(logPrefix + "About to write out content to target path: " + target);
                                File.WriteAllBytes(
                                    target,
                                    passedData);
                            }
                            catch (Exception fileSaveError)
                            {
                                logger.Error(logPrefix + "Error saving file: " + target, fileSaveError);
                                return(ErrorList.ERROR_SAVING_FILE);
                            }

                            logger.Debug(logPrefix + "content written to file.");
                            downloads[fileId] = target;
                            logger.Debug(logPrefix + "Returning id: " + fileId);
                            return(fileId);
                        }
                        else
                        {
                            logger.Error("Invalid file extension. Please check app settings in the App.config to ensure the file extension you are trying to save is supported. Returning id: 'Error - Invalid Extension'");
                            return(ErrorList.ERROR_INVALID_FILE_EXTENSION);
                        }
                    });
                    logger.Debug("save-file topic registered.");

                    logger.Debug("Registering: open-file topic.");
                    provider.RegisterTopic <JObject, string>("open-file", (args) =>
                    {
                        var logPrefix = "open-file: ";
                        logger.Debug(logPrefix + "Called");
                        var fileId = args.Value <string>("fileId");

                        if (fileId == null || fileId.Length == 0)
                        {
                            logger.Error(logPrefix + "No fileid was passed.");
                            return(ErrorList.ERROR_NO_FILE_ID);
                        }

                        logger.Debug(logPrefix + "Passed file id: " + fileId);
                        if (downloads.ContainsKey(fileId))
                        {
                            string fileName = downloads[fileId];
                            logger.Debug(logPrefix + "file name retrieved: " + fileName);
                            try
                            {
                                logger.Debug(logPrefix + "Opening file: " + fileName);
                                Process.Start(fileName);
                            }
                            catch (Exception fileOpenError)
                            {
                                logger.Error(logPrefix + "Error opening file: " + fileName, fileOpenError);
                                return(ErrorList.ERROR_OPENING_FILE);
                            }
                        }
                        else
                        {
                            return(ErrorList.ERROR_NO_FILE_ID_FOUND);
                        }

                        return("SUCCESS");
                    });
                    logger.Debug("open-file topic registered.");
                    provider.OpenAsync();
                }
                catch (Exception err)
                {
                    logger.Error("Error during create of channel or registration of topics.", err);
                    throw (new Exception("Unable to setup file helper channel", err));
                }
            });
        }