예제 #1
0
        private async Task <T> DispatchDataToHandlers <T>(IStorageFile file,
                                                          BufferDelegate <T> buffer,
                                                          LinesDelegate <T> lines,
                                                          TextDelegate <T> text)
        {
            switch (Format)
            {
            case RequiredDataFormat.IBuffer:
            {
                return(buffer(await FileIO.ReadBufferAsync(file)));
            }

            case RequiredDataFormat.Lines:
            {
                return(lines(await FileIO.ReadLinesAsync(file, Encoding)));
            }

            case RequiredDataFormat.Text:
            {
                return(text(await FileIO.ReadTextAsync(file, Encoding)));
            }

            default:
            {
                throw new NotSupportedException("Invalid data format selected");
            }
            }
        }
예제 #2
0
    public static void Main(string[] args)
    {
        //组合委托
        TextDelegate method = methodA;

        method += methodB;
        method();
    }
예제 #3
0
    private IEnumerator DownloadTest(string url, TextDelegate output)
    {
        WWW www = new WWW(url);

        yield return(www);

        output(www.text);
    }
예제 #4
0
    IEnumerator UpdateThemePizza(TextDelegate output)
    {
        WWW www = new WWW("https://path-of-buddha-database.000webhostapp.com/saveDataPizza.php?name=" + DatabaseManager.username +
                          "&totalFoodItem7=" + DatabaseManager.totalFoodItem7 + "&totalFoodItem8=" + DatabaseManager.totalFoodItem8 +
                          "&totalFoodItem9=" + DatabaseManager.totalFoodItem9);

        yield return(www);

        DatabaseManager.totalFoodItem7 = 0;
        DatabaseManager.totalFoodItem8 = 0;
        DatabaseManager.totalFoodItem9 = 0;
    }
예제 #5
0
    IEnumerator UpdateThemeMcDonalds(TextDelegate output)
    {
        WWW www = new WWW("https://path-of-buddha-database.000webhostapp.com/saveDataMcDonalds.php?name=" + DatabaseManager.username +
                          "&totalFoodItem4=" + DatabaseManager.totalFoodItem4 + "&totalFoodItem5=" + DatabaseManager.totalFoodItem5 +
                          "&totalFoodItem6=" + DatabaseManager.totalFoodItem6);

        yield return(www);

        DatabaseManager.totalFoodItem4 = 0;
        DatabaseManager.totalFoodItem5 = 0;
        DatabaseManager.totalFoodItem6 = 0;
    }
예제 #6
0
    IEnumerator UpdateThemeDefault(TextDelegate output)
    {
        WWW www = new WWW("https://path-of-buddha-database.000webhostapp.com/saveDataDefault.php?name=" + DatabaseManager.username +
                          "&totalFoodItem1=" + DatabaseManager.totalFoodItem1 + "&totalFoodItem2=" + DatabaseManager.totalFoodItem2 +
                          "&totalFoodItem3=" + DatabaseManager.totalFoodItem3);

        yield return(www);

        DatabaseManager.totalFoodItem1 = 0;
        DatabaseManager.totalFoodItem2 = 0;
        DatabaseManager.totalFoodItem3 = 0;
    }
예제 #7
0
 public static void SetTextToControl(Control textBox, string text)
 {
     if (textBox.InvokeRequired)
     {
         var d = new TextDelegate(SetTextToControl);
         textBox.Invoke(d, new object[] { textBox, text });
     }
     else
     {
         textBox.Text = text;
     }
 }
예제 #8
0
        private async Task Read(Process p)
        {
            while (!p.StandardOutput.EndOfStream)
            {
                int count = await p.StandardOutput.ReadAsync(buffer, 0, 1024);

                string chunk = new string(buffer, 0, count);
                chunk = chunk.Replace("\r\n", "\n");
                TextDelegate d = new TextDelegate(RichTextBox1TextAddText);
                this.Invoke(d, chunk);
            }
        }
