コード例 #1
0
        /// <summary>
        /// dynElement constructor for use by workbench in creating dynElements
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="nickName"></param>
        public dynElement()
        {
            InitializeComponent();
            //System.Uri resourceLocater = new System.Uri("/DynamoElements;component/dynElement.xaml", UriKind.Relative);
            //System.Uri resourceLocater = new System.Uri("/dynElement.xaml", UriKind.Relative);
            //System.Windows.Application.LoadComponent(this, resourceLocater);

            //set the main grid's data context to
            //this element
            nickNameBlock.DataContext = this;

            inPorts       = new List <dynPort>();
            inPortData    = new List <PortData>();
            outPortData   = new List <PortData>();
            outPorts      = new List <dynPort>();
            statePorts    = new List <dynPort>();
            statePortData = new List <PortData>();
            elements      = new ElementArray();
            dataTree      = new DataTree();
            stateSetter   = new SetStateDelegate(SetState);
            Dispatcher.Invoke(stateSetter, System.Windows.Threading.DispatcherPriority.Background, new object[] { this, ElementState.DEAD });

            ElementNameAttribute elNameAttrib = this.GetType().GetCustomAttributes(typeof(ElementNameAttribute), true)[0] as ElementNameAttribute;

            if (elNameAttrib != null)
            {
                NickName = elNameAttrib.ElementName;
            }

            //set the z index to 2
            Canvas.SetZIndex(this, 1);

            //generate a guid for the component
            dynElementReadyToBuild += new dynElementReadyToBuildHandler(Build);
        }
コード例 #2
0
        public void Update(LiquesceSvcState state, string message)
        {
            SetStateDelegate handler = setStateDelegate;

            if (handler != null)
            {
                handler(state, message);
            }
        }
コード例 #3
0
        private void _model_SearchFinished(object sender, System.EventArgs e)
        {
            timer.Stop();
            index = 0;

            if (_view.SearchResults.InvokeRequired)
            {
                SetStateDelegate setstate = new SetStateDelegate(_view.SetState);
                _view.SearchResults.Invoke(setstate, "Поиск завершён за " + counter + " миллисекунд, найдено: " + _model.Files.Count + " файлов");
            }
            else
                _view.SearchState.Text = "Поиск завершён за " + counter + " миллисекунд, найдено: " + _model.Files.Count + " файлов";
        }
コード例 #4
0
 public void CreateCallBack(SetStateDelegate newDelegate)
 {
     try
     {
         InstanceContext context = new InstanceContext(this);
         client = new LiquesceCallbackSvcRef.LiquesceCallBackClient(context);
         client.Subscribe(guid);
         setStateDelegate = newDelegate;
     }
     catch (Exception ex)
     {
         Log.ErrorException("CreateCallBack:", ex);
         Update(LiquesceSvcState.InError, ex.Message);
         client           = null;
         setStateDelegate = null;
     }
 }
コード例 #5
0
 public void RemoveCallback()
 {
     try
     {
         if (client != null)
         {
             client.Unsubscribe(guid);
         }
     }
     catch (Exception ex)
     {
         Log.ErrorException("RemoveCallback:", ex);
         Update(LiquesceSvcState.InError, ex.Message);
     }
     finally
     {
         client           = null;
         setStateDelegate = null;
     }
 }
コード例 #6
0
ファイル: dynNode.xaml.cs プロジェクト: Tadwork/Dynamo
        /// <summary>
        /// dynElement constructor for use by workbench in creating dynElements
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="nickName"></param>
        public dynNode()
        {
            InitializeComponent();
            //System.Uri resourceLocater = new System.Uri("/DynamoElements;component/dynElement.xaml", UriKind.Relative);
            //System.Uri resourceLocater = new System.Uri("/dynElement.xaml", UriKind.Relative);
            //System.Windows.Application.LoadComponent(this, resourceLocater);

            //set the main grid's data context to
            //this element
            nickNameBlock.DataContext = this;

            inPorts = new List<dynPort>();
            inPortData = new List<PortData>();
            statePorts = new List<dynPort>();
            statePortData = new List<PortData>();
            elements = new List<List<ElementId>>() { new List<ElementId>() };
            inPortTextBlocks = new Dictionary<dynPort, TextBlock>();

            stateSetter = new SetStateDelegate(SetState);
            State = ElementState.DEAD;

            //Fetch the element name from the custom attribute.
            var nameArray = GetType().GetCustomAttributes(typeof(ElementNameAttribute), true);

            if (nameArray.Length > 0)
            {
                ElementNameAttribute elNameAttrib = nameArray[0] as ElementNameAttribute;
                if (elNameAttrib != null)
                {
                    NickName = elNameAttrib.ElementName;
                }
            }
            else
                NickName = "";

            //set the z index to 2
            Canvas.SetZIndex(this, 1);

            //Canvas.SetZIndex(this.gridLeft, 40);
            //Canvas.SetZIndex(this.gridRight, 40);

            //dirtyEllipse = new System.Windows.Shapes.Ellipse();
            //dirtyEllipse.Height = 20;
            //dirtyEllipse.Width = 20;
            //dirtyEllipse.Fill = Brushes.Red;
            //elementCanvas.Children.Add(dirtyEllipse);
            //Canvas.SetBottom(dirtyEllipse, 10);
            //Canvas.SetRight(dirtyEllipse, 10);
            //Canvas.SetZIndex(dirtyEllipse, 100);

            //dynElementReadyToBuild += new dynElementReadyToBuildHandler(Build);
        }
