Example #1
0
        public string DropBoxUpload(string FileName)
        {
            try
            {
                NetCard.NetCard n = new NetCard.NetCard();
                m_clientIpAddress = n.getComputerIP();

                m_startSendingTime = DateTime.Now;
                string   res              = m_dropbox.Upload(FileName);
                DateTime endSendingTime   = DateTime.Now;
                TimeSpan TotalSendingTime = endSendingTime - m_startSendingTime;
                if (res == "ok")
                {
                    pCallback(633, m_clientIpAddress, FileName, FileName, TotalSendingTime.ToString(), 1, DateTime.Now, 0, m_userName);
                }
                else
                {
                    pCallback(533, m_clientIpAddress, FileName, FileName, "drop box failed: " + res, 1, DateTime.Now, 0, m_userName);
                }
                return(res);
            }
            catch (Exception err)
            {
                throw (new SystemException(err.Message));
            }
        }
Example #2
0
        public void OpenRepositoryStreamingClient(string ipAddress, string userName, string password)
        {
            try
            {
                NetCard.NetCard n = new NetCard.NetCard();
                m_clientIpAddress = n.getComputerIP();

                m_serverIpAddress       = ipAddress;
                m_userName              = userName;
                m_password              = password;
                m_connectedToFileServer = true;

                if (m_verbose)
                {
                    string msg = "OpenRepositoryStreamingClient: " + m_userName + " " + m_password;
                    pCallback(150, m_clientIpAddress, string.Empty, string.Empty, msg, 1, DateTime.Now, 0, m_userName);
                }

                if (m_thread == null || m_thread.IsAlive == false)
                {
                    m_thread = new Thread(CopyThread);
                    m_thread.Start();
                }
            }
            catch (Exception err)
            {
                throw (new SystemException(err.Message));
            }
        }
Example #3
0
        public void RunBoxInitialize()
        {
            try
            {
                NetCard.NetCard n = new NetCard.NetCard();
                m_clientIpAddress = n.getComputerIP();

                if (m_dropboxInitialized == false)
                {
                    Console.WriteLine("initializing dropbox..");
                    string res = m_dropbox.Initialize();
                    Console.WriteLine("done.. {0}", res);
                    pCallback(911, m_clientIpAddress, string.Empty, string.Empty, res, 1, DateTime.Now, 0, m_userName);
                    if (res != "ok")
                    {
                        return;
                    }
                }
                else
                {
                    pCallback(912, m_clientIpAddress, string.Empty, string.Empty, "Drop box already initialized", 1, DateTime.Now, 0, m_userName);
                }
                m_dropboxInitialized = true;
            }
            catch (Exception err)
            {
                throw (new SystemException(err.Message));
            }
        }
Example #4
0
 public service1()
 {
     NetCard.NetCard n = new NetCard.NetCard();
     m_ipAddress = n.getComputerIP();
     FileServerWinClient.CallbackMessage pCallback = new FileServerWinClient.CallbackMessage(CallbackMessage);
     m_fileServerClient.SetCallback(pCallback);
     m_fileServerClient.SetIpAddress(m_ipAddress);
 }
Example #5
0
 void WaitForIp()
 {
     while (m_running)
     {
         NetCard.NetCard n = new NetCard.NetCard();
         m_ipAddress = n.getComputerIP();
         if (m_ipAddress != "0.0.0.0")
         {
             OpenService();
             break;
         }
         Thread.Sleep(3000);
     }
 }
Example #6
0
 public int SyncFilesWithDataBase(string DirectoryToSync, bool recoursive, string userName, int SyncBy)
 {
     if (m_syncFileThread == null || m_syncFileThread.IsAlive == false)
     {
         m_syncFileThread = new Thread(() => SyncFileThread(DirectoryToSync, recoursive, userName, SyncBy));
         m_syncFileThread.Start();
         return(1);
     }
     else
     {
         NetCard.NetCard n = new NetCard.NetCard();
         m_clientIpAddress = n.getComputerIP();
         pCallback(133, m_clientIpAddress, "0", string.Empty, "0", 0, DateTime.Now, 0, m_FileOwnerUserName);
         return(0);
     }
 }
