Exemplo n.º 1
0
 /*@author Daniel Sandberg
  * The method constructs the request.
  */
 private void CreateRequest(Query query, int profileCounter)
 {
     string uri = query.ToString(profileCounter);
     request = HttpRequestFactory.Instance.CreateRequest(uri);
     request.Method = "GET";
     request.ContentType = "application/x-www-form-urlencoded";
     UTF8Encoding encoding = new UTF8Encoding();
     request.Headers.Add("Authorization: GoogleLogin auth=" + authenticationToken);
     request.Headers.Add("GData-Version: 2");
     request.ContentLength = 0;
 }
 private Query CompleteQuery(Query query)
 {
     if (startDateCalendar.SelectedDate.Value.Date.Equals(DateTime.Today))
     {
         query.TimePeriod = (TimePeriod)Enum.Parse(typeof(TimePeriod), TimeSpanBoxesColl.Where(p => (bool)p.IsChecked).First().Tag.ToString());
         query.SelectDates = false;
     }
     else
     {
         query.EndDate = (DateTime)endDateCalendar.SelectedDate;
         query.SelectDates = true;
     }
     return query;
 }
        public QueryBuilder(UserAccount userAccount, Query query)
        {
            double pixelHeight = System.Windows.SystemParameters.PrimaryScreenHeight;
            if (pixelHeight < 800)
            {

                SnapsToDevicePixels = true;

            }

            InitializeComponent();
            if (pixelHeight > 800)
            SizeToContent = System.Windows.SizeToContent.WidthAndHeight;

            this._query = query != null ? query : new Query();
            _currentUserAccount = userAccount;
            InitializeForm();
            SetTimePeriod(query);
            if (query.Ids.Count > 0)
                PreselectProfile(userAccount, query.Ids.First());
        }
Exemplo n.º 4
0
        public Report GetReport(Query query, string authToken, int profileCounter)
        {
            authenticationToken = authToken;
            NotifySubscribers(10 , "Requesting report" , null);
            Report report = new Report();
            int originalStartIndex = query.StartIndex;

            CreateRequest(query, profileCounter);
            if (!RequestData(request))
                return report;

            int dimensionsAndMetrics = query.GetDimensionsAndMetricsCount();

            if (xDoc != null)
            {
                NotifySubscribers(50, "Extract data", null);
                report.Data = ExtractDataFromXml(xDoc, dimensionsAndMetrics);
                report.Query = query.ToString();
                report.SiteURI = query.Ids[profileCounter].Value;
            }
            report.Headers = SetHeaders(query);

            // Checks if paging is neccessary.
            while (totalHitResult > upperLimitBound && upperLimitBound > 10000)
            {
                query.StartIndex = query.StartIndex + 10000;
                query.MaxResults = upperLimitBound = query.MaxResults + 10000;
                CreateRequest(query, profileCounter);
                if (!RequestData(request))
                    return report;
                NotifySubscribers(50, "Extract data", null);
                report.Data = ExtractDataFromXml(xDoc, dimensionsAndMetrics);
                if (upperLimitBound <= query.MaxResults)
                    break;
            }
            query.StartIndex = originalStartIndex;
            return report;
        }
