Esempio n. 1
0
        FileRepositoryServiceClient ConnectFileRepositoryServer()
        {
            FileRepositoryServiceClient client;
            var myEndpointAddress = new EndpointAddress("http://" + m_serverIpAddress + ":5000");

            client = new FileRepositoryServiceClient("FileRepositoryService", myEndpointAddress);

            if (m_userName != string.Empty && m_password != string.Empty)
            {
                client.ClientCredentials.Windows.ClientCredential.UserName = m_userName;
                client.ClientCredentials.Windows.ClientCredential.Password = m_password;
                client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.PeerOrChainTrust;
            }
            return(client);
        }
        public void Connect(string ipAddress, string userName = "", string Password = "")
        {
            try
            {
                if (m_client == null)
                {
                    int           port    = 5000;
                    NetTcpBinding binding = new NetTcpBinding();

                    binding.SendTimeout    = new TimeSpan(0, 0, 15); // 1 hour
                    binding.OpenTimeout    = new TimeSpan(0, 0, 15); // 1 hour
                    binding.ReceiveTimeout = new TimeSpan(0, 0, 15); // 1 hour

                    // Disable credential negotiation and establishment of the
                    // security context.
                    //binding.Security.Message.ClientCredentialType = MessageCredentialType.None;

                    binding.TransferMode  = TransferMode.Streamed;
                    binding.Security.Mode = SecurityMode.None;
                    binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
                    binding.Security.Transport.ProtectionLevel      = System.Net.Security.ProtectionLevel.None;
                    var myEndpointAddress = new EndpointAddress("net.tcp://" + ipAddress + ":" + port);
                    m_client = new FileRepositoryServiceClient("FileRepositoryService", myEndpointAddress);

                    if ((userName == string.Empty) || (Password == string.Empty))
                    {
                        Console.WriteLine("Assume computer are in the domain");
                    }
                    else
                    {
                        m_client.ClientCredentials.Windows.ClientCredential.UserName = userName; // "IND-MPFM2\\Incteam";
                        m_client.ClientCredentials.Windows.ClientCredential.Password = Password; // "Bator23";
                        m_client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.PeerOrChainTrust;
                    }
                    m_connectedToFileServer = true;
                }
            }
            catch (Exception err)
            {
                m_connectedToFileServer = false;
                throw (new SystemException(err.Message));
            }
        }
 public void Close()
 {
     try
     {
         while (m_queue.Count > 0)
         {
             UploadFileToServerWithPath(m_queue.Dequeue());
         }
         if (m_client != null)
         {
             m_client.Close();
         }
         m_client = null;
         m_connectedToFileServer = false;
         StopWatch();
     }
     catch (Exception err)
     {
         throw (new SystemException(err.Message));
     }
 }
Esempio n. 4
0
        private void UploadFileToServerWithPath(string FileName, DateTime startTimeToSend, ulong listNum, ulong fileNumber, ulong g360Index, string fileOwnerUserName, DateTime wtsDateTime)
        {
            string virtualPath = Path.GetFileName(FileName);

            string[] path       = SplitPath(Path.GetDirectoryName(FileName));
            string   targetPath = string.Empty;

            for (int i = 2; i < path.Length; i++)
            {
                targetPath += path[i] + "\\";
            }

            if (File.Exists(FileName) == false)
            {
                q1.MarkAsSent();
                m_event.Set();
                m_retryEvent.Set();
                return;
            }

            using (Stream uploadStream = new FileStream(FileName, FileMode.Open))
            {
                try
                {
                    if (m_client != null && keepStorageClientConnectionOpen == false)
                    {
                        m_client.Close();
                        m_client = null;
                    }
                    Console.WriteLine("Connect to repository..");

                    m_currentUploadedFile = string.Empty;
                    string strstartDate = DateTime.Now.AddYears(-10).ToString(FMT);
                    m_currentUploadedDate        = strstartDate;
                    m_currentUploadedG360Index   = 0;
                    m_currentUploadedFileOwner   = string.Empty;
                    m_currentUploadedVirtualPath = string.Empty;
                    m_currentUploadedTargetPath  = string.Empty;


                    if (m_verbose)
                    {
                        string msg = "Trying to connect to respository server..";
                        pCallback(150, m_clientIpAddress, string.Empty, string.Empty, msg, 1, DateTime.Now, 0, fileOwnerUserName);
                    }

                    if (m_client == null)
                    {
                        m_client = ConnectFileRepositoryServer();
                    }
                    Console.WriteLine("Connection done, uploading file: " + FileName);
                    m_uploadInProgress = true;
                    DateTime startSendingTime = DateTime.Now;


                    m_currentUploadedFile        = FileName;
                    strstartDate                 = DateTime.Now.ToString(FMT);
                    m_currentUploadedDate        = strstartDate;
                    m_currentUploadedG360Index   = g360Index;
                    m_currentUploadedFileOwner   = fileOwnerUserName;
                    m_currentUploadedVirtualPath = virtualPath;
                    m_currentUploadedTargetPath  = targetPath;


                    if (m_verbose)
                    {
                        string msg = "Connnected to repository , uploading file " + FileName + " (" + g360Index + ")";
                        Console.WriteLine(msg);
                        pCallback(155,
                                  m_clientIpAddress,
                                  string.Empty,
                                  string.Empty,
                                  _GetCurrentUploadedFileInfo(),
                                  1,
                                  DateTime.Now,
                                  0,
                                  fileOwnerUserName);
                    }

                    // Create new FileInfo object and get the Length.
                    FileInfo f = new FileInfo(m_currentUploadedFile);
                    m_currentSizeOfFile = f.Length;

                    m_client.PutFileWithPath(new FileUploadMessage()
                    {
                        VirtualPath           = virtualPath,
                        TargetPath            = targetPath,
                        DataStream            = uploadStream,
                        startTime             = startTimeToSend,
                        clientIpAddress       = m_clientIpAddress,
                        fieldGuid             = m_fieldGuid,
                        G360Index             = g360Index,
                        _fileOwnerUserName    = fileOwnerUserName,
                        AddDateToTargetFolder = m_addDateToTargetFolder,
                        watsonDateTime        = wtsDateTime,
                        SizeOfFile            = f.Length
                    });

                    m_readyToSendNextFile.WaitOne(10000);
                }
                catch (Exception err)
                {
                    m_uploadInProgress = false;
                    Console.WriteLine(err.Message);
                    pCallback(200, m_clientIpAddress, FileName, virtualPath, err.Message, 1, DateTime.Now, 0, fileOwnerUserName);
                    m_uploadErrorStatus = err.Message;
                    m_uploadErrorCount++;
                    if (m_client != null)
                    {
                        m_client.Close();
                        m_client = null;
                    }
                }
            }
        }