예제 #9
0
    IEnumerator UpdateThemeSushi(TextDelegate output)
    {
        WWW www = new WWW("https://path-of-buddha-database.000webhostapp.com/saveDataSushi.php?name=" + DatabaseManager.username +
                          "&totalFoodItem10=" + DatabaseManager.totalFoodItem10 + "&totalFoodItem11=" + DatabaseManager.totalFoodItem11 +
                          "&totalFoodItem12=" + DatabaseManager.totalFoodItem12);

        yield return(www);

        DatabaseManager.totalFoodItem10 = 0;
        DatabaseManager.totalFoodItem11 = 0;
        DatabaseManager.totalFoodItem12 = 0;
    }
예제 #10
0
 private void LogData(string text)
 {
     // This just appends all the data we receive to the logbox
     if (txtSerialLog.InvokeRequired)
     {
         var d = new TextDelegate(LogData);
         txtSerialLog.Invoke(d, new object[] { text });
     }
     else
     {
         txtSerialLog.AppendText(text + "\r\n");
     }
 }
예제 #11
0
    IEnumerator SavePlayerData(TextDelegate output)
    {
        WWW www = new WWW("https://path-of-buddha-database.000webhostapp.com/savedata.php?name=" + DatabaseManager.username +
                          "&totalDeaths=" + DatabaseManager.totalDeaths + "&totalWeight=" + DatabaseManager.totalWeight +
                          "&totalTime=" + DatabaseManager.totalTime + "&totalPlays=" + DatabaseManager.totalPlays + "&activeTheme=" + PlayerPrefs.GetInt("activeTheme") +
                          "&dataPoint1=" + dataPoint1 + "&dataPoint2=" + dataPoint2 + "&dataPoint3=" + dataPoint3 + "&dataPoint4=" + dataPoint4 + "&dataPoint5=" + dataPoint5);

        yield return(www);

        if (www.text.Equals("0"))
        {
            Debug.Log("Data successfully submitted");
        }
    }
예제 #12
0
        /// <summary>
        /// Accoda testo a quello corrente di una casella di testo.
        /// </summary>
        /// <param name="AppendingText">
        /// Il testo da aggiungere al contenuto corrente della casella di testo.
        /// </param>
        public new void AppendText(string AppendingText)
        {
            if (InvokeRequired)
            {
                TextDelegate callback = AppendText;
                BeginInvoke(callback, new object[] { AppendingText });
                return;
            }

            if (AppendingText.Length > 0)
            {
                SelectionStart = TextLength;
                ScrollToCaret();
                SendMessage(new HandleRef(this, Handle), 0xc2, 0, AppendingText);
                ClearUndo();
            }
            if (!AutoScrollText)
            {
                SelectionStart = 0;
                ScrollToCaret();
            }
        }
예제 #13
0
        //Constructor, just initializes values.
        public ServerHandler(bool serverWorking, string welcomeMessage, int port, int clientNumber,
                             TextBox outputTextbox, TextBox inputTextbox, ListView clientsListView,
                             TextBox ipTextbox, TextBox portTextbox, TextBox nameTextBox, Form serverForm)
        {
            ServerWorking  = serverWorking;
            WelcomeMessage = welcomeMessage;
            Port           = port;
            ClientNumber   = clientNumber;

            OutputTextbox   = outputTextbox;
            InputTextbox    = inputTextbox;
            IpTextbox       = ipTextbox;
            PortTextbox     = portTextbox;
            NameTextbox     = nameTextBox;
            ClientsListView = clientsListView;
            ServerForm      = serverForm;
            SelectedClient  = null;

            txtDelegate               = new TextDelegate(ChangeText);
            lstAddDelegate            = new listAddDelegate(AddList);
            lstClearDelegate          = new listClearDelegate(ClearList);
            serverThread              = new Thread(ServerListening);
            serverThread.IsBackground = true;
        }