Exemplo n.º 5
0
 void queryComplete(Query query, bool worksheet)
 {
     ExecuteQuery(_listQueries, worksheet);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Adds all queries to  a list. Gives each query one profileId if more than one.
        /// Sends the manipulated list of queries to execute.
        /// </summary>
        /// <param name="query"></param>
        void queryComplete(Query query)
        {
            // Here I need to go thru all selected profile and create a query for each one of them.
            //
            _listQueries = new List<Query>();
            List<Query> queries = new List<Query>();

            foreach (Item item in query.Ids)
            {
                _listQueries.Add(query);
            }

            ExecuteQuery(_listQueries, false);
        }
Exemplo n.º 7
0
 private void LaunchQueryBuilder(Query query)
 {
     if (_user != null && !string.IsNullOrEmpty(_user.AuthToken))
     {
         _queryBuilderWindow = new QueryBuilder(_user, query);
         _queryBuilderWindow.queryComplete += new QueryBuilder.QueryComplete(queryComplete);
         _queryBuilderWindow.ShowDialog();
     }
     else
     {
         InitLogin();
     }
 }
Exemplo n.º 8
0
        private void ClearPreviousQueryResult(bool clearFormat, bool worksheet, Query query)
        {
            int rows;
            int columns;

            if (worksheet)
            {
                if (int.TryParse(GetQueryExcelParamValueFromSpecificCell("rows", "")[1], out rows) &&
                    int.TryParse(GetQueryExcelParamValueFromSpecificCell("columns", "")[1], out columns))
                {
                    Worksheet _sheet = (Worksheet)GA_Excel2007.Globals.ThisAddIn.Application.ActiveSheet;

                    int activeColumn = query.Column;
                    int activeRow = query.Row;

                    Range queryInformationRange = _sheet.get_Range(_sheet.Cells[activeRow, activeColumn],
                    _sheet.Cells[activeRow + 1, activeColumn + 2 - 1]);
                    queryInformationRange.MergeCells = false;

                    Range rangeToClear = _sheet.get_Range(_sheet.Cells[activeRow + 1, activeColumn],
                                                                _sheet.Cells[activeRow + rows - 1, activeColumn + columns - 1]);

                    if (clearFormat)
                    {
                        queryInformationRange.Clear();
                        rangeToClear.Clear();
                    }
                    else
                        rangeToClear.ClearContents();
                }
            }
            else
            {
                if (int.TryParse(GetQueryExcelParamValueFromActiveCell("rows")[1], out rows) &&
                    int.TryParse(GetQueryExcelParamValueFromActiveCell("columns")[1], out columns))
                {
                    Microsoft.Office.Interop.Excel.Application currentApp = GA_Excel2007.Globals.ThisAddIn.Application;
                    Worksheet activeSheet = currentApp.ActiveSheet as Worksheet;
                    int activeColumn = currentApp.ActiveCell.Column;
                    int activeRow = currentApp.ActiveCell.Row;

                    Range rangeToClear = activeSheet.get_Range(activeSheet.Cells[activeRow + 1, activeColumn],
                                                                activeSheet.Cells[activeRow + rows - 1, activeColumn + columns - 1]);
                    if (clearFormat)
                        rangeToClear.Clear();
                    else
                        rangeToClear.ClearContents();
                }
            }
        }
Exemplo n.º 9
0
 private void buttonUpdate_Click(object sender, RibbonControlEventArgs e)
 {
     Query query = new Query(GetQueryExcelParamValueFromActiveCell("queryString"));
     query.TimePeriod = (Analytics.Data.Enums.TimePeriod)Enum.Parse(typeof(Analytics.Data.Enums.TimePeriod),
                                                                     GetQueryExcelParamValueFromActiveCell("timePeriod")[1]);
     LaunchQueryBuilder(query);
 }
Exemplo n.º 10
0
        private static void PresentResultUpdate(Query query, Report report, int profileCounter)
        {
            Microsoft.Office.Interop.Excel.Application currentApp = GA_Excel2007.Globals.ThisAddIn.Application;
            Worksheet activeSheet = currentApp.ActiveSheet as Worksheet;

            if (currentApp.ActiveSheet != null)
            {
                int activeColumn = query.Column;
                int activeRow = query.Row;
                string addressLocal = "";
                string addressHelper = "";

                object[] queryInformation = GetQueryInformation(query, report, profileCounter);

                int infoRows = queryInformation.GetLength(0);
                int dataLength = dataLength = report.Data.GetLength(1);

                Range queryInformationRange = currentApp.get_Range(activeSheet.Cells[activeRow, activeColumn],
                activeSheet.Cells[activeRow, activeColumn + dataLength - 1]);

                //
                addressLocal = queryInformationRange.get_Address().Replace("$", "");
                string[] adLocal = addressLocal.Split(':');

                // Looks after other reports in the same column.
                foreach (string address in _addressQueries)
                {
                    addressHelper = address.Replace("$", "");
                    // If there exist a report above this report then check where that report's data range ends.
                    if (addressHelper.First().Equals(adLocal[0].First()))
                    {

                        addressHelper = addressHelper.Substring(1, addressHelper.Length - 1);
                        int addressHelperInt = Int32.Parse(addressHelper);
                        int addressLocalInt = Int32.Parse(adLocal[0].Substring(1, adLocal[0].Length - 1));

                        if (addressHelperInt > addressLocalInt)
                        {
                            activeRow = addressHelperInt + 2;
                            queryInformationRange = currentApp.get_Range(activeSheet.Cells[activeRow, activeColumn],
                            activeSheet.Cells[activeRow, activeColumn + dataLength - 1]);
                        }
                    }
                }

                ((Style)queryInformationRange.Style).WrapText = false;
                queryInformationRange.Font.Italic = true;
                queryInformationRange.MergeCells = true;
                queryInformationRange.Borders.Weight = XlBorderWeight.xlThin;
                queryInformationRange.Value2 = queryInformation;

                if (report.Data != null)
                {
                    dataLength = report.Data.GetLength(1);
                    Range dataRange = currentApp.get_Range(activeSheet.Cells[activeRow + infoRows + 1, activeColumn],
                    activeSheet.Cells[activeRow + infoRows + report.Data.GetLength(0), activeColumn + report.Data.GetLength(1) - 1]);
                    dataRange.Value2 = report.Data;
                    // Saves the last cell in this particular data range.
                    string endDataRow = "";
                    endDataRow = adLocal[0].First() + (activeRow + infoRows + report.Data.GetLength(0)).ToString();
                    _addressQueries.Add(endDataRow);
                    Range headerRange = currentApp.get_Range(activeSheet.Cells[activeRow + infoRows, activeColumn],
                    activeSheet.Cells[activeRow + infoRows, activeColumn + report.Headers.GetLength(1) - 1]);
                    headerRange.Value2 = report.Headers;
                    headerRange.Font.Bold = true;
                }

            }
        }
Exemplo n.º 11
0
        private static void PresentResult(Query query, Report report, int profileCounter, int cellOffset)
        {
            // This method shall include a verification of empty columns. If the user has selected more than one profile
            // the second query shall be presented on the right of the first query result in Excel.

            Microsoft.Office.Interop.Excel.Application currentApp = GA_Excel2007.Globals.ThisAddIn.Application;
            Worksheet activeSheet = currentApp.ActiveSheet as Worksheet;

            if (currentApp.ActiveSheet != null)
            {
                int dataLength = 2;
                if (report.Data != null)
                {
                    dataLength = report.Data.GetLength(1);
                }

                int activeRow = currentApp.ActiveCell.Row;
                int activeColumn = currentApp.ActiveCell.Column + cellOffset;
                /*if (currentApp.ActiveCell.Cells.Value2 != null)
                {
                    activeColumn = ActiveColumn(profileCounter, dataLength);
                }*/

                object[] queryInformation = GetQueryInformation(query, report, profileCounter);

                int infoRows = queryInformation.GetLength(0);

                if (report.Data != null)
                {
                    dataLength = report.Data.GetLength(1);
                    Range dataRange = currentApp.get_Range(activeSheet.Cells[activeRow + infoRows + 1, activeColumn],
                    activeSheet.Cells[activeRow + infoRows + report.Data.GetLength(0), activeColumn + report.Data.GetLength(1) - 1]);
                    dataRange.Value2 = report.Data;

                    Range headerRange = currentApp.get_Range(activeSheet.Cells[activeRow + infoRows, activeColumn],
                    activeSheet.Cells[activeRow + infoRows, activeColumn + report.Headers.GetLength(1) - 1]);
                    headerRange.Value2 = report.Headers;
                    headerRange.Font.Bold = true;
                }

                Range queryInformationRange = currentApp.get_Range(activeSheet.Cells[activeRow, activeColumn],
                activeSheet.Cells[activeRow, activeColumn + dataLength - 1]);
                queryInformationRange.Font.Italic = true;
                queryInformationRange.MergeCells = true;
                queryInformationRange.Borders.Weight = XlBorderWeight.xlThin;

                queryInformationRange.Value2 = queryInformation;
                //int height = (int)queryInformationRange.Height; queryInformationRange.RowHeight = height;
            }
        }
Exemplo n.º 12
0
        private static object[] GetQueryInformation(Query query, Report report, int profileCounter)
        {
            string timePeriod = "";
            if (!query.SelectDates)
            {
                timePeriod += query.TimePeriod.ToString();
            }
            else
            {
                timePeriod = "PeriodNotSpecified";
            }

            object[] queryInformation = new object[] { report.SiteURI + " [ " + query.StartDate.ToShortDateString() + " -> " + query.EndDate.ToShortDateString() + " ]\n"
                + string.Format( "{0}queryString={1};rows={2};columns={3};timePeriod={4}]",
                                queryInfoIdentifier, query.ToString(profileCounter), report.Hits, query.GetDimensionsAndMetricsCount(), timePeriod)};
            return queryInformation;
        }
 private void ExecuteButton_Click(object sender, RoutedEventArgs e)
 {
     if (ValidateForm())
     {
         List<Query> queries = new List<Query>();
         Query queryHelper = new Query();
         foreach (Query query in _listQueries)
         {
             queryHelper = CompleteQuery(query);
             queryHelper = SetSelectedDates(queryHelper);
             queries.Add(queryHelper);
         }
         _listQueries = queries;
         this.Close();
         queryComplete(_query, true);
     }
 }
        private void SetTimePeriod(Query query)
        {
            if (!(query.Metrics.Values.Count.Equals(0)) && (_query.TimePeriod != TimePeriod.PeriodNotSpecified))
            {
                setCalendarToDefault();

                foreach (RadioButton itBox in TimeSpanBoxesColl)
                    itBox.IsChecked = query.TimePeriod.ToString() == itBox.Tag.ToString();

                timeSpanTab.IsSelected = true;
            }
        }
 private Query SetSelectedDates(Query query)
 {
     query.StartDate = (DateTime)startDateCalendar.SelectedDate;
     query.EndDate = (DateTime)endDateCalendar.SelectedDate;
     return query;
 }
Exemplo n.º 16
0
 private object[,] SetHeaders(Query query)
 {
     object[,] headers = new object[1, query.GetDimensionsAndMetricsCount()];
     int columnIndex = 0;
     foreach (string item in query.Dimensions.Keys)
     {
         headers[0, columnIndex] = item;
         columnIndex++;
     }
     foreach (string item in query.Metrics.Keys)
     {
         headers[0, columnIndex] = item;
         columnIndex++;
     }
     return headers;
 }