// Code to execute when the application is launching (eg, from Start)
        // This code will not execute when the application is reactivated
        private async void Application_Launching(object sender, LaunchingEventArgs e)
        {
            if (!AppSettings.Contains("ApplicationRated"))
            {
                AppSettings["ApplicationRated"] = false;
            }

            if (ConditionDevice.IsInternetConnected())
            {
                await SyncService.GetDraws();

                AnalyzeService.GetNumberStatistics();
                AnalyzeService.GetTzokerNumberStatistics();
            }
            else
            {
                MessageBox.Show("Δεν βρέθηκε σύνδεση στο διαδύκτιο. Η εφαρμογή τερματίζεται...");
                App.Current.Terminate();
            }
        }
예제 #2
0
        public bool ExecuteTask()
        {
            //MessageDialogs md =  new MessageDialogs(MessageDialogs.DialogButtonType.Cancel, "Cancel Publish.", filename, Gtk.MessageType.Question);
            Tool.Logger.LogDebugInfo("Publish no sign", null);

            /*if (MainClass.Settings.ClearConsoleBeforRuning){
             *      Tool.Logger.LogDebugInfo("CLEAR CONSOLE");
             *      MainClass.MainWindow.OutputConsole.Clear();
             * }*/

            if (MainClass.Workspace.ActualProject == null)
            {
                SetError(MainClass.Languages.Translate("no_project_selected"));
                Tool.Logger.LogDebugInfo(MainClass.Languages.Translate("no_project_selected"), null);
                return(false);
            }

            project = MainClass.Workspace.ActualProject;
            Tool.Logger.LogDebugInfo(String.Format("Project -> {0}", MainClass.Workspace.ActualProject), null);

            ShowInfo("Publish project", MainClass.Workspace.ActualProject.ProjectName);

            if (String.IsNullOrEmpty(project.ProjectOutput))
            {
                if (!String.IsNullOrEmpty(MainClass.Workspace.OutputDirectory))
                {
                    project.ProjectOutput = MainClass.Workspace.OutputDirectory;
                }
                else
                {
                    project.ProjectOutput = project.AbsolutProjectDir;
                }
                Tool.Logger.LogDebugInfo(String.Format("Project Output-> {0}", project.ProjectOutput), null);
            }

            if (!Directory.Exists(project.OutputMaskToFullPath))
            {
                try{
                    Tool.Logger.LogDebugInfo(String.Format("CREATE DIR Output-> {0}", project.OutputMaskToFullPath), null);
                    Directory.CreateDirectory(project.OutputMaskToFullPath);
                }catch
                {
                    SetError(MainClass.Languages.Translate("cannot_create_output"));
                    return(false);
                }
            }

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

            //project.GetAllFiles(ref filesList);
            GetAllFiles(ref filesList, project.AbsolutProjectDir);

            string tempDir = MainClass.Paths.TempPublishDir;             //System.IO.Path.Combine(MainClass.Settings.PublishDirectory,"_temp");

            Tool.Logger.LogDebugInfo(String.Format("Temp Directory-> {0}", tempDir), null);

            if (!Directory.Exists(tempDir))
            {
                try{
                    Tool.Logger.LogDebugInfo(String.Format("CREATE Temp Directory-> {0}", tempDir), null);
                    Directory.CreateDirectory(tempDir);
                } catch {
                    SetError(MainClass.Languages.Translate("cannot_create_temp_f1", tempDir));
                    return(false);
                }
            }

            if ((listCombinePublish == null) || (listCombinePublish.Count < 1))
            {
                Tool.Logger.LogDebugInfo("Publish list empty", null);
                SetError(MainClass.Languages.Translate("publish_list_is_empty"));
                return(false);
                //project.GeneratePublishCombination();
            }

            bool isAndroid = false;

            foreach (CombinePublish ccc in  listCombinePublish)
            {
                CombineCondition crPlatform = ccc.combineRule.Find(x => x.ConditionId == MainClass.Settings.Platform.Id);
                if (crPlatform != null)
                {
                    if ((crPlatform.RuleId == (int)DeviceType.Android_1_6) ||
                        (crPlatform.RuleId == (int)DeviceType.Android_2_2))
                    {
                        isAndroid = true;
                        //Console.WriteLine("ANDROID FOUND");
                        CheckJava();
                    }
                }
            }

            if (!isJavaInstaled && isAndroid)
            {
                ShowError(MainClass.Languages.Translate("java_missing"), MainClass.Languages.Translate("java_missing_title"));

                /*MessageDialogsUrl md = new MessageDialogsUrl(MessageDialogsUrl.DialogButtonType.Ok,MainClass.Languages.Translate("java_missing"), MainClass.Languages.Translate("java_missing_title"),"http://moscrif.com/java-requirement", Gtk.MessageType.Error,ParentWindow);
                 * md.ShowDialog();*/
            }

            /*if (listCombinePublish.Count > 0) {
             *
             *      double step = 1 / (listCombinePublish.Count * 1.0);
             *      MainClass.MainWindow.ProgressStart(step, MainClass.Languages.Translate("publish"));
             *      progressDialog = new ProgressDialog(MainClass.Languages.Translate("publishing"),ProgressDialog.CancelButtonType.Cancel,listCombinePublish.Count,ParentWindow);//MainClass.MainWindow
             * }*/

            foreach (CombinePublish ccc in  listCombinePublish)            //listCC ){
            //if (!ccc.IsSelected) continue;
            //Console.WriteLine(ccc.ToString());

            {
                if (stopProcess)
                {
                    break;
                }

                if (String.IsNullOrEmpty(project.ProjectArtefac))
                {
                    project.ProjectArtefac = System.IO.Path.GetFileNameWithoutExtension(project.RelativeAppFilePath);
                }
                string fileName = project.ProjectArtefac;

                List <ConditionDevice> condList = new List <ConditionDevice>();


                foreach (CombineCondition cr in ccc.combineRule)
                {
                    ConditionDevice cd = new ConditionDevice(cr.ConditionName, cr.RuleName);
                    //condList.Add(new ConditionDevice(cr.ConditionName,cr.RuleName));
                    if (cr.ConditionId == MainClass.Settings.Resolution.Id)
                    {
                        Rule rl = MainClass.Settings.Resolution.Rules.Find(x => x.Id == cr.RuleId);
                        if (rl != null)
                        {
                            cd.Height = rl.Height;
                            cd.Width  = rl.Width;
                        }
                    }
                    condList.Add(cd);

                    fileName = fileName.Replace(String.Format("$({0})", cr.ConditionName), cr.RuleName);
                }

                parentTask         = new TaskMessage("Publishing", fileName, null);
                devicePublishError = false;

                ShowInfo("Publishing", fileName);

                /*if (progressDialog != null)
                 *       progressDialog.SetLabel (fileName );*/

                if (Directory.Exists(tempDir))
                {
                    try{
                        DirectoryInfo di = new DirectoryInfo(tempDir);
                        foreach (DirectoryInfo d in di.GetDirectories())
                        {
                            d.Delete(true);
                        }
                        foreach (FileInfo f in di.GetFiles())
                        {
                            f.Delete();
                        }
                    } catch {
                    }
                }

                CombineCondition crPlatform  = ccc.combineRule.Find(x => x.ConditionId == MainClass.Settings.Platform.Id);
                CombineCondition crRsolution = ccc.combineRule.Find(x => x.ConditionId == MainClass.Settings.Resolution.Id);

                if (crPlatform == null)
                {
                    SetError(MainClass.Languages.Translate("platform_not_found", MainClass.Settings.Platform.Name), parentTask);
                    continue;
                }

                Device dvc = project.DevicesSettings.Find(x => x.TargetPlatformId == crPlatform.RuleId);

                if (dvc == null)
                {
                    SetError(MainClass.Languages.Translate("device_not_found", crPlatform.ConditionName, crPlatform.RuleName), parentTask);
                    continue;
                }

                if (((crPlatform.RuleId == (int)DeviceType.Android_1_6) ||
                     (crPlatform.RuleId == (int)DeviceType.Android_2_2)) &&
                    (!isJavaInstaled))
                {
                    SetError(MainClass.Languages.Translate("java_missing"), parentTask);
                    ShowError(MainClass.Languages.Translate("java_missing"), fileName);
                    continue;
                }

                string dirPublish = MainClass.Tools.GetPublishDirectory(dvc.Platform.Specific);                //System.IO.Path.Combine(MainClass.Settings.PublishDirectory,dvc.Platform.Specific);//crPlatform.RuleName);

                if (!Directory.Exists(dirPublish))
                {
                    SetError(MainClass.Languages.Translate("publish_tool_not_found"), parentTask);
                    continue;
                }

                if (String.IsNullOrEmpty(dirPublish))
                {
                    SetError(MainClass.Languages.Translate("publish_tool_not_found_f1"), parentTask);
                    continue;
                }

                dvc.Application = project.AppFile.Name;                 // TTT

                if (String.IsNullOrEmpty(project.ProjectOutput))
                {
                    if (!String.IsNullOrEmpty(MainClass.Workspace.OutputDirectory))
                    {
                        project.ProjectOutput = MainClass.Workspace.OutputDirectory;
                    }
                    else
                    {
                        project.ProjectOutput = project.AbsolutProjectDir;
                    }
                }

                dvc.Output_Dir = project.OutputMaskToFullPath;

                dvc.Temp = tempDir;

                dvc.Temp       = LastSeparator(dvc.Temp);
                dvc.Publish    = LastSeparator(MainClass.Settings.PublishDirectory);
                dvc.Root       = LastSeparator(MainClass.Workspace.RootDirectory);
                dvc.Output_Dir = LastSeparator(dvc.Output_Dir);

                dvc.Conditions = condList.ToArray();

                List <int> mergeResolutions = new List <int>();
                string     resolution       = crRsolution.RuleName;
                mergeResolutions.Add(crRsolution.RuleId);

                // Ak je zaskrtnute Merge All Resolution
                // Najdem vsetky publishovatelne combinacie danej platformy (napr. vsetky publishovane andrroidy)
                // a vytiahnem z nich rezolution a spojim do string odeleneho &
                if (dvc.Includes.Skin != null)
                {
                    dvc.Includes.Skin.ResolutionJson = dvc.Includes.Skin.Resolution;
                    if (!String.IsNullOrEmpty(dvc.Includes.Skin.Name))
                    {
                        if (project.IncludeAllResolution)
                        {
                            resolution = "";
                            mergeResolutions.Clear();
                            foreach (CombinePublish cp in  listCombinePublish)
                            {
                                CombineCondition crPlatform2 = cp.combineRule.Find(x => x.ConditionId == MainClass.Settings.Platform.Id && x.RuleId == crPlatform.RuleId);
                                if (crPlatform2 != null)
                                {
                                    CombineCondition crResolution2 = cp.combineRule.Find(x => x.ConditionId == MainClass.Settings.Resolution.Id);
                                    if (crResolution2 != null)
                                    {
                                        resolution = resolution + crResolution2.RuleName + "&";
                                        mergeResolutions.Add(crResolution2.RuleId);
                                    }
                                }
                            }
                            resolution = resolution.Remove(resolution.Length - 1, 1);
                            ConditionDevice cd = condList.Find(x => x.Name == MainClass.Settings.Resolution.Name);
                            if (cd != null)
                            {
                                cd.Value       = resolution;
                                dvc.Conditions = condList.ToArray();
                            }
                        }
                    }
                }

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

                foreach (string file in filesList)
                {
                    if (System.IO.Path.GetExtension(file) == ".msc")
                    {
                        continue;
                    }

                    string fileUpdate = FileUtility.AbsoluteToRelativePath(MainClass.Workspace.RootDirectory, file);

                    if (project.FilesProperty != null)
                    {
                        // vyhldam property suborov a pozriem ci nemam nejake conditiony nastavene
                        FileItem fi = project.FilesProperty.Find(x => x.SystemFilePath == fileUpdate);
                        if (fi != null)
                        {
                            if (fi.IsExcluded)
                            {
                                continue;
                            }

                            if (fi.ConditionValues == null)                             // nema ziadne konditions tak ho pridam
                            {
                                goto nav1;
                                //continue;
                            }
                            foreach (CombineCondition cr in ccc.combineRule)
                            {
                                ConditionRule conRile = fi.ConditionValues.Find(x => x.ConditionId == cr.ConditionId);
                                if (conRile != null)
                                {
                                    //if ((conRile.RuleId != cr.RuleId)) // subor ma condition daneho typu, ale nastavenu na inu hodnotu
                                    //goto nav;

                                    int resolutionId = -1;

                                    if (conRile.ConditionId == MainClass.Settings.Resolution.Id)
                                    {
                                        resolutionId = mergeResolutions.FindIndex(x => x == conRile.RuleId);
                                        //continue;
                                    }

                                    // mam merge resolution a subor patri do niektoreho mergnuteho resolution
                                    if ((conRile.ConditionId == MainClass.Settings.Resolution.Id) && (resolutionId > -1))
                                    {
                                        goto nav1;
                                    }

                                    // subor ma condition daneho typu, ale nastavenu na inu hodnotu
                                    if ((conRile.RuleId != cr.RuleId))
                                    {
                                        string msg1 = String.Format("File {0} REMOVE {1}-> {0}", fileUpdate, conRile.RuleId);
                                        Tool.Logger.LogDebugInfo(msg1, null);
                                        Console.WriteLine(msg1);
                                        goto nav;
                                    }
                                }
                            }
                        }
                    }
nav1:
                    fileUpdate = FileUtility.AbsoluteToRelativePath(project.AbsolutProjectDir, file);
                    fileUpdate = FileUtility.TrimStartingDotCharacter(fileUpdate);
                    fileUpdate = FileUtility.TrimStartingDirectorySeparator(fileUpdate);
                    filesForPublish.Add(fileUpdate);

                    /*string msg =String.Format("Add File to Publish-> {0}",fileUpdate);
                     * Tool.Logger.LogDebugInfo(msg,null);
                     * Console.WriteLine(msg);*/

                    nav :;
                }
                dvc.Includes.Files = filesForPublish.ToArray();

                List <string> fontForPublish = new List <string>();
                foreach (string fnt in dvc.Includes.Fonts)
                {
                    string tmp = fnt;
                    tmp = tmp.Replace('/', System.IO.Path.DirectorySeparatorChar);
                    tmp = tmp.Replace('\\', System.IO.Path.DirectorySeparatorChar);

                    fontForPublish.Add(tmp);
                }
                dvc.Includes.Fonts = fontForPublish.ToArray();

                dvc.Output_Name = fileName;

                dvc.PublishPropertisFull = new List <PublishProperty>();

                foreach (PublishProperty pp in dvc.PublishPropertisMask)
                {
                    PublishProperty ppFull = new PublishProperty(pp.PublishName);
                    ppFull.PublishValue = pp.PublishValue;
                    dvc.PublishPropertisFull.Add(ppFull);

                    if (pp.PublishName == Project.KEY_PERMISSION)
                    {
                        continue;
                    }
                    if (pp.PublishName == Project.KEY_CODESIGNINGIDENTITY)
                    {
                        continue;
                    }
                    if (pp.PublishName == Project.KEY_STOREPASSWORD)
                    {
                        continue;
                    }
                    if (pp.PublishName == Project.KEY_KEYPASSWORD)
                    {
                        continue;
                    }
                    if (pp.PublishName == Project.KEY_SUPPORTEDDEVICES)
                    {
                        continue;
                    }
                    if (pp.PublishName == Project.KEY_INSTALLOCATION)
                    {
                        continue;
                    }
                    if (pp.PublishName == Project.KEY_BUNDLEIDENTIFIER)
                    {
                        continue;
                    }
                    if (pp.PublishName == Project.KEY_ALIAS)
                    {
                        continue;
                    }
                    if (pp.PublishName == Project.KEY_APPLICATIONID)
                    {
                        continue;
                    }
                    if (pp.PublishName == Project.KEY_PASSWORD)
                    {
                        continue;
                    }

                    ppFull.PublishValue = project.ConvertProjectMaskPathToFull(pp.PublishValue);
                }

                //

                /*if(dvc.Includes.Skin != null){
                 *      dvc.Includes.Skin.ResolutionJson = dvc.Includes.Skin.Resolution;
                 *      if(!String.IsNullOrEmpty(dvc.Includes.Skin.Name)){
                 *              if(project.IncludeAllResolution){
                 *                      dvc.Includes.Skin.ResolutionJson = "*";
                 *              }
                 *      }
                 * }*/
                dvc.LogDebug        = MainClass.Settings.LogPublish;
                dvc.ApplicationType = project.ApplicationType;

                dvc.FacebookAppID = project.FacebookAppID;

                if (String.IsNullOrEmpty(project.FacebookAppID))
                {
                    dvc.FacebookAppID = "";
                }

                string path = System.IO.Path.Combine(dirPublish, "settings.mso");               //fileName+".mso"); //dvc.TargetPlatform + "_settings.mso");
                string json = dvc.GenerateJson();

                if (String.IsNullOrEmpty(json))
                {
                    SetError(MainClass.Languages.Translate("cannot_generate_mso"), parentTask);
                    continue;
                }

                try {
                    using (StreamWriter file = new StreamWriter(path)) {
                        file.Write(json);
                        file.Close();
                    }
                } catch {
                    SetError(MainClass.Languages.Translate("cannot_generate_mso"), parentTask);
                    continue;
                }

                //var platformRule = MainClass.Settings.Platform.Rules.Find(x => x.Id == dvc.TargetPlatformId);

                string appFile     = dvc.Platform.Specific + ".app"; /*dvc.TargetPlatform*/          //platformRule.Specific + ".app";
                string fullAppPath = System.IO.Path.Combine(MainClass.Settings.PublishDirectory, appFile);

                if (!System.IO.File.Exists(fullAppPath))
                {
                    SetError(MainClass.Languages.Translate("publish_tool_not_found_f2"), parentTask);
                    continue;
                }

                RunPublishTool(appFile, parentTask);

                /*if (RunPublishTool(appFile,parentTask) ){
                 *      parentTask.Message =MainClass.Languages.Translate("publish_successfully_done");
                 *      output.Add(parentTask);
                 *
                 *      //output.Add(new TaskMessage(MainClass.Languages.Translate("publish_successfully_done"),dvc.Platform.Specific,null));
                 * } else {
                 *      parentTask.Message =MainClass.Languages.Translate("publish_error");
                 *      Console.WriteLine(parentTask.Child.Message);
                 *      output.Add(parentTask);
                 *      //output.Add(new TaskMessage(MainClass.Languages.Translate("publish_error"),dvc.Platform.Specific,null));
                 * }*/
                if (MainClass.Platform.IsMac)
                {
                    ExitPublish(null, null);
                }

                if (devicePublishError)
                {
                    parentTask.Message = StateEnum.ERROR.ToString();
                    allPublishError    = true;
                    ShowError(StateEnum.ERROR.ToString(), " ");
                    //ShowError(lastMessage.Trim(),fileName);
                }
                else
                {
                    parentTask.Message = StateEnum.OK.ToString();
                    ShowInfo(" ", StateEnum.OK.ToString());
                }
                //parentTask.Message = //this.StateTask.ToString();
                //Console.WriteLine(parentTask.Child.Message);
                output.Add(parentTask);

                MainClass.MainWindow.ProgressStep();

                /*if (progressDialog != null)
                 *      cancelled = progressDialog.Update (fileName );*/
            }

            MainClass.MainWindow.ProgressEnd();

            /*if(progressDialog!= null){
             *      progressDialog.Destroy();
             * }*/
            //Console.WriteLine("allPublishError -> {0}",allPublishError);
            if (allPublishError)
            {
                this.stateTask = StateEnum.ERROR;
                string s = allErrors.ToString();

                if (s.Length > 120)
                {
                    s = s.Substring(0, 120);
                    s = s + " ... and more.";
                }

                ShowError(MainClass.Languages.Translate("publish_error"), " ");
                return(false);
            }
            if (stopProcess)
            {
                this.stateTask = StateEnum.CANCEL;
                ShowInfo(MainClass.Languages.Translate("Canceled"), " ", -1);

                return(false);
            }
            else
            {
                this.stateTask = StateEnum.OK;

                ShowInfo(" ", MainClass.Languages.Translate("publish_successfully_done"), 1);

                /*if(MainClass.Settings.OpenOutputAfterPublish){
                 *      if (!String.IsNullOrEmpty(project.ProjectOutput)){
                 *              MainClass.Tools.OpenFolder(project.OutputMaskToFullPath);
                 *      }
                 * }*/
                return(true);
            }
        }