コード例 #1
0
        private void StartListening()
        {
            IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Loopback, 0);
            Socket     listener      = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            List <string> promptCmdLines = new List <string> ();

            try
            {
                listener.Bind(localEndPoint);
                int port = ((IPEndPoint)listener.LocalEndPoint).Port;
                listener.Listen(100);

                promptCmdLines.Add(ExcelAppleScript.CreateMacroWithArguments("SetMekkoSenderPort", port.ToString()));
                promptCmdLines.Add(promptCmd);
                string [] commands = promptCmdLines.ToArray();
                DispatchQueue.MainQueue.DispatchAsync(() => {
                    ExcelAppleScript.Run(commands);
                });

                while (waiting)
                {
                    allDone.Reset();
                    listener.BeginAccept(new AsyncCallback(ControlAcceptCallback), listener);
                    allDone.WaitOne();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
コード例 #2
0
 public ExcelDataSender(string macroName, params string [] Arguments)
 {
     waiting   = true;
     allDone   = null;
     byteData  = null;
     promptCmd = ExcelAppleScript.CreateMacroWithArguments(macroName, Arguments);
 }
コード例 #3
0
 public static void StopSession()
 {
     StopSessionObservers();
     ClearInputData();
     ClearSessionData();
     ExcelAppleScript.RunMacroAsync("HideByMekko");
     if (printDebugOutput)
     {
         Console.Out.WriteLine("Excel session stopped");
     }
 }
コード例 #4
0
        //-------------------------------------
        public static void CreateNewSession()
        {
            if (CellsArrayInput == null || CellsListInput == null || minRowInput == 0 || minColInput == 0 || numRowInput == 0 || numColInput == 0)
            {
                StopSession();
                return;
            }

            takeFromExcel = false;
            firstRun      = false;

            StopSessionObservers();
            UseInput();
            string data = "";

            int minRowFmt = 0, minColFmt = 0, numRowFmt = 0, numColFmt = 0;

            string[,] fmtArray = ExcelCellsArray.ToFormatArray(CellsList, out minRowFmt, out minColFmt);
            if (fmtArray != null)
            {
                numRowFmt = fmtArray.GetLength(0);
                numColFmt = fmtArray.GetLength(1);

                for (int iR = 0; iR < numRowFmt; iR++)
                {
                    for (int iC = 0; iC < numColFmt; iC++)
                    {
                        data += fmtArray[iR, iC] + "\t";
                    }
                }
            }

            int minRowVal = 0, minColVal = 0, numRowVal = 0, numColVal = 0;

            string[,] valArray = ExcelCellsArray.ToValueArray(CellsList, out minRowVal, out minColVal);
            if (valArray != null)
            {
                numRowVal = valArray.GetLength(0);
                numColVal = valArray.GetLength(1);

                for (int iR = 0; iR < numRowVal; iR++)
                {
                    for (int iC = 0; iC < numColVal; iC++)
                    {
                        data += valArray[iR, iC] + "\t";
                    }
                }
            }

            StartSessionObservers();
            ExcelAppleScript.StartExcel("CleanupByMekko");
            firstRun      = true;
            timeOpenExcel = DateTime.Now.Ticks;

            long elapsedTime = (timeOpenExcel - timeStartSession) / TimeSpan.TicksPerMillisecond;

            if (printDebugOutput)
            {
                Console.Out.WriteLine("Excel session started {0} sec", elapsedTime / 1000.0);
            }

            ExcelDataSender dataSender = new ExcelDataSender("SetRangeValueByMekko",
                                                             minRowFmt.ToString(),
                                                             minColFmt.ToString(),
                                                             numRowFmt.ToString(),
                                                             numColFmt.ToString(),
                                                             minRowVal.ToString(),
                                                             minColVal.ToString(),
                                                             numRowVal.ToString(),
                                                             numColVal.ToString());

            dataSender.Send(data);
        }
コード例 #5
0
        //-------------------------------------
        public static void UpdateSpreadSheetFromArray(ChartData chartData)
        {
//			chartDataArray = chartData;
//
//			int lastRow = chartDataArray.Data.GetLength (0);
//			int lastCol = chartDataArray.Data.GetLength (1);
//			if (lastRow < 2 && lastCol < 2)
//			{
//				//Logger.LogVerbose("UpdateSpreadSheetFromArray", "Data Array is empty!");
//				return;
//			}
//
//			CellsListInput = new List<ExcelCellInfo> ();
//
//			DataCell cell = null;
//			for (int row = 0; row < lastRow; row++)
//			{
//				for (int col = 0; col < lastCol; col++)
//				{
//					cell = (DataCell)chartDataArray.Data.GetValue(row, col);
//					if (cell != null)
//					{
//						ExcelCellInfo cellInfo = new ExcelCellInfo (cell);
//						CellsListInput.Add (cellInfo);
//					}
//				}
//			}
//			CellsListInput.Sort ();

            CellsListInput = new List <ExcelCellInfo> ();
            List <ExcelCellInfo> cellsInput = TestList();

            foreach (ExcelCellInfo info in cellsInput)
            {
                CellsListInput.Add(info);
            }
            CellsListInput.Sort();

            takeFromExcel = false;
            firstRun      = false;

            CellsArrayInput = ExcelCellsArray.RebuildSessionArray(cellsInput,
                                                                  out minRowInput,
                                                                  out minColInput,
                                                                  out numRowInput,
                                                                  out numColInput);

            if (observExcelChanges != null && CellsArray != null && CellsList != null &&
                minRowInput == minRow && minColInput == minCol && numRowInput == numRow && numColInput == numCol)
            {
                bool theSame = true;
                for (int iR = 0; iR < numRow; iR++)
                {
                    for (int iC = 0; iC < numCol; iC++)
                    {
                        if (CellsArray [iR, iC] != CellsArrayInput [iR, iC])
                        {
                            theSame = false;
                            break;
                        }
                    }
                    if (!theSame)
                    {
                        break;
                    }
                }

                if (theSame)
                {
                    if (printDebugOutput)
                    {
                        Console.Out.WriteLine("Old session and input data are the same");
                    }
                    StopSessionObservers();
                    ClearInputData();
                    StartSessionObservers();
                    ExcelAppleScript.StartExcel();
                    return;
                }
                else
                {
                    if (printDebugOutput)
                    {
                        Console.Out.WriteLine("Old session and input data are different");
                    }
                    StopSessionObservers();
                    ClearSessionData();
                    DispatchQueue.MainQueue.DispatchAsync(() => {
                        CreateNewSession();
                    });
                    return;
                }
            }
            else
            {
                if (printDebugOutput)
                {
                    Console.Out.WriteLine("No old session. Read data from Excel");
                }
                StopSessionObservers();
                ClearSessionData();
                takeFromExcel = true;
                StartSessionObservers(checkEmptyRespond: true);
                ExcelAppleScript.StartExcel("SendContentToMekko");
                return;
            }
        }