예제 #14
0
    IEnumerator doWWW(string url, TextDelegate output)
    {
        www = new WWW(url);
        yield return(www);

        if (!string.IsNullOrEmpty(www.error))
        {
            Debug.Log(www.error);
        }
        else
        {
            Mesh       newMesh       = output(www.text);
            GameObject spawnedPrefab = Instantiate(OBJ, Vector3.zero, transform.rotation) as GameObject;

            spawnedPrefab.AddComponent <MeshRenderer>().material = OBJ_mat;
            spawnedPrefab.GetComponent <MeshFilter>().mesh       = newMesh;

            spawnedPrefab.AddComponent <MeshCollider>();

            spawnedPrefab.gameObject.tag = "Terrain";

            GameObject.FindGameObjectWithTag("UIController").GetComponent <ObjectManager>().loadedObjects.Add(spawnedPrefab);
        }
    }
예제 #15
0
        void bwDownload_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = (BackgroundWorker)sender;

            worker.ReportProgress(0);
            string searchString = e.Argument as string;

            using (GoogleImageDownloader loader = new GoogleImageDownloader())
            {
                string maxCountStr = ConfigurationManager.AppSettings["MaxCount"];
                int    maxCount    = 1000;
                if (!int.TryParse(maxCountStr, out maxCount))
                {
                    Debug.WriteLine("Invalid value : AppSettings[\"MaxCount\"]");
                }

                TextDelegate textDlg = new TextDelegate(SetText);

                // 画像URLの収集
                //Text = "Collecting Image URLs... - " + APP_NAME;
                Invoke(textDlg, new object[] { "Collecting Image URLs... - " + APP_NAME });
                Uri url = GoogleImageDownloader.BuildHtmlUri(searchString);
                Dictionary <string, string> imgurls = new Dictionary <string, string>();
                for (int i = 0; ; i = i + 20)
                {
                    if (worker.CancellationPending)
                    {
                        e.Cancel = true;
                        break;
                    }

                    Dictionary <string, string> newImgurls = loader.ParseHtml(new Uri(url.AbsoluteUri + "&start=" + i));
                    if (newImgurls == null)
                    {
                        break;
                    }
                    foreach (string newImgurl in newImgurls.Keys)
                    {
                        if (!imgurls.ContainsKey(newImgurl))
                        {
                            imgurls.Add(newImgurl, newImgurls[newImgurl]);
                            if (imgurls.Count >= maxCount)
                            {
                                goto COLLECT_URL_END;
                            }
                        }
                    }
                    worker.ReportProgress(10 * imgurls.Count / maxCount);
                    Debug.WriteLine("Target image count : " + imgurls.Count + "(" + i + ")");
                }
COLLECT_URL_END:

                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                //ダウンロード対象の画像個数
                int imgCount = imgurls.Count;

                //画像のダウンロード
                //Text = string.Format("Getting {0} Images... - " + APP_NAME, imgCount);
                Invoke(textDlg, new object[] { string.Format(CultureInfo.CurrentCulture,
                                                             "Getting {0} Images... - " + APP_NAME, imgCount) });
                int index = 0;
                foreach (string imgurl in imgurls.Keys)
                {
                    if (worker.CancellationPending)
                    {
                        e.Cancel = true;
                        break;
                    }

                    loader.GetImageFile(imgurl, imgurls[imgurl], searchString);

                    worker.ReportProgress(10 + (50 * ++index / imgCount));
                }

                //実行完了待機
                int  _poolCount        = loader.Queue.Count; //本時点でのQueue数
                int  poolCount         = loader.Queue.Count;
                int  wait              = 30000;
                bool isAlreadyCanceled = false;
                while (loader.Queue.Count != 0)
                {
                    if ((worker.CancellationPending || wait < 0) && !isAlreadyCanceled)
                    {
                        e.Cancel = true;

                        //キャンセル処理
                        CancelQueueAll(loader.Queue);
                        isAlreadyCanceled = true;
                    }

                    worker.ReportProgress(60 + (40 * (_poolCount - poolCount) / _poolCount));
                    //Text = string.Format("remain {0} files... - " + APP_NAME, loader.Queue.Count);
                    Invoke(textDlg, new object[] { string.Format(CultureInfo.CurrentCulture,
                                                                 "remain {0} files... - " + APP_NAME, loader.Queue.Count) });

                    Thread.Sleep(1000);

                    if (poolCount == loader.Queue.Count)
                    {
                        wait -= 1000;
                        Debug.WriteLine("remaining queue : " + poolCount);
                    }
                    else
                    {
                        poolCount = loader.Queue.Count;
                        wait      = 30000;
                    }
                }
            }

            //e.Result = "すべて完了";
        }