Example #7
0
        public string OpenTCPStreamingClient(string ipAddress, string userName, string password)
        {
            try
            {
                NetCard.NetCard n = new NetCard.NetCard();
                m_clientIpAddress = n.getComputerIP();

                m_serverIpAddress          = ipAddress;
                m_userName                 = userName;
                m_password                 = password;
                m_connectedToTcpFileServer = true;

                m_tcpStreamingClient = new
                                       FileStreamingClient(ipAddress,
                                                           5005,
                                                           m_fieldGuid,
                                                           userName,
                                                           password,
                                                           null);

                if (m_verbose)
                {
                    string msg = "OpenRepositoryStreamingClient: " + m_userName + " " + m_password;
                    pCallback(150, m_clientIpAddress, string.Empty, string.Empty, msg, 1, DateTime.Now, 0, m_userName);
                }

                if (m_thread == null || m_thread.IsAlive == false)
                {
                    m_thread = new Thread(CopyThread);
                    m_thread.Start();
                }
                return("ok");
            }
            catch (Exception err)
            {
                return(err.Message);
            }
        }
Example #8
0
        public void StartServer(int portNumber, bool reuse = true)
        {
            try
            {
                NetCard.NetCard n        = new NetCard.NetCard();
                string          serverIp = n.getComputerIP();

                serverSocket = new Socket(AddressFamily.InterNetwork,
                                          SocketType.Stream,
                                          ProtocolType.Tcp);

                IPAddress ipaddress = null;
                ipaddress = IPAddress.Parse(serverIp);


                //Assign the any IP of the machine and listen on port number 1000
                IPEndPoint ipEndPoint = new IPEndPoint(ipaddress, portNumber);
                m_serverAddress = ipaddress.ToString();
                if (reuse == true)
                {
                    serverSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
                }
                serverSocket.ReceiveBufferSize = m_receiveBufferSize;
                //Bind and listen on the given address
                serverSocket.Bind(ipEndPoint);
                serverSocket.Listen(4);
                m_portNumber = portNumber;

                //Accept the incoming clients
                serverSocket.BeginAccept(new AsyncCallback(OnAccept), null);
                m_serverConnected = true;
            }
            catch (Exception ex)
            {
                m_serverConnected = false;
                throw (new SystemException("SGSserverTCP: " + ex.Message));
            }
        }
Example #9
0
        void Initialize()
        {
            try
            {
                NetCard.NetCard n = new NetCard.NetCard();
                m_ipAddress = n.getComputerIP();
                while (m_ipAddress == "0.0.0.0")
                {
                    Thread.Sleep(10000);
                    m_ipAddress = n.getComputerIP();
                }
                File.WriteAllText("c:\\WCFStreamingClient.txt", "Initialized done: ip " + m_ipAddress);

                clsRegistry reg = new clsRegistry();
                m_fieldGuid = reg.GetStringValue(Registry.LocalMachine, "SOFTWARE\\Goji solutions\\Field", "Guid");
                if (reg.strRegError != null)
                {
                    m_fieldGuid = "error no guid";
                }

                FileServerWinClient.CallbackMessage pCallback = new FileServerWinClient.CallbackMessage(CallbackMessage);
                m_fileServerClient.SetCallback(pCallback);


                string strValue = reg.GetStringValue(
                    Registry.LocalMachine,
                    "SOFTWARE\\Goji solutions\\Field\\Watson",
                    "FileOwnerUserName");

                if (reg.strRegError == null)
                {
                    m_FileOwnerUserName = strValue;
                }
                else
                {
                    m_FileOwnerUserName = "******";
                }


                strValue = reg.GetStringValue(
                    Registry.LocalMachine,
                    "SOFTWARE\\Goji solutions\\Field\\Watson",
                    "WatsonStatus");
                if (reg.strRegError == null && strValue == "running")
                {
                    string userName;
                    userName = reg.GetStringValue(Registry.LocalMachine,
                                                  "SOFTWARE\\Goji solutions\\Field\\Watson",
                                                  "OperateUserName");

                    if (reg.strRegError != null)
                    {
                        pCallback(600, m_ipAddress, string.Empty, string.Empty, "Operator Owner does not exists", 0, DateTime.Now, 0, string.Empty);
                        return;
                    }

                    strValue = reg.GetStringValue(
                        Registry.LocalMachine,
                        "SOFTWARE\\Goji solutions\\Field\\Watson",
                        "StartWatchMonitorDirectory");
                    if (reg.strRegError == null)
                    {
                        if (Directory.Exists(strValue) == true)
                        {
                            m_fileServerClient.StartWatch(strValue, "*.bin", true, userName);
                        }
                    }
                }
            }
            catch (Exception err)
            {
                File.AppendAllText("c:\\GojiWCFStreamingClient.txt", err.Message);
            }
        }
