Beispiel #1
0
        /// <summary>
        /// waits for message from server
        /// added for synchronic comunication.
        /// the function also updates everyone via event about the information from server.
        /// </summary>
        /// <returns>the message from server</returns>
        private ServiceInfoEventArgs GetAnswer()
        {
            NetworkStream         stream   = this.client.GetStream();
            BinaryReader          reader   = new BinaryReader(stream);
            string                response = reader.ReadString(); // Wait for response from serve
            CommunicationProtocol msg      = JsonConvert.DeserializeObject <CommunicationProtocol>(response);
            ServiceInfoEventArgs  answer   = ClientServerArgsParser.Parse(msg);

            return(answer);
        }
Beispiel #2
0
        /// <summary>
        /// opens communication channel with ImageService
        /// </summary>
        public void ConnectToService()
        {
            bool                 result;
            SingletonClient      connection = SingletonClient.getInstance;
            ServiceInfoEventArgs info       = connection.ConnectToServer(out result);

            if (IsServiceConnected = result)
            {
                UpdateInfoFromServer(this, info);
            }
        }
Beispiel #3
0
        /// <summary>
        /// sends a request for deletion of a handler and waits for answer from server.
        /// </summary>
        public void CloseHandler()
        {
            SingletonClient      connection = SingletonClient.getInstance;
            ServiceInfoEventArgs answer     = connection.CloseHandler(new List <string>()
            {
                HandlerToDelete
            });

            if (answer.RemovedHandlers.Contains(HandlerToDelete))
            {
                Handlers.Remove(HandlerToDelete);
            }
        }
Beispiel #4
0
 /// <summary>
 /// this is called when information from the service server needs to be updated in web
 /// </summary>
 /// <param name="sender">who sends this</param>
 /// <param name="e">server info</param>
 private void UpdateInfoFromServer(object sender, ServiceInfoEventArgs e)
 {
     if (e.ConfigMap != null)
     {
         SetConfigInfo(e.ConfigMap);
     }
     if (e.LogsList != null)
     {
         foreach (Log log in e.LogsList)
         {
             LogsList.Add(log);
         }
     }
 }
Beispiel #5
0
        /// <summary>
        /// send to Server a command to close the given directory handler
        /// </summary>
        /// <param name="handlers">a directory handler to close</param>
        public ServiceInfoEventArgs CloseHandler(List <string> handlers)
        {
            CommunicationProtocol msg = new CommunicationProtocol(
                (int)CommandEnum.CloseHandlerCommand, handlers.ToArray());

            ServiceInfoEventArgs ret = SendDataToServer(msg);

            // wait for deletion confirmation
            while (ret.RemovedHandlers == null)
            {
                ret = GetAnswer();
            }
            return(ret);
        }
Beispiel #6
0
        /// <summary>
        /// connect to Server. takes the IP and Port from App.config
        /// </summary>
        /// <returns>true if succeeded in connecting to server, false o.w</returns>
        public ServiceInfoEventArgs ConnectToServer(out bool result)
        {
            string     ip   = ConfigurationManager.AppSettings["IP"];
            int        port = int.Parse(ConfigurationManager.AppSettings["Port"]);
            IPEndPoint ep   = new IPEndPoint(IPAddress.Parse(ip), port);

            //IPEndPoint ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8000);
            this.client = new TcpClient();
            try
            {
                client.Connect(ep);
                // get initial information from server
                ServiceInfoEventArgs info = new ServiceInfoEventArgs();
                bool config = false, logs = false;
                ServiceInfoEventArgs answer = GetAnswer();
                while (!config || !logs)
                {
                    if (answer.ConfigMap != null)
                    {
                        info.ConfigMap = answer.ConfigMap;
                        config         = true;
                    }
                    if (answer.LogsList != null)
                    {
                        info.LogsList = answer.LogsList;
                        logs          = true;
                    }
                    answer = GetAnswer();
                }
                result = true;
                return(info);
            }
            catch (Exception)
            {
                result = false;
                return(null);
            }
        }
        private void PrintTask_GetServiceInfoCompleted(object sender, ServiceInfoEventArgs e)
        {
            if (e.ServiceInfo != null)
            {
                isAsynPrintService = e.ServiceInfo.IsServiceAsynchronous;

                if (e.ServiceInfo.LayoutTemplates != null)
                {
                    foreach (string template in e.ServiceInfo.LayoutTemplates)
                    {
                        boxLayoutTemplates.Items.Add(template);
                    }

                    boxLayoutTemplates.SelectedIndex = 0;
                }

                if (e.ServiceInfo.Formats != null)
                {
                    foreach (string format in e.ServiceInfo.Formats)
                    {
                        boxExportFormats.Items.Add(format);
                    }

                    boxExportFormats.SelectedIndex = 0;
                }

                if (isAsynPrintService)
                {
                    printTask.JobCompleted += new EventHandler <PrintJobEventArgs>(PrintTask_JobCompleted);
                }
                else
                {
                    printTask.ExecuteCompleted += new EventHandler <PrintEventArgs>(PrintTask_ExecuteCompleted);
                }
            }
        }
 private void printTask_GetServiceInfoCompleted(object sender, ServiceInfoEventArgs e)
 {
     LayoutTemplates.ItemsSource = e.ServiceInfo.LayoutTemplates;
     Formats.ItemsSource         = e.ServiceInfo.Formats;
 }
 private void printTask_GetServiceInfoCompleted(object sender, ServiceInfoEventArgs e)
 {
     LayoutTemplates.ItemsSource = e.ServiceInfo.LayoutTemplates;
     Formats.ItemsSource = e.ServiceInfo.Formats;
 }
		/// <summary>
		/// This event is used to get print service information to populate layout and format choice lists.
		/// </summary>
		private void PrintTask_GetServiceInfoCompleted(object sender, ServiceInfoEventArgs e)
		{
			(sender as PrintTask).GetServiceInfoCompleted -= PrintTask_GetServiceInfoCompleted;
			IsBusy = printTask.IsBusy;
            
            // Set flag indicating that currently specified service has been retrieved
            serviceLoaded = true;

            // Raise execution state change for load command
            LoadChanged();

            var showStatus = (bool) e.UserState;
			if (e.Error != null || e.ServiceInfo == null)
			{
				Error = e.Error;
				return;
			}
            // Use service-defined choice lists.
            if (e.ServiceInfo.LayoutTemplates == null || e.ServiceInfo.LayoutTemplates.Count() == 0)
            {
                Error = new Exception("No layouts found for the specified URL");
                return;
            }
            else
            {
                LayoutTemplates = new List<string>(e.ServiceInfo.LayoutTemplates);
            }
            if (showStatus) Status = Resources.Strings.GetLayoutTemplatesCompleted;
			IsServiceAsynchronous = e.ServiceInfo.IsServiceAsynchronous;

			if (e.ServiceInfo.Formats != null)
			{
				Formats = new List<string>(e.ServiceInfo.Formats);
			}

			// Use service-defined default values.
			if (e.ServiceInfo.Parameters != null)
			{
				var layoutTemplateParameter = e.ServiceInfo.Parameters.FirstOrDefault(p => p.Name == "Layout_Template");
				LayoutTemplate = (layoutTemplateParameter != null) ? layoutTemplateParameter.DefaultValue as string : LayoutTemplates.FirstOrDefault();
				var formatParameter = e.ServiceInfo.Parameters.FirstOrDefault(p => p.Name == "Format");
				Format = (formatParameter != null) ? formatParameter.DefaultValue as string : Formats.FirstOrDefault();
			}
			IsValid = e.ServiceInfo != null;
		}