Exemplo n.º 1
0
        public List <IndexFile> LoadData(string fileName, string indexfilepath)
        {
            string           file;
            List <IndexFile> indexfiles = new List <IndexFile>();

            if (Directory.Exists(indexfilepath))
            {
                int fileCount = Directory.GetFiles(indexfilepath, "*", SearchOption.TopDirectoryOnly).Length;
                if (fileCount < 1)
                {
                    return(null);
                }
                for (int i = 0; i < fileCount; i++)
                {
                    file = indexfilepath + fileName + i;
                    if (File.Exists(file))
                    {
                        logger.Add($"Reading index from file: {file}......");
                        var        startTime = DateTime.Now;
                        IFormatter formatter = new BinaryFormatter();
                        Stream     stream    = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read);
                        indexfiles.AddRange((List <IndexFile>)formatter.Deserialize(stream));
                        stream.Close();
                        logger.Add($"Files in index: {indexfiles.Count} in {(DateTime.Now-startTime).TotalMilliseconds}");
                    }
                }

                indexfiles.RemoveAll(item => item == null);
                return(indexfiles);
            }
            logger.Add("No indexFiles found on disk.");
            return(null);
        }
Exemplo n.º 2
0
 public override void Validate(string userName, string password)
 {
     if (null == userName || null == password)
     {
         log.Add("Connection using empty username or password");
         throw new FaultException("Empty Username or Empty Password");
     }
     if (!GetUser(userName, password))
     {
         log.Add("Unknown Username or Incorrect Password");
         throw new FaultException("Unknown Username or Incorrect Password");
     }
 }
Exemplo n.º 3
0
 public bool DeleteIndexFiles(string path)
 {
     if (Directory.Exists(path))
     {
         DirectoryInfo di = new DirectoryInfo(path);
         foreach (var fileInfo in di.GetFiles())
         {
             fileInfo.Delete();
             logger.Add("Index file: " + fileInfo.Name + " Deleted.");
         }
     }
     return(true);
 }
Exemplo n.º 4
0
        public IndexService()
        {
            //TODO Evaluate reading settings on every connect not needing static
            if (!_settingsSet)
            {
                ReadSettings();
            }

            // if (indexFiles.Count < 1)
            // {
            //     CreateIndex();
            // }

            //Get client IP and name
            OperationContext context = OperationContext.Current;

            if (context != null)
            {
                MessageProperties             prop     = context.IncomingMessageProperties;
                RemoteEndpointMessageProperty endpoint =
                    prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
                ip = endpoint.Address;
                _logger.Add("Connecting ip: " + ip);

                name = OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name;
                _logger.Write("Connecting name: " + name);
            }
        }