Example #10
0
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == -1)
            {
                MessageBox.Show("please select upload type");
                return;
            }

            clsRegistry reg = new clsRegistry();

            m_baseGuid = reg.GetStringValue(Registry.LocalMachine, "SOFTWARE\\Goji solutions\\Base", "Guid");
            if (reg.strRegError != null)
            {
                m_baseGuid = Guid.NewGuid().ToString();
                reg.SetStringValue(Registry.LocalMachine, "SOFTWARE\\Goji solutions\\Base", "Guid", m_baseGuid);
            }
            string guid = m_client.GetClientGuid();

            NetCard.NetCard n      = new NetCard.NetCard();
            string          baseIp = n.getComputerIP();

            if (baseIp == "0.0.0.0")
            {
                string bip = reg.GetStringValue(Registry.LocalMachine, "SOFTWARE\\Goji solutions\\Base", "IpAddress");
                if (reg.strRegError == null)
                {
                    baseIp = bip;
                }
                else
                {
                    MessageBox.Show("You need to specify the base ip address in the registry");
                    return;
                }
            }

            if (checkBox1.Checked == true)
            {
                if (comboBox1.SelectedIndex == 0)
                {
                    try
                    {
                        Dictionary <string, string> storageDirectoryDic = new Dictionary <string, string>();
                        storageDirectoryDic.Add(guid, textBox3.Text);
                        GojiWCFStreamingBase.StartStorageServer(storageDirectoryDic);


                        if (SetCopyTimerEvent() == false)
                        {
                            return;
                        }
                        m_client.AddDateToUploadTargetFolder(checkBox8.Checked);
                        m_client.ConnectToStreamingServer(baseIp, textBox4.Text, textBox5.Text);
                        button14.Enabled = true;
                    }
                    catch (Exception err)
                    {
                        MessageBox.Show(err.Message);
                    }
                }
                else if (comboBox1.SelectedIndex == 1)
                {
                    try
                    {
                        string s = m_client.InitializeDropBox();
                        if (s != "ok")
                        {
                            MessageBox.Show(s);
                        }
                        else
                        {
                            m_client.StartDropBoxUploadMode(true);
                            button14.Enabled = true;
                        }
                    }
                    catch (Exception err)
                    {
                        MessageBox.Show(err.Message);
                    }
                }
                else if (comboBox1.SelectedIndex == 2)
                {
                    m_client.StartTCPStreamingServer(1024 * 1024 * 30, 5005);
                    m_client.OpenTCPStreamingClient(baseIp, textBox4.Text, textBox5.Text);
                }
                checkBox1.ForeColor = System.Drawing.Color.Green;
            }
            else
            {
                if (comboBox1.SelectedIndex == 0)
                {
                    m_client.CloseCopyThread();
                    while (m_client.IsCopyThreadIsAlive() == true)
                    {
                        Application.DoEvents();
                        Thread.Sleep(1000);
                    }
                }
                else
                {
                    try
                    {
                        m_client.StartDropBoxUploadMode(false);
                    }
                    catch (Exception err)
                    {
                        MessageBox.Show(err.Message);
                    }
                }
                checkBox1.ForeColor = System.Drawing.Color.Red;
            }
        }
