Esempio n. 1
0
        private void ShareWindow_SinaShareClick(object sender, RoutedEventArgs e)
        {
            ShareObject objShare = new ShareObject
            {
                Text              = $"{title}(分享自 @知乎日报 App)",
                Service           = "sina",
                StoryId           = story.Id,
                IncludeScreenshot = true,
                ShareUrl          = $" {shareUrl}?utm_campaign=in_app_share&utm_medium=Android&utm_source=Sina"
            };

            //string jsonShare = JsonConvertHelper.JsonSerializer(objShare);
            //string resJson = await WebProvider.GetInstance().SendPostRequestAsync("https://news-at.zhihu.com/api/4/share", jsonShare, WebProvider.ContentType.ContentType3);
            //if (string.IsNullOrEmpty(resJson))
            //{
            //    ToastPrompt.ShowToast("分享成功");
            //}
            //else
            //{
            //    try
            //    {
            //        var jsonObj = JsonObject.Parse(resJson);
            //        double status = jsonObj["status"].GetNumber();
            //        if (status > 0)
            //            ToastPrompt.ShowToast(jsonObj["error_msg"].GetString());
            //        //else
            //        //ToastPrompt.ShowToast(jsonObj["debug_info"].GetString());
            //    }
            //    catch { }
            //}
            this.Frame.Navigate(typeof(EditSinaShare), new object[] { objShare });
        }
Esempio n. 2
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            object[] parameters = e.Parameter as object[];
            if (parameters != null && parameters[0] != null)
            {
                ShareObject objShare = parameters[0] as ShareObject;
                this.DataContext = _viewModel = new EditSinaSharePageViewModel(objShare);
            }

            Messenger.Default.Register <NotificationMessage>(this, (msg) =>
            {
                switch (msg.Notification)
                {
                case "gobackSharePage":
                    this.Frame.GoBack();
                    break;

                default:
                    break;
                }
            });

            InputPane.GetForCurrentView().Showing += EditSinaShare_Showing;
            InputPane.GetForCurrentView().Hiding  += EditSinaShare_Hiding;
        }
Esempio n. 3
0
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            LogManager.WiteLog("启动浏览器窗口");

            browser.LifeSpanHandler = new OpenPageSelf();

            WindowHelper.SetForegroundWindowX(new WindowInteropHelper(this).Handle);

            setting          = new ClientSetting();
            setting.HomeUrl  = this.browser.Address;
            setting.Location = new ClientLocation()
            {
                X      = this.Left,
                Y      = this.Top,
                Width  = this.Width,
                Height = this.Height
            };

            iniSetting = new IniFileHelper(Path.Combine(appCachePath, "setting.ini"));
            string channelPort     = iniSetting.IniReadValue("General", "ChannelPort");
            string shareChannelUri = string.Format("tcp://localhost:{0}/ShareObject", channelPort);

            receiveMessageThread = new Thread(new ThreadStart(() =>
            {
                while (true)
                {
                    ShareObject remoteObject = (ShareObject)Activator.GetObject(typeof(ShareObject), shareChannelUri);
                    if (remoteObject != null)
                    {
                        HandleMessage(remoteObject);
                    }

                    Thread.Sleep(2000);
                }
            }));
            receiveMessageThread.Start();
        }
Esempio n. 4
0
        public void Execute(object parameter)
        {
            ShareObject article = (ShareObject)parameter;

            _shareProvider.Share(article.Title, article.Url);
        }
 public EditSinaSharePageViewModel(ShareObject shareObject)
 {
     _shareObject   = shareObject;
     SelectionStart = shareObject.Text.Length;
 }
Esempio n. 6
0
        private void HandleMessage(ShareObject remoteObject)
        {
            try
            {
                if (remoteObject.State == WinState.CLOSE)
                {
                    LogManager.WiteLog("关闭浏览器窗口");
                    remoteObject.State = WinState.NORMAL;
                    this.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        if (receiveMessageThread != null)
                        {
                            receiveMessageThread.Abort();
                        }
                        this.Close();
                    }));
                }

                if (!this.setting.HomeUrl.Equals(remoteObject.HomeUrl) &&
                    !string.IsNullOrEmpty(remoteObject.HomeUrl))
                {
                    LogManager.WiteLog("跳转到网页:" + remoteObject.HomeUrl);

                    this.setting.HomeUrl = remoteObject.HomeUrl;

                    this.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        this.browser.Address = this.setting.HomeUrl;
                    }));
                }

                if (remoteObject.Width == 0 || remoteObject.Height == 0)
                {
                    return;
                }

                if (this.setting.Location.Width != remoteObject.Width ||
                    this.setting.Location.Height != remoteObject.Height ||
                    this.setting.Location.X != remoteObject.X ||
                    this.setting.Location.Y != remoteObject.Y)
                {
                    ClientLocation location = new ClientLocation()
                    {
                        X      = remoteObject.X,
                        Y      = remoteObject.Y,
                        Width  = remoteObject.Width,
                        Height = remoteObject.Height
                    };
                    this.setting.Location = location;

                    this.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        this.Width  = location.Width;
                        this.Height = location.Height;

                        LogManager.WiteLog("设置窗口位置:" + location.X + " " + location.Y + " " + location.Width + " " + location.Height);

                        IntPtr winptr = new WindowInteropHelper(this).Handle;
                        WindowHelper.SetWindowPos(winptr, WindowHelper.HWND_TOP, (int)location.X, (int)location.Y, 0, 0, WindowHelper.SWP_NOSIZE);
                        WindowHelper.SetForegroundWindowX(winptr);
                    }));
                }
            }
            catch (Exception ex)
            {
                LogManager.WiteLog(ex.Message + ":" + ex.StackTrace);
            }
        }
