示例#1
1
        public override void Run(ServiceController[] services, Form mainForm, DataGrid serviceGrid)
        {
            var addedMachine = QuickDialog2.DoQuickDialog("Add A Machine's Services", "Machine Name:",".","Pattern  ^(Enable|EPX):","");

            if (addedMachine != null)
            {

                MachineName = addedMachine[0];
                this.SearchPattern = addedMachine[1];
                try
                {
                    DataGrid dgrid = serviceGrid;

                    this.addView = (DataView)dgrid.DataSource;

                    CurrencyManager bm = (CurrencyManager)dgrid.BindingContext[this.addView];
                    ArrayList arrSelectedRows = new ArrayList();

                    this.addView = (DataView)bm.List;

                    mainForm.Invoke(new InvokeDelegate(this.AddMachineInGUIThread));

                    serviceGrid.Refresh();

                }
                finally
                {
                    addedMachine = null;
                    addView = null;
                }

            }
        }
示例#2
1
        public MainWindow(Form parent, OGameBot bot, UGInfos forumInfos)
        {
            _bot = bot;
            _parent = parent;
            InitializeComponent();
            forumUserLabel.Text = @"User: "******"Post: " + forumInfos.Post;
            forumPostLabel.Text = @"UID: " + forumInfos.UID;
            forumStatusLabel.Text = @"Status: " + forumInfos.Status;
            PopulateAddBuildingList();

            _bot.BeganBuild += (o, b) => DisplayLogMessage(@"Iniziata la costruzione di " + b.GetDescription());

            _bot.Built += (o, b) =>
                              {
                                  DisplayLogMessage(@"Terminata la costruzione di " + b.GetDescription());
                                  buildingListView.Invoke(new Action(() => buildingListView.Items.RemoveAt(0)));
                              };

            _bot.BuildingUnavaiable += (o, b) => DisplayLogMessage(@"Non puoi costruire " + b.GetDescription() + ", verrà spostato in fondo alla coda.");
            _bot.NotEnoughResources += (o, b) =>
                                           {
                                               if (_notEnoughResourcesCount == 0)
                                                   DisplayLogMessage(@"Risorse non sufficenti per " + b.GetDescription() +
                                                                     ", in attesa");
                                               _notEnoughResourcesCount = ++_notEnoughResourcesCount%20;
                                           };

            _bot.InConstruction += o =>
                                       {
                                           if (_inConstructionCount == 0)
                                               DisplayLogMessage(
                                                   @"E' già presente un edificio in costruzione, in attesa");
                                           _inConstructionCount = ++_inConstructionCount%20;
                                       };
            _bot.Stopped += o => _parent.Invoke(new Action(Close));
        }
示例#3
0
文件: Convert.cs 项目: vaginessa/open
        private void pdf_to_word(save_progress progress, System.Windows.Forms.Form dlg, string fileType)
        {
            Aspose.Pdf.Document document = null;
            int num = 0;

            if (fileType == ".pdf")
            {
                document = this.pdf_doc;
                num      = 0;
            }
            else if ((fileType == ".ppt") || (fileType == ".pptx"))
            {
                document = this.ppt_to_pdf(progress, dlg, 0);
                num      = 50;
            }
            else if ((fileType == ".xls") || (fileType == ".xlsx"))
            {
                document = this.xls_to_pdf(progress, dlg, 0);
                num      = 50;
            }
            Aspose.Words.Document document2 = new Aspose.Words.Document();
            Aspose.Pdf.Document   document3 = new Aspose.Pdf.Document();
            if (progress != null)
            {
                dlg.Invoke(progress, new object[] { num });
            }
            document2.ChildNodes.Clear();
            for (int i = 1; i <= document.Pages.Count; i++)
            {
                try
                {
                    MemoryStream outputStream = new MemoryStream();
                    document3.Pages.Add(document.Pages[i]);
                    document3.Save(outputStream, Aspose.Pdf.SaveFormat.Doc);
                    document2.AppendDocument(new Aspose.Words.Document(outputStream), ImportFormatMode.KeepSourceFormatting);
                    document3.Pages.Delete();
                }
                catch (Exception)
                {
                    break;
                }
                if (progress != null)
                {
                    if (num == 50)
                    {
                        dlg.Invoke(progress, new object[] { ((i * 50) / document.Pages.Count) + 50 });
                    }
                    else
                    {
                        dlg.Invoke(progress, new object[] { (i * 100) / this.pdf_doc.Pages.Count });
                    }
                }
            }
            document2.Save(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + this.get_suffix());
            if (progress != null)
            {
                dlg.Invoke(progress, new object[] { 100 });
            }
        }
示例#4
0
文件: Convert.cs 项目: vaginessa/open
        private void pdf_to_excel(save_progress progress, System.Windows.Forms.Form dlg, string fileType)
        {
            Aspose.Pdf.Document document = null;
            int num = 0;

            try
            {
                if (fileType == ".pdf")
                {
                    document = this.pdf_doc;
                    num      = 0;
                }
                else if ((fileType == ".ppt") || (fileType == ".pptx"))
                {
                    document = this.ppt_to_pdf(progress, dlg, 0);
                    num      = 50;
                }
                else if ((fileType == ".doc") || (fileType == ".docx"))
                {
                    document = this.doc_to_pdf(progress, dlg, 0);
                    num      = 50;
                }
                Workbook            workbook  = new Workbook();
                Aspose.Pdf.Document document2 = new Aspose.Pdf.Document();
                if (progress != null)
                {
                    dlg.Invoke(progress, new object[] { num });
                }
                workbook.Worksheets.Clear();
                for (int i = 1; i <= document.Pages.Count; i++)
                {
                    MemoryStream outputStream = new MemoryStream();
                    document2.Pages.Add(document.Pages[i]);
                    document2.Save(outputStream, Aspose.Pdf.SaveFormat.Excel);
                    Workbook workbook2 = new Workbook(outputStream);
                    workbook.Worksheets.Add(i.ToString());
                    workbook.Worksheets[i - 1].Copy(workbook2.Worksheets[0]);
                    document2.Pages.Delete();
                    if (progress != null)
                    {
                        if (num == 50)
                        {
                            dlg.Invoke(progress, new object[] { ((i * 50) / document.Pages.Count) + 50 });
                        }
                        else
                        {
                            dlg.Invoke(progress, new object[] { (i * 100) / this.pdf_doc.Pages.Count });
                        }
                    }
                }
                workbook.Save(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + ".xls");
            }
            catch (Exception)
            {
            }
        }
示例#5
0
 public void displayStatusMsg(string strMsg)
 {
     try
     {
         _frmMainForm.Invoke(new AddMessageHandler(this.AddStatusMessage), new object[] { strMsg });
     }
     catch (Exception ex)
     {
     }
 }
