//--------< send file content each time 512 size >-------
        private bool SendFile(ICommService service, string file)
        {
            long blockSize = 512;

            try
            {
                string filename = Path.GetFileName(file);
                service.OpenFileForWrite(filename);
                FileStream fs        = File.Open(file, FileMode.Open, FileAccess.Read);
                int        bytesRead = 0;
                while (true)
                {
                    long remainder = (int)(fs.Length - fs.Position);
                    if (remainder == 0)
                    {
                        break;
                    }
                    long   size  = Math.Min(blockSize, remainder);
                    byte[] block = new byte[size];
                    bytesRead = fs.Read(block, 0, block.Length);
                    service.WriteFileBlock(block);
                }
                fs.Close();
                service.CloseFile();
                return(true);
            }
            catch (Exception ex)
            {
                Console.Write("\n  can't open {0} for writing - {1}", file, ex.Message);
                return(false);
            }
        }
        public void CreateMessageChannel(string url)
        {
            int                           tryCount = 0;
            int                           maxCount = 10;
            EndpointAddress               address  = new EndpointAddress(url);
            WSDualHttpBinding             binding  = new WSDualHttpBinding();
            ChannelFactory <ICommService> factory
                = new ChannelFactory <ICommService>(binding, address);

            channel = factory.CreateChannel();
            while (true)
            {
                try
                {
                    channel  = factory.CreateChannel();
                    tryCount = 0;
                    break;
                }
                catch (Exception ex)
                {
                    if (++tryCount <= maxCount)
                    {
                        Thread.Sleep(500);
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
        }
Esempio n. 3
0
        void CreateBasicHttpChannel(string url)
        {
            EndpointAddress  address = new EndpointAddress(url);
            BasicHttpBinding binding = new BasicHttpBinding();

            channel = ChannelFactory <ICommService> .CreateChannel(binding, address);
        }
Esempio n. 4
0
        private async void OnReceivedAsync(ICommService sender, MessageEventArgs args)
        {
            var msg = args.Message;
            await writer.Notice(msg);

            foreach (var s in Scanners)
            {
                var info = s.Scan(msg);
                if (info.Valid)
                {
                    await writer.Info(info.ToString());

                    if (info.WolTrigger)
                    {
                        if (CheckInterval())
                        {
                            lastWolTime = DateTimeOffset.Now;
                            await writer.Debug("WOL!");

                            WOLHelper.WakeUpAll();
                        }
                    }
                    break;
                }
            }
        }
Esempio n. 5
0
        void CreateNetTcpChannel(string url)
        {
            EndpointAddress address = new EndpointAddress(url);
            NetTcpBinding   binding = new NetTcpBinding();

            channel = ChannelFactory <ICommService> .CreateChannel(binding, address);
        }
Esempio n. 6
0
 public NavigationPageViewModel(IContainerProvider container, ICommService commService)
 {
     CommService        = commService;
     ShutdownDialog     = container.Resolve <ShutdownDialog>();
     RestartDialog      = container.Resolve <RestartDialog>();
     ItemInvokedCommand = new RelayCommand <NavigationViewItemInvokedEventArgs>(OnItemInvoked);
 }
Esempio n. 7
0
 public PacketLogModel(ICommService logReceiveServer)
 {
     textLog               = new List <string>();
     tagInfo               = new TagInfo();
     commService           = logReceiveServer;
     commService.Received += this.OnReceived;
     _ = commService.ConnectAsync();
 }
Esempio n. 8
0
        //----< Create proxy to another Peer's Communicator >------------

        public void CreateSendChannel(string address)
        {
            ChannelFactory <ICommService> factory
                = new ChannelFactory <ICommService>(new WSHttpBinding(), new EndpointAddress(address));

            channel = factory.CreateChannel();
            Console.Write("\n  service proxy created for {0}", address);
        }
Esempio n. 9
0
        private static void ExecuteOnMainProcess(Action action, bool doAsync)
        {
            ICommService service = GetChannel();

            if (service == null || service.ExecuteOnMainProcess(DelToByte(action), doAsync))
            {
                action();
            }
        }
Esempio n. 10
0
        public static void AddToTrayIcon(IntPtr tabBarHandle, IntPtr explorerHandle, string currentPath, string[] tabNames, string[] tabPaths)
        {
            ICommService service = GetChannel();

            if (service != null)
            {
                service.AddToTrayIcon(tabBarHandle, explorerHandle, currentPath, tabNames, tabPaths);
            }
        }
Esempio n. 11
0
        public static void RemoveFromTrayIcon(IntPtr tabBarHandle)
        {
            ICommService service = GetChannel();

            if (service != null)
            {
                service.RemoveFromTrayIcon(tabBarHandle);
            }
        }
Esempio n. 12
0
        public static void SelectTabOnOtherTabBar(IntPtr tabBarHandle, int index)
        {
            ICommService service = GetChannel();

            if (service != null)
            {
                service.SelectTabOnOtherTabBar(tabBarHandle, index);
            }
        }
Esempio n. 13
0
        public static void StaticBroadcast(Action action)
        {
            ICommService service = GetChannel();

            if (service != null)
            {
                service.Broadcast(DelToByte(action));
            }
        }
Esempio n. 14
0
        public static bool EnsureMainProcess(Action action)
        {
            ICommService service = GetChannel();

            if (service != null && service.IsMainProcess())
            {
                return(true);
            }
            ExecuteOnMainProcess(action, false);
            return(false);
        }
Esempio n. 15
0
        private void OnReceived(ICommService sender, MessageEventArgs args)
        {
            TagInfo tagValue = TagInfo.FromString(args.Message);

            if (tagValue.Valid)
            {
                Tag = tagValue;
            }
            while (textLog.Count > LOG_CAPACITY)
            {
                textLog.RemoveAt(0);
            }
            textLog.Add(string.Format(CultureInfo.InvariantCulture, "{0} {1} {2} {3}", args.Timestamp, args.Priority, args.Tag, args.Message));
            RaisePropertyChanged(nameof(LogList));
        }
Esempio n. 16
0
        public static void PushTabBarInstance(QTTabBarClass tabbar)
        {
            IntPtr handle = tabbar.Handle;

            using (new Keychain(rwLockTabBar, true)) {
                dictTabInstances[Thread.CurrentThread] = tabbar;
                sdTabHandles.Push(handle, tabbar);
            }
            ICommService service = GetChannel();

            if (service != null)
            {
                service.PushInstance(handle);
            }
        }
Esempio n. 17
0
 public bool Connect(string url)
 {
     for (int i = 0; i < 100; ++i)
     {
         try
         {
             svc = CreateProxy(url);
             return(true);
         }
         catch
         {
             Thread.Sleep(100);
         }
     }
     return(false);
 }
Esempio n. 18
0
 public bool Connect(string url)
 {
     for (int i = 0; i < 100; ++i)
       {
     try
     {
       svc = CreateProxy(url);
       return true;
     }
     catch
     {
       Thread.Sleep(100);
     }
       }
       return false;
 }
Esempio n. 19
0
 public static bool UnregisterTabBar()
 {
     using (new Keychain(rwLockTabBar, true)) {
         QTTabBarClass tabbar;
         if (dictTabInstances.TryGetValue(Thread.CurrentThread, out tabbar))
         {
             IntPtr handle = tabbar.Handle;
             dictTabInstances.Remove(Thread.CurrentThread);
             sdTabHandles.Remove(handle);
             ICommService service = GetChannel();
             if (service != null)
             {
                 service.DeleteInstance(handle);
             }
         }
         return(false);
     }
 }
        //--------< connect with server >-------
        public void UploadToServer(string targetfile)
        {
            ICommService cs    = null;
            int          count = 0;

            while (true)
            {
                try
                {
                    cs = Sender.CreateProxy(main.ServerUrl);
                    break;
                }
                catch
                {
                    Console.Write("\n  connection to service failed {0} times - trying again", ++count);
                    Thread.Sleep(500);
                    continue;
                }
            }
            SendFile(cs, targetfile);
        }
        //----< Connect repeatedly tries to send messages to service >-------

        public bool Connect(string remoteUrl)
        {
            if (Util.verbose)
            {
                sendMsgNotify("attempting to connect");
            }
            if (isConnected(remoteUrl))
            {
                return(true);
            }
            proxy = CreateProxy(remoteUrl);
            int     attemptNumber = 0;
            Message startMsg      = new Message();

            startMsg.fromUrl = localUrl;
            startMsg.toUrl   = remoteUrl;
            startMsg.content = "connection start message";
            while (attemptNumber < MaxConnectAttempts)
            {
                try
                {
                    proxy.sendMessage(startMsg);    // will throw if server isn't listening yet
                    proxyStore[remoteUrl] = proxy;  // remember this proxy
                    if (Util.verbose)
                    {
                        sendMsgNotify("connected");
                    }
                    return(true);
                }
                catch
                {
                    ++attemptNumber;
                    sendAttemptNotify(attemptNumber);
                    Thread.Sleep(100);
                }
            }
            return(false);
        }
Esempio n. 22
0
        /// <summary>
        /// Sends email info using the specified communication service.
        /// </summary>
        /// <param name="commService">The comm service.</param>
        /// <author>Jurie.smit</author>
        /// <datetime>2013/01/14-09:20 AM</datetime>
        /// <exception cref="System.NullReferenceException">ICommService of type EmailCommMessage</exception>
        public void Send(ICommService <EmailCommMessage> commService)
        {
            Dev2Logger.Log.Debug("");
            if (commService == null)
            {
                throw new NullReferenceException("ICommService<EmailCommMessage>");
            }

            var message = new EmailCommMessage
            {
                To      = StringResources.FeedbackEmail,
                Subject = String.Format("Some Real Live Feedback{0}{1}"
                                        , String.IsNullOrWhiteSpace(SelectedCategory) ? "" : " : ", SelectedCategory),
                Content = Comment
            };

            if (HasRecordingAttachment)
            {
                Attachments += !string.IsNullOrEmpty(RecordingAttachmentPath) ? RecordingAttachmentPath : "";
            }

            if (HasServerLogAttachment)
            {
                Attachments += !string.IsNullOrEmpty(Attachments) ? ";" : "";
                Attachments += !string.IsNullOrEmpty(ServerLogAttachmentPath) ? ServerLogAttachmentPath : "";
            }

            if (HasStudioLogAttachment)
            {
                Attachments += !string.IsNullOrEmpty(Attachments) ? ";" : "";
                Attachments += !string.IsNullOrEmpty(StudioLogAttachmentPath) ? StudioLogAttachmentPath : "";
            }

            message.AttachmentLocation = Attachments;
            commService.SendCommunication(message);
            RequestClose(ViewModelDialogResults.Okay);
        }
Esempio n. 23
0
    //----< close connection - not used in this demo >-------------------

    public void CloseConnection()
    {
      proxy = null;
    }
Esempio n. 24
0
    //----< Connect repeatedly tries to send messages to service >-------

    public bool Connect(string remoteUrl)
    {
      if(Util.verbose)
        sendMsgNotify("attempting to connect");
      if (isConnected(remoteUrl))
        return true;
      proxy = CreateProxy(remoteUrl);
      int attemptNumber = 0;
      Message startMsg = new Message();
      startMsg.fromUrl = localUrl;
      startMsg.toUrl = remoteUrl;
      startMsg.content = "connection start message";
      while (attemptNumber < MaxConnectAttempts)
      {
        try
        {
          proxy.sendMessage(startMsg);    // will throw if server isn't listening yet
          proxyStore[remoteUrl] = proxy;  // remember this proxy
          if(Util.verbose)
            sendMsgNotify("connected");
          return true;
        }
        catch
        {
          ++attemptNumber;
          sendAttemptNotify(attemptNumber);
          Thread.Sleep(100);
        }
      }
      return false;
    }
 public SearchesController(ISearchesService service, UserManager <ApplicationUser> manager, ICommService communication)
 {
     this._manager       = manager;
     this._service       = service;
     this._communication = communication;
 }
 public void CreateBasicHttpChannel(string url)
 {
   EndpointAddress address = new EndpointAddress(url);
   BasicHttpBinding binding = new BasicHttpBinding();
   channel = ChannelFactory<ICommService>.CreateChannel(binding, address);
 }
Esempio n. 27
0
 public CommClient()
 {
     pipeFactory = new ChannelFactory <ICommService>(new NetNamedPipeBinding(),
                                                     new EndpointAddress("net.pipe://localhost/beRemoteInterComm"));
     pipeProxy = pipeFactory.CreateChannel();
 }
Esempio n. 28
0
        public static int GetTotalInstanceCount()
        {
            ICommService service = GetChannel();

            return(service == null ? dictTabInstances.Count : service.GetTotalInstanceCount());
        }
        //----< close connection - not used in this demo >-------------------

        public void CloseConnection()
        {
            proxy = null;
        }
Esempio n. 30
0
 public CommsController(ICommService service, UserManager <ApplicationUser> manager)
 {
     this._service = service;
     this._manager = manager;
 }
Esempio n. 31
0
 public CommController(ICommService commService)
 {
     _commService = commService;
 }