예제 #16
0
 protected BaseCommandCapsule(string commandName, TextDelegate textDelegate, System.Drawing.Image image, TextDelegate hintDelegate = null)
     : base(commandName, textDelegate != null ? textDelegate() : null, image, hintDelegate != null ? hintDelegate() : null)
 {
     this.textDelegate = textDelegate;
     this.hintDelegate = hintDelegate;
 }
        /// <summary>
        /// Parses a Mustache-style markup
        /// </summary>
        /// <param name="content">Mustache-style markup</param>
        /// <param name="mustacheStyleTagHandler">Mustache-style tags handler</param>
        /// <param name="textHandler">Text handler</param>
        public static void ParseMarkup(string content, MustacheStyleTagDelegate mustacheStyleTagHandler,
			TextDelegate textHandler)
        {
            var innerContext = new InnerMarkupParsingContext(content);
            var context = new MarkupParsingContext(innerContext);

            MatchCollection mustacheStyleTagMatches = _mustacheStyleTagRegex.Matches(content);
            if (mustacheStyleTagMatches.Count == 0)
            {
                if (textHandler != null)
                {
                    textHandler(context, content);
                }

                innerContext.IncreasePosition(content.Length);

                return;
            }

            int currentPosition = 0;
            int endPosition = content.Length - 1;

            foreach (Match mustacheStyleTagMatch in mustacheStyleTagMatches)
            {
                int mustacheStyleTagPosition = mustacheStyleTagMatch.Index;
                int mustacheStyleTagLength = mustacheStyleTagMatch.Length;

                if (mustacheStyleTagPosition > currentPosition)
                {
                    string text = content.Substring(currentPosition, mustacheStyleTagPosition - currentPosition);

                    if (textHandler != null)
                    {
                        textHandler(context, text);
                    }

                    innerContext.IncreasePosition(text.Length);
                }

                GroupCollection mustacheStyleTagGroups = mustacheStyleTagMatch.Groups;

                string expression = mustacheStyleTagGroups["expression"].Value;
                string startDelimiter = mustacheStyleTagGroups["startDelimiter"].Value;
                string endDelimiter = mustacheStyleTagGroups["endDelimiter"].Value;

                if (expression.StartsWith("{") && expression.EndsWith("}"))
                {
                    expression = expression.Substring(1, expression.Length - 2);
                    startDelimiter = "{{{";
                    endDelimiter = "}}}";
                }

                if (mustacheStyleTagHandler != null)
                {
                    mustacheStyleTagHandler(context, expression, startDelimiter, endDelimiter);
                }

                innerContext.IncreasePosition(mustacheStyleTagLength);
                currentPosition = mustacheStyleTagPosition + mustacheStyleTagLength;
            }

            if (currentPosition > 0 && currentPosition <= endPosition)
            {
                string text = content.Substring(currentPosition, endPosition - currentPosition + 1);

                if (textHandler != null)
                {
                    textHandler(context, text);
                }

                innerContext.IncreasePosition(text.Length);
            }
        }
