Exemple #1
0
        public void Initialize(IDictionary <string, object> parameters, CancellationToken cancellationToken)
        {
            log_file_ = (string)parameters[".log_file"];
            if (log_file_ != null)
            {
                File.WriteAllText(log_file_, "");
            }

            string scriptroot = (string)parameters["scriptroot"];

            filesystem_ = new WWB.MyFileSystem(scriptroot);
            string root = filesystem_.Combine(null, null);

            bool reset = (bool)parameters["reset"];

            if (!Directory.Exists(root))
            {
                reset = true;
                Directory.CreateDirectory(root);
            }

            if (reset)
            {
                // copy samples to the virtual file system
                foreach (string res_name in WWB.Util.GetResourceFileNames("Samples"))
                {
                    string sample    = WWB.Util.ReadResourceTextFile("Samples." + res_name, false);
                    string file_name = root + "\\" + res_name;
                    File.WriteAllText(file_name, sample);
                }
            }

            bool debug                = (bool)parameters["debug"];
            bool sandboxed            = (bool)parameters["sandboxed"];
            SynchronizationContext sc = new SynchronizationContext();

            basic_thread_.SendAction(basic =>
            {
                // configure basic
                basic.Synchronizing += (sender, e) =>
                {
                    // response/notification from the remote BasicNoUIObj
                    sc.Post(state => {
                        Log(e.Param);
                        lock (lock_)
                            responses_sqs_.Enqueue(e.Param, e.Id);
                    }, null);
                };
                basic.ReceivedAppSyncMessage += (sender, e) =>
                {
                    basic.SendAppSyncMessage(e.Data, -1);
                };
                Util.IgnoreDialogs = true;
                basic.Secret       = new Guid(Secret.MySecret);
                basic.Initialize();
                basic.EditOnly          = !debug;
                basic.Sandboxed         = sandboxed;
                basic.BlockedKeywords   = "AboutWinWrapBasic Beep Dialog GetFilePath InputBox MsgBox ShowPopupMenu";
                basic.VirtualFileSystem = filesystem_;
                basic.SynchronizedEdit  = true; // synchronized editing
            });
        }