Example #11
0
        public Form1()
        {
            m_running = true;
            InitializeComponent();
            label18.Text = m_totalFieldFiles.ToString();
            Control.CheckForIllegalCrossThreadCalls = false;

            groupBox3.Enabled = false;
            p  = new GojiWCFStreamingBase.ClientCallbackMessage(ClientCallbackMsg);
            p1 = new GojiWCFStreamingBase.ServerCallbackMessage(ServerCallbackMsg);
            GojiWCFStreamingBase.SetServerCallback = p1;
            m_client = new GojiWCFStreamingBase(p);

            textBox1.Text = Properties.Settings.Default.FieldIpAddress;
            textBox7.Text = Properties.Settings.Default.FieldComputerUserName;
            textBox6.Text = Properties.Settings.Default.FieldComputerPassword;

            textBox4.Text           = Properties.Settings.Default.StorageServerUserName;
            textBox5.Text           = Properties.Settings.Default.StorageServerPassword;
            textBox2.Text           = Properties.Settings.Default.FieldDirectoryToMinotor;
            textBox3.Text           = Properties.Settings.Default.StorageDirectoryToUpload;
            comboBox1.SelectedIndex = Properties.Settings.Default.UploadMode;
            textBox10.Text          = Properties.Settings.Default.DeleteAllUploadedFilesTimer;
            textBox12.Text          = Properties.Settings.Default.uploadWrongFilesDirectory;
            textBox13.Text          = Properties.Settings.Default.SyncDirectory;
            checkBox4.Checked       = Properties.Settings.Default.RecoursiveSync;
            textBox14.Text          = Properties.Settings.Default.OperatorUserName;
            checkBox6.Checked       = Properties.Settings.Default.OperationsByUser;
            button14.Enabled        = false;

            try
            {
                MapNetworkDrives();
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }


            NetCard.NetCard n      = new NetCard.NetCard();
            string          baseIp = n.getComputerIP();

            if (baseIp == "0.0.0.0")
            {
                clsRegistry reg = new clsRegistry();
                string      bip = reg.GetStringValue(Registry.LocalMachine, "SOFTWARE\\Goji solutions\\Base", "IpAddress");
                if (reg.strRegError == null)
                {
                    baseIp    = bip;
                    this.Text = "Goji Field uploaded managment " + baseIp;
                }
                else
                {
                    MessageBox.Show("You need to specify the base ip address in the registry");
                    GetManualIpAddress g = new GetManualIpAddress();
                    g.ShowDialog();
                    if (g.DialogResult == System.Windows.Forms.DialogResult.OK)
                    {
                        baseIp    = g.IpAddress;
                        this.Text = "Goji Field uploaded managment " + baseIp;
                        reg.SetStringValue(Registry.LocalMachine, "SOFTWARE\\Goji solutions\\Base", "IpAddress", baseIp);
                    }
                    return;
                }
            }
            else
            {
                this.Text = "Goji Field uploaded managment " + baseIp;
            }
        }
Example #12
0
        private void checkBox9_CheckedChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == -1)
            {
                MessageBox.Show("please select upload type");
                return;
            }
            if (checkBox1.Checked == true)
            {
                if (comboBox1.SelectedIndex == 0)
                {
                    try
                    {
                        clsRegistry reg = new clsRegistry();
                        m_baseGuid = reg.GetStringValue(Registry.LocalMachine, "SOFTWARE\\Goji solutions\\Base", "Guid");
                        if (reg.strRegError != null)
                        {
                            m_baseGuid = Guid.NewGuid().ToString();
                            reg.SetStringValue(Registry.LocalMachine, "SOFTWARE\\Goji solutions\\Base", "Guid", m_baseGuid);
                        }

                        string guid = m_client.GetClientGuid();
                        m_client.StartTCPStreamingServer(1024 * 1024 * 10, 5005);

                        NetCard.NetCard n      = new NetCard.NetCard();
                        string          baseIp = n.getComputerIP();
                        if (baseIp == "0.0.0.0")
                        {
                            string bip = reg.GetStringValue(Registry.LocalMachine, "SOFTWARE\\Goji solutions\\Base", "IpAddress");
                            if (reg.strRegError == null)
                            {
                                baseIp = bip;
                            }
                            else
                            {
                                MessageBox.Show("You need to specify the base ip address in the registry");
                                return;
                            }
                        }
                        if (SetCopyTimerEvent() == false)
                        {
                            return;
                        }
                        m_client.OpenTCPStreamingClient(baseIp, textBox4.Text, textBox5.Text);
                        button14.Enabled = true;
                    }
                    catch (Exception err)
                    {
                        MessageBox.Show(err.Message);
                    }
                }
                else
                {
                }
                checkBox1.ForeColor = System.Drawing.Color.Green;
            }
            else
            {
                checkBox1.ForeColor = System.Drawing.Color.Red;
            }
        }