예제 #18
0
        private void WriteToServoRecText(string str)
        {
            TextDelegate d2 = ServoRecDel;

            textBoxServoRec.Invoke(d2, str);
        }
        /// <summary>
        /// Processes a websocket frame and triggers consumer events
        /// </summary>
        /// <param name="psocketState">We need to modify the websocket state here depending on the frame</param>
        private void ProcessFrame(WebSocketState psocketState)
        {
            if (psocketState.Header.IsMasked)
            {
                byte[] unmask = psocketState.ReceivedBytes.ToArray();
                WebSocketReader.Mask(psocketState.Header.Mask, unmask);
                psocketState.ReceivedBytes = new List <byte>(unmask);
            }

            switch (psocketState.Header.Opcode)
            {
            case WebSocketReader.OpCode.Ping:
                PingDelegate pingD = OnPing;
                if (pingD != null)
                {
                    pingD(this, new PingEventArgs());
                }

                WebSocketFrame pongFrame = new WebSocketFrame()
                {
                    Header = WebsocketFrameHeader.HeaderDefault(), WebSocketPayload = new byte[0]
                };
                pongFrame.Header.Opcode = WebSocketReader.OpCode.Pong;
                pongFrame.Header.IsEnd  = true;
                SendSocket(pongFrame.ToBytes());
                break;

            case WebSocketReader.OpCode.Pong:

                PongDelegate pongD = OnPong;
                if (pongD != null)
                {
                    pongD(this, new PongEventArgs()
                    {
                        PingResponseMS = Util.EnvironmentTickCountSubtract(Util.EnvironmentTickCount(), _pingtime)
                    });
                }
                break;

            case WebSocketReader.OpCode.Binary:
                if (!psocketState.Header.IsEnd)     // Not done, so we need to store this and wait for the end frame.
                {
                    psocketState.ContinuationFrame = new WebSocketFrame
                    {
                        Header           = psocketState.Header,
                        WebSocketPayload =
                            psocketState.ReceivedBytes.ToArray()
                    };
                }
                else
                {
                    // Send Done Event!
                    DataDelegate dataD = OnData;
                    if (dataD != null)
                    {
                        dataD(this, new WebsocketDataEventArgs()
                        {
                            Data = psocketState.ReceivedBytes.ToArray()
                        });
                    }
                }
                break;

            case WebSocketReader.OpCode.Text:
                if (!psocketState.Header.IsEnd)     // Not done, so we need to store this and wait for the end frame.
                {
                    psocketState.ContinuationFrame = new WebSocketFrame
                    {
                        Header           = psocketState.Header,
                        WebSocketPayload =
                            psocketState.ReceivedBytes.ToArray()
                    };
                }
                else
                {
                    TextDelegate textD = OnText;
                    if (textD != null)
                    {
                        textD(this, new WebsocketTextEventArgs()
                        {
                            Data = Encoding.UTF8.GetString(psocketState.ReceivedBytes.ToArray())
                        });
                    }

                    // Send Done Event!
                }
                break;

            case WebSocketReader.OpCode.Continue:      // Continuation.  Multiple frames worth of data for one message.   Only valid when not using Control Opcodes
                //Console.WriteLine("currhead " + psocketState.Header.IsEnd);
                //Console.WriteLine("Continuation! " + psocketState.ContinuationFrame.Header.IsEnd);
                byte[] combineddata = new byte[psocketState.ReceivedBytes.Count + psocketState.ContinuationFrame.WebSocketPayload.Length];
                byte[] newdata      = psocketState.ReceivedBytes.ToArray();
                Buffer.BlockCopy(psocketState.ContinuationFrame.WebSocketPayload, 0, combineddata, 0, psocketState.ContinuationFrame.WebSocketPayload.Length);
                Buffer.BlockCopy(newdata, 0, combineddata,
                                 psocketState.ContinuationFrame.WebSocketPayload.Length, newdata.Length);
                psocketState.ContinuationFrame.WebSocketPayload = combineddata;
                psocketState.Header.PayloadLen = (ulong)combineddata.Length;
                if (psocketState.Header.IsEnd)
                {
                    if (psocketState.ContinuationFrame.Header.Opcode == WebSocketReader.OpCode.Text)
                    {
                        // Send Done event
                        TextDelegate textD = OnText;
                        if (textD != null)
                        {
                            textD(this, new WebsocketTextEventArgs()
                            {
                                Data = Encoding.UTF8.GetString(combineddata)
                            });
                        }
                    }
                    else if (psocketState.ContinuationFrame.Header.Opcode == WebSocketReader.OpCode.Binary)
                    {
                        // Send Done event
                        DataDelegate dataD = OnData;
                        if (dataD != null)
                        {
                            dataD(this, new WebsocketDataEventArgs()
                            {
                                Data = combineddata
                            });
                        }
                    }
                    else
                    {
                        // protocol violation
                    }
                    psocketState.ContinuationFrame = null;
                }
                break;

            case WebSocketReader.OpCode.Close:
                Close(string.Empty);

                break;
            }
            psocketState.Header.SetDefault();
            psocketState.ReceivedBytes.Clear();
            psocketState.ExpectedBytes = 0;
        }