コード例 #7
0
 private void _view_SearchStop(object sender, System.EventArgs e)
 {
     _model.StopSearch();
     timer.Stop();
     if (_view.SearchResults.InvokeRequired)
     {
         SetStateDelegate setstate = new SetStateDelegate(_view.SetState);
         _view.SearchResults.Invoke(setstate, "Поиск остановлен на " + counter + " миллисекунде");
     }
     else
         _view.SearchState.Text = "Поиск остановлен на " + counter + " миллисекунде";
 }
コード例 #8
0
ファイル: dynElement.xaml.cs プロジェクト: TCadorette/dynamo
        /// <summary>
        /// dynElement constructor for use by workbench in creating dynElements
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="nickName"></param>
        public dynElement()
        {
            InitializeComponent();
            //System.Uri resourceLocater = new System.Uri("/DynamoElements;component/dynElement.xaml", UriKind.Relative);
            //System.Uri resourceLocater = new System.Uri("/dynElement.xaml", UriKind.Relative);
            //System.Windows.Application.LoadComponent(this, resourceLocater);

            //set the main grid's data context to
            //this element
            nickNameBlock.DataContext = this;

            inPorts = new List<dynPort>();
            inPortData = new List<PortData>();
            outPortData = new List<PortData>();
            outPorts = new List<dynPort>();
            statePorts = new List<dynPort>();
            statePortData = new List<PortData>();
            elements = new ElementArray();
            dataTree = new DataTree();
            stateSetter = new SetStateDelegate(SetState);
            Dispatcher.Invoke(stateSetter, System.Windows.Threading.DispatcherPriority.Background, new object[] {this, ElementState.DEAD });

            ElementNameAttribute elNameAttrib = this.GetType().GetCustomAttributes(typeof(ElementNameAttribute), true)[0] as ElementNameAttribute;
            if (elNameAttrib != null)
            {
                NickName = elNameAttrib.ElementName;
            }

            //set the z index to 2
            Canvas.SetZIndex(this, 1);

            //generate a guid for the component
            dynElementReadyToBuild += new dynElementReadyToBuildHandler(Build);
        }
コード例 #9
0
        // 截图翻译
        private void ScreenTran()
        {
            string           from = "en", src, dst = null;
            Image            captureImage = default;
            FrmScreenShot    shot         = new FrmScreenShot();
            SetStateDelegate setState     = new SetStateDelegate(MinimizeWindow);

            try
            {   // 截图翻译并显示
                if (tranMode == TranMode.TranAndShowText)
                {
                    this.Invoke((EventHandler) delegate
                    {
                        setState(true);
                    });
                    Thread.Sleep(200);
                    // 如果是固定区域翻译(isFixedScreen = true则视为固定区域翻译)
                    if (isFixedScreen == true)
                    {
                        captureImage = FixedScreen();
                    }
                    else
                    {
                        shot.CopyScreen();
                        if (shot.ShowDialog() == DialogResult.Cancel) // 显示截图窗口
                        {
                            return;
                        }
                        captureImage = shot.CaptureImage;
                    }

                    // 翻译模式isEnToZh=true为英译中,false为俄译中
                    if (isEnToZh == false)
                    {
                        from = "ru";
                    }

                    // sourceOfTran有“有道”两字使用有道翻译,否则使用百度翻译
                    if (sourceOfTran.IndexOf("有道") != -1)
                    {
                        Youdao.YoudaoTran(null, from, "zh-CHS", out src, out dst, captureImage);
                    }
                    else
                    {
                        Baidu.BaiduTran(captureImage, from, out src, out dst);
                    }

                    if (copySourceTextToClip)
                    {
                        Clipboard.SetText(src);// 复制原文到剪切板
                    }
                    if (copyDestTextToClip)
                    {
                        Clipboard.SetText(dst);// 复制译文到剪切板
                    }
                    if (isSpeak)
                    {
                        SpeechSynthesizer speech = new SpeechSynthesizer();
                        speech.Rate = 3;   // 语速
                        speech.SpeakAsync(dst);
                    }
                }
                else
                {
                    dst = showCont;
                }
                // 不为空
                if (!string.IsNullOrEmpty(dst))
                {
                    ShowText(dst);
                }
            }
            catch (Exception ex)
            {
                if (ex.GetType().FullName == "System.Threading.ThreadAbortException")
                {
                    return;
                }
                // 显示错误
                ShowText("错误:" + ex.Message);
            }
            finally
            {
                if (shot != null && !shot.IsDisposed)
                {
                    shot.Dispose();
                }
                //if (captureImage != null)
                //    captureImage.Dispose();
            }
        }