コード例 #1
0
            // Run the operation thread.
            public void BeginInvoke(String hostName)
            {
                try
                {
                    switch (operation)
                    {
                    case DnsOperation.GetHostByName:
                    {
                        acceptResult = Dns.GetHostByName(hostName);
                    }
                    break;

                    case DnsOperation.Resolve:
                    {
                        acceptResult = Dns.Resolve(hostName);
                    }
                    break;
                    }
                }
                catch (Exception e)
                {
                    // Save the exception to be thrown in EndXXX.
                    exception = e;
                }
                completed = true;
                if (callback != null)
                {
                    callback(this);
                }
                                #if ECMA_COMPAT
                SocketMethods.WaitHandleSet(waitHandle);
                                #else
                ((ManualResetEvent)waitHandle).Set();
                                #endif
            }
コード例 #2
0
ファイル: AccountVM.cs プロジェクト: Arxinos/Plutos
        /// <summary>
        /// Adds a new Account to the database
        /// </summary>
        private async Task NewAccount()
        {
            Account newAccount = new Account()
            {
                Name = NewAccountName, Description = NewAccountDescription, Amount = Convert.ToDouble(NewAccountAmount.Replace(',', '.'))
            };

            Task.Run(() => SocketMethods.CreateAccount(newAccount));
        }
コード例 #3
0
ファイル: SE_Booking.xaml.cs プロジェクト: Arxinos/Plutos
        private async void CreateTransaction(object sender, RoutedEventArgs e)
        {
            Windows.UI.Popups.MessageDialog mD = new Windows.UI.Popups.MessageDialog("Please select an expense type");

            string      command     = String.Empty;
            int         expenseType = -1;
            string      date        = HelperMethods.GetDate();
            Transaction transaction = null;

            if (TypeCB.SelectedIndex.Equals(1)) // User selected type expense
            {
                if (ExpenseTypeCB.SelectedItem != null)
                {
                    expenseType = ExpenseTypeCB.SelectedIndex;
                }
                else
                {
                    await mD.ShowAsync();

                    return;
                }
            }
            double tax = 0;

            switch (TaxCB.SelectedIndex)
            {
            case 0:
                tax = Convert.ToDouble(AmountTB.Text) * 0.1;     // 10%
                break;

            case 1:
                tax = Convert.ToDouble(AmountTB.Text) * 0.13;     // 13%
                break;

            case 2:
                tax = Convert.ToDouble(AmountTB.Text) * 0.20;     // 20%
                break;
            }
            transaction = new Transaction(DescrTB.Text, Convert.ToDouble(AmountTB.Text), date, expenseType, tax);
            string jsonObject = JsonConvert.SerializeObject(transaction);

            SocketMethods.ConnectToServer();
            SocketMethods.SendMessage($"8;{jsonObject}");
            SocketMethods.ReceiveMessage();


            if (SocketMethods.response.Equals(1))
            {
                MessageDialog md = new MessageDialog("Transaction failed");
                await md.ShowAsync();
            }
            SocketMethods.client.Shutdown(System.Net.Sockets.SocketShutdown.Both);
            SocketMethods.Disconnect();
        }
コード例 #4
0
 // Throw exception according to retval.
 // Timeout has value 0, otherwise it's generic IO exception.
 private void ThrowPortException(int retval)
 {
     if (retval == 0)
     {
         // TODO: throw System.ServiceProcess.TimeoutException
         throw new SystemException(S._("IO_Timeout"));
     }
     else
     {
         // This exception is not in docs but is useful
         Errno  errno   = SocketMethods.GetErrno();
         String message = SocketMethods.GetErrnoMessage(errno);
         throw new IOException(message);
     }
 }
コード例 #5
0
 // Constructor.
 public DnsAsyncResult(AsyncCallback callback, Object state,
                       DnsOperation operation)
 {
                     #if ECMA_COMPAT
     this.waitHandle = SocketMethods.CreateManualResetEvent();
                     #else
     this.waitHandle = new ManualResetEvent(false);
                     #endif
     this.completedSynchronously = false;
     this.completed    = false;
     this.operation    = operation;
     this.callback     = callback;
     this.state        = state;
     this.acceptResult = null;
     this.exception    = null;
 }
コード例 #6
0
ファイル: AccountVM.cs プロジェクト: Arxinos/Plutos
        public async Task DeleteAccount()
        {
            if (SelectedAccount == null)
            {
                md.Content = "No account selected";
                await md.ShowAsync();

                return;
            }
            SocketMethods.client = new Socket(SocketMethods.ipAddress.AddressFamily,
                                              SocketType.Stream, ProtocolType.Tcp);
            SocketMethods.ConnectToServer();
            SocketMethods.SendMessage($"6;{SelectedAccount.AccID}");
            SocketMethods.ReceiveMessage();
            SocketMethods.client.Shutdown(System.Net.Sockets.SocketShutdown.Both);
            SocketMethods.Disconnect();
            accounts.Remove(selectedAccount);
        }
