Ejemplo n.º 1
0
        public ServerSettingsControlViewModel()
        {
            model            = new ServersSettingsModel();
            repository       = new ServerSettingsRepository();
            log              = new InfoLog(Properties.Settings.Default.LogsFilePath);
            AvailableFolders = new ObservableCollection <string>();

            model = repository.LoadSettings();
        }
Ejemplo n.º 2
0
        public Socket SetupServer()
        {
            //Load Options before create new instance
            ServerSettingsRepository loader = new ServerSettingsRepository();
            var serverSettings = loader.LoadSettings();

            loader = null;

            options.BufferSize            = serverSettings._BufferSize;
            options.AvailableFoldersModel = serverSettings._AvailableFolders.ToArray();
            options.LogFile = serverSettings._LogsFilePath;
            options.Port    = serverSettings._Port;
            options.WLAN    = serverSettings._WLAN;

            Model.buffer = new byte[options.BufferSize];

            Socket socket;

            foreach (var item in Settings.Default.AvailableFoldersModel)
            {
                var filesFullNames = System.IO.Directory.GetFiles(item);

                All_Images.ImagesData.Add(new ServerData.TemporaryResources()
                {
                    Directory = item,
                    FilesFoundInSharedFolders = filesFullNames
                });

                foreach (var it in All_Images.ImagesData)
                {
                    for (int i = 0; i < it.FilesFoundInSharedFolders.Length; i++)
                    {
                        it.FilesFoundInSharedFolders[i] = Path.GetFileName(it.FilesFoundInSharedFolders[i]);
                    }
                }
            }
            #region local network
            if (options.WLAN == false)
            {
                Model.ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
                Model.iPAddress  = Model.ipHostInfo.AddressList[0];
                Model.iPEndPoint = new IPEndPoint(Model.iPAddress, options.Port);
                socket           = new Socket(Model.iPAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            }
            #endregion
            #region internet
            else
            {
                Model.ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
                Model.iPEndPoint = new IPEndPoint(IPAddress.Any, options.Port);
                socket           = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            }
            #endregion

            socket.Bind(Model.iPEndPoint);

            socket.Listen(100);

            serverSocket = socket;

            return(socket);
        }