示例#6
0
文件: Convert.cs 项目: vaginessa/open
        private Aspose.Pdf.Document xls_to_pdf(save_progress progress, System.Windows.Forms.Form dlg, int lst_select)
        {
            int num = 50;

            if (lst_select >= 7)
            {
                num = 100;
            }
            Aspose.Pdf.Document document = null;
            try
            {
                Workbook workbook = new Workbook();
                if (progress != null)
                {
                    dlg.Invoke(progress, new object[] { 0 });
                }
                workbook.Worksheets.Clear();
                if (this.excel_doc == null)
                {
                    return(document);
                }
                document = new Aspose.Pdf.Document();
                for (int i = 0; i < this.excel_doc.Worksheets.Count; i++)
                {
                    MemoryStream stream = new MemoryStream();
                    workbook.Worksheets.Add(i.ToString());
                    workbook.Worksheets[0].Copy(this.excel_doc.Worksheets[i]);
                    workbook.Save(stream, Aspose.Cells.SaveFormat.Pdf);
                    document.Pages.Add(new Aspose.Pdf.Document(stream).Pages);
                    workbook.Worksheets.RemoveAt(0);
                    if (progress != null)
                    {
                        dlg.Invoke(progress, new object[] { (i * num) / this.excel_doc.Worksheets.Count });
                    }
                }
                if (lst_select >= 7)
                {
                    document.Save(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + ".pdf");
                }
                if (progress != null)
                {
                    dlg.Invoke(progress, new object[] { num });
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(document);
        }
示例#7
0
文件: Convert.cs 项目: vaginessa/open
        private Aspose.Pdf.Document ppt_to_pdf(save_progress progress, System.Windows.Forms.Form dlg, int lst_select)
        {
            int num = 50;

            if (lst_select >= 7)
            {
                num = 100;
            }
            Presentation presentation = new Presentation();

            Aspose.Pdf.Document document = new Aspose.Pdf.Document();
            try
            {
                presentation.Slides.RemoveAt(0);
                if (progress != null)
                {
                    dlg.Invoke(progress, new object[] { 0 });
                }
                if (this.ppt_doc == null)
                {
                    return(null);
                }
                for (int i = 0; i < this.ppt_doc.Slides.Count; i++)
                {
                    MemoryStream stream = new MemoryStream();
                    presentation.Slides.AddClone(this.ppt_doc.Slides[i]);
                    presentation.Save(stream, Aspose.Slides.Export.SaveFormat.Pdf);
                    presentation.Slides.RemoveAt(0);
                    document.Pages.Add(new Aspose.Pdf.Document(stream).Pages);
                    if (progress != null)
                    {
                        dlg.Invoke(progress, new object[] { (i * num) / this.ppt_doc.Slides.Count });
                    }
                }
                if (lst_select >= 7)
                {
                    document.Save(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + ".pdf");
                }
                if (progress != null)
                {
                    dlg.Invoke(progress, new object[] { num });
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(document);
        }
示例#8
0
文件: Convert.cs 项目: vaginessa/open
        private Aspose.Pdf.Document doc_to_pdf(save_progress progress, System.Windows.Forms.Form dlg, int lst_select)
        {
            int num = 50;

            if (lst_select == 7)
            {
                num = 100;
            }
            Aspose.Pdf.Document document2 = new Aspose.Pdf.Document();
            try
            {
                document2.Pages.Delete();
                if (progress != null)
                {
                    dlg.Invoke(progress, new object[] { 0 });
                }
                if (this.word_doc == null)
                {
                    return(null);
                }
                for (int i = 0; i < this.word_doc.ChildNodes.Count; i++)
                {
                    MemoryStream          stream   = new MemoryStream();
                    Aspose.Words.Document document = new Aspose.Words.Document();
                    document.ChildNodes.RemoveAt(0);
                    document.AppendChild(document.ImportNode(this.word_doc.ChildNodes[i], true));
                    document.Save(stream, Aspose.Words.SaveFormat.Pdf);
                    document2.Pages.Add(new Aspose.Pdf.Document(stream).Pages);
                    if (progress != null)
                    {
                        dlg.Invoke(progress, new object[] { (i * num) / this.word_doc.ChildNodes.Count });
                    }
                }
                if (lst_select == 7)
                {
                    document2.Save(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + this.get_suffix());
                }
                if (progress != null)
                {
                    dlg.Invoke(progress, new object[] { num });
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(document2);
        }
示例#9
0
        protected virtual void OnPropertyChanged(string propertyName)
        {
            System.ComponentModel.PropertyChangedEventHandler handler = PropertyChanged;

            if (handler != null)
            {
                if (System.Windows.Forms.Application.OpenForms.Count > 0)
                {
                    System.Windows.Forms.Form mainForm = System.Windows.Forms.Application.OpenForms[0];

                    if (mainForm != null)
                    {
                        if (mainForm.InvokeRequired)
                        {
                            // We are not in UI Thread now
                            mainForm.Invoke(handler, new object[] { this, new System.ComponentModel.PropertyChangedEventArgs(propertyName) });
                        }
                        else
                        {
                            handler(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
                        }
                    }
                }
            }
        }
示例#10
0
 public static void Close(Form form)
 {
     if (form.InvokeRequired)
         form.Invoke(new CloseDelegate(Close), form);
     else
         form.Close();
 }
示例#11
0
 /// <summary>
 /// Will open a form that will ask for connection details (with option for default props) and attempt to ping target to see if it is possible to establish connection
 /// </summary>
 /// <param name="parent">Parent form that this form will be opened on</param>
 /// <param name="default_details">The default connection details to be inserted</param>
 /// <param name="forceTesting"></param>
 public static ConnectionDetails GetDetails(Form parent, ConnectionDetails default_details, bool forceTesting = true) {
     UserConnectionDetailsRequester getter = null;
     parent.Invoke(() => {
                       getter = new UserConnectionDetailsRequester(forceTesting, default_details);
                       getter.ShowDialog(parent);
                   });
     return getter.Results();
 }
示例#12
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="mainApplicationForm">The application's main form</param>
        public UIActor(Form mainApplicationForm)
        {
            m_applicationForm = mainApplicationForm;

            m_applicationForm.Invoke((Action)(() =>
            {
                if (Actor.CurrentActor != null) Actor.CurrentActor = this;
            }));
        }
			private delegate void ShowErrorCallback(Form frmWindow, string strMessage, Exception objException); // Permite llamadas asíncronas para mostrar un mensaje
			
		/// <summary>
		///		Muestra un cuadro de mensaje
		/// </summary>
		public static void ShowMessage(Form frmWindow, string strMessage)
		{ // InvokeRequired compara el ID del hilo llamante con el ID del hilo creador, si son diferentes devuelve True
				if (frmWindow != null && frmWindow.InvokeRequired)
					{	ShowMessageCallback fncCallback = new ShowMessageCallback(ShowMessage);
					
							frmWindow.Invoke(fncCallback, new object[] { frmWindow, strMessage });
					}
				else
					MessageBox.Show(frmWindow, strMessage, Application.ProductName);
		}
示例#14
0
 public static void CloseForm(Form form)
 {
     // Check if the form need to be invoked.
     if (form.InvokeRequired)
         // Invoke the form with the appropiate delegate.
         form.Invoke(new Action<Form>(CloseForm), form);
     else
         // Directly close the form.
         form.Close();
 }
示例#15
0
 public DrawingSystem(Form form, EntityManager manager)
     : base(manager)
 {
     _form = form;
     _form.Invoke(new Action(() =>
     {
         _context = BufferedGraphicsManager.Current;
         _buffer = _context.Allocate(_form.CreateGraphics(), _form.DisplayRectangle);
     }));
 }
示例#16
0
 public static void Invoke(Form form, AsyncAction action)
 {
     if (!form.InvokeRequired)
     {
         action();
     }
     else
     {
         form.Invoke((DispatcherInvoker)Invoke, form, action);
     }
 }
        private void ConnectionAccepted(IAsyncResult ar)
        {
            if (!StopThread)
            {
                // Dim listener As TcpListener = CType(ar.AsyncState, TcpListener)
                TcpClient client = server.EndAcceptTcpClient(ar);

                byte[] bytes = new byte[1025];

                // Get a stream object for reading and writing
                NetworkStream stream = client.GetStream();

                int i = stream.Read(bytes, 0, bytes.Length);


                string header = "<html xmlns : msxsl = \"urn:schemas-Microsoft - com: xslt\"  meta content=\"en-us\" http-equiv=\"Content-Language\" /> " + "<meta content=\"text/html; charset=utf-16\" http-equiv=\"Content-Type\" /> " + "<meta http-equiv=\"refresh\" content=\"" + m_RefreshTime.ToString() + "\"> ";

                header += "<img src=\"data:image/png;base64,";
                byte[] b = System.Text.ASCIIEncoding.Default.GetBytes(header);
                stream.Write(b, 0, b.Length);

                byte[] Imgbytes = null;
                bmpScreenCapture = new Bitmap(m_SourceForm.Width, m_SourceForm.Height);
                m_SourceForm.Invoke(dcc);
                using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                {
                    bmpScreenCapture.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    Imgbytes = ms.ToArray();
                }

                string s = Convert.ToBase64String(Imgbytes);
                Imgbytes = System.Text.ASCIIEncoding.Default.GetBytes(s);
                try
                {
                    stream.Write(Imgbytes, 0, Imgbytes.Length);

                    string trailer = " \"/>";
                    b = System.Text.ASCIIEncoding.Default.GetBytes(trailer);
                    stream.Write(b, 0, b.Length);


                    // Shutdown and end connection
                    client.Close();
                }
                catch (Exception ex)
                {
                }
            }

            if (!StopThread)
            {
                server.BeginAcceptTcpClient(ConnectionAccepted, server);
            }
        }
示例#18
0
 public static void SetText(Form form, Control ctrl, string text)
 {
     if (ctrl.InvokeRequired)
     {
         SetTextCallback stc = SetText;
         form.Invoke(stc, new object[] {form, ctrl, text});
     }
     else
     {
         ctrl.Text = text;
     }
 }
示例#19
0
        /// <summary>
        /// Initializes a new GameWindow class.
        /// </summary>
        /// <param name="handle">The Handle.</param>
        internal GameWindow(IntPtr handle)
        {
            _surface = (Form) Control.FromHandle(handle);
            _surfaceStyle = SurfaceStyle.Normal;
            _surfaceLayout = new SurfaceLayout(true, false, true);
            CursorVisibility = false;
            _surface.FormClosing += _surface_FormClosing;
            _surface.Activated += _surface_Activated;
            _surface.Deactivate += _surface_Deactivate;

            MethodInvoker br = delegate { _surface.KeyPreview = true; };
            _surface.Invoke(br);
        }
        public static void SetControlEnable(this Control control, Form CFrom, bool enable)
        {
            if (CFrom.InvokeRequired)
            {
                ControlEnableMethod controlEnableMethod = SetControlEnable;
                CFrom.Invoke(controlEnableMethod, new object[] { control, CFrom, enable });
            }
            else
            {
                control.Enabled = enable;
            }

            Application.DoEvents();
        }
		/// <summary>
		/// Safely retrieves the window's handle. The events the InstanceManager are on a separate thread
		/// forcing us to marshall the calls back to the window's thread.
		/// </summary>
		/// <param name="window">The window to retrieve the handle for.</param>
		/// <returns></returns>
		public static IntPtr SafeGetWindowHandle(Form window)
		{
			if (window == null)
			{
				return IntPtr.Zero;
			}

			if (window.InvokeRequired)
			{
				return (IntPtr)window.Invoke(new GetWindowHandleDelegate(SafeGetWindowHandle), window);
			}

			return window.Handle;
		}
 public void PrintText(string txt, TextBox printBox, Form owner)
 {
     if (printBox.InvokeRequired)
     {
         invokeTextBox d = new invokeTextBox(PrintText);
         owner.Invoke(d, txt, printBox, owner);
     }
     else
     {
         printBox.Text += txt;
         printBox.Select(printBox.Text.Length, 0);
         printBox.ScrollToCaret();
     }
 }
示例#23
0
        private static void ActivateParentForm(Form parentForm)
        {
            if (parentForm != null)
            {
                //HandleRef href = new HandleRef(ParentForm, ParentForm.Handle);
                //SetForegroundWindow(href);

                parentForm.Invoke(new Action(() => { parentForm.Activate(); }));
            }
            else if (ApplicationService.Current.MainForm != null)
            {
                ApplicationService.Current.MainForm.Invoke(new Action(() => { ApplicationService.Current.MainForm.Activate(); }));
            }
        }
        public static void SetControlText(this Control control, Form CFrom, string text)
        {
            if (CFrom.InvokeRequired)
            {
                ControlTextMethod controlTextMethod = SetControlText;
                CFrom.Invoke(controlTextMethod, new object[] { control, CFrom, text });
            }
            else
            {
                control.Text = text;
            }

            Application.DoEvents();
        }
示例#25
0
 /// <summary>
 /// Set text property of various controls
 /// </summary>
 /// <param name="form">The calling form</param>
 /// <param name="ctrl"></param>
 /// <param name="text"></param>
 public static void SetText(Form form, Control ctrl, string text)
 {
     // InvokeRequired required compares the thread ID of the
     // calling thread to the thread ID of the creating thread.
     // If these threads are different, it returns true.
     if (ctrl.InvokeRequired)
     {
         SetTextCallback d = new SetTextCallback(SetText);
         form.Invoke(d, new object[] { form, ctrl, text });
     }
     else
     {
         ctrl.Text = text;
     }
 }
示例#26
0
        public void RefreshGridFromService( Form mainForm, DataGrid serviceGrid )
        {
            DataGrid dgrid = serviceGrid;

            this.tempView = (DataView)dgrid.DataSource;

            CurrencyManager bm = (CurrencyManager)dgrid.BindingContext[ this.tempView ];
            ArrayList arrSelectedRows = new ArrayList();

            this.tempView = (DataView) bm.List;

            mainForm.Invoke( new InvokeDelegate( this.RefreshDataInGUIThread ));

            serviceGrid.Refresh();
        }
示例#27
0
 void webClient_DownloadStringCompleted(object sender, System.Net.DownloadStringCompletedEventArgs e)
 {
     if (mMonitor != null)
     {
         mMonitor.Close(new Action(() => { mCompletedFct(e, mParent, mParam); }));
     }
     else if (mParent.IsInvokeRequired())
     {
         mParent.Invoke(new Action(() => { mCompletedFct(e, mParent, mParam); }));
     }
     else
     {
         mCompletedFct(e, mParent, mParam);
     }
 }
示例#28
0
        public static void UnregisterHotKey(Form f)
        {
            try
            {
                Func ff = delegate()
                {
                    UnregisterHotKey(f.Handle, keyId); // modify this if you want more than one hotkey
                };

                f.Invoke(ff); // this should be checked if we really need it (InvokeRequired), but it's faster this way
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
        }
示例#29
0
        private void UpdateCursor(Form form, Cursor cursor)
        {
            MethodInvoker ChangeCursor = delegate
            {
                form.Cursor = cursor;
            };

            if (form.InvokeRequired)
            {
                form.Invoke(ChangeCursor);
            }
            else
            {
                ChangeCursor();
            }
        }
        public WindowSync(Form form, IntPtr windowHandle, ILogger logger)
        {
            _form = form;
            _windowHandle = windowHandle;
            _logger = logger;

            _form.Invoke(new MethodInvoker(() =>
            {
                _form.ShowInTaskbar = true;
                NativeWindowMethods.SetWindowLong(_windowHandle, -8, _form.Handle);
                // Until the electron window starts reporting window changes, use a timer to keep them in sync
                //_syncTimer = new System.Threading.Timer(OnTimerCallback, null, 10, 10);
            }));
            
             OnTimerCallback(null);
        }
示例#31
0
        /// <summary>
        /// Colse the WelcomerForm
        /// </summary>
        public static void Close()
        {
            if (_WelcomerThread == null || _WelcomerForm == null)
            {
                return;
            }

            try
            {
                _WelcomerForm.Invoke(new MethodInvoker(_WelcomerForm.Close));
            }
            finally
            {
                _WelcomerThread = null;
                _WelcomerForm   = null;
            }
        }
示例#32
0
 private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     lock (syncObject)
     {
         if (closed)
         {
             return;
         }
     }
     if (parent.IsInvokeRequired())
     {
         parent.Invoke(new Action(() => { OpenDialog(); }));
     }
     else
     {
         OpenDialog();
     }
 }
示例#33
0
 /// <summary>
 /// 跨线程匿名委托调用
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="t"></param>
 public static void CrossThreadCalls(this System.Windows.Forms.Form sender, Threading.ThreadStart t)
 {
     if (sender == null)
     {
         return;
     }
     lock (sender)
     {
         if (sender.InvokeRequired)
         {
             sender.Invoke(t, null);
         }
         else
         {
             t();
         }
     }
 }
示例#34
0
        private void Button_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                ProcessInput(textBox.Text);

                if (form.IsHandleCreated)
                {
                    lock (graph)
                    {
                        form.SuspendLayout();
                        form.Invoke(new RefreshDelegate(Refresh));
                        form.ResumeLayout();
                    }
                }

                textBox.Text = "";
            }
        }
示例#35
0
        public override void Run(ServiceController[] services, Form mainForm, DataGrid serviceGrid)
        {
            DataGrid dgrid = serviceGrid;

            this.dView = (DataView)dgrid.DataSource;

            CurrencyManager bm = (CurrencyManager)dgrid.BindingContext[ dView ];
            ArrayList arrSelectedRows = new ArrayList();

            this.dView = (DataView) bm.List;

            ArrayList sortedItems = new ArrayList();
            sortedItems.AddRange( dView.Table.Rows );

            DataRow[] rows = (DataRow[])sortedItems.ToArray( typeof( DataRow ));

            if ( this.dView.Sort != null && this.dView.Sort.Length > 0 )
            {
                try
                {
                    Array.Sort( rows, new  ServiceMgrWorkUnit.RowComparer( this.dView.Sort ));
                }
                catch (Exception e)
                {
                    Console.WriteLine("Unable to sort the rows as they were in the grid:" + e.Message );
                }
            }

            // See if multi's are selected
            this.rowsToDelete = new ArrayList();
            for ( int i = 0; i < rows.Length; i++ )
            {

                if ( dgrid.IsSelected(i))
                {

                    rowsToDelete.Add(rows[i] );
                }

            }

            mainForm.Invoke( new InvokeDelegate( this.DeleteRowsInGUIThread ));
        }
        /// <summary>
        /// Invoke with a form and a number of seconds and the helper will attempt to keep the form focused
        /// for that period of time.
        /// </summary>
        /// <param name="form">The form to retain focus on</param>
        /// <param name="seconds">The number of seconds to retain focus for</param>
        /// <remarks>This method uses the <see cref="ThreadPool" /> to asynchronously maintain focus.</remarks>
        public static void EnqueRetainFocusCallback(Form form, int seconds)
        {
            WaitCallback callback = delegate
                                        {
                                            try
                                            {
                                                for (int i = 0; i < (seconds*10); i++)
                                                {
                                                    Thread.Sleep(100);

                                                    // must ensure the form hasn't be disposed (in case the user closes the 
                                                    // form before the retain focus time has expired).

                                                    if (form.IsDisposed || form.Disposing) return;

                                                    if (!form.IsHandleCreated) continue;

                                                    form.Invoke(new ThreadStart(delegate
                                                                                    {
                                                                                        if (form.IsDisposed ||
                                                                                            form.Disposing) return;
                                                                                        form.Focus();
                                                                                    }));
                                                }
                                            }
                                            catch (Exception ex)
                                            {
                                                throw;
                                                // TODO: fix this
                                                /*if (IoC.IsInitialized)
                                                {
                                                    ILogger logger =
                                                        IoC.Resolve<ILoggerFactory>().Create(form.GetType());
                                                    logger.Error(
                                                        "Exception raised while attempting to maintain form focus, aborting callback",
                                                        ex);
                                                }
                                                return;*/
                                            }
                                        };

            ThreadPool.QueueUserWorkItem(callback);
        }
示例#37
0
        public static DialogResult DisplayMessageBox(Form form, string message, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
        {
            DialogResult result = DialogResult.Ignore;

            MethodInvoker DisplayMessage = delegate
            {
                result = MessageBox.Show(form, message, caption, buttons, icon);
            };

            if (form != null && form.InvokeRequired)
            {
                form.Invoke(DisplayMessage);
                return result;
            }
            else
            {
                DisplayMessage();
                return result;
            }
        }
示例#38
0
        public static void RegisterHotKey(Form f, Keys key)
        {
            int modifiers = 0;

            if ((key & Keys.Alt) == Keys.Alt)
                modifiers = modifiers | WindowsShell.MOD_ALT;

            if ((key & Keys.Control) == Keys.Control)
                modifiers = modifiers | WindowsShell.MOD_CONTROL;

            if ((key & Keys.Shift) == Keys.Shift)
                modifiers = modifiers | WindowsShell.MOD_SHIFT;

            Keys k = key & ~Keys.Control & ~Keys.Shift & ~Keys.Alt;

            Func ff = delegate()
                {
                    keyId = f.GetHashCode(); // this should be a key unique ID, modify this if you want more than one hotkey
                    RegisterHotKey((IntPtr)f.Handle, keyId, modifiers, (int)k);
                };

            f.Invoke(ff); // this should be checked if we really need it (InvokeRequired), but it's faster this way
        }
        public void ErrorManagement(Exception ex, bool drastic, System.Windows.Forms.Form frm)
        {
            //MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            frmErrorDetails frmError = new frmErrorDetails();

            frmError.ErrorMessage = ex.Message;
            if (frm != null)
            {
                frmError.ErrorMessage += " Module " + frm.Name + "[" + ex.StackTrace + "]";
            }
            frmError.ShowDialog();

            if (CommonItem.CurrentSettings.LogActive && CommonItem.CurrentSettings.LogPath != String.Empty)
            {
                WriteLog(ex.Message);
            }

            //Set cursor to default without exception (multithreads compatibility)
            try
            {
                frm.Invoke(new MethodInvoker(delegate
                {
                    frm.Cursor = System.Windows.Forms.Cursors.Default;
                }));
            }
            catch (Exception)
            {
            }

            //frm.Cursor = System.Windows.Forms.Cursors.Default;

            if (drastic)
            {
                frm.Close();
            }
        }
示例#40
0
文件: Convert.cs 项目: vaginessa/open
 private void pdf_to_txt(save_progress progress, System.Windows.Forms.Form dlg, string fileType)
 {
     try
     {
         Aspose.Pdf.Document document = null;
         int num = 0;
         if (fileType == ".pdf")
         {
             document = this.pdf_doc;
             num      = 0;
         }
         else if ((fileType == ".doc") || (fileType == ".docx"))
         {
             document = this.doc_to_pdf(progress, dlg, 0);
             num      = 50;
         }
         else if ((fileType == ".xls") || (fileType == ".xlsx"))
         {
             document = this.xls_to_pdf(progress, dlg, 0);
             num      = 50;
         }
         else if ((fileType == ".ppt") || (fileType == ".pptx"))
         {
             document = this.ppt_to_pdf(progress, dlg, 0);
             num      = 50;
         }
         PdfExtractor extractor    = new PdfExtractor(document);
         FileStream   outputStream = new FileStream(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + this.get_suffix(), FileMode.Create);
         extractor.ExtractTextMode = 0;
         if (progress != null)
         {
             dlg.Invoke(progress, new object[] { num });
         }
         for (int i = 1; i <= document.Pages.Count; i++)
         {
             extractor.StartPage = i;
             extractor.EndPage   = i;
             extractor.ExtractText(Encoding.UTF8);
             extractor.GetText(outputStream);
             if (progress != null)
             {
                 if (num == 50)
                 {
                     dlg.Invoke(progress, new object[] { ((i * 50) / document.Pages.Count) + 50 });
                 }
                 else
                 {
                     dlg.Invoke(progress, new object[] { (i * 100) / document.Pages.Count });
                 }
             }
         }
         outputStream.Close();
     }
     catch (Exception)
     {
         return;
     }
     if (progress != null)
     {
         dlg.Invoke(progress, new object[] { 100 });
     }
 }
示例#41
0
 /// <summary>
 /// Invoke方式设置窗体的TopMost属性
 /// </summary>
 public static void InvokeTopMost(Form form, bool isTopMost)
 {
     if (form.InvokeRequired)
     {
         form.Invoke(new MethodInvoker(() => { InvokeTopMost(form, isTopMost); }));
     }
     else
     {
         form.TopMost = isTopMost;
     }
 }
示例#42
0
 public static void writeInterpolatedDataToB(Number[,,] data, DataGridView table, int originX, int originY, int originZ, Form callForm)
 {
     for (int i = 0; i < table.Rows.Count - 1; i++)
     {
         int x = Convert.ToInt32(table.Rows[i].Cells[0].Value) - originX;
         int y = Convert.ToInt32(table.Rows[i].Cells[1].Value) - originY;
         int z = Convert.ToInt32(table.Rows[i].Cells[2].Value) - originZ;
         if ((x >= data.GetLength(0)) || (y >= data.GetLength(1)) || (z >= data.GetLength(2))
             || (x < 0) || (y < 0) || (z < 0))
         {
             callForm.Invoke(new ThreadStart(delegate
             {
                 table.Rows[i].Cells[3].Value = "#Index out of bounds";
                 table.Rows[i].Cells[4].Value = "#Index out of bounds";
                 table.Rows[i].Cells[5].Value = "#Index out of bounds";
             }));
         }
         else
         {
             callForm.Invoke(new ThreadStart(delegate
             {
                 table.Rows[i].Cells[3].Value = data[x, y, z].x;
                 table.Rows[i].Cells[4].Value = data[x, y, z].y;
                 table.Rows[i].Cells[5].Value = data[x, y, z].z;
             }));
         }
     }
 }
示例#43
0
 private void SetDropAllowed(Form form, bool allowDrop)
 {
     if(form.InvokeRequired)
     {
         form.Invoke(new Action<Form, bool>(SetDropAllowed), new object[] { form, allowDrop });
     }
     else
     {
         form.AllowDrop = allowDrop;
     }
 }
示例#44
0
文件: Convert.cs 项目: vaginessa/open
        private void pdf_to_epub(save_progress progress, System.Windows.Forms.Form dlg, int c)
        {
            try
            {
                Pdf          pdf;
                ListViewItem item;
                string       text;
                Aspose.Pdf.Generator.Section section;
                Aspose.Pdf.Generator.Image   image;
                string str4;
                string extension;
                if (progress != null)
                {
                    dlg.Invoke(progress, new object[] { 0 });
                }
                string str = new ini_config("config.ini").read_ini("isMerger", "App");
                ListView.ListViewItemCollection items = null;
                int num = 0;
                if (dlg.Name == "mainDlg")
                {
                    items = ((mainDlg)dlg).lstFile.Items;
                    num   = 0;
                }
                else
                {
                    items = ((mainDlg_A)dlg).lstFile.Items;
                    num   = 1;
                }
                if (str == "1")
                {
                    if (c == (items.Count - 1))
                    {
                        pdf = new Pdf();
                        for (int i = 0; i < items.Count; i++)
                        {
                            item    = items[i];
                            text    = item.SubItems[num].Text;
                            section = pdf.Sections.Add();
                            image   = new Aspose.Pdf.Generator.Image(section);
                            section.Paragraphs.Add(image);
                            image.ImageInfo.File = text;
                            extension            = Path.GetExtension(text);
                            if (extension == null)
                            {
                                goto Label_01C8;
                            }
                            if (!(extension == ".jpg"))
                            {
                                if (extension == ".gif")
                                {
                                    goto Label_0188;
                                }
                                if (extension == ".bmp")
                                {
                                    goto Label_0198;
                                }
                                if (extension == ".png")
                                {
                                    goto Label_01A8;
                                }
                                if (extension == ".tiff")
                                {
                                    goto Label_01B8;
                                }
                                goto Label_01C8;
                            }
                            image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg;
                            continue;
Label_0188:
                            image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Gif;
                            continue;
Label_0198:
                            image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Bmp;
                            continue;
Label_01A8:
                            image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Png;
                            continue;
Label_01B8:
                            image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Tiff;
                            continue;
Label_01C8:
                            image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg;
                        }
                        str4 = this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + this.get_suffix();
                        pdf.Save(str4);
                    }
                    goto Label_0366;
                }
                pdf     = new Pdf();
                item    = items[c];
                text    = item.SubItems[num].Text;
                section = pdf.Sections.Add();
                image   = new Aspose.Pdf.Generator.Image(section);
                section.Paragraphs.Add(image);
                image.ImageInfo.File = text;
                extension            = Path.GetExtension(text);
                if (extension == null)
                {
                    goto Label_0329;
                }
                if (!(extension == ".jpg"))
                {
                    if (extension == ".gif")
                    {
                        goto Label_02E9;
                    }
                    if (extension == ".bmp")
                    {
                        goto Label_02F9;
                    }
                    if (extension == ".png")
                    {
                        goto Label_0309;
                    }
                    if (extension == ".tiff")
                    {
                        goto Label_0319;
                    }
                    goto Label_0329;
                }
                image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg;
                goto Label_0339;
Label_02E9:
                image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Gif;
                goto Label_0339;
Label_02F9:
                image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Bmp;
                goto Label_0339;
Label_0309:
                image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Png;
                goto Label_0339;
Label_0319:
                image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Tiff;
                goto Label_0339;
Label_0329:
                image.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg;
Label_0339:
                str4 = this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + this.get_suffix();
                pdf.Save(str4);
Label_0366:
                if (progress != null)
                {
                    dlg.Invoke(progress, new object[] { 100 });
                }
            }
            catch (Exception)
            {
            }
        }
 public static void CloseForm(Form form)
 {
     if (form.InvokeRequired)
         form.Invoke(new CloseFormDelegate(CloseForm), new object[] { form });
     else
         form.Close();
 }
示例#46
0
        // Packet Receive
        private void Receive_Completed(object sender, SocketAsyncEventArgs e)
        {
            Socket ClientSocket = (Socket)sender;

            if (ClientSocket.Connected && e.BytesTransferred > 0)
            {
                byte[] szData2 = e.Buffer;
                e.SetBuffer(szData2, 0, szData2.Length);
                string sDatas = Encoding.Unicode.GetString(szData2);
                String sData  = sDatas;

                // # Packet Handling #
                try
                {
                    string[] co      = { "&%*^%" };
                    string[] dcodata = sData.Split(co, StringSplitOptions.RemoveEmptyEntries);

                    sData = dcodata[0];
                    string pkcode = dcodata[1];

                    #region Login

                    if (pkcode.Equals("UD"))
                    {
                        string[] spear = { "," };
                        string[] words = sData.Split(spear, StringSplitOptions.RemoveEmptyEntries);

                        // # 계정 데이터 획득 #
                        Properties.Settings.Default.UserId       = words[0];
                        Properties.Settings.Default.MapId        = Int32.Parse(words[1]);
                        Properties.Settings.Default.Actor_x      = Int32.Parse(words[2]);
                        Properties.Settings.Default.Actor_y      = Int32.Parse(words[3]);
                        Properties.Settings.Default.Actor_sprite = words[4];

                        Properties.Settings.Default.LoginCheck = true;

                        // get interface and user data
                        GetActorData();

                        // exit login form
                        Mainform.Invoke(new MethodInvoker(
                                            delegate()
                        {
                            Form_Login.Dispose();
                        }
                                            )
                                        );
                    }
                    else if (pkcode.Equals("LoginFail"))
                    {
                        ShowMessage("비밀번호를 확인해 주세요!");
                    }
                    else if (pkcode.Equals("LoginAlready"))
                    {
                        ShowMessage("현재 접속중인 계정입니다.");
                    }

                    #endregion

                    #region [Game Systems]

                    if (Properties.Settings.Default.LoginCheck)
                    {
                        // receive all chat

                        #region Chat systems

                        if (pkcode.Equals("AllChat"))
                        {
                            // update chat
                            Mainform.Invoke(new MethodInvoker(
                                                delegate()
                            {
                                // auto initializ chat data
                                try
                                {
                                    if (Form_Chat.panel1.VerticalScroll.Maximum >= 17000) // overall 17,000 - renew
                                    {
                                        Form_Chat.Dispose();
                                        Form_Chat = new Forms.Chatting();
                                        Form_Chat.Show();
                                        Form_Chat.Location = new System.Drawing.Point(Mainform.Location.X + 3, Mainform.Location.Y + Mainform.Height - 131);
                                    }
                                }
                                catch { }

                                // show up a new chat
                                Chatwrite(sData);

                                // receive other player's a new ballon
                                string[] spear = { " : " };
                                string[] words = sData.Split(spear, StringSplitOptions.RemoveEmptyEntries);

                                if (!words[0].Equals(Properties.Settings.Default.UserId))
                                {
                                    for (int i = 0; i < Users.Count; i++)
                                    {
                                        if (Users[i].username.Equals(words[0]))
                                        {
                                            if (Users[i].chatballon != null)
                                            {
                                                Users[i].chatballon.Dispose();
                                            }

                                            Users[i].chatballon = new Forms.ChatBallon(sData);
                                            Users[i].chatballon.Show();
                                        }
                                    }
                                }
                            }
                                                )
                                            );
                        }

                        #endregion

                        // drwaing other players

                        #region user map drawing

                        // drawing a new user
                        else if (pkcode.Equals("Mapres"))
                        {
                            string[] spear     = { "," };
                            string[] words     = sData.Split(spear, StringSplitOptions.RemoveEmptyEntries);
                            bool     isalready = false;

                            // check a player is already exist
                            for (int i = 0; i < Users.Count; i++)
                            {
                                if (Users[i].username.Equals(words[0]))
                                {
                                    isalready = true;
                                }
                            }

                            // if a new player, drawing start
                            if (!isalready && !words[0].Equals(Properties.Settings.Default.UserId) && Int32.Parse(words[1]) == Properties.Settings.Default.MapId)
                            {
                                Mainform.Invoke(new MethodInvoker(
                                                    delegate()
                                {
                                    Classes.OtherUser user = new Classes.OtherUser(words[0], Int32.Parse(words[1]), Int32.Parse(words[2]), Int32.Parse(words[3]), Content.Load <Texture2D>("Sprites\\" + words[4]));
                                    Users.Add(user);
                                }
                                                    )
                                                );
                            }

                            // get other player's position information - used dead reckoning
                            if (keyboardVal)
                            {
                                Send_Packet(
                                    Properties.Settings.Default.UserId + "," +
                                    Properties.Settings.Default.MapId + "," +
                                    Properties.Settings.Default.Actor_x + "," +
                                    Properties.Settings.Default.Actor_y + "," +
                                    Properties.Settings.Default.Actor_sprite + "," +
                                    Actor_activepo.X + "," +
                                    Actor_activepo.Y +
                                    ",&%*^%I+ZWQgko0LYrbcrYuZas5Q==&%*^%");
                            }
                        }

                        // remove a left user
                        else if (pkcode.Equals("MapExit"))
                        {
                            string[] spear = { "," };
                            string[] words = sData.Split(spear, StringSplitOptions.RemoveEmptyEntries);

                            if (Properties.Settings.Default.MapId == Int32.Parse(words[1]))
                            {
                                for (int i = 0; i < Users.Count; i++)
                                {
                                    if (Users[i].username.Equals(words[0]))
                                    {
                                        Mainform.Invoke(new MethodInvoker(
                                                            delegate()
                                        {
                                            Users[i].clear();
                                            Users.Remove(Users[i]);
                                        }
                                                            )
                                                        );
                                        break;
                                    }
                                }
                            }
                        }

                        // update other players position
                        else if (pkcode.Equals("UserMove"))
                        {
                            string[] spear   = { "," };
                            string[] words   = sData.Split(spear, StringSplitOptions.RemoveEmptyEntries);
                            bool     isexist = false;

                            for (int i = 0; i < Users.Count; i++)
                            {
                                if (Users[i].username.Equals(words[0]))
                                {
                                    Mainform.Invoke(new MethodInvoker(
                                                        delegate()
                                    {
                                        // 현재 좌표의 갱신과 움직임 설정
                                        Users[i].actor_x = Int32.Parse(words[1]);
                                        Users[i].actor_y = Int32.Parse(words[2]);
                                        Users[i].UserMove(Int32.Parse(words[4]));
                                        isexist = true;
                                    }
                                                        )
                                                    );
                                    break;
                                }
                            }

                            if (isexist == false) // if got user information failed, re-draw a new player
                            {
                                // draw a new player
                                if (!words[0].Equals(Properties.Settings.Default.UserId) && Int32.Parse(words[1]) == Properties.Settings.Default.MapId)
                                {
                                    Mainform.Invoke(new MethodInvoker(
                                                        delegate()
                                    {
                                        Classes.OtherUser user = new Classes.OtherUser(words[0], Int32.Parse(words[1]), Int32.Parse(words[2]), Int32.Parse(words[3]), Content.Load <Texture2D>("Sprites\\" + words[4]));
                                        Users.Add(user);
                                    }
                                                        )
                                                    );
                                }
                            }
                        }

                        // User
                        else if (pkcode.Equals("MoveStop"))
                        {
                            string[] spear = { "," };
                            string[] words = sData.Split(spear, StringSplitOptions.RemoveEmptyEntries);

                            for (int i = 0; i < Users.Count; i++)
                            {
                                if (Users[i].username.Equals(words[0]))
                                {
                                    Mainform.Invoke(new MethodInvoker(
                                                        delegate()
                                    {
                                        Users[i].UserStop();
                                    }
                                                        )
                                                    );
                                    break;
                                }
                            }
                        }

                        #endregion
                    }
                }
                catch { }

                #endregion

                // reactive chat form
                if (Properties.Settings.Default.chat_activated)
                {
                    Mainform.Invoke(new MethodInvoker(
                                        delegate()
                    {
                        Form_Chat.Activate();
                    }
                                        )
                                    );
                }

                // flush buffer and get start async receive mode
                szData2 = new byte[szData2.Length];
                e.SetBuffer(szData2, 0, szData2.Length);
                ClientSocket.ReceiveAsync(e);
            }
        }
示例#47
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if (MouseXLoc > Width - 30 && MouseXLoc < Width && MouseYLoc < 26)
            {
                if (_AllowClose)
                {
                    if (_FormOrWhole == __FormOrWhole.Form)
                    {
                        if (_Form == null)
                        {
                            Environment.Exit(0);
                        }
                        else
                        {
                            if (_Form.InvokeRequired)
                            {
                                _Form.Invoke(new _InvokeForm(OnMouseDown), e);
                            }
                            else
                            {
                                _Form.Close();
                            }
                        }
                    }
                    else
                    {
                        Environment.Exit(0);
                    }
                }
            }
            else if (MouseXLoc > Width - 60 && MouseXLoc < Width - 30 && MouseYLoc < 26)
            {
                if (_AllowMaximize)
                {
                    switch (FindForm().WindowState)
                    {
                    case FormWindowState.Maximized:
                        FindForm().WindowState = FormWindowState.Normal;
                        break;

                    case FormWindowState.Normal:
                        FindForm().WindowState = FormWindowState.Maximized;
                        break;
                    }
                }
            }
            else if (MouseXLoc > Width - 90 && MouseXLoc < Width - 60 && MouseYLoc < 26)
            {
                if (_AllowMinimize)
                {
                    switch (FindForm().WindowState)
                    {
                    case FormWindowState.Normal:
                        FindForm().WindowState = FormWindowState.Minimized;
                        break;

                    case FormWindowState.Maximized:
                        FindForm().WindowState = FormWindowState.Minimized;
                        break;
                    }
                }
            }
            else if (e.Button == MouseButtons.Left && (new Rectangle(0, 0, Width - 90, MoveHeight)).Contains(e.Location))
            {
                CaptureMovement = true;
                MouseP          = e.Location;
            }
            else if (e.Button == MouseButtons.Left && (new Rectangle(Width - 90, 22, 75, 13)).Contains(e.Location))
            {
                CaptureMovement = true;
                MouseP          = e.Location;
            }
            else if (e.Button == MouseButtons.Left && (new Rectangle(Width - 15, 0, 15, MoveHeight)).Contains(e.Location))
            {
                CaptureMovement = true;
                MouseP          = e.Location;
            }
            else
            {
                Focus();
            }
            State = MouseState.Down;
            Invalidate();
        }
示例#48
0
文件: Convert.cs 项目: vaginessa/open
 private void pdf_to_img(save_progress progress, System.Windows.Forms.Form dlg, string fileType)
 {
     try
     {
         Aspose.Pdf.Document document = null;
         int num = 0;
         if (fileType == ".pdf")
         {
             document = this.pdf_doc;
             num      = 0;
         }
         else if ((fileType == ".doc") || (fileType == ".docx"))
         {
             document = this.doc_to_pdf(progress, dlg, 0);
             num      = 50;
         }
         else if ((fileType == ".xls") || (fileType == ".xlsx"))
         {
             document = this.xls_to_pdf(progress, dlg, 0);
             num      = 50;
         }
         else if ((fileType == ".ppt") || (fileType == ".pptx"))
         {
             document = this.ppt_to_pdf(progress, dlg, 0);
             num      = 50;
         }
         if (document != null)
         {
             try
             {
                 JpegDevice device = new JpegDevice(new Resolution(300), 100);
                 if (progress != null)
                 {
                     dlg.Invoke(progress, new object[] { num });
                 }
                 for (int i = 1; i <= document.Pages.Count; i++)
                 {
                     device.Process(document.Pages[i], this.global_config.target_dic + i.ToString() + this.get_suffix());
                     if (progress != null)
                     {
                         if (num == 50)
                         {
                             dlg.Invoke(progress, new object[] { ((i * 50) / document.Pages.Count) + 50 });
                         }
                         else
                         {
                             dlg.Invoke(progress, new object[] { (i * 100) / document.Pages.Count });
                         }
                     }
                 }
             }
             catch (Exception)
             {
                 return;
             }
             if (progress != null)
             {
                 dlg.Invoke(progress, new object[] { 100 });
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#49
0
文件: Convert.cs 项目: vaginessa/open
 private void pdf_to_ppt(save_progress progress, System.Windows.Forms.Form dlg, string fileType)
 {
     try
     {
         Aspose.Pdf.Document document = null;
         int num = 0;
         if (fileType == ".pdf")
         {
             document = this.pdf_doc;
             num      = 0;
         }
         else if ((fileType == ".doc") || (fileType == ".docx"))
         {
             document = this.doc_to_pdf(progress, dlg, 0);
             num      = 50;
         }
         else if ((fileType == ".xls") || (fileType == ".xlsx"))
         {
             document = this.xls_to_pdf(progress, dlg, 0);
             num      = 50;
         }
         Presentation presentation = new Presentation();
         JpegDevice   device       = new JpegDevice(new Resolution(300), 100);
         if (progress != null)
         {
             dlg.Invoke(progress, new object[] { num });
         }
         int num3 = 0;
         for (int i = 1; num3 < document.Pages.Count; i++)
         {
             presentation.Slides.AddEmptySlide(presentation.LayoutSlides[0]);
             presentation.Slides[num3].Shapes.AddAutoShape(Aspose.Slides.ShapeType.Rectangle, 10f, 20f, (float)this.global_config.pic_width, (float)this.global_config.pic_height);
             int num2 = presentation.Slides[num3].Shapes.Count - 1;
             presentation.Slides[num3].Shapes[num2].FillFormat.FillType = FillType.Picture;
             presentation.Slides[num3].Shapes[num2].FillFormat.PictureFillFormat.PictureFillMode = PictureFillMode.Stretch;
             MemoryStream output = new MemoryStream();
             device.Process(document.Pages[i], output);
             IPPImage image = presentation.Images.AddImage(new Bitmap(output));
             presentation.Slides[num3].Shapes[num2].FillFormat.PictureFillFormat.Picture.Image = image;
             if (progress != null)
             {
                 if (num == 50)
                 {
                     dlg.Invoke(progress, new object[] { ((num3 * 50) / document.Pages.Count) + 50 });
                 }
                 else
                 {
                     dlg.Invoke(progress, new object[] { (num3 * 100) / document.Pages.Count });
                 }
             }
             num3++;
         }
         presentation.Save(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + this.get_suffix(), Aspose.Slides.Export.SaveFormat.Ppt);
     }
     catch (Exception)
     {
         return;
     }
     if (progress != null)
     {
         dlg.Invoke(progress, new object[] { 100 });
     }
 }
示例#50
0
文件: Convert.cs 项目: vaginessa/open
        private void pdf_to_html(save_progress progress, System.Windows.Forms.Form dlg, string fileType)
        {
            int num = 0;

            if (fileType == ".pdf")
            {
                num = 0;
            }
            else if ((fileType == ".doc") || (fileType == ".docx"))
            {
                this.pdf_doc = this.doc_to_pdf(progress, dlg, 0);
                num          = 50;
            }
            else if ((fileType == ".xls") || (fileType == ".xlsx"))
            {
                this.pdf_doc = this.xls_to_pdf(progress, dlg, 0);
                num          = 50;
            }
            else if ((fileType == ".ppt") || (fileType == ".pptx"))
            {
                this.pdf_doc = this.ppt_to_pdf(progress, dlg, 0);
                num          = 50;
            }
            new Thread(new ThreadStart(this.pdf_to_html_callback)).Start();
            int num2  = 1;
            int num3  = num2;
            int count = this.pdf_doc.Pages.Count;

            if (progress != null)
            {
                dlg.Invoke(progress, new object[] { num });
            }
            while (true)
            {
                bool flag2 = true;
                num3 = num2;
                try
                {
                    if ((Directory.GetFiles(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + "_files").Length != 0) || (Directory.GetFiles(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + "_files", "img_" + num2.ToString().PadLeft(2, '0') + ".*").Length != 0))
                    {
                        num2++;
                    }
                }
                catch
                {
                }
                if (num2 == count)
                {
                    if (progress != null)
                    {
                        try
                        {
                            bool flag = false;
                            goto Label_028D;
Label_0250:
                            if (Directory.GetFiles(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + "_files", "style.css").Length != 0)
                            {
                                flag = true;
                                goto Label_0292;
                            }
Label_028D:
                            flag2 = true;
                            goto Label_0250;
Label_0292:
                            if (flag)
                            {
                                dlg.Invoke(progress, new object[] { 100 });
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                    return;
                }
                if (progress != null)
                {
                    if (num == 50)
                    {
                        dlg.Invoke(progress, new object[] { ((num2 * 50) / count) + 50 });
                    }
                    else
                    {
                        dlg.Invoke(progress, new object[] { (num2 * 100) / count });
                    }
                }
                Thread.Sleep(30);
            }
        }
示例#51
0
        public static int ShowDialog(string title, Icon icon, string message, string[] buttons, int default_button, Form owner, bool? button_autosize = null, bool? no_duplicate = null)
        {
            owner = owner ?? Owner;
            if (owner == null || !owner.InvokeRequired)
                return show_dialog(title, icon, message, buttons, default_button, owner, button_autosize, no_duplicate);

            return (int)owner.Invoke(() =>
           {
               return show_dialog(title, icon, message, buttons, default_button, owner, button_autosize, no_duplicate);
           });
        }
        /*消息解析
         * */
        public int parseMsg()
        {
            try
            {
                switch (msgStruct.ID())
                {
                case protocol.GW_LOGIN_ACK:
                {
                    int res = 0;
                    //m_msg >> res;
                    if (res == (int)protocol.RET_OK)
                    {
                        //Console.WriteLine("登录成功");
                    }
                    else
                    {
                        MessageBox.Show("登录失败");
                    }
                }
                break;

                case protocol.GM_CHANNELLIST_ACK:
                {
                    //M_SDO.Notice notice = new M_SDO.Notice();
                    int  nChan    = 0;
                    byte bHasMore = 0;

                    nChan    = (int)msgStruct.ReadData(nChan, 4);
                    bHasMore = Convert.ToByte(msgStruct.ReadData(bHasMore, 1));
                    //Console.WriteLine("收到频道信息"+nChan+"个");
                    for (int i = 0; i < nChan; i++)
                    {
                        wPlanetID    = Convert.ToInt16(msgStruct.ReadData(wPlanetID, 2));
                        wChannelID   = Convert.ToInt16(msgStruct.ReadData(wChannelID, 2));
                        iLimitUser   = (int)msgStruct.ReadData(iLimitUser, 4);
                        iCurrentUser = (int)msgStruct.ReadData(iCurrentUser, 4);
                        ipaddr       = Convert.ToString(msgStruct.ReadData(ipaddr, 15));
                        iItemIndex   = i;

                        _form.Invoke(new EventHandler(ReLoadChannel1));
                        //this._listView.Invoke(new LoadChannel(ToLoadChannel));

                        // LoadChannel loadChannel = new LoadChannel(notice.ToLoadChannel);
                        // loadChannel(i, wPlanetID, wChannelID, iLimitUser, iCurrentUser, ipaddr, this._form);
                        //Console.WriteLine(wPlanetID+"/"+wChannelID+"/"+iLimitUser+"/"+iCurrentUser+"/");
                        //this._listView.Items.Add(wPlanetID.ToString() + "/" + wChannelID.ToString() + "/" + iLimitUser.ToString() + "/" + iCurrentUser.ToString() + "/" + ipaddr);
                        //this._listView.Items[i].Tag = wPlanetID.ToString() + "/" + wChannelID.ToString() + "/" + iLimitUser.ToString() + "/" + iCurrentUser.ToString() + "/" + ipaddr;
                        //Console.WriteLine(ipaddr);
                    }
                    Thread.CurrentThread.Abort();
                }
                break;

                case protocol.EH_ALIVE_REQ:
                {
                    msgStruct = new CMsg((short)protocol.EH_ALIVE_ACK);
                    send_msg(msgStruct);
                }
                break;

                default:
                    //Console.WriteLine("Unknown Message Received:"+msgStruct.ID());
                    break;
                    //////m_debugList.AddString(debugString);
                }
            }
            catch { }
            return(0);
        }