コード例 #7
0
ファイル: Process.cs プロジェクト: ForNeVeR/pnet
        // Start a process.
        public bool Start()
        {
            ProcessStartInfo.ProcessStartFlags flags;

            // Validate the start information.
            if (startInfo == null || startInfo.FileName == String.Empty)
            {
                throw new InvalidOperationException
                          (S._("Invalid_ProcessStartInfo"));
            }
            flags = startInfo.flags;
            if ((flags & ProcessStartInfo.ProcessStartFlags.UseShellExecute)
                != 0)
            {
                if ((flags & (ProcessStartInfo.ProcessStartFlags
                              .RedirectStdin |
                              ProcessStartInfo.ProcessStartFlags
                              .RedirectStdout |
                              ProcessStartInfo.ProcessStartFlags
                              .RedirectStderr)) != 0)
                {
                    // Cannot redirect if using shell execution.
                    throw new InvalidOperationException
                              (S._("Invalid_ProcessStartInfo"));
                }
            }

            // Close the current process information, if any.
            Close();

            // If attempting to start using the current process,
            // then we want to do "execute over the top" instead,
            // replacing the current process with a new one.
            if (IsCurrentProcess(this))
            {
                flags |= ProcessStartInfo.ProcessStartFlags.ExecOverTop;
            }

            // Get the environment to use in the new process if it
            // was potentially modified by the programmer.
            String[] env = null;
            if (startInfo.envVars != null)
            {
                StringCollection      coll = new StringCollection();
                IDictionaryEnumerator e    =
                    (IDictionaryEnumerator)
                    (startInfo.envVars.GetEnumerator());
                while (e.MoveNext())
                {
                    coll.Add(((String)(e.Key)).ToUpper(CultureInfo.InvariantCulture) +
                             "=" + ((String)(e.Value)));
                }
                env = new String [coll.Count];
                coll.CopyTo(env, 0);
            }

            // Get the pathname of the program to be executed.
            String program;

            if (startInfo.UseShellExecute && startInfo.WorkingDirectory != String.Empty && !Path.IsPathRooted(startInfo.FileName))
            {
                program = Path.Combine(startInfo.WorkingDirectory, startInfo.FileName);
            }
            else
            {
                program = startInfo.FileName;
            }

            // Parse the arguments into a local argv array.
            String[] args = ProcessStartInfo.ArgumentsToArgV
                                (startInfo.Arguments);
            argv    = new String [args.Length + 1];
            argv[0] = program;
            Array.Copy(args, 0, argv, 1, args.Length);

            // Start the process.
            IntPtr stdinHandle;
            IntPtr stdoutHandle;
            IntPtr stderrHandle;

            if (!StartProcess(program, startInfo.Arguments, startInfo.WorkingDirectory, argv,
                              (int)flags, (int)(startInfo.WindowStyle),
                              env, startInfo.Verb,
                              startInfo.ErrorDialogParentHandle,
                              out processHandle, out processID,
                              out stdinHandle, out stdoutHandle,
                              out stderrHandle))
            {
                // Checking errno for error
                Errno errno = Process.GetErrno();
                if (errno != Errno.Success)
                {
                    throw new Win32Exception(Process.GetErrnoMessage(errno));
                }
            }

            // Wrap up the redirected I/O streams.
            if (stdinHandle != SocketMethods.GetInvalidHandle())
            {
                stdin = new StreamWriter
                            (new FileStream(stdinHandle, FileAccess.Write, true));
                stdin.AutoFlush = true;
            }
            if (stdoutHandle != SocketMethods.GetInvalidHandle())
            {
                stdout = new StreamReader
                             (new FileStream(stdoutHandle, FileAccess.Read, true));
            }
            if (stderrHandle != SocketMethods.GetInvalidHandle())
            {
                stderr = new StreamReader
                             (new FileStream(stderrHandle, FileAccess.Read, true));
            }

            // Add the process to the list of active children.
            lock (typeof(Process))
            {
                if (children == null)
                {
                    children = new ArrayList();
                }
                children.Add(this);
            }
            return(true);
        }
コード例 #8
0
ファイル: CompanyVM.cs プロジェクト: Arxinos/Plutos
 private async Task SetCompID()
 {
     App.compID = SelectedCompanyID;
     await Task.Run(() => SocketMethods.ChangeCompany());
 }
コード例 #9
0
ファイル: CompanyVM.cs プロジェクト: Arxinos/Plutos
        public async Task LoadCompanies()
        {
            await Task.Run(() => SocketMethods.GetData());

            Companies = SocketMethods.data.Companies;
        }