示例#1
0
        ///<summary>产生线路数据</summary>
        static void genline(DistNet dn)
        {
            foreach (DNACLineBase item in dn.getAllObjListByObjType(EObjectType.输电线路))
            {
                RunDataACLineBase rundata = item.busiRunData as RunDataACLineBase;
                AcntACLineBase    acnt    = item.busiAccount as AcntACLineBase;
                if (acnt.cap == 0)
                {
                    acnt.cap = rd.Next(50);
                }
                rundata.activePower = acnt.cap * (0.4 + 0.5 * rd.NextDouble());
                //rundata.powerFactor = 0.8 + 0.2 * rd.NextDouble();
                //rundata.apparentPower = rundata.activePower / rundata.powerFactor;
                rundata.reactivePower = Math.Sqrt(Math.Pow(rundata.apparentPower, 2) - Math.Pow(rundata.activePower, 2));
                //rundata.rateOfLoad = rundata.apparentPower / acnt.cap;

                if (rd.NextDouble() < 0.01)
                {
                    if (events.Count > 50)
                    {
                        events.Remove(events.Last());
                    }
                    events.Insert(0, new EventData()
                    {
                        eObjID = item.id, startTime = DateTime.Now, eType = (EventData.EEventType)rd.Next(2), eTitle = item.name + "事件.", eContent = DateTime.Now.ToShortDateString() + item.name + "事件描述......"
                    });
                }



                if (item is DNACLine)
                {
                    if (rundata.lstApparentPower.Count == 0) //初始模拟50条
                    {
                        for (int i = 50; i > 0; i--)
                        {
                            rundata.lstApparentPower.Add(new MyClassLibrary.DevShare.ChartDataPoint()
                            {
                                argudate = DateTime.Now.AddMinutes(i), value = acnt.cap * (0.4 + 0.5 * rd.NextDouble())
                            });
                        }
                    }
                    //rundata.addApparentPower(rundata.apparentPower);
                    rundata.refresh();
                }
            }
        }
示例#2
0
        internal bool AcceptFileTransfer(Socket socket, int port1, MainWindow mainWindow)
        {
            int             _port2;
            SocketException _socketException;

            if (!NetworkCommunicationManagers.ConnectToEndPoint(port1, socket.RemoteEndPoint.ToString().Remove(socket.RemoteEndPoint.ToString().LastIndexOf(':')), out dataSocket, out _socketException))
            {
                return(false);
            }

            NetworkCommunicationManagers.ReceiveIntOverSocket(dataSocket, out _port2);

            if (!NetworkCommunicationManagers.ConnectToEndPoint(_port2, socket.RemoteEndPoint.ToString().Remove(socket.RemoteEndPoint.ToString().LastIndexOf(':')), out controlSocket, out _socketException))
            {
                return(false);
            }

            fileTransferContainer.FileTransferClassInstance = this;

            byte[] _buffer = null;
            int    _temp;
            long   _size;
            string _filename;

            try {
                NetworkCommunicationManagers.ReceiveIntOverSocket(dataSocket, out _temp);
                NetworkCommunicationManagers.ReceiveByteArrayOverSocket(dataSocket, out _buffer, _temp);
            }
            catch (ObjectDisposedException) {
                NetworkCommunicationManagers.Disconnect(dataSocket);
                NetworkCommunicationManagers.Disconnect(controlSocket);
                return(false);
            }
            catch (SocketException) {
                NetworkCommunicationManagers.Disconnect(dataSocket);
                NetworkCommunicationManagers.Disconnect(controlSocket);
                return(false);
            }

            unpackFileMetadata(_buffer, out _filename, out _size);

            fileTransferContainer.fileName    = _filename;
            fileTransferContainer.sizeInBytes = _size;
            fileTransferContainer.size        = Converters.DataConverter.bytesToReadableString(_size);

            if (_size > mainWindow.maxAcceptedFileSizeWithoutConfirmation)
            {
                ManualResetEvent _replyRecieved           = new ManualResetEvent(false);
                System.Windows.MessageBoxResult _continue = System.Windows.MessageBoxResult.No;
                mainWindow.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() => {
                    Thread.Sleep(1000);
                    _continue = System.Windows.MessageBox.Show("Receive file \"" + _filename + "\" from " + socket.RemoteEndPoint.ToString().Remove(socket.RemoteEndPoint.ToString().LastIndexOf(':')) + " (Size: " + _size + " bytes)", "File Transfer", System.Windows.MessageBoxButton.YesNo);
                    _replyRecieved.Set();
                }));
                _replyRecieved.WaitOne();
                _replyRecieved.Dispose();
                if (_continue != System.Windows.MessageBoxResult.Yes)
                {
                    mainWindow.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() => {
                        lock (RunningTransfers) {
                            RunningTransfers.Remove(fileTransferContainer);
                        }
                    }));
                    NetworkCommunicationManagers.Disconnect(dataSocket);
                    NetworkCommunicationManagers.Disconnect(controlSocket);
                    return(false);
                }
            }

            if (!Directory.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads", "ChatApp")))
            {
                Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads", "ChatApp"));
            }
            ;

            string _filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads", "ChatApp", _filename);

            if (File.Exists(_filePath))
            {
                string _extension, _assignedFilename;
                if (_filename.LastIndexOf('.') == -1)
                {
                    _extension        = "";
                    _assignedFilename = _filename;
                }
                else
                {
                    _extension        = "." + _filename.Remove(0, _filename.LastIndexOf('.') + 1);
                    _assignedFilename = _filename.Remove(_filename.Length - _extension.Length, _extension.Length);
                }

                for (int i = 0; true; i++)
                {
                    _filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads", "ChatApp", _assignedFilename + "(" + i + ")" + _extension);
                    if (!File.Exists(_filePath))
                    {
                        break;
                    }
                }
            }

            fileTransferContainer.filePath = _filePath;

            return(managedReceiveFileOverSockets(_filePath, _size));
        }
示例#3
0
 private void Delete_Click(object sender, RoutedEventArgs e)
 {
     Views.UsersView user = (Views.UsersView)UsersDataGrid.SelectedItem;
     DatabaseConnector.DatabaseConnector.DeleteUser(user);
     bindingList.Remove(user);
 }