Esempio n. 7
0
        private void StartService(WebSocket ws)
        {
            ws.OnMessage += (sender, e) =>
            {
                ShareObject objRemoteObject = (ShareObject)Activator.GetObject(typeof(ShareObject), channelUri);
                if (objRemoteObject == null)
                {
                    return;
                }
                LogManager.WiteLog("接收到消息" + e.Data);

                string[] infos   = e.Data.Split(' ');
                string   command = infos[0].ToUpper();
                switch (command)
                {
                case "START":
                    objRemoteObject.State = WinState.NORMAL;
                    if (IsSkyViewerStarted() == false)
                    {
                        StartSkyViewer();
                    }
                    ws.Send("STARTING");
                    break;

                case "CLOSE":
                    objRemoteObject.State = WinState.CLOSE;
                    ws.Send("CLOSING");
                    break;

                case "HOME":
                    if (infos.Length > 1)
                    {
                        string homeUrl = infos[1];
                        if (!string.IsNullOrEmpty(homeUrl))
                        {
                            objRemoteObject.HomeUrl = homeUrl;
                        }
                    }
                    ws.Send("HOME_SETTING");
                    break;

                case "LOCATION":
                    if (infos.Length > 1)
                    {
                        string position = infos[1];
                        if (!string.IsNullOrEmpty(position))
                        {
                            string[] posInfos = position.Split(',');
                            objRemoteObject.X      = double.Parse(posInfos[0]);
                            objRemoteObject.Y      = double.Parse(posInfos[1]);
                            objRemoteObject.Width  = double.Parse(posInfos[2]);
                            objRemoteObject.Height = double.Parse(posInfos[3]);
                        }
                    }
                    ws.Send("LOCATION_SETTING");
                    break;

                default:
                    break;
                }
            };

            ws.OnError += (sender, e) =>
            {
                LogManager.WiteLog("检测到错误:" + e.Message);
            };

            ws.OnClose += (sender, e) =>
            {
                LogManager.WiteLog("检测到连接断开:" + e.Reason);
                ConnectWebSocketServer();
            };
        }
Esempio n. 8
0
        public static JObject DownloadItem(string token, string subdomain, string itemId, string email, DateTime date)
        {
            string hosturl = string.Format("{0}.sf-api.com", subdomain);

            String uri = string.Format("https://{0}/sf/v3/Shares?notify=false", hosturl, itemId);

            Console.WriteLine(uri);

            HttpWebRequest request = WebRequest.CreateHttp(uri);

            addAuthorizationHeader(request, token);
            request.AllowAutoRedirect = true;

            // Dictionary<string, object> Sharefolder = new Dictionary<string, object>();
            //Sharefolder.Add("ShareType", "Send");
            //Sharefolder.Add("Title", "Sample Send Share");
            //Sharefolder.Add("Recipients", "[{ 'User': { 'Email': '*****@*****.**' } }]");
            //Sharefolder.Add("Parent", "{ 'Id':'"+itemId+"' }");
            //Sharefolder.Add("ExpirationDate", DateTime.Today.AddDays(10));
            //Sharefolder.Add("RequireUserInfo", false);
            //Sharefolder.Add("MaxDownloads", 4);
            // Sharefolder.Add("UsesStreamIDs", false);

            ShareObject shareObject = new ShareObject();

            shareObject.ShareType = "send";
            shareObject.Title     = "Send file";
            shareObject.Items     = new List <Parent>();
            shareObject.Items.Add(new Parent()
            {
                Id = itemId
            });
            // shareObject.Parent = new Parent() { Id = itemId };
            shareObject.Recipients = new List <ShareWith>();
            shareObject.Recipients.Add(new ShareWith()
            {
                User = new ShareUser()
                {
                    Email = "*****@*****.**"
                }
            });
            //  shareObject.Parent = new Parent() { Id = itemId };
            shareObject.ExpirationDate  = date.ToString("yyyy-MM-dd");
            shareObject.RequireUserInfo = false;
            shareObject.MaxDownloads    = 4;
            shareObject.UsesStreamIDs   = false;


            string json = JsonConvert.SerializeObject(shareObject);

            //Console.WriteLine(json);

            request.Method      = "POST";
            request.ContentType = "application/json";
            using (var writer = new StreamWriter(request.GetRequestStream()))
            {
                writer.Write(json);
            }

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            // Console.WriteLine(response.StatusCode);
            using (var reader = new StreamReader(response.GetResponseStream()))
            {
                String body = reader.ReadToEnd();

                JObject item = JObject.Parse(body);
                //Console.WriteLine(item["Id"] + " " + item["CreationDate"] + " " + item["Name"]);

                return(item);
            }
        }