Example #13
0
        static void Main(string[] args)
        {
            try
            {
                /*
                 * // test code for the queue...
                 * QueueBaseFileListWriter q = new QueueBaseFileListWriter(10, "writeList\\");
                 * QueueBaseFileListReader q1 = new QueueBaseFileListReader(10, "readList\\", "writeList\\");
                 * ulong listNum;
                 * ulong fileNumber;
                 * bool copyStatus;
                 * for (int i = 0; i < 20; i++)
                 * {
                 *  q.AddFile("eee");
                 *  Console.WriteLine(q1.GetFile(out listNum, out fileNumber, out copyStatus));
                 *  //q1.MarkAsSent();
                 * }
                 */
                _handler += new _EventHandler(Handler);
                SetConsoleCtrlHandler(_handler, true);

                int             port      = 8030;
                NetCard.NetCard n         = new NetCard.NetCard();
                string          ipaddress = n.getComputerIP();
                Console.WriteLine("Listening on ip address: " + ipaddress);
                // Create the url that is needed to specify where the service should be started
                urlService = "net.tcp://" + ipaddress + ":" + port + "/MyService";
                //host = new ServiceHost(typeof(ServiceLibrary.service1));
                host = new ServiceHost(m_Instance, new Uri(urlService));

                host.Opening += new EventHandler(host_Opening);
                host.Opened  += new EventHandler(host_Opened);
                host.Closing += new EventHandler(host_Closing);
                host.Closed  += new EventHandler(host_Closed);

                // The binding is where we can choose what
                // transport layer we want to use. HTTP, TCP ect.
                NetTcpBinding tcpBinding = new NetTcpBinding();
                tcpBinding.TransactionFlow = false;
                tcpBinding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign;

                int x = tcpBinding.MaxConnections;
                tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;


                //tcpBinding.ReceiveTimeout = new TimeSpan(0, 0, 5);
                tcpBinding.SendTimeout   = new TimeSpan(0, 0, 5);
                tcpBinding.OpenTimeout   = new TimeSpan(0, 0, 10);
                tcpBinding.CloseTimeout  = new TimeSpan(0, 0, 2);
                tcpBinding.Security.Mode = SecurityMode.Transport;
                // <- Very crucial

                // Add a endpoint
                host.AddServiceEndpoint(typeof(ServiceLibrary.IService), tcpBinding, urlService);

                // A channel to describe the service.
                // Used with the proxy scvutil.exe tool
                ServiceMetadataBehavior metadataBehavior;
                metadataBehavior =
                    host.Description.Behaviors.Find <ServiceMetadataBehavior>();
                if (metadataBehavior == null)
                {
                    // This is how I create the proxy object
                    // that is generated via the svcutil.exe tool
                    metadataBehavior                = new ServiceMetadataBehavior();
                    metadataBehavior.HttpGetUrl     = new Uri("http://" + ipaddress + ":" + (port + 1) + "/MyService");
                    metadataBehavior.HttpGetEnabled = true;
                    metadataBehavior.ToString();
                    host.Description.Behaviors.Add(metadataBehavior);
                    urlMeta = metadataBehavior.HttpGetUrl.ToString();
                }

                host.Open();
                m_open = true;
                Console.WriteLine("WCF Streaming Client on field Service is opened");
                Console.ReadLine();
                (m_Instance as ServiceLibrary.service1).CloseService();
                host.Close();
                m_open = false;
            }
            catch (Exception err)
            {
                throw (new SystemException(err.Message));
            }
        }