예제 #20
0
        /// <summary>
        /// Parses a Mustache-style markup
        /// </summary>
        /// <param name="content">Mustache-style markup</param>
        /// <param name="mustacheStyleTagHandler">Mustache-style tags handler</param>
        /// <param name="textHandler">Text handler</param>
        public static void ParseMarkup(string content, MustacheStyleTagDelegate mustacheStyleTagHandler,
                                       TextDelegate textHandler)
        {
            var innerContext = new InnerMarkupParsingContext(content);
            var context      = new MarkupParsingContext(innerContext);

            MatchCollection mustacheStyleTagMatches = _mustacheStyleTagRegex.Matches(content);

            if (mustacheStyleTagMatches.Count == 0)
            {
                if (textHandler != null)
                {
                    textHandler(context, content);
                }

                innerContext.IncreasePosition(content.Length);

                return;
            }

            int currentPosition = 0;
            int endPosition     = content.Length - 1;

            foreach (Match mustacheStyleTagMatch in mustacheStyleTagMatches)
            {
                int mustacheStyleTagPosition = mustacheStyleTagMatch.Index;
                int mustacheStyleTagLength   = mustacheStyleTagMatch.Length;

                if (mustacheStyleTagPosition > currentPosition)
                {
                    string text = content.Substring(currentPosition, mustacheStyleTagPosition - currentPosition);

                    if (textHandler != null)
                    {
                        textHandler(context, text);
                    }

                    innerContext.IncreasePosition(text.Length);
                }

                GroupCollection mustacheStyleTagGroups = mustacheStyleTagMatch.Groups;

                string expression     = mustacheStyleTagGroups["expression"].Value;
                string startDelimiter = mustacheStyleTagGroups["startDelimiter"].Value;
                string endDelimiter   = mustacheStyleTagGroups["endDelimiter"].Value;

                if (expression.StartsWith("{") && expression.EndsWith("}"))
                {
                    expression     = expression.Substring(1, expression.Length - 2);
                    startDelimiter = "{{{";
                    endDelimiter   = "}}}";
                }

                if (mustacheStyleTagHandler != null)
                {
                    mustacheStyleTagHandler(context, expression, startDelimiter, endDelimiter);
                }

                innerContext.IncreasePosition(mustacheStyleTagLength);
                currentPosition = mustacheStyleTagPosition + mustacheStyleTagLength;
            }

            if (currentPosition > 0 && currentPosition <= endPosition)
            {
                string text = content.Substring(currentPosition, endPosition - currentPosition + 1);

                if (textHandler != null)
                {
                    textHandler(context, text);
                }

                innerContext.IncreasePosition(text.Length);
            }
        }
예제 #21
0
 public GraphPage()
 {
     InitializeComponent();
      updateYoungestReadingDelegate = new TextDelegate(UpdateYoungestReading);
 }
예제 #22
0
        private void WriteToIOSendText(string str)
        {
            TextDelegate d1 = IOSendDel;

            textBoxIOSend.Invoke(d1, str);
        }
예제 #23
0
        private void WriteToIORecText(string str)
        {
            TextDelegate d2 = IORecDel;

            textBoxIORec.Invoke(d2, str);
        }
예제 #24
0
        private delegate void TextDelegate(string str);     //用于文本框代理

        private void WriteToServoSendText(string str)
        {
            TextDelegate d1 = ServoSendDel;

            textBoxServoSend.Invoke(d1, str);
        }